]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/bot/default/bot.qc
318422153bb3423478e9f8dc980a0fea24daf5e4
[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 * pow(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                         {
378                                 bot_list = it;
379                                 bot_list.nextbot = NULL;
380                         }
381                         prevbot = it;
382                         ++currentbots;
383                 }
384         });
385         LOG_TRACE("relink: ", ftos(currentbots), " bots seen.");
386         bot_strategytoken = bot_list;
387         bot_strategytoken_taken = true;
388 }
389
390 void bot_clientdisconnect(entity this)
391 {
392         if (!IS_BOT_CLIENT(this))
393                 return;
394         bot_clearqueue(this);
395         if(this.cleanname)
396                 strunzone(this.cleanname);
397         if(this.netname_freeme)
398                 strunzone(this.netname_freeme);
399         if(this.playermodel_freeme)
400                 strunzone(this.playermodel_freeme);
401         if(this.playerskin_freeme)
402                 strunzone(this.playerskin_freeme);
403         this.cleanname = string_null;
404         this.netname_freeme = string_null;
405         this.playermodel_freeme = string_null;
406         this.playerskin_freeme = string_null;
407         if(this.bot_cmd_current)
408                 delete(this.bot_cmd_current);
409         if(bot_waypoint_queue_owner == this)
410                 bot_waypoint_queue_owner = NULL;
411 }
412
413 void bot_clientconnect(entity this)
414 {
415         if (!IS_BOT_CLIENT(this)) return;
416         this.bot_preferredcolors = this.clientcolors;
417         this.bot_nextthink = time - random();
418         this.lag_func = bot_lagfunc;
419         this.isbot = true;
420         this.createdtime = this.bot_nextthink;
421
422         if(!this.bot_config_loaded) // This is needed so team overrider doesn't break between matches
423                 bot_setnameandstuff(this);
424
425         if(this.bot_forced_team==1)
426                 this.team = NUM_TEAM_1;
427         else if(this.bot_forced_team==2)
428                 this.team = NUM_TEAM_2;
429         else if(this.bot_forced_team==3)
430                 this.team = NUM_TEAM_3;
431         else if(this.bot_forced_team==4)
432                 this.team = NUM_TEAM_4;
433         else
434                 JoinBestTeam(this, false, true);
435
436         havocbot_setupbot(this);
437 }
438
439 void bot_removefromlargestteam()
440 {
441         CheckAllowedTeams(NULL);
442         GetTeamCounts(NULL);
443
444         entity best = NULL;
445         float besttime = 0;
446         int bestcount = 0;
447
448         int bcount = 0;
449         FOREACH_CLIENT(it.isbot,
450         {
451                 ++bcount;
452
453                 if(!best)
454                 {
455                         best = it;
456                         besttime = it.createdtime;
457                 }
458
459                 int thiscount = 0;
460
461                 switch(it.team)
462                 {
463                         case NUM_TEAM_1: thiscount = c1; break;
464                         case NUM_TEAM_2: thiscount = c2; break;
465                         case NUM_TEAM_3: thiscount = c3; break;
466                         case NUM_TEAM_4: thiscount = c4; break;
467                 }
468
469                 if(thiscount > bestcount)
470                 {
471                         bestcount = thiscount;
472                         besttime = it.createdtime;
473                         best = it;
474                 }
475                 else if(thiscount == bestcount && besttime < it.createdtime)
476                 {
477                         besttime = it.createdtime;
478                         best = it;
479                 }
480         });
481         if(!bcount)
482                 return; // no bots to remove
483         currentbots = currentbots - 1;
484         dropclient(best);
485 }
486
487 void bot_removenewest()
488 {
489         if(teamplay)
490         {
491                 bot_removefromlargestteam();
492                 return;
493         }
494
495         float besttime = 0;
496         entity best = NULL;
497         int bcount = 0;
498
499         FOREACH_CLIENT(it.isbot,
500         {
501                 ++bcount;
502
503                 if(!best)
504                 {
505                         best = it;
506                         besttime = it.createdtime;
507                 }
508
509                 if(besttime < it.createdtime)
510                 {
511                         besttime = it.createdtime;
512                         best = it;
513                 }
514         });
515
516         if(!bcount)
517                 return; // no bots to remove
518
519         currentbots = currentbots - 1;
520         dropclient(best);
521 }
522
523 void autoskill(float factor)
524 {
525         float bestbot;
526         float bestplayer;
527
528         bestbot = -1;
529         bestplayer = -1;
530         FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
531                 if(IS_REAL_CLIENT(it))
532                         bestplayer = max(bestplayer, it.totalfrags - it.totalfrags_lastcheck);
533                 else
534                         bestbot = max(bestbot, it.totalfrags - it.totalfrags_lastcheck);
535         ));
536
537         LOG_TRACE("autoskill: best player got ", ftos(bestplayer), ", ");
538         LOG_TRACE("best bot got ", ftos(bestbot), "; ");
539         if(bestbot < 0 || bestplayer < 0)
540         {
541                 LOG_TRACE("not doing anything");
542                 // don't return, let it reset all counters below
543         }
544         else if(bestbot <= bestplayer * factor - 2)
545         {
546                 if(autocvar_skill < 17)
547                 {
548                         LOG_TRACE("2 frags difference, increasing skill");
549                         cvar_set("skill", ftos(autocvar_skill + 1));
550                         bprint("^2SKILL UP!^7 Now at level ", ftos(autocvar_skill), "\n");
551                 }
552         }
553         else if(bestbot >= bestplayer * factor + 2)
554         {
555                 if(autocvar_skill > 0)
556                 {
557                         LOG_TRACE("2 frags difference, decreasing skill");
558                         cvar_set("skill", ftos(autocvar_skill - 1));
559                         bprint("^1SKILL DOWN!^7 Now at level ", ftos(autocvar_skill), "\n");
560                 }
561         }
562         else
563         {
564                 LOG_TRACE("not doing anything");
565                 return;
566                 // don't reset counters, wait for them to accumulate
567         }
568
569         FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(it.totalfrags_lastcheck = it.totalfrags));
570 }
571
572 void bot_calculate_stepheightvec()
573 {
574         stepheightvec = autocvar_sv_stepheight * '0 0 1';
575         jumpstepheightvec = stepheightvec +
576                 ((autocvar_sv_jumpvelocity * autocvar_sv_jumpvelocity) / (2 * autocvar_sv_gravity)) * '0 0 0.85';
577                 // 0.75 factor is for safety to make the jumps easy
578 }
579
580 float bot_fixcount()
581 {
582         int activerealplayers = 0;
583         int realplayers = 0;
584         if (MUTATOR_CALLHOOK(Bot_FixCount, activerealplayers, realplayers)) {
585                 activerealplayers = M_ARGV(0, int);
586                 realplayers = M_ARGV(1, int);
587         } else {
588                 FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
589                         if(IS_PLAYER(it))
590                                 ++activerealplayers;
591                         ++realplayers;
592                 ));
593         }
594
595         int bots;
596         // add/remove bots if needed to make sure there are at least
597         // minplayers+bot_number, or remove all bots if no one is playing
598         // But don't remove bots immediately on level change, as the real players
599         // usually haven't rejoined yet
600         bots_would_leave = false;
601         if (teamplay && autocvar_bot_vs_human && AvailableTeams() == 2)
602                 bots = min(ceil(fabs(autocvar_bot_vs_human) * activerealplayers), maxclients - realplayers);
603         else if ((realplayers || autocvar_bot_join_empty || (currentbots > 0 && time < 5)))
604         {
605                 float realminplayers, minplayers;
606                 realminplayers = autocvar_minplayers;
607                 minplayers = max(0, floor(realminplayers));
608
609                 float realminbots, minbots;
610                 realminbots = autocvar_bot_number;
611                 minbots = max(0, floor(realminbots));
612
613                 bots = min(max(minbots, minplayers - activerealplayers), maxclients - realplayers);
614                 if(bots > minbots)
615                         bots_would_leave = true;
616         }
617         else
618         {
619                 // if there are no players, remove bots
620                 bots = 0;
621         }
622
623         // only add one bot per frame to avoid utter chaos
624         if(time > botframe_nextthink)
625         {
626                 //dprint(ftos(bots), " ? ", ftos(currentbots), "\n");
627                 while (currentbots < bots)
628                 {
629                         if (bot_spawn() == NULL)
630                         {
631                                 bprint("Can not add bot, server full.\n");
632                                 return false;
633                         }
634                 }
635                 while (currentbots > bots)
636                         bot_removenewest();
637         }
638
639         return true;
640 }
641
642 void bot_remove_from_bot_list(entity this)
643 {
644         entity e = bot_list;
645         entity prev_bot = NULL;
646         while (e)
647         {
648                 if(e == this)
649                 {
650                         if(!prev_bot)
651                                 bot_list = this.nextbot;
652                         else
653                                 prev_bot.nextbot = this.nextbot;
654                         if(bot_strategytoken == this)
655                         {
656                                 bot_strategytoken = this.nextbot;
657                                 bot_strategytoken_taken = true;
658                         }
659                         this.nextbot = NULL;
660                         break;
661                 }
662                 prev_bot = e;
663                 e = e.nextbot;
664         }
665 }
666
667 void bot_clear(entity this)
668 {
669         bot_remove_from_bot_list(this);
670         if(bot_waypoint_queue_owner == this)
671                 bot_waypoint_queue_owner = NULL;
672         this.aistatus &= ~AI_STATUS_STUCK; // otherwise bot_waypoint_queue_owner will be set again to this by navigation_unstuck
673 }
674
675 void bot_serverframe()
676 {
677         if (game_stopped)
678                 return;
679
680         if (time < 2)
681                 return;
682
683         bot_calculate_stepheightvec();
684         bot_navigation_movemode = ((autocvar_bot_navigation_ignoreplayers) ? MOVE_NOMONSTERS : MOVE_NORMAL);
685
686         if(time > autoskill_nextthink)
687         {
688                 float a;
689                 a = autocvar_skill_auto;
690                 if(a)
691                         autoskill(a);
692                 autoskill_nextthink = time + 5;
693         }
694
695         if(time > botframe_nextthink)
696         {
697                 if(!bot_fixcount())
698                         botframe_nextthink = time + 10;
699         }
700
701         bot_ignore_bots = autocvar_bot_ignore_bots;
702
703         if(botframe_spawnedwaypoints)
704         {
705                 if(autocvar_waypoint_benchmark)
706                         localcmd("quit\n");
707         }
708
709         if (currentbots > 0 || autocvar_g_waypointeditor || autocvar_g_waypointeditor_auto)
710         if (botframe_spawnedwaypoints)
711         {
712                 if(botframe_cachedwaypointlinks)
713                 {
714                         if(!botframe_loadedforcedlinks)
715                                 waypoint_load_links_hardwired();
716                 }
717                 else
718                 {
719                         // TODO: Make this check cleaner
720                         IL_EACH(g_waypoints, time - it.nextthink > 10,
721                         {
722                                 waypoint_save_links();
723                                 break;
724                         });
725                 }
726         }
727         else
728         {
729                 botframe_spawnedwaypoints = true;
730                 waypoint_loadall();
731                 if(!waypoint_load_links())
732                         waypoint_schedulerelinkall();
733         }
734
735         if (bot_list)
736         {
737                 // cycle the goal token from one bot to the next each frame
738                 // (this prevents them from all doing spawnfunc_waypoint searches on the same
739                 //  frame, which causes choppy framerates)
740                 if (bot_strategytoken_taken)
741                 {
742                         bot_strategytoken_taken = false;
743                         if (bot_strategytoken)
744                                 bot_strategytoken = bot_strategytoken.nextbot;
745                         if (!bot_strategytoken)
746                                 bot_strategytoken = bot_list;
747                 }
748
749                 if (botframe_nextdangertime < time)
750                 {
751                         float interval;
752                         interval = autocvar_bot_ai_dangerdetectioninterval;
753                         if (botframe_nextdangertime < time - interval * 1.5)
754                                 botframe_nextdangertime = time;
755                         botframe_nextdangertime = botframe_nextdangertime + interval;
756                         botframe_updatedangerousobjects(autocvar_bot_ai_dangerdetectionupdates);
757                 }
758         }
759
760         if (autocvar_g_waypointeditor)
761                 botframe_showwaypointlinks();
762
763         if (autocvar_g_waypointeditor_auto)
764                 botframe_autowaypoints();
765
766         if(time > bot_cvar_nextthink)
767         {
768                 if(currentbots>0)
769                         bot_custom_weapon_priority_setup();
770                 bot_cvar_nextthink = time + 5;
771         }
772 }