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.waterlevel > 1)
158 self.aistatus &~= AI_STATUS_RUNNING;
162 if(self.bot_lastseengoal != self.goalcurrent && !(self.aistatus & AI_STATUS_RUNNING))
164 self.bot_canruntogoal = 0;
165 self.bot_timelastseengoal = 0;
168 distance = vlen(self.origin - self.goalcurrent.origin);
170 // Run only to visible goals
171 traceline(self.origin + self.view_ofs , self.goalcurrent.origin, TRUE, world);
172 if(self.flags & FL_ONGROUND)
173 if(trace_fraction == 1)
175 self.bot_lastseengoal = self.goalcurrent;
178 if(self.bot_timelastseengoal)
180 // for a period of time
181 if(time - self.bot_timelastseengoal > cvar("bot_ai_bunnyhop_firstjumpdelay"))
183 local float checkdistance;
184 checkdistance = TRUE;
186 // don't run if it is too close
187 if(self.bot_canruntogoal==0)
189 if(distance > cvar("bot_ai_bunnyhop_startdistance"))
190 self.bot_canruntogoal = 1;
192 self.bot_canruntogoal = -1;
195 if(self.bot_canruntogoal != 1)
198 if(self.aistatus & AI_STATUS_ROAMING)
199 if(self.goalcurrent.classname=="waypoint")
200 if(fabs(self.goalcurrent.origin_z - self.origin_z) < self.maxs_z - self.mins_z)
201 if(self.goalstack01!=world)
203 deviation = self.goalstack01.origin - (self.origin + self.view_ofs);
204 deviation = vectoangles(deviation) - self.v_angle;
205 while (deviation_y < -180) deviation_y = deviation_y + 360;
206 while (deviation_y > 180) deviation_y = deviation_y - 360;
208 if(fabs(deviation_y) < 15)
209 if(distance < vlen(self.origin - self.goalstack01.origin))
210 if(fabs(self.goalstack01.origin_z - self.goalcurrent.origin_z) < self.maxs_z - self.mins_z)
212 traceline(self.origin + self.view_ofs , self.goalstack01.origin, TRUE, world);
213 if(trace_fraction==1)
215 checkdistance = FALSE;
222 self.aistatus &~= AI_STATUS_RUNNING;
223 if(distance > cvar("bot_ai_bunnyhop_stopdistance"))
224 self.BUTTON_JUMP = TRUE;
228 self.aistatus |= AI_STATUS_RUNNING;
229 self.BUTTON_JUMP = TRUE;
235 self.bot_timelastseengoal = time;
240 self.bot_timelastseengoal = 0;
243 // Release jump button
244 if(self.flags & FL_ONGROUND == 0)
246 if(self.velocity_z < 0)
247 self.BUTTON_JUMP = FALSE;
250 local float maxspeed;
251 maxspeed = cvar("sv_maxspeed");
253 if(self.aistatus & AI_STATUS_RUNNING)
254 if(vlen(self.velocity)>maxspeed)
256 deviation = vectoangles(dir) - self.v_angle;
257 while (deviation_y < -180) deviation_y = deviation_y + 360;
258 while (deviation_y > 180) deviation_y = deviation_y - 360;
260 if ( deviation_y > 2 )
261 self.movement_y = maxspeed;
262 if ( deviation_y < -2 )
263 self.movement_y = maxspeed * -1;
268 //.float havocbotignoretime;
269 //.vector bot_dodgevector;
270 //.float bot_dodgevector_time;
271 //.float bot_dodgevector_jumpbutton;
273 .entity ladder_entity;
274 void havocbot_movetogoal()
276 local vector destorg;
279 local vector flatdir;
282 local vector evadeobstacle;
283 local vector evadelava;
285 local float maxspeed;
288 //if (self.goalentity)
289 // te_lightning2(self, self.origin, (self.goalentity.absmin + self.goalentity.absmax) * 0.5);
290 self.movement = '0 0 0';
291 maxspeed = cvar("sv_maxspeed");
293 if(self.jumppadcount)
295 if(self.flags & FL_ONGROUND)
297 self.jumppadcount = FALSE;
298 if(self.aistatus & AI_STATUS_OUT_JUMPPAD)
299 self.aistatus &~= AI_STATUS_OUT_JUMPPAD;
302 // If got stuck on the jump pad try to reach the farther visible item
303 if(self.aistatus & AI_STATUS_OUT_JUMPPAD)
305 if(fabs(self.velocity_z)<50)
307 local entity head, newgoal;
308 local float distance, bestdistance;
310 for (head = findchainfloat(bot_pickup, TRUE); head; head = head.chain)
312 if(head.classname=="worldspawn")
315 distance = vlen(head.origin - self.origin);
319 traceline(self.origin + self.view_ofs , head.origin, TRUE, world);
324 if(distance>bestdistance)
327 bestdistance = distance;
333 self.ignoregoal = self.goalcurrent;
334 self.ignoregoaltime = time + cvar("bot_ai_ignoregoal_timeout");
335 navigation_routetogoal(newgoal);
336 self.aistatus &~= AI_STATUS_OUT_JUMPPAD;
344 if(self.velocity_z>0)
346 local float threshold;
347 threshold = maxspeed * 0.2;
348 if(fabs(self.velocity_x) < threshold && fabs(self.velocity_y) < threshold)
349 self.aistatus |= AI_STATUS_OUT_JUMPPAD;
355 // If we are under water with no goals, swim up
357 if(self.goalcurrent==world)
360 if(self.waterlevel>2)
362 else if(self.velocity_z >= 0 && !(self.waterlevel == 1 && self.watertype == CONTENT_WATER))
363 self.BUTTON_JUMP = TRUE;
365 self.BUTTON_JUMP = FALSE;
366 makevectors(self.v_angle_y * '0 1 0');
367 self.movement_x = dir * v_forward * maxspeed;
368 self.movement_y = dir * v_right * maxspeed;
369 self.movement_z = dir * v_up * maxspeed;
372 // if there is nowhere to go, exit
373 if (self.goalcurrent == world)
376 if (self.goalcurrent)
377 navigation_poptouchedgoals();
379 // if ran out of goals try to use an alternative goal or get a new strategy asap
380 if(self.goalcurrent == world)
381 if(self.flags & FL_ONGROUND || self.aistatus & AI_STATUS_RUNNING || self.BUTTON_JUMP == TRUE)
383 if(self.alternativegoal==world)
386 self.bot_strategytime = 0;
390 // use the alternative goal
391 if (bot_strategytoken == self)
392 if (!bot_strategytoken_taken)
394 navigation_findnearestwaypoint(self.alternativegoal, TRUE);
395 navigation_routetogoal(self.alternativegoal);
396 self.alternativegoal = world;
397 bot_strategytoken_taken = TRUE;
403 #ifdef DEBUG_BOT_GOALSTACK
407 m1 = self.goalcurrent.origin + self.goalcurrent.mins;
408 m2 = self.goalcurrent.origin + self.goalcurrent.maxs;
409 destorg = self.origin;
410 destorg_x = bound(m1_x, destorg_x, m2_x);
411 destorg_y = bound(m1_y, destorg_y, m2_y);
412 destorg_z = bound(m1_z, destorg_z, m2_z);
413 diff = destorg - self.origin;
415 dir = normalize(diff);
416 flatdir = diff;flatdir_z = 0;
417 flatdir = normalize(flatdir);
419 //if (self.bot_dodgevector_time < time)
421 // self.bot_dodgevector_time = time + cvar("bot_ai_dodgeupdateinterval");
422 // self.bot_dodgevector_jumpbutton = 1;
423 evadeobstacle = '0 0 0';
428 if(self.waterlevel>2)
431 self.aistatus |= AI_STATUS_OUT_WATER;
435 if(self.velocity_z >= 0 && !(self.watertype == CONTENT_WATER && self.goalcurrent.origin_z < self.origin_z) &&
436 ( !(self.waterlevel == 1 && self.watertype == CONTENT_WATER) || self.aistatus & AI_STATUS_OUT_WATER))
437 self.BUTTON_JUMP = TRUE;
439 self.BUTTON_JUMP = FALSE;
441 dir = normalize(flatdir);
442 makevectors(self.v_angle_y * '0 1 0');
446 if(self.aistatus & AI_STATUS_OUT_WATER)
447 self.aistatus &~= AI_STATUS_OUT_WATER;
449 // jump if going toward an obstacle that doesn't look like stairs we
450 // can walk up directly
451 tracebox(self.origin, self.mins, self.maxs, self.origin + self.velocity * 0.2, FALSE, self);
452 if (trace_fraction < 1)
453 if (trace_plane_normal_z < 0.7)
456 tracebox(self.origin + '0 0 16', self.mins, self.maxs, self.origin + self.velocity * 0.2 + '0 0 16', FALSE, self);
457 if (trace_fraction < s + 0.01)
458 if (trace_plane_normal_z < 0.7)
461 tracebox(self.origin + '0 0 48', self.mins, self.maxs, self.origin + self.velocity * 0.2 + '0 0 48', FALSE, self);
462 if (trace_fraction > s)
463 self.BUTTON_JUMP = 1;
467 // avoiding dangers and obstacles
468 local vector dst_ahead, dst_down;
469 dst_ahead = self.origin + self.view_ofs + (self.velocity * 0.32);
470 dst_down = dst_ahead + '0 0 -1500';
473 traceline(self.origin + self.view_ofs , dst_ahead, TRUE, world);
475 // Check head-banging against walls
476 if(vlen(self.origin + self.view_ofs - trace_endpos) < 2 && !(self.aistatus & AI_STATUS_OUT_WATER))
478 if(self.facingwalltime && time > self.facingwalltime)
480 self.ignoregoal = self.goalcurrent;
481 self.ignoregoaltime = time + cvar("bot_ai_ignoregoal_timeout");
482 navigation_poproute();
486 self.facingwalltime = time + 0.05;
491 self.facingwalltime = 0;
493 if(self.ignoregoal != world && time > self.ignoregoaltime)
495 self.ignoregoal = world;
496 self.ignoregoaltime = 0;
500 // Check for water/slime/lava and dangerous edges
501 // (only when the bot is on the ground or jumping intentionally)
502 self.aistatus &~= AI_STATUS_DANGER_AHEAD;
504 if(trace_fraction == 1)
505 if(self.flags & FL_ONGROUND || self.aistatus & AI_STATUS_RUNNING || self.BUTTON_JUMP == TRUE)
508 traceline(dst_ahead , dst_down, TRUE, world);
509 // te_lightning2(world, self.origin, dst_ahead); // Draw "ahead" look
510 // te_lightning2(world, dst_ahead, dst_down); // Draw "downwards" look
511 if(trace_endpos_z < self.origin_z + self.mins_z)
513 s = pointcontents(trace_endpos + '0 0 1');
514 if (s != CONTENT_SOLID)
515 if (s == CONTENT_LAVA || s == CONTENT_SLIME)
516 evadelava = normalize(self.velocity) * -1;
517 else if (s == CONTENT_SKY)
518 evadeobstacle = normalize(self.velocity) * -1;
519 else if (!boxesoverlap(dst_ahead - self.view_ofs + self.mins, dst_ahead - self.view_ofs + self.maxs,
520 self.goalcurrent.absmin, self.goalcurrent.absmax))
522 // if ain't a safe goal with "holes" (like the jumpad on soylent)
523 // and there is a trigger_hurt below
524 if(tracebox_hits_trigger_hurt(dst_ahead, self.mins, self.maxs, trace_endpos))
526 // Remove dangerous dynamic goals from stack
527 if (self.goalcurrent.classname == "player" || self.goalcurrent.classname == "droppedweapon")
528 navigation_poproute();
531 evadeobstacle = normalize(self.velocity) * -1;
540 makevectors(self.v_angle_y * '0 1 0');
542 if(evadeobstacle!='0 0 0'||evadelava!='0 0 0')
543 self.aistatus |= AI_STATUS_DANGER_AHEAD;
546 dodge = havocbot_dodge();
547 dodge = dodge * bound(0,3+skill*0.1,1);
548 evadelava = evadelava * bound(1,3-skill,3); //Noobs fear lava a lot and take more distance from it
549 traceline(self.origin, self.enemy.origin, TRUE, world);
550 if(trace_ent.classname == "player")
551 dir = dir * bound(0,skill/7,1);
553 dir = normalize(dir + dodge + evadeobstacle + evadelava);
554 // self.bot_dodgevector = dir;
555 // self.bot_dodgevector_jumpbutton = self.BUTTON_JUMP;
558 if(time < self.ladder_time)
560 if(self.goalcurrent.origin_z + self.goalcurrent.mins_z > self.origin_z + self.mins_z)
562 if(self.origin_z + self.mins_z < self.ladder_entity.origin_z + self.ladder_entity.maxs_z)
567 if(self.origin_z + self.mins_z > self.ladder_entity.origin_z + self.ladder_entity.mins_z)
572 //dir = self.bot_dodgevector;
573 //if (self.bot_dodgevector_jumpbutton)
574 // self.BUTTON_JUMP = 1;
575 self.movement_x = dir * v_forward * maxspeed;
576 self.movement_y = dir * v_right * maxspeed;
577 self.movement_z = dir * v_up * maxspeed;
579 // Emulate keyboard interface
581 havocbot_keyboard_movement(destorg);
584 // if(self.aistatus & AI_STATUS_ROAMING)
585 if(skill >= cvar("bot_ai_bunnyhop_skilloffset"))
586 havocbot_bunnyhop(dir);
588 if ((dir * v_up) >= cvar("sv_jumpvelocity")*0.5 && (self.flags & FL_ONGROUND)) self.BUTTON_JUMP=1;
589 if (((dodge * v_up) > 0) && random()*frametime >= 0.2*bound(0,(10-skill)*0.1,1)) self.BUTTON_JUMP=TRUE;
590 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);
593 .float havocbot_chooseenemy_finished;
594 .float havocbot_stickenemy;
595 void havocbot_chooseenemy()
597 local entity head, best;
598 local float rating, bestrating;
600 if (cvar("bot_nofire") || IS_INDEPENDENT_PLAYER(self))
607 if (!bot_shouldattack(self.enemy))
609 // enemy died or something, find a new target
611 self.havocbot_chooseenemy_finished = time;
613 else if (self.havocbot_stickenemy)
615 // tracking last chosen enemy
616 // if enemy is visible
617 // and not really really far away
618 // and we're not severely injured
619 // then keep tracking for a half second into the future
620 traceline(self.origin+self.view_ofs, self.enemy.origin+self.enemy.view_ofs*0.5,FALSE,world);
621 if (trace_ent == self.enemy || trace_fraction == 1)
622 if (vlen(self.enemy.origin - self.origin) < 1000)
623 if (self.health > 30)
625 // remain tracking him for a shot while (case he went after a small corner or pilar
626 self.havocbot_chooseenemy_finished = time + cvar("bot_ai_enemydetectioninterval");
629 // enemy isn't visible, or is far away, or we're injured severely
630 // so stop preferring this enemy
631 // (it will still take a half second until a new one is chosen)
632 self.havocbot_stickenemy = 0;
635 if (time < self.havocbot_chooseenemy_finished)
637 self.havocbot_chooseenemy_finished = time + cvar("bot_ai_enemydetectioninterval");
638 eye = (self.origin + self.view_ofs);
640 bestrating = 100000000;
641 head = findchainfloat(bot_attack, TRUE);
644 v = (head.absmin + head.absmax) * 0.5;
645 rating = vlen(v - eye);
646 if (bestrating > rating)
647 if (bot_shouldattack(head))
649 traceline(eye, v, TRUE, self);
650 if (trace_ent == head || trace_fraction >= 1)
659 self.havocbot_stickenemy = TRUE;
662 .float bot_chooseweapontime;
663 float(entity e) w_getbestweapon;
664 void havocbot_chooseweapon()
666 // TODO: clean this up by moving it to weapon code
667 if(self.enemy.classname!="player")
669 // self.switchweapon = w_getbestweapon(self);
670 if(client_hasweapon(self, WEP_LASER, TRUE, FALSE))
671 self.switchweapon = WEP_LASER;
676 local float rocket ; rocket =-1000;
677 local float nex ; nex =-1000;
678 local float hagar ; hagar =-1000;
679 local float grenade ; grenade =-1000;
680 local float electro ; electro =-1000;
681 local float crylink ; crylink =-1000;
682 local float uzi ; uzi =-1000;
683 local float shotgun ; shotgun =-1000;
684 local float campingrifle ; campingrifle =-1000;
685 local float laser ; laser =-1000;
686 local float minstanex ; minstanex =-1000;
687 local float currentscore;
688 local float bestscore; bestscore = 0;
689 local float bestweapon; bestweapon=self.switchweapon;
690 local float distance; distance=bound(10,vlen(self.origin-self.enemy.origin)-200,10000);
691 local float maxdelaytime=0.5;
692 local float spreadpenalty=10;
693 local float distancefromfloor;
695 local float af, ct, combo_time;
697 traceline(self.enemy.origin,self.enemy.origin-'0 0 1000',TRUE,world);
698 distancefromfloor = self.enemy.origin_z - trace_endpos_z;
700 af = ATTACK_FINISHED(self);
701 ct = cvar("bot_ai_weapon_combo_threshold");
703 // Bots with no skill will be 4 times more slower than "godlike" bots when doing weapon combos
704 // Ideally this 4 should be calculated as longest_weapon_refire / bot_ai_weapon_combo_threshold
705 combo_time = time + ct + (ct * ((-0.3*skill)+3));
707 // Custom weapon list based on distance to the enemy
708 local float i; i = 0;
709 if(bot_custom_weapon){
711 // Choose weapons for far distance
712 if ( distance > bot_distance_far ) {
713 for(i=0; i < WEP_COUNT && bot_weapons_far[i] != -1 ; ++i){
714 w = bot_weapons_far[i];
715 if ( client_hasweapon(self, w, TRUE, FALSE) ){
716 if ( self.weapon == w){
717 if( cvar("bot_ai_weapon_combo") && af > combo_time)
720 self.switchweapon = w;
727 // Choose weapons for mid distance
728 if ( distance > bot_distance_close ) {
729 for(i= 0; i < WEP_COUNT && bot_weapons_mid[i] != -1 ; ++i){
730 w = bot_weapons_mid[i];
731 if ( client_hasweapon(self, w, TRUE, FALSE) ){
732 if ( self.weapon == w){
733 if( cvar("bot_ai_weapon_combo") && af > combo_time)
736 self.switchweapon = w;
743 // Choose weapons for close distance
744 for(i= 0; i < WEP_COUNT && bot_weapons_close[i] != -1 ; ++i){
745 w = bot_weapons_close[i];
746 if ( client_hasweapon(self, w, TRUE, FALSE) ){
747 if ( self.weapon == w){
748 if( cvar("bot_ai_weapon_combo") && af > combo_time)
751 self.switchweapon = w;
756 // If now weapon was chosen by this system fall back to the previous one
760 // (Damage/Sec * Weapon spefic change to get that damage)
761 // *(Time to get to target * weapon specfic hitchange bonus) / (in a time of maxdelaytime)
762 // *(Spread change of hit) // if it applies
763 // *(Penality for target beeing in air)
765 if (client_hasweapon(self, WEP_MINSTANEX, TRUE, FALSE))
766 minstanex = (1000/cvar("g_balance_minstanex_refire")*1.0)
769 if (client_hasweapon(self, WEP_ROCKET_LAUNCHER, TRUE, FALSE) &&
770 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_ROCKET_LAUNCHER &&
774 rocket = (cvar("g_balance_rocketlauncher_damage")/cvar("g_balance_rocketlauncher_refire")*0.75)
775 * bound(0,(cvar("g_balance_rocketlauncher_speed")/distance*maxdelaytime),1)*1.5;
777 if (client_hasweapon(self, WEP_NEX, TRUE, FALSE) &&
778 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_NEX &&
782 nex = (cvar("g_balance_nex_damage")/cvar("g_balance_nex_refire")*1.0)
785 if (client_hasweapon(self, WEP_HAGAR, TRUE, FALSE) ) // &&
786 // !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_HAGAR && time < self.bot_lastshot + cvar("g_balance_hagar_primary_refire") ))
787 hagar = (cvar("g_balance_hagar_primary_damage")/cvar("g_balance_hagar_primary_refire")*1.0)
788 * bound(0,(cvar("g_balance_hagar_primary_speed")/distance*maxdelaytime),1)*0.2;
790 if (client_hasweapon(self, WEP_GRENADE_LAUNCHER, TRUE, FALSE) &&
792 cvar("bot_ai_weapon_combo") && self.weapon == WEP_GRENADE_LAUNCHER &&
796 grenade = (cvar("g_balance_grenadelauncher_primary_damage")/cvar("g_balance_grenadelauncher_primary_refire")*1.0)
797 * bound(0,(cvar("g_balance_grenadelauncher_primary_speed")/distance*maxdelaytime),1)*1.1;
799 if (client_hasweapon(self, WEP_ELECTRO, TRUE, FALSE) &&
800 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_ELECTRO &&
804 electro = (cvar("g_balance_electro_primary_damage")/cvar("g_balance_electro_primary_refire")*0.75)
805 * bound(0,(cvar("g_balance_electro_primary_speed")/distance*maxdelaytime),1)*1.0;
807 if (client_hasweapon(self, WEP_CRYLINK, TRUE, FALSE) ) // &&
808 // !( self.weapon == WEP_CRYLINK && time < self.bot_lastshot + cvar("g_balance_crylink_primary_refire") ))
809 crylink = (cvar("g_balance_crylink_primary_damage")/cvar("g_balance_crylink_primary_refire")*1.0)
810 * bound(0,(cvar("g_balance_crylink_primary_speed")/distance*maxdelaytime),1)*(64/(32+cvar("g_balance_crylink_primary_spread")*distance))*1.0;
812 if (client_hasweapon(self, WEP_UZI, TRUE, FALSE) ) // &&
813 // !( self.weapon == WEP_UZI && time < self.bot_lastshot + cvar("g_balance_uzi_sustained_refire") ))
814 uzi = (cvar("g_balance_uzi_sustained_damage")/cvar("g_balance_uzi_sustained_refire")*1.0)
815 * bound(0,32/(32+cvar("g_balance_uzi_sustained_spread")*distance),1);
817 if (client_hasweapon(self, WEP_SHOTGUN, TRUE, FALSE) &&
818 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_SHOTGUN &&
822 shotgun = (cvar("g_balance_shotgun_primary_damage")*cvar("g_balance_shotgun_primary_bullets")/cvar("g_balance_shotgun_primary_refire")*1.0)
823 * bound(0,32/(32+cvar("g_balance_shotgun_primary_spread")*distance),1);
825 if (client_hasweapon(self, WEP_LASER, FALSE, FALSE) &&
826 !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_LASER &&
830 laser = (cvar("g_balance_laser_primary_damage")/cvar("g_balance_laser_primary_refire")*1.0)
831 * bound(0,cvar("g_balance_laser_primary_speed")/distance*maxdelaytime,1);
833 if((self.enemy.flags & FL_ONGROUND)==FALSE){
834 rocket = rocket * (1.5-bound(0, distancefromfloor/cvar("g_balance_rocketlauncher_radius" ),0.9)); //slight bigger change
835 grenade = grenade * (1.5-bound(0,distancefromfloor/cvar("g_balance_grenadelauncher_primary_radius"),0.95));
836 electro = electro * (1.5-bound(0,distancefromfloor/cvar("g_balance_electro_primary_radius" ),0.95));
837 laser = laser * (1.5-bound(0,distancefromfloor/cvar("g_balance_laser_primary_radius" ),0.95));
840 dprint("Floor distance: ",ftos(distancefromfloor),"\n");
841 dprint("Rocket: " , ftos(rocket ), "\n");
842 dprint("Nex: " , ftos(nex ), "\n");
843 dprint("Hagar: " , ftos(hagar ), "\n");
844 dprint("Grenade: ", ftos(grenade ), "\n");
845 dprint("Electro: ", ftos(electro ), "\n");
846 dprint("Crylink: ", ftos(crylink ), "\n");
847 dprint("Uzi: " , ftos(uzi ), "\n");
848 dprint("Shotgun :", ftos(shotgun ), "\n");
849 dprint("Laser :", ftos(laser ), "\n\n");
852 w = WEP_MINSTANEX ;s = minstanex;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
853 w = WEP_ROCKET_LAUNCHER ;s = rocket ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
854 w = WEP_NEX ;s = nex ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
855 w = WEP_HAGAR ;s = hagar ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
856 w = WEP_GRENADE_LAUNCHER ;s = grenade ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
857 w = WEP_ELECTRO ;s = electro ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
858 w = WEP_CRYLINK ;s = crylink ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
859 w = WEP_UZI ;s = uzi ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
860 w = WEP_SHOTGUN ;s = shotgun ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
861 w = WEP_LASER ;s = laser ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
863 // switch if the best weapon would provide a significant damage increase
864 if (bestscore > currentscore*1.5){
865 self.switchweapon = bestweapon;
867 // buys time for detonating the rocket. not tested yet
868 if ( cvar("bot_ai_weapon_combo") && bestweapon == WEP_ROCKET_LAUNCHER )
869 self.bot_chooseweapontime += (distance / cvar("g_balance_rocketlauncher_speed"));
876 local vector selfvel, enemyvel;
877 // if(self.flags & FL_INWATER)
879 if (time < self.nextaim)
881 self.nextaim = time + 0.1;
882 selfvel = self.velocity;
883 if (!self.waterlevel)
887 enemyvel = self.enemy.velocity;
888 if (!self.enemy.waterlevel)
890 lag_additem(time + self.ping, 0, 0, self.enemy, self.origin, selfvel, self.enemy.origin, enemyvel);
893 lag_additem(time + self.ping, 0, 0, world, self.origin, selfvel, self.goalcurrent.origin, '0 0 0');
898 if (bot_strategytoken == self)
899 if (!bot_strategytoken_taken)
901 self.havocbot_role();
903 // TODO: tracewalk() should take care of this job (better path finding under water)
904 // if we don't have a goal and we're under water look for a waypoint near the "shore" and push it
905 if(self.goalcurrent==world)
906 if(self.waterlevel==2 || self.aistatus & AI_STATUS_OUT_WATER)
908 // Look for the closest waypoint out of water
909 local entity newgoal, head;
910 local float bestdistance, distance;
913 bestdistance = 10000;
914 for (head = findchain(classname, "waypoint"); head; head = head.chain)
916 distance = vlen(head.origin - self.origin);
920 if(head.origin_z < self.origin_z)
923 if(head.origin_z - self.origin_z - self.view_ofs_z > 100)
926 if (pointcontents(head.origin + head.maxs + '0 0 1') != CONTENT_EMPTY)
929 traceline(self.origin + self.view_ofs , head.origin, TRUE, head);
934 if(distance<bestdistance)
937 bestdistance = distance;
943 // te_wizspike(newgoal.origin);
944 navigation_pushroute(newgoal);
948 // token has been used this frame
949 bot_strategytoken_taken = TRUE;
951 havocbot_chooseenemy();
952 if (self.bot_chooseweapontime < time )
954 self.bot_chooseweapontime = time + cvar("bot_ai_chooseweaponinterval");
955 havocbot_chooseweapon();
959 if (self.bot_aimtarg)
961 self.aistatus |= AI_STATUS_ATTACKING;
962 self.aistatus &~= AI_STATUS_ROAMING;
964 weapon_action(self.weapon, WR_AIM);
965 if (cvar("bot_nofire") || IS_INDEPENDENT_PLAYER(self))
967 self.BUTTON_ATCK = FALSE;
968 self.BUTTON_ATCK2 = FALSE;
971 else if (self.goalcurrent)
973 self.aistatus |= AI_STATUS_ROAMING;
974 self.aistatus &~= AI_STATUS_ATTACKING;
976 local vector now,v,next;//,heading;
977 local float distance,skillblend,distanceblend,blend;
978 next = now = self.goalcurrent.origin - (self.origin + self.view_ofs);
979 distance = vlen(now);
980 //heading = self.velocity;
981 //dprint(self.goalstack01.classname,etos(self.goalstack01),"\n");
982 if(self.goalstack01 != self && self.goalstack01 != world && self.aistatus & AI_STATUS_RUNNING == 0)
983 next = self.goalstack01.origin - (self.origin + self.view_ofs);
984 skillblend=bound(0,(skill-2.5)*0.5,1); //lower skill player can't preturn
985 distanceblend=bound(0,distance/cvar("bot_ai_keyboard_distance"),1);
986 blend = skillblend * (1-distanceblend);
987 //v = (now * (distanceblend) + next * (1-distanceblend)) * (skillblend) + now * (1-skillblend);
988 //v = now * (distanceblend) * (skillblend) + next * (1-distanceblend) * (skillblend) + now * (1-skillblend);
989 //v = now * ((1-skillblend) + (distanceblend) * (skillblend)) + next * (1-distanceblend) * (skillblend);
990 v = now + blend * (next - now);
991 //dprint(etos(self), " ");
992 //dprint(vtos(now), ":", vtos(next), "=", vtos(v), " (blend ", ftos(blend), ")\n");
993 //v = now * (distanceblend) + next * (1-distanceblend);
994 if (self.waterlevel < 2)
996 //dprint("walk at:", vtos(v), "\n");
997 //te_lightning2(world, self.origin, self.goalcurrent.origin);
1000 havocbot_movetogoal();
1003 void havocbot_setupbot()
1005 self.bot_ai = havocbot_ai;
1006 // will be updated by think code
1007 //Generate some random skill levels
1008 self.havocbot_keyboardskill=random()-0.5;
1009 havocbot_chooserole();
1013 #ifdef DEBUG_BOT_GOALSTACK
1016 .vector lastposition;
1018 // Debug the goal stack visually
1019 void debuggoalstack()
1021 local entity target;
1024 if(self.goalcounter==0)target=self.goalcurrent;
1025 else if(self.goalcounter==1)target=self.goalstack01;
1026 else if(self.goalcounter==2)target=self.goalstack02;
1027 else if(self.goalcounter==3)target=self.goalstack03;
1028 else if(self.goalcounter==4)target=self.goalstack04;
1029 else if(self.goalcounter==5)target=self.goalstack05;
1030 else if(self.goalcounter==6)target=self.goalstack06;
1031 else if(self.goalcounter==7)target=self.goalstack07;
1032 else if(self.goalcounter==8)target=self.goalstack08;
1033 else if(self.goalcounter==9)target=self.goalstack09;
1034 else if(self.goalcounter==10)target=self.goalstack10;
1035 else if(self.goalcounter==11)target=self.goalstack11;
1036 else if(self.goalcounter==12)target=self.goalstack12;
1037 else if(self.goalcounter==13)target=self.goalstack13;
1038 else if(self.goalcounter==14)target=self.goalstack14;
1039 else if(self.goalcounter==15)target=self.goalstack15;
1040 else if(self.goalcounter==16)target=self.goalstack16;
1041 else if(self.goalcounter==17)target=self.goalstack17;
1042 else if(self.goalcounter==18)target=self.goalstack18;
1043 else if(self.goalcounter==19)target=self.goalstack19;
1044 else if(self.goalcounter==20)target=self.goalstack20;
1045 else if(self.goalcounter==21)target=self.goalstack21;
1046 else if(self.goalcounter==22)target=self.goalstack22;
1047 else if(self.goalcounter==23)target=self.goalstack23;
1048 else if(self.goalcounter==24)target=self.goalstack24;
1049 else if(self.goalcounter==25)target=self.goalstack25;
1050 else if(self.goalcounter==26)target=self.goalstack26;
1051 else if(self.goalcounter==27)target=self.goalstack27;
1052 else if(self.goalcounter==28)target=self.goalstack28;
1053 else if(self.goalcounter==29)target=self.goalstack29;
1054 else if(self.goalcounter==30)target=self.goalstack30;
1055 else if(self.goalcounter==31)target=self.goalstack31;
1059 self.goalcounter = 0;
1060 self.lastposition='0 0 0';
1064 if(self.lastposition=='0 0 0')
1067 org = self.lastposition;
1070 te_lightning2(world, org, target.origin);
1071 self.lastposition = target.origin;