7 float autocvar_g_turrets_unit_walker_melee_damage;
8 float autocvar_g_turrets_unit_walker_melee_force;
9 float autocvar_g_turrets_unit_walker_melee_range;
10 float autocvar_g_turrets_unit_walker_rocket_damage;
11 float autocvar_g_turrets_unit_walker_rocket_radius;
12 float autocvar_g_turrets_unit_walker_rocket_force;
13 float autocvar_g_turrets_unit_walker_rocket_speed;
14 float autocvar_g_turrets_unit_walker_rocket_range;
15 float autocvar_g_turrets_unit_walker_rocket_range_min;
16 float autocvar_g_turrets_unit_walker_rocket_refire;
17 float autocvar_g_turrets_unit_walker_rocket_turnrate;
18 float autocvar_g_turrets_unit_walker_speed_stop;
19 float autocvar_g_turrets_unit_walker_speed_walk;
20 float autocvar_g_turrets_unit_walker_speed_run;
21 float autocvar_g_turrets_unit_walker_speed_jump;
22 float autocvar_g_turrets_unit_walker_speed_swim;
23 float autocvar_g_turrets_unit_walker_speed_roam;
24 float autocvar_g_turrets_unit_walker_turn;
25 float autocvar_g_turrets_unit_walker_turn_walk;
26 float autocvar_g_turrets_unit_walker_turn_strafe;
27 float autocvar_g_turrets_unit_walker_turn_swim;
28 float autocvar_g_turrets_unit_walker_turn_run;
30 const int ANIM_NO = 0;
31 const int ANIM_TURN = 1;
32 const int ANIM_WALK = 2;
33 const int ANIM_RUN = 3;
34 const int ANIM_STRAFE_L = 4;
35 const int ANIM_STRAFE_R = 5;
36 const int ANIM_JUMP = 6;
37 const int ANIM_LAND = 7;
38 const int ANIM_PAIN = 8;
39 const int ANIM_MELEE = 9;
40 const int ANIM_SWIM = 10;
41 const int ANIM_ROAM = 11;
46 #define WALKER_PATH(this, s, e) pathlib_astar(this, s, e)
48 bool walker_firecheck(entity this)
50 if (this.animflag == ANIM_MELEE)
53 return turret_firecheck(this);
56 void walker_melee_do_dmg(entity this)
61 makevectors(this.angles);
62 where = this.origin + v_forward * 128;
64 e = findradius(where,32);
67 if (turret_validate_target(this, e, this.target_validate_flags))
68 if (e != this && e.owner != this)
69 Damage(e, this, this, (autocvar_g_turrets_unit_walker_melee_damage), DEATH_TURRET_WALK_MELEE.m_id, '0 0 0', v_forward * (autocvar_g_turrets_unit_walker_melee_force));
75 void walker_setnoanim(entity this)
77 turrets_setframe(this, ANIM_NO, false);
78 this.animflag = this.frame;
80 void walker_rocket_explode(entity this)
82 RadiusDamage (this, this.owner, (autocvar_g_turrets_unit_walker_rocket_damage), 0, (autocvar_g_turrets_unit_walker_rocket_radius), this, NULL, (autocvar_g_turrets_unit_walker_rocket_force), DEATH_TURRET_WALK_ROCKET.m_id, NULL);
86 void walker_rocket_touch(entity this, entity toucher)
88 walker_rocket_explode(this);
91 void walker_rocket_damage(entity this, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce)
93 this.health = this.health - damage;
94 this.velocity = this.velocity + vforce;
97 W_PrepareExplosionByDamage(this, this.owner, walker_rocket_explode);
100 #define WALKER_ROCKET_MOVE(s) movelib_move_simple((s), newdir, (autocvar_g_turrets_unit_walker_rocket_speed), (autocvar_g_turrets_unit_walker_rocket_turnrate)); UpdateCSQCProjectile(s)
101 void walker_rocket_loop(entity this);
102 void walker_rocket_think(entity this)
109 this.nextthink = time;
111 edist = vlen(this.enemy.origin - this.origin);
113 // Simulate crude guidance
117 this.tur_shotorg = randomvec() * min(edist, 64);
119 this.tur_shotorg = randomvec() * min(edist, 256);
121 this.cnt = time + 0.5;
125 this.tur_shotorg = '0 0 0';
127 if (this.max_health < time)
129 setthink(this, walker_rocket_explode);
130 this.nextthink = time;
134 if (this.shot_dmg != 1337 && random() < 0.01)
136 walker_rocket_loop(this);
140 m_speed = vlen(this.velocity);
142 // Enemy dead? just keep on the current heading then.
143 if (this.enemy == NULL || IS_DEAD(this.enemy))
148 itime = max(edist / m_speed, 1);
149 newdir = steerlib_pull(this, this.enemy.origin + this.tur_shotorg);
152 newdir = normalize(this.velocity);
154 WALKER_ROCKET_MOVE(this);
157 void walker_rocket_loop3(entity this)
159 this.nextthink = time;
161 if (this.max_health < time)
163 setthink(this, walker_rocket_explode);
167 if(vdist(this.origin - this.tur_shotorg, <, 100))
169 setthink(this, walker_rocket_think);
173 vector newdir = steerlib_pull(this, this.tur_shotorg);
174 WALKER_ROCKET_MOVE(this);
176 this.angles = vectoangles(this.velocity);
179 void walker_rocket_loop2(entity this)
181 this.nextthink = time;
183 if (this.max_health < time)
185 setthink(this, walker_rocket_explode);
189 if(vdist(this.origin - this.tur_shotorg, <, 100))
191 this.tur_shotorg = this.origin - '0 0 200';
192 setthink(this, walker_rocket_loop3);
196 vector newdir = steerlib_pull(this, this.tur_shotorg);
197 WALKER_ROCKET_MOVE(this);
200 void walker_rocket_loop(entity this)
202 this.nextthink = time;
203 this.tur_shotorg = this.origin + '0 0 300';
204 setthink(this, walker_rocket_loop2);
205 this.shot_dmg = 1337;
208 void walker_fire_rocket(entity this, vector org)
210 fixedmakevectors(this.angles);
214 entity rocket = new(walker_rocket);
215 setorigin(rocket, org);
217 sound (this, CH_WEAPON_A, SND_HAGAR_FIRE, VOL_BASE, ATTEN_NORM);
218 setsize (rocket, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
221 rocket.bot_dodge = true;
222 rocket.bot_dodgerating = 50;
223 rocket.takedamage = DAMAGE_YES;
224 rocket.damageforcescale = 2;
226 rocket.tur_shotorg = randomvec() * 512;
227 rocket.cnt = time + 1;
228 rocket.enemy = this.enemy;
231 setthink(rocket, walker_rocket_loop);
233 setthink(rocket, walker_rocket_think);
235 rocket.event_damage = walker_rocket_damage;
237 rocket.nextthink = time;
238 set_movetype(rocket, MOVETYPE_FLY);
239 rocket.velocity = normalize((v_forward + v_up * 0.5) + (randomvec() * 0.2)) * (autocvar_g_turrets_unit_walker_rocket_speed);
240 rocket.angles = vectoangles(rocket.velocity);
241 settouch(rocket, walker_rocket_touch);
242 rocket.flags = FL_PROJECTILE;
243 IL_PUSH(g_projectiles, rocket);
244 IL_PUSH(g_bot_dodge, rocket);
245 rocket.solid = SOLID_BBOX;
246 rocket.max_health = time + 9;
247 rocket.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_HEAT;
249 CSQCProjectile(rocket, false, PROJECTILE_ROCKET, false); // no culling, has fly sound
252 .vector enemy_last_loc;
253 .float enemy_last_time;
254 void walker_move_to(entity this, vector _target, float _dist)
256 switch (this.waterlevel)
258 case WATERLEVEL_NONE:
260 this.animflag = ANIM_RUN;
262 this.animflag = ANIM_WALK;
263 case WATERLEVEL_WETFEET:
264 case WATERLEVEL_SWIMMING:
265 if (this.animflag != ANIM_SWIM)
266 this.animflag = ANIM_WALK;
268 this.animflag = ANIM_SWIM;
270 case WATERLEVEL_SUBMERGED:
271 this.animflag = ANIM_SWIM;
274 this.moveto = _target;
275 this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95);
279 this.enemy_last_loc = _target;
280 this.enemy_last_time = time;
284 void walker_move_path(entity this)
286 #ifdef WALKER_FANCYPATHING
287 // Are we close enougth to a path node to switch to the next?
288 if(vdist(this.origin - this.pathcurrent.origin, <, 64))
289 if (this.pathcurrent.path_next == NULL)
291 // Path endpoint reached
292 pathlib_deletepath(this.pathcurrent.owner);
293 this.pathcurrent = NULL;
297 if (this.pathgoal.use)
298 this.pathgoal.use(this, NULL, NULL);
300 if (this.pathgoal.enemy)
302 this.pathcurrent = WALKER_PATH(this, this.pathgoal.origin, this.pathgoal.enemy.origin);
303 this.pathgoal = this.pathgoal.enemy;
307 this.pathgoal = NULL;
310 this.pathcurrent = this.pathcurrent.path_next;
312 this.moveto = this.pathcurrent.origin;
313 this.steerto = steerlib_attract2(this, this.moveto,0.5,500,0.95);
314 walker_move_to(this, this.moveto, 0);
317 if(vdist(this.origin - this.pathcurrent.origin, <, 64))
318 this.pathcurrent = this.pathcurrent.enemy;
320 if(!this.pathcurrent)
323 this.moveto = this.pathcurrent.origin;
324 this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95);
325 walker_move_to(this, this.moveto, 0);
329 spawnfunc(turret_walker) { if(!turret_initialize(this, TUR_WALKER)) delete(this); }
331 METHOD(WalkerTurret, tr_think, void(WalkerTurret thistur, entity it))
333 fixedmakevectors(it.angles);
335 if (it.spawnflags & TSF_NO_PATHBREAK && it.pathcurrent)
336 walker_move_path(it);
337 else if (it.enemy == NULL)
340 walker_move_path(it);
343 if(it.enemy_last_time != 0)
345 if(vdist(it.origin - it.enemy_last_loc, <, 128) || time - it.enemy_last_time > 10)
346 it.enemy_last_time = 0;
348 walker_move_to(it, it.enemy_last_loc, 0);
352 if(it.animflag != ANIM_NO)
354 traceline(it.origin + '0 0 64', it.origin + '0 0 64' + v_forward * 128, MOVE_NORMAL, it);
356 if(trace_fraction != 1.0)
357 it.tur_head.idletime = -1337;
360 traceline(trace_endpos, trace_endpos - '0 0 256', MOVE_NORMAL, it);
361 if(trace_fraction == 1.0)
362 it.tur_head.idletime = -1337;
365 if(it.tur_head.idletime == -1337)
367 it.moveto = it.origin + randomvec() * 256;
368 it.tur_head.idletime = 0;
371 it.moveto = it.moveto * 0.9 + ((it.origin + v_forward * 500) + randomvec() * 400) * 0.1;
372 it.moveto_z = it.origin_z + 64;
373 walker_move_to(it, it.moveto, 0);
376 if(it.idletime < time)
378 if(random() < 0.5 || !(it.spawnflags & TSL_ROAM))
380 it.idletime = time + 1 + random() * 5;
381 it.moveto = it.origin;
382 it.animflag = ANIM_NO;
386 it.animflag = ANIM_WALK;
387 it.idletime = time + 4 + random() * 2;
388 it.moveto = it.origin + randomvec() * 256;
389 it.tur_head.moveto = it.moveto;
390 it.tur_head.idletime = 0;
398 if (it.tur_dist_enemy < (autocvar_g_turrets_unit_walker_melee_range) && it.animflag != ANIM_MELEE)
402 wish_angle = angleofs(it, it.enemy);
403 if (it.animflag != ANIM_SWIM)
404 if (fabs(wish_angle_y) < 15)
406 it.moveto = it.enemy.origin;
407 it.steerto = steerlib_attract2(it, it.moveto, 0.5, 500, 0.95);
408 it.animflag = ANIM_MELEE;
411 else if (it.tur_head.attack_finished_single[0] < time)
413 if(it.tur_head.shot_volly)
415 it.animflag = ANIM_NO;
417 it.tur_head.shot_volly = it.tur_head.shot_volly -1;
418 if(it.tur_head.shot_volly == 0)
419 it.tur_head.attack_finished_single[0] = time + (autocvar_g_turrets_unit_walker_rocket_refire);
421 it.tur_head.attack_finished_single[0] = time + 0.2;
423 if(it.tur_head.shot_volly > 1)
424 walker_fire_rocket(it, gettaginfo(it, gettagindex(it, "tag_rocket01")));
426 walker_fire_rocket(it, gettaginfo(it, gettagindex(it, "tag_rocket02")));
430 if (it.tur_dist_enemy > (autocvar_g_turrets_unit_walker_rocket_range_min))
431 if (it.tur_dist_enemy < (autocvar_g_turrets_unit_walker_rocket_range))
432 it.tur_head.shot_volly = 4;
437 if (it.animflag != ANIM_MELEE)
438 walker_move_to(it, it.enemy.origin, it.tur_dist_enemy);
444 float turny = 0, turnx = 0;
447 real_angle = vectoangles(it.steerto) - it.angles;
453 movelib_brake_simple(it, (autocvar_g_turrets_unit_walker_speed_stop));
457 turny = (autocvar_g_turrets_unit_walker_turn);
458 movelib_brake_simple(it, (autocvar_g_turrets_unit_walker_speed_stop));
462 turny = (autocvar_g_turrets_unit_walker_turn_walk);
463 movelib_move_simple(it, v_forward, (autocvar_g_turrets_unit_walker_speed_walk), 0.6);
467 turny = (autocvar_g_turrets_unit_walker_turn_run);
468 movelib_move_simple(it, v_forward, (autocvar_g_turrets_unit_walker_speed_run), 0.6);
472 turny = (autocvar_g_turrets_unit_walker_turn_strafe);
473 movelib_move_simple(it, v_right * -1, (autocvar_g_turrets_unit_walker_speed_walk), 0.8);
477 turny = (autocvar_g_turrets_unit_walker_turn_strafe);
478 movelib_move_simple(it, v_right, (autocvar_g_turrets_unit_walker_speed_walk), 0.8);
482 it.velocity += '0 0 1' * (autocvar_g_turrets_unit_walker_speed_jump);
489 if(it.frame != ANIM_PAIN)
490 defer(it, 0.25, walker_setnoanim);
495 if(it.frame != ANIM_MELEE)
497 defer(it, 0.41, walker_setnoanim);
498 defer(it, 0.21, walker_melee_do_dmg);
501 movelib_brake_simple(it, (autocvar_g_turrets_unit_walker_speed_stop));
505 turny = (autocvar_g_turrets_unit_walker_turn_swim);
506 turnx = (autocvar_g_turrets_unit_walker_turn_swim);
508 it.angles_x += bound(-10, shortangle_f(real_angle_x, it.angles_x), 10);
509 movelib_move_simple(it, v_forward, (autocvar_g_turrets_unit_walker_speed_swim), 0.3);
510 vz = it.velocity_z + sin(time * 4) * 8;
514 turny = (autocvar_g_turrets_unit_walker_turn_walk);
515 movelib_move_simple(it, v_forward ,(autocvar_g_turrets_unit_walker_speed_roam), 0.5);
521 turny = bound( turny * -1, shortangle_f(real_angle_y, it.angles_y), turny );
522 it.angles_y += turny;
527 turnx = bound( turnx * -1, shortangle_f(real_angle_x, it.angles_x), turnx );
528 it.angles_x += turnx;
535 if(it.origin != it.oldorigin)
536 it.SendFlags |= TNSF_MOVE;
538 it.oldorigin = it.origin;
539 turrets_setframe(it, it.animflag, false);
541 METHOD(WalkerTurret, tr_death, void(WalkerTurret this, entity it))
543 #ifdef WALKER_FANCYPATHING
545 pathlib_deletepath(it.pathcurrent.owner);
547 it.pathcurrent = NULL;
549 METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it))
555 // Respawn is called & first spawn to, to set team. need to make sure we do not move the initial spawn.
556 if(it.move_movetype == MOVETYPE_WALK)
559 setorigin(it, it.pos1);
564 it.ammo_flags = TFL_AMMO_BULLETS | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE;
565 it.aim_flags = TFL_AIM_LEAD;
566 it.turret_flags |= TUR_FLAG_HITSCAN;
568 it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
569 it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
570 it.iscreature = true;
571 it.teleportable = TELEPORT_NORMAL;
572 if(!it.damagedbycontents)
573 IL_PUSH(g_damagedbycontents, it);
574 it.damagedbycontents = true;
575 it.solid = SOLID_SLIDEBOX;
576 it.takedamage = DAMAGE_AIM;
577 if(it.move_movetype != MOVETYPE_WALK)
579 setorigin(it, it.origin);
580 tracebox(it.origin + '0 0 128', it.mins, it.maxs, it.origin - '0 0 10000', MOVE_NORMAL, it);
581 setorigin(it, trace_endpos + '0 0 4');
585 set_movetype(it, MOVETYPE_WALK);
586 it.idle_aim = '0 0 0';
587 it.turret_firecheckfunc = walker_firecheck;
591 e = find(NULL, targetname, it.target);
594 LOG_TRACE("Initital waypoint for walker does NOT exsist, fix your map!");
598 if (e.classname != "turret_checkpoint")
599 LOG_TRACE("Warning: not a turrret path");
602 #ifdef WALKER_FANCYPATHING
603 it.pathcurrent = WALKER_PATH(it, it.origin, e.origin);
615 #include <common/physics/movelib.qh>
617 void walker_draw(entity this)
621 dt = time - this.move_time;
622 this.move_time = time;
626 fixedmakevectors(this.angles);
627 movelib_groundalign4point(this, 300, 100, 0.25, 45);
628 setorigin(this, this.origin + this.velocity * dt);
629 this.tur_head.angles += dt * this.tur_head.avelocity;
631 if (this.health < 127)
633 te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
636 METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it))
639 set_movetype(it, MOVETYPE_BOUNCE);
641 it.draw = walker_draw;