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_WALKER_MEELE,'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()
54 if (self.event_damage != SUB_Null)
56 self.event_damage = SUB_Null;
57 self.think = walker_rocket_explode;
58 self.nextthink = time;
62 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_WALKER_ROCKET, world);
67 void walker_rocket_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce)
69 self.health = self.health - damage;
70 self.velocity = self.velocity + vforce;
72 walker_rocket_explode();
75 #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)
76 void walker_rocket_loop();
77 void walker_rocket_think()
84 self.nextthink = time;
86 edist = vlen(self.enemy.origin - self.origin);
88 // Simulate crude guidance
92 self.tur_shotorg = randomvec() * min(edist, 64);
94 self.tur_shotorg = randomvec() * min(edist, 256);
96 self.cnt = time + 0.5;
100 self.tur_shotorg = '0 0 0';
102 if (self.tur_health < time)
104 self.think = walker_rocket_explode;
105 self.nextthink = time;
109 if (self.shot_dmg != 1337 && random() < 0.01)
111 walker_rocket_loop();
115 m_speed = vlen(self.velocity);
117 // Enemy dead? just keep on the current heading then.
118 if (self.enemy == world || self.enemy.deadflag != DEAD_NO)
123 itime = max(edist / m_speed, 1);
124 newdir = steerlib_pull(self.enemy.origin + self.tur_shotorg);
127 newdir = normalize(self.velocity);
132 void walker_rocket_loop3()
135 self.nextthink = time;
137 if (self.tur_health < time)
139 self.think = walker_rocket_explode;
143 if (vlen(self.origin - self.tur_shotorg) < 100 )
145 self.think = walker_rocket_think;
149 newdir = steerlib_pull(self.tur_shotorg);
152 self.angles = vectoangles(self.velocity);
155 void walker_rocket_loop2()
159 self.nextthink = time;
161 if (self.tur_health < time)
163 self.think = walker_rocket_explode;
167 if (vlen(self.origin - self.tur_shotorg) < 100 )
169 self.tur_shotorg = self.origin - '0 0 200';
170 self.think = walker_rocket_loop3;
174 newdir = steerlib_pull(self.tur_shotorg);
178 void walker_rocket_loop()
180 self.nextthink = time;
181 self.tur_shotorg = self.origin + '0 0 300';
182 self.think = walker_rocket_loop2;
183 self.shot_dmg = 1337;
186 void walker_fire_rocket(vector org)
190 fixedmakevectors(self.angles);
195 setorigin(rocket, org);
197 sound (self, CH_WEAPON_A, "weapons/hagar_fire.wav", VOL_BASE, ATTN_NORM);
198 setsize (rocket, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
200 rocket.classname = "walker_rocket";
202 rocket.bot_dodge = TRUE;
203 rocket.bot_dodgerating = 50;
204 rocket.takedamage = DAMAGE_YES;
205 rocket.damageforcescale = 2;
207 rocket.tur_shotorg = randomvec() * 512;
208 rocket.cnt = time + 1;
209 rocket.enemy = self.enemy;
212 rocket.think = walker_rocket_loop;
214 rocket.think = walker_rocket_think;
216 rocket.event_damage = walker_rocket_damage;
218 rocket.nextthink = time;
219 rocket.movetype = MOVETYPE_FLY;
220 rocket.velocity = normalize((v_forward + v_up * 0.5) + (randomvec() * 0.2)) * autocvar_g_turrets_unit_walker_std_rocket_speed;
221 rocket.angles = vectoangles(rocket.velocity);
222 rocket.touch = walker_rocket_explode;
223 rocket.flags = FL_PROJECTILE;
224 rocket.solid = SOLID_BBOX;
225 rocket.tur_health = time + 9;
227 CSQCProjectile(rocket, FALSE, PROJECTILE_ROCKET, FALSE); // no culling, has fly sound
230 .vector enemy_last_loc;
231 .float enemy_last_time;
232 void walker_move_to(vector _target, float _dist)
234 switch (self.waterlevel)
236 case WATERLEVEL_NONE:
238 self.animflag = ANIM_RUN;
240 self.animflag = ANIM_WALK;
241 case WATERLEVEL_WETFEET:
242 case WATERLEVEL_SWIMMING:
243 if (self.animflag != ANIM_SWIM)
244 self.animflag = ANIM_WALK;
246 self.animflag = ANIM_SWIM;
248 case WATERLEVEL_SUBMERGED:
249 self.animflag = ANIM_SWIM;
252 self.moveto = _target;
253 self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
257 self.enemy_last_loc = _target;
258 self.enemy_last_time = time;
262 //#define WALKER_FANCYPATHING
264 void walker_move_path()
266 #ifdef WALKER_FANCYPATHING
267 // Are we close enougth to a path node to switch to the next?
268 if (vlen(self.origin - self.pathcurrent.origin) < 64)
269 if (self.pathcurrent.path_next == world)
271 // Path endpoint reached
272 pathlib_deletepath(self.pathcurrent.owner);
273 self.pathcurrent = world;
277 if (self.pathgoal.use)
280 if (self.pathgoal.enemy)
282 self.pathcurrent = WALKER_PATH(self.pathgoal.origin,self.pathgoal.enemy.origin);
283 self.pathgoal = self.pathgoal.enemy;
287 self.pathgoal = world;
290 self.pathcurrent = self.pathcurrent.path_next;
292 self.moveto = self.pathcurrent.origin;
293 self.steerto = steerlib_attract2(self.moveto,0.5,500,0.95);
294 walker_move_to(self.moveto, 0);
297 if (vlen(self.origin - self.pathcurrent.origin) < 64)
298 self.pathcurrent = self.pathcurrent.enemy;
300 if(!self.pathcurrent)
303 self.moveto = self.pathcurrent.origin;
304 self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
305 walker_move_to(self.moveto, 0);
313 void walker_postthink()
315 fixedmakevectors(self.angles);
317 if (self.spawnflags & TSF_NO_PATHBREAK && self.pathcurrent)
319 else if (self.enemy == world)
325 if(self.enemy_last_time != 0)
327 if(vlen(self.origin - self.enemy_last_loc) < 128 || time - self.enemy_last_time > 10)
328 self.enemy_last_time = 0;
330 walker_move_to(self.enemy_last_loc, 0);
334 if(self.animflag != ANIM_NO)
336 traceline(self.origin + '0 0 64', self.origin + '0 0 64' + v_forward * 128, MOVE_NORMAL, self);
338 if(trace_fraction != 1.0)
339 self.tur_head.idletime = -1337;
342 traceline(trace_endpos, trace_endpos - '0 0 256', MOVE_NORMAL, self);
343 if(trace_fraction == 1.0)
344 self.tur_head.idletime = -1337;
347 if(self.tur_head.idletime == -1337)
349 self.moveto = self.origin + randomvec() * 256;
350 self.tur_head.idletime = 0;
353 self.moveto = self.moveto * 0.9 + ((self.origin + v_forward * 500) + randomvec() * 400) * 0.1;
354 self.moveto_z = self.origin_z + 64;
355 walker_move_to(self.moveto, 0);
358 if(self.idletime < time)
360 if(random() < 0.5 || !(self.spawnflags & TSL_ROAM))
362 self.idletime = time + 1 + random() * 5;
363 self.moveto = self.origin;
364 self.animflag = ANIM_NO;
368 self.animflag = ANIM_WALK;
369 self.idletime = time + 4 + random() * 2;
370 self.moveto = self.origin + randomvec() * 256;
371 self.tur_head.moveto = self.moveto;
372 self.tur_head.idletime = 0;
380 if (self.tur_dist_enemy < autocvar_g_turrets_unit_walker_std_meele_range && self.animflag != ANIM_MEELE)
384 wish_angle = angleofs(self, self.enemy);
385 if (self.animflag != ANIM_SWIM)
386 if (fabs(wish_angle_y) < 15)
388 self.moveto = self.enemy.origin;
389 self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
390 self.animflag = ANIM_MEELE;
393 else if (self.tur_head.attack_finished_single < time)
395 if(self.tur_head.shot_volly)
397 self.animflag = ANIM_NO;
399 self.tur_head.shot_volly = self.tur_head.shot_volly -1;
400 if(self.tur_head.shot_volly == 0)
401 self.tur_head.attack_finished_single = time + autocvar_g_turrets_unit_walker_std_rocket_refire;
403 self.tur_head.attack_finished_single = time + 0.2;
405 if(self.tur_head.shot_volly > 1)
406 walker_fire_rocket(gettaginfo(self, gettagindex(self, "tag_rocket01")));
408 walker_fire_rocket(gettaginfo(self, gettagindex(self, "tag_rocket02")));
412 if (self.tur_dist_enemy > autocvar_g_turrets_unit_walker_std_rockets_range_min)
413 if (self.tur_dist_enemy < autocvar_g_turrets_unit_walker_std_rockets_range)
414 self.tur_head.shot_volly = 4;
419 if (self.animflag != ANIM_MEELE)
420 walker_move_to(self.enemy.origin, self.tur_dist_enemy);
424 //if(self.animflag != ANIM_NO)
430 real_angle = vectoangles(self.steerto) - self.angles;
431 vz = self.velocity_z;
433 switch (self.animflag)
436 movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop);
440 turny = autocvar_g_turrets_unit_walker_turn;
441 movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop);
445 turny = autocvar_g_turrets_unit_walker_turn_walk;
446 movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_walk, 0.6);
450 turny = autocvar_g_turrets_unit_walker_turn_run;
451 movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_run, 0.6);
455 turny = autocvar_g_turrets_unit_walker_turn_strafe;
456 movelib_move_simple(v_right * -1, autocvar_g_turrets_unit_walker_speed_walk, 0.8);
460 turny = autocvar_g_turrets_unit_walker_turn_strafe;
461 movelib_move_simple(v_right, autocvar_g_turrets_unit_walker_speed_walk, 0.8);
465 self.velocity += '0 0 1' * autocvar_g_turrets_unit_walker_speed_jump;
472 if(self.frame != ANIM_PAIN)
473 defer(0.25, walker_setnoanim);
478 if(self.frame != ANIM_MEELE)
480 defer(0.41, walker_setnoanim);
481 defer(0.21, walker_meele_do_dmg);
484 movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop);
488 turny = autocvar_g_turrets_unit_walker_turn_swim;
489 turnx = autocvar_g_turrets_unit_walker_turn_swim;
491 self.angles_x += bound(-10, shortangle_f(real_angle_x, self.angles_x), 10);
492 movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_swim, 0.3);
493 vz = self.velocity_z + sin(time * 4) * 8;
497 turny = autocvar_g_turrets_unit_walker_turn_walk;
498 movelib_move_simple(v_forward ,autocvar_g_turrets_unit_walker_speed_roam, 0.5);
504 turny = bound( turny * -1, shortangle_f(real_angle_y, self.angles_y), turny );
505 self.angles_y += turny;
510 turnx = bound( turnx * -1, shortangle_f(real_angle_x, self.angles_x), turnx );
511 self.angles_x += turnx;
514 self.velocity_z = vz;
518 if(self.origin != self.oldorigin)
519 self.SendFlags |= TNSF_MOVE;
521 self.oldorigin = self.origin;
522 turrets_setframe(self.animflag, FALSE);
528 sound (self, CH_WEAPON_A, "weapons/uzi_fire.wav", VOL_BASE, ATTN_NORM);
529 fireBallisticBullet (self.tur_shotorg, self.tur_shotdir_updated, self.shot_spread, self.shot_speed, 5, self.shot_dmg, 0, self.shot_force, DEATH_TURRET_WALKER_GUN, 0, 1, autocvar_g_balance_uzi_bulletconstant);
530 endFireBallisticBullet();
531 pointparticles(particleeffectnum("laser_muzzleflash"), self.tur_shotorg, self.tur_shotdir_updated * 1000, 1);
535 void walker_respawnhook()
539 // Respawn is called & first spawn to, to set team. need to make sure we do not move the initial spawn.
540 if(self.movetype != MOVETYPE_WALK)
543 setorigin(self, self.pos1);
544 self.angles = self.pos2;
546 if (self.target != "")
548 e = find(world,targetname,self.target);
551 dprint("Warning! initital waypoint for Walker does NOT exsist!\n");
555 if (e.classname != "turret_checkpoint")
556 dprint("Warning: not a turrret path\n");
559 self.pathcurrent = WALKER_PATH(self.origin,e.origin);
565 void walker_diehook()
567 #ifdef self.pathcurrent
568 if (self.pathcurrent)
569 pathlib_deletepath(self.pathcurrent.owner);
572 self.pathcurrent = world;
575 void turret_walker_dinit()
580 if (self.netname == "") self.netname = "Walker Turret";
582 self.ammo_flags = TFL_AMMO_BULLETS | TFL_AMMO_RECHARGE | TFL_AMMO_RECIVE;
583 self.turrcaps_flags = TFL_TURRCAPS_PLAYERKILL | TFL_TURRCAPS_MOVE ;
584 self.aim_flags = TFL_AIM_LEAD;
586 if (autocvar_g_antilag_bullets)
587 self.turrcaps_flags |= TFL_TURRCAPS_HITSCAN;
589 self.aim_flags |= TFL_AIM_SHOTTIMECOMPENSATE;
592 self.turret_respawnhook = walker_respawnhook;
593 self.turret_diehook = walker_diehook;
596 if (turret_stdproc_init("walker_std", "models/turrets/walker_body.md3", "models/turrets/walker_head_minigun.md3", TID_WALKER) == 0)
602 self.damage_flags |= TFL_DMG_DEATH_NOGIBS;
603 self.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
604 self.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
606 self.iscreature = TRUE;
607 self.movetype = MOVETYPE_WALK;
608 self.solid = SOLID_SLIDEBOX;
609 self.takedamage = DAMAGE_AIM;
612 setsize(self, WALKER_MIN, WALKER_MAX);
614 setorigin(self, self.origin);
615 tracebox(self.origin + '0 0 128', self.mins,self.maxs,self.origin - '0 0 10000', MOVE_NORMAL, self);
616 setorigin(self, trace_endpos + '0 0 4');
617 self.pos1 = self.origin;
618 self.pos2 = self.angles;
620 self.idle_aim = '0 0 0';
621 self.turret_firecheckfunc = walker_firecheck;
622 self.turret_firefunc = walker_attack;
623 self.turret_postthink = walker_postthink;
625 if (self.target != "")
627 e = find(world, targetname, self.target);
630 dprint("Initital waypoint for walker does NOT exsist, fix your map!\n");
634 if (e.classname != "turret_checkpoint")
635 dprint("Warning: not a turrret path\n");
638 #ifdef WALKER_FANCYPATHING
639 self.pathcurrent = WALKER_PATH(self.origin, e.origin);
642 self.pathcurrent = e;
649 void spawnfunc_turret_walker()
651 g_turrets_common_precash();
653 precache_model ("models/turrets/walker_head_minigun.md3");
654 precache_model ("models/turrets/walker_body.md3");
655 precache_model ( "models/turrets/rocket.md3");
656 precache_sound ( "weapons/rocket_impact.wav" );
658 self.think = turret_walker_dinit;
659 self.nextthink = time + 0.5;