]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/bot/havocbot/havocbot.qc
Merge remote branch 'origin/master' into fruitiex/animations
[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 waypoint
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 = findchain(classname, "waypoint"); head; head = head.chain)
501                                 {
502
503                                         distance = vlen(head.origin - self.origin);
504                                         if(distance>1000)
505                                                 continue;
506
507                                         traceline(self.origin + self.view_ofs , ( ( head.absmin + head.absmax ) * 0.5 ), TRUE, world);
508
509                                         if(trace_fraction<1)
510                                                 continue;
511
512                                         if(distance>bestdistance)
513                                         {
514                                                 newgoal = head;
515                                                 bestdistance = distance;
516                                         }
517                                 }
518
519                                 if(newgoal)
520                                 {
521                                         self.ignoregoal = self.goalcurrent;
522                                         self.ignoregoaltime = time + autocvar_bot_ai_ignoregoal_timeout;
523                                         navigation_clearroute();
524                                         navigation_routetogoal(newgoal, self.origin);
525                                         self.aistatus &~= AI_STATUS_OUT_JUMPPAD;
526                                 }
527                         }
528                         else
529                                 return;
530                 }
531                 else
532                 {
533                         if(self.velocity_z>0)
534                         {
535                                 float threshold, sxy;
536                                 vector velxy = self.velocity; velxy_z = 0;
537                                 sxy = vlen(velxy);
538                                 threshold = maxspeed * 0.2;
539                                 if(sxy < threshold)
540                                 {
541                                         dprint("Warning: ", self.netname, " got stuck on a jumppad (velocity in xy is ", ftos(sxy), "), 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, hf;
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         // Backup hit flags
912         hf = self.dphitcontentsmask;
913
914         // Search for enemies, if no enemy can be seen directly try to look through transparent objects
915
916         self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
917
918         for(;;)
919         {
920                 while (head)
921                 {
922                         v = (head.absmin + head.absmax) * 0.5;
923                         rating = vlen(v - eye);
924                         if (rating<autocvar_bot_ai_enemydetectionradius)
925                         if (bestrating > rating)
926                         if (bot_shouldattack(head))
927                         {
928                                 traceline(eye, v, TRUE, self);
929                                 if (trace_ent == head || trace_fraction >= 1)
930                                 {
931                                         best = head;
932                                         bestrating = rating;
933                                 }
934                         }
935                         head = head.chain;
936                 }
937
938                 // I want to do a second scan if no enemy was found or I don't have weapons
939                 // TODO: Perform the scan when using the rifle (requires changes on the rifle code)
940                 if(best || self.weapons) // || self.weapon == WEP_RIFLE
941                         break;
942                 if(i)
943                         break;
944
945                 // Set flags to see through transparent objects
946                 self.dphitcontentsmask |= DPCONTENTS_OPAQUE;
947
948                 head = head2;
949                 ++i;
950         }
951
952         // Restore hit flags
953         self.dphitcontentsmask = hf;
954
955         self.enemy = best;
956         self.havocbot_stickenemy = TRUE;
957 };
958
959 float havocbot_chooseweapon_checkreload(float new_weapon)
960 {
961         // bots under this skill cannot find unloaded weapons to reload idly when not in combat,
962         // so skip this for them, or they'll never get to reload their weapons at all.
963         // this also allows bots under this skill to be more stupid, and reload more often during combat :)
964         if(skill < 5)
965                 return FALSE;
966
967         // if this weapon is scheduled for reloading, don't switch to it during combat
968         if (self.weapon_load[new_weapon] < 0)
969         {
970                 local float i, other_weapon_available;
971                 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
972                 {
973                         // if we are out of ammo for all other weapons, it's an emergency to switch to anything else
974                         if (weapon_action(i, WR_CHECKAMMO1) + weapon_action(i, WR_CHECKAMMO2))
975                                 other_weapon_available = TRUE;
976                 }
977                 if(other_weapon_available)
978                         return TRUE;
979         }
980
981         return FALSE;
982 }
983
984 void havocbot_chooseweapon()
985 {
986         local float i;
987
988         // ;)
989         if(g_weaponarena == WEPBIT_TUBA)
990         {
991                 self.switchweapon = WEP_TUBA;
992                 return;
993         }
994
995         // TODO: clean this up by moving it to weapon code
996         if(self.enemy==world)
997         {
998                 // If no weapon was chosen get the first available weapon
999                 if(self.weapon==0)
1000                 for(i=WEP_LASER + 1; i < WEP_COUNT ; ++i)
1001                 {
1002                         if(client_hasweapon(self, i, TRUE, FALSE))
1003                         {
1004                                 self.switchweapon = i;
1005                                 return;
1006                         }
1007                 }
1008                 return;
1009         }
1010
1011         // Do not change weapon during the next second after a combo
1012         i = time - self.lastcombotime;
1013         if(i < 1)
1014                 return;
1015
1016         local float w;
1017         local float distance; distance=bound(10,vlen(self.origin-self.enemy.origin)-200,10000);
1018
1019         // Should it do a weapon combo?
1020         local float af, ct, combo_time, combo;
1021
1022         af = ATTACK_FINISHED(self);
1023         ct = autocvar_bot_ai_weapon_combo_threshold;
1024
1025         // Bots with no skill will be 4 times more slower than "godlike" bots when doing weapon combos
1026         // Ideally this 4 should be calculated as longest_weapon_refire / bot_ai_weapon_combo_threshold
1027         combo_time = time + ct + (ct * ((-0.3*(skill+self.bot_weaponskill))+3));
1028
1029         combo = FALSE;
1030
1031         if(autocvar_bot_ai_weapon_combo)
1032         if(self.weapon == self.lastfiredweapon)
1033         if(af > combo_time)
1034         {
1035                 combo = TRUE;
1036                 self.lastcombotime = time;
1037         }
1038
1039         distance *= pow(2, self.bot_rangepreference);
1040
1041         // Custom weapon list based on distance to the enemy
1042         if(bot_custom_weapon){
1043
1044                 // Choose weapons for far distance
1045                 if ( distance > bot_distance_far ) {
1046                         for(i=0; i < WEP_COUNT && bot_weapons_far[i] != -1 ; ++i){
1047                                 w = bot_weapons_far[i];
1048                                 if ( client_hasweapon(self, w, TRUE, FALSE) )
1049                                 {
1050                                         if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
1051                                                 continue;
1052                                         self.switchweapon = w;
1053                                         return;
1054                                 }
1055                         }
1056                 }
1057
1058                 // Choose weapons for mid distance
1059                 if ( distance > bot_distance_close) {
1060                         for(i=0; i < WEP_COUNT && bot_weapons_mid[i] != -1 ; ++i){
1061                                 w = bot_weapons_mid[i];
1062                                 if ( client_hasweapon(self, w, TRUE, FALSE) )
1063                                 {
1064                                         if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
1065                                                 continue;
1066                                         self.switchweapon = w;
1067                                         return;
1068                                 }
1069                         }
1070                 }
1071
1072                 // Choose weapons for close distance
1073                 for(i=0; i < WEP_COUNT && bot_weapons_close[i] != -1 ; ++i){
1074                         w = bot_weapons_close[i];
1075                         if ( client_hasweapon(self, w, TRUE, FALSE) )
1076                         {
1077                                 if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
1078                                         continue;
1079                                 self.switchweapon = w;
1080                                 return;
1081                         }
1082                 }
1083         }
1084 };
1085
1086 void havocbot_aim()
1087 {
1088         local vector selfvel, enemyvel;
1089 //      if(self.flags & FL_INWATER)
1090 //              return;
1091         if (time < self.nextaim)
1092                 return;
1093         self.nextaim = time + 0.1;
1094         selfvel = self.velocity;
1095         if (!self.waterlevel)
1096                 selfvel_z = 0;
1097         if (self.enemy)
1098         {
1099                 enemyvel = self.enemy.velocity;
1100                 if (!self.enemy.waterlevel)
1101                         enemyvel_z = 0;
1102                 lag_additem(time + self.ping, 0, 0, self.enemy, self.origin, selfvel, (self.enemy.absmin + self.enemy.absmax) * 0.5, enemyvel);
1103         }
1104         else
1105                 lag_additem(time + self.ping, 0, 0, world, self.origin, selfvel, ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5, '0 0 0');
1106 };
1107
1108 float havocbot_moveto_refresh_route()
1109 {
1110         // Refresh path to goal if necessary
1111         entity wp;
1112         wp = self.havocbot_personal_waypoint;
1113         navigation_goalrating_start();
1114         navigation_routerating(wp, 10000, 10000);
1115         navigation_goalrating_end();
1116         return self.navigation_hasgoals;
1117 }
1118
1119 float havocbot_moveto(vector pos)
1120 {
1121         local entity wp;
1122
1123         if(self.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
1124         {
1125                 // Step 4: Move to waypoint
1126                 if(self.havocbot_personal_waypoint==world)
1127                 {
1128                         dprint("Error: ", self.netname, " trying to walk to a non existent personal waypoint\n");
1129                         self.aistatus &~= AI_STATUS_WAYPOINT_PERSONAL_GOING;
1130                         return CMD_STATUS_ERROR;
1131                 }
1132
1133                 if (!bot_strategytoken_taken)
1134                 if(self.havocbot_personal_waypoint_searchtime<time)
1135                 {
1136                         bot_strategytoken_taken = TRUE;
1137                         if(havocbot_moveto_refresh_route())
1138                         {
1139                                 dprint(self.netname, " walking to its personal waypoint (after ", ftos(self.havocbot_personal_waypoint_failcounter), " failed attempts)\n");
1140                                 self.havocbot_personal_waypoint_searchtime = time + 10;
1141                                 self.havocbot_personal_waypoint_failcounter = 0;
1142                         }
1143                         else
1144                         {
1145                                 self.havocbot_personal_waypoint_failcounter += 1;
1146                                 self.havocbot_personal_waypoint_searchtime = time + 2;
1147                                 if(self.havocbot_personal_waypoint_failcounter >= 30)
1148                                 {
1149                                         dprint("Warning: can't walk to the personal waypoint located at ", vtos(self.havocbot_personal_waypoint.origin),"\n");
1150                                         self.aistatus &~= AI_STATUS_WAYPOINT_PERSONAL_LINKING;
1151                                         remove(self.havocbot_personal_waypoint);
1152                                         return CMD_STATUS_ERROR;
1153                                 }
1154                                 else
1155                                         dprint(self.netname, " can't walk to its personal waypoint (after ", ftos(self.havocbot_personal_waypoint_failcounter), " failed attempts), trying later\n");
1156                         }
1157                 }
1158
1159                 if(autocvar_bot_debug_goalstack)
1160                         debuggoalstack();
1161
1162                 // Heading
1163                 local vector dir = ( ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5 ) - (self.origin + self.view_ofs);
1164                 dir_z = 0;
1165                 bot_aimdir(dir, -1);
1166
1167                 // Go!
1168                 havocbot_movetogoal();
1169
1170                 if(self.aistatus & AI_STATUS_WAYPOINT_PERSONAL_REACHED)
1171                 {
1172                         // Step 5: Waypoint reached
1173                         dprint(self.netname, "'s personal waypoint reached\n");
1174                         remove(self.havocbot_personal_waypoint);
1175                         self.aistatus &~= AI_STATUS_WAYPOINT_PERSONAL_REACHED;
1176                         return CMD_STATUS_FINISHED;
1177                 }
1178
1179                 return CMD_STATUS_EXECUTING;
1180         }
1181
1182         // Step 2: Linking waypoint
1183         if(self.aistatus & AI_STATUS_WAYPOINT_PERSONAL_LINKING)
1184         {
1185                 // Wait until it is linked
1186                 if(!self.havocbot_personal_waypoint.wplinked)
1187                 {
1188                         dprint(self.netname, " waiting for personal waypoint to be linked\n");
1189                         return CMD_STATUS_EXECUTING;
1190                 }
1191
1192                 self.havocbot_personal_waypoint_searchtime = time; // so we set the route next frame
1193                 self.aistatus &~= AI_STATUS_WAYPOINT_PERSONAL_LINKING;
1194                 self.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_GOING;
1195
1196                 // Step 3: Route to waypoint
1197                 dprint(self.netname, " walking to its personal waypoint\n");
1198
1199                 return CMD_STATUS_EXECUTING;
1200         }
1201
1202         // Step 1: Spawning waypoint
1203         wp = waypoint_spawnpersonal(pos);
1204         if(wp==world)
1205         {
1206                 dprint("Error: Can't spawn personal waypoint at ",vtos(pos),"\n");
1207                 return CMD_STATUS_ERROR;
1208         }
1209
1210         self.havocbot_personal_waypoint = wp;
1211         self.havocbot_personal_waypoint_failcounter = 0;
1212         self.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_LINKING;
1213
1214         // if pos is inside a teleport, then let's mark it as teleport waypoint
1215         entity head;
1216         for(head = world; (head = find(head, classname, "trigger_teleport")); )
1217         {
1218                 if(WarpZoneLib_BoxTouchesBrush(pos, pos, head, world))
1219                 {
1220                         wp.wpflags |= WAYPOINTFLAG_TELEPORT;
1221                         self.lastteleporttime = 0;
1222                 }
1223         }
1224
1225 /*
1226         if(wp.wpflags & WAYPOINTFLAG_TELEPORT)
1227                 print("routing to a teleporter\n");
1228         else
1229                 print("routing to a non-teleporter\n");
1230 */
1231
1232         return CMD_STATUS_EXECUTING;
1233 }
1234
1235 float havocbot_resetgoal()
1236 {
1237         navigation_clearroute();
1238         return CMD_STATUS_FINISHED;
1239 }
1240
1241 void havocbot_setupbot()
1242 {
1243         self.bot_ai = havocbot_ai;
1244         self.cmd_moveto = havocbot_moveto;
1245         self.cmd_resetgoal = havocbot_resetgoal;
1246
1247         havocbot_chooserole();
1248 }
1249
1250 vector havocbot_dodge()
1251 {
1252         // LordHavoc: disabled because this is too expensive
1253         return '0 0 0';
1254 #if 0
1255         local entity head;
1256         local vector dodge, v, n;
1257         local float danger, bestdanger, vl, d;
1258         dodge = '0 0 0';
1259         bestdanger = -20;
1260         // check for dangerous objects near bot or approaching bot
1261         head = findchainfloat(bot_dodge, TRUE);
1262         while(head)
1263         {
1264                 if (head.owner != self)
1265                 {
1266                         vl = vlen(head.velocity);
1267                         if (vl > autocvar_sv_maxspeed * 0.3)
1268                         {
1269                                 n = normalize(head.velocity);
1270                                 v = self.origin - head.origin;
1271                                 d = v * n;
1272                                 if (d > (0 - head.bot_dodgerating))
1273                                 if (d < (vl * 0.2 + head.bot_dodgerating))
1274                                 {
1275                                         // calculate direction and distance from the flight path, by removing the forward axis
1276                                         v = v - (n * (v * n));
1277                                         danger = head.bot_dodgerating - vlen(v);
1278                                         if (bestdanger < danger)
1279                                         {
1280                                                 bestdanger = danger;
1281                                                 // dodge to the side of the object
1282                                                 dodge = normalize(v);
1283                                         }
1284                                 }
1285                         }
1286                         else
1287                         {
1288                                 danger = head.bot_dodgerating - vlen(head.origin - self.origin);
1289                                 if (bestdanger < danger)
1290                                 {
1291                                         bestdanger = danger;
1292                                         dodge = normalize(self.origin - head.origin);
1293                                 }
1294                         }
1295                 }
1296                 head = head.chain;
1297         }
1298         return dodge;
1299 #endif
1300 };