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))
144 vector wish_angle, real_angle;
148 it.angles_x = anglemods(it.angles_x);
149 it.angles_y = anglemods(it.angles_y);
151 fixedmakevectors(it.angles);
153 wish_angle = normalize(it.steerto);
154 wish_angle = vectoangles(wish_angle);
155 real_angle = wish_angle - it.angles;
156 real_angle = shortangle_vxy(real_angle, it.tur_head.angles);
158 it.tur_head.spawnshieldtime = fabs(real_angle_y);
159 real_angle_y = bound(-it.tur_head.aim_speed, real_angle_y, it.tur_head.aim_speed);
160 it.angles_y = (it.angles_y + real_angle_y);
163 ewheel_move_enemy(it);
164 else if(it.pathcurrent)
165 ewheel_move_path(it);
167 ewheel_move_idle(it);
172 it.SendFlags |= TNSF_MOVE;
175 METHOD(EWheel, tr_death, void(EWheel this, entity it))
177 it.velocity = '0 0 0';
179 #ifdef EWHEEL_FANCYPATH
181 pathlib_deletepath(it.pathcurrent.owner);
183 it.pathcurrent = NULL;
186 METHOD(EWheel, tr_setup, void(EWheel this, entity it))
188 if(it.move_movetype == MOVETYPE_WALK)
190 it.velocity = '0 0 0';
193 setorigin(it, it.pos1);
196 InitializeEntity(it, ewheel_findtarget, INITPRIO_FINDTARGET);
199 it.iscreature = true;
200 it.teleportable = TELEPORT_NORMAL;
201 if(!it.damagedbycontents)
202 IL_PUSH(g_damagedbycontents, it);
203 it.damagedbycontents = true;
204 set_movetype(it, MOVETYPE_WALK);
205 it.solid = SOLID_SLIDEBOX;
206 it.takedamage = DAMAGE_AIM;
207 it.idle_aim = '0 0 0';
209 it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
210 it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
211 it.frame = it.tur_head.frame = 1;
212 it.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE;
214 // Convert from dgr / sec to dgr / tic
215 it.tur_head.aim_speed = (autocvar_g_turrets_unit_ewheel_turnrate);
216 it.tur_head.aim_speed = it.tur_head.aim_speed / (1 / it.ticrate);
222 void ewheel_draw(entity this)
226 dt = time - this.move_time;
227 this.move_time = time;
231 fixedmakevectors(this.angles);
232 setorigin(this, this.origin + this.velocity * dt);
233 this.tur_head.angles += dt * this.tur_head.avelocity;
235 if (this.health < 127)
237 te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
240 METHOD(EWheel, tr_setup, void(EWheel this, entity it))
243 set_movetype(it, MOVETYPE_BOUNCE);
245 it.draw = ewheel_draw;