5 #define ANIM_STRAFE_L 4
6 #define ANIM_STRAFE_R 5
15 #define WALKER_MIN '-70 -70 0'
16 #define WALKER_MAX '70 70 95'
18 #define WALKER_PATH(s,e) pathlib_astar(s,e)
20 float walker_firecheck()
22 if (self.animflag == ANIM_MEELE)
25 return turret_stdproc_firecheck();
28 void walker_meele_do_dmg()
33 makevectors(self.angles);
34 where = self.origin + v_forward * 128;
36 e = findradius(where,32);
39 if (turret_validate_target(self,e,self.target_validate_flags))
40 if (e != self && e.owner != self)
41 Damage(e, self, self, autocvar_g_turrets_unit_walker_std_meele_dmg ,DEATH_TURRET,'0 0 0', v_forward * autocvar_g_turrets_unit_walker_std_meele_force);
47 void walker_setnoanim()
49 turrets_setframe(ANIM_NO, FALSE);
50 self.animflag = self.frame;
52 void walker_rocket_explode()
56 if (self.event_damage != SUB_Null)
58 self.event_damage = SUB_Null;
59 self.think = walker_rocket_explode;
60 self.nextthink = time;
64 sound (self, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
65 org2 = findbetterlocation (self.origin, 16);
67 pointparticles(particleeffectnum("rocket_explode"), org2, '0 0 0', 1);
68 RadiusDamage (self, self.owner, autocvar_g_turrets_unit_walker_std_rocket_dmg, 0, autocvar_g_turrets_unit_walker_std_rocket_radius, world,autocvar_g_turrets_unit_walker_std_rocket_force, DEATH_TURRET, world);
73 void walker_rocket_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce)
75 self.health = self.health - damage;
76 self.velocity = self.velocity + vforce;
78 walker_rocket_explode();
81 #define WALKER_ROCKET_MOVE movelib_move_simple(newdir, autocvar_g_turrets_unit_walker_std_rocket_speed, autocvar_g_turrets_unit_walker_std_rocket_turnrate); UpdateCSQCProjectile(self)
82 void walker_rocket_loop();
83 void walker_rocket_think()
90 self.nextthink = time;
92 edist = vlen(self.enemy.origin - self.origin);
94 // Simulate crude guidance
98 self.tur_shotorg = randomvec() * min(edist, 64);
100 self.tur_shotorg = randomvec() * min(edist, 256);
102 self.cnt = time + 0.5;
106 self.tur_shotorg = '0 0 0';
108 if (self.tur_health < time)
110 self.think = walker_rocket_explode;
111 self.nextthink = time;
115 if (self.shot_dmg != 1337 && random() < 0.01)
117 walker_rocket_loop();
121 m_speed = vlen(self.velocity);
123 // Enemy dead? just keep on the current heading then.
124 if (self.enemy == world || self.enemy.deadflag != DEAD_NO)
129 itime = max(edist / m_speed, 1);
130 newdir = steerlib_pull(self.enemy.origin + self.tur_shotorg);
133 newdir = normalize(self.velocity);
138 void walker_rocket_loop3()
141 self.nextthink = time;
143 if (self.tur_health < time)
145 self.think = walker_rocket_explode;
149 if (vlen(self.origin - self.tur_shotorg) < 100 )
151 self.think = walker_rocket_think;
155 newdir = steerlib_pull(self.tur_shotorg);
158 self.angles = vectoangles(self.velocity);
161 void walker_rocket_loop2()
165 self.nextthink = time;
167 if (self.tur_health < time)
169 self.think = walker_rocket_explode;
173 if (vlen(self.origin - self.tur_shotorg) < 100 )
175 self.tur_shotorg = self.origin - '0 0 200';
176 self.think = walker_rocket_loop3;
180 newdir = steerlib_pull(self.tur_shotorg);
184 void walker_rocket_loop()
186 self.nextthink = time;
187 self.tur_shotorg = self.origin + '0 0 300';
188 self.think = walker_rocket_loop2;
189 self.shot_dmg = 1337;
192 void walker_fire_rocket(vector org)
196 fixedmakevectors(self.angles);
201 setorigin(rocket, org);
203 sound (self, CHAN_WEAPON, "weapons/hagar_fire.wav", VOL_BASE, ATTN_NORM);
204 setsize (rocket, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
206 rocket.classname = "walker_rocket";
208 rocket.bot_dodge = TRUE;
209 rocket.bot_dodgerating = 50;
210 rocket.takedamage = DAMAGE_YES;
211 rocket.damageforcescale = 2;
213 rocket.tur_shotorg = randomvec() * 512;
214 rocket.cnt = time + 1;
215 rocket.enemy = self.enemy;
218 rocket.think = walker_rocket_loop;
220 rocket.think = walker_rocket_think;
222 rocket.event_damage = walker_rocket_damage;
224 rocket.nextthink = time;
225 rocket.movetype = MOVETYPE_FLY;
226 rocket.velocity = normalize((v_forward + v_up * 0.5) + (randomvec() * 0.2)) * autocvar_g_turrets_unit_walker_std_rocket_speed;
227 rocket.angles = vectoangles(rocket.velocity);
228 rocket.touch = walker_rocket_explode;
229 rocket.flags = FL_PROJECTILE;
230 rocket.solid = SOLID_BBOX;
231 rocket.tur_health = time + 9;
233 CSQCProjectile(rocket, FALSE, PROJECTILE_ROCKET, FALSE); // no culling, has fly sound
236 .vector enemy_last_loc;
237 .float enemy_last_time;
238 void walker_move_to(vector _target, float _dist)
240 switch (self.waterlevel)
242 case WATERLEVEL_NONE:
244 self.animflag = ANIM_RUN;
246 self.animflag = ANIM_WALK;
247 case WATERLEVEL_WETFEET:
248 case WATERLEVEL_SWIMMING:
249 if (self.animflag != ANIM_SWIM)
250 self.animflag = ANIM_WALK;
252 self.animflag = ANIM_SWIM;
254 case WATERLEVEL_SUBMERGED:
255 self.animflag = ANIM_SWIM;
258 self.moveto = _target;
259 self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
263 self.enemy_last_loc = _target;
264 self.enemy_last_time = time;
268 void walker_move_path()
270 // Are we close enougth to a path node to switch to the next?
271 if (vlen(self.origin - self.pathcurrent.origin) < 64)
272 if (self.pathcurrent.path_next == world)
274 // Path endpoint reached
275 pathlib_deletepath(self.pathcurrent.owner);
276 self.pathcurrent = world;
280 if (self.pathgoal.use)
283 if (self.pathgoal.enemy)
285 self.pathcurrent = WALKER_PATH(self.pathgoal.origin,self.pathgoal.enemy.origin);
286 self.pathgoal = self.pathgoal.enemy;
290 self.pathgoal = world;
293 self.pathcurrent = self.pathcurrent.path_next;
295 self.moveto = self.pathcurrent.origin;
296 self.steerto = steerlib_attract2(self.moveto,0.5,500,0.95);
297 walker_move_to(self.moveto, 0);
305 void walker_postthink()
307 fixedmakevectors(self.angles);
309 if (self.spawnflags & TSF_NO_PATHBREAK && self.pathcurrent)
311 else if (self.enemy == world)
317 if(self.enemy_last_time != 0)
319 if(vlen(self.origin - self.enemy_last_loc) < 128 || time - self.enemy_last_time > 10)
320 self.enemy_last_time = 0;
322 walker_move_to(self.enemy_last_loc, 0);
326 if(self.animflag != ANIM_NO)
328 traceline(self.origin + '0 0 64', self.origin + '0 0 64' + v_forward * 128, MOVE_NORMAL, self);
330 if(trace_fraction != 1.0)
331 self.tur_head.idletime = -1337;
334 traceline(trace_endpos, trace_endpos - '0 0 256', MOVE_NORMAL, self);
335 if(trace_fraction == 1.0)
336 self.tur_head.idletime = -1337;
339 if(self.tur_head.idletime == -1337)
341 self.moveto = self.origin + randomvec() * 256;
342 self.tur_head.idletime = 0;
345 self.moveto = self.moveto * 0.9 + ((self.origin + v_forward * 500) + randomvec() * 400) * 0.1;
346 self.moveto_z = self.origin_z + 64;
347 walker_move_to(self.moveto, 0);
350 if(self.idletime < time)
354 self.idletime = time + 1 + random() * 5;
355 self.moveto = self.origin;
356 self.animflag = ANIM_NO;
360 self.animflag = ANIM_WALK;
361 self.idletime = time + 4 + random() * 2;
362 self.moveto = self.origin + randomvec() * 256;
363 self.tur_head.moveto = self.moveto;
364 self.tur_head.idletime = 0;
372 if (self.tur_dist_enemy < autocvar_g_turrets_unit_walker_std_meele_range && self.animflag != ANIM_MEELE)
376 wish_angle = angleofs(self, self.enemy);
377 if (self.animflag != ANIM_SWIM)
378 if (fabs(wish_angle_y) < 15)
380 self.moveto = self.enemy.origin;
381 self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
382 self.animflag = ANIM_MEELE;
385 else if (self.tur_head.attack_finished_single < time)
387 if(self.tur_head.shot_volly)
389 self.animflag = ANIM_NO;
391 self.tur_head.shot_volly = self.tur_head.shot_volly -1;
392 if(self.tur_head.shot_volly == 0)
393 self.tur_head.attack_finished_single = time + autocvar_g_turrets_unit_walker_std_rocket_refire;
395 self.tur_head.attack_finished_single = time + 0.2;
397 if(self.tur_head.shot_volly > 1)
398 walker_fire_rocket(gettaginfo(self, gettagindex(self, "tag_rocket01")));
400 walker_fire_rocket(gettaginfo(self, gettagindex(self, "tag_rocket02")));
404 if (self.tur_dist_enemy > autocvar_g_turrets_unit_walker_std_rockets_range_min)
405 if (self.tur_dist_enemy < autocvar_g_turrets_unit_walker_std_rockets_range)
406 self.tur_head.shot_volly = 4;
411 if (self.animflag != ANIM_MEELE)
412 walker_move_to(self.enemy.origin, self.tur_dist_enemy);
416 //if(self.animflag != ANIM_NO)
422 real_angle = vectoangles(self.steerto) - self.angles;
423 vz = self.velocity_z;
425 switch (self.animflag)
428 movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop);
432 turny = autocvar_g_turrets_unit_walker_turn;
433 movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop);
437 turny = autocvar_g_turrets_unit_walker_turn_walk;
438 movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_walk, 0.6);
442 turny = autocvar_g_turrets_unit_walker_turn_run;
443 movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_run, 0.6);
447 turny = autocvar_g_turrets_unit_walker_turn_strafe;
448 movelib_move_simple(v_right * -1, autocvar_g_turrets_unit_walker_speed_walk, 0.8);
452 turny = autocvar_g_turrets_unit_walker_turn_strafe;
453 movelib_move_simple(v_right, autocvar_g_turrets_unit_walker_speed_walk, 0.8);
457 self.velocity += '0 0 1' * autocvar_g_turrets_unit_walker_speed_jump;
464 if(self.frame != ANIM_PAIN)
465 defer(0.25, walker_setnoanim);
470 if(self.frame != ANIM_MEELE)
472 defer(0.41, walker_setnoanim);
473 defer(0.21, walker_meele_do_dmg);
476 movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop);
480 turny = autocvar_g_turrets_unit_walker_turn_swim;
481 turnx = autocvar_g_turrets_unit_walker_turn_swim;
483 self.angles_x += bound(-10, shortangle_f(real_angle_x, self.angles_x), 10);
484 movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_swim, 0.3);
485 vz = self.velocity_z + sin(time * 4) * 8;
489 turny = autocvar_g_turrets_unit_walker_turn_walk;
490 movelib_move_simple(v_forward ,autocvar_g_turrets_unit_walker_speed_roam, 0.5);
496 turny = bound( turny * -1, shortangle_f(real_angle_y, self.angles_y), turny );
497 self.angles_y += turny;
502 turnx = bound( turnx * -1, shortangle_f(real_angle_x, self.angles_x), turnx );
503 self.angles_x += turnx;
506 self.velocity_z = vz;
510 if(self.origin != self.oldorigin)
511 self.SendFlags |= TNSF_MOVE;
513 self.oldorigin = self.origin;
514 turrets_setframe(self.animflag, FALSE);
520 sound (self, CHAN_WEAPON, "weapons/uzi_fire.wav", VOL_BASE, ATTN_NORM);
521 fireBallisticBullet (self.tur_shotorg, self.tur_shotdir_updated, self.shot_spread, self.shot_speed, 5, self.shot_dmg, 0, self.shot_force, DEATH_TURRET, 0, 1, autocvar_g_balance_uzi_bulletconstant);
522 endFireBallisticBullet();
523 pointparticles(particleeffectnum("laser_muzzleflash"), self.tur_shotorg, self.tur_shotdir_updated * 1000, 1);
527 void walker_respawnhook()
531 // Respawn is called & first spawn to, to set team. need to make sure we do not move the initial spawn.
532 if(self.movetype != MOVETYPE_WALK)
535 setorigin(self, self.pos1);
536 self.angles = self.pos2;
538 if (self.target != "")
540 e = find(world,targetname,self.target);
543 dprint("Warning! initital waypoint for Walker does NOT exsist!\n");
547 if (e.classname != "turret_checkpoint")
548 dprint("Warning: not a turrret path\n");
551 self.pathcurrent = WALKER_PATH(self.origin,e.origin);
557 void walker_diehook()
559 if (self.pathcurrent)
560 pathlib_deletepath(self.pathcurrent.owner);
562 self.pathcurrent = world;
565 void turret_walker_dinit()
570 if (self.netname == "") self.netname = "Walker Turret";
572 self.ammo_flags = TFL_AMMO_BULLETS | TFL_AMMO_RECHARGE | TFL_AMMO_RECIVE;
573 self.turrcaps_flags = TFL_TURRCAPS_PLAYERKILL | TFL_TURRCAPS_MOVE ;
574 self.aim_flags = TFL_AIM_LEAD;
576 if (autocvar_g_antilag_bullets)
577 self.turrcaps_flags |= TFL_TURRCAPS_HITSCAN;
579 self.aim_flags |= TFL_AIM_SHOTTIMECOMPENSATE;
582 self.turret_respawnhook = walker_respawnhook;
583 self.turret_diehook = walker_diehook;
586 if (turret_stdproc_init("walker_std", "models/turrets/walker_body.md3", "models/turrets/walker_head_minigun.md3", TID_WALKER) == 0)
592 self.damage_flags |= TFL_DMG_DEATH_NOGIBS;
593 self.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
594 self.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
596 self.iscreature = TRUE;
597 self.movetype = MOVETYPE_WALK;
598 self.solid = SOLID_SLIDEBOX;
599 self.takedamage = DAMAGE_AIM;
602 setsize(self, WALKER_MIN, WALKER_MAX);
604 setorigin(self, self.origin);
605 tracebox(self.origin + '0 0 128', self.mins,self.maxs,self.origin - '0 0 10000', MOVE_NORMAL, self);
606 setorigin(self, trace_endpos + '0 0 4');
607 self.pos1 = self.origin;
608 self.pos2 = self.angles;
610 self.idle_aim = '0 0 0';
611 self.turret_firecheckfunc = walker_firecheck;
612 self.turret_firefunc = walker_attack;
613 self.turret_postthink = walker_postthink;
615 if (self.target != "")
617 e = find(world,targetname,self.target);
620 dprint("Initital waypoint for walker does NOT exsist, fix your map!\n");
624 if (e.classname != "turret_checkpoint")
625 dprint("Warning: not a turrret path\n");
628 self.pathcurrent = WALKER_PATH(self.origin,e.origin);
635 void spawnfunc_turret_walker()
637 g_turrets_common_precash();
639 precache_model ("models/turrets/walker_head_minigun.md3");
640 precache_model ("models/turrets/walker_body.md3");
641 precache_model ( "models/turrets/rocket.md3");
642 precache_sound ( "weapons/rocket_impact.wav" );
644 self.think = turret_walker_dinit;
645 self.nextthink = time + 0.5;