]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/bot/default/bot.qc
Merge branch 'master' into Mario/cts_respawn_clear
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / bot.qc
1 #include "bot.qh"
2
3 #include "cvars.qh"
4
5 #include "aim.qh"
6 #include "navigation.qh"
7 #include "scripting.qh"
8 #include "waypoints.qh"
9
10 #include "havocbot/havocbot.qh"
11 #include "havocbot/scripting.qh"
12
13 #include "../../teamplay.qh"
14
15 #include "../../antilag.qh"
16 #include "../../autocvars.qh"
17 #include "../../campaign.qh"
18 #include "../../client.qh"
19 #include "../../constants.qh"
20 #include "../../defs.qh"
21 #include "../../race.qh"
22 #include <common/t_items.qh>
23
24 #include "../../mutators/_mod.qh"
25
26 #include "../../weapons/accuracy.qh"
27
28 #include <common/physics/player.qh>
29 #include <common/constants.qh>
30 #include <common/net_linked.qh>
31 #include <common/mapinfo.qh>
32 #include <common/teams.qh>
33 #include <common/util.qh>
34
35 #include <server/scores_rules.qh>
36
37 #include <common/weapons/_all.qh>
38
39 #include <lib/csqcmodel/sv_model.qh>
40
41 #include <lib/warpzone/common.qh>
42 #include <lib/warpzone/util_server.qh>
43
44 entity bot_spawn()
45 {
46         entity bot = spawnclient();
47         if (bot)
48         {
49                 setItemGroupCount();
50                 currentbots = currentbots + 1;
51                 bot_setnameandstuff(bot);
52                 ClientConnect(bot);
53                 PutClientInServer(bot);
54         }
55         return bot;
56 }
57
58 void bot_think(entity this)
59 {
60         if (this.bot_nextthink > time)
61                 return;
62
63         this.flags &= ~FL_GODMODE;
64         if(autocvar_bot_god)
65                 this.flags |= FL_GODMODE;
66
67         this.bot_nextthink = max(time, this.bot_nextthink) + max(0.01, autocvar_bot_ai_thinkinterval * (0.5 ** this.bot_aiskill) * min(14 / (skill + 14), 1));
68
69         //if (this.bot_painintensity > 0)
70         //      this.bot_painintensity = this.bot_painintensity - (skill + 1) * 40 * frametime;
71
72         //this.bot_painintensity = this.bot_painintensity + this.bot_oldhealth - this.health;
73         //this.bot_painintensity = bound(0, this.bot_painintensity, 100);
74
75         if (!IS_PLAYER(this) || (autocvar_g_campaign && !campaign_bots_may_start))
76         {
77                 this.movement = '0 0 0';
78                 this.bot_nextthink = time + 0.5;
79                 return;
80         }
81
82         if (this.fixangle)
83         {
84                 this.v_angle = this.angles;
85                 this.v_angle_z = 0;
86                 this.fixangle = false;
87         }
88
89         this.dmg_take = 0;
90         this.dmg_save = 0;
91         this.dmg_inflictor = NULL;
92
93         // calculate an aiming latency based on the skill setting
94         // (simulated network latency + naturally delayed reflexes)
95         //this.ping = 0.7 - bound(0, 0.05 * skill, 0.5); // moved the reflexes to bot_aimdir (under the name 'think')
96         // minimum ping 20+10 random
97         this.ping = bound(0,0.07 - bound(0, (skill + this.bot_pingskill) * 0.005,0.05)+random()*0.01,0.65); // Now holds real lag to server, and higer skill players take a less laggy server
98         // skill 10 = ping 0.2 (adrenaline)
99         // skill 0 = ping 0.7 (slightly drunk)
100
101         // clear buttons
102         PHYS_INPUT_BUTTON_ATCK(this) = false;
103         PHYS_INPUT_BUTTON_JUMP(this) = false;
104         PHYS_INPUT_BUTTON_ATCK2(this) = false;
105         PHYS_INPUT_BUTTON_ZOOM(this) = false;
106         PHYS_INPUT_BUTTON_CROUCH(this) = false;
107         PHYS_INPUT_BUTTON_HOOK(this) = false;
108         PHYS_INPUT_BUTTON_INFO(this) = false;
109         PHYS_INPUT_BUTTON_DRAG(this) = false;
110         PHYS_INPUT_BUTTON_CHAT(this) = false;
111         PHYS_INPUT_BUTTON_USE(this) = false;
112
113         if (time < game_starttime)
114         {
115                 // block the bot during the countdown to game start
116                 this.movement = '0 0 0';
117                 this.bot_nextthink = game_starttime;
118                 return;
119         }
120
121         // if dead, just wait until we can respawn
122         if (IS_DEAD(this))
123         {
124                 this.movement = '0 0 0';
125                 if (this.deadflag == DEAD_DEAD)
126                 {
127                         PHYS_INPUT_BUTTON_JUMP(this) = true; // press jump to respawn
128                         this.bot_strategytime = 0;
129                 }
130         }
131         else if(this.aistatus & AI_STATUS_STUCK)
132                 navigation_unstuck(this);
133
134         // now call the current bot AI (havocbot for example)
135         this.bot_ai(this);
136 }
137
138 void bot_setnameandstuff(entity this)
139 {
140         string readfile, s;
141         float file, tokens, prio;
142
143         string bot_name, bot_model, bot_skin, bot_shirt, bot_pants;
144         string name, prefix, suffix;
145
146         if(autocvar_g_campaign)
147         {
148                 prefix = "";
149                 suffix = "";
150         }
151         else
152         {
153                 prefix = autocvar_bot_prefix;
154                 suffix = autocvar_bot_suffix;
155         }
156
157         file = fopen(autocvar_bot_config_file, FILE_READ);
158
159         if(file < 0)
160         {
161                 LOG_INFO(strcat("Error: Can not open the bot configuration file '",autocvar_bot_config_file,"'\n"));
162                 readfile = "";
163         }
164         else
165         {
166                 RandomSelection_Init();
167                 while((readfile = fgets(file)))
168                 {
169                         if(substring(readfile, 0, 2) == "//")
170                                 continue;
171                         if(substring(readfile, 0, 1) == "#")
172                                 continue;
173                         tokens = tokenizebyseparator(readfile, "\t");
174                         if(tokens == 0)
175                                 continue;
176                         s = argv(0);
177                         prio = 1;
178                         FOREACH_CLIENT(IS_BOT_CLIENT(it), LAMBDA(
179                                 if(s == it.cleanname)
180                                 {
181                                         prio = 0;
182                                         break;
183                                 }
184                         ));
185                         RandomSelection_AddString(readfile, 1, prio);
186                 }
187                 readfile = RandomSelection_chosen_string;
188                 fclose(file);
189         }
190
191         tokens = tokenizebyseparator(readfile, "\t");
192         if(argv(0) != "") bot_name = argv(0);
193         else bot_name = "Bot";
194
195         if(argv(1) != "") bot_model = argv(1);
196         else bot_model = "";
197
198         if(argv(2) != "") bot_skin = argv(2);
199         else bot_skin = "0";
200
201         if(argv(3) != "" && stof(argv(3)) >= 0) bot_shirt = argv(3);
202         else bot_shirt = ftos(floor(random() * 15));
203
204         if(argv(4) != "" && stof(argv(4)) >= 0) bot_pants = argv(4);
205         else bot_pants = ftos(floor(random() * 15));
206
207         this.bot_forced_team = stof(argv(5));
208
209         prio = 6;
210
211         #define READSKILL(f, w, r) MACRO_BEGIN { \
212                 if(argv(prio) != "") \
213                         this.f = stof(argv(prio)) * w; \
214                 else \
215                         this.f = (!autocvar_g_campaign) * (2 * random() - 1) * r * w; \
216                 prio++; \
217         } MACRO_END
218         //print(bot_name, ": ping=", argv(9), "\n");
219
220         READSKILL(havocbot_keyboardskill, 0.5, 0.5); // keyboard skill
221         READSKILL(bot_moveskill, 2, 0); // move skill
222         READSKILL(bot_dodgeskill, 2, 0); // dodge skill
223
224         READSKILL(bot_pingskill, 0.5, 0); // ping skill
225
226         READSKILL(bot_weaponskill, 2, 0); // weapon skill
227         READSKILL(bot_aggresskill, 1, 0); // aggre skill
228         READSKILL(bot_rangepreference, 1, 0); // read skill
229
230         READSKILL(bot_aimskill, 2, 0); // aim skill
231         READSKILL(bot_offsetskill, 2, 0.5); // offset skill
232         READSKILL(bot_mouseskill, 1, 0.5); // mouse skill
233
234         READSKILL(bot_thinkskill, 1, 0.5); // think skill
235         READSKILL(bot_aiskill, 2, 0); // "ai" skill
236
237         this.bot_config_loaded = true;
238
239         // this is really only a default, JoinBestTeam is called later
240         setcolor(this, stof(bot_shirt) * 16 + stof(bot_pants));
241         this.bot_preferredcolors = this.clientcolors;
242
243         // pick the name
244         if (autocvar_bot_usemodelnames)
245                 name = bot_model;
246         else
247                 name = bot_name;
248
249         // number bots with identical names
250         int j = 0;
251         FOREACH_CLIENT(IS_BOT_CLIENT(it), LAMBDA(
252                 if(it.cleanname == name)
253                         ++j;
254         ));
255         if (j)
256                 this.netname = this.netname_freeme = strzone(strcat(prefix, name, "(", ftos(j), ")", suffix));
257         else
258                 this.netname = this.netname_freeme = strzone(strcat(prefix, name, suffix));
259
260         this.cleanname = strzone(name);
261
262         // pick the model and skin
263         if(substring(bot_model, -4, 1) != ".")
264                 bot_model = strcat(bot_model, ".iqm");
265         this.playermodel = this.playermodel_freeme = strzone(strcat("models/player/", bot_model));
266         this.playerskin = this.playerskin_freeme = strzone(bot_skin);
267
268         this.cvar_cl_accuracy_data_share = 1;  // share the bots weapon accuracy data with the NULL
269         this.cvar_cl_accuracy_data_receive = 0;  // don't receive any weapon accuracy data
270 }
271
272 void bot_custom_weapon_priority_setup()
273 {
274         float tokens, i, w;
275
276         bot_custom_weapon = false;
277
278         if(     autocvar_bot_ai_custom_weapon_priority_far == "" ||
279                 autocvar_bot_ai_custom_weapon_priority_mid == "" ||
280                 autocvar_bot_ai_custom_weapon_priority_close == "" ||
281                 autocvar_bot_ai_custom_weapon_priority_distances == ""
282         )
283                 return;
284
285         // Parse distances
286         tokens = tokenizebyseparator(autocvar_bot_ai_custom_weapon_priority_distances," ");
287
288         if (tokens!=2)
289                 return;
290
291         bot_distance_far = stof(argv(0));
292         bot_distance_close = stof(argv(1));
293
294         if(bot_distance_far < bot_distance_close){
295                 bot_distance_far = stof(argv(1));
296                 bot_distance_close = stof(argv(0));
297         }
298
299         // Initialize list of weapons
300         bot_weapons_far[0] = -1;
301         bot_weapons_mid[0] = -1;
302         bot_weapons_close[0] = -1;
303
304         // Parse far distance weapon priorities
305         tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_far)," ");
306
307         int c = 0;
308         for(i=0; i < tokens && c < Weapons_COUNT; ++i){
309                 w = stof(argv(i));
310                 if ( w >= WEP_FIRST && w <= WEP_LAST) {
311                         bot_weapons_far[c] = w;
312                         ++c;
313                 }
314         }
315         if(c < Weapons_COUNT)
316                 bot_weapons_far[c] = -1;
317
318         // Parse mid distance weapon priorities
319         tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_mid)," ");
320
321         c = 0;
322         for(i=0; i < tokens && c < Weapons_COUNT; ++i){
323                 w = stof(argv(i));
324                 if ( w >= WEP_FIRST && w <= WEP_LAST) {
325                         bot_weapons_mid[c] = w;
326                         ++c;
327                 }
328         }
329         if(c < Weapons_COUNT)
330                 bot_weapons_mid[c] = -1;
331
332         // Parse close distance weapon priorities
333         tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_close)," ");
334
335         c = 0;
336         for(i=0; i < tokens && i < Weapons_COUNT; ++i){
337                 w = stof(argv(i));
338                 if ( w >= WEP_FIRST && w <= WEP_LAST) {
339                         bot_weapons_close[c] = w;
340                         ++c;
341                 }
342         }
343         if(c < Weapons_COUNT)
344                 bot_weapons_close[c] = -1;
345
346         bot_custom_weapon = true;
347 }
348
349 void bot_endgame()
350 {
351         bot_relinkplayerlist();
352         entity e = bot_list;
353         while (e)
354         {
355                 setcolor(e, e.bot_preferredcolors);
356                 e = e.nextbot;
357         }
358         // if dynamic waypoints are ever implemented, save them here
359 }
360
361 void bot_relinkplayerlist()
362 {
363         player_count = 0;
364         currentbots = 0;
365         bot_list = NULL;
366
367         entity prevbot = NULL;
368         FOREACH_CLIENT(true,
369         {
370                 ++player_count;
371
372                 if(IS_BOT_CLIENT(it))
373                 {
374                         if(prevbot)
375                                 prevbot.nextbot = it;
376                         else
377                                 bot_list = it;
378                         prevbot = it;
379                         ++currentbots;
380                 }
381         });
382         if(prevbot)
383                 prevbot.nextbot = NULL;
384         LOG_TRACE("relink: ", ftos(currentbots), " bots seen.");
385         bot_strategytoken = bot_list;
386         bot_strategytoken_taken = true;
387 }
388
389 void bot_clientdisconnect(entity this)
390 {
391         if (!IS_BOT_CLIENT(this))
392                 return;
393         bot_clearqueue(this);
394         if(this.cleanname)
395                 strunzone(this.cleanname);
396         if(this.netname_freeme)
397                 strunzone(this.netname_freeme);
398         if(this.playermodel_freeme)
399                 strunzone(this.playermodel_freeme);
400         if(this.playerskin_freeme)
401                 strunzone(this.playerskin_freeme);
402         this.cleanname = string_null;
403         this.netname_freeme = string_null;
404         this.playermodel_freeme = string_null;
405         this.playerskin_freeme = string_null;
406         if(this.bot_cmd_current)
407                 delete(this.bot_cmd_current);
408         if(bot_waypoint_queue_owner == this)
409                 bot_waypoint_queue_owner = NULL;
410 }
411
412 void bot_clientconnect(entity this)
413 {
414         if (!IS_BOT_CLIENT(this)) return;
415         this.bot_preferredcolors = this.clientcolors;
416         this.bot_nextthink = time - random();
417         this.lag_func = bot_lagfunc;
418         this.isbot = true;
419         this.createdtime = this.bot_nextthink;
420
421         if(!this.bot_config_loaded) // This is needed so team overrider doesn't break between matches
422                 bot_setnameandstuff(this);
423
424         if(this.bot_forced_team==1)
425                 this.team = NUM_TEAM_1;
426         else if(this.bot_forced_team==2)
427                 this.team = NUM_TEAM_2;
428         else if(this.bot_forced_team==3)
429                 this.team = NUM_TEAM_3;
430         else if(this.bot_forced_team==4)
431                 this.team = NUM_TEAM_4;
432         else
433                 JoinBestTeam(this, false, true);
434
435         havocbot_setupbot(this);
436 }
437
438 void bot_removefromlargestteam()
439 {
440         CheckAllowedTeams(NULL);
441         GetTeamCounts(NULL);
442
443         entity best = NULL;
444         float besttime = 0;
445         int bestcount = 0;
446
447         int bcount = 0;
448         FOREACH_CLIENT(it.isbot,
449         {
450                 ++bcount;
451
452                 if(!best)
453                 {
454                         best = it;
455                         besttime = it.createdtime;
456                 }
457
458                 int thiscount = 0;
459
460                 switch(it.team)
461                 {
462                         case NUM_TEAM_1: thiscount = c1; break;
463                         case NUM_TEAM_2: thiscount = c2; break;
464                         case NUM_TEAM_3: thiscount = c3; break;
465                         case NUM_TEAM_4: thiscount = c4; break;
466                 }
467
468                 if(thiscount > bestcount)
469                 {
470                         bestcount = thiscount;
471                         besttime = it.createdtime;
472                         best = it;
473                 }
474                 else if(thiscount == bestcount && besttime < it.createdtime)
475                 {
476                         besttime = it.createdtime;
477                         best = it;
478                 }
479         });
480         if(!bcount)
481                 return; // no bots to remove
482         currentbots = currentbots - 1;
483         dropclient(best);
484 }
485
486 void bot_removenewest()
487 {
488         if(teamplay)
489         {
490                 bot_removefromlargestteam();
491                 return;
492         }
493
494         float besttime = 0;
495         entity best = NULL;
496         int bcount = 0;
497
498         FOREACH_CLIENT(it.isbot,
499         {
500                 ++bcount;
501
502                 if(!best)
503                 {
504                         best = it;
505                         besttime = it.createdtime;
506                 }
507
508                 if(besttime < it.createdtime)
509                 {
510                         besttime = it.createdtime;
511                         best = it;
512                 }
513         });
514
515         if(!bcount)
516                 return; // no bots to remove
517
518         currentbots = currentbots - 1;
519         dropclient(best);
520 }
521
522 void autoskill(float factor)
523 {
524         float bestbot;
525         float bestplayer;
526
527         bestbot = -1;
528         bestplayer = -1;
529         FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
530                 if(IS_REAL_CLIENT(it))
531                         bestplayer = max(bestplayer, it.totalfrags - it.totalfrags_lastcheck);
532                 else
533                         bestbot = max(bestbot, it.totalfrags - it.totalfrags_lastcheck);
534         ));
535
536         LOG_TRACE("autoskill: best player got ", ftos(bestplayer), ", ");
537         LOG_TRACE("best bot got ", ftos(bestbot), "; ");
538         if(bestbot < 0 || bestplayer < 0)
539         {
540                 LOG_TRACE("not doing anything");
541                 // don't return, let it reset all counters below
542         }
543         else if(bestbot <= bestplayer * factor - 2)
544         {
545                 if(autocvar_skill < 17)
546                 {
547                         LOG_TRACE("2 frags difference, increasing skill");
548                         cvar_set("skill", ftos(autocvar_skill + 1));
549                         bprint("^2SKILL UP!^7 Now at level ", ftos(autocvar_skill), "\n");
550                 }
551         }
552         else if(bestbot >= bestplayer * factor + 2)
553         {
554                 if(autocvar_skill > 0)
555                 {
556                         LOG_TRACE("2 frags difference, decreasing skill");
557                         cvar_set("skill", ftos(autocvar_skill - 1));
558                         bprint("^1SKILL DOWN!^7 Now at level ", ftos(autocvar_skill), "\n");
559                 }
560         }
561         else
562         {
563                 LOG_TRACE("not doing anything");
564                 return;
565                 // don't reset counters, wait for them to accumulate
566         }
567
568         FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(it.totalfrags_lastcheck = it.totalfrags));
569 }
570
571 void bot_calculate_stepheightvec()
572 {
573         stepheightvec = autocvar_sv_stepheight * '0 0 1';
574         jumpstepheightvec = stepheightvec +
575                 ((autocvar_sv_jumpvelocity * autocvar_sv_jumpvelocity) / (2 * autocvar_sv_gravity)) * '0 0 0.85';
576                 // 0.75 factor is for safety to make the jumps easy
577 }
578
579 float bot_fixcount()
580 {
581         int activerealplayers = 0;
582         int realplayers = 0;
583         if (MUTATOR_CALLHOOK(Bot_FixCount, activerealplayers, realplayers)) {
584                 activerealplayers = M_ARGV(0, int);
585                 realplayers = M_ARGV(1, int);
586         } else {
587                 FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
588                         if(IS_PLAYER(it))
589                                 ++activerealplayers;
590                         ++realplayers;
591                 ));
592         }
593
594         int bots;
595         // add/remove bots if needed to make sure there are at least
596         // minplayers+bot_number, or remove all bots if no one is playing
597         // But don't remove bots immediately on level change, as the real players
598         // usually haven't rejoined yet
599         bots_would_leave = false;
600         if (teamplay && autocvar_bot_vs_human && AvailableTeams() == 2)
601                 bots = min(ceil(fabs(autocvar_bot_vs_human) * activerealplayers), maxclients - realplayers);
602         else if ((realplayers || autocvar_bot_join_empty || (currentbots > 0 && time < 5)))
603         {
604                 float realminplayers, minplayers;
605                 realminplayers = autocvar_minplayers;
606                 minplayers = max(0, floor(realminplayers));
607
608                 float realminbots, minbots;
609                 realminbots = autocvar_bot_number;
610                 minbots = max(0, floor(realminbots));
611
612                 bots = min(max(minbots, minplayers - activerealplayers), maxclients - realplayers);
613                 if(bots > minbots)
614                         bots_would_leave = true;
615         }
616         else
617         {
618                 // if there are no players, remove bots
619                 bots = 0;
620         }
621
622         // only add one bot per frame to avoid utter chaos
623         if(time > botframe_nextthink)
624         {
625                 //dprint(ftos(bots), " ? ", ftos(currentbots), "\n");
626                 while (currentbots < bots)
627                 {
628                         if (bot_spawn() == NULL)
629                         {
630                                 bprint("Can not add bot, server full.\n");
631                                 return false;
632                         }
633                 }
634                 while (currentbots > bots)
635                         bot_removenewest();
636         }
637
638         return true;
639 }
640
641 void bot_remove_from_bot_list(entity this)
642 {
643         entity e = bot_list;
644         entity prev_bot = NULL;
645         while (e)
646         {
647                 if(e == this)
648                 {
649                         if(!prev_bot)
650                                 bot_list = this.nextbot;
651                         else
652                                 prev_bot.nextbot = this.nextbot;
653                         if(bot_strategytoken == this)
654                         {
655                                 bot_strategytoken = this.nextbot;
656                                 bot_strategytoken_taken = true;
657                         }
658                         this.nextbot = NULL;
659                         break;
660                 }
661                 prev_bot = e;
662                 e = e.nextbot;
663         }
664 }
665
666 void bot_clear(entity this)
667 {
668         bot_remove_from_bot_list(this);
669         if(bot_waypoint_queue_owner == this)
670                 bot_waypoint_queue_owner = NULL;
671         this.aistatus &= ~AI_STATUS_STUCK; // otherwise bot_waypoint_queue_owner will be set again to this by navigation_unstuck
672 }
673
674 void bot_serverframe()
675 {
676         if (game_stopped)
677                 return;
678
679         if (time < 2)
680                 return;
681
682         bot_calculate_stepheightvec();
683         bot_navigation_movemode = ((autocvar_bot_navigation_ignoreplayers) ? MOVE_NOMONSTERS : MOVE_NORMAL);
684
685         if(time > autoskill_nextthink)
686         {
687                 float a;
688                 a = autocvar_skill_auto;
689                 if(a)
690                         autoskill(a);
691                 autoskill_nextthink = time + 5;
692         }
693
694         if(time > botframe_nextthink)
695         {
696                 if(!bot_fixcount())
697                         botframe_nextthink = time + 10;
698         }
699
700         bot_ignore_bots = autocvar_bot_ignore_bots;
701
702         if(botframe_spawnedwaypoints)
703         {
704                 if(autocvar_waypoint_benchmark)
705                         localcmd("quit\n");
706         }
707
708         if (currentbots > 0 || autocvar_g_waypointeditor || autocvar_g_waypointeditor_auto)
709         if (botframe_spawnedwaypoints)
710         {
711                 if(botframe_cachedwaypointlinks)
712                 {
713                         if(!botframe_loadedforcedlinks)
714                                 waypoint_load_links_hardwired();
715                 }
716                 else
717                 {
718                         // TODO: Make this check cleaner
719                         IL_EACH(g_waypoints, time - it.nextthink > 10,
720                         {
721                                 waypoint_save_links();
722                                 break;
723                         });
724                 }
725         }
726         else
727         {
728                 botframe_spawnedwaypoints = true;
729                 waypoint_loadall();
730                 if(!waypoint_load_links())
731                         waypoint_schedulerelinkall();
732         }
733
734         if (bot_list)
735         {
736                 // cycle the goal token from one bot to the next each frame
737                 // (this prevents them from all doing spawnfunc_waypoint searches on the same
738                 //  frame, which causes choppy framerates)
739                 if (bot_strategytoken_taken)
740                 {
741                         bot_strategytoken_taken = false;
742                         if (bot_strategytoken)
743                                 bot_strategytoken = bot_strategytoken.nextbot;
744                         if (!bot_strategytoken)
745                                 bot_strategytoken = bot_list;
746                 }
747
748                 if (botframe_nextdangertime < time)
749                 {
750                         float interval;
751                         interval = autocvar_bot_ai_dangerdetectioninterval;
752                         if (botframe_nextdangertime < time - interval * 1.5)
753                                 botframe_nextdangertime = time;
754                         botframe_nextdangertime = botframe_nextdangertime + interval;
755                         botframe_updatedangerousobjects(autocvar_bot_ai_dangerdetectionupdates);
756                 }
757         }
758
759         if (autocvar_g_waypointeditor)
760                 botframe_showwaypointlinks();
761
762         if (autocvar_g_waypointeditor_auto)
763                 botframe_autowaypoints();
764
765         if(time > bot_cvar_nextthink)
766         {
767                 if(currentbots>0)
768                         bot_custom_weapon_priority_setup();
769                 bot_cvar_nextthink = time + 5;
770         }
771 }