7 float autocvar_g_turrets_unit_ewheel_speed_fast;
8 float autocvar_g_turrets_unit_ewheel_speed_slow;
9 float autocvar_g_turrets_unit_ewheel_speed_slower;
10 float autocvar_g_turrets_unit_ewheel_speed_stop;
11 float autocvar_g_turrets_unit_ewheel_turnrate;
13 const int ewheel_anim_stop = 0;
14 const int ewheel_anim_fwd_slow = 1;
15 const int ewheel_anim_fwd_fast = 2;
16 const int ewheel_anim_bck_slow = 3;
17 const int ewheel_anim_bck_fast = 4;
19 void ewheel_move_path(entity this)
21 // Are we close enough to a path node to switch to the next?
22 if(vdist(this.origin - this.pathcurrent.origin, <, 64))
24 #ifdef EWHEEL_FANCYPATH
25 if (this.pathcurrent.path_next == NULL)
27 // Path endpoint reached
28 pathlib_deletepath(this.pathcurrent.owner);
29 this.pathcurrent = NULL;
33 if (this.pathgoal.use)
34 this.pathgoal.use(this.pathgoal, NULL, NULL);
36 if (this.pathgoal.enemy)
38 this.pathcurrent = pathlib_astar(this, this.pathgoal.origin,this.pathgoal.enemy.origin);
39 this.pathgoal = this.pathgoal.enemy;
46 this.pathcurrent = this.pathcurrent.path_next;
48 this.pathcurrent = this.pathcurrent.enemy;
55 this.moveto = this.pathcurrent.origin;
56 this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95);
58 movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_fast), 0.4);
62 void ewheel_move_enemy(entity this)
66 this.steerto = steerlib_arrive(this, this.enemy.origin,this.target_range_optimal);
68 this.moveto = this.origin + this.steerto * 128;
70 if (this.tur_dist_enemy > this.target_range_optimal)
72 if ( this.tur_head.spawnshieldtime < 1 )
74 newframe = ewheel_anim_fwd_fast;
75 movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_fast), 0.4);
77 else if (this.tur_head.spawnshieldtime < 2)
80 newframe = ewheel_anim_fwd_slow;
81 movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_slow), 0.4);
85 newframe = ewheel_anim_fwd_slow;
86 movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_slower), 0.4);
89 else if (this.tur_dist_enemy < this.target_range_optimal * 0.5)
91 newframe = ewheel_anim_bck_slow;
92 movelib_move_simple(this, v_forward * -1, (autocvar_g_turrets_unit_ewheel_speed_slow), 0.4);
96 newframe = ewheel_anim_stop;
97 movelib_brake_simple(this, (autocvar_g_turrets_unit_ewheel_speed_stop));
100 turrets_setframe(this, newframe, false);
103 void ewheel_move_idle(entity this)
107 this.SendFlags |= TNSF_ANIM;
108 this.anim_start_time = time;
113 movelib_brake_simple(this, (autocvar_g_turrets_unit_ewheel_speed_stop));
116 void ewheel_findtarget(entity this)
118 entity e = find(NULL, targetname, this.target);
121 LOG_TRACE("Initital waypoint for ewheel does NOT exist, fix your map!");
125 if (e.classname != "turret_checkpoint")
126 LOG_TRACE("Warning: not a turret path");
130 #ifdef EWHEEL_FANCYPATH
131 this.pathcurrent = pathlib_astar(this, this.origin, e.origin);
134 this.pathcurrent = e;
139 spawnfunc(turret_ewheel) { if(!turret_initialize(this, TUR_EWHEEL)) delete(this); }
141 METHOD(EWheel, tr_think, void(EWheel thistur, entity it))
143 vector wish_angle, real_angle;
145 float vz = it.velocity_z;
147 it.angles_x = anglemods(it.angles_x);
148 it.angles_y = anglemods(it.angles_y);
150 fixedmakevectors(it.angles);
152 wish_angle = normalize(it.steerto);
153 wish_angle = vectoangles(wish_angle);
154 real_angle = wish_angle - it.angles;
155 real_angle = shortangle_vxy(real_angle, it.tur_head.angles);
157 it.tur_head.spawnshieldtime = fabs(real_angle_y);
158 real_angle_y = bound(-it.tur_head.aim_speed, real_angle_y, it.tur_head.aim_speed);
159 it.angles_y = (it.angles_y + real_angle_y);
162 ewheel_move_enemy(it);
163 else if(it.pathcurrent)
164 ewheel_move_path(it);
166 ewheel_move_idle(it);
171 it.SendFlags |= TNSF_MOVE;
174 METHOD(EWheel, tr_death, void(EWheel this, entity it))
176 it.velocity = '0 0 0';
178 #ifdef EWHEEL_FANCYPATH
180 pathlib_deletepath(it.pathcurrent.owner);
182 it.pathcurrent = NULL;
185 METHOD(EWheel, tr_setup, void(EWheel this, entity it))
187 if(it.move_movetype == MOVETYPE_WALK)
189 it.velocity = '0 0 0';
192 setorigin(it, it.pos1);
195 InitializeEntity(it, ewheel_findtarget, INITPRIO_FINDTARGET);
198 it.iscreature = true;
199 it.teleportable = TELEPORT_NORMAL;
200 if(!it.damagedbycontents)
201 IL_PUSH(g_damagedbycontents, it);
202 it.damagedbycontents = true;
203 set_movetype(it, MOVETYPE_WALK);
204 it.solid = SOLID_SLIDEBOX;
205 it.takedamage = DAMAGE_AIM;
206 it.idle_aim = '0 0 0';
208 it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
209 it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
210 it.frame = it.tur_head.frame = 1;
211 it.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE;
213 // Convert from dgr / sec to dgr / tic
214 it.tur_head.aim_speed = (autocvar_g_turrets_unit_ewheel_turnrate);
215 it.tur_head.aim_speed = it.tur_head.aim_speed / (1 / it.ticrate);
221 void ewheel_draw(entity this)
225 dt = time - this.move_time;
226 this.move_time = time;
230 fixedmakevectors(this.angles);
231 setorigin(this, this.origin + this.velocity * dt);
232 this.tur_head.angles += dt * this.tur_head.avelocity;
234 if (this.health < 127)
236 te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
239 METHOD(EWheel, tr_setup, void(EWheel this, entity it))
242 set_movetype(it, MOVETYPE_BOUNCE);
244 it.draw = ewheel_draw;