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, CHAN_WEAPON, "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 void walker_move_path()
264 // Are we close enougth to a path node to switch to the next?
265 if (vlen(self.origin - self.pathcurrent.origin) < 64)
266 if (self.pathcurrent.path_next == world)
268 // Path endpoint reached
269 pathlib_deletepath(self.pathcurrent.owner);
270 self.pathcurrent = world;
274 if (self.pathgoal.use)
277 if (self.pathgoal.enemy)
279 self.pathcurrent = WALKER_PATH(self.pathgoal.origin,self.pathgoal.enemy.origin);
280 self.pathgoal = self.pathgoal.enemy;
284 self.pathgoal = world;
287 self.pathcurrent = self.pathcurrent.path_next;
289 self.moveto = self.pathcurrent.origin;
290 self.steerto = steerlib_attract2(self.moveto,0.5,500,0.95);
291 walker_move_to(self.moveto, 0);
299 void walker_postthink()
301 fixedmakevectors(self.angles);
303 if (self.spawnflags & TSF_NO_PATHBREAK && self.pathcurrent)
305 else if (self.enemy == world)
311 if(self.enemy_last_time != 0)
313 if(vlen(self.origin - self.enemy_last_loc) < 128 || time - self.enemy_last_time > 10)
314 self.enemy_last_time = 0;
316 walker_move_to(self.enemy_last_loc, 0);
320 if(self.animflag != ANIM_NO)
322 traceline(self.origin + '0 0 64', self.origin + '0 0 64' + v_forward * 128, MOVE_NORMAL, self);
324 if(trace_fraction != 1.0)
325 self.tur_head.idletime = -1337;
328 traceline(trace_endpos, trace_endpos - '0 0 256', MOVE_NORMAL, self);
329 if(trace_fraction == 1.0)
330 self.tur_head.idletime = -1337;
333 if(self.tur_head.idletime == -1337)
335 self.moveto = self.origin + randomvec() * 256;
336 self.tur_head.idletime = 0;
339 self.moveto = self.moveto * 0.9 + ((self.origin + v_forward * 500) + randomvec() * 400) * 0.1;
340 self.moveto_z = self.origin_z + 64;
341 walker_move_to(self.moveto, 0);
344 if(self.idletime < time)
348 self.idletime = time + 1 + random() * 5;
349 self.moveto = self.origin;
350 self.animflag = ANIM_NO;
354 self.animflag = ANIM_WALK;
355 self.idletime = time + 4 + random() * 2;
356 self.moveto = self.origin + randomvec() * 256;
357 self.tur_head.moveto = self.moveto;
358 self.tur_head.idletime = 0;
366 if (self.tur_dist_enemy < autocvar_g_turrets_unit_walker_std_meele_range && self.animflag != ANIM_MEELE)
370 wish_angle = angleofs(self, self.enemy);
371 if (self.animflag != ANIM_SWIM)
372 if (fabs(wish_angle_y) < 15)
374 self.moveto = self.enemy.origin;
375 self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
376 self.animflag = ANIM_MEELE;
379 else if (self.tur_head.attack_finished_single < time)
381 if(self.tur_head.shot_volly)
383 self.animflag = ANIM_NO;
385 self.tur_head.shot_volly = self.tur_head.shot_volly -1;
386 if(self.tur_head.shot_volly == 0)
387 self.tur_head.attack_finished_single = time + autocvar_g_turrets_unit_walker_std_rocket_refire;
389 self.tur_head.attack_finished_single = time + 0.2;
391 if(self.tur_head.shot_volly > 1)
392 walker_fire_rocket(gettaginfo(self, gettagindex(self, "tag_rocket01")));
394 walker_fire_rocket(gettaginfo(self, gettagindex(self, "tag_rocket02")));
398 if (self.tur_dist_enemy > autocvar_g_turrets_unit_walker_std_rockets_range_min)
399 if (self.tur_dist_enemy < autocvar_g_turrets_unit_walker_std_rockets_range)
400 self.tur_head.shot_volly = 4;
405 if (self.animflag != ANIM_MEELE)
406 walker_move_to(self.enemy.origin, self.tur_dist_enemy);
410 //if(self.animflag != ANIM_NO)
416 real_angle = vectoangles(self.steerto) - self.angles;
417 vz = self.velocity_z;
419 switch (self.animflag)
422 movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop);
426 turny = autocvar_g_turrets_unit_walker_turn;
427 movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop);
431 turny = autocvar_g_turrets_unit_walker_turn_walk;
432 movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_walk, 0.6);
436 turny = autocvar_g_turrets_unit_walker_turn_run;
437 movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_run, 0.6);
441 turny = autocvar_g_turrets_unit_walker_turn_strafe;
442 movelib_move_simple(v_right * -1, autocvar_g_turrets_unit_walker_speed_walk, 0.8);
446 turny = autocvar_g_turrets_unit_walker_turn_strafe;
447 movelib_move_simple(v_right, autocvar_g_turrets_unit_walker_speed_walk, 0.8);
451 self.velocity += '0 0 1' * autocvar_g_turrets_unit_walker_speed_jump;
458 if(self.frame != ANIM_PAIN)
459 defer(0.25, walker_setnoanim);
464 if(self.frame != ANIM_MEELE)
466 defer(0.41, walker_setnoanim);
467 defer(0.21, walker_meele_do_dmg);
470 movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop);
474 turny = autocvar_g_turrets_unit_walker_turn_swim;
475 turnx = autocvar_g_turrets_unit_walker_turn_swim;
477 self.angles_x += bound(-10, shortangle_f(real_angle_x, self.angles_x), 10);
478 movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_swim, 0.3);
479 vz = self.velocity_z + sin(time * 4) * 8;
483 turny = autocvar_g_turrets_unit_walker_turn_walk;
484 movelib_move_simple(v_forward ,autocvar_g_turrets_unit_walker_speed_roam, 0.5);
490 turny = bound( turny * -1, shortangle_f(real_angle_y, self.angles_y), turny );
491 self.angles_y += turny;
496 turnx = bound( turnx * -1, shortangle_f(real_angle_x, self.angles_x), turnx );
497 self.angles_x += turnx;
500 self.velocity_z = vz;
504 if(self.origin != self.oldorigin)
505 self.SendFlags |= TNSF_MOVE;
507 self.oldorigin = self.origin;
508 turrets_setframe(self.animflag, FALSE);
514 sound (self, CHAN_WEAPON, "weapons/uzi_fire.wav", VOL_BASE, ATTN_NORM);
515 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);
516 endFireBallisticBullet();
517 pointparticles(particleeffectnum("laser_muzzleflash"), self.tur_shotorg, self.tur_shotdir_updated * 1000, 1);
521 void walker_respawnhook()
525 // Respawn is called & first spawn to, to set team. need to make sure we do not move the initial spawn.
526 if(self.movetype != MOVETYPE_WALK)
529 setorigin(self, self.pos1);
530 self.angles = self.pos2;
532 if (self.target != "")
534 e = find(world,targetname,self.target);
537 dprint("Warning! initital waypoint for Walker does NOT exsist!\n");
541 if (e.classname != "turret_checkpoint")
542 dprint("Warning: not a turrret path\n");
545 self.pathcurrent = WALKER_PATH(self.origin,e.origin);
551 void walker_diehook()
553 if (self.pathcurrent)
554 pathlib_deletepath(self.pathcurrent.owner);
556 self.pathcurrent = world;
559 void turret_walker_dinit()
564 if (self.netname == "") self.netname = "Walker Turret";
566 self.ammo_flags = TFL_AMMO_BULLETS | TFL_AMMO_RECHARGE | TFL_AMMO_RECIVE;
567 self.turrcaps_flags = TFL_TURRCAPS_PLAYERKILL | TFL_TURRCAPS_MOVE ;
568 self.aim_flags = TFL_AIM_LEAD;
570 if (autocvar_g_antilag_bullets)
571 self.turrcaps_flags |= TFL_TURRCAPS_HITSCAN;
573 self.aim_flags |= TFL_AIM_SHOTTIMECOMPENSATE;
576 self.turret_respawnhook = walker_respawnhook;
577 self.turret_diehook = walker_diehook;
580 if (turret_stdproc_init("walker_std", "models/turrets/walker_body.md3", "models/turrets/walker_head_minigun.md3", TID_WALKER) == 0)
586 self.damage_flags |= TFL_DMG_DEATH_NOGIBS;
587 self.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
588 self.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
590 self.iscreature = TRUE;
591 self.movetype = MOVETYPE_WALK;
592 self.solid = SOLID_SLIDEBOX;
593 self.takedamage = DAMAGE_AIM;
596 setsize(self, WALKER_MIN, WALKER_MAX);
598 setorigin(self, self.origin);
599 tracebox(self.origin + '0 0 128', self.mins,self.maxs,self.origin - '0 0 10000', MOVE_NORMAL, self);
600 setorigin(self, trace_endpos + '0 0 4');
601 self.pos1 = self.origin;
602 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 self.pathcurrent = WALKER_PATH(self.origin,e.origin);
629 void spawnfunc_turret_walker()
631 g_turrets_common_precash();
633 precache_model ("models/turrets/walker_head_minigun.md3");
634 precache_model ("models/turrets/walker_body.md3");
635 precache_model ( "models/turrets/rocket.md3");
636 precache_sound ( "weapons/rocket_impact.wav" );
638 self.think = turret_walker_dinit;
639 self.nextthink = time + 0.5;