]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/bot/havocbot/havocbot.qc
Merge branch 'master' into divVerent/urllib-weaponstats
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / havocbot / havocbot.qc
1 #include "havocbot.qh"
2 #include "role_ctf.qc"
3 #include "role_onslaught.qc"
4 #include "role_keyhunt.qc"
5 #include "role_freezetag.qc"
6 #include "role_keepaway.qc"
7 #include "role_assault.qc"
8 #include "roles.qc"
9
10 void havocbot_ai()
11 {
12         if(self.draggedby)
13                 return;
14
15         if(bot_execute_commands())
16                 return;
17
18         if (bot_strategytoken == self)
19         if (!bot_strategytoken_taken)
20         {
21                 if(self.havocbot_blockhead)
22                 {
23                         self.havocbot_blockhead = FALSE;
24                 }
25                 else
26                 {
27                         if not(self.jumppadcount)
28                                 self.havocbot_role();
29                 }
30
31                 // TODO: tracewalk() should take care of this job (better path finding under water)
32                 // if we don't have a goal and we're under water look for a waypoint near the "shore" and push it
33                 if(self.deadflag != DEAD_NO)
34                 if(self.goalcurrent==world)
35                 if(self.waterlevel==WATERLEVEL_SWIMMING || self.aistatus & AI_STATUS_OUT_WATER)
36                 {
37                         // Look for the closest waypoint out of water
38                         local entity newgoal, head;
39                         local float bestdistance, distance;
40
41                         newgoal = world;
42                         bestdistance = 10000;
43                         for (head = findchain(classname, "waypoint"); head; head = head.chain)
44                         {
45                                 distance = vlen(head.origin - self.origin);
46                                 if(distance>10000)
47                                         continue;
48
49                                 if(head.origin_z < self.origin_z)
50                                         continue;
51
52                                 if(head.origin_z - self.origin_z - self.view_ofs_z > 100)
53                                         continue;
54
55                                 if (pointcontents(head.origin + head.maxs + '0 0 1') != CONTENT_EMPTY)
56                                         continue;
57
58                                 traceline(self.origin + self.view_ofs , head.origin, TRUE, head);
59
60                                 if(trace_fraction<1)
61                                         continue;
62
63                                 if(distance<bestdistance)
64                                 {
65                                         newgoal = head;
66                                         bestdistance = distance;
67                                 }
68                         }
69
70                         if(newgoal)
71                         {
72                         //      te_wizspike(newgoal.origin);
73                                 navigation_pushroute(newgoal);
74                         }
75                 }
76
77                 // token has been used this frame
78                 bot_strategytoken_taken = TRUE;
79         }
80
81         if(self.deadflag != DEAD_NO)
82                 return;
83
84         havocbot_chooseenemy();
85         if (self.bot_chooseweapontime < time )
86         {
87                 self.bot_chooseweapontime = time + autocvar_bot_ai_chooseweaponinterval;
88                 havocbot_chooseweapon();
89         }
90         havocbot_aim();
91         lag_update();
92         if (self.bot_aimtarg)
93         {
94                 self.aistatus |= AI_STATUS_ATTACKING;
95                 self.aistatus &~= AI_STATUS_ROAMING;
96
97                 if(self.weapons)
98                 {
99                         weapon_action(self.weapon, WR_AIM);
100                         if (autocvar_bot_nofire || IS_INDEPENDENT_PLAYER(self))
101                         {
102                                 self.BUTTON_ATCK = FALSE;
103                                 self.BUTTON_ATCK2 = FALSE;
104                         }
105                         else
106                         {
107                                 if(self.BUTTON_ATCK||self.BUTTON_ATCK2)
108                                         self.lastfiredweapon = self.weapon;
109                         }
110                 }
111                 else
112                 {
113                         if(self.bot_aimtarg.classname=="player")
114                                 bot_aimdir(self.bot_aimtarg.origin + self.bot_aimtarg.view_ofs - self.origin - self.view_ofs , -1);
115                 }
116         }
117         else if (self.goalcurrent)
118         {
119                 self.aistatus |= AI_STATUS_ROAMING;
120                 self.aistatus &~= AI_STATUS_ATTACKING;
121
122                 local vector now,v,next;//,heading;
123                 local float aimdistance,skillblend,distanceblend,blend;
124                 next = now = ( (self.goalcurrent.absmin + self.goalcurrent.absmax) * 0.5) - (self.origin + self.view_ofs);
125                 aimdistance = vlen(now);
126                 //heading = self.velocity;
127                 //dprint(self.goalstack01.classname,etos(self.goalstack01),"\n");
128                 if(
129                         self.goalstack01 != self && self.goalstack01 != world && self.aistatus & AI_STATUS_RUNNING == 0 &&
130                         !(self.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
131                 )
132                         next = ((self.goalstack01.absmin + self.goalstack01.absmax) * 0.5) - (self.origin + self.view_ofs);
133
134                 skillblend=bound(0,(skill+self.bot_moveskill-2.5)*0.5,1); //lower skill player can't preturn
135                 distanceblend=bound(0,aimdistance/autocvar_bot_ai_keyboard_distance,1);
136                 blend = skillblend * (1-distanceblend);
137                 //v = (now * (distanceblend) + next * (1-distanceblend)) * (skillblend) + now * (1-skillblend);
138                 //v = now * (distanceblend) * (skillblend) + next * (1-distanceblend) * (skillblend) + now * (1-skillblend);
139                 //v = now * ((1-skillblend) + (distanceblend) * (skillblend)) + next * (1-distanceblend) * (skillblend);
140                 v = now + blend * (next - now);
141                 //dprint(etos(self), " ");
142                 //dprint(vtos(now), ":", vtos(next), "=", vtos(v), " (blend ", ftos(blend), ")\n");
143                 //v = now * (distanceblend) + next * (1-distanceblend);
144                 if (self.waterlevel < WATERLEVEL_SWIMMING)
145                         v_z = 0;
146                 //dprint("walk at:", vtos(v), "\n");
147                 //te_lightning2(world, self.origin, self.goalcurrent.origin);
148                 bot_aimdir(v, -1);
149         }
150         havocbot_movetogoal();
151
152         // if the bot is not attacking, consider reloading weapons
153         if not(self.aistatus & AI_STATUS_ATTACKING)
154         {
155                 float i;
156                 entity e;
157
158                 // we are currently holding a weapon that's not fully loaded, reload it
159                 if(skill >= 2) // bots can only reload the held weapon on purpose past this skill
160                 if(self.clip_load < self.clip_size)
161                         self.impulse = 20; // "press" the reload button, not sure if this is done right
162
163                 // if we're not reloading a weapon, switch to any weapon in our invnetory that's not fully loaded to reload it next
164                 // the code above executes next frame, starting the reloading then
165                 if(skill >= 5) // bots can only look for unloaded weapons past this skill
166                 if(self.clip_load >= 0) // only if we're not reloading a weapon already
167                 {
168                         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
169                         {
170                                 e = get_weaponinfo(i);
171                                 if ((e.spawnflags & WEP_FLAG_RELOADABLE) && (self.weapon_load[i] < cvar(strcat("g_balance_", e.netname, "_reload_ammo"))))
172                                         self.switchweapon = i;
173                         }
174                 }
175         }
176 };
177
178 void havocbot_keyboard_movement(vector destorg)
179 {
180         local vector keyboard;
181         local float blend, maxspeed;
182         float sk;
183
184         sk = skill + self.bot_moveskill;
185
186         maxspeed = autocvar_sv_maxspeed;
187
188         if (time < self.havocbot_keyboardtime)
189                 return;
190
191         self.havocbot_keyboardtime =
192                 max(
193                         self.havocbot_keyboardtime
194                                 + 0.05/max(1, sk+self.havocbot_keyboardskill)
195                                 + random()*0.025/max(0.00025, skill+self.havocbot_keyboardskill)
196                 , time);
197         keyboard = self.movement * (1.0 / maxspeed);
198
199         local float trigger, trigger1;
200         blend = bound(0,sk*0.1,1);
201         trigger = autocvar_bot_ai_keyboard_threshold;
202         trigger1 = 0 - trigger;
203
204         // categorize forward movement
205         // at skill < 1.5 only forward
206         // at skill < 2.5 only individual directions
207         // at skill < 4.5 only individual directions, and forward diagonals
208         // at skill >= 4.5, all cases allowed
209         if (keyboard_x > trigger)
210         {
211                 keyboard_x = 1;
212                 if (sk < 2.5)
213                         keyboard_y = 0;
214         }
215         else if (keyboard_x < trigger1 && sk > 1.5)
216         {
217                 keyboard_x = -1;
218                 if (sk < 4.5)
219                         keyboard_y = 0;
220         }
221         else
222         {
223                 keyboard_x = 0;
224                 if (sk < 1.5)
225                         keyboard_y = 0;
226         }
227         if (sk < 4.5)
228                 keyboard_z = 0;
229
230         if (keyboard_y > trigger)
231                 keyboard_y = 1;
232         else if (keyboard_y < trigger1)
233                 keyboard_y = -1;
234         else
235                 keyboard_y = 0;
236
237         if (keyboard_z > trigger)
238                 keyboard_z = 1;
239         else if (keyboard_z < trigger1)
240                 keyboard_z = -1;
241         else
242                 keyboard_z = 0;
243
244         self.havocbot_keyboard = keyboard * maxspeed;
245         if (self.havocbot_ducktime>time) self.BUTTON_CROUCH=TRUE;
246
247         keyboard = self.havocbot_keyboard;
248         blend = bound(0,vlen(destorg-self.origin)/autocvar_bot_ai_keyboard_distance,1); // When getting close move with 360 degree
249         //dprint("movement ", vtos(self.movement), " keyboard ", vtos(keyboard), " blend ", ftos(blend), "\n");
250         self.movement = self.movement + (keyboard - self.movement) * blend;
251 };
252
253 void havocbot_bunnyhop(vector dir)
254 {
255         local float bunnyhopdistance;
256         local vector deviation;
257         local float maxspeed;
258         vector gco, gno;
259
260         if(autocvar_g_midair)
261                 return;
262
263         // Don't jump when using some weapons
264         /*
265         if(self.aistatus & AI_STATUS_ATTACKING)
266         if(self.weapon == WEP_RIFLE)
267                 return;
268
269         if(self.goalcurrent.classname == "player")
270                 return;
271         */
272
273         maxspeed = autocvar_sv_maxspeed;
274
275         if(self.aistatus & AI_STATUS_DANGER_AHEAD)
276         {
277                 self.aistatus &~= AI_STATUS_RUNNING;
278                 self.BUTTON_JUMP = FALSE;
279                 self.bot_canruntogoal = 0;
280                 self.bot_timelastseengoal = 0;
281                 return;
282         }
283
284         if(self.waterlevel > WATERLEVEL_WETFEET)
285         {
286                 self.aistatus &~= AI_STATUS_RUNNING;
287                 return;
288         }
289
290         if(self.bot_lastseengoal != self.goalcurrent && !(self.aistatus & AI_STATUS_RUNNING))
291         {
292                 self.bot_canruntogoal = 0;
293                 self.bot_timelastseengoal = 0;
294         }
295
296         gco = (self.goalcurrent.absmin + self.goalcurrent.absmax) * 0.5;
297         bunnyhopdistance = vlen(self.origin - gco);
298
299         // Run only to visible goals
300         if(self.flags & FL_ONGROUND)
301         if(self.speed==maxspeed)
302         if(checkpvs(self.origin + self.view_ofs, self.goalcurrent))
303         {
304                         self.bot_lastseengoal = self.goalcurrent;
305
306                         // seen it before
307                         if(self.bot_timelastseengoal)
308                         {
309                                 // for a period of time
310                                 if(time - self.bot_timelastseengoal > autocvar_bot_ai_bunnyhop_firstjumpdelay)
311                                 {
312                                         local float checkdistance;
313                                         checkdistance = TRUE;
314
315                                         // don't run if it is too close
316                                         if(self.bot_canruntogoal==0)
317                                         {
318                                                 if(bunnyhopdistance > autocvar_bot_ai_bunnyhop_startdistance)
319                                                         self.bot_canruntogoal = 1;
320                                                 else
321                                                         self.bot_canruntogoal = -1;
322                                         }
323
324                                         if(self.bot_canruntogoal != 1)
325                                                 return;
326
327                                         if(self.aistatus & AI_STATUS_ROAMING)
328                                         if(self.goalcurrent.classname=="waypoint")
329                                         if not(self.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL)
330                                         if(fabs(gco_z - self.origin_z) < self.maxs_z - self.mins_z)
331                                         if(self.goalstack01!=world)
332                                         {
333                                                 gno = (self.goalstack01.absmin + self.goalstack01.absmax) * 0.5;
334                                                 deviation = vectoangles(gno - self.origin) - vectoangles(gco - self.origin);
335                                                 while (deviation_y < -180) deviation_y = deviation_y + 360;
336                                                 while (deviation_y > 180) deviation_y = deviation_y - 360;
337
338                                                 if(fabs(deviation_y) < 20)
339                                                 if(bunnyhopdistance < vlen(self.origin - gno))
340                                                 if(fabs(gno_z - gco_z) < self.maxs_z - self.mins_z)
341                                                 {
342                                                         if(vlen(gco - gno) > autocvar_bot_ai_bunnyhop_startdistance)
343                                                         if(checkpvs(self.origin + self.view_ofs, self.goalstack01))
344                                                         {
345                                                                 checkdistance = FALSE;
346                                                         }
347                                                 }
348                                         }
349
350                                         if(checkdistance)
351                                         {
352                                                 self.aistatus &~= AI_STATUS_RUNNING;
353                                                 if(bunnyhopdistance > autocvar_bot_ai_bunnyhop_stopdistance)
354                                                         self.BUTTON_JUMP = TRUE;
355                                         }
356                                         else
357                                         {
358                                                 self.aistatus |= AI_STATUS_RUNNING;
359                                                 self.BUTTON_JUMP = TRUE;
360                                         }
361                                 }
362                         }
363                         else
364                         {
365                                 self.bot_timelastseengoal = time;
366                         }
367         }
368         else
369         {
370                 self.bot_timelastseengoal = 0;
371         }
372
373         // Release jump button
374         if(!cvar("sv_pogostick"))
375         if(self.flags & FL_ONGROUND == 0)
376         {
377                 if(self.velocity_z < 0 || vlen(self.velocity)<maxspeed)
378                         self.BUTTON_JUMP = FALSE;
379
380                 // Strafe
381                 if(self.aistatus & AI_STATUS_RUNNING)
382                 if(vlen(self.velocity)>maxspeed)
383                 {
384                         deviation = vectoangles(dir) - vectoangles(self.velocity);
385                         while (deviation_y < -180) deviation_y = deviation_y + 360;
386                         while (deviation_y > 180) deviation_y = deviation_y - 360;
387
388                         if(fabs(deviation_y)>10)
389                                 self.movement_x = 0;
390
391                         if(deviation_y>10)
392                                 self.movement_y = maxspeed * -1;
393                         else if(deviation_y<10)
394                                 self.movement_y = maxspeed;
395
396                 }
397         }
398 };
399
400 void havocbot_movetogoal()
401 {
402         local vector destorg;
403         local vector diff;
404         local vector dir;
405         local vector flatdir;
406         local vector m1;
407         local vector m2;
408         local vector evadeobstacle;
409         local vector evadelava;
410         local float s;
411         local float maxspeed;
412         local vector gco;
413         //local float dist;
414         local vector dodge;
415         //if (self.goalentity)
416         //      te_lightning2(self, self.origin, (self.goalentity.absmin + self.goalentity.absmax) * 0.5);
417         self.movement = '0 0 0';
418         maxspeed = autocvar_sv_maxspeed;
419
420         // Jetpack navigation
421         if(self.goalcurrent)
422         if(self.navigation_jetpack_goal)
423         if(self.goalcurrent==self.navigation_jetpack_goal)
424         if(self.ammo_fuel)
425         {
426                 if(autocvar_bot_debug_goalstack)
427                 {
428                         debuggoalstack();
429                         te_wizspike(self.navigation_jetpack_point);
430                 }
431
432                 // Take off
433                 if not(self.aistatus & AI_STATUS_JETPACK_FLYING)
434                 {
435                         // Brake almost completely so it can get a good direction
436                         if(vlen(self.velocity)>10)
437                                 return;
438                         self.aistatus |= AI_STATUS_JETPACK_FLYING;
439                 }
440
441                 makevectors(self.v_angle_y * '0 1 0');
442                 dir = normalize(self.navigation_jetpack_point - self.origin);
443
444                 // Landing
445                 if(self.aistatus & AI_STATUS_JETPACK_LANDING)
446                 {
447                         // Calculate brake distance in xy
448                         float db, v, d;
449                         vector dxy;
450
451                         dxy = self.origin - ( ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5 ); dxy_z = 0;
452                         d = vlen(dxy);
453                         v = vlen(self.velocity -  self.velocity_z * '0 0 1');
454                         db = (pow(v,2) / (autocvar_g_jetpack_acceleration_side * 2)) + 100;
455                 //      dprint("distance ", ftos(ceil(d)), " velocity ", ftos(ceil(v)), " brake at ", ftos(ceil(db)), "\n");
456                         if(d < db || d < 500)
457                         {
458                                 // Brake
459                                 if(fabs(self.velocity_x)>maxspeed*0.3)
460                                 {
461                                         self.movement_x = dir * v_forward * -maxspeed;
462                                         return;
463                                 }
464                                 // Switch to normal mode
465                                 self.navigation_jetpack_goal = world;
466                                 self.aistatus &~= AI_STATUS_JETPACK_LANDING;
467                                 self.aistatus &~= AI_STATUS_JETPACK_FLYING;
468                                 return;
469                         }
470                 }
471                 else if(checkpvs(self.origin,self.goalcurrent))
472                 {
473                         // If I can see the goal switch to landing code
474                         self.aistatus &~= AI_STATUS_JETPACK_FLYING;
475                         self.aistatus |= AI_STATUS_JETPACK_LANDING;
476                         return;
477                 }
478
479                 // Flying
480                 self.BUTTON_HOOK = TRUE;
481                 if(self.navigation_jetpack_point_z - PL_MAX_z + PL_MIN_z < self.origin_z)
482                 {
483                         self.movement_x = dir * v_forward * maxspeed;
484                         self.movement_y = dir * v_right * maxspeed;
485                 }
486                 return;
487         }
488
489         // Handling of jump pads
490         if(self.jumppadcount)
491         {
492                 // If got stuck on the jump pad try to reach the farthest visible item
493                 if(self.aistatus & AI_STATUS_OUT_JUMPPAD)
494                 {
495                         if(fabs(self.velocity_z)<50)
496                         {
497                                 local entity head, newgoal;
498                                 local float distance, bestdistance;
499
500                                 for (head = findchainfloat(bot_pickup, TRUE); head; head = head.chain)
501                                 {
502                                         if(head.classname=="worldspawn")
503                                                 continue;
504
505                                         distance = vlen(head.origin - self.origin);
506                                         if(distance>1000)
507                                                 continue;
508
509                                         traceline(self.origin + self.view_ofs , ( ( head.absmin + head.absmax ) * 0.5 ), TRUE, world);
510
511                                         if(trace_fraction<1)
512                                                 continue;
513
514                                         if(distance>bestdistance)
515                                         {
516                                                 newgoal = head;
517                                                 bestdistance = distance;
518                                         }
519                                 }
520
521                                 if(newgoal)
522                                 {
523                                         self.ignoregoal = self.goalcurrent;
524                                         self.ignoregoaltime = time + autocvar_bot_ai_ignoregoal_timeout;
525                                         navigation_clearroute();
526                                         navigation_routetogoal(newgoal, self.origin);
527                                         self.aistatus &~= AI_STATUS_OUT_JUMPPAD;
528                                 }
529                         }
530                         else
531                                 return;
532                 }
533                 else
534                 {
535                         if(self.velocity_z>0)
536                         {
537                                 local float threshold;
538                                 threshold = maxspeed * 0.2;
539                                 if(fabs(self.velocity_x) < threshold  &&  fabs(self.velocity_y) < threshold)
540                                 {
541                                         dprint("Warning: ", self.netname, " got stuck on a jumppad, trying to get out of it now\n");
542                                         self.aistatus |= AI_STATUS_OUT_JUMPPAD;
543                                 }
544                                 return;
545                         }
546
547                         // Don't chase players while using a jump pad
548                         if(self.goalcurrent.classname=="player" || self.goalstack01.classname=="player")
549                                 return;
550                 }
551         }
552         else if(self.aistatus & AI_STATUS_OUT_JUMPPAD)
553                 self.aistatus &~= AI_STATUS_OUT_JUMPPAD;
554
555         // If there is a trigger_hurt right below try to use the jetpack or make a rocketjump
556         if(skill>6)
557         if not(self.flags & FL_ONGROUND)
558         {
559                 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 -65536', MOVE_NOMONSTERS, self);
560                 if(tracebox_hits_trigger_hurt(self.origin, self.mins, self.maxs, trace_endpos ))
561                 if(self.items & IT_JETPACK)
562                 {
563                         tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 65536', MOVE_NOMONSTERS, self);
564                         if(tracebox_hits_trigger_hurt(self.origin, self.mins, self.maxs, trace_endpos + '0 0 1' ))
565                         {
566                                 if(self.velocity_z<0)
567                                 {
568                                         self.BUTTON_HOOK = TRUE;
569                                 }
570                         }
571                         else
572                                 self.BUTTON_HOOK = TRUE;
573
574                         // If there is no goal try to move forward
575
576                         if(self.goalcurrent==world)
577                                 dir = v_forward;
578                         else
579                                 dir = normalize(( ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5 ) - self.origin);
580
581                         local vector xyvelocity = self.velocity; xyvelocity_z = 0;
582                         local float xyspeed = xyvelocity * dir;
583
584                         if(xyspeed < (maxspeed / 2))
585                         {
586                                 makevectors(self.v_angle_y * '0 1 0');
587                                 tracebox(self.origin, self.mins, self.maxs, self.origin + (dir * maxspeed * 3), MOVE_NOMONSTERS, self);
588                                 if(trace_fraction==1)
589                                 {
590                                         self.movement_x = dir * v_forward * maxspeed;
591                                         self.movement_y = dir * v_right * maxspeed;
592                                         if (skill < 10)
593                                                 havocbot_keyboard_movement(self.origin + dir * 100);
594                                 }
595                         }
596
597                         self.havocbot_blockhead = TRUE;
598
599                         return;
600                 }
601                 else if(self.health>autocvar_g_balance_rocketlauncher_damage*0.5)
602                 {
603                         if(self.velocity_z < 0)
604                         if(client_hasweapon(self, WEP_ROCKET_LAUNCHER, TRUE, FALSE))
605                         {
606                                 self.movement_x = maxspeed;
607
608                                 if(self.rocketjumptime)
609                                 {
610                                         if(time > self.rocketjumptime)
611                                         {
612                                                 self.BUTTON_ATCK2 = TRUE;
613                                                 self.rocketjumptime = 0;
614                                         }
615                                         return;
616                                 }
617
618                                 self.switchweapon = WEP_ROCKET_LAUNCHER;
619                                 self.v_angle_x = 90;
620                                 self.BUTTON_ATCK = TRUE;
621                                 self.rocketjumptime = time + autocvar_g_balance_rocketlauncher_detonatedelay;
622                                 return;
623                         }
624                 }
625                 else
626                 {
627                         // If there is no goal try to move forward
628                         if(self.goalcurrent==world)
629                                 self.movement_x = maxspeed;
630                 }
631         }
632
633         // If we are under water with no goals, swim up
634         if(self.waterlevel)
635         if(self.goalcurrent==world)
636         {
637                 dir = '0 0 0';
638                 if(self.waterlevel>WATERLEVEL_SWIMMING)
639                         dir_z = 1;
640                 else if(self.velocity_z >= 0 && !(self.waterlevel == WATERLEVEL_WETFEET && self.watertype == CONTENT_WATER))
641                         self.BUTTON_JUMP = TRUE;
642                 else
643                         self.BUTTON_JUMP = FALSE;
644                 makevectors(self.v_angle_y * '0 1 0');
645                 self.movement_x = dir * v_forward * maxspeed;
646                 self.movement_y = dir * v_right * maxspeed;
647                 self.movement_z = dir * v_up * maxspeed;
648         }
649
650         // if there is nowhere to go, exit
651         if (self.goalcurrent == world)
652                 return;
653
654         if (self.goalcurrent)
655                 navigation_poptouchedgoals();
656
657         // if ran out of goals try to use an alternative goal or get a new strategy asap
658         if(self.goalcurrent == world)
659         {
660                 self.bot_strategytime = 0;
661                 return;
662         }
663
664
665         if(autocvar_bot_debug_goalstack)
666                 debuggoalstack();
667
668         m1 = self.goalcurrent.origin + self.goalcurrent.mins;
669         m2 = self.goalcurrent.origin + self.goalcurrent.maxs;
670         destorg = self.origin;
671         destorg_x = bound(m1_x, destorg_x, m2_x);
672         destorg_y = bound(m1_y, destorg_y, m2_y);
673         destorg_z = bound(m1_z, destorg_z, m2_z);
674         diff = destorg - self.origin;
675         //dist = vlen(diff);
676         dir = normalize(diff);
677         flatdir = diff;flatdir_z = 0;
678         flatdir = normalize(flatdir);
679         gco = (self.goalcurrent.absmin + self.goalcurrent.absmax) * 0.5;
680
681         //if (self.bot_dodgevector_time < time)
682         {
683         //      self.bot_dodgevector_time = time + cvar("bot_ai_dodgeupdateinterval");
684         //      self.bot_dodgevector_jumpbutton = 1;
685                 evadeobstacle = '0 0 0';
686                 evadelava = '0 0 0';
687
688                 if (self.waterlevel)
689                 {
690                         if(self.waterlevel>WATERLEVEL_SWIMMING)
691                         {
692                         //      flatdir_z = 1;
693                                 self.aistatus |= AI_STATUS_OUT_WATER;
694                         }
695                         else
696                         {
697                                 if(self.velocity_z >= 0 && !(self.watertype == CONTENT_WATER && gco_z < self.origin_z) &&
698                                         ( !(self.waterlevel == WATERLEVEL_WETFEET && self.watertype == CONTENT_WATER) || self.aistatus & AI_STATUS_OUT_WATER))
699                                         self.BUTTON_JUMP = TRUE;
700                                 else
701                                         self.BUTTON_JUMP = FALSE;
702                         }
703                         dir = normalize(flatdir);
704                         makevectors(self.v_angle_y * '0 1 0');
705                 }
706                 else
707                 {
708                         if(self.aistatus & AI_STATUS_OUT_WATER)
709                                 self.aistatus &~= AI_STATUS_OUT_WATER;
710
711                         // jump if going toward an obstacle that doesn't look like stairs we
712                         // can walk up directly
713                         tracebox(self.origin, self.mins, self.maxs, self.origin + self.velocity * 0.2, FALSE, self);
714                         if (trace_fraction < 1)
715                         if (trace_plane_normal_z < 0.7)
716                         {
717                                 s = trace_fraction;
718                                 tracebox(self.origin + stepheightvec, self.mins, self.maxs, self.origin + self.velocity * 0.2 + stepheightvec, FALSE, self);
719                                 if (trace_fraction < s + 0.01)
720                                 if (trace_plane_normal_z < 0.7)
721                                 {
722                                         s = trace_fraction;
723                                         tracebox(self.origin + jumpstepheightvec, self.mins, self.maxs, self.origin + self.velocity * 0.2 + jumpstepheightvec, FALSE, self);
724                                         if (trace_fraction > s)
725                                                 self.BUTTON_JUMP = 1;
726                                 }
727                         }
728
729                         // avoiding dangers and obstacles
730                         local vector dst_ahead, dst_down;
731                         makevectors(self.v_angle_y * '0 1 0');
732                         dst_ahead = self.origin + self.view_ofs + (self.velocity * 0.4) + (v_forward * 32 * 3);
733                         dst_down = dst_ahead + '0 0 -1500';
734
735                         // Look ahead
736                         traceline(self.origin + self.view_ofs , dst_ahead, TRUE, world);
737
738                         // Check head-banging against walls
739                         if(vlen(self.origin + self.view_ofs - trace_endpos) < 25 && !(self.aistatus & AI_STATUS_OUT_WATER))
740                         {
741                                 self.BUTTON_JUMP = TRUE;
742                                 if(self.facingwalltime && time > self.facingwalltime)
743                                 {
744                                         self.ignoregoal = self.goalcurrent;
745                                         self.ignoregoaltime = time + autocvar_bot_ai_ignoregoal_timeout;
746                                         self.bot_strategytime = 0;
747                                         return;
748                                 }
749                                 else
750                                 {
751                                         self.facingwalltime = time + 0.05;
752                                 }
753                         }
754                         else
755                         {
756                                 self.facingwalltime = 0;
757
758                                 if(self.ignoregoal != world && time > self.ignoregoaltime)
759                                 {
760                                         self.ignoregoal = world;
761                                         self.ignoregoaltime = 0;
762                                 }
763                         }
764
765                         // Check for water/slime/lava and dangerous edges
766                         // (only when the bot is on the ground or jumping intentionally)
767                         self.aistatus &~= AI_STATUS_DANGER_AHEAD;
768
769                         if(trace_fraction == 1 && self.jumppadcount == 0)
770                         if(self.flags & FL_ONGROUND || self.aistatus & AI_STATUS_RUNNING || self.BUTTON_JUMP == TRUE)
771                         {
772                                 // Look downwards
773                                 traceline(dst_ahead , dst_down, TRUE, world);
774                         //      te_lightning2(world, self.origin, dst_ahead);   // Draw "ahead" look
775                         //      te_lightning2(world, dst_ahead, dst_down);              // Draw "downwards" look
776                                 if(trace_endpos_z < self.origin_z + self.mins_z)
777                                 {
778                                         s = pointcontents(trace_endpos + '0 0 1');
779                                         if (s != CONTENT_SOLID)
780                                         if (s == CONTENT_LAVA || s == CONTENT_SLIME)
781                                                 evadelava = normalize(self.velocity) * -1;
782                                         else if (s == CONTENT_SKY)
783                                                 evadeobstacle = normalize(self.velocity) * -1;
784                                         else if (!boxesoverlap(dst_ahead - self.view_ofs + self.mins, dst_ahead - self.view_ofs + self.maxs,
785                                                                 self.goalcurrent.absmin, self.goalcurrent.absmax))
786                                         {
787                                                 // if ain't a safe goal with "holes" (like the jumpad on soylent)
788                                                 // and there is a trigger_hurt below
789                                                 if(tracebox_hits_trigger_hurt(dst_ahead, self.mins, self.maxs, trace_endpos))
790                                                 {
791                                                         // Remove dangerous dynamic goals from stack
792                                                         if (self.goalcurrent.classname == "player" || self.goalcurrent.classname == "droppedweapon")
793                                                         {
794                                                                 navigation_poproute();
795                                                                 if(self.goalcurrent)
796                                                                         gco = (self.goalcurrent.absmin + self.goalcurrent.absmax) * 0.5;
797                                                         }
798                                                         // try to stop
799                                                         flatdir = '0 0 0';
800                                                         evadeobstacle = normalize(self.velocity) * -1;
801                                                 }
802                                         }
803                                 }
804                         }
805
806                         dir = flatdir;
807                         evadeobstacle_z = 0;
808                         evadelava_z = 0;
809                         makevectors(self.v_angle_y * '0 1 0');
810
811                         if(evadeobstacle!='0 0 0'||evadelava!='0 0 0')
812                                 self.aistatus |= AI_STATUS_DANGER_AHEAD;
813                 }
814
815                 dodge = havocbot_dodge();
816                 dodge = dodge * bound(0,0.5+(skill+self.bot_dodgeskill)*0.1,1);
817                 evadelava = evadelava * bound(1,3-(skill+self.bot_dodgeskill),3); //Noobs fear lava a lot and take more distance from it
818                 traceline(self.origin, ( ( self.enemy.absmin + self.enemy.absmax ) * 0.5 ), TRUE, world);
819                 if(trace_ent.classname == "player")
820                         dir = dir * bound(0,(skill+self.bot_dodgeskill)/7,1);
821
822                 dir = normalize(dir + dodge + evadeobstacle + evadelava);
823         //      self.bot_dodgevector = dir;
824         //      self.bot_dodgevector_jumpbutton = self.BUTTON_JUMP;
825         }
826
827         if(time < self.ladder_time)
828         {
829                 if(self.goalcurrent.origin_z + self.goalcurrent.mins_z > self.origin_z + self.mins_z)
830                 {
831                         if(self.origin_z + self.mins_z  < self.ladder_entity.origin_z + self.ladder_entity.maxs_z)
832                                 dir_z = 1;
833                 }
834                 else
835                 {
836                         if(self.origin_z + self.mins_z  > self.ladder_entity.origin_z + self.ladder_entity.mins_z)
837                                 dir_z = -1;
838                 }
839         }
840
841         //dir = self.bot_dodgevector;
842         //if (self.bot_dodgevector_jumpbutton)
843         //      self.BUTTON_JUMP = 1;
844         self.movement_x = dir * v_forward * maxspeed;
845         self.movement_y = dir * v_right * maxspeed;
846         self.movement_z = dir * v_up * maxspeed;
847
848         // Emulate keyboard interface
849         if (skill < 10)
850                 havocbot_keyboard_movement(destorg);
851
852         // Bunnyhop!
853 //      if(self.aistatus & AI_STATUS_ROAMING)
854         if(self.goalcurrent)
855         if(skill+self.bot_moveskill >= autocvar_bot_ai_bunnyhop_skilloffset)
856                 havocbot_bunnyhop(dir);
857
858         if ((dir * v_up) >= autocvar_sv_jumpvelocity*0.5 && (self.flags & FL_ONGROUND)) self.BUTTON_JUMP=1;
859         if (((dodge * v_up) > 0) && random()*frametime >= 0.2*bound(0,(10-skill-self.bot_dodgeskill)*0.1,1)) self.BUTTON_JUMP=TRUE;
860         if (((dodge * v_up) < 0) && random()*frametime >= 0.5*bound(0,(10-skill-self.bot_dodgeskill)*0.1,1)) self.havocbot_ducktime=time+0.3/bound(0.1,skill+self.bot_dodgeskill,10);
861 };
862
863 void havocbot_chooseenemy()
864 {
865         local entity head, best, head2;
866         local float rating, bestrating, i, f;
867         local vector eye, v;
868         if (autocvar_bot_nofire || IS_INDEPENDENT_PLAYER(self))
869         {
870                 self.enemy = world;
871                 return;
872         }
873         if (self.enemy)
874         {
875                 if (!bot_shouldattack(self.enemy))
876                 {
877                         // enemy died or something, find a new target
878                         self.enemy = world;
879                         self.havocbot_chooseenemy_finished = time;
880                 }
881                 else if (self.havocbot_stickenemy)
882                 {
883                         // tracking last chosen enemy
884                         // if enemy is visible
885                         // and not really really far away
886                         // and we're not severely injured
887                         // then keep tracking for a half second into the future
888                         traceline(self.origin+self.view_ofs, ( self.enemy.absmin + self.enemy.absmax ) * 0.5,FALSE,world);
889                         if (trace_ent == self.enemy || trace_fraction == 1)
890                         if (vlen((( self.enemy.absmin + self.enemy.absmax ) * 0.5) - self.origin) < 1000)
891                         if (self.health > 30)
892                         {
893                                 // remain tracking him for a shot while (case he went after a small corner or pilar
894                                 self.havocbot_chooseenemy_finished = time + autocvar_bot_ai_enemydetectioninterval;
895                                 return;
896                         }
897                         // enemy isn't visible, or is far away, or we're injured severely
898                         // so stop preferring this enemy
899                         // (it will still take a half second until a new one is chosen)
900                         self.havocbot_stickenemy = 0;
901                 }
902         }
903         if (time < self.havocbot_chooseenemy_finished)
904                 return;
905         self.havocbot_chooseenemy_finished = time + autocvar_bot_ai_enemydetectioninterval;
906         eye = self.origin + self.view_ofs;
907         best = world;
908         bestrating = 100000000;
909         head = head2 = findchainfloat(bot_attack, TRUE);
910
911         // Search for enemies, if no enemy can be seen directly try to look through transparent objects
912         for(;;)
913         {
914                 while (head)
915                 {
916                         v = (head.absmin + head.absmax) * 0.5;
917                         rating = vlen(v - eye);
918                         if (rating<autocvar_bot_ai_enemydetectionradius)
919                         if (bestrating > rating)
920                         if (bot_shouldattack(head))
921                         {
922                                 traceline(eye, v, TRUE, self);
923                                 if (trace_ent == head || trace_fraction >= 1)
924                                 {
925                                         best = head;
926                                         bestrating = rating;
927                                 }
928                         }
929                         head = head.chain;
930                 }
931
932                 // I want to do a second scan if no enemy was found or I don't have weapons
933                 // TODO: Perform the scan when using the rifle (requires changes on the rifle code)
934                 if(best || self.weapons) // || self.weapon == WEP_RIFLE
935                         break;
936                 if(i)
937                         break;
938
939                 // Set flags to see through transparent objects
940                 f = self.dphitcontentsmask;
941                 self.dphitcontentsmask = DPCONTENTS_OPAQUE;
942
943                 head = head2;
944                 ++i;
945         }
946
947         // Restore hit flags if needed
948         if(i)
949                 self.dphitcontentsmask = f;
950
951         self.enemy = best;
952         self.havocbot_stickenemy = TRUE;
953 };
954
955 float havocbot_chooseweapon_checkreload(float new_weapon)
956 {
957         // bots under this skill cannot find unloaded weapons to reload idly when not in combat,
958         // so skip this for them, or they'll never get to reload their weapons at all.
959         // this also allows bots under this skill to be more stupid, and reload more often during combat :)
960         if(skill < 5)
961                 return FALSE;
962
963         // if this weapon is scheduled for reloading, don't switch to it during combat
964         if (self.weapon_load[new_weapon] < 0)
965         {
966                 local float i, other_weapon_available;
967                 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
968                 {
969                         // if we are out of ammo for all other weapons, it's an emergency to switch to anything else
970                         if (weapon_action(i, WR_CHECKAMMO1) + weapon_action(i, WR_CHECKAMMO2))
971                                 other_weapon_available = TRUE;
972                 }
973                 if(other_weapon_available)
974                         return TRUE;
975         }
976
977         return FALSE;
978 }
979
980 void havocbot_chooseweapon()
981 {
982         local float i;
983
984         // ;)
985         if(g_weaponarena == WEPBIT_TUBA)
986         {
987                 self.switchweapon = WEP_TUBA;
988                 return;
989         }
990
991         // TODO: clean this up by moving it to weapon code
992         if(self.enemy==world)
993         {
994                 // If no weapon was chosen get the first available weapon
995                 if(self.weapon==0)
996                 for(i=WEP_LASER + 1; i < WEP_COUNT ; ++i)
997                 {
998                         if(client_hasweapon(self, i, TRUE, FALSE))
999                         {
1000                                 self.switchweapon = i;
1001                                 return;
1002                         }
1003                 }
1004                 return;
1005         }
1006
1007         // Do not change weapon during the next second after a combo
1008         i = time - self.lastcombotime;
1009         if(i < 1)
1010                 return;
1011
1012         local float w;
1013         local float distance; distance=bound(10,vlen(self.origin-self.enemy.origin)-200,10000);
1014
1015         // Should it do a weapon combo?
1016         local float af, ct, combo_time, combo;
1017
1018         af = ATTACK_FINISHED(self);
1019         ct = autocvar_bot_ai_weapon_combo_threshold;
1020
1021         // Bots with no skill will be 4 times more slower than "godlike" bots when doing weapon combos
1022         // Ideally this 4 should be calculated as longest_weapon_refire / bot_ai_weapon_combo_threshold
1023         combo_time = time + ct + (ct * ((-0.3*(skill+self.bot_weaponskill))+3));
1024
1025         combo = FALSE;
1026
1027         if(autocvar_bot_ai_weapon_combo)
1028         if(self.weapon == self.lastfiredweapon)
1029         if(af > combo_time)
1030         {
1031                 combo = TRUE;
1032                 self.lastcombotime = time;
1033         }
1034
1035         distance *= pow(2, self.bot_rangepreference);
1036
1037         // Custom weapon list based on distance to the enemy
1038         if(bot_custom_weapon){
1039
1040                 // Choose weapons for far distance
1041                 if ( distance > bot_distance_far ) {
1042                         for(i=0; i < WEP_COUNT && bot_weapons_far[i] != -1 ; ++i){
1043                                 w = bot_weapons_far[i];
1044                                 if ( client_hasweapon(self, w, TRUE, FALSE) )
1045                                 {
1046                                         if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
1047                                                 continue;
1048                                         self.switchweapon = w;
1049                                         return;
1050                                 }
1051                         }
1052                 }
1053
1054                 // Choose weapons for mid distance
1055                 if ( distance > bot_distance_close) {
1056                         for(i=0; i < WEP_COUNT && bot_weapons_mid[i] != -1 ; ++i){
1057                                 w = bot_weapons_mid[i];
1058                                 if ( client_hasweapon(self, w, TRUE, FALSE) )
1059                                 {
1060                                         if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
1061                                                 continue;
1062                                         self.switchweapon = w;
1063                                         return;
1064                                 }
1065                         }
1066                 }
1067
1068                 // Choose weapons for close distance
1069                 for(i=0; i < WEP_COUNT && bot_weapons_close[i] != -1 ; ++i){
1070                         w = bot_weapons_close[i];
1071                         if ( client_hasweapon(self, w, TRUE, FALSE) )
1072                         {
1073                                 if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
1074                                         continue;
1075                                 self.switchweapon = w;
1076                                 return;
1077                         }
1078                 }
1079         }
1080 };
1081
1082 void havocbot_aim()
1083 {
1084         local vector selfvel, enemyvel;
1085 //      if(self.flags & FL_INWATER)
1086 //              return;
1087         if (time < self.nextaim)
1088                 return;
1089         self.nextaim = time + 0.1;
1090         selfvel = self.velocity;
1091         if (!self.waterlevel)
1092                 selfvel_z = 0;
1093         if (self.enemy)
1094         {
1095                 enemyvel = self.enemy.velocity;
1096                 if (!self.enemy.waterlevel)
1097                         enemyvel_z = 0;
1098                 lag_additem(time + self.ping, 0, 0, self.enemy, self.origin, selfvel, (self.enemy.absmin + self.enemy.absmax) * 0.5, enemyvel);
1099         }
1100         else
1101                 lag_additem(time + self.ping, 0, 0, world, self.origin, selfvel, ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5, '0 0 0');
1102 };
1103
1104 float havocbot_moveto_refresh_route()
1105 {
1106         // Refresh path to goal if necessary
1107         entity wp;
1108         wp = self.havocbot_personal_waypoint;
1109         navigation_goalrating_start();
1110         navigation_routerating(wp, 10000, 10000);
1111         navigation_goalrating_end();
1112         return self.navigation_hasgoals;
1113 }
1114
1115 float havocbot_moveto(vector pos)
1116 {
1117         local entity wp;
1118
1119         if(self.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
1120         {
1121                 // Step 4: Move to waypoint
1122                 if(self.havocbot_personal_waypoint==world)
1123                 {
1124                         dprint("Error: ", self.netname, " trying to walk to a non existent personal waypoint\n");
1125                         self.aistatus &~= AI_STATUS_WAYPOINT_PERSONAL_GOING;
1126                         return CMD_STATUS_ERROR;
1127                 }
1128
1129                 if (!bot_strategytoken_taken)
1130                 if(self.havocbot_personal_waypoint_searchtime<time)
1131                 {
1132                         bot_strategytoken_taken = TRUE;
1133                         if(havocbot_moveto_refresh_route())
1134                         {
1135                                 dprint(self.netname, " walking to its personal waypoint (after ", ftos(self.havocbot_personal_waypoint_failcounter), " failed attempts)\n");
1136                                 self.havocbot_personal_waypoint_searchtime = time + 10;
1137                                 self.havocbot_personal_waypoint_failcounter = 0;
1138                         }
1139                         else
1140                         {
1141                                 self.havocbot_personal_waypoint_failcounter += 1;
1142                                 self.havocbot_personal_waypoint_searchtime = time + 2;
1143                                 if(self.havocbot_personal_waypoint_failcounter >= 30)
1144                                 {
1145                                         dprint("Warning: can't walk to the personal waypoint located at ", vtos(self.havocbot_personal_waypoint.origin),"\n");
1146                                         self.aistatus &~= AI_STATUS_WAYPOINT_PERSONAL_LINKING;
1147                                         remove(self.havocbot_personal_waypoint);
1148                                         return CMD_STATUS_ERROR;
1149                                 }
1150                                 else
1151                                         dprint(self.netname, " can't walk to its personal waypoint (after ", ftos(self.havocbot_personal_waypoint_failcounter), " failed attempts), trying later\n");
1152                         }
1153                 }
1154
1155                 if(autocvar_bot_debug_goalstack)
1156                         debuggoalstack();
1157
1158                 // Heading
1159                 local vector dir = ( ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5 ) - (self.origin + self.view_ofs);
1160                 dir_z = 0;
1161                 bot_aimdir(dir, -1);
1162
1163                 // Go!
1164                 havocbot_movetogoal();
1165
1166                 if(self.aistatus & AI_STATUS_WAYPOINT_PERSONAL_REACHED)
1167                 {
1168                         // Step 5: Waypoint reached
1169                         dprint(self.netname, "'s personal waypoint reached\n");
1170                         remove(self.havocbot_personal_waypoint);
1171                         self.aistatus &~= AI_STATUS_WAYPOINT_PERSONAL_REACHED;
1172                         return CMD_STATUS_FINISHED;
1173                 }
1174
1175                 return CMD_STATUS_EXECUTING;
1176         }
1177
1178         // Step 2: Linking waypoint
1179         if(self.aistatus & AI_STATUS_WAYPOINT_PERSONAL_LINKING)
1180         {
1181                 // Wait until it is linked
1182                 if(!self.havocbot_personal_waypoint.wplinked)
1183                 {
1184                         dprint(self.netname, " waiting for personal waypoint to be linked\n");
1185                         return CMD_STATUS_EXECUTING;
1186                 }
1187
1188                 self.havocbot_personal_waypoint_searchtime = time; // so we set the route next frame
1189                 self.aistatus &~= AI_STATUS_WAYPOINT_PERSONAL_LINKING;
1190                 self.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_GOING;
1191
1192                 // Step 3: Route to waypoint
1193                 dprint(self.netname, " walking to its personal waypoint\n");
1194
1195                 return CMD_STATUS_EXECUTING;
1196         }
1197
1198         // Step 1: Spawning waypoint
1199         wp = waypoint_spawnpersonal(pos);
1200         if(wp==world)
1201         {
1202                 dprint("Error: Can't spawn personal waypoint at ",vtos(pos),"\n");
1203                 return CMD_STATUS_ERROR;
1204         }
1205
1206         self.havocbot_personal_waypoint = wp;
1207         self.havocbot_personal_waypoint_failcounter = 0;
1208         self.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_LINKING;
1209
1210         // if pos is inside a teleport, then let's mark it as teleport waypoint
1211         entity head;
1212         for(head = world; (head = find(head, classname, "trigger_teleport")); )
1213         {
1214                 if(WarpZoneLib_BoxTouchesBrush(pos, pos, head, world))
1215                 {
1216                         wp.wpflags |= WAYPOINTFLAG_TELEPORT;
1217                         self.lastteleporttime = 0;
1218                 }
1219         }
1220
1221 /*
1222         if(wp.wpflags & WAYPOINTFLAG_TELEPORT)
1223                 print("routing to a teleporter\n");
1224         else
1225                 print("routing to a non-teleporter\n");
1226 */
1227
1228         return CMD_STATUS_EXECUTING;
1229 }
1230
1231 float havocbot_resetgoal()
1232 {
1233         navigation_clearroute();
1234         return CMD_STATUS_FINISHED;
1235 }
1236
1237 void havocbot_setupbot()
1238 {
1239         self.bot_ai = havocbot_ai;
1240         self.cmd_moveto = havocbot_moveto;
1241         self.cmd_resetgoal = havocbot_resetgoal;
1242
1243         havocbot_chooserole();
1244 }
1245
1246 vector havocbot_dodge()
1247 {
1248         // LordHavoc: disabled because this is too expensive
1249         return '0 0 0';
1250 #if 0
1251         local entity head;
1252         local vector dodge, v, n;
1253         local float danger, bestdanger, vl, d;
1254         dodge = '0 0 0';
1255         bestdanger = -20;
1256         // check for dangerous objects near bot or approaching bot
1257         head = findchainfloat(bot_dodge, TRUE);
1258         while(head)
1259         {
1260                 if (head.owner != self)
1261                 {
1262                         vl = vlen(head.velocity);
1263                         if (vl > autocvar_sv_maxspeed * 0.3)
1264                         {
1265                                 n = normalize(head.velocity);
1266                                 v = self.origin - head.origin;
1267                                 d = v * n;
1268                                 if (d > (0 - head.bot_dodgerating))
1269                                 if (d < (vl * 0.2 + head.bot_dodgerating))
1270                                 {
1271                                         // calculate direction and distance from the flight path, by removing the forward axis
1272                                         v = v - (n * (v * n));
1273                                         danger = head.bot_dodgerating - vlen(v);
1274                                         if (bestdanger < danger)
1275                                         {
1276                                                 bestdanger = danger;
1277                                                 // dodge to the side of the object
1278                                                 dodge = normalize(v);
1279                                         }
1280                                 }
1281                         }
1282                         else
1283                         {
1284                                 danger = head.bot_dodgerating - vlen(head.origin - self.origin);
1285                                 if (bestdanger < danger)
1286                                 {
1287                                         bestdanger = danger;
1288                                         dodge = normalize(self.origin - head.origin);
1289                                 }
1290                         }
1291                 }
1292                 head = head.chain;
1293         }
1294         return dodge;
1295 #endif
1296 };