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 float ewheel_anim_stop = 0;
14 const float ewheel_anim_fwd_slow = 1;
15 const float ewheel_anim_fwd_fast = 2;
16 const float ewheel_anim_bck_slow = 3;
17 const float ewheel_anim_bck_fast = 4;
19 void ewheel_move_path(entity this)
21 #ifdef EWHEEL_FANCYPATH
22 // Are we close enougth to a path node to switch to the next?
23 if(vdist(this.origin - this.pathcurrent.origin, <, 64))
24 if (this.pathcurrent.path_next == NULL)
26 // Path endpoint reached
27 pathlib_deletepath(this.pathcurrent.owner);
28 this.pathcurrent = NULL;
32 if (this.pathgoal.use)
33 this.pathgoal.use(this.pathgoal, NULL, NULL);
35 if (this.pathgoal.enemy)
37 this.pathcurrent = pathlib_astar(this, this.pathgoal.origin,this.pathgoal.enemy.origin);
38 this.pathgoal = this.pathgoal.enemy;
45 this.pathcurrent = this.pathcurrent.path_next;
48 if(vdist(this.origin - this.pathcurrent.origin, <, 64))
49 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 spawnfunc(turret_ewheel) { if(!turret_initialize(this, TUR_EWHEEL)) delete(this); }
118 METHOD(EWheel, tr_think, void(EWheel thistur, entity it))
121 vector wish_angle, real_angle;
125 it.angles_x = anglemods(it.angles_x);
126 it.angles_y = anglemods(it.angles_y);
128 fixedmakevectors(it.angles);
130 wish_angle = normalize(it.steerto);
131 wish_angle = vectoangles(wish_angle);
132 real_angle = wish_angle - it.angles;
133 real_angle = shortangle_vxy(real_angle, it.tur_head.angles);
135 it.tur_head.spawnshieldtime = fabs(real_angle_y);
136 real_angle_y = bound(-it.tur_head.aim_speed, real_angle_y, it.tur_head.aim_speed);
137 it.angles_y = (it.angles_y + real_angle_y);
140 ewheel_move_enemy(it);
141 else if(it.pathcurrent)
142 ewheel_move_path(it);
144 ewheel_move_idle(it);
149 it.SendFlags |= TNSF_MOVE;
152 METHOD(EWheel, tr_death, void(EWheel this, entity it))
154 it.velocity = '0 0 0';
156 #ifdef EWHEEL_FANCYPATH
158 pathlib_deletepath(it.pathcurrent.owner);
160 it.pathcurrent = NULL;
163 METHOD(EWheel, tr_setup, void(EWheel this, entity it))
167 if(it.move_movetype == MOVETYPE_WALK)
169 it.velocity = '0 0 0';
172 setorigin(it, it.pos1);
176 e = find(NULL, targetname, it.target);
179 LOG_TRACE("Initital waypoint for ewheel does NOT exsist, fix your map!");
183 if (e.classname != "turret_checkpoint")
184 LOG_TRACE("Warning: not a turrret path");
188 #ifdef EWHEEL_FANCYPATH
189 it.pathcurrent = WALKER_PATH(it, it.origin, e.origin);
198 it.iscreature = true;
199 it.teleportable = TELEPORT_NORMAL;
200 it.damagedbycontents = true;
201 IL_PUSH(g_damagedbycontents, it);
202 set_movetype(it, MOVETYPE_WALK);
203 it.solid = SOLID_SLIDEBOX;
204 it.takedamage = DAMAGE_AIM;
205 it.idle_aim = '0 0 0';
207 it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
208 it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
209 it.frame = it.tur_head.frame = 1;
210 it.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE;
212 // Convert from dgr / sec to dgr / tic
213 it.tur_head.aim_speed = (autocvar_g_turrets_unit_ewheel_turnrate);
214 it.tur_head.aim_speed = it.tur_head.aim_speed / (1 / it.ticrate);
220 void ewheel_draw(entity this)
224 dt = time - this.move_time;
225 this.move_time = time;
229 fixedmakevectors(this.angles);
230 setorigin(this, this.origin + this.velocity * dt);
231 this.tur_head.angles += dt * this.tur_head.avelocity;
233 if (this.health < 127)
235 te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
238 METHOD(EWheel, tr_setup, void(EWheel this, entity it))
241 set_movetype(it, MOVETYPE_BOUNCE);
243 it.draw = ewheel_draw;