X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fbot%2Fbot.qc;h=b2e20e776435478bf7454d3eadef79ce5e989e5f;hb=19ab1a2ba6824a03f8d263d27cc84dc7d54958ac;hp=c9a54c7f6a79100f2a63323260d00369cd7e0aa2;hpb=34158189655e4cb4a5d26c4a7f465df4bf05431e;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/bot/bot.qc b/qcsrc/server/bot/bot.qc index c9a54c7f6..b2e20e776 100644 --- a/qcsrc/server/bot/bot.qc +++ b/qcsrc/server/bot/bot.qc @@ -12,7 +12,7 @@ entity bot_spawn() { - local entity oldself, bot; + entity oldself, bot; bot = spawnclient(); if (bot) { @@ -25,7 +25,7 @@ entity bot_spawn() self = oldself; } return bot; -}; +} void bot_think() { @@ -45,7 +45,7 @@ void bot_think() if (autocvar_g_campaign && !campaign_bots_may_start) { - self.nextthink = time + 0.5; + self.bot_nextthink = time + 0.5; return; } @@ -85,7 +85,7 @@ void bot_think() { // block the bot during the countdown to game start self.movement = '0 0 0'; - self.nextthink = game_starttime; + self.bot_nextthink = game_starttime; return; } @@ -103,7 +103,7 @@ void bot_think() // now call the current bot AI (havocbot for example) self.bot_ai(); -}; +} void bot_setnameandstuff() { @@ -128,20 +128,22 @@ void bot_setnameandstuff() file = fopen(autocvar_bot_config_file, FILE_READ); if(file < 0) + { print(strcat("Error: Can not open the bot configuration file '",autocvar_bot_config_file,"'\n")); + readfile = ""; + } else { RandomSelection_Init(); - for(;;) + while((readfile = fgets(file))) { - readfile = fgets(file); - if(!readfile) - break; if(substring(readfile, 0, 2) == "//") continue; if(substring(readfile, 0, 1) == "#") continue; tokens = tokenizebyseparator(readfile, "\t"); + if(tokens == 0) + continue; s = argv(0); prio = 1; FOR_EACH_CLIENT(p) @@ -235,11 +237,11 @@ void bot_setnameandstuff() self.cvar_cl_accuracy_data_share = 1; // share the bots weapon accuracy data with the world self.cvar_cl_accuracy_data_receive = 0; // don't receive any weapon accuracy data -}; +} void bot_custom_weapon_priority_setup() { - local float tokens, i, c, w; + float tokens, i, c, w; bot_custom_weapon = FALSE; @@ -312,11 +314,11 @@ void bot_custom_weapon_priority_setup() bot_weapons_close[c] = -1; bot_custom_weapon = TRUE; -}; +} void bot_endgame() { - local entity e; + entity e; //dprint("bot_endgame\n"); e = bot_list; while (e) @@ -325,12 +327,12 @@ void bot_endgame() e = e.nextbot; } // if dynamic waypoints are ever implemented, save them here -}; +} void bot_relinkplayerlist() { - local entity e; - local entity prevbot; + entity e; + entity prevbot; player_count = 0; currentbots = 0; player_list = e = findchainflags(flags, FL_CLIENT); @@ -357,12 +359,13 @@ void bot_relinkplayerlist() dprint(strcat("relink: ", ftos(currentbots), " bots seen.\n")); bot_strategytoken = bot_list; bot_strategytoken_taken = TRUE; -}; +} void bot_clientdisconnect() { if (clienttype(self) != CLIENTTYPE_BOT) return; + bot_clearqueue(self); if(self.cleanname) strunzone(self.cleanname); if(self.netname_freeme) @@ -375,7 +378,8 @@ void bot_clientdisconnect() self.netname_freeme = string_null; self.playermodel_freeme = string_null; self.playerskin_freeme = string_null; - remove(self.bot_cmd_current); + if(self.bot_cmd_current) + remove(self.bot_cmd_current); if(bot_waypoint_queue_owner==self) bot_waypoint_queue_owner = world; } @@ -388,29 +392,29 @@ void bot_clientconnect() self.bot_nextthink = time - random(); self.lag_func = bot_lagfunc; self.isbot = TRUE; - self.createdtime = self.nextthink; + self.createdtime = self.bot_nextthink; if(!self.bot_config_loaded) // This is needed so team overrider doesn't break between matches bot_setnameandstuff(); if(self.bot_forced_team==1) - self.team = COLOR_TEAM1; + self.team = FL_TEAM_1; else if(self.bot_forced_team==2) - self.team = COLOR_TEAM2; + self.team = FL_TEAM_2; else if(self.bot_forced_team==3) - self.team = COLOR_TEAM3; + self.team = FL_TEAM_3; else if(self.bot_forced_team==4) - self.team = COLOR_TEAM4; + self.team = FL_TEAM_4; else JoinBestTeam(self, FALSE, TRUE); havocbot_setupbot(); -}; +} void bot_removefromlargestteam() { - local float besttime, bestcount, thiscount; - local entity best, head; + float besttime, bestcount, thiscount; + entity best, head; CheckAllowedTeams(world); GetTeamCounts(world); head = findchainfloat(isbot, TRUE); @@ -421,13 +425,13 @@ void bot_removefromlargestteam() bestcount = 0; while (head) { - if(head.team == COLOR_TEAM1) + if(head.team == FL_TEAM_1) thiscount = c1; - else if(head.team == COLOR_TEAM2) + else if(head.team == FL_TEAM_2) thiscount = c2; - else if(head.team == COLOR_TEAM3) + else if(head.team == FL_TEAM_3) thiscount = c3; - else if(head.team == COLOR_TEAM4) + else if(head.team == FL_TEAM_4) thiscount = c4; else thiscount = 0; @@ -446,12 +450,12 @@ void bot_removefromlargestteam() } currentbots = currentbots - 1; dropclient(best); -}; +} void bot_removenewest() { - local float besttime; - local entity best, head; + float besttime; + entity best, head; if(teamplay) { @@ -475,7 +479,7 @@ void bot_removenewest() } currentbots = currentbots - 1; dropclient(best); -}; +} void autoskill(float factor) { @@ -537,28 +541,10 @@ void bot_calculate_stepheightvec(void) // 0.75 factor is for safety to make the jumps easy } -void bot_serverframe() +float bot_fixcount() { - float realplayers, bots, activerealplayers; entity head; - - if (intermission_running) - return; - - if (time < 2) - return; - - bot_calculate_stepheightvec(); - bot_navigation_movemode = ((autocvar_bot_navigation_ignoreplayers) ? MOVE_NOMONSTERS : MOVE_NORMAL); - - if(time > autoskill_nextthink) - { - float a; - a = autocvar_skill_auto; - if(a) - autoskill(a); - autoskill_nextthink = time + 5; - } + float realplayers, bots, activerealplayers; activerealplayers = 0; realplayers = 0; @@ -597,8 +583,6 @@ void bot_serverframe() bots = 0; } - bot_ignore_bots = autocvar_bot_ignore_bots; - // only add one bot per frame to avoid utter chaos if(time > botframe_nextthink) { @@ -608,14 +592,44 @@ void bot_serverframe() if (bot_spawn() == world) { bprint("Can not add bot, server full.\n"); - botframe_nextthink = time + 10; - break; + return FALSE; } } while (currentbots > bots) bot_removenewest(); } + return TRUE; +} + +void bot_serverframe() +{ + if (intermission_running) + return; + + if (time < 2) + return; + + bot_calculate_stepheightvec(); + bot_navigation_movemode = ((autocvar_bot_navigation_ignoreplayers) ? MOVE_NOMONSTERS : MOVE_NORMAL); + + if(time > autoskill_nextthink) + { + float a; + a = autocvar_skill_auto; + if(a) + autoskill(a); + autoskill_nextthink = time + 5; + } + + if(time > botframe_nextthink) + { + if(!bot_fixcount()) + botframe_nextthink = time + 10; + } + + bot_ignore_bots = autocvar_bot_ignore_bots; + if(botframe_spawnedwaypoints) { if(autocvar_waypoint_benchmark) @@ -633,7 +647,7 @@ void bot_serverframe() else { // TODO: Make this check cleaner - local entity wp = findchain(classname, "waypoint"); + entity wp = findchain(classname, "waypoint"); if(time - wp.nextthink > 10) waypoint_save_links(); } @@ -662,7 +676,7 @@ void bot_serverframe() if (botframe_nextdangertime < time) { - local float interval; + float interval; interval = autocvar_bot_ai_dangerdetectioninterval; if (botframe_nextdangertime < time - interval * 1.5) botframe_nextdangertime = time; @@ -683,4 +697,4 @@ void bot_serverframe() bot_custom_weapon_priority_setup(); bot_cvar_nextthink = time + 5; } -}; +}