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 distance;
144 local vector deviation;
146 if(self.goalcurrent.classname == "player")
149 if(self.aistatus & AI_STATUS_DANGER_AHEAD)
151 self.aistatus &~= AI_STATUS_RUNNING;
152 self.BUTTON_JUMP = FALSE;
156 if(self.bot_lastseengoal != self.goalcurrent && !(self.aistatus & AI_STATUS_RUNNING))
158 self.bot_canruntogoal = 0;
159 self.bot_timelastseengoal = 0;
162 distance = vlen(self.origin - self.goalcurrent.origin);
164 // Run only to visible goals
165 traceline(self.origin + self.view_ofs , self.goalcurrent.origin, TRUE, world);
166 if(self.flags & FL_ONGROUND)
167 if(trace_fraction == 1)
169 self.bot_lastseengoal = self.goalcurrent;
172 if(self.bot_timelastseengoal)
174 // for a period of time
175 if(time - self.bot_timelastseengoal > cvar("bot_ai_bunnyhop_firstjumpdelay"))
177 local float checkdistance;
178 checkdistance = TRUE;
180 // don't run if it is too close
181 if(self.bot_canruntogoal==0)
183 if(distance > cvar("bot_ai_bunnyhop_startdistance"))
184 self.bot_canruntogoal = 1;
186 self.bot_canruntogoal = -1;
189 if(self.bot_canruntogoal != 1)
192 if(self.aistatus & AI_STATUS_ROAMING)
193 if(self.goalcurrent.classname=="waypoint")
194 if(fabs(self.goalcurrent.origin_z - self.origin_z) < self.maxs_z - self.mins_z)
195 if(self.goalstack01!=world)
197 deviation = self.goalstack01.origin - (self.origin + self.view_ofs);
198 deviation = vectoangles(deviation) - self.v_angle;
199 while (deviation_y < -180) deviation_y = deviation_y + 360;
200 while (deviation_y > 180) deviation_y = deviation_y - 360;
202 if(deviation_y < 20 && deviation_y > -20)
203 if(distance < vlen(self.origin - self.goalstack01.origin))
204 if(fabs(self.goalstack01.origin_z - self.goalcurrent.origin_z) < self.maxs_z - self.mins_z)
206 traceline(self.origin + self.view_ofs , self.goalstack01.origin, TRUE, world);
207 if(trace_fraction==1)
209 checkdistance = FALSE;
216 self.aistatus &~= AI_STATUS_RUNNING;
217 if(distance > cvar("bot_ai_bunnyhop_stopdistance"))
218 self.BUTTON_JUMP = TRUE;
222 self.aistatus |= AI_STATUS_RUNNING;
223 self.BUTTON_JUMP = TRUE;
229 self.bot_timelastseengoal = time;
234 self.bot_timelastseengoal = 0;
237 // Release jump button
238 if(self.flags & FL_ONGROUND == 0)
240 if(self.velocity_z < 0)
241 self.BUTTON_JUMP = FALSE;
244 local float maxspeed;
245 maxspeed = cvar("sv_maxspeed");
247 if(self.aistatus & AI_STATUS_RUNNING)
248 if(vlen(self.velocity)>maxspeed)
250 deviation = vectoangles(dir) - self.v_angle;
251 while (deviation_y < -180) deviation_y = deviation_y + 360;
252 while (deviation_y > 180) deviation_y = deviation_y - 360;
254 if ( deviation_y > 2 )
255 self.movement_y = maxspeed;
256 if ( deviation_y < -2 )
257 self.movement_y = maxspeed * -1;
262 //.float havocbotignoretime;
263 //.vector bot_dodgevector;
264 //.float bot_dodgevector_time;
265 //.float bot_dodgevector_jumpbutton;
266 void havocbot_movetogoal()
268 local vector destorg;
271 local vector flatdir;
274 local vector evadeobstacle;
275 local vector evadelava;
277 local float maxspeed;
280 //if (self.goalentity)
281 // te_lightning2(self, self.origin, (self.goalentity.absmin + self.goalentity.absmax) * 0.5);
282 self.movement = '0 0 0';
283 maxspeed = cvar("sv_maxspeed");
285 if(self.jumppadcount)
287 if(self.flags & FL_ONGROUND)
288 self.jumppadcount = FALSE;
293 if (self.goalcurrent == world)
296 navigation_poptouchedgoals();
297 if (self.goalcurrent == world)
299 if(self.alternativegoal==world)
301 // ran out of goals, rethink strategy as soon as possible
302 self.bot_strategytime = 0;
305 // try to use the alternative goal
306 navigation_findnearestwaypoint(self.alternativegoal, TRUE);
307 navigation_routetogoal(self.alternativegoal);
308 self.alternativegoal = world;
312 #ifdef DEBUG_BOT_GOALSTACK
316 m1 = self.goalcurrent.origin + self.goalcurrent.mins;
317 m2 = self.goalcurrent.origin + self.goalcurrent.maxs;
318 destorg = self.origin;
319 destorg_x = bound(m1_x, destorg_x, m2_x);
320 destorg_y = bound(m1_y, destorg_y, m2_y);
321 destorg_z = bound(m1_z, destorg_z, m2_z);
322 diff = destorg - self.origin;
324 dir = normalize(diff);
325 flatdir = diff;flatdir_z = 0;
326 flatdir = normalize(flatdir);
328 //if (self.bot_dodgevector_time < time)
330 // self.bot_dodgevector_time = time + cvar("bot_ai_dodgeupdateinterval");
331 // self.bot_dodgevector_jumpbutton = 1;
332 evadeobstacle = '0 0 0';
336 makevectors(self.v_angle);
337 self.BUTTON_JUMP = TRUE;
342 // jump if going toward an obstacle that doesn't look like stairs we
343 // can walk up directly
344 tracebox(self.origin, self.mins, self.maxs, self.origin + self.velocity * 0.2, FALSE, self);
345 if (trace_fraction < 1)
346 if (trace_plane_normal_z < 0.7)
349 tracebox(self.origin + '0 0 16', self.mins, self.maxs, self.origin + self.velocity * 0.2 + '0 0 16', FALSE, self);
350 if (trace_fraction < s + 0.01)
351 if (trace_plane_normal_z < 0.7)
354 tracebox(self.origin + '0 0 48', self.mins, self.maxs, self.origin + self.velocity * 0.2 + '0 0 48', FALSE, self);
355 if (trace_fraction > s)
356 self.BUTTON_JUMP = 1;
360 // avoiding dangers and obstacles
361 local vector dst_ahead, dst_down;
362 dst_ahead = self.origin + self.view_ofs + (self.velocity * 0.32);
363 dst_down = dst_ahead + '0 0 -1500';
366 traceline(self.origin + self.view_ofs , dst_ahead, TRUE, world);
368 // Check head-banging against walls
369 if(vlen(self.origin + self.view_ofs - trace_endpos) < 2)
371 if(self.facingwalltime && time > self.facingwalltime)
373 self.ignoregoal = self.goalcurrent;
374 self.ignoregoaltime = time + cvar("bot_ai_ignoregoal_timeout");
375 navigation_poproute();
379 self.facingwalltime = time + 0.05;
384 self.facingwalltime = 0;
386 if(self.ignoregoal != world && time > self.ignoregoaltime)
388 self.ignoregoal = world;
389 self.ignoregoaltime = 0;
393 // Check for water/slime/lava and dangerous edges
394 // (only when the bot is on the ground or jumping intentionally)
395 self.aistatus &~= AI_STATUS_DANGER_AHEAD;
397 if(trace_fraction == 1)
398 if(self.flags & FL_ONGROUND || self.aistatus & AI_STATUS_RUNNING || self.BUTTON_JUMP == TRUE)
401 traceline(dst_ahead , dst_down, TRUE, world);
402 // te_lightning2(world, self.origin, dst_ahead); // Draw "ahead" look
403 // te_lightning2(world, dst_ahead, dst_down); // Draw "downwards" look
404 if(trace_endpos_z < self.origin_z + self.mins_z)
406 s = pointcontents(trace_endpos + '0 0 1');
407 if (s != CONTENT_SOLID)
408 if (s == CONTENT_LAVA || s == CONTENT_SLIME)
409 evadelava = normalize(self.velocity) * -1;
410 else if (s == CONTENT_SKY)
411 evadeobstacle = normalize(self.velocity) * -1;
412 else if (!boxesoverlap(dst_ahead - self.view_ofs + self.mins, dst_ahead - self.view_ofs + self.maxs,
413 self.goalcurrent.absmin, self.goalcurrent.absmax))
415 // if ain't a safe goal with "holes" (like the jumpad on soylent)
416 // and there is a trigger_hurt below
417 if(tracebox_hits_trigger_hurt(dst_ahead, self.mins, self.maxs, trace_endpos))
419 // Remove dangerous dynamic goals from stack
420 if (self.goalcurrent.classname == "player" || self.goalcurrent.classname == "droppedweapon")
421 navigation_poproute();
424 evadeobstacle = normalize(self.velocity) * -1;
433 makevectors(self.v_angle_y * '0 1 0');
435 if(evadeobstacle!='0 0 0'||evadelava!='0 0 0')
436 self.aistatus |= AI_STATUS_DANGER_AHEAD;
439 dodge = havocbot_dodge();
440 dodge = dodge * bound(0,3+skill*0.1,1);
441 evadelava = evadelava * bound(1,3-skill,3); //Noobs fear lava a lot and take more distance from it
442 traceline(self.origin, self.enemy.origin, TRUE, world);
443 if(trace_ent.classname == "player")
444 dir = dir * bound(0,skill/7,1);
446 dir = normalize(dir + dodge + evadeobstacle + evadelava);
447 // self.bot_dodgevector = dir;
448 // self.bot_dodgevector_jumpbutton = self.BUTTON_JUMP;
451 //dir = self.bot_dodgevector;
452 //if (self.bot_dodgevector_jumpbutton)
453 // self.BUTTON_JUMP = 1;
454 self.movement_x = dir * v_forward * maxspeed;
455 self.movement_y = dir * v_right * maxspeed;
456 self.movement_z = dir * v_up * maxspeed;
458 // Emulate keyboard interface
460 havocbot_keyboard_movement(destorg);
463 // if(self.aistatus & AI_STATUS_ROAMING)
464 if(skill >= cvar("bot_ai_bunnyhop_skilloffset"))
465 havocbot_bunnyhop(dir);
467 if ((dir * v_up) >= cvar("sv_jumpvelocity")*0.5 && (self.flags & FL_ONGROUND)) self.BUTTON_JUMP=1;
468 if (((dodge * v_up) > 0) && random()*frametime >= 0.2*bound(0,(10-skill)*0.1,1)) self.BUTTON_JUMP=TRUE;
469 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);
472 .float havocbot_chooseenemy_finished;
473 .float havocbot_stickenemy;
474 void havocbot_chooseenemy()
476 local entity head, best;
477 local float rating, bestrating;
479 if (cvar("bot_nofire") || IS_INDEPENDENT_PLAYER(self))
486 if (!bot_shouldattack(self.enemy))
488 // enemy died or something, find a new target
490 self.havocbot_chooseenemy_finished = time;
492 else if (self.havocbot_stickenemy)
494 // tracking last chosen enemy
495 // if enemy is visible
496 // and not really really far away
497 // and we're not severely injured
498 // then keep tracking for a half second into the future
499 traceline(self.origin+self.view_ofs, self.enemy.origin+self.enemy.view_ofs*0.5,FALSE,world);
500 if (trace_ent == self.enemy || trace_fraction == 1)
501 if (vlen(self.enemy.origin - self.origin) < 1000)
502 if (self.health > 30)
504 // remain tracking him for a shot while (case he went after a small corner or pilar
505 self.havocbot_chooseenemy_finished = time + cvar("bot_ai_enemydetectioninterval");
508 // enemy isn't visible, or is far away, or we're injured severely
509 // so stop preferring this enemy
510 // (it will still take a half second until a new one is chosen)
511 self.havocbot_stickenemy = 0;
514 if (time < self.havocbot_chooseenemy_finished)
516 self.havocbot_chooseenemy_finished = time + cvar("bot_ai_enemydetectioninterval");
517 eye = (self.origin + self.view_ofs);
519 bestrating = 100000000;
520 head = findchainfloat(bot_attack, TRUE);
523 v = (head.absmin + head.absmax) * 0.5;
524 rating = vlen(v - eye);
525 if (bestrating > rating)
526 if (bot_shouldattack(head))
528 traceline(eye, v, TRUE, self);
529 if (trace_ent == head || trace_fraction >= 1)
538 self.havocbot_stickenemy = TRUE;
541 .float bot_chooseweapontime;
542 float(entity e) w_getbestweapon;
543 void havocbot_chooseweapon()
545 // TODO: clean this up by moving it to weapon code
546 if(self.enemy.classname!="player")
548 self.switchweapon = w_getbestweapon(self);
553 local float rocket ; rocket =-1000;
554 local float nex ; nex =-1000;
555 local float hagar ; hagar =-1000;
556 local float grenade ; grenade =-1000;
557 local float electro ; electro =-1000;
558 local float crylink ; crylink =-1000;
559 local float uzi ; uzi =-1000;
560 local float shotgun ; shotgun =-1000;
561 local float campingrifle ; campingrifle =-1000;
562 local float laser ; laser =-1000;
563 local float minstanex ; minstanex =-1000;
564 local float currentscore;
565 local float bestscore; bestscore = 0;
566 local float bestweapon; bestweapon=self.switchweapon;
567 local float distance; distance=bound(10,vlen(self.origin-self.enemy.origin)-200,10000);
568 local float maxdelaytime=0.5;
569 local float spreadpenalty=10;
570 local float distancefromfloor;
572 local float af, ct, combo_time;
574 traceline(self.enemy.origin,self.enemy.origin-'0 0 1000',TRUE,world);
575 distancefromfloor = self.enemy.origin_z - trace_endpos_z;
577 af = ATTACK_FINISHED(self);
578 ct = cvar("bot_ai_weapon_combo_threshold");
580 // Bots with no skill will be 4 times more slower than "godlike" bots when doing weapon combos
581 // Ideally this 4 should be calculated as longest_weapon_refire / bot_ai_weapon_combo_threshold
582 combo_time = time + ct + (ct * ((-0.3*skill)+3));
584 // Custom weapon list based on distance to the enemy
585 local float i; i = 0;
586 if(bot_custom_weapon){
588 // Choose weapons for far distance
589 if ( distance > bot_distance_far ) {
590 for(i=0; i < WEP_LAST && bot_weapons_far[i] != -1 ; ++i){
591 w = bot_weapons_far[i];
592 if ( client_hasweapon(self, w, TRUE, FALSE) ){
593 if ( self.weapon == w){
594 if( cvar("bot_ai_weapon_combo") && af > combo_time)
597 self.switchweapon = w;
604 // Choose weapons for mid distance
605 if ( distance > bot_distance_close ) {
606 for(i=0; i < WEP_LAST && bot_weapons_mid[i] != -1 ; ++i){
607 w = bot_weapons_mid[i];
608 if ( client_hasweapon(self, w, TRUE, FALSE) ){
609 if ( self.weapon == w){
610 if( cvar("bot_ai_weapon_combo") && af > combo_time)
613 self.switchweapon = w;
620 // Choose weapons for close distance
621 for(i=0; i < WEP_LAST && bot_weapons_close[i] != -1 ; ++i){
622 w = bot_weapons_close[i];
623 if ( client_hasweapon(self, w, TRUE, FALSE) ){
624 if ( self.weapon == w){
625 if( cvar("bot_ai_weapon_combo") && af > combo_time)
628 self.switchweapon = w;
633 // If now weapon was chosen by this system fall back to the previous one
637 // (Damage/Sec * Weapon spefic change to get that damage)
638 // *(Time to get to target * weapon specfic hitchange bonus) / (in a time of maxdelaytime)
639 // *(Spread change of hit) // if it applies
640 // *(Penality for target beeing in air)
642 if (client_hasweapon(self, WEP_MINSTANEX, TRUE, FALSE))
643 minstanex = (1000/cvar("g_balance_minstanex_refire")*1.0)
646 if (client_hasweapon(self, WEP_ROCKET_LAUNCHER, TRUE, FALSE) &&
647 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_ROCKET_LAUNCHER &&
651 rocket = (cvar("g_balance_rocketlauncher_damage")/cvar("g_balance_rocketlauncher_refire")*0.75)
652 * bound(0,(cvar("g_balance_rocketlauncher_speed")/distance*maxdelaytime),1)*1.5;
654 if (client_hasweapon(self, WEP_NEX, TRUE, FALSE) &&
655 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_NEX &&
659 nex = (cvar("g_balance_nex_damage")/cvar("g_balance_nex_refire")*1.0)
662 if (client_hasweapon(self, WEP_HAGAR, TRUE, FALSE) ) // &&
663 // !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_HAGAR && time < self.bot_lastshot + cvar("g_balance_hagar_primary_refire") ))
664 hagar = (cvar("g_balance_hagar_primary_damage")/cvar("g_balance_hagar_primary_refire")*1.0)
665 * bound(0,(cvar("g_balance_hagar_primary_speed")/distance*maxdelaytime),1)*0.2;
667 if (client_hasweapon(self, WEP_GRENADE_LAUNCHER, TRUE, FALSE) &&
669 cvar("bot_ai_weapon_combo") && self.weapon == WEP_GRENADE_LAUNCHER &&
673 grenade = (cvar("g_balance_grenadelauncher_primary_damage")/cvar("g_balance_grenadelauncher_primary_refire")*1.0)
674 * bound(0,(cvar("g_balance_grenadelauncher_primary_speed")/distance*maxdelaytime),1)*1.1;
676 if (client_hasweapon(self, WEP_ELECTRO, TRUE, FALSE) &&
677 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_ELECTRO &&
681 electro = (cvar("g_balance_electro_primary_damage")/cvar("g_balance_electro_primary_refire")*0.75)
682 * bound(0,(cvar("g_balance_electro_primary_speed")/distance*maxdelaytime),1)*1.0;
684 if (client_hasweapon(self, WEP_CRYLINK, TRUE, FALSE) ) // &&
685 // !( self.weapon == WEP_CRYLINK && time < self.bot_lastshot + cvar("g_balance_crylink_primary_refire") ))
686 crylink = (cvar("g_balance_crylink_primary_damage")/cvar("g_balance_crylink_primary_refire")*1.0)
687 * bound(0,(cvar("g_balance_crylink_primary_speed")/distance*maxdelaytime),1)*(64/(32+cvar("g_balance_crylink_primary_spread")*distance))*1.0;
689 if (client_hasweapon(self, WEP_UZI, TRUE, FALSE) ) // &&
690 // !( self.weapon == WEP_UZI && time < self.bot_lastshot + cvar("g_balance_uzi_sustained_refire") ))
691 uzi = (cvar("g_balance_uzi_sustained_damage")/cvar("g_balance_uzi_sustained_refire")*1.0)
692 * bound(0,32/(32+cvar("g_balance_uzi_sustained_spread")*distance),1);
694 if (client_hasweapon(self, WEP_SHOTGUN, TRUE, FALSE) &&
695 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_SHOTGUN &&
699 shotgun = (cvar("g_balance_shotgun_primary_damage")*cvar("g_balance_shotgun_primary_bullets")/cvar("g_balance_shotgun_primary_refire")*1.0)
700 * bound(0,32/(32+cvar("g_balance_shotgun_primary_spread")*distance),1);
702 if (client_hasweapon(self, WEP_LASER, FALSE, FALSE) &&
703 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_LASER &&
707 laser = (cvar("g_balance_laser_primary_damage")/cvar("g_balance_laser_primary_refire")*1.0)
708 * bound(0,cvar("g_balance_laser_primary_speed")/distance*maxdelaytime,1);
710 if((self.enemy.flags & FL_ONGROUND)==FALSE){
711 rocket = rocket * (1.5-bound(0, distancefromfloor/cvar("g_balance_rocketlauncher_radius" ),0.9)); //slight bigger change
712 grenade = grenade * (1.5-bound(0,distancefromfloor/cvar("g_balance_grenadelauncher_primary_radius"),0.95));
713 electro = electro * (1.5-bound(0,distancefromfloor/cvar("g_balance_electro_primary_radius" ),0.95));
714 laser = laser * (1.5-bound(0,distancefromfloor/cvar("g_balance_laser_primary_radius" ),0.95));
717 dprint("Floor distance: ",ftos(distancefromfloor),"\n");
718 dprint("Rocket: " , ftos(rocket ), "\n");
719 dprint("Nex: " , ftos(nex ), "\n");
720 dprint("Hagar: " , ftos(hagar ), "\n");
721 dprint("Grenade: ", ftos(grenade ), "\n");
722 dprint("Electro: ", ftos(electro ), "\n");
723 dprint("Crylink: ", ftos(crylink ), "\n");
724 dprint("Uzi: " , ftos(uzi ), "\n");
725 dprint("Shotgun :", ftos(shotgun ), "\n");
726 dprint("Laser :", ftos(laser ), "\n\n");
729 w = WEP_MINSTANEX ;s = minstanex;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
730 w = WEP_ROCKET_LAUNCHER ;s = rocket ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
731 w = WEP_NEX ;s = nex ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
732 w = WEP_HAGAR ;s = hagar ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
733 w = WEP_GRENADE_LAUNCHER ;s = grenade ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
734 w = WEP_ELECTRO ;s = electro ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
735 w = WEP_CRYLINK ;s = crylink ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
736 w = WEP_UZI ;s = uzi ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
737 w = WEP_SHOTGUN ;s = shotgun ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
738 w = WEP_LASER ;s = laser ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
740 // switch if the best weapon would provide a significant damage increase
741 if (bestscore > currentscore*1.5){
742 self.switchweapon = bestweapon;
744 // buys time for detonating the rocket. not tested yet
745 if ( cvar("bot_ai_weapon_combo") && bestweapon == WEP_ROCKET_LAUNCHER )
746 self.bot_chooseweapontime += (distance / cvar("g_balance_rocketlauncher_speed"));
753 local vector selfvel, enemyvel;
754 if(self.flags & FL_INWATER)
756 if (time < self.nextaim)
758 self.nextaim = time + 0.1;
759 selfvel = self.velocity;
760 if (!self.waterlevel)
764 enemyvel = self.enemy.velocity;
765 if (!self.enemy.waterlevel)
767 lag_additem(time + self.ping, 0, 0, self.enemy, self.origin, selfvel, self.enemy.origin, enemyvel);
770 lag_additem(time + self.ping, 0, 0, world, self.origin, selfvel, self.goalcurrent.origin, '0 0 0');
775 if (bot_strategytoken == self)
776 if (!bot_strategytoken_taken)
778 self.havocbot_role();
779 // token has been used this frame
780 bot_strategytoken_taken = TRUE;
785 havocbot_chooseenemy();
786 if (self.bot_chooseweapontime < time )
788 self.bot_chooseweapontime = time + cvar("bot_ai_chooseweaponinterval");
789 havocbot_chooseweapon();
793 if (self.bot_aimtarg)
795 self.aistatus |= AI_STATUS_ATTACKING;
796 self.aistatus &~= AI_STATUS_ROAMING;
798 weapon_action(self.weapon, WR_AIM);
799 if (cvar("bot_nofire") || IS_INDEPENDENT_PLAYER(self))
801 self.BUTTON_ATCK = FALSE;
802 self.BUTTON_ATCK2 = FALSE;
805 else if (self.goalcurrent)
807 self.aistatus |= AI_STATUS_ROAMING;
808 self.aistatus &~= AI_STATUS_ATTACKING;
810 local vector now,v,next;//,heading;
811 local float distance,skillblend,distanceblend,blend;
812 next = now = self.goalcurrent.origin - (self.origin + self.view_ofs);
813 distance = vlen(now);
814 //heading = self.velocity;
815 //dprint(self.goalstack01.classname,etos(self.goalstack01),"\n");
816 if(self.goalstack01 != self && self.goalstack01 != world && self.aistatus & AI_STATUS_RUNNING == 0)
817 next = self.goalstack01.origin - (self.origin + self.view_ofs);
818 skillblend=bound(0,(skill-2.5)*0.5,1); //lower skill player can't preturn
819 distanceblend=bound(0,distance/cvar("bot_ai_keyboard_distance"),1);
820 blend = skillblend * (1-distanceblend);
821 //v = (now * (distanceblend) + next * (1-distanceblend)) * (skillblend) + now * (1-skillblend);
822 //v = now * (distanceblend) * (skillblend) + next * (1-distanceblend) * (skillblend) + now * (1-skillblend);
823 //v = now * ((1-skillblend) + (distanceblend) * (skillblend)) + next * (1-distanceblend) * (skillblend);
824 v = now + blend * (next - now);
825 //dprint(etos(self), " ");
826 //dprint(vtos(now), ":", vtos(next), "=", vtos(v), " (blend ", ftos(blend), ")\n");
827 //v = now * (distanceblend) + next * (1-distanceblend);
828 if (self.waterlevel < 2)
830 //dprint("walk at:", vtos(v), "\n");
831 //te_lightning2(world, self.origin, self.goalcurrent.origin);
834 havocbot_movetogoal();
837 void havocbot_setupbot()
839 self.bot_ai = havocbot_ai;
840 // will be updated by think code
841 //Generate some random skill levels
842 self.havocbot_keyboardskill=random()-0.5;
843 havocbot_chooserole();
847 #ifdef DEBUG_BOT_GOALSTACK
850 .vector lastposition;
852 // Debug the goal stack visually
853 void debuggoalstack()
858 if(self.goalcounter==0)target=self.goalcurrent;
859 else if(self.goalcounter==1)target=self.goalstack01;
860 else if(self.goalcounter==2)target=self.goalstack02;
861 else if(self.goalcounter==3)target=self.goalstack03;
862 else if(self.goalcounter==4)target=self.goalstack04;
863 else if(self.goalcounter==5)target=self.goalstack05;
864 else if(self.goalcounter==6)target=self.goalstack06;
865 else if(self.goalcounter==7)target=self.goalstack07;
866 else if(self.goalcounter==8)target=self.goalstack08;
867 else if(self.goalcounter==9)target=self.goalstack09;
868 else if(self.goalcounter==10)target=self.goalstack10;
869 else if(self.goalcounter==11)target=self.goalstack11;
870 else if(self.goalcounter==12)target=self.goalstack12;
871 else if(self.goalcounter==13)target=self.goalstack13;
872 else if(self.goalcounter==14)target=self.goalstack14;
873 else if(self.goalcounter==15)target=self.goalstack15;
874 else if(self.goalcounter==16)target=self.goalstack16;
875 else if(self.goalcounter==17)target=self.goalstack17;
876 else if(self.goalcounter==18)target=self.goalstack18;
877 else if(self.goalcounter==19)target=self.goalstack19;
878 else if(self.goalcounter==20)target=self.goalstack20;
879 else if(self.goalcounter==21)target=self.goalstack21;
880 else if(self.goalcounter==22)target=self.goalstack22;
881 else if(self.goalcounter==23)target=self.goalstack23;
882 else if(self.goalcounter==24)target=self.goalstack24;
883 else if(self.goalcounter==25)target=self.goalstack25;
884 else if(self.goalcounter==26)target=self.goalstack26;
885 else if(self.goalcounter==27)target=self.goalstack27;
886 else if(self.goalcounter==28)target=self.goalstack28;
887 else if(self.goalcounter==29)target=self.goalstack29;
888 else if(self.goalcounter==30)target=self.goalstack30;
889 else if(self.goalcounter==31)target=self.goalstack31;
893 self.goalcounter = 0;
894 self.lastposition='0 0 0';
898 if(self.lastposition=='0 0 0')
901 org = self.lastposition;
904 te_lightning2(world, org, target.origin);
905 self.lastposition = target.origin;