#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 <server/items/items.qh>
-
-#include <server/mutators/_mod.qh>
-
-#include "../../weapons/accuracy.qh"
-
-#include <common/physics/player.qh>
#include <common/constants.qh>
-#include <common/net_linked.qh>
#include <common/mapinfo.qh>
+#include <common/net_linked.qh>
+#include <common/physics/player.qh>
+#include <common/stats.qh>
#include <common/teams.qh>
#include <common/util.qh>
-
-#include <server/scores_rules.qh>
-
#include <common/weapons/_all.qh>
-
#include <lib/csqcmodel/sv_model.qh>
-
#include <lib/warpzone/common.qh>
#include <lib/warpzone/util_server.qh>
+#include <server/antilag.qh>
+#include <server/bot/default/aim.qh>
+#include <server/bot/default/cvars.qh>
+#include <server/bot/default/havocbot/havocbot.qh>
+#include <server/bot/default/havocbot/scripting.qh>
+#include <server/bot/default/navigation.qh>
+#include <server/bot/default/scripting.qh>
+#include <server/bot/default/waypoints.qh>
+#include <server/campaign.qh>
+#include <server/client.qh>
+#include <server/damage.qh>
+#include <server/items/items.qh>
+#include <server/mutators/_mod.qh>
+#include <server/race.qh>
+#include <server/scores_rules.qh>
+#include <server/teamplay.qh>
+#include <server/weapons/accuracy.qh>
+#include <server/weapons/selection.qh>
+#include <server/world.qh>
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()
if(autocvar_bot_god)
this.flags |= FL_GODMODE;
- 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));
+ this.bot_nextthink = max(time, this.bot_nextthink) + max(0.01, autocvar_bot_ai_thinkinterval * min(14 / (skill + this.bot_aiskill + 14), 1));
if (!IS_PLAYER(this) || (autocvar_g_campaign && !campaign_bots_may_start))
{
+ if (IS_PLAYER(this))
+ {
+ .entity weaponentity = weaponentities[0];
+ if(this.(weaponentity).m_weapon == WEP_Null)
+ W_NextWeapon(this, 0, weaponentity);
+ }
CS(this).movement = '0 0 0';
this.bot_nextthink = time + 0.5;
return;
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;
return;
}
// 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)
int smallest_count = -1;
if (teamplay)
{
- for (int i = 1; i <= AvailableTeams(); ++i)
+ for (int i = 1; i <= AVAILABLE_TEAMS; ++i)
{
// NOTE if (autocvar_g_campaign && autocvar_g_campaign_forceteam == i)
// TeamBalance_GetNumberOfPlayers(balance, i); returns the number of players + 1
});
if (!conflict)
prio += 1;
- if (teamplay && !(autocvar_bot_vs_human && AvailableTeams() == 2))
+ if (teamplay && !(autocvar_bot_vs_human && AVAILABLE_TEAMS == 2))
{
int forced_team = stof(argv(5));
if (!Team_IsValidIndex(forced_team))
if(argv(4) != "" && stof(argv(4)) >= 0) bot_pants = argv(4);
else bot_pants = ftos(floor(random() * 15));
- if (teamplay && !(autocvar_bot_vs_human && AvailableTeams() == 2))
+ if (teamplay && !(autocvar_bot_vs_human && AVAILABLE_TEAMS == 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;
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;
}
if (!IS_BOT_CLIENT(this)) return;
this.bot_preferredcolors = this.clientcolors;
this.bot_nextthink = time - random();
- this.lag_func = bot_lagfunc;
this.isbot = true;
this.createdtime = this.bot_nextthink;
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);
}
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);
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; });
}
jumpheight_time = autocvar_sv_jumpvelocity / autocvar_sv_gravity;
}
-bool bot_fixcount()
+bool bot_fixcount(bool multiple_per_frame)
{
int activerealplayers = 0;
int realplayers = 0;
// But don't remove bots immediately on level change, as the real players
// usually haven't rejoined yet
bots_would_leave = false;
- if (teamplay && autocvar_bot_vs_human && AvailableTeams() == 2)
+ if (autocvar_bot_vs_human && AVAILABLE_TEAMS == 2)
bots = min(ceil(fabs(autocvar_bot_vs_human) * activerealplayers), maxclients - realplayers);
else if ((realplayers || autocvar_bot_join_empty || (currentbots > 0 && time < 5)))
{
int minplayers = max(0, floor(autocvar_minplayers));
if (teamplay)
- minplayers = max(0, floor(autocvar_minplayers_per_team) * AvailableTeams());
+ minplayers = max(0, floor(autocvar_minplayers_per_team) * AVAILABLE_TEAMS);
int minbots = max(0, floor(autocvar_bot_number));
// add bots to reach minplayers if needed
// 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();
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)
// 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;
if(time > botframe_nextthink)
{
- if(!bot_fixcount())
+ if(!bot_fixcount(false))
botframe_nextthink = time + 10;
}
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)
}
}
- if (autocvar_g_waypointeditor)
+ if (waypointeditor_enabled)
botframe_showwaypointlinks();
if (autocvar_g_waypointeditor_auto)