X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fbot%2Fbot.qc;h=468b32c4a57ef46fd2eb6186901475b5aae946fa;hb=f41d9f31538bef0259d2b2c74536bb977901f99d;hp=e42a50f6d4a9ccb8abad44d3b3db2511a13a06a6;hpb=221325d0a55851348e3397354225f04cd472d42f;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/bot/bot.qc b/qcsrc/server/bot/bot.qc index e42a50f6d..468b32c4a 100644 --- a/qcsrc/server/bot/bot.qc +++ b/qcsrc/server/bot/bot.qc @@ -1,5 +1,4 @@ #include "bot.qh" -#include "../_all.qh" #include "aim.qh" #include "navigation.qh" @@ -9,6 +8,8 @@ #include "havocbot/havocbot.qh" #include "havocbot/scripting.qh" +#include "../teamplay.qh" + #include "../antilag.qh" #include "../autocvars.qh" #include "../campaign.qh" @@ -16,46 +17,41 @@ #include "../constants.qh" #include "../defs.qh" #include "../race.qh" -#include "../t_items.qh" +#include -#include "../mutators/mutators_include.qh" +#include "../mutators/all.qh" #include "../weapons/accuracy.qh" -#include "../../common/constants.qh" -#include "../../common/mapinfo.qh" -#include "../../common/teams.qh" -#include "../../common/util.qh" - -#include "../../common/weapons/all.qh" +#include +#include +#include +#include -#include "../../csqcmodellib/sv_model.qh" +#include -#include "../../dpdefs/dpextensions.qh" -#include "../../dpdefs/progsdefs.qh" +#include -#include "../../warpzonelib/common.qh" -#include "../../warpzonelib/util_server.qh" +#include +#include entity bot_spawn() -{ - entity oldself, bot; - bot = spawnclient(); +{SELFPARAM(); + entity bot = spawnclient(); if (bot) { currentbots = currentbots + 1; - oldself = self; - self = bot; + setself(bot); bot_setnameandstuff(); ClientConnect(); PutClientInServer(); - self = oldself; + setself(this); } return bot; } void bot_think() -{ +{SELFPARAM(); if (self.bot_nextthink > time) return; @@ -117,7 +113,7 @@ void bot_think() } // if dead, just wait until we can respawn - if (self.deadflag) + if (IS_DEAD(self)) { if (self.deadflag == DEAD_DEAD) { @@ -133,10 +129,9 @@ void bot_think() } void bot_setnameandstuff() -{ +{SELFPARAM(); string readfile, s; float file, tokens, prio; - entity p; string bot_name, bot_model, bot_skin, bot_shirt, bot_pants; string name, prefix, suffix; @@ -156,7 +151,7 @@ void bot_setnameandstuff() if(file < 0) { - print(strcat("Error: Can not open the bot configuration file '",autocvar_bot_config_file,"'\n")); + LOG_INFO(strcat("Error: Can not open the bot configuration file '",autocvar_bot_config_file,"'\n")); readfile = ""; } else @@ -173,15 +168,13 @@ void bot_setnameandstuff() continue; s = argv(0); prio = 1; - FOR_EACH_CLIENT(p) - { - if(IS_BOT_CLIENT(p)) - if(s == p.cleanname) + FOREACH_CLIENT(IS_BOT_CLIENT(it), LAMBDA( + if(s == it.cleanname) { prio = 0; break; } - } + )); RandomSelection_Add(world, 0, readfile, 1, prio); } readfile = RandomSelection_chosen_string; @@ -241,16 +234,13 @@ void bot_setnameandstuff() name = bot_name; // number bots with identical names - float i; - i = 0; - FOR_EACH_CLIENT(p) - { - if(IS_BOT_CLIENT(p)) - if(p.cleanname == name) - ++i; - } - if (i) - self.netname = self.netname_freeme = strzone(strcat(prefix, name, "(", ftos(i), ")", suffix)); + int j = 0; + FOREACH_CLIENT(IS_BOT_CLIENT(it), LAMBDA( + if(it.cleanname == name) + ++j; + )); + if (j) + self.netname = self.netname_freeme = strzone(strcat(prefix, name, "(", ftos(j), ")", suffix)); else self.netname = self.netname_freeme = strzone(strcat(prefix, name, suffix)); @@ -302,42 +292,42 @@ void bot_custom_weapon_priority_setup() tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_far)," "); int c = 0; - for(i=0; i < tokens && c < WEP_COUNT; ++i){ + for(i=0; i < tokens && c < Weapons_COUNT; ++i){ w = stof(argv(i)); if ( w >= WEP_FIRST && w <= WEP_LAST) { bot_weapons_far[c] = w; ++c; } } - if(c < WEP_COUNT) + if(c < Weapons_COUNT) bot_weapons_far[c] = -1; // Parse mid distance weapon priorities tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_mid)," "); c = 0; - for(i=0; i < tokens && c < WEP_COUNT; ++i){ + for(i=0; i < tokens && c < Weapons_COUNT; ++i){ w = stof(argv(i)); if ( w >= WEP_FIRST && w <= WEP_LAST) { bot_weapons_mid[c] = w; ++c; } } - if(c < WEP_COUNT) + if(c < Weapons_COUNT) bot_weapons_mid[c] = -1; // Parse close distance weapon priorities tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_close)," "); c = 0; - for(i=0; i < tokens && i < WEP_COUNT; ++i){ + for(i=0; i < tokens && i < Weapons_COUNT; ++i){ w = stof(argv(i)); if ( w >= WEP_FIRST && w <= WEP_LAST) { bot_weapons_close[c] = w; ++c; } } - if(c < WEP_COUNT) + if(c < Weapons_COUNT) bot_weapons_close[c] = -1; bot_custom_weapon = true; @@ -383,13 +373,13 @@ void bot_relinkplayerlist() } e = e.chain; } - dprint(strcat("relink: ", ftos(currentbots), " bots seen.\n")); + LOG_TRACE(strcat("relink: ", ftos(currentbots), " bots seen.\n")); bot_strategytoken = bot_list; bot_strategytoken_taken = true; } void bot_clientdisconnect() -{ +{SELFPARAM(); if (!IS_BOT_CLIENT(self)) return; bot_clearqueue(self); @@ -411,10 +401,9 @@ void bot_clientdisconnect() bot_waypoint_queue_owner = world; } -void bot_clientconnect() +void bot_clientconnect(entity this) { - if (!IS_BOT_CLIENT(self)) - return; + if (!IS_BOT_CLIENT(this)) return; self.bot_preferredcolors = self.clientcolors; self.bot_nextthink = time - random(); self.lag_func = bot_lagfunc; @@ -512,30 +501,28 @@ void autoskill(float factor) { float bestbot; float bestplayer; - entity head; bestbot = -1; bestplayer = -1; - FOR_EACH_PLAYER(head) - { - if(IS_REAL_CLIENT(head)) - bestplayer = max(bestplayer, head.totalfrags - head.totalfrags_lastcheck); + FOREACH_CLIENT(IS_PLAYER(it), LAMBDA( + if(IS_REAL_CLIENT(it)) + bestplayer = max(bestplayer, it.totalfrags - it.totalfrags_lastcheck); else - bestbot = max(bestbot, head.totalfrags - head.totalfrags_lastcheck); - } + bestbot = max(bestbot, it.totalfrags - it.totalfrags_lastcheck); + )); - dprint("autoskill: best player got ", ftos(bestplayer), ", "); - dprint("best bot got ", ftos(bestbot), "; "); + LOG_TRACE("autoskill: best player got ", ftos(bestplayer), ", "); + LOG_TRACE("best bot got ", ftos(bestbot), "; "); if(bestbot < 0 || bestplayer < 0) { - dprint("not doing anything\n"); + LOG_TRACE("not doing anything\n"); // don't return, let it reset all counters below } else if(bestbot <= bestplayer * factor - 2) { if(autocvar_skill < 17) { - dprint("2 frags difference, increasing skill\n"); + LOG_TRACE("2 frags difference, increasing skill\n"); cvar_set("skill", ftos(autocvar_skill + 1)); bprint("^2SKILL UP!^7 Now at level ", ftos(autocvar_skill), "\n"); } @@ -544,23 +531,22 @@ void autoskill(float factor) { if(autocvar_skill > 0) { - dprint("2 frags difference, decreasing skill\n"); + LOG_TRACE("2 frags difference, decreasing skill\n"); cvar_set("skill", ftos(autocvar_skill - 1)); bprint("^1SKILL DOWN!^7 Now at level ", ftos(autocvar_skill), "\n"); } } else { - dprint("not doing anything\n"); + LOG_TRACE("not doing anything\n"); return; // don't reset counters, wait for them to accumulate } - FOR_EACH_PLAYER(head) - head.totalfrags_lastcheck = head.totalfrags; + FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(it.totalfrags_lastcheck = it.totalfrags)); } -void bot_calculate_stepheightvec(void) +void bot_calculate_stepheightvec() { stepheightvec = autocvar_sv_stepheight * '0 0 1'; jumpstepheightvec = stepheightvec + @@ -570,19 +556,20 @@ void bot_calculate_stepheightvec(void) float bot_fixcount() { - entity head; - float realplayers, bots, activerealplayers; - - activerealplayers = 0; - realplayers = 0; - - FOR_EACH_REALCLIENT(head) - { - if(IS_PLAYER(head) || g_lms || head.caplayer == 1) - ++activerealplayers; - ++realplayers; - } - + int activerealplayers = 0; + int realplayers = 0; + if (MUTATOR_CALLHOOK(Bot_FixCount, activerealplayers, realplayers)) { + activerealplayers = bot_activerealplayers; + realplayers = bot_realplayers; + } else { + FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA( + if(IS_PLAYER(it)) + ++activerealplayers; + ++realplayers; + )); + } + + int bots; // add/remove bots if needed to make sure there are at least // minplayers+bot_number, or remove all bots if no one is playing // But don't remove bots immediately on level change, as the real players