5 float autocvar_g_turrets_unit_ewheel_speed_fast;
6 float autocvar_g_turrets_unit_ewheel_speed_slow;
7 float autocvar_g_turrets_unit_ewheel_speed_slower;
8 float autocvar_g_turrets_unit_ewheel_speed_stop;
9 float autocvar_g_turrets_unit_ewheel_turnrate;
11 const int ewheel_anim_stop = 0;
12 const int ewheel_anim_fwd_slow = 1;
13 const int ewheel_anim_fwd_fast = 2;
14 const int ewheel_anim_bck_slow = 3;
15 const int ewheel_anim_bck_fast = 4;
17 void ewheel_move_path(entity this)
19 // Are we close enough to a path node to switch to the next?
20 if(turret_closetotarget(this, this.pathcurrent.origin, 64))
22 #ifdef EWHEEL_FANCYPATH
23 if (this.pathcurrent.path_next == NULL)
25 // Path endpoint reached
26 pathlib_deletepath(this.pathcurrent.owner);
27 this.pathcurrent = NULL;
31 if (this.pathgoal.use)
32 this.pathgoal.use(this.pathgoal, NULL, NULL);
34 if (this.pathgoal.enemy)
36 this.pathcurrent = pathlib_astar(this, this.pathgoal.origin,this.pathgoal.enemy.origin);
37 this.pathgoal = this.pathgoal.enemy;
44 this.pathcurrent = this.pathcurrent.path_next;
46 this.pathcurrent = this.pathcurrent.enemy;
52 this.moveto = this.pathcurrent.origin;
53 this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95);
55 movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_fast), 0.4);
59 void ewheel_move_enemy(entity this)
63 this.steerto = steerlib_arrive(this, this.enemy.origin,this.target_range_optimal);
65 this.moveto = this.origin + this.steerto * 128;
67 if (this.tur_dist_enemy > this.target_range_optimal)
69 if ( this.tur_head.spawnshieldtime < 1 )
71 newframe = ewheel_anim_fwd_fast;
72 movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_fast), 0.4);
74 else if (this.tur_head.spawnshieldtime < 2)
77 newframe = ewheel_anim_fwd_slow;
78 movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_slow), 0.4);
82 newframe = ewheel_anim_fwd_slow;
83 movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_slower), 0.4);
86 else if (this.tur_dist_enemy < this.target_range_optimal * 0.5)
88 newframe = ewheel_anim_bck_slow;
89 movelib_move_simple(this, v_forward * -1, (autocvar_g_turrets_unit_ewheel_speed_slow), 0.4);
93 newframe = ewheel_anim_stop;
94 movelib_brake_simple(this, (autocvar_g_turrets_unit_ewheel_speed_stop));
97 turrets_setframe(this, newframe, false);
100 void ewheel_move_idle(entity this)
104 this.SendFlags |= TNSF_ANIM;
105 this.anim_start_time = time;
110 movelib_brake_simple(this, (autocvar_g_turrets_unit_ewheel_speed_stop));
113 void ewheel_findtarget(entity this)
115 entity e = find(NULL, targetname, this.target);
118 LOG_TRACE("Initital waypoint for ewheel does NOT exist, fix your map!");
122 if (e.classname != "turret_checkpoint")
123 LOG_TRACE("Warning: not a turret path");
127 #ifdef EWHEEL_FANCYPATH
128 this.pathcurrent = pathlib_astar(this, this.origin, e.origin);
131 this.pathcurrent = e;
136 spawnfunc(turret_ewheel) { if(!turret_initialize(this, TUR_EWHEEL)) delete(this); }
138 METHOD(EWheel, tr_think, void(EWheel thistur, entity it))
140 vector wish_angle, real_angle;
142 float vz = it.velocity_z;
144 it.angles_x = anglemods(it.angles_x);
145 it.angles_y = anglemods(it.angles_y);
147 fixedmakevectors(it.angles);
149 wish_angle = normalize(it.steerto);
150 wish_angle = vectoangles(wish_angle);
151 real_angle = wish_angle - it.angles;
152 real_angle = shortangle_vxy(real_angle, it.tur_head.angles);
154 it.tur_head.spawnshieldtime = fabs(real_angle_y);
155 real_angle_y = bound(-it.tur_head.aim_speed, real_angle_y, it.tur_head.aim_speed);
156 it.angles_y = (it.angles_y + real_angle_y);
159 ewheel_move_enemy(it);
160 else if(it.pathcurrent)
161 ewheel_move_path(it);
163 ewheel_move_idle(it);
168 it.SendFlags |= TNSF_MOVE;
171 METHOD(EWheel, tr_death, void(EWheel this, entity it))
173 it.velocity = '0 0 0';
175 #ifdef EWHEEL_FANCYPATH
177 pathlib_deletepath(it.pathcurrent.owner);
179 it.pathcurrent = NULL;
182 METHOD(EWheel, tr_setup, void(EWheel this, entity it))
184 if(it.move_movetype == MOVETYPE_WALK)
186 it.velocity = '0 0 0';
189 setorigin(it, it.pos1);
192 InitializeEntity(it, ewheel_findtarget, INITPRIO_FINDTARGET);
195 it.iscreature = true;
196 it.teleportable = TELEPORT_NORMAL;
197 if(!it.damagedbycontents)
198 IL_PUSH(g_damagedbycontents, it);
199 it.damagedbycontents = true;
200 set_movetype(it, MOVETYPE_WALK);
201 it.solid = SOLID_SLIDEBOX;
202 it.takedamage = DAMAGE_AIM;
203 it.idle_aim = '0 0 0';
205 it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
206 it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
207 it.frame = it.tur_head.frame = 1;
208 it.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE;
210 // Convert from dgr / sec to dgr / tic
211 it.tur_head.aim_speed = (autocvar_g_turrets_unit_ewheel_turnrate);
212 it.tur_head.aim_speed = it.tur_head.aim_speed / (1 / it.ticrate);
218 void ewheel_draw(entity this)
222 dt = time - this.move_time;
223 this.move_time = time;
227 fixedmakevectors(this.angles);
228 setorigin(this, this.origin + this.velocity * dt);
229 this.tur_head.angles += dt * this.tur_head.avelocity;
231 if(GetResource(this, RES_HEALTH) < 127)
233 te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
236 METHOD(EWheel, tr_setup, void(EWheel this, entity it))
239 set_movetype(it, MOVETYPE_BOUNCE);
241 it.draw = ewheel_draw;