X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fbot%2Fdefault%2Fbot.qc;h=a42b0609a191ccf9e063de4d429807ccdbb2e59b;hb=0121566a6e21d8cad4438da85c344a86c21e57b8;hp=7b30b62dfabbd720111f6cafad9296c231ce7a66;hpb=3c08700f00a014d84ffe1bb64305ca5da7594cea;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/bot/default/bot.qc b/qcsrc/server/bot/default/bot.qc index 7b30b62df..a42b0609a 100644 --- a/qcsrc/server/bot/default/bot.qc +++ b/qcsrc/server/bot/default/bot.qc @@ -1,53 +1,43 @@ #include "bot.qh" -#include "cvars.qh" - -#include "aim.qh" -#include "navigation.qh" -#include "scripting.qh" -#include "waypoints.qh" - -#include "havocbot/havocbot.qh" -#include "havocbot/scripting.qh" - -#include "../../teamplay.qh" - -#include "../../antilag.qh" -#include "../../autocvars.qh" -#include "../../campaign.qh" -#include "../../client.qh" -#include "../../constants.qh" -#include "../../defs.qh" -#include "../../race.qh" -#include - -#include - -#include "../../weapons/accuracy.qh" - -#include #include -#include #include +#include +#include +#include #include #include - -#include - #include - #include - #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include STATIC_INIT(bot) { bot_calculate_stepheightvec(); } // TODO: remove this function! its only purpose is to update these fields since bot_setnameandstuff is called before ClientState void bot_setclientfields(entity this) { - CS(this).cvar_cl_accuracy_data_share = 1; // share the bots weapon accuracy data with the world - CS(this).cvar_cl_accuracy_data_receive = 0; // don't receive any weapon accuracy data + CS_CVAR(this).cvar_cl_accuracy_data_share = 1; // share the bots weapon accuracy data with the world + CS_CVAR(this).cvar_cl_accuracy_data_receive = 0; // don't receive any weapon accuracy data } entity bot_spawn() @@ -117,6 +107,9 @@ void bot_think(entity this) if (time < game_starttime) { + .entity weaponentity = weaponentities[0]; + if(this.(weaponentity).m_weapon == WEP_Null) + W_NextWeapon(this, 0, weaponentity); // block the bot during the countdown to game start CS(this).movement = '0 0 0'; this.bot_nextthink = game_starttime; @@ -124,16 +117,24 @@ void bot_think(entity this) } // if dead, just wait until we can respawn - if (IS_DEAD(this)) + if (IS_DEAD(this) || IS_OBSERVER(this)) { if (bot_waypoint_queue_owner == this) bot_waypoint_queue_owner = NULL; this.aistatus = 0; CS(this).movement = '0 0 0'; - if (this.deadflag == DEAD_DEAD) + if (IS_OBSERVER(this)) + return; + if (IS_DEAD(this)) { - PHYS_INPUT_BUTTON_JUMP(this) = true; // press jump to respawn - navigation_goalrating_timeout_force(this); + if (!navigation_goalrating_timeout(this)) + navigation_goalrating_timeout_force(this); + // jump must not be pressed for at least one frame in order for + // PlayerThink to detect the key down event + if (this.deadflag == DEAD_DYING) + PHYS_INPUT_BUTTON_JUMP(this) = false; + else if (this.deadflag == DEAD_DEAD) + PHYS_INPUT_BUTTON_JUMP(this) = true; // press jump to respawn } } else if(this.aistatus & AI_STATUS_STUCK) @@ -236,7 +237,11 @@ void bot_setnameandstuff(entity this) else bot_pants = ftos(floor(random() * 15)); if (teamplay && !(autocvar_bot_vs_human && AvailableTeams() == 2)) + { this.bot_forced_team = stof(argv(5)); + if (!Team_IsValidIndex(this.bot_forced_team)) + this.bot_forced_team = 0; + } else this.bot_forced_team = 0; @@ -350,14 +355,14 @@ void bot_custom_weapon_priority_setup() tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_##dist)," "); \ bot_weapons_##dist[0] = -1; \ c = 0; \ - for(i = 0; i < tokens && c < Weapons_COUNT; ++i) { \ + for(i = 0; i < tokens && c < REGISTRY_COUNT(Weapons); ++i) { \ w = stof(argv(i)); \ if (w >= WEP_FIRST && w <= WEP_LAST) { \ bot_weapons_##dist[c] = w; \ ++c; \ } \ } \ - if (c < Weapons_COUNT) \ + if (c < REGISTRY_COUNT(Weapons)) \ bot_weapons_##dist[c] = -1; \ } \ MACRO_END @@ -394,17 +399,19 @@ void bot_relinkplayerlist() if(IS_BOT_CLIENT(it)) { - if(prevbot) - prevbot.nextbot = it; - else - bot_list = it; - prevbot = it; + if (!IS_OBSERVER(it) && !bot_ispaused(it)) + { + if(prevbot) + prevbot.nextbot = it; + else + bot_list = it; + prevbot = it; + } ++currentbots; } }); if(prevbot) prevbot.nextbot = NULL; - LOG_TRACE("relink: ", ftos(currentbots), " bots seen."); bot_strategytoken = bot_list; bot_strategytoken_taken = true; } @@ -439,16 +446,6 @@ void bot_clientconnect(entity this) bot_setclientfields(this); } - if (teamplay && Team_IsValidIndex(this.bot_forced_team)) - { - SetPlayerTeam(this, this.bot_forced_team, TEAM_CHANGE_MANUAL); - } - else - { - this.bot_forced_team = 0; - TeamBalance_JoinBestTeam(this); - } - havocbot_setupbot(this); } @@ -537,11 +534,8 @@ void bot_removenewest() void autoskill(float factor) { - float bestbot; - float bestplayer; - - bestbot = -1; - bestplayer = -1; + int bestbot = -1; + int bestplayer = -1; FOREACH_CLIENT(IS_PLAYER(it), { if(IS_REAL_CLIENT(it)) bestplayer = max(bestplayer, it.totalfrags - it.totalfrags_lastcheck); @@ -549,37 +543,37 @@ void autoskill(float factor) bestbot = max(bestbot, it.totalfrags - it.totalfrags_lastcheck); }); - LOG_DEBUG("autoskill: best player got ", ftos(bestplayer), ", "); - LOG_DEBUG("best bot got ", ftos(bestbot), "; "); + string msg = strcat("autoskill: best player got ", ftos(bestplayer), ", ""best bot got ", ftos(bestbot), "; "); if(bestbot < 0 || bestplayer < 0) { - LOG_DEBUG("not doing anything"); + msg = strcat(msg, "not doing anything"); // don't return, let it reset all counters below } else if(bestbot <= bestplayer * factor - 2) { if(autocvar_skill < 17) { - LOG_DEBUG("2 frags difference, increasing skill"); + msg = strcat(msg, "2 frags difference, increasing skill"); cvar_set("skill", ftos(autocvar_skill + 1)); - bprint("^2SKILL UP!^7 Now at level ", ftos(autocvar_skill), "\n"); + bprint("^2BOT SKILL UP!^7 Now at level ", ftos(autocvar_skill), "\n"); } } else if(bestbot >= bestplayer * factor + 2) { if(autocvar_skill > 0) { - LOG_DEBUG("2 frags difference, decreasing skill"); + msg = strcat(msg, "2 frags difference, decreasing skill"); cvar_set("skill", ftos(autocvar_skill - 1)); - bprint("^1SKILL DOWN!^7 Now at level ", ftos(autocvar_skill), "\n"); + bprint("^1BOT SKILL DOWN!^7 Now at level ", ftos(autocvar_skill), "\n"); } } else { - LOG_DEBUG("not doing anything"); + msg = strcat(msg, "not doing anything"); return; // don't reset counters, wait for them to accumulate } + LOG_DEBUG(msg); FOREACH_CLIENT(IS_PLAYER(it), { it.totalfrags_lastcheck = it.totalfrags; }); } @@ -592,7 +586,7 @@ void bot_calculate_stepheightvec() jumpheight_time = autocvar_sv_jumpvelocity / autocvar_sv_gravity; } -bool bot_fixcount() +bool bot_fixcount(bool multiple_per_frame) { int activerealplayers = 0; int realplayers = 0; @@ -640,13 +634,17 @@ bool bot_fixcount() // only add one bot per frame to avoid utter chaos if(time > botframe_nextthink) { - if (currentbots < bots) + while (currentbots < bots) { if (bot_spawn() == NULL) { bprint("Can not add bot, server full.\n"); return false; } + if (!multiple_per_frame) + { + break; + } } while (currentbots > bots && bots >= 0) bot_removenewest(); @@ -655,39 +653,6 @@ bool bot_fixcount() return true; } -void bot_remove_from_bot_list(entity this) -{ - entity e = bot_list; - entity prev_bot = NULL; - while (e) - { - if(e == this) - { - if(!prev_bot) - bot_list = this.nextbot; - else - prev_bot.nextbot = this.nextbot; - if(bot_strategytoken == this) - { - bot_strategytoken = this.nextbot; - bot_strategytoken_taken = true; - } - this.nextbot = NULL; - break; - } - prev_bot = e; - e = e.nextbot; - } -} - -void bot_clear(entity this) -{ - bot_remove_from_bot_list(this); - if(bot_waypoint_queue_owner == this) - bot_waypoint_queue_owner = NULL; - this.aistatus &= ~AI_STATUS_STUCK; // otherwise bot_waypoint_queue_owner will be set again to this by navigation_unstuck -} - void bot_serverframe() { if (intermission_running && currentbots > 0) @@ -710,6 +675,7 @@ void bot_serverframe() // spectators in the scoreboard and never go away. This issue happens at time 2 if map is changed // with the gotomap command, minplayers is > 1 and human clients join as players very soon // either intentionally or automatically (sv_spectate 0) + // A working workaround for this bug was implemented in commit fbd145044, see entcs_attach if (time < 2.5) { currentbots = -1; @@ -750,7 +716,7 @@ void bot_serverframe() if(time > botframe_nextthink) { - if(!bot_fixcount()) + if(!bot_fixcount(false)) botframe_nextthink = time + 10; } @@ -760,7 +726,7 @@ void bot_serverframe() localcmd("quit\n"); } - if (currentbots > 0 || autocvar_g_waypointeditor || autocvar_g_waypointeditor_auto) + if (currentbots > 0 || waypointeditor_enabled || autocvar_g_waypointeditor_auto) if (botframe_spawnedwaypoints) { if(botframe_cachedwaypointlinks) @@ -825,7 +791,7 @@ void bot_serverframe() } } - if (autocvar_g_waypointeditor) + if (waypointeditor_enabled) botframe_showwaypointlinks(); if (autocvar_g_waypointeditor_auto)