2 #include "role_onslaught.qc"
3 #include "role_keyhunt.qc"
5 #include "../../../common/triggers/trigger/jumppads.qh"
12 if(bot_execute_commands())
15 if (bot_strategytoken == self)
16 if (!bot_strategytoken_taken)
18 if(self.havocbot_blockhead)
20 self.havocbot_blockhead = false;
24 if (!self.jumppadcount)
28 // TODO: tracewalk() should take care of this job (better path finding under water)
29 // if we don't have a goal and we're under water look for a waypoint near the "shore" and push it
30 if(self.deadflag != DEAD_NO)
31 if(self.goalcurrent==world)
32 if(self.waterlevel==WATERLEVEL_SWIMMING || (self.aistatus & AI_STATUS_OUT_WATER))
34 // Look for the closest waypoint out of water
36 float bestdistance, distance;
40 for (head = findchain(classname, "waypoint"); head; head = head.chain)
42 distance = vlen(head.origin - self.origin);
46 if(head.origin.z < self.origin.z)
49 if(head.origin.z - self.origin.z - self.view_ofs.z > 100)
52 if (pointcontents(head.origin + head.maxs + '0 0 1') != CONTENT_EMPTY)
55 traceline(self.origin + self.view_ofs , head.origin, true, head);
60 if(distance<bestdistance)
63 bestdistance = distance;
69 // te_wizspike(newgoal.origin);
70 navigation_pushroute(newgoal);
74 // token has been used this frame
75 bot_strategytoken_taken = true;
78 if(self.deadflag != DEAD_NO)
81 havocbot_chooseenemy();
82 if (self.bot_chooseweapontime < time )
84 self.bot_chooseweapontime = time + autocvar_bot_ai_chooseweaponinterval;
85 havocbot_chooseweapon();
91 self.aistatus |= AI_STATUS_ATTACKING;
92 self.aistatus &= ~AI_STATUS_ROAMING;
96 WEP_ACTION(self.weapon, WR_AIM);
97 if (autocvar_bot_nofire || IS_INDEPENDENT_PLAYER(self))
99 self.BUTTON_ATCK = false;
100 self.BUTTON_ATCK2 = false;
104 if(self.BUTTON_ATCK||self.BUTTON_ATCK2)
105 self.lastfiredweapon = self.weapon;
110 if(IS_PLAYER(self.bot_aimtarg))
111 bot_aimdir(self.bot_aimtarg.origin + self.bot_aimtarg.view_ofs - self.origin - self.view_ofs , -1);
114 else if (self.goalcurrent)
116 self.aistatus |= AI_STATUS_ROAMING;
117 self.aistatus &= ~AI_STATUS_ATTACKING;
119 vector now,v,next;//,heading;
120 float aimdistance,skillblend,distanceblend,blend;
121 next = now = ( (self.goalcurrent.absmin + self.goalcurrent.absmax) * 0.5) - (self.origin + self.view_ofs);
122 aimdistance = vlen(now);
123 //heading = self.velocity;
124 //dprint(self.goalstack01.classname,etos(self.goalstack01),"\n");
126 self.goalstack01 != self && self.goalstack01 != world && ((self.aistatus & AI_STATUS_RUNNING) == 0) &&
127 !(self.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
129 next = ((self.goalstack01.absmin + self.goalstack01.absmax) * 0.5) - (self.origin + self.view_ofs);
131 skillblend=bound(0,(skill+self.bot_moveskill-2.5)*0.5,1); //lower skill player can't preturn
132 distanceblend=bound(0,aimdistance/autocvar_bot_ai_keyboard_distance,1);
133 blend = skillblend * (1-distanceblend);
134 //v = (now * (distanceblend) + next * (1-distanceblend)) * (skillblend) + now * (1-skillblend);
135 //v = now * (distanceblend) * (skillblend) + next * (1-distanceblend) * (skillblend) + now * (1-skillblend);
136 //v = now * ((1-skillblend) + (distanceblend) * (skillblend)) + next * (1-distanceblend) * (skillblend);
137 v = now + blend * (next - now);
138 //dprint(etos(self), " ");
139 //dprint(vtos(now), ":", vtos(next), "=", vtos(v), " (blend ", ftos(blend), ")\n");
140 //v = now * (distanceblend) + next * (1-distanceblend);
141 if (self.waterlevel < WATERLEVEL_SWIMMING)
143 //dprint("walk at:", vtos(v), "\n");
144 //te_lightning2(world, self.origin, self.goalcurrent.origin);
147 havocbot_movetogoal();
149 // if the bot is not attacking, consider reloading weapons
150 if (!(self.aistatus & AI_STATUS_ATTACKING))
155 // we are currently holding a weapon that's not fully loaded, reload it
156 if(skill >= 2) // bots can only reload the held weapon on purpose past this skill
157 if(self.clip_load < self.clip_size)
158 self.impulse = 20; // "press" the reload button, not sure if this is done right
160 // if we're not reloading a weapon, switch to any weapon in our invnetory that's not fully loaded to reload it next
161 // the code above executes next frame, starting the reloading then
162 if(skill >= 5) // bots can only look for unloaded weapons past this skill
163 if(self.clip_load >= 0) // only if we're not reloading a weapon already
165 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
167 e = get_weaponinfo(i);
168 if ((self.weapons & WepSet_FromWeapon(i)) && (e.spawnflags & WEP_FLAG_RELOADABLE) && (self.weapon_load[i] < e.reloading_ammo))
169 self.switchweapon = i;
175 void havocbot_keyboard_movement(vector destorg)
178 float blend, maxspeed;
181 sk = skill + self.bot_moveskill;
183 maxspeed = autocvar_sv_maxspeed;
185 if (time < self.havocbot_keyboardtime)
188 self.havocbot_keyboardtime =
190 self.havocbot_keyboardtime
191 + 0.05/max(1, sk+self.havocbot_keyboardskill)
192 + random()*0.025/max(0.00025, skill+self.havocbot_keyboardskill)
194 keyboard = self.movement * (1.0 / maxspeed);
196 float trigger, trigger1;
197 blend = bound(0,sk*0.1,1);
198 trigger = autocvar_bot_ai_keyboard_threshold;
199 trigger1 = 0 - trigger;
201 // categorize forward movement
202 // at skill < 1.5 only forward
203 // at skill < 2.5 only individual directions
204 // at skill < 4.5 only individual directions, and forward diagonals
205 // at skill >= 4.5, all cases allowed
206 if (keyboard.x > trigger)
212 else if (keyboard.x < trigger1 && sk > 1.5)
227 if (keyboard.y > trigger)
229 else if (keyboard.y < trigger1)
234 if (keyboard.z > trigger)
236 else if (keyboard.z < trigger1)
241 self.havocbot_keyboard = keyboard * maxspeed;
242 if (self.havocbot_ducktime>time) self.BUTTON_CROUCH=true;
244 keyboard = self.havocbot_keyboard;
245 blend = bound(0,vlen(destorg-self.origin)/autocvar_bot_ai_keyboard_distance,1); // When getting close move with 360 degree
246 //dprint("movement ", vtos(self.movement), " keyboard ", vtos(keyboard), " blend ", ftos(blend), "\n");
247 self.movement = self.movement + (keyboard - self.movement) * blend;
250 void havocbot_bunnyhop(vector dir)
252 float bunnyhopdistance;
257 // Don't jump when attacking
258 if(self.aistatus & AI_STATUS_ATTACKING)
261 if(IS_PLAYER(self.goalcurrent))
264 maxspeed = autocvar_sv_maxspeed;
266 if(self.aistatus & AI_STATUS_DANGER_AHEAD)
268 self.aistatus &= ~AI_STATUS_RUNNING;
269 self.BUTTON_JUMP = false;
270 self.bot_canruntogoal = 0;
271 self.bot_timelastseengoal = 0;
275 if(self.waterlevel > WATERLEVEL_WETFEET)
277 self.aistatus &= ~AI_STATUS_RUNNING;
281 if(self.bot_lastseengoal != self.goalcurrent && !(self.aistatus & AI_STATUS_RUNNING))
283 self.bot_canruntogoal = 0;
284 self.bot_timelastseengoal = 0;
287 gco = (self.goalcurrent.absmin + self.goalcurrent.absmax) * 0.5;
288 bunnyhopdistance = vlen(self.origin - gco);
290 // Run only to visible goals
291 if(self.flags & FL_ONGROUND)
292 if(self.speed==maxspeed)
293 if(checkpvs(self.origin + self.view_ofs, self.goalcurrent))
295 self.bot_lastseengoal = self.goalcurrent;
298 if(self.bot_timelastseengoal)
300 // for a period of time
301 if(time - self.bot_timelastseengoal > autocvar_bot_ai_bunnyhop_firstjumpdelay)
304 checkdistance = true;
306 // don't run if it is too close
307 if(self.bot_canruntogoal==0)
309 if(bunnyhopdistance > autocvar_bot_ai_bunnyhop_startdistance)
310 self.bot_canruntogoal = 1;
312 self.bot_canruntogoal = -1;
315 if(self.bot_canruntogoal != 1)
318 if(self.aistatus & AI_STATUS_ROAMING)
319 if(self.goalcurrent.classname=="waypoint")
320 if (!(self.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL))
321 if(fabs(gco.z - self.origin.z) < self.maxs.z - self.mins.z)
322 if(self.goalstack01!=world)
324 gno = (self.goalstack01.absmin + self.goalstack01.absmax) * 0.5;
325 deviation = vectoangles(gno - self.origin) - vectoangles(gco - self.origin);
326 while (deviation.y < -180) deviation.y = deviation.y + 360;
327 while (deviation.y > 180) deviation.y = deviation.y - 360;
329 if(fabs(deviation.y) < 20)
330 if(bunnyhopdistance < vlen(self.origin - gno))
331 if(fabs(gno.z - gco.z) < self.maxs.z - self.mins.z)
333 if(vlen(gco - gno) > autocvar_bot_ai_bunnyhop_startdistance)
334 if(checkpvs(self.origin + self.view_ofs, self.goalstack01))
336 checkdistance = false;
343 self.aistatus &= ~AI_STATUS_RUNNING;
344 if(bunnyhopdistance > autocvar_bot_ai_bunnyhop_stopdistance)
345 self.BUTTON_JUMP = true;
349 self.aistatus |= AI_STATUS_RUNNING;
350 self.BUTTON_JUMP = true;
356 self.bot_timelastseengoal = time;
361 self.bot_timelastseengoal = 0;
365 // Release jump button
366 if(!cvar("sv_pogostick"))
367 if((self.flags & FL_ONGROUND) == 0)
369 if(self.velocity.z < 0 || vlen(self.velocity)<maxspeed)
370 self.BUTTON_JUMP = false;
373 if(self.aistatus & AI_STATUS_RUNNING)
374 if(vlen(self.velocity)>maxspeed)
376 deviation = vectoangles(dir) - vectoangles(self.velocity);
377 while (deviation.y < -180) deviation.y = deviation.y + 360;
378 while (deviation.y > 180) deviation.y = deviation.y - 360;
380 if(fabs(deviation.y)>10)
384 self.movement_y = maxspeed * -1;
385 else if(deviation.y<10)
386 self.movement_y = maxspeed;
393 void havocbot_movetogoal()
401 vector evadeobstacle;
408 //if (self.goalentity)
409 // te_lightning2(self, self.origin, (self.goalentity.absmin + self.goalentity.absmax) * 0.5);
410 self.movement = '0 0 0';
411 maxspeed = autocvar_sv_maxspeed;
413 // Jetpack navigation
415 if(self.navigation_jetpack_goal)
416 if(self.goalcurrent==self.navigation_jetpack_goal)
419 if(autocvar_bot_debug_goalstack)
422 te_wizspike(self.navigation_jetpack_point);
426 if (!(self.aistatus & AI_STATUS_JETPACK_FLYING))
428 // Brake almost completely so it can get a good direction
429 if(vlen(self.velocity)>10)
431 self.aistatus |= AI_STATUS_JETPACK_FLYING;
434 makevectors(self.v_angle.y * '0 1 0');
435 dir = normalize(self.navigation_jetpack_point - self.origin);
438 if(self.aistatus & AI_STATUS_JETPACK_LANDING)
440 // Calculate brake distance in xy
444 dxy = self.origin - ( ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5 ); dxy.z = 0;
446 v = vlen(self.velocity - self.velocity.z * '0 0 1');
447 db = (pow(v,2) / (autocvar_g_jetpack_acceleration_side * 2)) + 100;
448 // dprint("distance ", ftos(ceil(d)), " velocity ", ftos(ceil(v)), " brake at ", ftos(ceil(db)), "\n");
449 if(d < db || d < 500)
452 if(fabs(self.velocity.x)>maxspeed*0.3)
454 self.movement_x = dir * v_forward * -maxspeed;
457 // Switch to normal mode
458 self.navigation_jetpack_goal = world;
459 self.aistatus &= ~AI_STATUS_JETPACK_LANDING;
460 self.aistatus &= ~AI_STATUS_JETPACK_FLYING;
464 else if(checkpvs(self.origin,self.goalcurrent))
466 // If I can see the goal switch to landing code
467 self.aistatus &= ~AI_STATUS_JETPACK_FLYING;
468 self.aistatus |= AI_STATUS_JETPACK_LANDING;
473 self.BUTTON_HOOK = true;
474 if(self.navigation_jetpack_point.z - PL_MAX.z + PL_MIN.z < self.origin.z)
476 self.movement_x = dir * v_forward * maxspeed;
477 self.movement_y = dir * v_right * maxspeed;
482 // Handling of jump pads
483 if(self.jumppadcount)
485 // If got stuck on the jump pad try to reach the farthest visible waypoint
486 if(self.aistatus & AI_STATUS_OUT_JUMPPAD)
488 if(fabs(self.velocity.z)<50)
490 entity head, newgoal = world;
491 float distance, bestdistance = 0;
493 for (head = findchain(classname, "waypoint"); head; head = head.chain)
496 distance = vlen(head.origin - self.origin);
500 traceline(self.origin + self.view_ofs , ( ( head.absmin + head.absmax ) * 0.5 ), true, world);
505 if(distance>bestdistance)
508 bestdistance = distance;
514 self.ignoregoal = self.goalcurrent;
515 self.ignoregoaltime = time + autocvar_bot_ai_ignoregoal_timeout;
516 navigation_clearroute();
517 navigation_routetogoal(newgoal, self.origin);
518 self.aistatus &= ~AI_STATUS_OUT_JUMPPAD;
526 if(self.velocity.z>0)
528 float threshold, sxy;
529 vector velxy = self.velocity; velxy_z = 0;
531 threshold = maxspeed * 0.2;
534 dprint("Warning: ", self.netname, " got stuck on a jumppad (velocity in xy is ", ftos(sxy), "), trying to get out of it now\n");
535 self.aistatus |= AI_STATUS_OUT_JUMPPAD;
540 // Don't chase players while using a jump pad
541 if(IS_PLAYER(self.goalcurrent) || IS_PLAYER(self.goalstack01))
545 else if(self.aistatus & AI_STATUS_OUT_JUMPPAD)
546 self.aistatus &= ~AI_STATUS_OUT_JUMPPAD;
548 // If there is a trigger_hurt right below try to use the jetpack or make a rocketjump
550 if (!(self.flags & FL_ONGROUND))
552 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 -65536', MOVE_NOMONSTERS, self);
553 if(tracebox_hits_trigger_hurt(self.origin, self.mins, self.maxs, trace_endpos ))
554 if(self.items & IT_JETPACK)
556 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 65536', MOVE_NOMONSTERS, self);
557 if(tracebox_hits_trigger_hurt(self.origin, self.mins, self.maxs, trace_endpos + '0 0 1' ))
559 if(self.velocity.z<0)
561 self.BUTTON_HOOK = true;
565 self.BUTTON_HOOK = true;
567 // If there is no goal try to move forward
569 if(self.goalcurrent==world)
572 dir = normalize(( ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5 ) - self.origin);
574 vector xyvelocity = self.velocity; xyvelocity_z = 0;
575 float xyspeed = xyvelocity * dir;
577 if(xyspeed < (maxspeed / 2))
579 makevectors(self.v_angle.y * '0 1 0');
580 tracebox(self.origin, self.mins, self.maxs, self.origin + (dir * maxspeed * 3), MOVE_NOMONSTERS, self);
581 if(trace_fraction==1)
583 self.movement_x = dir * v_forward * maxspeed;
584 self.movement_y = dir * v_right * maxspeed;
586 havocbot_keyboard_movement(self.origin + dir * 100);
590 self.havocbot_blockhead = true;
594 else if(self.health>WEP_CVAR(devastator, damage)*0.5)
596 if(self.velocity.z < 0)
597 if(client_hasweapon(self, WEP_DEVASTATOR, true, false))
599 self.movement_x = maxspeed;
601 if(self.rocketjumptime)
603 if(time > self.rocketjumptime)
605 self.BUTTON_ATCK2 = true;
606 self.rocketjumptime = 0;
611 self.switchweapon = WEP_DEVASTATOR;
613 self.BUTTON_ATCK = true;
614 self.rocketjumptime = time + WEP_CVAR(devastator, detonatedelay);
620 // If there is no goal try to move forward
621 if(self.goalcurrent==world)
622 self.movement_x = maxspeed;
626 // If we are under water with no goals, swim up
628 if(self.goalcurrent==world)
631 if(self.waterlevel>WATERLEVEL_SWIMMING)
633 else if(self.velocity.z >= 0 && !(self.waterlevel == WATERLEVEL_WETFEET && self.watertype == CONTENT_WATER))
634 self.BUTTON_JUMP = true;
636 self.BUTTON_JUMP = false;
637 makevectors(self.v_angle.y * '0 1 0');
638 self.movement_x = dir * v_forward * maxspeed;
639 self.movement_y = dir * v_right * maxspeed;
640 self.movement_z = dir * v_up * maxspeed;
643 // if there is nowhere to go, exit
644 if (self.goalcurrent == world)
647 if (self.goalcurrent)
648 navigation_poptouchedgoals();
650 // if ran out of goals try to use an alternative goal or get a new strategy asap
651 if(self.goalcurrent == world)
653 self.bot_strategytime = 0;
658 if(autocvar_bot_debug_goalstack)
661 m1 = self.goalcurrent.origin + self.goalcurrent.mins;
662 m2 = self.goalcurrent.origin + self.goalcurrent.maxs;
663 destorg = self.origin;
664 destorg.x = bound(m1_x, destorg.x, m2_x);
665 destorg.y = bound(m1_y, destorg.y, m2_y);
666 destorg.z = bound(m1_z, destorg.z, m2_z);
667 diff = destorg - self.origin;
669 dir = normalize(diff);
670 flatdir = diff;flatdir.z = 0;
671 flatdir = normalize(flatdir);
672 gco = (self.goalcurrent.absmin + self.goalcurrent.absmax) * 0.5;
674 //if (self.bot_dodgevector_time < time)
676 // self.bot_dodgevector_time = time + cvar("bot_ai_dodgeupdateinterval");
677 // self.bot_dodgevector_jumpbutton = 1;
678 evadeobstacle = '0 0 0';
683 if(self.waterlevel>WATERLEVEL_SWIMMING)
686 self.aistatus |= AI_STATUS_OUT_WATER;
690 if(self.velocity.z >= 0 && !(self.watertype == CONTENT_WATER && gco.z < self.origin.z) &&
691 ( !(self.waterlevel == WATERLEVEL_WETFEET && self.watertype == CONTENT_WATER) || self.aistatus & AI_STATUS_OUT_WATER))
692 self.BUTTON_JUMP = true;
694 self.BUTTON_JUMP = false;
696 dir = normalize(flatdir);
697 makevectors(self.v_angle.y * '0 1 0');
701 if(self.aistatus & AI_STATUS_OUT_WATER)
702 self.aistatus &= ~AI_STATUS_OUT_WATER;
704 // jump if going toward an obstacle that doesn't look like stairs we
705 // can walk up directly
706 tracebox(self.origin, self.mins, self.maxs, self.origin + self.velocity * 0.2, false, self);
707 if (trace_fraction < 1)
708 if (trace_plane_normal.z < 0.7)
711 tracebox(self.origin + stepheightvec, self.mins, self.maxs, self.origin + self.velocity * 0.2 + stepheightvec, false, self);
712 if (trace_fraction < s + 0.01)
713 if (trace_plane_normal.z < 0.7)
716 tracebox(self.origin + jumpstepheightvec, self.mins, self.maxs, self.origin + self.velocity * 0.2 + jumpstepheightvec, false, self);
717 if (trace_fraction > s)
718 self.BUTTON_JUMP = 1;
722 // avoiding dangers and obstacles
723 vector dst_ahead, dst_down;
724 makevectors(self.v_angle.y * '0 1 0');
725 dst_ahead = self.origin + self.view_ofs + (self.velocity * 0.4) + (v_forward * 32 * 3);
726 dst_down = dst_ahead - '0 0 1500';
729 traceline(self.origin + self.view_ofs, dst_ahead, true, world);
731 // Check head-banging against walls
732 if(vlen(self.origin + self.view_ofs - trace_endpos) < 25 && !(self.aistatus & AI_STATUS_OUT_WATER))
734 self.BUTTON_JUMP = true;
735 if(self.facingwalltime && time > self.facingwalltime)
737 self.ignoregoal = self.goalcurrent;
738 self.ignoregoaltime = time + autocvar_bot_ai_ignoregoal_timeout;
739 self.bot_strategytime = 0;
744 self.facingwalltime = time + 0.05;
749 self.facingwalltime = 0;
751 if(self.ignoregoal != world && time > self.ignoregoaltime)
753 self.ignoregoal = world;
754 self.ignoregoaltime = 0;
758 // Check for water/slime/lava and dangerous edges
759 // (only when the bot is on the ground or jumping intentionally)
760 self.aistatus &= ~AI_STATUS_DANGER_AHEAD;
762 if(trace_fraction == 1 && self.jumppadcount == 0 && !self.goalcurrent.wphardwired )
763 if((self.flags & FL_ONGROUND) || (self.aistatus & AI_STATUS_RUNNING) || self.BUTTON_JUMP == true)
766 traceline(dst_ahead , dst_down, true, world);
767 // te_lightning2(world, self.origin, dst_ahead); // Draw "ahead" look
768 // te_lightning2(world, dst_ahead, dst_down); // Draw "downwards" look
769 if(trace_endpos.z < self.origin.z + self.mins.z)
771 s = pointcontents(trace_endpos + '0 0 1');
772 if (s != CONTENT_SOLID)
773 if (s == CONTENT_LAVA || s == CONTENT_SLIME)
774 evadelava = normalize(self.velocity) * -1;
775 else if (s == CONTENT_SKY)
776 evadeobstacle = normalize(self.velocity) * -1;
777 else if (!boxesoverlap(dst_ahead - self.view_ofs + self.mins, dst_ahead - self.view_ofs + self.maxs,
778 self.goalcurrent.absmin, self.goalcurrent.absmax))
780 // if ain't a safe goal with "holes" (like the jumpad on soylent)
781 // and there is a trigger_hurt below
782 if(tracebox_hits_trigger_hurt(dst_ahead, self.mins, self.maxs, trace_endpos))
784 // Remove dangerous dynamic goals from stack
785 dprint("bot ", self.netname, " avoided the goal ", self.goalcurrent.classname, " ", etos(self.goalcurrent), " because it led to a dangerous path; goal stack cleared\n");
786 navigation_clearroute();
796 makevectors(self.v_angle.y * '0 1 0');
798 if(evadeobstacle!='0 0 0'||evadelava!='0 0 0')
799 self.aistatus |= AI_STATUS_DANGER_AHEAD;
802 dodge = havocbot_dodge();
803 dodge = dodge * bound(0,0.5+(skill+self.bot_dodgeskill)*0.1,1);
804 evadelava = evadelava * bound(1,3-(skill+self.bot_dodgeskill),3); //Noobs fear lava a lot and take more distance from it
805 traceline(self.origin, ( ( self.enemy.absmin + self.enemy.absmax ) * 0.5 ), true, world);
806 if(IS_PLAYER(trace_ent))
807 dir = dir * bound(0,(skill+self.bot_dodgeskill)/7,1);
809 dir = normalize(dir + dodge + evadeobstacle + evadelava);
810 // self.bot_dodgevector = dir;
811 // self.bot_dodgevector_jumpbutton = self.BUTTON_JUMP;
814 if(time < self.ladder_time)
816 if(self.goalcurrent.origin.z + self.goalcurrent.mins.z > self.origin.z + self.mins.z)
818 if(self.origin.z + self.mins.z < self.ladder_entity.origin.z + self.ladder_entity.maxs.z)
823 if(self.origin.z + self.mins.z > self.ladder_entity.origin.z + self.ladder_entity.mins.z)
828 //dir = self.bot_dodgevector;
829 //if (self.bot_dodgevector_jumpbutton)
830 // self.BUTTON_JUMP = 1;
831 self.movement_x = dir * v_forward * maxspeed;
832 self.movement_y = dir * v_right * maxspeed;
833 self.movement_z = dir * v_up * maxspeed;
835 // Emulate keyboard interface
837 havocbot_keyboard_movement(destorg);
840 // if(self.aistatus & AI_STATUS_ROAMING)
842 if(skill+self.bot_moveskill >= autocvar_bot_ai_bunnyhop_skilloffset)
843 havocbot_bunnyhop(dir);
845 if ((dir * v_up) >= autocvar_sv_jumpvelocity*0.5 && (self.flags & FL_ONGROUND)) self.BUTTON_JUMP=1;
846 if (((dodge * v_up) > 0) && random()*frametime >= 0.2*bound(0,(10-skill-self.bot_dodgeskill)*0.1,1)) self.BUTTON_JUMP=true;
847 if (((dodge * v_up) < 0) && random()*frametime >= 0.5*bound(0,(10-skill-self.bot_dodgeskill)*0.1,1)) self.havocbot_ducktime=time+0.3/bound(0.1,skill+self.bot_dodgeskill,10);
850 void havocbot_chooseenemy()
852 entity head, best, head2;
853 float rating, bestrating, i, hf;
855 if (autocvar_bot_nofire || IS_INDEPENDENT_PLAYER(self))
862 if (!bot_shouldattack(self.enemy))
864 // enemy died or something, find a new target
866 self.havocbot_chooseenemy_finished = time;
868 else if (self.havocbot_stickenemy)
870 // tracking last chosen enemy
871 // if enemy is visible
872 // and not really really far away
873 // and we're not severely injured
874 // then keep tracking for a half second into the future
875 traceline(self.origin+self.view_ofs, ( self.enemy.absmin + self.enemy.absmax ) * 0.5,false,world);
876 if (trace_ent == self.enemy || trace_fraction == 1)
877 if (vlen((( self.enemy.absmin + self.enemy.absmax ) * 0.5) - self.origin) < 1000)
878 if (self.health > 30)
880 // remain tracking him for a shot while (case he went after a small corner or pilar
881 self.havocbot_chooseenemy_finished = time + 0.5;
884 // enemy isn't visible, or is far away, or we're injured severely
885 // so stop preferring this enemy
886 // (it will still take a half second until a new one is chosen)
887 self.havocbot_stickenemy = 0;
890 if (time < self.havocbot_chooseenemy_finished)
892 self.havocbot_chooseenemy_finished = time + autocvar_bot_ai_enemydetectioninterval;
893 eye = self.origin + self.view_ofs;
895 bestrating = 100000000;
896 head = head2 = findchainfloat(bot_attack, true);
899 hf = self.dphitcontentsmask;
901 // Search for enemies, if no enemy can be seen directly try to look through transparent objects
903 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
909 v = (head.absmin + head.absmax) * 0.5;
910 rating = vlen(v - eye);
911 if (rating<autocvar_bot_ai_enemydetectionradius)
912 if (bestrating > rating)
913 if (bot_shouldattack(head))
915 traceline(eye, v, true, self);
916 if (trace_ent == head || trace_fraction >= 1)
925 // I want to do a second scan if no enemy was found or I don't have weapons
926 // TODO: Perform the scan when using the rifle (requires changes on the rifle code)
927 if(best || self.weapons) // || self.weapon == WEP_RIFLE
932 // Set flags to see through transparent objects
933 self.dphitcontentsmask |= DPCONTENTS_OPAQUE;
939 self.dphitcontentsmask = hf;
942 self.havocbot_stickenemy = true;
945 float havocbot_chooseweapon_checkreload(int new_weapon)
947 // bots under this skill cannot find unloaded weapons to reload idly when not in combat,
948 // so skip this for them, or they'll never get to reload their weapons at all.
949 // this also allows bots under this skill to be more stupid, and reload more often during combat :)
953 // if this weapon is scheduled for reloading, don't switch to it during combat
954 if (self.weapon_load[new_weapon] < 0)
956 float i, other_weapon_available = false;
957 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
959 // if we are out of ammo for all other weapons, it's an emergency to switch to anything else
960 if (WEP_ACTION(i, WR_CHECKAMMO1) + WEP_ACTION(i, WR_CHECKAMMO2))
961 other_weapon_available = true;
963 if(other_weapon_available)
970 void havocbot_chooseweapon()
975 if(g_weaponarena_weapons == WEPSET_TUBA)
977 self.switchweapon = WEP_TUBA;
981 // TODO: clean this up by moving it to weapon code
982 if(self.enemy==world)
984 // If no weapon was chosen get the first available weapon
986 for(i = WEP_FIRST; i <= WEP_LAST; ++i) if(i != WEP_BLASTER)
988 if(client_hasweapon(self, i, true, false))
990 self.switchweapon = i;
997 // Do not change weapon during the next second after a combo
998 float f = time - self.lastcombotime;
1003 float distance; distance=bound(10,vlen(self.origin-self.enemy.origin)-200,10000);
1005 // Should it do a weapon combo?
1006 float af, ct, combo_time, combo;
1008 af = ATTACK_FINISHED(self);
1009 ct = autocvar_bot_ai_weapon_combo_threshold;
1011 // Bots with no skill will be 4 times more slower than "godlike" bots when doing weapon combos
1012 // Ideally this 4 should be calculated as longest_weapon_refire / bot_ai_weapon_combo_threshold
1013 combo_time = time + ct + (ct * ((-0.3*(skill+self.bot_weaponskill))+3));
1017 if(autocvar_bot_ai_weapon_combo)
1018 if(self.weapon == self.lastfiredweapon)
1022 self.lastcombotime = time;
1025 distance *= pow(2, self.bot_rangepreference);
1027 // Custom weapon list based on distance to the enemy
1028 if(bot_custom_weapon){
1030 // Choose weapons for far distance
1031 if ( distance > bot_distance_far ) {
1032 for(i=0; i < WEP_COUNT && bot_weapons_far[i] != -1 ; ++i){
1033 w = bot_weapons_far[i];
1034 if ( client_hasweapon(self, w, true, false) )
1036 if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
1038 self.switchweapon = w;
1044 // Choose weapons for mid distance
1045 if ( distance > bot_distance_close) {
1046 for(i=0; i < WEP_COUNT && bot_weapons_mid[i] != -1 ; ++i){
1047 w = bot_weapons_mid[i];
1048 if ( client_hasweapon(self, w, true, false) )
1050 if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
1052 self.switchweapon = w;
1058 // Choose weapons for close distance
1059 for(i=0; i < WEP_COUNT && bot_weapons_close[i] != -1 ; ++i){
1060 w = bot_weapons_close[i];
1061 if ( client_hasweapon(self, w, true, false) )
1063 if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
1065 self.switchweapon = w;
1074 vector selfvel, enemyvel;
1075 // if(self.flags & FL_INWATER)
1077 if (time < self.nextaim)
1079 self.nextaim = time + 0.1;
1080 selfvel = self.velocity;
1081 if (!self.waterlevel)
1085 enemyvel = self.enemy.velocity;
1086 if (!self.enemy.waterlevel)
1088 lag_additem(time + self.ping, 0, 0, self.enemy, self.origin, selfvel, (self.enemy.absmin + self.enemy.absmax) * 0.5, enemyvel);
1091 lag_additem(time + self.ping, 0, 0, world, self.origin, selfvel, ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5, '0 0 0');
1094 float havocbot_moveto_refresh_route()
1096 // Refresh path to goal if necessary
1098 wp = self.havocbot_personal_waypoint;
1099 navigation_goalrating_start();
1100 navigation_routerating(wp, 10000, 10000);
1101 navigation_goalrating_end();
1102 return self.navigation_hasgoals;
1105 float havocbot_moveto(vector pos)
1109 if(self.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
1111 // Step 4: Move to waypoint
1112 if(self.havocbot_personal_waypoint==world)
1114 dprint("Error: ", self.netname, " trying to walk to a non existent personal waypoint\n");
1115 self.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_GOING;
1116 return CMD_STATUS_ERROR;
1119 if (!bot_strategytoken_taken)
1120 if(self.havocbot_personal_waypoint_searchtime<time)
1122 bot_strategytoken_taken = true;
1123 if(havocbot_moveto_refresh_route())
1125 dprint(self.netname, " walking to its personal waypoint (after ", ftos(self.havocbot_personal_waypoint_failcounter), " failed attempts)\n");
1126 self.havocbot_personal_waypoint_searchtime = time + 10;
1127 self.havocbot_personal_waypoint_failcounter = 0;
1131 self.havocbot_personal_waypoint_failcounter += 1;
1132 self.havocbot_personal_waypoint_searchtime = time + 2;
1133 if(self.havocbot_personal_waypoint_failcounter >= 30)
1135 dprint("Warning: can't walk to the personal waypoint located at ", vtos(self.havocbot_personal_waypoint.origin),"\n");
1136 self.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_LINKING;
1137 remove(self.havocbot_personal_waypoint);
1138 return CMD_STATUS_ERROR;
1141 dprint(self.netname, " can't walk to its personal waypoint (after ", ftos(self.havocbot_personal_waypoint_failcounter), " failed attempts), trying later\n");
1145 if(autocvar_bot_debug_goalstack)
1149 vector dir = ( ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5 ) - (self.origin + self.view_ofs);
1151 bot_aimdir(dir, -1);
1154 havocbot_movetogoal();
1156 if(self.aistatus & AI_STATUS_WAYPOINT_PERSONAL_REACHED)
1158 // Step 5: Waypoint reached
1159 dprint(self.netname, "'s personal waypoint reached\n");
1160 remove(self.havocbot_personal_waypoint);
1161 self.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_REACHED;
1162 return CMD_STATUS_FINISHED;
1165 return CMD_STATUS_EXECUTING;
1168 // Step 2: Linking waypoint
1169 if(self.aistatus & AI_STATUS_WAYPOINT_PERSONAL_LINKING)
1171 // Wait until it is linked
1172 if(!self.havocbot_personal_waypoint.wplinked)
1174 dprint(self.netname, " waiting for personal waypoint to be linked\n");
1175 return CMD_STATUS_EXECUTING;
1178 self.havocbot_personal_waypoint_searchtime = time; // so we set the route next frame
1179 self.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_LINKING;
1180 self.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_GOING;
1182 // Step 3: Route to waypoint
1183 dprint(self.netname, " walking to its personal waypoint\n");
1185 return CMD_STATUS_EXECUTING;
1188 // Step 1: Spawning waypoint
1189 wp = waypoint_spawnpersonal(pos);
1192 dprint("Error: Can't spawn personal waypoint at ",vtos(pos),"\n");
1193 return CMD_STATUS_ERROR;
1196 self.havocbot_personal_waypoint = wp;
1197 self.havocbot_personal_waypoint_failcounter = 0;
1198 self.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_LINKING;
1200 // if pos is inside a teleport, then let's mark it as teleport waypoint
1202 for(head = world; (head = find(head, classname, "trigger_teleport")); )
1204 if(WarpZoneLib_BoxTouchesBrush(pos, pos, head, world))
1206 wp.wpflags |= WAYPOINTFLAG_TELEPORT;
1207 self.lastteleporttime = 0;
1212 if(wp.wpflags & WAYPOINTFLAG_TELEPORT)
1213 print("routing to a teleporter\n");
1215 print("routing to a non-teleporter\n");
1218 return CMD_STATUS_EXECUTING;
1221 float havocbot_resetgoal()
1223 navigation_clearroute();
1224 return CMD_STATUS_FINISHED;
1227 void havocbot_setupbot()
1229 self.bot_ai = havocbot_ai;
1230 self.cmd_moveto = havocbot_moveto;
1231 self.cmd_resetgoal = havocbot_resetgoal;
1233 havocbot_chooserole();
1236 vector havocbot_dodge()
1238 // LordHavoc: disabled because this is too expensive
1243 float danger, bestdanger, vl, d;
1246 // check for dangerous objects near bot or approaching bot
1247 head = findchainfloat(bot_dodge, true);
1250 if (head.owner != self)
1252 vl = vlen(head.velocity);
1253 if (vl > autocvar_sv_maxspeed * 0.3)
1255 n = normalize(head.velocity);
1256 v = self.origin - head.origin;
1258 if (d > (0 - head.bot_dodgerating))
1259 if (d < (vl * 0.2 + head.bot_dodgerating))
1261 // calculate direction and distance from the flight path, by removing the forward axis
1262 v = v - (n * (v * n));
1263 danger = head.bot_dodgerating - vlen(v);
1264 if (bestdanger < danger)
1266 bestdanger = danger;
1267 // dodge to the side of the object
1268 dodge = normalize(v);
1274 danger = head.bot_dodgerating - vlen(head.origin - self.origin);
1275 if (bestdanger < danger)
1277 bestdanger = danger;
1278 dodge = normalize(self.origin - head.origin);