3 #include <server/defs.qh>
4 #include <server/miscfunctions.qh>
9 #include "../navigation.qh"
10 #include "../scripting.qh"
11 #include "../waypoints.qh"
13 #include <common/constants.qh>
14 #include <common/impulses/all.qh>
15 #include <common/net_linked.qh>
16 #include <common/physics/player.qh>
17 #include <common/state.qh>
18 #include <common/items/_mod.qh>
19 #include <common/wepent.qh>
21 #include <common/triggers/teleporters.qh>
22 #include <common/triggers/trigger/jumppads.qh>
24 #include <lib/warpzone/common.qh>
28 void havocbot_ai(entity this)
33 if(bot_execute_commands(this))
36 if (bot_strategytoken == this)
37 if (!bot_strategytoken_taken)
39 if(this.havocbot_blockhead)
41 this.havocbot_blockhead = false;
45 if (!this.jumppadcount && !STAT(FROZEN, this))
46 this.havocbot_role(this); // little too far down the rabbit hole
49 // if we don't have a goal and we're under water look for a waypoint near the "shore" and push it
50 if(!(IS_DEAD(this) || STAT(FROZEN, this)))
52 if(this.waterlevel == WATERLEVEL_SWIMMING || (this.aistatus & AI_STATUS_OUT_WATER))
54 // Look for the closest waypoint out of water
55 entity newgoal = NULL;
56 IL_EACH(g_waypoints, vdist(it.origin - this.origin, <=, 10000),
58 if(it.origin.z < this.origin.z)
61 if(it.origin.z - this.origin.z - this.view_ofs.z > 100)
64 if (pointcontents(it.origin + it.maxs + '0 0 1') != CONTENT_EMPTY)
67 traceline(this.origin + this.view_ofs, ((it.absmin + it.absmax) * 0.5), true, this);
69 if(trace_fraction < 1)
72 if(!newgoal || vlen2(it.origin - this.origin) < vlen2(newgoal.origin - this.origin))
78 // te_wizspike(newgoal.origin);
79 navigation_pushroute(this, newgoal);
83 // token has been used this frame
84 bot_strategytoken_taken = true;
87 if(IS_DEAD(this) || STAT(FROZEN, this))
90 navigation_clearroute(this);
94 havocbot_chooseenemy(this);
96 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
98 .entity weaponentity = weaponentities[slot];
99 if(this.(weaponentity).m_weapon != WEP_Null || slot == 0)
100 if(this.(weaponentity).bot_chooseweapontime < time)
102 this.(weaponentity).bot_chooseweapontime = time + autocvar_bot_ai_chooseweaponinterval;
103 havocbot_chooseweapon(this, weaponentity);
108 if (this.bot_aimtarg)
110 this.aistatus |= AI_STATUS_ATTACKING;
111 this.aistatus &= ~AI_STATUS_ROAMING;
115 if (autocvar_bot_nofire || IS_INDEPENDENT_PLAYER(this))
117 PHYS_INPUT_BUTTON_ATCK(this) = false;
118 PHYS_INPUT_BUTTON_ATCK2(this) = false;
122 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
124 .entity weaponentity = weaponentities[slot];
125 Weapon w = this.(weaponentity).m_weapon;
126 if(w == WEP_Null && slot != 0)
128 w.wr_aim(w, this, weaponentity);
129 if(PHYS_INPUT_BUTTON_ATCK(this) || PHYS_INPUT_BUTTON_ATCK2(this)) // TODO: what if we didn't fire this weapon, but the previous?
130 this.(weaponentity).lastfiredweapon = this.(weaponentity).m_weapon.m_id;
136 if(IS_PLAYER(this.bot_aimtarg))
137 bot_aimdir(this, this.bot_aimtarg.origin + this.bot_aimtarg.view_ofs - this.origin - this.view_ofs , -1);
140 else if (this.goalcurrent)
142 this.aistatus |= AI_STATUS_ROAMING;
143 this.aistatus &= ~AI_STATUS_ATTACKING;
145 vector v = '0 0 0', now, next;
146 float aimdistance,skillblend,distanceblend,blend;
148 SET_DESTCOORDS(this.goalcurrent, this.origin, v);
149 if(this.goalcurrent.wpisbox)
151 // avoid a glitch when bot is teleported but teleport waypoint isn't removed yet
152 if(this.goalstack02 && this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT
153 && this.lastteleporttime > 0 && time - this.lastteleporttime < 0.15)
154 v = (this.goalstack02.absmin + this.goalstack02.absmax) * 0.5;
155 // aim to teleport origin if bot is inside teleport waypoint but hasn't touched the real teleport yet
156 else if(boxesoverlap(this.goalcurrent.absmin, this.goalcurrent.absmax, this.origin, this.origin))
157 v = this.goalcurrent.origin;
159 next = now = v - (this.origin + this.view_ofs);
160 aimdistance = vlen(now);
162 //dprint(this.goalstack01.classname,etos(this.goalstack01),"\n");
164 this.goalstack01 != this && this.goalstack01 && !wasfreed(this.goalstack01) && ((this.aistatus & AI_STATUS_RUNNING) == 0) &&
165 !(this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
167 next = ((this.goalstack01.absmin + this.goalstack01.absmax) * 0.5) - (this.origin + this.view_ofs);
169 skillblend=bound(0,(skill+this.bot_moveskill-2.5)*0.5,1); //lower skill player can't preturn
170 distanceblend=bound(0,aimdistance/autocvar_bot_ai_keyboard_distance,1);
171 blend = skillblend * (1-distanceblend);
172 //v = (now * (distanceblend) + next * (1-distanceblend)) * (skillblend) + now * (1-skillblend);
173 //v = now * (distanceblend) * (skillblend) + next * (1-distanceblend) * (skillblend) + now * (1-skillblend);
174 //v = now * ((1-skillblend) + (distanceblend) * (skillblend)) + next * (1-distanceblend) * (skillblend);
175 v = now + blend * (next - now);
176 //dprint(etos(this), " ");
177 //dprint(vtos(now), ":", vtos(next), "=", vtos(v), " (blend ", ftos(blend), ")\n");
178 //v = now * (distanceblend) + next * (1-distanceblend);
179 if (this.waterlevel < WATERLEVEL_SWIMMING)
181 //dprint("walk at:", vtos(v), "\n");
182 //te_lightning2(NULL, this.origin, this.goalcurrent.origin);
183 bot_aimdir(this, v, -1);
185 havocbot_movetogoal(this);
187 // if the bot is not attacking, consider reloading weapons
188 if (!(this.aistatus & AI_STATUS_ATTACKING))
190 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
192 .entity weaponentity = weaponentities[slot];
194 if(this.(weaponentity).m_weapon == WEP_Null && slot != 0)
197 // we are currently holding a weapon that's not fully loaded, reload it
198 if(skill >= 2) // bots can only reload the held weapon on purpose past this skill
199 if(this.(weaponentity).clip_load < this.(weaponentity).clip_size)
200 CS(this).impulse = IMP_weapon_reload.impulse; // not sure if this is done right
202 // if we're not reloading a weapon, switch to any weapon in our invnetory that's not fully loaded to reload it next
203 // the code above executes next frame, starting the reloading then
204 if(skill >= 5) // bots can only look for unloaded weapons past this skill
205 if(this.(weaponentity).clip_load >= 0) // only if we're not reloading a weapon already
207 FOREACH(Weapons, it != WEP_Null, {
208 if((this.weapons & (it.m_wepset)) && (it.spawnflags & WEP_FLAG_RELOADABLE) && (this.(weaponentity).weapon_load[it.m_id] < it.reloading_ammo))
210 this.(weaponentity).m_switchweapon = it;
219 void havocbot_keyboard_movement(entity this, vector destorg)
223 if (time > this.havocbot_keyboardtime)
225 float sk = skill + this.bot_moveskill;
226 this.havocbot_keyboardtime =
228 this.havocbot_keyboardtime
229 + 0.05 / max(1, sk + this.havocbot_keyboardskill)
230 + random() * 0.025 / max(0.00025, skill + this.havocbot_keyboardskill)
232 keyboard = CS(this).movement / autocvar_sv_maxspeed;
234 float trigger = autocvar_bot_ai_keyboard_threshold;
235 float trigger1 = -trigger;
237 // categorize forward movement
238 // at skill < 1.5 only forward
239 // at skill < 2.5 only individual directions
240 // at skill < 4.5 only individual directions, and forward diagonals
241 // at skill >= 4.5, all cases allowed
242 if (keyboard.x > trigger)
248 else if (keyboard.x < trigger1 && sk > 1.5)
263 if (keyboard.y > trigger)
265 else if (keyboard.y < trigger1)
270 if (keyboard.z > trigger)
272 else if (keyboard.z < trigger1)
277 this.havocbot_keyboard = keyboard * autocvar_sv_maxspeed;
278 if (this.havocbot_ducktime > time)
279 PHYS_INPUT_BUTTON_CROUCH(this) = true;
282 keyboard = this.havocbot_keyboard;
283 float blend = bound(0, vlen(destorg - this.origin) / autocvar_bot_ai_keyboard_distance, 1); // When getting close move with 360 degree
284 //dprint("movement ", vtos(CS(this).movement), " keyboard ", vtos(keyboard), " blend ", ftos(blend), "\n");
285 CS(this).movement = CS(this).movement + (keyboard - CS(this).movement) * blend;
288 void havocbot_bunnyhop(entity this, vector dir)
290 float bunnyhopdistance;
293 vector gco = '0 0 0', gno;
295 // Don't jump when attacking
296 if(this.aistatus & AI_STATUS_ATTACKING)
299 if(IS_PLAYER(this.goalcurrent))
302 maxspeed = autocvar_sv_maxspeed;
304 if(this.aistatus & AI_STATUS_RUNNING && vdist(this.velocity, <, autocvar_sv_maxspeed * 0.75)
305 || this.aistatus & AI_STATUS_DANGER_AHEAD)
307 this.aistatus &= ~AI_STATUS_RUNNING;
308 PHYS_INPUT_BUTTON_JUMP(this) = false;
309 this.bot_canruntogoal = 0;
310 this.bot_timelastseengoal = 0;
314 if(this.waterlevel > WATERLEVEL_WETFEET)
316 this.aistatus &= ~AI_STATUS_RUNNING;
320 if(this.bot_lastseengoal != this.goalcurrent && !(this.aistatus & AI_STATUS_RUNNING))
322 this.bot_canruntogoal = 0;
323 this.bot_timelastseengoal = 0;
326 SET_DESTCOORDS(this.goalcurrent, this.origin, gco);
327 bunnyhopdistance = vlen(this.origin - gco);
329 // Run only to visible goals
330 if(IS_ONGROUND(this))
331 if(vdist(vec2(this.velocity), >=, autocvar_sv_maxspeed)) // if -really- running
332 if(checkpvs(this.origin + this.view_ofs, this.goalcurrent))
334 this.bot_lastseengoal = this.goalcurrent;
337 if(this.bot_timelastseengoal)
339 // for a period of time
340 if(time - this.bot_timelastseengoal > autocvar_bot_ai_bunnyhop_firstjumpdelay)
343 checkdistance = true;
345 // don't run if it is too close
346 if(this.bot_canruntogoal==0)
348 if(bunnyhopdistance > autocvar_bot_ai_bunnyhop_startdistance)
349 this.bot_canruntogoal = 1;
351 this.bot_canruntogoal = -1;
354 if(this.bot_canruntogoal != 1)
357 if(this.aistatus & AI_STATUS_ROAMING)
358 if(this.goalcurrent.classname=="waypoint")
359 if (!(this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL))
360 if(fabs(gco.z - this.origin.z) < this.maxs.z - this.mins.z)
361 if(this.goalstack01 && !wasfreed(this.goalstack01))
363 gno = (this.goalstack01.absmin + this.goalstack01.absmax) * 0.5;
364 deviation = vectoangles(gno - this.origin) - vectoangles(gco - this.origin);
365 while (deviation.y < -180) deviation.y = deviation.y + 360;
366 while (deviation.y > 180) deviation.y = deviation.y - 360;
368 if(fabs(deviation.y) < 20)
369 if(bunnyhopdistance < vlen(this.origin - gno))
370 if(fabs(gno.z - gco.z) < this.maxs.z - this.mins.z)
372 if(vdist(gco - gno, >, autocvar_bot_ai_bunnyhop_startdistance))
373 if(checkpvs(this.origin + this.view_ofs, this.goalstack01))
375 checkdistance = false;
382 this.aistatus &= ~AI_STATUS_RUNNING;
383 // increase stop distance in case the goal is on a slope or a lower platform
384 if(bunnyhopdistance > autocvar_bot_ai_bunnyhop_stopdistance + (this.origin.z - gco.z))
385 PHYS_INPUT_BUTTON_JUMP(this) = true;
389 this.aistatus |= AI_STATUS_RUNNING;
390 PHYS_INPUT_BUTTON_JUMP(this) = true;
396 this.bot_timelastseengoal = time;
401 this.bot_timelastseengoal = 0;
405 // Release jump button
406 if(!cvar("sv_pogostick"))
407 if((IS_ONGROUND(this)) == 0)
409 if(this.velocity.z < 0 || vlen(this.velocity)<maxspeed)
410 PHYS_INPUT_BUTTON_JUMP(this) = false;
413 if(this.aistatus & AI_STATUS_RUNNING)
414 if(vlen(this.velocity)>maxspeed)
416 deviation = vectoangles(dir) - vectoangles(this.velocity);
417 while (deviation.y < -180) deviation.y = deviation.y + 360;
418 while (deviation.y > 180) deviation.y = deviation.y - 360;
420 if(fabs(deviation.y)>10)
421 CS(this).movement_x = 0;
424 CS(this).movement_y = maxspeed * -1;
425 else if(deviation.y<10)
426 CS(this).movement_y = maxspeed;
433 // return true when bot isn't getting closer to the current goal
434 bool havocbot_checkgoaldistance(entity this, vector gco)
436 float curr_dist_z = max(20, fabs(this.origin.z - gco.z));
437 float curr_dist_2d = max(20, vlen(vec2(this.origin - gco)));
438 float distance_time = this.goalcurrent_distance_time;
439 if(distance_time < 0)
440 distance_time = -distance_time;
441 if(curr_dist_z >= this.goalcurrent_distance_z && curr_dist_2d >= this.goalcurrent_distance_2d)
444 this.goalcurrent_distance_time = time;
445 else if (time - distance_time > 0.5)
450 // reduce it a little bit so it works even with very small approaches to the goal
451 this.goalcurrent_distance_z = max(20, curr_dist_z - 10);
452 this.goalcurrent_distance_2d = max(20, curr_dist_2d - 10);
453 this.goalcurrent_distance_time = 0;
458 void havocbot_movetogoal(entity this)
460 vector destorg = '0 0 0';
464 vector evadeobstacle;
470 //if (this.goalentity)
471 // te_lightning2(this, this.origin, (this.goalentity.absmin + this.goalentity.absmax) * 0.5);
472 CS(this).movement = '0 0 0';
473 maxspeed = autocvar_sv_maxspeed;
475 PHYS_INPUT_BUTTON_JETPACK(this) = false;
476 // Jetpack navigation
477 if(this.navigation_jetpack_goal)
478 if(this.goalcurrent==this.navigation_jetpack_goal)
481 if(autocvar_bot_debug_goalstack)
483 debuggoalstack(this);
484 te_wizspike(this.navigation_jetpack_point);
488 if (!(this.aistatus & AI_STATUS_JETPACK_FLYING))
490 // Brake almost completely so it can get a good direction
491 if(vdist(this.velocity, >, 10))
493 this.aistatus |= AI_STATUS_JETPACK_FLYING;
496 makevectors(this.v_angle.y * '0 1 0');
497 dir = normalize(this.navigation_jetpack_point - this.origin);
500 if(this.aistatus & AI_STATUS_JETPACK_LANDING)
502 // Calculate brake distance in xy
503 float d = vlen(vec2(this.origin - (this.goalcurrent.absmin + this.goalcurrent.absmax) * 0.5));
504 float v = vlen(vec2(this.velocity));
505 float db = ((v ** 2) / (autocvar_g_jetpack_acceleration_side * 2)) + 100;
506 //LOG_INFOF("distance %d, velocity %d, brake at %d ", ceil(d), ceil(v), ceil(db));
507 if(d < db || d < 500)
510 if(v > maxspeed * 0.3)
512 CS(this).movement_x = dir * v_forward * -maxspeed;
515 // Switch to normal mode
516 this.navigation_jetpack_goal = NULL;
517 this.aistatus &= ~AI_STATUS_JETPACK_LANDING;
518 this.aistatus &= ~AI_STATUS_JETPACK_FLYING;
522 else if(checkpvs(this.origin,this.goalcurrent))
524 // If I can see the goal switch to landing code
525 this.aistatus &= ~AI_STATUS_JETPACK_FLYING;
526 this.aistatus |= AI_STATUS_JETPACK_LANDING;
531 PHYS_INPUT_BUTTON_JETPACK(this) = true;
532 if(this.navigation_jetpack_point.z - STAT(PL_MAX, this).z + STAT(PL_MIN, this).z < this.origin.z)
534 CS(this).movement_x = dir * v_forward * maxspeed;
535 CS(this).movement_y = dir * v_right * maxspeed;
540 // Handling of jump pads
541 if(this.jumppadcount)
543 if(this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
545 this.aistatus |= AI_STATUS_OUT_JUMPPAD;
546 navigation_poptouchedgoals(this);
549 else if(this.aistatus & AI_STATUS_OUT_JUMPPAD)
551 // If got stuck on the jump pad try to reach the farthest visible waypoint
552 // but with some randomness so it can try out different paths
553 if(!this.goalcurrent)
555 entity newgoal = NULL;
556 IL_EACH(g_waypoints, vdist(it.origin - this.origin, <=, 1000),
558 if(it.wpflags & WAYPOINTFLAG_TELEPORT)
559 if(it.origin.z < this.origin.z - 100 && vdist(vec2(it.origin - this.origin), <, 100))
562 traceline(this.origin + this.view_ofs, ((it.absmin + it.absmax) * 0.5), true, this);
564 if(trace_fraction < 1)
567 if(!newgoal || ((random() < 0.8) && vlen2(it.origin - this.origin) > vlen2(newgoal.origin - this.origin)))
573 this.ignoregoal = this.goalcurrent;
574 this.ignoregoaltime = time + autocvar_bot_ai_ignoregoal_timeout;
575 navigation_clearroute(this);
576 navigation_routetogoal(this, newgoal, this.origin);
577 if(autocvar_bot_debug_goalstack)
578 debuggoalstack(this);
579 this.aistatus &= ~AI_STATUS_OUT_JUMPPAD;
584 if (this.goalcurrent.bot_pickup)
586 entity jumppad_wp = this.goalcurrent_prev;
587 navigation_poptouchedgoals(this);
588 if(!this.goalcurrent && jumppad_wp.wp00)
590 // head to the jumppad destination once bot reaches the goal item
591 navigation_pushroute(this, jumppad_wp.wp00);
594 gco = (this.goalcurrent.absmin + this.goalcurrent.absmax) * 0.5;
595 if (this.origin.z > gco.z && vdist(vec2(this.velocity), <, autocvar_sv_maxspeed))
596 this.aistatus &= ~AI_STATUS_OUT_JUMPPAD;
597 else if(havocbot_checkgoaldistance(this, gco))
599 navigation_clearroute(this);
600 navigation_goalrating_timeout_force(this);
608 if(time - this.lastteleporttime > 0.2 && this.velocity.z > 0)
610 vector velxy = this.velocity; velxy_z = 0;
611 if(vdist(velxy, <, autocvar_sv_maxspeed * 0.2))
613 LOG_TRACE("Warning: ", this.netname, " got stuck on a jumppad (velocity in xy is ", vtos(velxy), "), trying to get out of it now");
614 this.aistatus |= AI_STATUS_OUT_JUMPPAD;
619 // Don't chase players while using a jump pad
620 if(IS_PLAYER(this.goalcurrent) || IS_PLAYER(this.goalstack01))
624 else if(this.aistatus & AI_STATUS_OUT_JUMPPAD)
625 this.aistatus &= ~AI_STATUS_OUT_JUMPPAD;
627 // If there is a trigger_hurt right below try to use the jetpack or make a rocketjump
628 if (skill > 6 && !(IS_ONGROUND(this)))
630 #define ROCKETJUMP_DAMAGE() WEP_CVAR(devastator, damage) * 0.8 \
631 * ((this.strength_finished > time) ? autocvar_g_balance_powerup_strength_selfdamage : 1) \
632 * ((this.invincible_finished > time) ? autocvar_g_balance_powerup_invincible_takedamage : 1)
634 tracebox(this.origin, this.mins, this.maxs, this.origin + '0 0 -65536', MOVE_NOMONSTERS, this);
635 if(tracebox_hits_trigger_hurt(this.origin, this.mins, this.maxs, trace_endpos ))
636 if(this.items & IT_JETPACK)
638 tracebox(this.origin, this.mins, this.maxs, this.origin + '0 0 65536', MOVE_NOMONSTERS, this);
639 if(tracebox_hits_trigger_hurt(this.origin, this.mins, this.maxs, trace_endpos + '0 0 1' ))
641 if(this.velocity.z<0)
642 PHYS_INPUT_BUTTON_JETPACK(this) = true;
645 PHYS_INPUT_BUTTON_JETPACK(this) = true;
647 // If there is no goal try to move forward
649 if(this.goalcurrent==NULL)
652 dir = normalize(( ( this.goalcurrent.absmin + this.goalcurrent.absmax ) * 0.5 ) - this.origin);
654 vector xyvelocity = this.velocity; xyvelocity_z = 0;
655 float xyspeed = xyvelocity * dir;
657 if(xyspeed < (maxspeed / 2))
659 makevectors(this.v_angle.y * '0 1 0');
660 tracebox(this.origin, this.mins, this.maxs, this.origin + (dir * maxspeed * 3), MOVE_NOMONSTERS, this);
661 if(trace_fraction==1)
663 CS(this).movement_x = dir * v_forward * maxspeed;
664 CS(this).movement_y = dir * v_right * maxspeed;
666 havocbot_keyboard_movement(this, this.origin + dir * 100);
670 this.havocbot_blockhead = true;
674 else if(this.health + this.armorvalue > ROCKETJUMP_DAMAGE())
676 if(this.velocity.z < 0)
678 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
680 .entity weaponentity = weaponentities[slot];
682 if(this.(weaponentity).m_weapon == WEP_Null && slot != 0)
685 if(client_hasweapon(this, WEP_DEVASTATOR, weaponentity, true, false))
687 CS(this).movement_x = maxspeed;
689 if(this.rocketjumptime)
691 if(time > this.rocketjumptime)
693 PHYS_INPUT_BUTTON_ATCK2(this) = true;
694 this.rocketjumptime = 0;
699 this.(weaponentity).m_switchweapon = WEP_DEVASTATOR;
701 PHYS_INPUT_BUTTON_ATCK(this) = true;
702 this.rocketjumptime = time + WEP_CVAR(devastator, detonatedelay);
710 // If there is no goal try to move forward
711 if(this.goalcurrent==NULL)
712 CS(this).movement_x = maxspeed;
716 // If we are under water with no goals, swim up
718 if(this.goalcurrent==NULL)
721 if(this.waterlevel>WATERLEVEL_SWIMMING)
723 else if(this.velocity.z >= 0 && !(this.waterlevel == WATERLEVEL_WETFEET && this.watertype == CONTENT_WATER))
724 PHYS_INPUT_BUTTON_JUMP(this) = true;
726 PHYS_INPUT_BUTTON_JUMP(this) = false;
727 makevectors(this.v_angle.y * '0 1 0');
728 CS(this).movement_x = dir * v_forward * maxspeed;
729 CS(this).movement_y = dir * v_right * maxspeed;
730 CS(this).movement_z = dir * v_up * maxspeed;
733 // if there is nowhere to go, exit
734 if (this.goalcurrent == NULL)
738 bool locked_goal = false;
739 if(this.goalentity && wasfreed(this.goalentity))
741 navigation_clearroute(this);
742 navigation_goalrating_timeout_force(this);
745 else if(this.goalentity.bot_pickup)
747 if(this.goalentity.bot_pickup_respawning)
749 if(this.goalentity.solid) // item respawned
750 this.goalentity.bot_pickup_respawning = false;
751 else if(time < this.goalentity.scheduledrespawntime - 10) // item already taken (by someone else)
753 if(checkpvs(this.origin, this.goalentity))
755 this.goalentity.bot_pickup_respawning = false;
756 navigation_clearroute(this);
757 navigation_goalrating_timeout_force(this);
760 locked_goal = true; // wait for item to respawn
762 else if(this.goalentity == this.goalcurrent)
763 locked_goal = true; // wait for item to respawn
765 else if(!this.goalentity.solid && !boxesoverlap(this.goalentity.absmin, this.goalentity.absmax, this.absmin, this.absmax))
767 if(checkpvs(this.origin, this.goalentity))
769 navigation_clearroute(this);
770 navigation_goalrating_timeout_force(this);
775 if (this.goalcurrent == this.goalentity && this.goalentity_lock_timeout > time)
780 // optimize path finding by anticipating goalrating when bot is near a waypoint;
781 // in this case path finding can start directly from a waypoint instead of
782 // looking for all the reachable waypoints up to a certain distance
783 if(navigation_poptouchedgoals(this) && this.goalcurrent)
785 if(navigation_goalrating_timeout_can_be_anticipated(this))
786 navigation_goalrating_timeout_force(this);
790 // if ran out of goals try to use an alternative goal or get a new strategy asap
791 if(this.goalcurrent == NULL)
793 navigation_goalrating_timeout_force(this);
798 if(autocvar_bot_debug_goalstack)
799 debuggoalstack(this);
801 bool bunnyhop_forbidden = false;;
802 SET_DESTCOORDS(this.goalcurrent, this.origin, destorg);
804 // in case bot ends up inside the teleport waypoint without touching
805 // the teleport itself, head to the teleport origin
806 if(this.goalcurrent.wpisbox && boxesoverlap(this.goalcurrent.absmin, this.goalcurrent.absmax, this.origin + eZ * this.mins.z, this.origin + eZ * this.maxs.z))
808 bunnyhop_forbidden = true;
809 destorg = this.goalcurrent.origin;
810 if(destorg.z > this.origin.z)
811 PHYS_INPUT_BUTTON_JUMP(this) = true;
814 diff = destorg - this.origin;
816 if (fabs(diff.x) < 10 && fabs(diff.y) < 10
817 && this.goalcurrent == this.goalentity && time < this.goalentity_lock_timeout)
819 destorg = this.origin;
824 dir = normalize(diff);
825 flatdir = diff;flatdir.z = 0;
826 flatdir = normalize(flatdir);
827 gco = (this.goalcurrent.absmin + this.goalcurrent.absmax) * 0.5;
829 //if (this.bot_dodgevector_time < time)
831 //this.bot_dodgevector_time = time + cvar("bot_ai_dodgeupdateinterval");
832 //this.bot_dodgevector_jumpbutton = 1;
833 evadeobstacle = '0 0 0';
836 this.aistatus &= ~AI_STATUS_DANGER_AHEAD;
837 makevectors(this.v_angle.y * '0 1 0');
840 if(this.waterlevel>WATERLEVEL_SWIMMING)
842 if(!this.goalcurrent)
843 this.aistatus |= AI_STATUS_OUT_WATER;
844 else if(gco.z > this.origin.z)
845 PHYS_INPUT_BUTTON_JUMP(this) = true;
850 if(this.velocity.z >= 0 && !(this.watertype == CONTENT_WATER && gco.z < this.origin.z) &&
851 ( !(this.waterlevel == WATERLEVEL_WETFEET && this.watertype == CONTENT_WATER) || this.aistatus & AI_STATUS_OUT_WATER))
852 PHYS_INPUT_BUTTON_JUMP(this) = true;
854 PHYS_INPUT_BUTTON_JUMP(this) = false;
861 if(this.aistatus & AI_STATUS_OUT_WATER)
862 this.aistatus &= ~AI_STATUS_OUT_WATER;
864 // jump if going toward an obstacle that doesn't look like stairs we
865 // can walk up directly
866 offset = (vdist(this.velocity, >, 32) ? this.velocity * 0.2 : v_forward * 32);
867 tracebox(this.origin, this.mins, this.maxs, this.origin + offset, false, this);
868 if (trace_fraction < 1)
869 if (trace_plane_normal.z < 0.7)
872 tracebox(this.origin + stepheightvec, this.mins, this.maxs, this.origin + offset + stepheightvec, false, this);
873 if (trace_fraction < s + 0.01)
874 if (trace_plane_normal.z < 0.7)
877 tracebox(this.origin + jumpstepheightvec, this.mins, this.maxs, this.origin + offset + jumpstepheightvec, false, this);
878 if (trace_fraction > s)
879 PHYS_INPUT_BUTTON_JUMP(this) = true;
883 // if bot for some reason doesn't get close to the current goal find another one
884 if(!this.jumppadcount && !IS_PLAYER(this.goalcurrent))
885 if(!(locked_goal && this.goalcurrent_distance_z < 50 && this.goalcurrent_distance_2d < 50))
886 if(havocbot_checkgoaldistance(this, gco))
888 if(this.goalcurrent_distance_time < 0) // can't get close for the second time
890 navigation_clearroute(this);
891 navigation_goalrating_timeout_force(this);
895 vector dest = '0 0 0';
896 float dest_height = 0;
897 SET_TRACEWALK_DESTCOORDS(this.goalcurrent, this.origin, dest, dest_height);
898 if (!tracewalk(this, this.origin, this.mins, this.maxs, dest, dest_height, bot_navigation_movemode))
900 navigation_clearroute(this);
901 navigation_goalrating_timeout_force(this);
905 // give bot only another chance to prevent bot getting stuck
906 // in case it thinks it can walk but actually can't
907 this.goalcurrent_distance_z = FLOAT_MAX;
908 this.goalcurrent_distance_2d = FLOAT_MAX;
909 this.goalcurrent_distance_time = -time; // mark second try
912 // Check for water/slime/lava and dangerous edges
913 // (only when the bot is on the ground or jumping intentionally)
915 vector dst_ahead = this.origin + this.view_ofs + offset;
916 vector dst_down = dst_ahead - '0 0 3000';
917 traceline(this.origin + this.view_ofs, dst_ahead, true, NULL);
919 bool unreachable = false;
921 if(trace_fraction == 1 && this.jumppadcount == 0 && !this.goalcurrent.wphardwired )
922 if((IS_ONGROUND(this)) || (this.aistatus & AI_STATUS_RUNNING) || (this.aistatus & AI_STATUS_ROAMING) || PHYS_INPUT_BUTTON_JUMP(this))
925 traceline(dst_ahead , dst_down, true, NULL);
926 //te_lightning2(NULL, this.origin + this.view_ofs, dst_ahead); // Draw "ahead" look
927 //te_lightning2(NULL, dst_ahead, dst_down); // Draw "downwards" look
928 if(trace_endpos.z < this.origin.z + this.mins.z)
930 s = pointcontents(trace_endpos + '0 0 1');
931 if (s != CONTENT_SOLID)
932 if (s == CONTENT_LAVA || s == CONTENT_SLIME)
933 evadelava = normalize(this.velocity) * -1;
934 else if (s == CONTENT_SKY)
935 evadeobstacle = normalize(this.velocity) * -1;
936 else if (tracebox_hits_trigger_hurt(dst_ahead, this.mins, this.maxs, trace_endpos))
938 // the traceline check isn't enough but is good as optimization,
939 // when not true (most of the time) this tracebox call is avoided
940 tracebox(dst_ahead, this.mins, this.maxs, dst_down, true, this);
941 if (tracebox_hits_trigger_hurt(dst_ahead, this.mins, this.maxs, trace_endpos))
943 if (gco.z > this.origin.z + jumpstepheightvec.z)
945 // the goal is probably on an upper platform, assume bot can't get there
949 evadelava = normalize(this.velocity) * -1;
958 makevectors(this.v_angle.y * '0 1 0');
960 if(evadeobstacle || evadelava || (s == CONTENT_WATER))
962 this.aistatus |= AI_STATUS_DANGER_AHEAD;
963 if(IS_PLAYER(this.goalcurrent))
968 navigation_clearroute(this);
969 navigation_goalrating_timeout_force(this);
973 dodge = havocbot_dodge(this);
974 dodge = dodge * bound(0,0.5+(skill+this.bot_dodgeskill)*0.1,1);
975 evadelava = evadelava * bound(1,3-(skill+this.bot_dodgeskill),3); //Noobs fear lava a lot and take more distance from it
976 traceline(this.origin, ( ( this.enemy.absmin + this.enemy.absmax ) * 0.5 ), true, NULL);
977 if(IS_PLAYER(trace_ent))
978 dir = dir * bound(0,(skill+this.bot_dodgeskill)/7,1);
980 dir = normalize(dir + dodge + evadeobstacle + evadelava);
981 // this.bot_dodgevector = dir;
982 // this.bot_dodgevector_jumpbutton = PHYS_INPUT_BUTTON_JUMP(this);
985 if(time < this.ladder_time)
987 if(this.goalcurrent.origin.z + this.goalcurrent.mins.z > this.origin.z + this.mins.z)
989 if(this.origin.z + this.mins.z < this.ladder_entity.origin.z + this.ladder_entity.maxs.z)
994 if(this.origin.z + this.mins.z > this.ladder_entity.origin.z + this.ladder_entity.mins.z)
999 //dir = this.bot_dodgevector;
1000 //if (this.bot_dodgevector_jumpbutton)
1001 // PHYS_INPUT_BUTTON_JUMP(this) = true;
1002 CS(this).movement_x = dir * v_forward * maxspeed;
1003 CS(this).movement_y = dir * v_right * maxspeed;
1004 CS(this).movement_z = dir * v_up * maxspeed;
1006 // Emulate keyboard interface
1008 havocbot_keyboard_movement(this, destorg);
1011 //if(this.aistatus & AI_STATUS_ROAMING)
1012 if(!bunnyhop_forbidden && this.goalcurrent)
1013 if(skill+this.bot_moveskill >= autocvar_bot_ai_bunnyhop_skilloffset)
1014 havocbot_bunnyhop(this, dir);
1016 if ((dir * v_up) >= autocvar_sv_jumpvelocity*0.5 && (IS_ONGROUND(this))) PHYS_INPUT_BUTTON_JUMP(this) = true;
1017 if (((dodge * v_up) > 0) && random()*frametime >= 0.2*bound(0,(10-skill-this.bot_dodgeskill)*0.1,1)) PHYS_INPUT_BUTTON_JUMP(this) = true;
1018 if (((dodge * v_up) < 0) && random()*frametime >= 0.5*bound(0,(10-skill-this.bot_dodgeskill)*0.1,1)) this.havocbot_ducktime=time+0.3/bound(0.1,skill+this.bot_dodgeskill,10);
1021 entity havocbot_gettarget(entity this, bool secondary)
1024 vector eye = CENTER_OR_VIEWOFS(this);
1025 IL_EACH(g_bot_targets, boolean((secondary) ? it.classname == "misc_breakablemodel" : it.classname != "misc_breakablemodel"),
1027 vector v = CENTER_OR_VIEWOFS(it);
1028 if(vdist(v - eye, <, autocvar_bot_ai_enemydetectionradius))
1029 if(!best || vlen2(CENTER_OR_VIEWOFS(best) - eye) > vlen2(v - eye))
1030 if(bot_shouldattack(this, it))
1032 traceline(eye, v, true, this);
1033 if (trace_ent == it || trace_fraction >= 1)
1041 void havocbot_chooseenemy(entity this)
1043 if (autocvar_bot_nofire || IS_INDEPENDENT_PLAYER(this))
1050 if (!bot_shouldattack(this, this.enemy))
1052 // enemy died or something, find a new target
1054 this.havocbot_chooseenemy_finished = time;
1056 else if (this.havocbot_stickenemy)
1058 // tracking last chosen enemy
1059 // if enemy is visible
1060 // and not really really far away
1061 // and we're not severely injured
1062 // then keep tracking for a half second into the future
1063 traceline(this.origin+this.view_ofs, ( this.enemy.absmin + this.enemy.absmax ) * 0.5,false,NULL);
1064 if (trace_ent == this.enemy || trace_fraction == 1)
1065 if (vdist(((this.enemy.absmin + this.enemy.absmax) * 0.5) - this.origin, <, 1000))
1066 if (this.health > 30)
1068 // remain tracking him for a shot while (case he went after a small corner or pilar
1069 this.havocbot_chooseenemy_finished = time + 0.5;
1072 // enemy isn't visible, or is far away, or we're injured severely
1073 // so stop preferring this enemy
1074 // (it will still take a half second until a new one is chosen)
1075 this.havocbot_stickenemy = 0;
1078 if (time < this.havocbot_chooseenemy_finished)
1080 this.havocbot_chooseenemy_finished = time + autocvar_bot_ai_enemydetectioninterval;
1081 vector eye = this.origin + this.view_ofs;
1083 float bestrating = 100000000;
1086 int hf = this.dphitcontentsmask;
1088 // Search for enemies, if no enemy can be seen directly try to look through transparent objects
1090 this.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
1092 bool scan_transparent = false;
1093 bool scan_secondary_targets = false;
1094 bool have_secondary_targets = false;
1097 scan_secondary_targets = false;
1099 IL_EACH(g_bot_targets, it.bot_attack,
1101 if(!scan_secondary_targets)
1103 if(it.classname == "misc_breakablemodel")
1105 have_secondary_targets = true;
1109 else if(it.classname != "misc_breakablemodel")
1112 vector v = (it.absmin + it.absmax) * 0.5;
1113 float rating = vlen2(v - eye);
1114 if (vdist(v - eye, <, autocvar_bot_ai_enemydetectionradius))
1115 if (bestrating > rating)
1116 if (bot_shouldattack(this, it))
1118 traceline(eye, v, true, this);
1119 if (trace_ent == it || trace_fraction >= 1)
1122 bestrating = rating;
1127 if(!best && have_secondary_targets && !scan_secondary_targets)
1129 scan_secondary_targets = true;
1131 bestrating = 100000000;
1135 // I want to do a second scan if no enemy was found or I don't have weapons
1136 // TODO: Perform the scan when using the rifle (requires changes on the rifle code)
1137 if(best || this.weapons) // || this.weapon == WEP_RIFLE.m_id
1139 if(scan_transparent)
1142 // Set flags to see through transparent objects
1143 this.dphitcontentsmask |= DPCONTENTS_OPAQUE;
1145 scan_transparent = true;
1148 // Restore hit flags
1149 this.dphitcontentsmask = hf;
1152 this.havocbot_stickenemy = true;
1153 if(best && best.classname == "misc_breakablemodel")
1154 this.havocbot_stickenemy = false;
1157 float havocbot_chooseweapon_checkreload(entity this, .entity weaponentity, int new_weapon)
1159 // bots under this skill cannot find unloaded weapons to reload idly when not in combat,
1160 // so skip this for them, or they'll never get to reload their weapons at all.
1161 // this also allows bots under this skill to be more stupid, and reload more often during combat :)
1165 // if this weapon is scheduled for reloading, don't switch to it during combat
1166 if (this.(weaponentity).weapon_load[new_weapon] < 0)
1168 FOREACH(Weapons, it != WEP_Null, {
1169 if(it.wr_checkammo1(it, this, weaponentity) + it.wr_checkammo2(it, this, weaponentity))
1170 return true; // other weapon available
1177 void havocbot_chooseweapon(entity this, .entity weaponentity)
1182 if(g_weaponarena_weapons == WEPSET(TUBA))
1184 this.(weaponentity).m_switchweapon = WEP_TUBA;
1188 // TODO: clean this up by moving it to weapon code
1189 if(this.enemy==NULL)
1191 // If no weapon was chosen get the first available weapon
1192 if(this.(weaponentity).m_weapon==WEP_Null)
1193 FOREACH(Weapons, it != WEP_Null, {
1194 if(client_hasweapon(this, it, weaponentity, true, false))
1196 this.(weaponentity).m_switchweapon = it;
1203 // Do not change weapon during the next second after a combo
1204 float f = time - this.lastcombotime;
1209 float distance; distance=bound(10,vlen(this.origin-this.enemy.origin)-200,10000);
1211 // Should it do a weapon combo?
1212 float af, ct, combo_time, combo;
1214 af = ATTACK_FINISHED(this, 0);
1215 ct = autocvar_bot_ai_weapon_combo_threshold;
1217 // Bots with no skill will be 4 times more slower than "godlike" bots when doing weapon combos
1218 // Ideally this 4 should be calculated as longest_weapon_refire / bot_ai_weapon_combo_threshold
1219 combo_time = time + ct + (ct * ((-0.3*(skill+this.bot_weaponskill))+3));
1223 if(autocvar_bot_ai_weapon_combo)
1224 if(this.(weaponentity).m_weapon.m_id == this.(weaponentity).lastfiredweapon)
1228 this.lastcombotime = time;
1231 distance *= (2 ** this.bot_rangepreference);
1233 // Custom weapon list based on distance to the enemy
1234 if(bot_custom_weapon){
1236 // Choose weapons for far distance
1237 if ( distance > bot_distance_far ) {
1238 for(i=0; i < Weapons_COUNT && bot_weapons_far[i] != -1 ; ++i){
1239 w = bot_weapons_far[i];
1240 if ( client_hasweapon(this, Weapons_from(w), weaponentity, true, false) )
1242 if ((this.(weaponentity).m_weapon.m_id == w && combo) || havocbot_chooseweapon_checkreload(this, weaponentity, w))
1244 this.(weaponentity).m_switchweapon = Weapons_from(w);
1250 // Choose weapons for mid distance
1251 if ( distance > bot_distance_close) {
1252 for(i=0; i < Weapons_COUNT && bot_weapons_mid[i] != -1 ; ++i){
1253 w = bot_weapons_mid[i];
1254 if ( client_hasweapon(this, Weapons_from(w), weaponentity, true, false) )
1256 if ((this.(weaponentity).m_weapon.m_id == w && combo) || havocbot_chooseweapon_checkreload(this, weaponentity, w))
1258 this.(weaponentity).m_switchweapon = Weapons_from(w);
1264 // Choose weapons for close distance
1265 for(i=0; i < Weapons_COUNT && bot_weapons_close[i] != -1 ; ++i){
1266 w = bot_weapons_close[i];
1267 if ( client_hasweapon(this, Weapons_from(w), weaponentity, true, false) )
1269 if ((this.(weaponentity).m_weapon.m_id == w && combo) || havocbot_chooseweapon_checkreload(this, weaponentity, w))
1271 this.(weaponentity).m_switchweapon = Weapons_from(w);
1278 void havocbot_aim(entity this)
1280 if (time < this.nextaim)
1282 this.nextaim = time + 0.1;
1283 vector myvel = this.velocity;
1284 if (!this.waterlevel)
1286 if(MUTATOR_CALLHOOK(HavocBot_Aim, this)) { /* do nothing */ }
1287 else if (this.enemy)
1289 vector enemyvel = this.enemy.velocity;
1290 if (!this.enemy.waterlevel)
1292 lag_additem(this, time + CS(this).ping, 0, 0, this.enemy, this.origin, myvel, (this.enemy.absmin + this.enemy.absmax) * 0.5, enemyvel);
1295 lag_additem(this, time + CS(this).ping, 0, 0, NULL, this.origin, myvel, ( this.goalcurrent.absmin + this.goalcurrent.absmax ) * 0.5, '0 0 0');
1298 bool havocbot_moveto_refresh_route(entity this)
1300 // Refresh path to goal if necessary
1302 wp = this.havocbot_personal_waypoint;
1303 navigation_goalrating_start(this);
1304 navigation_routerating(this, wp, 10000, 10000);
1305 navigation_goalrating_end(this);
1306 return (this.goalentity != NULL);
1309 float havocbot_moveto(entity this, vector pos)
1313 if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
1315 // Step 4: Move to waypoint
1316 if(this.havocbot_personal_waypoint==NULL)
1318 LOG_TRACE("Error: ", this.netname, " trying to walk to a non existent personal waypoint");
1319 this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_GOING;
1320 return CMD_STATUS_ERROR;
1323 if (!bot_strategytoken_taken)
1324 if(this.havocbot_personal_waypoint_searchtime<time)
1326 bot_strategytoken_taken = true;
1327 if(havocbot_moveto_refresh_route(this))
1329 LOG_TRACE(this.netname, " walking to its personal waypoint (after ", ftos(this.havocbot_personal_waypoint_failcounter), " failed attempts)");
1330 this.havocbot_personal_waypoint_searchtime = time + 10;
1331 this.havocbot_personal_waypoint_failcounter = 0;
1335 this.havocbot_personal_waypoint_failcounter += 1;
1336 this.havocbot_personal_waypoint_searchtime = time + 2;
1337 if(this.havocbot_personal_waypoint_failcounter >= 30)
1339 LOG_TRACE("Warning: can't walk to the personal waypoint located at ", vtos(this.havocbot_personal_waypoint.origin));
1340 this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_LINKING;
1341 delete(this.havocbot_personal_waypoint);
1342 return CMD_STATUS_ERROR;
1345 LOG_TRACE(this.netname, " can't walk to its personal waypoint (after ", ftos(this.havocbot_personal_waypoint_failcounter), " failed attempts), trying later");
1349 if(autocvar_bot_debug_goalstack)
1350 debuggoalstack(this);
1353 vector dir = '0 0 0';
1354 SET_DESTCOORDS(this.goalcurrent, this.origin, dir);
1355 dir = dir - (this.origin + this.view_ofs);
1357 bot_aimdir(this, dir, -1);
1360 havocbot_movetogoal(this);
1362 if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_REACHED)
1364 // Step 5: Waypoint reached
1365 LOG_TRACE(this.netname, "'s personal waypoint reached");
1366 delete(this.havocbot_personal_waypoint);
1367 this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_REACHED;
1368 return CMD_STATUS_FINISHED;
1371 return CMD_STATUS_EXECUTING;
1374 // Step 2: Linking waypoint
1375 if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_LINKING)
1377 // Wait until it is linked
1378 if(!this.havocbot_personal_waypoint.wplinked)
1380 LOG_TRACE(this.netname, " waiting for personal waypoint to be linked");
1381 return CMD_STATUS_EXECUTING;
1384 this.havocbot_personal_waypoint_searchtime = time; // so we set the route next frame
1385 this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_LINKING;
1386 this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_GOING;
1388 // Step 3: Route to waypoint
1389 LOG_TRACE(this.netname, " walking to its personal waypoint");
1391 return CMD_STATUS_EXECUTING;
1394 // Step 1: Spawning waypoint
1395 wp = waypoint_spawnpersonal(this, pos);
1398 LOG_TRACE("Error: Can't spawn personal waypoint at ",vtos(pos));
1399 return CMD_STATUS_ERROR;
1402 this.havocbot_personal_waypoint = wp;
1403 this.havocbot_personal_waypoint_failcounter = 0;
1404 this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_LINKING;
1406 // if pos is inside a teleport, then let's mark it as teleport waypoint
1407 IL_EACH(g_teleporters, WarpZoneLib_BoxTouchesBrush(pos, pos, it, NULL),
1409 wp.wpflags |= WAYPOINTFLAG_TELEPORT;
1410 this.lastteleporttime = 0;
1414 if(wp.wpflags & WAYPOINTFLAG_TELEPORT)
1415 print("routing to a teleporter\n");
1417 print("routing to a non-teleporter\n");
1420 return CMD_STATUS_EXECUTING;
1423 float havocbot_resetgoal(entity this)
1425 navigation_clearroute(this);
1426 return CMD_STATUS_FINISHED;
1429 void havocbot_setupbot(entity this)
1431 this.bot_ai = havocbot_ai;
1432 this.cmd_moveto = havocbot_moveto;
1433 this.cmd_resetgoal = havocbot_resetgoal;
1435 havocbot_chooserole(this);
1438 vector havocbot_dodge(entity this)
1440 // LordHavoc: disabled because this is too expensive
1445 float danger, bestdanger, vl, d;
1448 // check for dangerous objects near bot or approaching bot
1449 head = findchainfloat(bot_dodge, true);
1452 if (head.owner != this)
1454 vl = vlen(head.velocity);
1455 if (vl > autocvar_sv_maxspeed * 0.3)
1457 n = normalize(head.velocity);
1458 v = this.origin - head.origin;
1460 if (d > (0 - head.bot_dodgerating))
1461 if (d < (vl * 0.2 + head.bot_dodgerating))
1463 // calculate direction and distance from the flight path, by removing the forward axis
1464 v = v - (n * (v * n));
1465 danger = head.bot_dodgerating - vlen(v);
1466 if (bestdanger < danger)
1468 bestdanger = danger;
1469 // dodge to the side of the object
1470 dodge = normalize(v);
1476 danger = head.bot_dodgerating - vlen(head.origin - this.origin);
1477 if (bestdanger < danger)
1479 bestdanger = danger;
1480 dodge = normalize(this.origin - head.origin);