]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/havocbot.qc
n00bots never heard about weapon combos
[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 campingrifle ; campingrifle  =-1000;
344         local float laser   ; laser    =-1000;
345         local float minstanex ; minstanex =-1000;
346         local float currentscore;
347         local float bestscore; bestscore = 0;
348         local float bestweapon; bestweapon=self.switchweapon;
349         local float distance; distance=bound(10,vlen(self.origin-self.enemy.origin)-200,10000);
350         local float maxdelaytime=0.5;
351         local float spreadpenalty=10;
352         local float distancefromfloor;
353
354         local float af, ct, combo_time;
355
356         traceline(self.enemy.origin,self.enemy.origin-'0 0 1000',TRUE,world);
357         distancefromfloor = self.enemy.origin_z - trace_endpos_z;
358         
359         af = ATTACK_FINISHED(self);
360         ct = cvar("bot_ai_weapon_combo_threshold");
361
362         // Bots with no skill will be 4 times more slower than "godlike" bots when doing weapon combos
363         // Ideally this 4 should be calculated as longest_weapon_refire / bot_ai_weapon_combo_threshold
364         combo_time = time + ct + (ct * ((-0.3*skill)+3));
365
366         // Custom weapon list based on distance to the enemy
367         local float i; i = 0;
368         if(bot_custom_weapon){
369
370                 // Choose weapons for far distance
371                 if ( distance > bot_distance_far ) {
372                         for(i=0; i < WEP_LAST && bot_weapons_far[i] != -1 ; ++i){
373                                 w = bot_weapons_far[i];
374                                 if ( client_hasweapon(self, w, TRUE, FALSE) ){
375                                         if ( self.weapon == w){
376                                                 if( cvar("bot_ai_weapon_combo") && af > combo_time)
377                                                         continue;
378                                         } else {
379                                                 self.switchweapon = w;
380                                         }
381                                         return;
382                                 }
383                         }
384                 }
385
386                 // Choose weapons for mid distance
387                 if ( distance > bot_distance_close ) {
388                         for(i=0; i < WEP_LAST && bot_weapons_mid[i] != -1 ; ++i){
389                                 w = bot_weapons_mid[i];
390                                 if ( client_hasweapon(self, w, TRUE, FALSE) ){
391                                         if ( self.weapon == w){
392                                                 if( cvar("bot_ai_weapon_combo") && af > combo_time)
393                                                         continue;
394                                         } else {
395                                                 self.switchweapon = w;
396                                         }
397                                         return;
398                                 }
399                         }
400                 }
401
402                 // Choose weapons for close distance
403                 for(i=0; i < WEP_LAST && bot_weapons_close[i] != -1 ; ++i){
404                         w = bot_weapons_close[i];
405                         if ( client_hasweapon(self, w, TRUE, FALSE) ){
406                                 if ( self.weapon == w){
407                                         if( cvar("bot_ai_weapon_combo") && af > combo_time)
408                                                 continue;
409                                 } else {
410                                         self.switchweapon = w;
411                                 }
412                                 return;
413                         }
414                 }
415                 // If now weapon was chosen by this system fall back to the previous one
416         }
417
418         // Formula:
419         //      (Damage/Sec * Weapon spefic change to get that damage)
420         //      *(Time to get to target * weapon specfic hitchange bonus) / (in a time of maxdelaytime)
421         //      *(Spread change of hit) // if it applies
422         //      *(Penality for target beeing in air)
423         // %weaponaddpoint
424         if (client_hasweapon(self, WEP_MINSTANEX, TRUE, FALSE))
425                 minstanex = (1000/cvar("g_balance_minstanex_refire")*1.0)
426                         * (0.5);
427
428         if (client_hasweapon(self, WEP_ROCKET_LAUNCHER, TRUE, FALSE)  && 
429                 !(      cvar("bot_ai_weapon_combo") && self.weapon == WEP_ROCKET_LAUNCHER && 
430                         af > combo_time
431                 )
432         )
433                 rocket = (cvar("g_balance_rocketlauncher_damage")/cvar("g_balance_rocketlauncher_refire")*0.75)
434                         * bound(0,(cvar("g_balance_rocketlauncher_speed")/distance*maxdelaytime),1)*1.5;
435                         
436         if (client_hasweapon(self, WEP_NEX, TRUE, FALSE)  && 
437                 !(      cvar("bot_ai_weapon_combo") && self.weapon == WEP_NEX && 
438                         af > combo_time
439                 )
440         )
441                 nex = (cvar("g_balance_nex_damage")/cvar("g_balance_nex_refire")*1.0)
442                         * (0.5);
443                         
444         if (client_hasweapon(self, WEP_HAGAR, TRUE, FALSE) ) // && 
445         //      !( cvar("bot_ai_weapon_combo") && self.weapon == WEP_HAGAR &&  time < self.bot_lastshot + cvar("g_balance_hagar_primary_refire") ))
446                 hagar = (cvar("g_balance_hagar_primary_damage")/cvar("g_balance_hagar_primary_refire")*1.0)
447                         * bound(0,(cvar("g_balance_hagar_primary_speed")/distance*maxdelaytime),1)*0.2;
448                         
449         if (client_hasweapon(self, WEP_GRENADE_LAUNCHER, TRUE, FALSE) && 
450                 !( 
451                         cvar("bot_ai_weapon_combo") && self.weapon == WEP_GRENADE_LAUNCHER && 
452                         af > combo_time
453                 )
454         )
455                 grenade = (cvar("g_balance_grenadelauncher_primary_damage")/cvar("g_balance_grenadelauncher_primary_refire")*1.0)
456                         * bound(0,(cvar("g_balance_grenadelauncher_primary_speed")/distance*maxdelaytime),1)*1.1;
457                         
458         if (client_hasweapon(self, WEP_ELECTRO, TRUE, FALSE) && 
459                 !(      cvar("bot_ai_weapon_combo") && self.weapon == WEP_ELECTRO && 
460                         af > combo_time
461                 )
462         )
463                 electro = (cvar("g_balance_electro_primary_damage")/cvar("g_balance_electro_primary_refire")*0.75)
464                         * bound(0,(cvar("g_balance_electro_primary_speed")/distance*maxdelaytime),1)*1.0;
465                         
466         if (client_hasweapon(self, WEP_CRYLINK, TRUE, FALSE) ) // && 
467         //      !( self.weapon == WEP_CRYLINK &&  time < self.bot_lastshot + cvar("g_balance_crylink_primary_refire") ))
468                 crylink = (cvar("g_balance_crylink_primary_damage")/cvar("g_balance_crylink_primary_refire")*1.0)
469                         * bound(0,(cvar("g_balance_crylink_primary_speed")/distance*maxdelaytime),1)*(64/(32+cvar("g_balance_crylink_primary_spread")*distance))*1.0;
470                         
471         if (client_hasweapon(self, WEP_UZI, TRUE, FALSE) ) // && 
472         //      !( self.weapon == WEP_UZI &&  time < self.bot_lastshot + cvar("g_balance_uzi_sustained_refire") ))
473                 uzi = (cvar("g_balance_uzi_sustained_damage")/cvar("g_balance_uzi_sustained_refire")*1.0)
474                         * bound(0,32/(32+cvar("g_balance_uzi_sustained_spread")*distance),1);
475                         
476         if (client_hasweapon(self, WEP_SHOTGUN, TRUE, FALSE) && 
477                 !(      cvar("bot_ai_weapon_combo") && self.weapon == WEP_SHOTGUN && 
478                         af > combo_time
479                 )
480         )
481                 shotgun = (cvar("g_balance_shotgun_primary_damage")*cvar("g_balance_shotgun_primary_bullets")/cvar("g_balance_shotgun_primary_refire")*1.0)
482                         * bound(0,32/(32+cvar("g_balance_shotgun_primary_spread")*distance),1);
483                         
484         if (client_hasweapon(self, WEP_LASER, FALSE, FALSE) && 
485                 !(      cvar("bot_ai_weapon_combo") && self.weapon == WEP_LASER && 
486                         af > combo_time
487                 )
488         )
489                 laser = (cvar("g_balance_laser_primary_damage")/cvar("g_balance_laser_primary_refire")*1.0)
490                         * bound(0,cvar("g_balance_laser_primary_speed")/distance*maxdelaytime,1);
491                         
492         if((self.enemy.flags & FL_ONGROUND)==FALSE){
493                 rocket = rocket   * (1.5-bound(0, distancefromfloor/cvar("g_balance_rocketlauncher_radius"         ),0.9)); //slight bigger change
494                 grenade = grenade * (1.5-bound(0,distancefromfloor/cvar("g_balance_grenadelauncher_primary_radius"),0.95));
495                 electro = electro * (1.5-bound(0,distancefromfloor/cvar("g_balance_electro_primary_radius"        ),0.95));
496                 laser = laser     * (1.5-bound(0,distancefromfloor/cvar("g_balance_laser_primary_radius"                  ),0.95));
497         }
498         /*
499         dprint("Floor distance: ",ftos(distancefromfloor),"\n");
500         dprint("Rocket: " , ftos(rocket  ), "\n");
501         dprint("Nex: "    , ftos(nex     ), "\n");
502         dprint("Hagar: "  , ftos(hagar   ), "\n");
503         dprint("Grenade: ", ftos(grenade ), "\n");
504         dprint("Electro: ", ftos(electro ), "\n");
505         dprint("Crylink: ", ftos(crylink ), "\n");
506         dprint("Uzi: "    , ftos(uzi     ), "\n");
507         dprint("Shotgun :", ftos(shotgun ), "\n");
508         dprint("Laser   :", ftos(laser   ), "\n\n");
509         */
510         currentscore = -1;
511         w = WEP_MINSTANEX        ;s = minstanex;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
512         w = WEP_ROCKET_LAUNCHER  ;s = rocket   ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
513         w = WEP_NEX              ;s = nex      ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
514         w = WEP_HAGAR            ;s = hagar    ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
515         w = WEP_GRENADE_LAUNCHER ;s = grenade  ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
516         w = WEP_ELECTRO          ;s = electro  ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
517         w = WEP_CRYLINK          ;s = crylink  ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
518         w = WEP_UZI              ;s = uzi      ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
519         w = WEP_SHOTGUN          ;s = shotgun  ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
520         w = WEP_LASER            ;s = laser    ;if (s > bestscore){bestscore = s;bestweapon = w;} if (self.switchweapon == w) currentscore = s;
521
522         // switch if the best weapon would provide a significant damage increase
523         if (bestscore > currentscore*1.5){
524                 self.switchweapon = bestweapon;
525                 
526                 // buys time for detonating the rocket. not tested yet
527                 if ( cvar("bot_ai_weapon_combo") && bestweapon == WEP_ROCKET_LAUNCHER )
528                         self.bot_chooseweapontime += (distance  / cvar("g_balance_rocketlauncher_speed"));
529         }
530 };
531
532 .float nextaim;
533 void havocbot_aim()
534 {
535         local vector selfvel, enemyvel;
536         if (time < self.nextaim)
537                 return;
538         self.nextaim = time + 0.1;
539         selfvel = self.velocity;
540         if (!self.waterlevel)
541                 selfvel_z = 0;
542         if (self.enemy)
543         {
544                 enemyvel = self.enemy.velocity;
545                 if (!self.enemy.waterlevel)
546                         enemyvel_z = 0;
547                 lag_additem(time + self.ping, 0, 0, self.enemy, self.origin, selfvel, self.enemy.origin, enemyvel);
548         }
549         else
550                 lag_additem(time + self.ping, 0, 0, world, self.origin, selfvel, self.goalcurrent.origin, '0 0 0');
551 };
552
553 void havocbot_ai()
554 {
555         if (bot_strategytoken == self)
556         if (!bot_strategytoken_taken)
557         {
558                 self.havocbot_role();
559                 // token has been used this frame
560                 bot_strategytoken_taken = TRUE;
561         }
562         havocbot_chooseenemy();
563         if (self.bot_chooseweapontime < time )
564         {
565                 self.bot_chooseweapontime = time + cvar("bot_ai_chooseweaponinterval");
566                 havocbot_chooseweapon();
567         }
568         havocbot_aim();
569         lag_update();
570         if (self.bot_aimtarg)
571         {
572                 weapon_action(self.weapon, WR_AIM);
573                 if (cvar("bot_nofire") || IS_INDEPENDENT_PLAYER(self))
574                 {
575                         self.BUTTON_ATCK = FALSE;
576                         self.BUTTON_ATCK2 = FALSE;
577                 }
578         }
579         else if (self.goalcurrent)
580         {
581                 local vector now,v,next;//,heading;
582                 local float distance,skillblend,distanceblend,blend;
583                 next = now = self.goalcurrent.origin - (self.origin + self.view_ofs);
584                 distance = vlen(now);
585                 //heading = self.velocity;
586                 //dprint(self.goalstack01.classname,etos(self.goalstack01),"\n");
587                 if(self.goalstack01 != self && self.goalstack01 != world)
588                         next = self.goalstack01.origin - (self.origin + self.view_ofs);
589                 skillblend=bound(0,(skill-2.5)*0.5,1); //lower skill player can't preturn
590                 distanceblend=bound(0,distance/cvar("bot_ai_keyboard_distance"),1);
591                 blend = skillblend * (1-distanceblend);
592                 //v = (now * (distanceblend) + next * (1-distanceblend)) * (skillblend) + now * (1-skillblend);
593                 //v = now * (distanceblend) * (skillblend) + next * (1-distanceblend) * (skillblend) + now * (1-skillblend);
594                 //v = now * ((1-skillblend) + (distanceblend) * (skillblend)) + next * (1-distanceblend) * (skillblend);
595                 v = now + blend * (next - now);
596                 //dprint(etos(self), " ");
597                 //dprint(vtos(now), ":", vtos(next), "=", vtos(v), " (blend ", ftos(blend), ")\n");
598                 //v = now * (distanceblend) + next * (1-distanceblend);
599                 if (self.waterlevel < 2)
600                         v_z = 0;
601                 //dprint("walk at:", vtos(v), "\n");
602                 //te_lightning2(world, self.origin, self.goalcurrent.origin);
603                 bot_aimdir(v, -1);
604         }
605         havocbot_movetogoal();
606 };
607
608 void havocbot_setupbot()
609 {
610         self.bot_ai = havocbot_ai;
611         // will be updated by think code
612         //Generate some random skill levels
613         self.havocbot_keyboardskill=random()-0.5;
614         havocbot_chooserole();
615 }