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 RadiusDamage (self, self.owner, autocvar_g_turrets_unit_walker_std_rocket_dmg, 0, autocvar_g_turrets_unit_walker_std_rocket_radius, self, autocvar_g_turrets_unit_walker_std_rocket_force, DEATH_TURRET_WALKER_ROCKET, world);
58 void walker_rocket_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce)
60 self.health = self.health - damage;
61 self.velocity = self.velocity + vforce;
64 W_PrepareExplosionByDamage(self.owner, walker_rocket_explode);
67 #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)
68 void walker_rocket_loop();
69 void walker_rocket_think()
76 self.nextthink = time;
78 edist = vlen(self.enemy.origin - self.origin);
80 // Simulate crude guidance
84 self.tur_shotorg = randomvec() * min(edist, 64);
86 self.tur_shotorg = randomvec() * min(edist, 256);
88 self.cnt = time + 0.5;
92 self.tur_shotorg = '0 0 0';
94 if (self.tur_health < time)
96 self.think = walker_rocket_explode;
97 self.nextthink = time;
101 if (self.shot_dmg != 1337 && random() < 0.01)
103 walker_rocket_loop();
107 m_speed = vlen(self.velocity);
109 // Enemy dead? just keep on the current heading then.
110 if (self.enemy == world || self.enemy.deadflag != DEAD_NO)
115 itime = max(edist / m_speed, 1);
116 newdir = steerlib_pull(self.enemy.origin + self.tur_shotorg);
119 newdir = normalize(self.velocity);
124 void walker_rocket_loop3()
127 self.nextthink = time;
129 if (self.tur_health < time)
131 self.think = walker_rocket_explode;
135 if (vlen(self.origin - self.tur_shotorg) < 100 )
137 self.think = walker_rocket_think;
141 newdir = steerlib_pull(self.tur_shotorg);
144 self.angles = vectoangles(self.velocity);
147 void walker_rocket_loop2()
151 self.nextthink = time;
153 if (self.tur_health < time)
155 self.think = walker_rocket_explode;
159 if (vlen(self.origin - self.tur_shotorg) < 100 )
161 self.tur_shotorg = self.origin - '0 0 200';
162 self.think = walker_rocket_loop3;
166 newdir = steerlib_pull(self.tur_shotorg);
170 void walker_rocket_loop()
172 self.nextthink = time;
173 self.tur_shotorg = self.origin + '0 0 300';
174 self.think = walker_rocket_loop2;
175 self.shot_dmg = 1337;
178 void walker_fire_rocket(vector org)
182 fixedmakevectors(self.angles);
187 setorigin(rocket, org);
189 sound (self, CH_WEAPON_A, "weapons/hagar_fire.wav", VOL_BASE, ATTN_NORM);
190 setsize (rocket, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
192 rocket.classname = "walker_rocket";
194 rocket.bot_dodge = TRUE;
195 rocket.bot_dodgerating = 50;
196 rocket.takedamage = DAMAGE_YES;
197 rocket.damageforcescale = 2;
199 rocket.tur_shotorg = randomvec() * 512;
200 rocket.cnt = time + 1;
201 rocket.enemy = self.enemy;
204 rocket.think = walker_rocket_loop;
206 rocket.think = walker_rocket_think;
208 rocket.event_damage = walker_rocket_damage;
210 rocket.nextthink = time;
211 rocket.movetype = MOVETYPE_FLY;
212 rocket.velocity = normalize((v_forward + v_up * 0.5) + (randomvec() * 0.2)) * autocvar_g_turrets_unit_walker_std_rocket_speed;
213 rocket.angles = vectoangles(rocket.velocity);
214 rocket.touch = walker_rocket_explode;
215 rocket.flags = FL_PROJECTILE;
216 rocket.solid = SOLID_BBOX;
217 rocket.tur_health = time + 9;
219 CSQCProjectile(rocket, FALSE, PROJECTILE_ROCKET, FALSE); // no culling, has fly sound
222 .vector enemy_last_loc;
223 .float enemy_last_time;
224 void walker_move_to(vector _target, float _dist)
226 switch (self.waterlevel)
228 case WATERLEVEL_NONE:
230 self.animflag = ANIM_RUN;
232 self.animflag = ANIM_WALK;
233 case WATERLEVEL_WETFEET:
234 case WATERLEVEL_SWIMMING:
235 if (self.animflag != ANIM_SWIM)
236 self.animflag = ANIM_WALK;
238 self.animflag = ANIM_SWIM;
240 case WATERLEVEL_SUBMERGED:
241 self.animflag = ANIM_SWIM;
244 self.moveto = _target;
245 self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
249 self.enemy_last_loc = _target;
250 self.enemy_last_time = time;
254 //#define WALKER_FANCYPATHING
256 void walker_move_path()
258 #ifdef WALKER_FANCYPATHING
259 // Are we close enougth to a path node to switch to the next?
260 if (vlen(self.origin - self.pathcurrent.origin) < 64)
261 if (self.pathcurrent.path_next == world)
263 // Path endpoint reached
264 pathlib_deletepath(self.pathcurrent.owner);
265 self.pathcurrent = world;
269 if (self.pathgoal.use)
272 if (self.pathgoal.enemy)
274 self.pathcurrent = WALKER_PATH(self.pathgoal.origin,self.pathgoal.enemy.origin);
275 self.pathgoal = self.pathgoal.enemy;
279 self.pathgoal = world;
282 self.pathcurrent = self.pathcurrent.path_next;
284 self.moveto = self.pathcurrent.origin;
285 self.steerto = steerlib_attract2(self.moveto,0.5,500,0.95);
286 walker_move_to(self.moveto, 0);
289 if (vlen(self.origin - self.pathcurrent.origin) < 64)
290 self.pathcurrent = self.pathcurrent.enemy;
292 if(!self.pathcurrent)
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);
302 void walker_postthink()
304 fixedmakevectors(self.angles);
306 if (self.spawnflags & TSF_NO_PATHBREAK && self.pathcurrent)
308 else if (self.enemy == world)
314 if(self.enemy_last_time != 0)
316 if(vlen(self.origin - self.enemy_last_loc) < 128 || time - self.enemy_last_time > 10)
317 self.enemy_last_time = 0;
319 walker_move_to(self.enemy_last_loc, 0);
323 if(self.animflag != ANIM_NO)
325 traceline(self.origin + '0 0 64', self.origin + '0 0 64' + v_forward * 128, MOVE_NORMAL, self);
327 if(trace_fraction != 1.0)
328 self.tur_head.idletime = -1337;
331 traceline(trace_endpos, trace_endpos - '0 0 256', MOVE_NORMAL, self);
332 if(trace_fraction == 1.0)
333 self.tur_head.idletime = -1337;
336 if(self.tur_head.idletime == -1337)
338 self.moveto = self.origin + randomvec() * 256;
339 self.tur_head.idletime = 0;
342 self.moveto = self.moveto * 0.9 + ((self.origin + v_forward * 500) + randomvec() * 400) * 0.1;
343 self.moveto_z = self.origin_z + 64;
344 walker_move_to(self.moveto, 0);
347 if(self.idletime < time)
349 if(random() < 0.5 || !(self.spawnflags & TSL_ROAM))
351 self.idletime = time + 1 + random() * 5;
352 self.moveto = self.origin;
353 self.animflag = ANIM_NO;
357 self.animflag = ANIM_WALK;
358 self.idletime = time + 4 + random() * 2;
359 self.moveto = self.origin + randomvec() * 256;
360 self.tur_head.moveto = self.moveto;
361 self.tur_head.idletime = 0;
369 if (self.tur_dist_enemy < autocvar_g_turrets_unit_walker_std_meele_range && self.animflag != ANIM_MEELE)
373 wish_angle = angleofs(self, self.enemy);
374 if (self.animflag != ANIM_SWIM)
375 if (fabs(wish_angle_y) < 15)
377 self.moveto = self.enemy.origin;
378 self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
379 self.animflag = ANIM_MEELE;
382 else if (self.tur_head.attack_finished_single < time)
384 if(self.tur_head.shot_volly)
386 self.animflag = ANIM_NO;
388 self.tur_head.shot_volly = self.tur_head.shot_volly -1;
389 if(self.tur_head.shot_volly == 0)
390 self.tur_head.attack_finished_single = time + autocvar_g_turrets_unit_walker_std_rocket_refire;
392 self.tur_head.attack_finished_single = time + 0.2;
394 if(self.tur_head.shot_volly > 1)
395 walker_fire_rocket(gettaginfo(self, gettagindex(self, "tag_rocket01")));
397 walker_fire_rocket(gettaginfo(self, gettagindex(self, "tag_rocket02")));
401 if (self.tur_dist_enemy > autocvar_g_turrets_unit_walker_std_rockets_range_min)
402 if (self.tur_dist_enemy < autocvar_g_turrets_unit_walker_std_rockets_range)
403 self.tur_head.shot_volly = 4;
408 if (self.animflag != ANIM_MEELE)
409 walker_move_to(self.enemy.origin, self.tur_dist_enemy);
413 //if(self.animflag != ANIM_NO)
419 real_angle = vectoangles(self.steerto) - self.angles;
420 vz = self.velocity_z;
422 switch (self.animflag)
425 movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop);
429 turny = autocvar_g_turrets_unit_walker_turn;
430 movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop);
434 turny = autocvar_g_turrets_unit_walker_turn_walk;
435 movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_walk, 0.6);
439 turny = autocvar_g_turrets_unit_walker_turn_run;
440 movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_run, 0.6);
444 turny = autocvar_g_turrets_unit_walker_turn_strafe;
445 movelib_move_simple(v_right * -1, autocvar_g_turrets_unit_walker_speed_walk, 0.8);
449 turny = autocvar_g_turrets_unit_walker_turn_strafe;
450 movelib_move_simple(v_right, autocvar_g_turrets_unit_walker_speed_walk, 0.8);
454 self.velocity += '0 0 1' * autocvar_g_turrets_unit_walker_speed_jump;
461 if(self.frame != ANIM_PAIN)
462 defer(0.25, walker_setnoanim);
467 if(self.frame != ANIM_MEELE)
469 defer(0.41, walker_setnoanim);
470 defer(0.21, walker_meele_do_dmg);
473 movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop);
477 turny = autocvar_g_turrets_unit_walker_turn_swim;
478 turnx = autocvar_g_turrets_unit_walker_turn_swim;
480 self.angles_x += bound(-10, shortangle_f(real_angle_x, self.angles_x), 10);
481 movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_swim, 0.3);
482 vz = self.velocity_z + sin(time * 4) * 8;
486 turny = autocvar_g_turrets_unit_walker_turn_walk;
487 movelib_move_simple(v_forward ,autocvar_g_turrets_unit_walker_speed_roam, 0.5);
493 turny = bound( turny * -1, shortangle_f(real_angle_y, self.angles_y), turny );
494 self.angles_y += turny;
499 turnx = bound( turnx * -1, shortangle_f(real_angle_x, self.angles_x), turnx );
500 self.angles_x += turnx;
503 self.velocity_z = vz;
507 if(self.origin != self.oldorigin)
508 self.SendFlags |= TNSF_MOVE;
510 self.oldorigin = self.origin;
511 turrets_setframe(self.animflag, FALSE);
516 sound (self, CH_WEAPON_A, "weapons/uzi_fire.wav", VOL_BASE, ATTN_NORM);
517 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);
518 endFireBallisticBullet();
519 pointparticles(particleeffectnum("laser_muzzleflash"), self.tur_shotorg, self.tur_shotdir_updated * 1000, 1);
523 void walker_respawnhook()
527 // Respawn is called & first spawn to, to set team. need to make sure we do not move the initial spawn.
528 if(self.movetype != MOVETYPE_WALK)
531 setorigin(self, self.pos1);
532 self.angles = self.pos2;
534 if (self.target != "")
536 e = find(world, targetname, self.target);
539 dprint("Warning! initital waypoint for Walker does NOT exsist!\n");
543 if (e.classname != "turret_checkpoint")
544 dprint("Warning: not a turrret path\n");
547 #ifdef WALKER_FANCYPATHING
548 self.pathcurrent = WALKER_PATH(self.origin, e.origin);
551 self.pathcurrent = e;
557 void walker_diehook()
559 #ifdef WALKER_FANCYPATHING
560 if (self.pathcurrent)
561 pathlib_deletepath(self.pathcurrent.owner);
563 self.pathcurrent = world;
566 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)
591 setsize(self, WALKER_MIN, WALKER_MAX);
592 self.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
593 self.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
594 self.iscreature = TRUE;
595 self.damagedbycontents = TRUE;
596 self.movetype = MOVETYPE_WALK;
597 self.solid = SOLID_SLIDEBOX;
598 self.takedamage = DAMAGE_AIM;
599 setorigin(self, self.origin);
600 tracebox(self.origin + '0 0 128', self.mins, self.maxs, self.origin - '0 0 10000', MOVE_NORMAL, self);
601 setorigin(self, trace_endpos + '0 0 4');
602 self.pos1 = self.origin;
603 self.pos2 = self.angles;
604 self.idle_aim = '0 0 0';
605 self.turret_firecheckfunc = walker_firecheck;
606 self.turret_firefunc = walker_attack;
607 self.turret_postthink = walker_postthink;
609 if (self.target != "")
611 e = find(world, targetname, self.target);
614 dprint("Initital waypoint for walker does NOT exsist, fix your map!\n");
618 if (e.classname != "turret_checkpoint")
619 dprint("Warning: not a turrret path\n");
622 #ifdef WALKER_FANCYPATHING
623 self.pathcurrent = WALKER_PATH(self.origin, e.origin);
626 self.pathcurrent = e;
633 void spawnfunc_turret_walker()
635 g_turrets_common_precash();
637 precache_model ("models/turrets/walker_head_minigun.md3");
638 precache_model ("models/turrets/walker_body.md3");
639 precache_model ( "models/turrets/rocket.md3");
640 precache_sound ( "weapons/rocket_impact.wav" );
642 self.think = turret_walker_dinit;
643 self.nextthink = time + 0.5;