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