]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/havocbot.qc
bots: combos; custom weapon priorities
[divverent/nexuiz.git] / data / qcsrc / server / havocbot.qc
1
2 .void() havocbot_role;
3 void() havocbot_chooserole;
4 .float havocbot_keyboardskill;
5
6 vector havocbot_dodge()
7 {
8         // LordHavoc: disabled because this is too expensive
9         return '0 0 0';
10         /*
11         local entity head;
12         local vector dodge, v, n;
13         local float danger, bestdanger, vl, d;
14         dodge = '0 0 0';
15         bestdanger = -20;
16         // check for dangerous objects near bot or approaching bot
17         head = findchainfloat(bot_dodge, TRUE);
18         while(head)
19         {
20                 if (head.owner != self)
21                 {
22                         vl = vlen(head.velocity);
23                         if (vl > sv_maxspeed * 0.3)
24                         {
25                                 n = normalize(head.velocity);
26                                 v = self.origin - head.origin;
27                                 d = v * n;
28                                 if (d > (0 - head.bot_dodgerating))
29                                 if (d < (vl * 0.2 + head.bot_dodgerating))
30                                 {
31                                         // calculate direction and distance from the flight path, by removing the forward axis
32                                         v = v - (n * (v * n));
33                                         danger = head.bot_dodgerating - vlen(v);
34                                         if (bestdanger < danger)
35                                         {
36                                                 bestdanger = danger;
37                                                 // dodge to the side of the object
38                                                 dodge = normalize(v);
39                                         }
40                                 }
41                         }
42                         else
43                         {
44                                 danger = head.bot_dodgerating - vlen(head.origin - self.origin);
45                                 if (bestdanger < danger)
46                                 {
47                                         bestdanger = danger;
48                                         dodge = normalize(self.origin - head.origin);
49                                 }
50                         }
51                 }
52                 head = head.chain;
53         }
54         return dodge;
55         */
56 };
57
58 //.float havocbotignoretime;
59 .float havocbot_keyboardtime;
60 .float havocbot_ducktime;
61 .vector havocbot_keyboard;
62 //.vector bot_dodgevector;
63 //.float bot_dodgevector_time;
64 //.float bot_dodgevector_jumpbutton;
65 void havocbot_movetogoal()
66 {
67         local vector destorg;
68         local vector diff;
69         local vector dir;
70         local vector flatdir;
71         local vector m1;
72         local vector m2;
73         local vector evadeobstacle;
74         local vector evadelava;
75         local float s;
76         local float maxspeed;
77         //local float dist;
78         local vector dodge;
79         //if (self.goalentity)
80         //      te_lightning2(self, self.origin, (self.goalentity.absmin + self.goalentity.absmax) * 0.5);
81         self.movement = '0 0 0';
82         maxspeed = cvar("sv_maxspeed");
83
84         if(self.jumppadcount)
85         {
86                 if(self.flags & FL_ONGROUND)
87                         self.jumppadcount = FALSE;
88                 else
89                         return;
90         }
91
92         if (self.goalcurrent == world)
93                 return;
94         navigation_poptouchedgoals();
95         if (self.goalcurrent == world)
96         {
97                 // ran out of goals, rethink strategy as soon as possible
98                 self.bot_strategytime = 0;
99                 return;
100         }
101         m1 = self.goalcurrent.origin + self.goalcurrent.mins;
102         m2 = self.goalcurrent.origin + self.goalcurrent.maxs;
103         destorg = self.origin;
104         destorg_x = bound(m1_x, destorg_x, m2_x);
105         destorg_y = bound(m1_y, destorg_y, m2_y);
106         destorg_z = bound(m1_z, destorg_z, m2_z);
107         diff = destorg - self.origin;
108         //dist = vlen(diff);
109         dir = normalize(diff);
110         flatdir = diff;flatdir_z = 0;
111         flatdir = normalize(flatdir);
112         //if (self.bot_dodgevector_time < time)
113         {
114         //      self.bot_dodgevector_time = time + cvar("bot_ai_dodgeupdateinterval");
115         //      self.bot_dodgevector_jumpbutton = 1;
116                 evadeobstacle = '0 0 0';
117                 evadelava = '0 0 0';
118                 if (!self.waterlevel)
119                 {
120                         // Since new update in air contol, we can move in air
121                         //if (!(self.flags & FL_ONGROUND))
122                         //{
123                         //      // prevent goal checks when we can't walk
124                         //      if (self.bot_strategytime < time + 0.1)
125                         //              self.bot_strategytime = time + 0.1;
126                         //      return;
127                         //}
128
129                         // jump if going toward an obstacle that doesn't look like stairs we
130                         // can walk up directly
131                         tracebox(self.origin, self.mins, self.maxs, self.origin + self.velocity * 0.2, FALSE, self);
132                         if (trace_fraction < 1)
133                         if (trace_plane_normal_z < 0.7)
134                         {
135                                 s = trace_fraction;
136                                 tracebox(self.origin + '0 0 16', self.mins, self.maxs, self.origin + self.velocity * 0.2 + '0 0 16', FALSE, self);
137                                 if (trace_fraction < s + 0.01)
138                                 if (trace_plane_normal_z < 0.7)
139                                 {
140                                         s = trace_fraction;
141                                         tracebox(self.origin + '0 0 48', self.mins, self.maxs, self.origin + self.velocity * 0.2 + '0 0 48', FALSE, self);
142                                         if (trace_fraction > s)
143                                                 self.BUTTON_JUMP = 1;
144                                 }
145                         }
146
147                         traceline(self.origin + self.velocity * 0.3, self.origin + self.velocity * 0.3 + '0 0 -1000', TRUE, world);
148                         s = pointcontents(trace_endpos + '0 0 1');
149                         if (s == CONTENT_LAVA || s == CONTENT_SLIME)
150                                 evadelava = normalize(self.velocity) * -1;
151
152                         dir = flatdir;
153                         evadeobstacle_z = 0;
154                         evadelava_z = 0;
155                         makevectors(self.v_angle_y * '0 1 0');
156                 }
157                 else
158                         makevectors(self.v_angle);
159                 dodge = havocbot_dodge();
160                 dodge = dodge * bound(0,3+skill*0.1,1);
161                 evadelava = evadelava * bound(1,3-skill,3); //Noobs fear lava a lot and take more distance from it
162                 traceline(self.origin, self.enemy.origin, TRUE, world);
163                 if(trace_ent.classname == "player")
164                         dir = dir * bound(0,skill/7,1);
165
166                 dir = normalize(dir + dodge + evadeobstacle + evadelava);
167         //      self.bot_dodgevector = dir;
168         //      self.bot_dodgevector_jumpbutton = self.BUTTON_JUMP;
169         }
170
171         //dir = self.bot_dodgevector;
172         //if (self.bot_dodgevector_jumpbutton)
173         //      self.BUTTON_JUMP = 1;
174
175         self.movement_x = dir * v_forward * maxspeed;
176         self.movement_y = dir * v_right * maxspeed;
177         self.movement_z = dir * v_up * maxspeed;
178
179         if (skill < 10)
180         {
181                 // Emulate keyboard interface;
182                 local vector keyboard;
183                 local float blend;
184                 if (time >= self.havocbot_keyboardtime)
185                 {
186                         self.havocbot_keyboardtime =
187                                 max(
188                                         self.havocbot_keyboardtime
189                                                 + bound(0,0.05/(skill+self.havocbot_keyboardskill),0.05)
190                                                 +random()*bound(0,0.025/(skill+self.havocbot_keyboardskill),100)
191                                 , time);
192                         keyboard = self.movement * (1.0 / maxspeed);
193
194                         local float trigger, trigger1;
195                         blend = bound(0,skill*0.1,1);
196                         trigger = cvar("bot_ai_keyboard_treshold");
197                         trigger1 = 0 - trigger;
198
199                         // categorize forward movement
200                         // at skill < 1.5 only forward
201                         // at skill < 2.5 only individual directions
202                         // at skill < 4.5 only individual directions, and forward diagonals
203                         // at skill >= 4.5, all cases allowed
204                         if (keyboard_x > trigger)
205                         {
206                                 keyboard_x = 1;
207                                 if (skill < 2.5)
208                                         keyboard_y = 0;
209                         }
210                         else if (keyboard_x < trigger1 && skill > 1.5)
211                         {
212                                 keyboard_x = -1;
213                                 if (skill < 4.5)
214                                         keyboard_y = 0;
215                         }
216                         else
217                         {
218                                 keyboard_x = 0;
219                                 if (skill < 1.5)
220                                         keyboard_y = 0;
221                         }
222                         if (skill < 4.5)
223                                 keyboard_z = 0;
224
225                         if (keyboard_y > trigger)
226                                 keyboard_y = 1;
227                         else if (keyboard_y < trigger1)
228                                 keyboard_y = -1;
229                         else
230                                 keyboard_y = 0;
231
232                         if (keyboard_z > trigger)
233                                 keyboard_z = 1;
234                         else if (keyboard_z < trigger1)
235                                 keyboard_z = -1;
236                         else
237                                 keyboard_z = 0;
238
239                         self.havocbot_keyboard = keyboard * maxspeed;
240                         if (self.havocbot_ducktime>time) self.BUTTON_CROUCH=TRUE;
241                 }
242                 keyboard = self.havocbot_keyboard;
243                 blend = bound(0,vlen(destorg-self.origin)/cvar("bot_ai_keyboard_distance"),1); // When getting close move with 360 degree
244                 //dprint("movement ", vtos(self.movement), " keyboard ", vtos(keyboard), " blend ", ftos(blend), "\n");
245                 self.movement = self.movement + (keyboard - self.movement) * blend;
246         }
247
248         if ((dir * v_up) >= cvar("sv_jumpvelocity")*0.5 && (self.flags & FL_ONGROUND)) self.BUTTON_JUMP=1;
249         if (((dodge * v_up) > 0) && random()*frametime >= 0.2*bound(0,(10-skill)*0.1,1)) self.BUTTON_JUMP=TRUE;
250         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);
251
252 };
253
254 .float havocbot_chooseenemy_finished;
255 .float havocbot_stickenemy;
256 void havocbot_chooseenemy()
257 {
258         local entity head, best;
259         local float rating, bestrating;
260         local vector eye, v;
261         if (cvar("bot_nofire") || IS_INDEPENDENT_PLAYER(self))
262         {
263                 self.enemy = world;
264                 return;
265         }
266         if (self.enemy)
267         {
268                 if (!bot_shouldattack(self.enemy))
269                 {
270                         // enemy died or something, find a new target
271                         self.enemy = world;
272                         self.havocbot_chooseenemy_finished = time;
273                 }
274                 else if (self.havocbot_stickenemy)
275                 {
276                         // tracking last chosen enemy
277                         // if enemy is visible
278                         // and not really really far away
279                         // and we're not severely injured
280                         // then keep tracking for a half second into the future
281                         traceline(self.origin+self.view_ofs, self.enemy.origin+self.enemy.view_ofs*0.5,FALSE,world);
282                         if (trace_ent == self.enemy || trace_fraction == 1)
283                         if (vlen(self.enemy.origin - self.origin) < 1000)
284                         if (self.health > 30)
285                         {
286                                 // remain tracking him for a shot while (case he went after a small corner or pilar
287                                 self.havocbot_chooseenemy_finished = time + cvar("bot_ai_enemydetectioninterval");
288                                 return;
289                         }
290                         // enemy isn't visible, or is far away, or we're injured severely
291                         // so stop preferring this enemy
292                         // (it will still take a half second until a new one is chosen)
293                         self.havocbot_stickenemy = 0;
294                 }
295         }
296         if (time < self.havocbot_chooseenemy_finished)
297                 return;
298         self.havocbot_chooseenemy_finished = time + cvar("bot_ai_enemydetectioninterval");
299         eye = (self.origin + self.view_ofs);
300         best = world;
301         bestrating = 100000000;
302         head = findchainfloat(bot_attack, TRUE);
303         while (head)
304         {
305                 v = (head.absmin + head.absmax) * 0.5;
306                 rating = vlen(v - eye);
307                 if (bestrating > rating)
308                 if (bot_shouldattack(head))
309                 {
310                         traceline(eye, v, TRUE, self);
311                         if (trace_ent == head || trace_fraction >= 1)
312                         {
313                                 best = head;
314                                 bestrating = rating;
315                         }
316                 }
317                 head = head.chain;
318         }
319         self.enemy = best;
320         self.havocbot_stickenemy = 1;
321 };
322
323 .float bot_chooseweapontime;
324 float(entity e) w_getbestweapon;
325 void havocbot_chooseweapon()
326 {
327         // TODO: clean this up by moving it to weapon code
328         if(self.enemy.classname!="player")
329         {
330                 self.switchweapon = w_getbestweapon(self);
331                 return;
332         }
333
334         local float w, s;
335         local float rocket  ; rocket   =-1000;
336         local float nex     ; nex      =-1000;
337         local float hagar   ; hagar    =-1000;
338         local float grenade ; grenade  =-1000;
339         local float electro ; electro  =-1000;
340         local float crylink ; crylink  =-1000;
341         local float uzi     ; uzi      =-1000;
342         local float shotgun ; shotgun  =-1000;
343         local float laser   ; laser    =-1000;
344         local float minstanex ; minstanex =-1000;
345         local float currentscore;
346         local float bestscore; bestscore = 0;
347         local float bestweapon; bestweapon=self.switchweapon;
348         local float distance; distance=bound(10,vlen(self.origin-self.enemy.origin)-200,10000);
349         local float maxdelaytime=0.5;
350         local float spreadpenalty=10;
351         local float distancefromfloor;
352         traceline(self.enemy.origin,self.enemy.origin-'0 0 1000',TRUE,world);
353         distancefromfloor = self.enemy.origin_z - trace_endpos_z;
354
355         // Custom weapon list based on distance to the enemy
356         local float i; i = 0;
357         if(bot_custom_weapon){
358
359                 // Choose weapons for far distance
360                 if ( distance > bot_distance_far ) {
361                         for(i=0; i < WEP_LAST && bot_weapons_far[i] != -1 ; ++i){
362                                 w = bot_weapons_far[i];
363                                 if ( client_hasweapon(self, w, TRUE, FALSE) ){
364                                         if ( self.weapon == w){
365                                                 if( cvar("bot_ai_weapon_combo") && 
366                                                         ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold"))
367                                                         continue;
368                                         } else {
369                                                 self.switchweapon = w;
370                                         }
371                                         return;
372                                 }
373                         }
374                 }
375
376                 // Choose weapons for mid distance
377                 if ( distance > bot_distance_close ) {
378                         for(i=0; i < WEP_LAST && bot_weapons_mid[i] != -1 ; ++i){
379                                 w = bot_weapons_mid[i];
380                                 if ( client_hasweapon(self, w, TRUE, FALSE) ){
381                                         if ( self.weapon == w){
382                                                 if( cvar("bot_ai_weapon_combo") && 
383                                                         ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold"))
384                                                         continue;
385                                         } else {
386                                                 self.switchweapon = w;
387                                         }
388                                         return;
389                                 }
390                         }
391                 }
392
393                 // Choose weapons for close distance
394                 for(i=0; i < WEP_LAST && bot_weapons_close[i] != -1 ; ++i){
395                         w = bot_weapons_close[i];
396                         if ( client_hasweapon(self, w, TRUE, FALSE) ){
397                                 if ( self.weapon == w){
398                                         if( cvar("bot_ai_weapon_combo") && 
399                                                 ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold"))
400                                                 continue;
401                                 } else {
402                                         self.switchweapon = w;
403                                 }
404                                 return;
405                         }
406                 }
407                 // If now weapon was chosen by this system fall back to the previous one
408         }
409
410         // Formula:
411         //      (Damage/Sec * Weapon spefic change to get that damage)
412         //      *(Time to get to target * weapon specfic hitchange bonus) / (in a time of maxdelaytime)
413         //      *(Spread change of hit) // if it applies
414         //      *(Penality for target beeing in air)
415         // %weaponaddpoint
416         if (client_hasweapon(self, WEP_MINSTANEX, TRUE, FALSE))
417                 minstanex = (1000/cvar("g_balance_minstanex_refire")*1.0)
418                         * (0.5);
419
420         if (client_hasweapon(self, WEP_ROCKET_LAUNCHER, TRUE, FALSE)  && 
421                 !(      cvar("bot_ai_weapon_combo") && self.weapon == WEP_ROCKET_LAUNCHER && 
422                         ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold") 
423                 )
424         )
425                 rocket = (cvar("g_balance_rocketlauncher_damage")/cvar("g_balance_rocketlauncher_refire")*0.75)
426                         * bound(0,(cvar("g_balance_rocketlauncher_speed")/distance*maxdelaytime),1)*1.5;
427                         
428         if (client_hasweapon(self, WEP_NEX, TRUE, FALSE)  && 
429                 !(      cvar("bot_ai_weapon_combo") && self.weapon == WEP_NEX && 
430                         ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold") 
431                 )
432         )
433                 nex = (cvar("g_balance_nex_damage")/cvar("g_balance_nex_refire")*1.0)
434                         * (0.5);
435                         
436         if (client_hasweapon(self, WEP_HAGAR, TRUE, FALSE) ) // && 
437         //      !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_HAGAR &&  time < self.bot_lastshot + cvar("g_balance_hagar_primary_refire") ))
438                 hagar = (cvar("g_balance_hagar_primary_damage")/cvar("g_balance_hagar_primary_refire")*1.0)
439                         * bound(0,(cvar("g_balance_hagar_primary_speed")/distance*maxdelaytime),1)*0.2;
440                         
441         if (client_hasweapon(self, WEP_GRENADE_LAUNCHER, TRUE, FALSE) && 
442                 !( 
443                         cvar("bot_ai_weapon_combo") && self.weapon == WEP_GRENADE_LAUNCHER && 
444                         ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold") 
445                 )
446         )
447                 grenade = (cvar("g_balance_grenadelauncher_primary_damage")/cvar("g_balance_grenadelauncher_primary_refire")*1.0)
448                         * bound(0,(cvar("g_balance_grenadelauncher_primary_speed")/distance*maxdelaytime),1)*1.1;
449                         
450         if (client_hasweapon(self, WEP_ELECTRO, TRUE, FALSE) && 
451                 !(      cvar("bot_ai_weapon_combo") && self.weapon == WEP_ELECTRO && 
452                         ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold") 
453                 )
454         )
455                 electro = (cvar("g_balance_electro_primary_damage")/cvar("g_balance_electro_primary_refire")*0.75)
456                         * bound(0,(cvar("g_balance_electro_primary_speed")/distance*maxdelaytime),1)*1.0;
457                         
458         if (client_hasweapon(self, WEP_CRYLINK, TRUE, FALSE) ) // && 
459         //      !( self.weapon == WEP_CRYLINK &&  time < self.bot_lastshot + cvar("g_balance_crylink_primary_refire") ))
460                 crylink = (cvar("g_balance_crylink_primary_damage")/cvar("g_balance_crylink_primary_refire")*1.0)
461                         * bound(0,(cvar("g_balance_crylink_primary_speed")/distance*maxdelaytime),1)*(64/(32+cvar("g_balance_crylink_primary_spread")*distance))*1.0;
462                         
463         if (client_hasweapon(self, WEP_UZI, TRUE, FALSE) ) // && 
464         //      !( self.weapon == WEP_UZI &&  time < self.bot_lastshot + cvar("g_balance_uzi_sustained_refire") ))
465                 uzi = (cvar("g_balance_uzi_sustained_damage")/cvar("g_balance_uzi_sustained_refire")*1.0)
466                         * bound(0,32/(32+cvar("g_balance_uzi_sustained_spread")*distance),1);
467                         
468         if (client_hasweapon(self, WEP_SHOTGUN, TRUE, FALSE) && 
469                 !(      cvar("bot_ai_weapon_combo") && self.weapon == WEP_SHOTGUN && 
470                         ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold") 
471                 )
472         )
473                 shotgun = (cvar("g_balance_shotgun_primary_damage")*cvar("g_balance_shotgun_primary_bullets")/cvar("g_balance_shotgun_primary_refire")*1.0)
474                         * bound(0,32/(32+cvar("g_balance_shotgun_primary_spread")*distance),1);
475                         
476         if (client_hasweapon(self, WEP_LASER, FALSE, FALSE) && 
477                 !(      cvar("bot_ai_weapon_combo") && self.weapon == WEP_LASER && 
478                         ATTACK_FINISHED(self) > time + cvar("bot_ai_weapon_combo_threshold") 
479                 )
480         )
481                 laser = (cvar("g_balance_laser_primary_damage")/cvar("g_balance_laser_primary_refire")*1.0)
482                         * bound(0,cvar("g_balance_laser_primary_speed")/distance*maxdelaytime,1);
483                         
484         if((self.enemy.flags & FL_ONGROUND)==FALSE){
485                 rocket = rocket   * (1.5-bound(0, distancefromfloor/cvar("g_balance_rocketlauncher_radius"         ),0.9)); //slight bigger change
486                 grenade = grenade * (1.5-bound(0,distancefromfloor/cvar("g_balance_grenadelauncher_primary_radius"),0.95));
487                 electro = electro * (1.5-bound(0,distancefromfloor/cvar("g_balance_electro_primary_radius"        ),0.95));
488                 laser = laser     * (1.5-bound(0,distancefromfloor/cvar("g_balance_laser_primary_radius"                  ),0.95));
489         }
490         /*
491         dprint("Floor distance: ",ftos(distancefromfloor),"\n");
492         dprint("Rocket: " , ftos(rocket  ), "\n");
493         dprint("Nex: "    , ftos(nex     ), "\n");
494         dprint("Hagar: "  , ftos(hagar   ), "\n");
495         dprint("Grenade: ", ftos(grenade ), "\n");
496         dprint("Electro: ", ftos(electro ), "\n");
497         dprint("Crylink: ", ftos(crylink ), "\n");
498         dprint("Uzi: "    , ftos(uzi     ), "\n");
499         dprint("Shotgun :", ftos(shotgun ), "\n");
500         dprint("Laser   :", ftos(laser   ), "\n\n");
501         */
502         currentscore = -1;
503         w = WEP_MINSTANEX        ;s = minstanex;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
504         w = WEP_ROCKET_LAUNCHER  ;s = rocket   ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
505         w = WEP_NEX              ;s = nex      ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
506         w = WEP_HAGAR            ;s = hagar    ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
507         w = WEP_GRENADE_LAUNCHER ;s = grenade  ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
508         w = WEP_ELECTRO          ;s = electro  ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
509         w = WEP_CRYLINK          ;s = crylink  ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
510         w = WEP_UZI              ;s = uzi      ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
511         w = WEP_SHOTGUN          ;s = shotgun  ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
512         w = WEP_LASER            ;s = laser    ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
513
514         // switch if the best weapon would provide a significant damage increase
515         if (bestscore > currentscore*1.5){
516                 self.switchweapon = bestweapon;
517                 
518                 // buys time for detonating the rocket. not tested yet
519                 if ( cvar("bot_ai_weapon_combo") && bestweapon == WEP_ROCKET_LAUNCHER )
520                         self.bot_chooseweapontime += (distance  / cvar("g_balance_rocketlauncher_speed"));
521         }
522 };
523
524 .float nextaim;
525 void havocbot_aim()
526 {
527         local vector selfvel, enemyvel;
528         if (time < self.nextaim)
529                 return;
530         self.nextaim = time + 0.1;
531         selfvel = self.velocity;
532         if (!self.waterlevel)
533                 selfvel_z = 0;
534         if (self.enemy)
535         {
536                 enemyvel = self.enemy.velocity;
537                 if (!self.enemy.waterlevel)
538                         enemyvel_z = 0;
539                 lag_additem(time + self.ping, 0, 0, self.enemy, self.origin, selfvel, self.enemy.origin, enemyvel);
540         }
541         else
542                 lag_additem(time + self.ping, 0, 0, world, self.origin, selfvel, self.goalcurrent.origin, '0 0 0');
543 };
544
545 void havocbot_ai()
546 {
547         if (bot_strategytoken == self)
548         if (!bot_strategytoken_taken)
549         {
550                 self.havocbot_role();
551                 // token has been used this frame
552                 bot_strategytoken_taken = TRUE;
553         }
554         havocbot_chooseenemy();
555         if (self.bot_chooseweapontime < time )
556         {
557                 self.bot_chooseweapontime = time + cvar("bot_ai_chooseweaponinterval");
558                 havocbot_chooseweapon();
559         }
560         havocbot_aim();
561         lag_update();
562         if (self.bot_aimtarg)
563         {
564                 weapon_action(self.weapon, WR_AIM);
565                 if (cvar("bot_nofire") || IS_INDEPENDENT_PLAYER(self))
566                 {
567                         self.BUTTON_ATCK = FALSE;
568                         self.BUTTON_ATCK2 = FALSE;
569                 }
570         }
571         else if (self.goalcurrent)
572         {
573                 local vector now,v,next;//,heading;
574                 local float distance,skillblend,distanceblend,blend;
575                 next = now = self.goalcurrent.origin - (self.origin + self.view_ofs);
576                 distance = vlen(now);
577                 //heading = self.velocity;
578                 //dprint(self.goalstack01.classname,etos(self.goalstack01),"\n");
579                 if(self.goalstack01 != self && self.goalstack01 != world)
580                         next = self.goalstack01.origin - (self.origin + self.view_ofs);
581                 skillblend=bound(0,(skill-2.5)*0.5,1); //lower skill player can't preturn
582                 distanceblend=bound(0,distance/cvar("bot_ai_keyboard_distance"),1);
583                 blend = skillblend * (1-distanceblend);
584                 //v = (now * (distanceblend) + next * (1-distanceblend)) * (skillblend) + now * (1-skillblend);
585                 //v = now * (distanceblend) * (skillblend) + next * (1-distanceblend) * (skillblend) + now * (1-skillblend);
586                 //v = now * ((1-skillblend) + (distanceblend) * (skillblend)) + next * (1-distanceblend) * (skillblend);
587                 v = now + blend * (next - now);
588                 //dprint(etos(self), " ");
589                 //dprint(vtos(now), ":", vtos(next), "=", vtos(v), " (blend ", ftos(blend), ")\n");
590                 //v = now * (distanceblend) + next * (1-distanceblend);
591                 if (self.waterlevel < 2)
592                         v_z = 0;
593                 //dprint("walk at:", vtos(v), "\n");
594                 //te_lightning2(world, self.origin, self.goalcurrent.origin);
595                 bot_aimdir(v, -1);
596         }
597         havocbot_movetogoal();
598 };
599
600 void havocbot_setupbot()
601 {
602         self.bot_ai = havocbot_ai;
603         // will be updated by think code
604         //Generate some random skill levels
605         self.havocbot_keyboardskill=random()-0.5;
606         havocbot_chooserole();
607 }