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 rocket.solid = SOLID_BBOX;
245 rocket.max_health = time + 9;
246 rocket.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_HEAT;
248 CSQCProjectile(rocket, false, PROJECTILE_ROCKET, false); // no culling, has fly sound
251 .vector enemy_last_loc;
252 .float enemy_last_time;
253 void walker_move_to(entity this, vector _target, float _dist)
255 switch (this.waterlevel)
257 case WATERLEVEL_NONE:
259 this.animflag = ANIM_RUN;
261 this.animflag = ANIM_WALK;
262 case WATERLEVEL_WETFEET:
263 case WATERLEVEL_SWIMMING:
264 if (this.animflag != ANIM_SWIM)
265 this.animflag = ANIM_WALK;
267 this.animflag = ANIM_SWIM;
269 case WATERLEVEL_SUBMERGED:
270 this.animflag = ANIM_SWIM;
273 this.moveto = _target;
274 this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95);
278 this.enemy_last_loc = _target;
279 this.enemy_last_time = time;
283 void walker_move_path(entity this)
285 #ifdef WALKER_FANCYPATHING
286 // Are we close enougth to a path node to switch to the next?
287 if(vdist(this.origin - this.pathcurrent.origin, <, 64))
288 if (this.pathcurrent.path_next == NULL)
290 // Path endpoint reached
291 pathlib_deletepath(this.pathcurrent.owner);
292 this.pathcurrent = NULL;
296 if (this.pathgoal.use)
297 this.pathgoal.use(this, NULL, NULL);
299 if (this.pathgoal.enemy)
301 this.pathcurrent = WALKER_PATH(this, this.pathgoal.origin, this.pathgoal.enemy.origin);
302 this.pathgoal = this.pathgoal.enemy;
306 this.pathgoal = NULL;
309 this.pathcurrent = this.pathcurrent.path_next;
311 this.moveto = this.pathcurrent.origin;
312 this.steerto = steerlib_attract2(this, this.moveto,0.5,500,0.95);
313 walker_move_to(this, this.moveto, 0);
316 if(vdist(this.origin - this.pathcurrent.origin, <, 64))
317 this.pathcurrent = this.pathcurrent.enemy;
319 if(!this.pathcurrent)
322 this.moveto = this.pathcurrent.origin;
323 this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95);
324 walker_move_to(this, this.moveto, 0);
328 spawnfunc(turret_walker) { if(!turret_initialize(this, TUR_WALKER)) delete(this); }
330 METHOD(WalkerTurret, tr_think, void(WalkerTurret thistur, entity it))
332 fixedmakevectors(it.angles);
334 if (it.spawnflags & TSF_NO_PATHBREAK && it.pathcurrent)
335 walker_move_path(it);
336 else if (it.enemy == NULL)
339 walker_move_path(it);
342 if(it.enemy_last_time != 0)
344 if(vdist(it.origin - it.enemy_last_loc, <, 128) || time - it.enemy_last_time > 10)
345 it.enemy_last_time = 0;
347 walker_move_to(it, it.enemy_last_loc, 0);
351 if(it.animflag != ANIM_NO)
353 traceline(it.origin + '0 0 64', it.origin + '0 0 64' + v_forward * 128, MOVE_NORMAL, it);
355 if(trace_fraction != 1.0)
356 it.tur_head.idletime = -1337;
359 traceline(trace_endpos, trace_endpos - '0 0 256', MOVE_NORMAL, it);
360 if(trace_fraction == 1.0)
361 it.tur_head.idletime = -1337;
364 if(it.tur_head.idletime == -1337)
366 it.moveto = it.origin + randomvec() * 256;
367 it.tur_head.idletime = 0;
370 it.moveto = it.moveto * 0.9 + ((it.origin + v_forward * 500) + randomvec() * 400) * 0.1;
371 it.moveto_z = it.origin_z + 64;
372 walker_move_to(it, it.moveto, 0);
375 if(it.idletime < time)
377 if(random() < 0.5 || !(it.spawnflags & TSL_ROAM))
379 it.idletime = time + 1 + random() * 5;
380 it.moveto = it.origin;
381 it.animflag = ANIM_NO;
385 it.animflag = ANIM_WALK;
386 it.idletime = time + 4 + random() * 2;
387 it.moveto = it.origin + randomvec() * 256;
388 it.tur_head.moveto = it.moveto;
389 it.tur_head.idletime = 0;
397 if (it.tur_dist_enemy < (autocvar_g_turrets_unit_walker_melee_range) && it.animflag != ANIM_MELEE)
401 wish_angle = angleofs(it, it.enemy);
402 if (it.animflag != ANIM_SWIM)
403 if (fabs(wish_angle_y) < 15)
405 it.moveto = it.enemy.origin;
406 it.steerto = steerlib_attract2(it, it.moveto, 0.5, 500, 0.95);
407 it.animflag = ANIM_MELEE;
410 else if (it.tur_head.attack_finished_single[0] < time)
412 if(it.tur_head.shot_volly)
414 it.animflag = ANIM_NO;
416 it.tur_head.shot_volly = it.tur_head.shot_volly -1;
417 if(it.tur_head.shot_volly == 0)
418 it.tur_head.attack_finished_single[0] = time + (autocvar_g_turrets_unit_walker_rocket_refire);
420 it.tur_head.attack_finished_single[0] = time + 0.2;
422 if(it.tur_head.shot_volly > 1)
423 walker_fire_rocket(it, gettaginfo(it, gettagindex(it, "tag_rocket01")));
425 walker_fire_rocket(it, gettaginfo(it, gettagindex(it, "tag_rocket02")));
429 if (it.tur_dist_enemy > (autocvar_g_turrets_unit_walker_rocket_range_min))
430 if (it.tur_dist_enemy < (autocvar_g_turrets_unit_walker_rocket_range))
431 it.tur_head.shot_volly = 4;
436 if (it.animflag != ANIM_MELEE)
437 walker_move_to(it, it.enemy.origin, it.tur_dist_enemy);
443 float turny = 0, turnx = 0;
446 real_angle = vectoangles(it.steerto) - it.angles;
452 movelib_brake_simple(it, (autocvar_g_turrets_unit_walker_speed_stop));
456 turny = (autocvar_g_turrets_unit_walker_turn);
457 movelib_brake_simple(it, (autocvar_g_turrets_unit_walker_speed_stop));
461 turny = (autocvar_g_turrets_unit_walker_turn_walk);
462 movelib_move_simple(it, v_forward, (autocvar_g_turrets_unit_walker_speed_walk), 0.6);
466 turny = (autocvar_g_turrets_unit_walker_turn_run);
467 movelib_move_simple(it, v_forward, (autocvar_g_turrets_unit_walker_speed_run), 0.6);
471 turny = (autocvar_g_turrets_unit_walker_turn_strafe);
472 movelib_move_simple(it, v_right * -1, (autocvar_g_turrets_unit_walker_speed_walk), 0.8);
476 turny = (autocvar_g_turrets_unit_walker_turn_strafe);
477 movelib_move_simple(it, v_right, (autocvar_g_turrets_unit_walker_speed_walk), 0.8);
481 it.velocity += '0 0 1' * (autocvar_g_turrets_unit_walker_speed_jump);
488 if(it.frame != ANIM_PAIN)
489 defer(it, 0.25, walker_setnoanim);
494 if(it.frame != ANIM_MELEE)
496 defer(it, 0.41, walker_setnoanim);
497 defer(it, 0.21, walker_melee_do_dmg);
500 movelib_brake_simple(it, (autocvar_g_turrets_unit_walker_speed_stop));
504 turny = (autocvar_g_turrets_unit_walker_turn_swim);
505 turnx = (autocvar_g_turrets_unit_walker_turn_swim);
507 it.angles_x += bound(-10, shortangle_f(real_angle_x, it.angles_x), 10);
508 movelib_move_simple(it, v_forward, (autocvar_g_turrets_unit_walker_speed_swim), 0.3);
509 vz = it.velocity_z + sin(time * 4) * 8;
513 turny = (autocvar_g_turrets_unit_walker_turn_walk);
514 movelib_move_simple(it, v_forward ,(autocvar_g_turrets_unit_walker_speed_roam), 0.5);
520 turny = bound( turny * -1, shortangle_f(real_angle_y, it.angles_y), turny );
521 it.angles_y += turny;
526 turnx = bound( turnx * -1, shortangle_f(real_angle_x, it.angles_x), turnx );
527 it.angles_x += turnx;
534 if(it.origin != it.oldorigin)
535 it.SendFlags |= TNSF_MOVE;
537 it.oldorigin = it.origin;
538 turrets_setframe(it, it.animflag, false);
540 METHOD(WalkerTurret, tr_death, void(WalkerTurret this, entity it))
542 #ifdef WALKER_FANCYPATHING
544 pathlib_deletepath(it.pathcurrent.owner);
546 it.pathcurrent = NULL;
548 METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it))
554 // Respawn is called & first spawn to, to set team. need to make sure we do not move the initial spawn.
555 if(it.move_movetype == MOVETYPE_WALK)
558 setorigin(it, it.pos1);
563 it.ammo_flags = TFL_AMMO_BULLETS | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE;
564 it.aim_flags = TFL_AIM_LEAD;
565 it.turret_flags |= TUR_FLAG_HITSCAN;
567 it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
568 it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
569 it.iscreature = true;
570 it.teleportable = TELEPORT_NORMAL;
571 it.damagedbycontents = true;
572 IL_PUSH(g_damagedbycontents, it);
573 it.solid = SOLID_SLIDEBOX;
574 it.takedamage = DAMAGE_AIM;
575 if(it.move_movetype != MOVETYPE_WALK)
577 setorigin(it, it.origin);
578 tracebox(it.origin + '0 0 128', it.mins, it.maxs, it.origin - '0 0 10000', MOVE_NORMAL, it);
579 setorigin(it, trace_endpos + '0 0 4');
583 set_movetype(it, MOVETYPE_WALK);
584 it.idle_aim = '0 0 0';
585 it.turret_firecheckfunc = walker_firecheck;
589 e = find(NULL, targetname, it.target);
592 LOG_TRACE("Initital waypoint for walker does NOT exsist, fix your map!");
596 if (e.classname != "turret_checkpoint")
597 LOG_TRACE("Warning: not a turrret path");
600 #ifdef WALKER_FANCYPATHING
601 it.pathcurrent = WALKER_PATH(it, it.origin, e.origin);
613 #include <common/physics/movelib.qh>
615 void walker_draw(entity this)
619 dt = time - this.move_time;
620 this.move_time = time;
624 fixedmakevectors(this.angles);
625 movelib_groundalign4point(this, 300, 100, 0.25, 45);
626 setorigin(this, this.origin + this.velocity * dt);
627 this.tur_head.angles += dt * this.tur_head.avelocity;
629 if (this.health < 127)
631 te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
634 METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it))
637 set_movetype(it, MOVETYPE_BOUNCE);
639 it.draw = walker_draw;