2 void() havocbot_chooserole;
3 .float havocbot_keyboardskill;
4 .float facingwalltime, ignoregoaltime;
7 #ifdef DEBUG_BOT_GOALSTACK
11 vector havocbot_dodge()
13 // LordHavoc: disabled because this is too expensive
17 local vector dodge, v, n;
18 local float danger, bestdanger, vl, d;
21 // check for dangerous objects near bot or approaching bot
22 head = findchainfloat(bot_dodge, TRUE);
25 if (head.owner != self)
27 vl = vlen(head.velocity);
28 if (vl > sv_maxspeed * 0.3)
30 n = normalize(head.velocity);
31 v = self.origin - head.origin;
33 if (d > (0 - head.bot_dodgerating))
34 if (d < (vl * 0.2 + head.bot_dodgerating))
36 // calculate direction and distance from the flight path, by removing the forward axis
37 v = v - (n * (v * n));
38 danger = head.bot_dodgerating - vlen(v);
39 if (bestdanger < danger)
42 // dodge to the side of the object
49 danger = head.bot_dodgerating - vlen(head.origin - self.origin);
50 if (bestdanger < danger)
53 dodge = normalize(self.origin - head.origin);
63 .float havocbot_keyboardtime;
64 .float havocbot_ducktime;
65 .vector havocbot_keyboard;
66 void havocbot_keyboard_movement(vector destorg)
68 local vector keyboard;
69 local float blend, maxspeed;
71 maxspeed = cvar("sv_maxspeed");
73 if (time < self.havocbot_keyboardtime)
76 self.havocbot_keyboardtime =
78 self.havocbot_keyboardtime
79 + bound(0,0.05/(skill+self.havocbot_keyboardskill),0.05)
80 +random()*bound(0,0.025/(skill+self.havocbot_keyboardskill),100)
82 keyboard = self.movement * (1.0 / maxspeed);
84 local float trigger, trigger1;
85 blend = bound(0,skill*0.1,1);
86 trigger = cvar("bot_ai_keyboard_treshold");
87 trigger1 = 0 - trigger;
89 // categorize forward movement
90 // at skill < 1.5 only forward
91 // at skill < 2.5 only individual directions
92 // at skill < 4.5 only individual directions, and forward diagonals
93 // at skill >= 4.5, all cases allowed
94 if (keyboard_x > trigger)
100 else if (keyboard_x < trigger1 && skill > 1.5)
115 if (keyboard_y > trigger)
117 else if (keyboard_y < trigger1)
122 if (keyboard_z > trigger)
124 else if (keyboard_z < trigger1)
129 self.havocbot_keyboard = keyboard * maxspeed;
130 if (self.havocbot_ducktime>time) self.BUTTON_CROUCH=TRUE;
132 keyboard = self.havocbot_keyboard;
133 blend = bound(0,vlen(destorg-self.origin)/cvar("bot_ai_keyboard_distance"),1); // When getting close move with 360 degree
134 //dprint("movement ", vtos(self.movement), " keyboard ", vtos(keyboard), " blend ", ftos(blend), "\n");
135 self.movement = self.movement + (keyboard - self.movement) * blend;
138 .entity bot_lastseengoal;
139 .float bot_timelastseengoal;
140 .float bot_canruntogoal;
141 void havocbot_bunnyhop(vector dir)
143 local float bunnyhopdistance;
144 local vector deviation;
145 local float maxspeed;
147 if(self.goalcurrent.classname == "player")
150 maxspeed = cvar("sv_maxspeed");
152 if(self.aistatus & AI_STATUS_DANGER_AHEAD)
154 self.aistatus &~= AI_STATUS_RUNNING;
155 self.BUTTON_JUMP = FALSE;
159 if(self.waterlevel > WATERLEVEL_WETFEET)
161 self.aistatus &~= AI_STATUS_RUNNING;
165 if(self.bot_lastseengoal != self.goalcurrent && !(self.aistatus & AI_STATUS_RUNNING))
167 self.bot_canruntogoal = 0;
168 self.bot_timelastseengoal = 0;
171 bunnyhopdistance = vlen(self.origin - self.goalcurrent.origin);
173 // Run only to visible goals
174 if(self.flags & FL_ONGROUND)
175 if(self.speed==maxspeed)
176 if(checkpvs(self.origin + self.view_ofs, self.goalcurrent))
178 self.bot_lastseengoal = self.goalcurrent;
181 if(self.bot_timelastseengoal)
183 // for a period of time
184 if(time - self.bot_timelastseengoal > cvar("bot_ai_bunnyhop_firstjumpdelay"))
186 local float checkdistance;
187 checkdistance = TRUE;
189 // don't run if it is too close
190 if(self.bot_canruntogoal==0)
192 if(bunnyhopdistance > cvar("bot_ai_bunnyhop_startdistance"))
193 self.bot_canruntogoal = 1;
195 self.bot_canruntogoal = -1;
198 if(self.bot_canruntogoal != 1)
201 if(self.aistatus & AI_STATUS_ROAMING)
202 if(self.goalcurrent.classname=="waypoint")
203 if(fabs(self.goalcurrent.origin_z - self.origin_z) < self.maxs_z - self.mins_z)
204 if(self.goalstack01!=world)
206 deviation = vectoangles(self.goalstack01.origin - self.origin) - vectoangles(self.goalcurrent.origin - self.origin);
207 while (deviation_y < -180) deviation_y = deviation_y + 360;
208 while (deviation_y > 180) deviation_y = deviation_y - 360;
210 if(fabs(deviation_y) < 20)
211 if(bunnyhopdistance < vlen(self.origin - self.goalstack01.origin))
212 if(fabs(self.goalstack01.origin_z - self.goalcurrent.origin_z) < self.maxs_z - self.mins_z)
214 if(vlen(self.goalcurrent.origin - self.goalstack01.origin) > cvar("bot_ai_bunnyhop_startdistance"))
215 if(checkpvs(self.origin + self.view_ofs, self.goalstack01))
217 checkdistance = FALSE;
224 self.aistatus &~= AI_STATUS_RUNNING;
225 if(bunnyhopdistance > cvar("bot_ai_bunnyhop_stopdistance"))
226 self.BUTTON_JUMP = TRUE;
230 self.aistatus |= AI_STATUS_RUNNING;
231 self.BUTTON_JUMP = TRUE;
237 self.bot_timelastseengoal = time;
242 self.bot_timelastseengoal = 0;
245 // Release jump button
246 if(self.flags & FL_ONGROUND == 0)
248 if(self.velocity_z < 0 || vlen(self.velocity)<maxspeed)
249 self.BUTTON_JUMP = FALSE;
252 if(self.aistatus & AI_STATUS_RUNNING)
253 if(vlen(self.velocity)>maxspeed)
255 deviation = vectoangles(dir) - vectoangles(self.velocity);
256 while (deviation_y < -180) deviation_y = deviation_y + 360;
257 while (deviation_y > 180) deviation_y = deviation_y - 360;
259 if(fabs(deviation_y)>10)
263 self.movement_y = maxspeed * -1;
264 else if(deviation_y<10)
265 self.movement_y = maxspeed;
271 //.float havocbotignoretime;
272 //.vector bot_dodgevector;
273 //.float bot_dodgevector_time;
274 //.float bot_dodgevector_jumpbutton;
276 .entity ladder_entity;
277 void havocbot_movetogoal()
279 local vector destorg;
282 local vector flatdir;
285 local vector evadeobstacle;
286 local vector evadelava;
288 local float maxspeed;
291 //if (self.goalentity)
292 // te_lightning2(self, self.origin, (self.goalentity.absmin + self.goalentity.absmax) * 0.5);
293 self.movement = '0 0 0';
294 maxspeed = cvar("sv_maxspeed");
296 if(self.jumppadcount)
298 if(self.flags & FL_ONGROUND)
300 self.jumppadcount = FALSE;
301 if(self.aistatus & AI_STATUS_OUT_JUMPPAD)
302 self.aistatus &~= AI_STATUS_OUT_JUMPPAD;
305 // If got stuck on the jump pad try to reach the farther visible item
306 if(self.aistatus & AI_STATUS_OUT_JUMPPAD)
308 if(fabs(self.velocity_z)<50)
310 local entity head, newgoal;
311 local float distance, bestdistance;
313 for (head = findchainfloat(bot_pickup, TRUE); head; head = head.chain)
315 if(head.classname=="worldspawn")
318 distance = vlen(head.origin - self.origin);
322 traceline(self.origin + self.view_ofs , head.origin, TRUE, world);
327 if(distance>bestdistance)
330 bestdistance = distance;
336 self.ignoregoal = self.goalcurrent;
337 self.ignoregoaltime = time + cvar("bot_ai_ignoregoal_timeout");
338 navigation_routetogoal(newgoal);
339 self.aistatus &~= AI_STATUS_OUT_JUMPPAD;
347 if(self.velocity_z>0)
349 local float threshold;
350 threshold = maxspeed * 0.2;
351 if(fabs(self.velocity_x) < threshold && fabs(self.velocity_y) < threshold)
352 self.aistatus |= AI_STATUS_OUT_JUMPPAD;
358 // If there is a trigger_hurt right below try to use the jetpack or make a rocketjump
359 if not(self.flags & FL_ONGROUND)
361 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 -65536', MOVE_NOMONSTERS, self);
363 if(tracebox_hits_trigger_hurt(self.origin, self.mins, self.maxs, trace_endpos ))
364 if(self.items & IT_JETPACK)
366 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 65536', MOVE_NOMONSTERS, self);
368 if(tracebox_hits_trigger_hurt(self.origin, self.mins, self.maxs, trace_endpos + '0 0 1' ))
370 if(self.velocity_z<0)
372 self.BUTTON_HOOK = TRUE;
376 self.BUTTON_HOOK = TRUE;
378 else if(self.health>cvar("g_balance_rocketlauncher_damage")*0.5)
380 if(self.velocity_z < -maxspeed)
381 if(client_hasweapon(self, WEP_ROCKET_LAUNCHER, TRUE, FALSE))
383 self.switchweapon = WEP_ROCKET_LAUNCHER;
385 self.BUTTON_ATCK = TRUE;
386 self.BUTTON_ATCK2 = TRUE;
391 // If we are under water with no goals, swim up
393 if(self.goalcurrent==world)
396 if(self.waterlevel>WATERLEVEL_SWIMMING)
398 else if(self.velocity_z >= 0 && !(self.waterlevel == WATERLEVEL_WETFEET && self.watertype == CONTENT_WATER))
399 self.BUTTON_JUMP = TRUE;
401 self.BUTTON_JUMP = FALSE;
402 makevectors(self.v_angle_y * '0 1 0');
403 self.movement_x = dir * v_forward * maxspeed;
404 self.movement_y = dir * v_right * maxspeed;
405 self.movement_z = dir * v_up * maxspeed;
408 // if there is nowhere to go, exit
409 if (self.goalcurrent == world)
412 if (self.goalcurrent)
413 navigation_poptouchedgoals();
415 // if ran out of goals try to use an alternative goal or get a new strategy asap
416 if(self.goalcurrent == world)
417 if(self.flags & FL_ONGROUND || self.aistatus & AI_STATUS_RUNNING || self.BUTTON_JUMP == TRUE)
419 if(self.alternativegoal==world)
422 self.bot_strategytime = 0;
426 // use the alternative goal
427 navigation_findnearestwaypoint(self.alternativegoal, TRUE);
428 navigation_routetogoal(self.alternativegoal);
429 self.alternativegoal = world;
430 bot_strategytoken_taken = TRUE;
435 #ifdef DEBUG_BOT_GOALSTACK
439 m1 = self.goalcurrent.origin + self.goalcurrent.mins;
440 m2 = self.goalcurrent.origin + self.goalcurrent.maxs;
441 destorg = self.origin;
442 destorg_x = bound(m1_x, destorg_x, m2_x);
443 destorg_y = bound(m1_y, destorg_y, m2_y);
444 destorg_z = bound(m1_z, destorg_z, m2_z);
445 diff = destorg - self.origin;
447 dir = normalize(diff);
448 flatdir = diff;flatdir_z = 0;
449 flatdir = normalize(flatdir);
451 //if (self.bot_dodgevector_time < time)
453 // self.bot_dodgevector_time = time + cvar("bot_ai_dodgeupdateinterval");
454 // self.bot_dodgevector_jumpbutton = 1;
455 evadeobstacle = '0 0 0';
460 if(self.waterlevel>WATERLEVEL_SWIMMING)
463 self.aistatus |= AI_STATUS_OUT_WATER;
467 if(self.velocity_z >= 0 && !(self.watertype == CONTENT_WATER && self.goalcurrent.origin_z < self.origin_z) &&
468 ( !(self.waterlevel == WATERLEVEL_WETFEET && self.watertype == CONTENT_WATER) || self.aistatus & AI_STATUS_OUT_WATER))
469 self.BUTTON_JUMP = TRUE;
471 self.BUTTON_JUMP = FALSE;
473 dir = normalize(flatdir);
474 makevectors(self.v_angle_y * '0 1 0');
478 if(self.aistatus & AI_STATUS_OUT_WATER)
479 self.aistatus &~= AI_STATUS_OUT_WATER;
481 // jump if going toward an obstacle that doesn't look like stairs we
482 // can walk up directly
483 tracebox(self.origin, self.mins, self.maxs, self.origin + self.velocity * 0.2, FALSE, self);
484 if (trace_fraction < 1)
485 if (trace_plane_normal_z < 0.7)
488 tracebox(self.origin + '0 0 16', self.mins, self.maxs, self.origin + self.velocity * 0.2 + '0 0 16', FALSE, self);
489 if (trace_fraction < s + 0.01)
490 if (trace_plane_normal_z < 0.7)
493 tracebox(self.origin + '0 0 48', self.mins, self.maxs, self.origin + self.velocity * 0.2 + '0 0 48', FALSE, self);
494 if (trace_fraction > s)
495 self.BUTTON_JUMP = 1;
499 // avoiding dangers and obstacles
500 local vector dst_ahead, dst_down;
501 dst_ahead = self.origin + self.view_ofs + (self.velocity * 0.32);
502 dst_down = dst_ahead + '0 0 -1500';
505 traceline(self.origin + self.view_ofs , dst_ahead, TRUE, world);
507 // Check head-banging against walls
508 if(vlen(self.origin + self.view_ofs - trace_endpos) < 2 && !(self.aistatus & AI_STATUS_OUT_WATER))
510 if(self.facingwalltime && time > self.facingwalltime)
512 self.ignoregoal = self.goalcurrent;
513 self.ignoregoaltime = time + cvar("bot_ai_ignoregoal_timeout");
514 navigation_poproute();
518 self.facingwalltime = time + 0.05;
523 self.facingwalltime = 0;
525 if(self.ignoregoal != world && time > self.ignoregoaltime)
527 self.ignoregoal = world;
528 self.ignoregoaltime = 0;
532 // Check for water/slime/lava and dangerous edges
533 // (only when the bot is on the ground or jumping intentionally)
534 self.aistatus &~= AI_STATUS_DANGER_AHEAD;
536 if(trace_fraction == 1)
537 if(self.flags & FL_ONGROUND || self.aistatus & AI_STATUS_RUNNING || self.BUTTON_JUMP == TRUE)
540 traceline(dst_ahead , dst_down, TRUE, world);
541 // te_lightning2(world, self.origin, dst_ahead); // Draw "ahead" look
542 // te_lightning2(world, dst_ahead, dst_down); // Draw "downwards" look
543 if(trace_endpos_z < self.origin_z + self.mins_z)
545 s = pointcontents(trace_endpos + '0 0 1');
546 if (s != CONTENT_SOLID)
547 if (s == CONTENT_LAVA || s == CONTENT_SLIME)
548 evadelava = normalize(self.velocity) * -1;
549 else if (s == CONTENT_SKY)
550 evadeobstacle = normalize(self.velocity) * -1;
551 else if (!boxesoverlap(dst_ahead - self.view_ofs + self.mins, dst_ahead - self.view_ofs + self.maxs,
552 self.goalcurrent.absmin, self.goalcurrent.absmax))
554 // if ain't a safe goal with "holes" (like the jumpad on soylent)
555 // and there is a trigger_hurt below
556 if(tracebox_hits_trigger_hurt(dst_ahead, self.mins, self.maxs, trace_endpos))
558 // Remove dangerous dynamic goals from stack
559 if (self.goalcurrent.classname == "player" || self.goalcurrent.classname == "droppedweapon")
560 navigation_poproute();
563 evadeobstacle = normalize(self.velocity) * -1;
572 makevectors(self.v_angle_y * '0 1 0');
574 if(evadeobstacle!='0 0 0'||evadelava!='0 0 0')
575 self.aistatus |= AI_STATUS_DANGER_AHEAD;
578 dodge = havocbot_dodge();
579 dodge = dodge * bound(0,3+skill*0.1,1);
580 evadelava = evadelava * bound(1,3-skill,3); //Noobs fear lava a lot and take more distance from it
581 traceline(self.origin, self.enemy.origin, TRUE, world);
582 if(trace_ent.classname == "player")
583 dir = dir * bound(0,skill/7,1);
585 dir = normalize(dir + dodge + evadeobstacle + evadelava);
586 // self.bot_dodgevector = dir;
587 // self.bot_dodgevector_jumpbutton = self.BUTTON_JUMP;
590 if(time < self.ladder_time)
592 if(self.goalcurrent.origin_z + self.goalcurrent.mins_z > self.origin_z + self.mins_z)
594 if(self.origin_z + self.mins_z < self.ladder_entity.origin_z + self.ladder_entity.maxs_z)
599 if(self.origin_z + self.mins_z > self.ladder_entity.origin_z + self.ladder_entity.mins_z)
604 //dir = self.bot_dodgevector;
605 //if (self.bot_dodgevector_jumpbutton)
606 // self.BUTTON_JUMP = 1;
607 self.movement_x = dir * v_forward * maxspeed;
608 self.movement_y = dir * v_right * maxspeed;
609 self.movement_z = dir * v_up * maxspeed;
611 // Emulate keyboard interface
613 havocbot_keyboard_movement(destorg);
616 // if(self.aistatus & AI_STATUS_ROAMING)
617 if(skill >= cvar("bot_ai_bunnyhop_skilloffset"))
618 havocbot_bunnyhop(dir);
620 if ((dir * v_up) >= cvar("sv_jumpvelocity")*0.5 && (self.flags & FL_ONGROUND)) self.BUTTON_JUMP=1;
621 if (((dodge * v_up) > 0) && random()*frametime >= 0.2*bound(0,(10-skill)*0.1,1)) self.BUTTON_JUMP=TRUE;
622 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);
625 .float havocbot_chooseenemy_finished;
626 .float havocbot_stickenemy;
627 void havocbot_chooseenemy()
629 local entity head, best;
630 local float rating, bestrating;
632 if (cvar("bot_nofire") || IS_INDEPENDENT_PLAYER(self))
639 if (!bot_shouldattack(self.enemy))
641 // enemy died or something, find a new target
643 self.havocbot_chooseenemy_finished = time;
645 else if (self.havocbot_stickenemy)
647 // tracking last chosen enemy
648 // if enemy is visible
649 // and not really really far away
650 // and we're not severely injured
651 // then keep tracking for a half second into the future
652 traceline(self.origin+self.view_ofs, self.enemy.origin+self.enemy.view_ofs*0.5,FALSE,world);
653 if (trace_ent == self.enemy || trace_fraction == 1)
654 if (vlen(self.enemy.origin - self.origin) < 1000)
655 if (self.health > 30)
657 // remain tracking him for a shot while (case he went after a small corner or pilar
658 self.havocbot_chooseenemy_finished = time + cvar("bot_ai_enemydetectioninterval");
661 // enemy isn't visible, or is far away, or we're injured severely
662 // so stop preferring this enemy
663 // (it will still take a half second until a new one is chosen)
664 self.havocbot_stickenemy = 0;
667 if (time < self.havocbot_chooseenemy_finished)
669 self.havocbot_chooseenemy_finished = time + cvar("bot_ai_enemydetectioninterval");
670 eye = (self.origin + self.view_ofs);
672 bestrating = 100000000;
673 head = findchainfloat(bot_attack, TRUE);
676 v = (head.absmin + head.absmax) * 0.5;
677 rating = vlen(v - eye);
678 if (bestrating > rating)
679 if (bot_shouldattack(head))
681 traceline(eye, v, TRUE, self);
682 if (trace_ent == head || trace_fraction >= 1)
691 self.havocbot_stickenemy = TRUE;
694 .float bot_chooseweapontime;
695 float(entity e) w_getbestweapon;
696 void havocbot_chooseweapon()
700 // TODO: clean this up by moving it to weapon code
701 if(self.enemy.classname!="player")
703 // If there aren't enemies at sight use the laser (like most players)
704 if(client_hasweapon(self, WEP_LASER, TRUE, FALSE))
706 self.switchweapon = WEP_LASER;
710 // Otherwise get the first available weapon
711 for(i=WEP_LASER + 1; i < WEP_COUNT ; ++i)
713 if(client_hasweapon(self, i, TRUE, FALSE))
715 self.switchweapon = i;
723 local float rocket ; rocket =-1000;
724 local float nex ; nex =-1000;
725 local float hagar ; hagar =-1000;
726 local float grenade ; grenade =-1000;
727 local float electro ; electro =-1000;
728 local float crylink ; crylink =-1000;
729 local float uzi ; uzi =-1000;
730 local float shotgun ; shotgun =-1000;
731 local float campingrifle ; campingrifle =-1000;
732 local float laser ; laser =-1000;
733 local float minstanex ; minstanex =-1000;
734 local float currentscore;
735 local float bestscore; bestscore = 0;
736 local float bestweapon; bestweapon=self.switchweapon;
737 local float distance; distance=bound(10,vlen(self.origin-self.enemy.origin)-200,10000);
738 local float maxdelaytime=0.5;
739 local float spreadpenalty=10;
740 local float distancefromfloor;
742 local float af, ct, combo_time;
744 traceline(self.enemy.origin,self.enemy.origin-'0 0 1000',TRUE,world);
745 distancefromfloor = self.enemy.origin_z - trace_endpos_z;
747 af = ATTACK_FINISHED(self);
748 ct = cvar("bot_ai_weapon_combo_threshold");
750 // Bots with no skill will be 4 times more slower than "godlike" bots when doing weapon combos
751 // Ideally this 4 should be calculated as longest_weapon_refire / bot_ai_weapon_combo_threshold
752 combo_time = time + ct + (ct * ((-0.3*skill)+3));
754 // Custom weapon list based on distance to the enemy
756 if(bot_custom_weapon){
758 // Choose weapons for far distance
759 if ( distance > bot_distance_far ) {
760 for(i=0; i < WEP_COUNT && bot_weapons_far[i] != -1 ; ++i){
761 w = bot_weapons_far[i];
762 if ( client_hasweapon(self, w, TRUE, FALSE) ){
763 if ( self.weapon == w){
764 if( cvar("bot_ai_weapon_combo") && af > combo_time)
767 self.switchweapon = w;
774 // Choose weapons for mid distance
775 if ( distance > bot_distance_close ) {
776 for(i= 0; i < WEP_COUNT && bot_weapons_mid[i] != -1 ; ++i){
777 w = bot_weapons_mid[i];
778 if ( client_hasweapon(self, w, TRUE, FALSE) ){
779 if ( self.weapon == w){
780 if( cvar("bot_ai_weapon_combo") && af > combo_time)
783 self.switchweapon = w;
790 // Choose weapons for close distance
791 for(i= 0; i < WEP_COUNT && bot_weapons_close[i] != -1 ; ++i){
792 w = bot_weapons_close[i];
793 if ( client_hasweapon(self, w, TRUE, FALSE) ){
794 if ( self.weapon == w){
795 if( cvar("bot_ai_weapon_combo") && af > combo_time)
798 self.switchweapon = w;
803 // If now weapon was chosen by this system fall back to the previous one
807 // (Damage/Sec * Weapon spefic change to get that damage)
808 // *(Time to get to target * weapon specfic hitchange bonus) / (in a time of maxdelaytime)
809 // *(Spread change of hit) // if it applies
810 // *(Penality for target beeing in air)
812 if (client_hasweapon(self, WEP_MINSTANEX, TRUE, FALSE))
813 minstanex = (1000/cvar("g_balance_minstanex_refire")*1.0)
816 if (client_hasweapon(self, WEP_ROCKET_LAUNCHER, TRUE, FALSE) &&
817 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_ROCKET_LAUNCHER &&
821 rocket = (cvar("g_balance_rocketlauncher_damage")/cvar("g_balance_rocketlauncher_refire")*0.75)
822 * bound(0,(cvar("g_balance_rocketlauncher_speed")/distance*maxdelaytime),1)*1.5;
824 if (client_hasweapon(self, WEP_NEX, TRUE, FALSE) &&
825 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_NEX &&
829 nex = (cvar("g_balance_nex_damage")/cvar("g_balance_nex_refire")*1.0)
832 if (client_hasweapon(self, WEP_HAGAR, TRUE, FALSE) ) // &&
833 // !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_HAGAR && time < self.bot_lastshot + cvar("g_balance_hagar_primary_refire") ))
834 hagar = (cvar("g_balance_hagar_primary_damage")/cvar("g_balance_hagar_primary_refire")*1.0)
835 * bound(0,(cvar("g_balance_hagar_primary_speed")/distance*maxdelaytime),1)*0.2;
837 if (client_hasweapon(self, WEP_GRENADE_LAUNCHER, TRUE, FALSE) &&
839 cvar("bot_ai_weapon_combo") && self.weapon == WEP_GRENADE_LAUNCHER &&
843 grenade = (cvar("g_balance_grenadelauncher_primary_damage")/cvar("g_balance_grenadelauncher_primary_refire")*1.0)
844 * bound(0,(cvar("g_balance_grenadelauncher_primary_speed")/distance*maxdelaytime),1)*1.1;
846 if (client_hasweapon(self, WEP_ELECTRO, TRUE, FALSE) &&
847 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_ELECTRO &&
851 electro = (cvar("g_balance_electro_primary_damage")/cvar("g_balance_electro_primary_refire")*0.75)
852 * bound(0,(cvar("g_balance_electro_primary_speed")/distance*maxdelaytime),1)*1.0;
854 if (client_hasweapon(self, WEP_CRYLINK, TRUE, FALSE) ) // &&
855 // !( self.weapon == WEP_CRYLINK && time < self.bot_lastshot + cvar("g_balance_crylink_primary_refire") ))
856 crylink = (cvar("g_balance_crylink_primary_damage")/cvar("g_balance_crylink_primary_refire")*1.0)
857 * bound(0,(cvar("g_balance_crylink_primary_speed")/distance*maxdelaytime),1)*(64/(32+cvar("g_balance_crylink_primary_spread")*distance))*1.0;
859 if (client_hasweapon(self, WEP_UZI, TRUE, FALSE) ) // &&
860 // !( self.weapon == WEP_UZI && time < self.bot_lastshot + cvar("g_balance_uzi_sustained_refire") ))
861 uzi = (cvar("g_balance_uzi_sustained_damage")/cvar("g_balance_uzi_sustained_refire")*1.0)
862 * bound(0,32/(32+cvar("g_balance_uzi_sustained_spread")*distance),1);
864 if (client_hasweapon(self, WEP_SHOTGUN, TRUE, FALSE) &&
865 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_SHOTGUN &&
869 shotgun = (cvar("g_balance_shotgun_primary_damage")*cvar("g_balance_shotgun_primary_bullets")/cvar("g_balance_shotgun_primary_refire")*1.0)
870 * bound(0,32/(32+cvar("g_balance_shotgun_primary_spread")*distance),1);
872 if (client_hasweapon(self, WEP_LASER, FALSE, FALSE) &&
873 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_LASER &&
877 laser = (cvar("g_balance_laser_primary_damage")/cvar("g_balance_laser_primary_refire")*1.0)
878 * bound(0,cvar("g_balance_laser_primary_speed")/distance*maxdelaytime,1);
880 if((self.enemy.flags & FL_ONGROUND)==FALSE){
881 rocket = rocket * (1.5-bound(0, distancefromfloor/cvar("g_balance_rocketlauncher_radius" ),0.9)); //slight bigger change
882 grenade = grenade * (1.5-bound(0,distancefromfloor/cvar("g_balance_grenadelauncher_primary_radius"),0.95));
883 electro = electro * (1.5-bound(0,distancefromfloor/cvar("g_balance_electro_primary_radius" ),0.95));
884 laser = laser * (1.5-bound(0,distancefromfloor/cvar("g_balance_laser_primary_radius" ),0.95));
887 dprint("Floor distance: ",ftos(distancefromfloor),"\n");
888 dprint("Rocket: " , ftos(rocket ), "\n");
889 dprint("Nex: " , ftos(nex ), "\n");
890 dprint("Hagar: " , ftos(hagar ), "\n");
891 dprint("Grenade: ", ftos(grenade ), "\n");
892 dprint("Electro: ", ftos(electro ), "\n");
893 dprint("Crylink: ", ftos(crylink ), "\n");
894 dprint("Uzi: " , ftos(uzi ), "\n");
895 dprint("Shotgun :", ftos(shotgun ), "\n");
896 dprint("Laser :", ftos(laser ), "\n\n");
899 w = WEP_MINSTANEX ;s = minstanex;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
900 w = WEP_ROCKET_LAUNCHER ;s = rocket ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
901 w = WEP_NEX ;s = nex ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
902 w = WEP_HAGAR ;s = hagar ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
903 w = WEP_GRENADE_LAUNCHER ;s = grenade ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
904 w = WEP_ELECTRO ;s = electro ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
905 w = WEP_CRYLINK ;s = crylink ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
906 w = WEP_UZI ;s = uzi ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
907 w = WEP_SHOTGUN ;s = shotgun ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
908 w = WEP_LASER ;s = laser ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
910 // switch if the best weapon would provide a significant damage increase
911 if (bestscore > currentscore*1.5){
912 self.switchweapon = bestweapon;
914 // buys time for detonating the rocket. not tested yet
915 if ( cvar("bot_ai_weapon_combo") && bestweapon == WEP_ROCKET_LAUNCHER )
916 self.bot_chooseweapontime += (distance / cvar("g_balance_rocketlauncher_speed"));
923 local vector selfvel, enemyvel;
924 // if(self.flags & FL_INWATER)
926 if (time < self.nextaim)
928 self.nextaim = time + 0.1;
929 selfvel = self.velocity;
930 if (!self.waterlevel)
934 enemyvel = self.enemy.velocity;
935 if (!self.enemy.waterlevel)
937 lag_additem(time + self.ping, 0, 0, self.enemy, self.origin, selfvel, self.enemy.origin, enemyvel);
940 lag_additem(time + self.ping, 0, 0, world, self.origin, selfvel, self.goalcurrent.origin, '0 0 0');
945 if (bot_strategytoken == self)
946 if (!bot_strategytoken_taken)
948 self.havocbot_role();
950 // TODO: tracewalk() should take care of this job (better path finding under water)
951 // if we don't have a goal and we're under water look for a waypoint near the "shore" and push it
952 if(self.goalcurrent==world)
953 if(self.waterlevel==WATERLEVEL_SWIMMING || self.aistatus & AI_STATUS_OUT_WATER)
955 // Look for the closest waypoint out of water
956 local entity newgoal, head;
957 local float bestdistance, distance;
960 bestdistance = 10000;
961 for (head = findchain(classname, "waypoint"); head; head = head.chain)
963 distance = vlen(head.origin - self.origin);
967 if(head.origin_z < self.origin_z)
970 if(head.origin_z - self.origin_z - self.view_ofs_z > 100)
973 if (pointcontents(head.origin + head.maxs + '0 0 1') != CONTENT_EMPTY)
976 traceline(self.origin + self.view_ofs , head.origin, TRUE, head);
981 if(distance<bestdistance)
984 bestdistance = distance;
990 // te_wizspike(newgoal.origin);
991 navigation_pushroute(newgoal);
995 // token has been used this frame
996 bot_strategytoken_taken = TRUE;
998 havocbot_chooseenemy();
999 if (self.bot_chooseweapontime < time )
1001 self.bot_chooseweapontime = time + cvar("bot_ai_chooseweaponinterval");
1002 havocbot_chooseweapon();
1006 if (self.bot_aimtarg)
1008 self.aistatus |= AI_STATUS_ATTACKING;
1009 self.aistatus &~= AI_STATUS_ROAMING;
1011 weapon_action(self.weapon, WR_AIM);
1012 if (cvar("bot_nofire") || IS_INDEPENDENT_PLAYER(self))
1014 self.BUTTON_ATCK = FALSE;
1015 self.BUTTON_ATCK2 = FALSE;
1018 else if (self.goalcurrent)
1020 self.aistatus |= AI_STATUS_ROAMING;
1021 self.aistatus &~= AI_STATUS_ATTACKING;
1023 local vector now,v,next;//,heading;
1024 local float aimdistance,skillblend,distanceblend,blend;
1025 next = now = self.goalcurrent.origin - (self.origin + self.view_ofs);
1026 aimdistance = vlen(now);
1027 //heading = self.velocity;
1028 //dprint(self.goalstack01.classname,etos(self.goalstack01),"\n");
1029 if(self.goalstack01 != self && self.goalstack01 != world && self.aistatus & AI_STATUS_RUNNING == 0)
1030 next = self.goalstack01.origin - (self.origin + self.view_ofs);
1031 skillblend=bound(0,(skill-2.5)*0.5,1); //lower skill player can't preturn
1032 distanceblend=bound(0,aimdistance/cvar("bot_ai_keyboard_distance"),1);
1033 blend = skillblend * (1-distanceblend);
1034 //v = (now * (distanceblend) + next * (1-distanceblend)) * (skillblend) + now * (1-skillblend);
1035 //v = now * (distanceblend) * (skillblend) + next * (1-distanceblend) * (skillblend) + now * (1-skillblend);
1036 //v = now * ((1-skillblend) + (distanceblend) * (skillblend)) + next * (1-distanceblend) * (skillblend);
1037 v = now + blend * (next - now);
1038 //dprint(etos(self), " ");
1039 //dprint(vtos(now), ":", vtos(next), "=", vtos(v), " (blend ", ftos(blend), ")\n");
1040 //v = now * (distanceblend) + next * (1-distanceblend);
1041 if (self.waterlevel < WATERLEVEL_SWIMMING)
1043 //dprint("walk at:", vtos(v), "\n");
1044 //te_lightning2(world, self.origin, self.goalcurrent.origin);
1047 havocbot_movetogoal();
1050 void havocbot_setupbot()
1052 self.bot_ai = havocbot_ai;
1053 // will be updated by think code
1054 //Generate some random skill levels
1055 self.havocbot_keyboardskill=random()-0.5;
1056 havocbot_chooserole();
1060 #ifdef DEBUG_BOT_GOALSTACK
1063 .vector lastposition;
1065 // Debug the goal stack visually
1066 void debuggoalstack()
1068 local entity target;
1071 if(self.goalcounter==0)target=self.goalcurrent;
1072 else if(self.goalcounter==1)target=self.goalstack01;
1073 else if(self.goalcounter==2)target=self.goalstack02;
1074 else if(self.goalcounter==3)target=self.goalstack03;
1075 else if(self.goalcounter==4)target=self.goalstack04;
1076 else if(self.goalcounter==5)target=self.goalstack05;
1077 else if(self.goalcounter==6)target=self.goalstack06;
1078 else if(self.goalcounter==7)target=self.goalstack07;
1079 else if(self.goalcounter==8)target=self.goalstack08;
1080 else if(self.goalcounter==9)target=self.goalstack09;
1081 else if(self.goalcounter==10)target=self.goalstack10;
1082 else if(self.goalcounter==11)target=self.goalstack11;
1083 else if(self.goalcounter==12)target=self.goalstack12;
1084 else if(self.goalcounter==13)target=self.goalstack13;
1085 else if(self.goalcounter==14)target=self.goalstack14;
1086 else if(self.goalcounter==15)target=self.goalstack15;
1087 else if(self.goalcounter==16)target=self.goalstack16;
1088 else if(self.goalcounter==17)target=self.goalstack17;
1089 else if(self.goalcounter==18)target=self.goalstack18;
1090 else if(self.goalcounter==19)target=self.goalstack19;
1091 else if(self.goalcounter==20)target=self.goalstack20;
1092 else if(self.goalcounter==21)target=self.goalstack21;
1093 else if(self.goalcounter==22)target=self.goalstack22;
1094 else if(self.goalcounter==23)target=self.goalstack23;
1095 else if(self.goalcounter==24)target=self.goalstack24;
1096 else if(self.goalcounter==25)target=self.goalstack25;
1097 else if(self.goalcounter==26)target=self.goalstack26;
1098 else if(self.goalcounter==27)target=self.goalstack27;
1099 else if(self.goalcounter==28)target=self.goalstack28;
1100 else if(self.goalcounter==29)target=self.goalstack29;
1101 else if(self.goalcounter==30)target=self.goalstack30;
1102 else if(self.goalcounter==31)target=self.goalstack31;
1106 self.goalcounter = 0;
1107 self.lastposition='0 0 0';
1111 if(self.lastposition=='0 0 0')
1114 org = self.lastposition;
1117 te_lightning2(world, org, target.origin);
1118 self.lastposition = target.origin;