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