2 void() havocbot_chooserole;
3 .float havocbot_keyboardskill;
4 .float facingwalltime, ignoregoaltime;
6 .float lastfiredweapon;
8 .float havocbot_blockhead;
10 #ifdef DEBUG_BOT_GOALSTACK
11 void debuggoalstack();
14 vector havocbot_dodge()
16 // LordHavoc: disabled because this is too expensive
20 local vector dodge, v, n;
21 local float danger, bestdanger, vl, d;
24 // check for dangerous objects near bot or approaching bot
25 head = findchainfloat(bot_dodge, TRUE);
28 if (head.owner != self)
30 vl = vlen(head.velocity);
31 if (vl > sv_maxspeed * 0.3)
33 n = normalize(head.velocity);
34 v = self.origin - head.origin;
36 if (d > (0 - head.bot_dodgerating))
37 if (d < (vl * 0.2 + head.bot_dodgerating))
39 // calculate direction and distance from the flight path, by removing the forward axis
40 v = v - (n * (v * n));
41 danger = head.bot_dodgerating - vlen(v);
42 if (bestdanger < danger)
45 // dodge to the side of the object
52 danger = head.bot_dodgerating - vlen(head.origin - self.origin);
53 if (bestdanger < danger)
56 dodge = normalize(self.origin - head.origin);
66 .float havocbot_keyboardtime;
67 .float havocbot_ducktime;
68 .vector havocbot_keyboard;
69 void havocbot_keyboard_movement(vector destorg)
71 local vector keyboard;
72 local float blend, maxspeed;
74 maxspeed = cvar("sv_maxspeed");
76 if (time < self.havocbot_keyboardtime)
79 self.havocbot_keyboardtime =
81 self.havocbot_keyboardtime
82 + bound(0,0.05/(skill+self.havocbot_keyboardskill),0.05)
83 +random()*bound(0,0.025/(skill+self.havocbot_keyboardskill),100)
85 keyboard = self.movement * (1.0 / maxspeed);
87 local float trigger, trigger1;
88 blend = bound(0,skill*0.1,1);
89 trigger = cvar("bot_ai_keyboard_treshold");
90 trigger1 = 0 - trigger;
92 // categorize forward movement
93 // at skill < 1.5 only forward
94 // at skill < 2.5 only individual directions
95 // at skill < 4.5 only individual directions, and forward diagonals
96 // at skill >= 4.5, all cases allowed
97 if (keyboard_x > trigger)
103 else if (keyboard_x < trigger1 && skill > 1.5)
118 if (keyboard_y > trigger)
120 else if (keyboard_y < trigger1)
125 if (keyboard_z > trigger)
127 else if (keyboard_z < trigger1)
132 self.havocbot_keyboard = keyboard * maxspeed;
133 if (self.havocbot_ducktime>time) self.BUTTON_CROUCH=TRUE;
135 keyboard = self.havocbot_keyboard;
136 blend = bound(0,vlen(destorg-self.origin)/cvar("bot_ai_keyboard_distance"),1); // When getting close move with 360 degree
137 //dprint("movement ", vtos(self.movement), " keyboard ", vtos(keyboard), " blend ", ftos(blend), "\n");
138 self.movement = self.movement + (keyboard - self.movement) * blend;
141 .entity bot_lastseengoal;
142 .float bot_timelastseengoal;
143 .float bot_canruntogoal;
144 void havocbot_bunnyhop(vector dir)
146 local float bunnyhopdistance;
147 local vector deviation;
148 local float maxspeed;
153 if(self.goalcurrent.classname == "player")
156 maxspeed = cvar("sv_maxspeed");
158 if(self.aistatus & AI_STATUS_DANGER_AHEAD)
160 self.aistatus &~= AI_STATUS_RUNNING;
161 self.BUTTON_JUMP = FALSE;
162 self.bot_canruntogoal = 0;
163 self.bot_timelastseengoal = 0;
167 if(self.waterlevel > WATERLEVEL_WETFEET)
169 self.aistatus &~= AI_STATUS_RUNNING;
173 if(self.bot_lastseengoal != self.goalcurrent && !(self.aistatus & AI_STATUS_RUNNING))
175 self.bot_canruntogoal = 0;
176 self.bot_timelastseengoal = 0;
179 bunnyhopdistance = vlen(self.origin - self.goalcurrent.origin);
181 // Run only to visible goals
182 if(self.flags & FL_ONGROUND)
183 if(self.speed==maxspeed)
184 if(checkpvs(self.origin + self.view_ofs, self.goalcurrent))
186 self.bot_lastseengoal = self.goalcurrent;
189 if(self.bot_timelastseengoal)
191 // for a period of time
192 if(time - self.bot_timelastseengoal > cvar("bot_ai_bunnyhop_firstjumpdelay"))
194 local float checkdistance;
195 checkdistance = TRUE;
197 // don't run if it is too close
198 if(self.bot_canruntogoal==0)
200 if(bunnyhopdistance > cvar("bot_ai_bunnyhop_startdistance"))
201 self.bot_canruntogoal = 1;
203 self.bot_canruntogoal = -1;
206 if(self.bot_canruntogoal != 1)
209 if(self.aistatus & AI_STATUS_ROAMING)
210 if(self.goalcurrent.classname=="waypoint")
211 if(fabs(self.goalcurrent.origin_z - self.origin_z) < self.maxs_z - self.mins_z)
212 if(self.goalstack01!=world)
214 deviation = vectoangles(self.goalstack01.origin - self.origin) - vectoangles(self.goalcurrent.origin - self.origin);
215 while (deviation_y < -180) deviation_y = deviation_y + 360;
216 while (deviation_y > 180) deviation_y = deviation_y - 360;
218 if(fabs(deviation_y) < 20)
219 if(bunnyhopdistance < vlen(self.origin - self.goalstack01.origin))
220 if(fabs(self.goalstack01.origin_z - self.goalcurrent.origin_z) < self.maxs_z - self.mins_z)
222 if(vlen(self.goalcurrent.origin - self.goalstack01.origin) > cvar("bot_ai_bunnyhop_startdistance"))
223 if(checkpvs(self.origin + self.view_ofs, self.goalstack01))
225 checkdistance = FALSE;
232 self.aistatus &~= AI_STATUS_RUNNING;
233 if(bunnyhopdistance > cvar("bot_ai_bunnyhop_stopdistance"))
234 self.BUTTON_JUMP = TRUE;
238 self.aistatus |= AI_STATUS_RUNNING;
239 self.BUTTON_JUMP = TRUE;
245 self.bot_timelastseengoal = time;
250 self.bot_timelastseengoal = 0;
253 // Release jump button
254 if(self.flags & FL_ONGROUND == 0)
256 if(self.velocity_z < 0 || vlen(self.velocity)<maxspeed)
257 self.BUTTON_JUMP = FALSE;
260 if(self.aistatus & AI_STATUS_RUNNING)
261 if(vlen(self.velocity)>maxspeed)
263 deviation = vectoangles(dir) - vectoangles(self.velocity);
264 while (deviation_y < -180) deviation_y = deviation_y + 360;
265 while (deviation_y > 180) deviation_y = deviation_y - 360;
267 if(fabs(deviation_y)>10)
271 self.movement_y = maxspeed * -1;
272 else if(deviation_y<10)
273 self.movement_y = maxspeed;
279 //.float havocbotignoretime;
280 //.vector bot_dodgevector;
281 //.float bot_dodgevector_time;
282 //.float bot_dodgevector_jumpbutton;
284 .entity ladder_entity;
285 .float rocketjumptime;
286 void havocbot_movetogoal()
288 local vector destorg;
291 local vector flatdir;
294 local vector evadeobstacle;
295 local vector evadelava;
297 local float maxspeed;
300 //if (self.goalentity)
301 // te_lightning2(self, self.origin, (self.goalentity.absmin + self.goalentity.absmax) * 0.5);
302 self.movement = '0 0 0';
303 maxspeed = cvar("sv_maxspeed");
305 if(self.jumppadcount)
307 if(self.flags & FL_ONGROUND)
309 self.jumppadcount = FALSE;
310 if(self.aistatus & AI_STATUS_OUT_JUMPPAD)
311 self.aistatus &~= AI_STATUS_OUT_JUMPPAD;
314 // If got stuck on the jump pad try to reach the farther visible item
315 if(self.aistatus & AI_STATUS_OUT_JUMPPAD)
317 if(fabs(self.velocity_z)<50)
319 local entity head, newgoal;
320 local float distance, bestdistance;
322 for (head = findchainfloat(bot_pickup, TRUE); head; head = head.chain)
324 if(head.classname=="worldspawn")
327 distance = vlen(head.origin - self.origin);
331 traceline(self.origin + self.view_ofs , head.origin, TRUE, world);
336 if(distance>bestdistance)
339 bestdistance = distance;
345 self.ignoregoal = self.goalcurrent;
346 self.ignoregoaltime = time + cvar("bot_ai_ignoregoal_timeout");
347 navigation_clearroute();
348 navigation_routetogoal(newgoal, self.origin);
349 self.aistatus &~= AI_STATUS_OUT_JUMPPAD;
357 if(self.velocity_z>0)
359 local float threshold;
360 threshold = maxspeed * 0.2;
361 if(fabs(self.velocity_x) < threshold && fabs(self.velocity_y) < threshold)
362 self.aistatus |= AI_STATUS_OUT_JUMPPAD;
368 // If there is a trigger_hurt right below try to use the jetpack or make a rocketjump
370 if not(self.flags & FL_ONGROUND)
372 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 -65536', MOVE_NOMONSTERS, self);
373 if(tracebox_hits_trigger_hurt(self.origin, self.mins, self.maxs, trace_endpos ))
374 if(self.items & IT_JETPACK)
376 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 65536', MOVE_NOMONSTERS, self);
377 if(tracebox_hits_trigger_hurt(self.origin, self.mins, self.maxs, trace_endpos + '0 0 1' ))
379 if(self.velocity_z<0)
381 self.BUTTON_HOOK = TRUE;
385 self.BUTTON_HOOK = TRUE;
387 // If there is no goal try to move forward
389 if(self.goalcurrent==world)
392 dir = normalize(self.goalcurrent.origin - self.origin);
394 local vector xyvelocity = self.velocity; xyvelocity_z = 0;
395 local float xyspeed = xyvelocity * dir;
397 if(xyspeed < (maxspeed / 2))
399 makevectors(self.v_angle_y * '0 1 0');
400 tracebox(self.origin, self.mins, self.maxs, self.origin + (dir * maxspeed * 3), MOVE_NOMONSTERS, self);
401 if(trace_fraction==1)
403 self.movement_x = dir * v_forward * maxspeed;
404 self.movement_y = dir * v_right * maxspeed;
406 havocbot_keyboard_movement(self.origin + dir * 100);
410 self.havocbot_blockhead = TRUE;
414 else if(self.health>cvar("g_balance_rocketlauncher_damage")*0.5)
416 if(self.velocity_z < 0)
417 if(client_hasweapon(self, WEP_ROCKET_LAUNCHER, TRUE, FALSE))
419 self.movement_x = maxspeed;
421 if(self.rocketjumptime)
423 if(time > self.rocketjumptime)
425 self.BUTTON_ATCK2 = TRUE;
426 self.rocketjumptime = 0;
431 self.switchweapon = WEP_ROCKET_LAUNCHER;
433 self.BUTTON_ATCK = TRUE;
434 self.rocketjumptime = time + cvar("g_balance_rocketlauncher_detonatedelay");
440 // If there is no goal try to move forward
441 if(self.goalcurrent==world)
442 self.movement_x = maxspeed;
446 // If we are under water with no goals, swim up
448 if(self.goalcurrent==world)
451 if(self.waterlevel>WATERLEVEL_SWIMMING)
453 else if(self.velocity_z >= 0 && !(self.waterlevel == WATERLEVEL_WETFEET && self.watertype == CONTENT_WATER))
454 self.BUTTON_JUMP = TRUE;
456 self.BUTTON_JUMP = FALSE;
457 makevectors(self.v_angle_y * '0 1 0');
458 self.movement_x = dir * v_forward * maxspeed;
459 self.movement_y = dir * v_right * maxspeed;
460 self.movement_z = dir * v_up * maxspeed;
463 // if there is nowhere to go, exit
464 if (self.goalcurrent == world)
467 if (self.goalcurrent)
468 navigation_poptouchedgoals();
470 // if ran out of goals try to use an alternative goal or get a new strategy asap
471 if(self.goalcurrent == world)
473 self.bot_strategytime = 0;
477 #ifdef DEBUG_BOT_GOALSTACK
481 m1 = self.goalcurrent.origin + self.goalcurrent.mins;
482 m2 = self.goalcurrent.origin + self.goalcurrent.maxs;
483 destorg = self.origin;
484 destorg_x = bound(m1_x, destorg_x, m2_x);
485 destorg_y = bound(m1_y, destorg_y, m2_y);
486 destorg_z = bound(m1_z, destorg_z, m2_z);
487 diff = destorg - self.origin;
489 dir = normalize(diff);
490 flatdir = diff;flatdir_z = 0;
491 flatdir = normalize(flatdir);
493 //if (self.bot_dodgevector_time < time)
495 // self.bot_dodgevector_time = time + cvar("bot_ai_dodgeupdateinterval");
496 // self.bot_dodgevector_jumpbutton = 1;
497 evadeobstacle = '0 0 0';
502 if(self.waterlevel>WATERLEVEL_SWIMMING)
505 self.aistatus |= AI_STATUS_OUT_WATER;
509 if(self.velocity_z >= 0 && !(self.watertype == CONTENT_WATER && self.goalcurrent.origin_z < self.origin_z) &&
510 ( !(self.waterlevel == WATERLEVEL_WETFEET && self.watertype == CONTENT_WATER) || self.aistatus & AI_STATUS_OUT_WATER))
511 self.BUTTON_JUMP = TRUE;
513 self.BUTTON_JUMP = FALSE;
515 dir = normalize(flatdir);
516 makevectors(self.v_angle_y * '0 1 0');
520 if(self.aistatus & AI_STATUS_OUT_WATER)
521 self.aistatus &~= AI_STATUS_OUT_WATER;
523 // jump if going toward an obstacle that doesn't look like stairs we
524 // can walk up directly
525 tracebox(self.origin, self.mins, self.maxs, self.origin + self.velocity * 0.2, FALSE, self);
526 if (trace_fraction < 1)
527 if (trace_plane_normal_z < 0.7)
530 tracebox(self.origin + '0 0 16', self.mins, self.maxs, self.origin + self.velocity * 0.2 + '0 0 16', FALSE, self);
531 if (trace_fraction < s + 0.01)
532 if (trace_plane_normal_z < 0.7)
535 tracebox(self.origin + '0 0 48', self.mins, self.maxs, self.origin + self.velocity * 0.2 + '0 0 48', FALSE, self);
536 if (trace_fraction > s)
537 self.BUTTON_JUMP = 1;
541 // avoiding dangers and obstacles
542 local vector dst_ahead, dst_down;
543 makevectors(self.v_angle_y * '0 1 0');
544 dst_ahead = self.origin + self.view_ofs + (self.velocity * 0.4) + (v_forward * 32 * 2);
545 dst_down = dst_ahead + '0 0 -1500';
548 traceline(self.origin + self.view_ofs , dst_ahead, TRUE, world);
550 // Check head-banging against walls
551 if(vlen(self.origin + self.view_ofs - trace_endpos) < 2 && !(self.aistatus & AI_STATUS_OUT_WATER))
553 if(self.facingwalltime && time > self.facingwalltime)
555 self.ignoregoal = self.goalcurrent;
556 self.ignoregoaltime = time + cvar("bot_ai_ignoregoal_timeout");
557 navigation_poproute();
561 self.facingwalltime = time + 0.05;
566 self.facingwalltime = 0;
568 if(self.ignoregoal != world && time > self.ignoregoaltime)
570 self.ignoregoal = world;
571 self.ignoregoaltime = 0;
575 // Check for water/slime/lava and dangerous edges
576 // (only when the bot is on the ground or jumping intentionally)
577 self.aistatus &~= AI_STATUS_DANGER_AHEAD;
579 if(trace_fraction == 1)
580 if(self.flags & FL_ONGROUND || self.aistatus & AI_STATUS_RUNNING || self.BUTTON_JUMP == TRUE)
583 traceline(dst_ahead , dst_down, TRUE, world);
584 // te_lightning2(world, self.origin, dst_ahead); // Draw "ahead" look
585 // te_lightning2(world, dst_ahead, dst_down); // Draw "downwards" look
586 if(trace_endpos_z < self.origin_z + self.mins_z)
588 s = pointcontents(trace_endpos + '0 0 1');
589 if (s != CONTENT_SOLID)
590 if (s == CONTENT_LAVA || s == CONTENT_SLIME)
591 evadelava = normalize(self.velocity) * -1;
592 else if (s == CONTENT_SKY)
593 evadeobstacle = normalize(self.velocity) * -1;
594 else if (!boxesoverlap(dst_ahead - self.view_ofs + self.mins, dst_ahead - self.view_ofs + self.maxs,
595 self.goalcurrent.absmin, self.goalcurrent.absmax))
597 // if ain't a safe goal with "holes" (like the jumpad on soylent)
598 // and there is a trigger_hurt below
599 if(tracebox_hits_trigger_hurt(dst_ahead, self.mins, self.maxs, trace_endpos))
601 // Remove dangerous dynamic goals from stack
602 if (self.goalcurrent.classname == "player" || self.goalcurrent.classname == "droppedweapon")
603 navigation_poproute();
606 evadeobstacle = normalize(self.velocity) * -1;
615 makevectors(self.v_angle_y * '0 1 0');
617 if(evadeobstacle!='0 0 0'||evadelava!='0 0 0')
618 self.aistatus |= AI_STATUS_DANGER_AHEAD;
621 dodge = havocbot_dodge();
622 dodge = dodge * bound(0,3+skill*0.1,1);
623 evadelava = evadelava * bound(1,3-skill,3); //Noobs fear lava a lot and take more distance from it
624 traceline(self.origin, self.enemy.origin, TRUE, world);
625 if(trace_ent.classname == "player")
626 dir = dir * bound(0,skill/7,1);
628 dir = normalize(dir + dodge + evadeobstacle + evadelava);
629 // self.bot_dodgevector = dir;
630 // self.bot_dodgevector_jumpbutton = self.BUTTON_JUMP;
633 if(time < self.ladder_time)
635 if(self.goalcurrent.origin_z + self.goalcurrent.mins_z > self.origin_z + self.mins_z)
637 if(self.origin_z + self.mins_z < self.ladder_entity.origin_z + self.ladder_entity.maxs_z)
642 if(self.origin_z + self.mins_z > self.ladder_entity.origin_z + self.ladder_entity.mins_z)
647 //dir = self.bot_dodgevector;
648 //if (self.bot_dodgevector_jumpbutton)
649 // self.BUTTON_JUMP = 1;
650 self.movement_x = dir * v_forward * maxspeed;
651 self.movement_y = dir * v_right * maxspeed;
652 self.movement_z = dir * v_up * maxspeed;
654 // Emulate keyboard interface
656 havocbot_keyboard_movement(destorg);
659 // if(self.aistatus & AI_STATUS_ROAMING)
660 if(skill >= cvar("bot_ai_bunnyhop_skilloffset"))
661 havocbot_bunnyhop(dir);
663 if ((dir * v_up) >= cvar("sv_jumpvelocity")*0.5 && (self.flags & FL_ONGROUND)) self.BUTTON_JUMP=1;
664 if (((dodge * v_up) > 0) && random()*frametime >= 0.2*bound(0,(10-skill)*0.1,1)) self.BUTTON_JUMP=TRUE;
665 if (((dodge * v_up) < 0) && random()*frametime >= 0.5*bound(0,(10-skill)*0.1,1)) self.havocbot_ducktime=time+0.3/bound(0.1,skill,10);
668 .float havocbot_chooseenemy_finished;
669 .float havocbot_stickenemy;
670 void havocbot_chooseenemy()
672 local entity head, best;
673 local float rating, bestrating;
675 if (cvar("bot_nofire") || IS_INDEPENDENT_PLAYER(self))
682 if (!bot_shouldattack(self.enemy))
684 // enemy died or something, find a new target
686 self.havocbot_chooseenemy_finished = time;
688 else if (self.havocbot_stickenemy)
690 // tracking last chosen enemy
691 // if enemy is visible
692 // and not really really far away
693 // and we're not severely injured
694 // then keep tracking for a half second into the future
695 traceline(self.origin+self.view_ofs, self.enemy.origin+self.enemy.view_ofs*0.5,FALSE,world);
696 if (trace_ent == self.enemy || trace_fraction == 1)
697 if (vlen(self.enemy.origin - self.origin) < 1000)
698 if (self.health > 30)
700 // remain tracking him for a shot while (case he went after a small corner or pilar
701 self.havocbot_chooseenemy_finished = time + cvar("bot_ai_enemydetectioninterval");
704 // enemy isn't visible, or is far away, or we're injured severely
705 // so stop preferring this enemy
706 // (it will still take a half second until a new one is chosen)
707 self.havocbot_stickenemy = 0;
710 if (time < self.havocbot_chooseenemy_finished)
712 self.havocbot_chooseenemy_finished = time + cvar("bot_ai_enemydetectioninterval");
713 eye = (self.origin + self.view_ofs);
715 bestrating = 100000000;
716 head = findchainfloat(bot_attack, TRUE);
719 v = (head.absmin + head.absmax) * 0.5;
720 rating = vlen(v - eye);
721 if (bestrating > rating)
722 if (bot_shouldattack(head))
724 traceline(eye, v, TRUE, self);
725 if (trace_ent == head || trace_fraction >= 1)
734 self.havocbot_stickenemy = TRUE;
737 .float bot_chooseweapontime;
738 float(entity e) w_getbestweapon;
739 void havocbot_chooseweapon()
743 // TODO: clean this up by moving it to weapon code
744 if(self.enemy.classname!="player")
746 // If no weapon was chosen get the first available weapon
748 for(i=WEP_LASER + 1; i < WEP_COUNT ; ++i)
750 if(client_hasweapon(self, i, TRUE, FALSE))
752 self.switchweapon = i;
759 // Do not change weapon during the next second after a combo
760 i = time - self.lastcombotime;
764 // Workaround for rifle reloading (..)
765 if(self.weapon == WEP_CAMPINGRIFLE)
766 if(i < cvar("g_balance_campingrifle_reloadtime") + 1)
770 local float rocket ; rocket =-1000;
771 local float nex ; nex =-1000;
772 local float hagar ; hagar =-1000;
773 local float grenade ; grenade =-1000;
774 local float electro ; electro =-1000;
775 local float crylink ; crylink =-1000;
776 local float uzi ; uzi =-1000;
777 local float shotgun ; shotgun =-1000;
778 local float campingrifle ; campingrifle =-1000;
779 local float laser ; laser =-1000;
780 local float minstanex ; minstanex =-1000;
781 local float currentscore;
782 local float bestscore; bestscore = 0;
783 local float bestweapon; bestweapon=self.switchweapon;
784 local float distance; distance=bound(10,vlen(self.origin-self.enemy.origin)-200,10000);
785 local float maxdelaytime=0.5;
786 local float spreadpenalty=10;
787 local float distancefromfloor;
789 // Should it do a weapon combo?
790 local float af, ct, combo_time, combo;
792 af = ATTACK_FINISHED(self);
793 ct = cvar("bot_ai_weapon_combo_threshold");
795 // Bots with no skill will be 4 times more slower than "godlike" bots when doing weapon combos
796 // Ideally this 4 should be calculated as longest_weapon_refire / bot_ai_weapon_combo_threshold
797 combo_time = time + ct + (ct * ((-0.3*skill)+3));
801 if(cvar("bot_ai_weapon_combo"))
802 if(self.weapon == self.lastfiredweapon)
806 self.lastcombotime = time;
809 // Custom weapon list based on distance to the enemy
810 if(bot_custom_weapon){
812 // Choose weapons for far distance
813 if ( distance > bot_distance_far ) {
814 for(i=0; i < WEP_COUNT && bot_weapons_far[i] != -1 ; ++i){
815 w = bot_weapons_far[i];
816 if ( client_hasweapon(self, w, TRUE, FALSE) ){
817 if ( self.weapon == w && combo)
819 self.switchweapon = w;
825 // Choose weapons for mid distance
826 if ( distance > bot_distance_close ) {
827 for(i=0; i < WEP_COUNT && bot_weapons_mid[i] != -1 ; ++i){
828 w = bot_weapons_mid[i];
829 if ( client_hasweapon(self, w, TRUE, FALSE) ){
830 if ( self.weapon == w && combo)
832 self.switchweapon = w;
838 // Choose weapons for close distance
839 for(i=0; i < WEP_COUNT && bot_weapons_close[i] != -1 ; ++i){
840 w = bot_weapons_close[i];
841 if ( client_hasweapon(self, w, TRUE, FALSE) ){
842 if ( self.weapon == w && combo)
844 self.switchweapon = w;
848 // If now weapon was chosen by this system fall back to the previous one
852 // (Damage/Sec * Weapon spefic change to get that damage)
853 // *(Time to get to target * weapon specfic hitchange bonus) / (in a time of maxdelaytime)
854 // *(Spread change of hit) // if it applies
855 // *(Penality for target beeing in air)
858 traceline(self.enemy.origin,self.enemy.origin-'0 0 1000',TRUE,world);
859 distancefromfloor = self.enemy.origin_z - trace_endpos_z;
861 if (client_hasweapon(self, WEP_MINSTANEX, TRUE, FALSE))
862 minstanex = (1000/cvar("g_balance_minstanex_refire")*1.0)
865 if (client_hasweapon(self, WEP_ROCKET_LAUNCHER, TRUE, FALSE) &&
866 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_ROCKET_LAUNCHER &&
870 rocket = (cvar("g_balance_rocketlauncher_damage")/cvar("g_balance_rocketlauncher_refire")*0.75)
871 * bound(0,(cvar("g_balance_rocketlauncher_speed")/distance*maxdelaytime),1)*1.5;
873 if (client_hasweapon(self, WEP_NEX, TRUE, FALSE) &&
874 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_NEX &&
878 nex = (cvar("g_balance_nex_damage")/cvar("g_balance_nex_refire")*1.0)
881 if (client_hasweapon(self, WEP_HAGAR, TRUE, FALSE) ) // &&
882 // !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_HAGAR && time < self.bot_lastshot + cvar("g_balance_hagar_primary_refire") ))
883 hagar = (cvar("g_balance_hagar_primary_damage")/cvar("g_balance_hagar_primary_refire")*1.0)
884 * bound(0,(cvar("g_balance_hagar_primary_speed")/distance*maxdelaytime),1)*0.2;
886 if (client_hasweapon(self, WEP_GRENADE_LAUNCHER, TRUE, FALSE) &&
888 cvar("bot_ai_weapon_combo") && self.weapon == WEP_GRENADE_LAUNCHER &&
892 grenade = (cvar("g_balance_grenadelauncher_primary_damage")/cvar("g_balance_grenadelauncher_primary_refire")*1.0)
893 * bound(0,(cvar("g_balance_grenadelauncher_primary_speed")/distance*maxdelaytime),1)*1.1;
895 if (client_hasweapon(self, WEP_ELECTRO, TRUE, FALSE) &&
896 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_ELECTRO &&
900 electro = (cvar("g_balance_electro_primary_damage")/cvar("g_balance_electro_primary_refire")*0.75)
901 * bound(0,(cvar("g_balance_electro_primary_speed")/distance*maxdelaytime),1)*1.0;
903 if (client_hasweapon(self, WEP_CRYLINK, TRUE, FALSE) ) // &&
904 // !( self.weapon == WEP_CRYLINK && time < self.bot_lastshot + cvar("g_balance_crylink_primary_refire") ))
905 crylink = (cvar("g_balance_crylink_primary_damage")/cvar("g_balance_crylink_primary_refire")*1.0)
906 * bound(0,(cvar("g_balance_crylink_primary_speed")/distance*maxdelaytime),1)*(64/(32+cvar("g_balance_crylink_primary_spread")*distance))*1.0;
908 if (client_hasweapon(self, WEP_UZI, TRUE, FALSE) ) // &&
909 // !( self.weapon == WEP_UZI && time < self.bot_lastshot + cvar("g_balance_uzi_sustained_refire") ))
910 uzi = (cvar("g_balance_uzi_sustained_damage")/cvar("g_balance_uzi_sustained_refire")*1.0)
911 * bound(0,32/(32+cvar("g_balance_uzi_sustained_spread")*distance),1);
913 if (client_hasweapon(self, WEP_SHOTGUN, TRUE, FALSE) &&
914 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_SHOTGUN &&
918 shotgun = (cvar("g_balance_shotgun_primary_damage")*cvar("g_balance_shotgun_primary_bullets")/cvar("g_balance_shotgun_primary_refire")*1.0)
919 * bound(0,32/(32+cvar("g_balance_shotgun_primary_spread")*distance),1);
921 if (client_hasweapon(self, WEP_LASER, FALSE, FALSE) &&
922 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_LASER &&
926 laser = (cvar("g_balance_laser_primary_damage")/cvar("g_balance_laser_primary_refire")*1.0)
927 * bound(0,cvar("g_balance_laser_primary_speed")/distance*maxdelaytime,1);
929 if((self.enemy.flags & FL_ONGROUND)==FALSE){
930 rocket = rocket * (1.5-bound(0, distancefromfloor/cvar("g_balance_rocketlauncher_radius" ),0.9)); //slight bigger change
931 grenade = grenade * (1.5-bound(0,distancefromfloor/cvar("g_balance_grenadelauncher_primary_radius"),0.95));
932 electro = electro * (1.5-bound(0,distancefromfloor/cvar("g_balance_electro_primary_radius" ),0.95));
933 laser = laser * (1.5-bound(0,distancefromfloor/cvar("g_balance_laser_primary_radius" ),0.95));
936 dprint("Floor distance: ",ftos(distancefromfloor),"\n");
937 dprint("Rocket: " , ftos(rocket ), "\n");
938 dprint("Nex: " , ftos(nex ), "\n");
939 dprint("Hagar: " , ftos(hagar ), "\n");
940 dprint("Grenade: ", ftos(grenade ), "\n");
941 dprint("Electro: ", ftos(electro ), "\n");
942 dprint("Crylink: ", ftos(crylink ), "\n");
943 dprint("Uzi: " , ftos(uzi ), "\n");
944 dprint("Shotgun :", ftos(shotgun ), "\n");
945 dprint("Laser :", ftos(laser ), "\n\n");
948 w = WEP_MINSTANEX ;s = minstanex;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
949 w = WEP_ROCKET_LAUNCHER ;s = rocket ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
950 w = WEP_NEX ;s = nex ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
951 w = WEP_HAGAR ;s = hagar ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
952 w = WEP_GRENADE_LAUNCHER ;s = grenade ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
953 w = WEP_ELECTRO ;s = electro ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
954 w = WEP_CRYLINK ;s = crylink ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
955 w = WEP_UZI ;s = uzi ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
956 w = WEP_SHOTGUN ;s = shotgun ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
957 w = WEP_LASER ;s = laser ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
959 // switch if the best weapon would provide a significant damage increase
960 if (bestscore > currentscore*1.5){
961 self.switchweapon = bestweapon;
963 // buys time for detonating the rocket. not tested yet
964 if ( cvar("bot_ai_weapon_combo") && bestweapon == WEP_ROCKET_LAUNCHER )
965 self.bot_chooseweapontime += (distance / cvar("g_balance_rocketlauncher_speed"));
972 local vector selfvel, enemyvel;
973 // if(self.flags & FL_INWATER)
975 if (time < self.nextaim)
977 self.nextaim = time + 0.1;
978 selfvel = self.velocity;
979 if (!self.waterlevel)
983 enemyvel = self.enemy.velocity;
984 if (!self.enemy.waterlevel)
986 lag_additem(time + self.ping, 0, 0, self.enemy, self.origin, selfvel, self.enemy.origin, enemyvel);
989 lag_additem(time + self.ping, 0, 0, world, self.origin, selfvel, self.goalcurrent.origin, '0 0 0');
994 if(bot_execute_commands())
997 if (bot_strategytoken == self)
998 if (!bot_strategytoken_taken)
1000 if(self.havocbot_blockhead)
1002 self.havocbot_blockhead = FALSE;
1006 self.havocbot_role();
1009 // TODO: tracewalk() should take care of this job (better path finding under water)
1010 // if we don't have a goal and we're under water look for a waypoint near the "shore" and push it
1011 if(self.goalcurrent==world)
1012 if(self.waterlevel==WATERLEVEL_SWIMMING || self.aistatus & AI_STATUS_OUT_WATER)
1014 // Look for the closest waypoint out of water
1015 local entity newgoal, head;
1016 local float bestdistance, distance;
1019 bestdistance = 10000;
1020 for (head = findchain(classname, "waypoint"); head; head = head.chain)
1022 distance = vlen(head.origin - self.origin);
1026 if(head.origin_z < self.origin_z)
1029 if(head.origin_z - self.origin_z - self.view_ofs_z > 100)
1032 if (pointcontents(head.origin + head.maxs + '0 0 1') != CONTENT_EMPTY)
1035 traceline(self.origin + self.view_ofs , head.origin, TRUE, head);
1037 if(trace_fraction<1)
1040 if(distance<bestdistance)
1043 bestdistance = distance;
1049 // te_wizspike(newgoal.origin);
1050 navigation_pushroute(newgoal);
1054 // token has been used this frame
1055 bot_strategytoken_taken = TRUE;
1057 havocbot_chooseenemy();
1058 if (self.bot_chooseweapontime < time )
1060 self.bot_chooseweapontime = time + cvar("bot_ai_chooseweaponinterval");
1061 havocbot_chooseweapon();
1065 if (self.bot_aimtarg)
1067 self.aistatus |= AI_STATUS_ATTACKING;
1068 self.aistatus &~= AI_STATUS_ROAMING;
1070 weapon_action(self.weapon, WR_AIM);
1071 if (cvar("bot_nofire") || IS_INDEPENDENT_PLAYER(self))
1073 self.BUTTON_ATCK = FALSE;
1074 self.BUTTON_ATCK2 = FALSE;
1078 if(self.BUTTON_ATCK||self.BUTTON_ATCK2)
1079 self.lastfiredweapon = self.weapon;
1082 else if (self.goalcurrent)
1084 self.aistatus |= AI_STATUS_ROAMING;
1085 self.aistatus &~= AI_STATUS_ATTACKING;
1087 local vector now,v,next;//,heading;
1088 local float aimdistance,skillblend,distanceblend,blend;
1089 next = now = self.goalcurrent.origin - (self.origin + self.view_ofs);
1090 aimdistance = vlen(now);
1091 //heading = self.velocity;
1092 //dprint(self.goalstack01.classname,etos(self.goalstack01),"\n");
1094 self.goalstack01 != self && self.goalstack01 != world && self.aistatus & AI_STATUS_RUNNING == 0 &&
1095 !(self.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
1097 next = self.goalstack01.origin - (self.origin + self.view_ofs);
1099 skillblend=bound(0,(skill-2.5)*0.5,1); //lower skill player can't preturn
1100 distanceblend=bound(0,aimdistance/cvar("bot_ai_keyboard_distance"),1);
1101 blend = skillblend * (1-distanceblend);
1102 //v = (now * (distanceblend) + next * (1-distanceblend)) * (skillblend) + now * (1-skillblend);
1103 //v = now * (distanceblend) * (skillblend) + next * (1-distanceblend) * (skillblend) + now * (1-skillblend);
1104 //v = now * ((1-skillblend) + (distanceblend) * (skillblend)) + next * (1-distanceblend) * (skillblend);
1105 v = now + blend * (next - now);
1106 //dprint(etos(self), " ");
1107 //dprint(vtos(now), ":", vtos(next), "=", vtos(v), " (blend ", ftos(blend), ")\n");
1108 //v = now * (distanceblend) + next * (1-distanceblend);
1109 if (self.waterlevel < WATERLEVEL_SWIMMING)
1111 //dprint("walk at:", vtos(v), "\n");
1112 //te_lightning2(world, self.origin, self.goalcurrent.origin);
1115 havocbot_movetogoal();
1118 void havocbot_setupbot()
1120 self.bot_ai = havocbot_ai;
1121 // will be updated by think code
1122 //Generate some random skill levels
1123 self.havocbot_keyboardskill=random()-0.5;
1124 havocbot_chooserole();
1128 #ifdef DEBUG_BOT_GOALSTACK
1131 .vector lastposition;
1133 // Debug the goal stack visually
1134 void debuggoalstack()
1136 local entity target;
1139 if(self.goalcounter==0)target=self.goalcurrent;
1140 else if(self.goalcounter==1)target=self.goalstack01;
1141 else if(self.goalcounter==2)target=self.goalstack02;
1142 else if(self.goalcounter==3)target=self.goalstack03;
1143 else if(self.goalcounter==4)target=self.goalstack04;
1144 else if(self.goalcounter==5)target=self.goalstack05;
1145 else if(self.goalcounter==6)target=self.goalstack06;
1146 else if(self.goalcounter==7)target=self.goalstack07;
1147 else if(self.goalcounter==8)target=self.goalstack08;
1148 else if(self.goalcounter==9)target=self.goalstack09;
1149 else if(self.goalcounter==10)target=self.goalstack10;
1150 else if(self.goalcounter==11)target=self.goalstack11;
1151 else if(self.goalcounter==12)target=self.goalstack12;
1152 else if(self.goalcounter==13)target=self.goalstack13;
1153 else if(self.goalcounter==14)target=self.goalstack14;
1154 else if(self.goalcounter==15)target=self.goalstack15;
1155 else if(self.goalcounter==16)target=self.goalstack16;
1156 else if(self.goalcounter==17)target=self.goalstack17;
1157 else if(self.goalcounter==18)target=self.goalstack18;
1158 else if(self.goalcounter==19)target=self.goalstack19;
1159 else if(self.goalcounter==20)target=self.goalstack20;
1160 else if(self.goalcounter==21)target=self.goalstack21;
1161 else if(self.goalcounter==22)target=self.goalstack22;
1162 else if(self.goalcounter==23)target=self.goalstack23;
1163 else if(self.goalcounter==24)target=self.goalstack24;
1164 else if(self.goalcounter==25)target=self.goalstack25;
1165 else if(self.goalcounter==26)target=self.goalstack26;
1166 else if(self.goalcounter==27)target=self.goalstack27;
1167 else if(self.goalcounter==28)target=self.goalstack28;
1168 else if(self.goalcounter==29)target=self.goalstack29;
1169 else if(self.goalcounter==30)target=self.goalstack30;
1170 else if(self.goalcounter==31)target=self.goalstack31;
1174 self.goalcounter = 0;
1175 self.lastposition='0 0 0';
1179 if(self.lastposition=='0 0 0')
1182 org = self.lastposition;
1185 te_lightning2(world, org, target.origin);
1186 self.lastposition = target.origin;