#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 <common/t_items.qh>
+
+#include "../../mutators/_mod.qh"
#include "../../weapons/accuracy.qh"
+#include <common/physics/player.qh>
+#include <common/constants.qh>
+#include <common/mapinfo.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>
+
entity bot_spawn()
-{SELFPARAM();
+{
entity bot = spawnclient();
if (bot)
{
currentbots = currentbots + 1;
- setself(bot);
- bot_setnameandstuff();
- ClientConnect();
- PutClientInServer();
- setself(this);
+ bot_setnameandstuff(bot);
+ ClientConnect(bot);
+ PutClientInServer(bot);
}
return bot;
}
-void bot_think()
-{SELFPARAM();
- if (self.bot_nextthink > time)
+void bot_think(entity this)
+{
+ if (this.bot_nextthink > time)
return;
- self.flags &= ~FL_GODMODE;
+ this.flags &= ~FL_GODMODE;
if(autocvar_bot_god)
- self.flags |= FL_GODMODE;
+ this.flags |= FL_GODMODE;
- self.bot_nextthink = self.bot_nextthink + autocvar_bot_ai_thinkinterval * pow(0.5, self.bot_aiskill);
- //if (self.bot_painintensity > 0)
- // self.bot_painintensity = self.bot_painintensity - (skill + 1) * 40 * frametime;
+ this.bot_nextthink = this.bot_nextthink + autocvar_bot_ai_thinkinterval * pow(0.5, this.bot_aiskill);
+ //if (this.bot_painintensity > 0)
+ // this.bot_painintensity = this.bot_painintensity - (skill + 1) * 40 * frametime;
- //self.bot_painintensity = self.bot_painintensity + self.bot_oldhealth - self.health;
- //self.bot_painintensity = bound(0, self.bot_painintensity, 100);
+ //this.bot_painintensity = this.bot_painintensity + this.bot_oldhealth - this.health;
+ //this.bot_painintensity = bound(0, this.bot_painintensity, 100);
- if (!IS_PLAYER(self) || (autocvar_g_campaign && !campaign_bots_may_start))
+ if (!IS_PLAYER(this) || (autocvar_g_campaign && !campaign_bots_may_start))
{
- self.bot_nextthink = time + 0.5;
+ this.bot_nextthink = time + 0.5;
return;
}
- if (self.fixangle)
+ if (this.fixangle)
{
- self.v_angle = self.angles;
- self.v_angle_z = 0;
- self.fixangle = false;
+ this.v_angle = this.angles;
+ this.v_angle_z = 0;
+ this.fixangle = false;
}
- self.dmg_take = 0;
- self.dmg_save = 0;
- self.dmg_inflictor = world;
+ this.dmg_take = 0;
+ this.dmg_save = 0;
+ this.dmg_inflictor = NULL;
// calculate an aiming latency based on the skill setting
// (simulated network latency + naturally delayed reflexes)
- //self.ping = 0.7 - bound(0, 0.05 * skill, 0.5); // moved the reflexes to bot_aimdir (under the name 'think')
+ //this.ping = 0.7 - bound(0, 0.05 * skill, 0.5); // moved the reflexes to bot_aimdir (under the name 'think')
// minimum ping 20+10 random
- self.ping = bound(0,0.07 - bound(0, (skill + self.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
+ 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
// skill 10 = ping 0.2 (adrenaline)
// skill 0 = ping 0.7 (slightly drunk)
// clear buttons
- self.BUTTON_ATCK = 0;
- self.button1 = 0;
- self.BUTTON_JUMP = 0;
- self.BUTTON_ATCK2 = 0;
- self.BUTTON_ZOOM = 0;
- self.BUTTON_CROUCH = 0;
- self.BUTTON_HOOK = 0;
- self.BUTTON_INFO = 0;
- self.button8 = 0;
- self.BUTTON_CHAT = 0;
- self.BUTTON_USE = 0;
+ PHYS_INPUT_BUTTON_ATCK(this) = false;
+ PHYS_INPUT_BUTTON_JUMP(this) = false;
+ PHYS_INPUT_BUTTON_ATCK2(this) = false;
+ PHYS_INPUT_BUTTON_ZOOM(this) = false;
+ PHYS_INPUT_BUTTON_CROUCH(this) = false;
+ PHYS_INPUT_BUTTON_HOOK(this) = false;
+ PHYS_INPUT_BUTTON_INFO(this) = false;
+ PHYS_INPUT_BUTTON_DRAG(this) = false;
+ PHYS_INPUT_BUTTON_CHAT(this) = false;
+ PHYS_INPUT_BUTTON_USE(this) = false;
if (time < game_starttime)
{
// block the bot during the countdown to game start
- self.movement = '0 0 0';
- self.bot_nextthink = game_starttime;
+ this.movement = '0 0 0';
+ this.bot_nextthink = game_starttime;
return;
}
// if dead, just wait until we can respawn
- if (self.deadflag)
+ if (IS_DEAD(this))
{
- if (self.deadflag == DEAD_DEAD)
+ if (this.deadflag == DEAD_DEAD)
{
- self.BUTTON_JUMP = 1; // press jump to respawn
- self.bot_strategytime = 0;
+ PHYS_INPUT_BUTTON_JUMP(this) = true; // press jump to respawn
+ this.bot_strategytime = 0;
}
}
- else if(self.aistatus & AI_STATUS_STUCK)
- navigation_unstuck();
+ else if(this.aistatus & AI_STATUS_STUCK)
+ navigation_unstuck(this);
// now call the current bot AI (havocbot for example)
- self.bot_ai();
+ this.bot_ai(this);
}
-void bot_setnameandstuff()
-{SELFPARAM();
+void bot_setnameandstuff(entity this)
+{
string readfile, s;
float file, tokens, prio;
- entity p;
string bot_name, bot_model, bot_skin, bot_shirt, bot_pants;
string name, prefix, suffix;
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);
+ ));
+ RandomSelection_Add(NULL, 0, readfile, 1, prio);
}
readfile = RandomSelection_chosen_string;
fclose(file);
if(argv(4) != "" && stof(argv(4)) >= 0) bot_pants = argv(4);
else bot_pants = ftos(floor(random() * 15));
- self.bot_forced_team = stof(argv(5));
+ this.bot_forced_team = stof(argv(5));
prio = 6;
- #define READSKILL(f,w,r) if(argv(prio) != "") self.f = stof(argv(prio)) * (w); else self.f = (!autocvar_g_campaign) * (2 * random() - 1) * (r) * (w); ++prio
+ #define READSKILL(f,w,r) if(argv(prio) != "") this.f = stof(argv(prio)) * (w); else this.f = (!autocvar_g_campaign) * (2 * random() - 1) * (r) * (w); ++prio
//print(bot_name, ": ping=", argv(9), "\n");
READSKILL(havocbot_keyboardskill, 0.5, 0.5); // keyboard skill
READSKILL(bot_thinkskill, 1, 0.5); // think skill
READSKILL(bot_aiskill, 2, 0); // "ai" skill
- self.bot_config_loaded = true;
+ this.bot_config_loaded = true;
// this is really only a default, JoinBestTeam is called later
- setcolor(self, stof(bot_shirt) * 16 + stof(bot_pants));
- self.bot_preferredcolors = self.clientcolors;
+ setcolor(this, stof(bot_shirt) * 16 + stof(bot_pants));
+ this.bot_preferredcolors = this.clientcolors;
// pick the name
if (autocvar_bot_usemodelnames)
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)
+ this.netname = this.netname_freeme = strzone(strcat(prefix, name, "(", ftos(j), ")", suffix));
else
- self.netname = self.netname_freeme = strzone(strcat(prefix, name, suffix));
+ this.netname = this.netname_freeme = strzone(strcat(prefix, name, suffix));
- self.cleanname = strzone(name);
+ this.cleanname = strzone(name);
// pick the model and skin
if(substring(bot_model, -4, 1) != ".")
bot_model = strcat(bot_model, ".iqm");
- self.playermodel = self.playermodel_freeme = strzone(strcat("models/player/", bot_model));
- self.playerskin = self.playerskin_freeme = strzone(bot_skin);
+ this.playermodel = this.playermodel_freeme = strzone(strcat("models/player/", bot_model));
+ this.playerskin = this.playerskin_freeme = strzone(bot_skin);
- 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
+ this.cvar_cl_accuracy_data_share = 1; // share the bots weapon accuracy data with the NULL
+ this.cvar_cl_accuracy_data_receive = 0; // don't receive any weapon accuracy data
}
void bot_custom_weapon_priority_setup()
void bot_relinkplayerlist()
{
- entity e;
- entity prevbot;
player_count = 0;
currentbots = 0;
- player_list = e = findchainflags(flags, FL_CLIENT);
- bot_list = world;
- prevbot = world;
- while (e)
+ bot_list = NULL;
+
+ entity prevbot = NULL;
+ FOREACH_CLIENT(true,
{
- player_count = player_count + 1;
- e.nextplayer = e.chain;
- if (IS_BOT_CLIENT(e))
+ ++player_count;
+
+ if(IS_BOT_CLIENT(it))
{
- if (prevbot)
- prevbot.nextbot = e;
+ if(prevbot)
+ prevbot.nextbot = it;
else
{
- bot_list = e;
- bot_list.nextbot = world;
+ bot_list = it;
+ bot_list.nextbot = NULL;
}
- prevbot = e;
- currentbots = currentbots + 1;
+ prevbot = it;
+ ++currentbots;
}
- e = e.chain;
- }
- LOG_TRACE(strcat("relink: ", ftos(currentbots), " bots seen.\n"));
+ });
+ LOG_TRACE("relink: ", ftos(currentbots), " bots seen.");
bot_strategytoken = bot_list;
bot_strategytoken_taken = true;
}
-void bot_clientdisconnect()
-{SELFPARAM();
- if (!IS_BOT_CLIENT(self))
+void bot_clientdisconnect(entity this)
+{
+ if (!IS_BOT_CLIENT(this))
return;
- bot_clearqueue(self);
- if(self.cleanname)
- strunzone(self.cleanname);
- if(self.netname_freeme)
- strunzone(self.netname_freeme);
- if(self.playermodel_freeme)
- strunzone(self.playermodel_freeme);
- if(self.playerskin_freeme)
- strunzone(self.playerskin_freeme);
- self.cleanname = string_null;
- self.netname_freeme = string_null;
- self.playermodel_freeme = string_null;
- self.playerskin_freeme = string_null;
- if(self.bot_cmd_current)
- remove(self.bot_cmd_current);
- if(bot_waypoint_queue_owner==self)
- bot_waypoint_queue_owner = world;
+ bot_clearqueue(this);
+ if(this.cleanname)
+ strunzone(this.cleanname);
+ if(this.netname_freeme)
+ strunzone(this.netname_freeme);
+ if(this.playermodel_freeme)
+ strunzone(this.playermodel_freeme);
+ if(this.playerskin_freeme)
+ strunzone(this.playerskin_freeme);
+ this.cleanname = string_null;
+ this.netname_freeme = string_null;
+ this.playermodel_freeme = string_null;
+ this.playerskin_freeme = string_null;
+ if(this.bot_cmd_current)
+ delete(this.bot_cmd_current);
+ if(bot_waypoint_queue_owner==this)
+ bot_waypoint_queue_owner = NULL;
}
-void bot_clientconnect()
-{SELFPARAM();
- if (!IS_BOT_CLIENT(self))
- return;
- self.bot_preferredcolors = self.clientcolors;
- self.bot_nextthink = time - random();
- self.lag_func = bot_lagfunc;
- self.isbot = true;
- 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 = NUM_TEAM_1;
- else if(self.bot_forced_team==2)
- self.team = NUM_TEAM_2;
- else if(self.bot_forced_team==3)
- self.team = NUM_TEAM_3;
- else if(self.bot_forced_team==4)
- self.team = NUM_TEAM_4;
+void bot_clientconnect(entity this)
+{
+ 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;
+
+ if(!this.bot_config_loaded) // This is needed so team overrider doesn't break between matches
+ bot_setnameandstuff(this);
+
+ if(this.bot_forced_team==1)
+ this.team = NUM_TEAM_1;
+ else if(this.bot_forced_team==2)
+ this.team = NUM_TEAM_2;
+ else if(this.bot_forced_team==3)
+ this.team = NUM_TEAM_3;
+ else if(this.bot_forced_team==4)
+ this.team = NUM_TEAM_4;
else
- JoinBestTeam(self, false, true);
+ JoinBestTeam(this, false, true);
- havocbot_setupbot();
+ havocbot_setupbot(this);
}
void bot_removefromlargestteam()
{
- float besttime, bestcount, thiscount;
- entity best, head;
- CheckAllowedTeams(world);
- GetTeamCounts(world);
- head = findchainfloat(isbot, true);
- if (!head)
- return;
- best = head;
- besttime = head.createdtime;
- bestcount = 0;
- while (head)
+ CheckAllowedTeams(NULL);
+ GetTeamCounts(NULL);
+
+ entity best = NULL;
+ float besttime = 0;
+ int bestcount = 0;
+
+ int bcount = 0;
+ FOREACH_CLIENT(it.isbot,
{
- if(head.team == NUM_TEAM_1)
- thiscount = c1;
- else if(head.team == NUM_TEAM_2)
- thiscount = c2;
- else if(head.team == NUM_TEAM_3)
- thiscount = c3;
- else if(head.team == NUM_TEAM_4)
- thiscount = c4;
- else
- thiscount = 0;
- if (thiscount > bestcount)
+ ++bcount;
+
+ if(!best)
+ {
+ best = it;
+ besttime = it.createdtime;
+ }
+
+ int thiscount = 0;
+
+ switch(it.team)
+ {
+ case NUM_TEAM_1: thiscount = c1; break;
+ case NUM_TEAM_2: thiscount = c2; break;
+ case NUM_TEAM_3: thiscount = c3; break;
+ case NUM_TEAM_4: thiscount = c4; break;
+ }
+
+ if(thiscount > bestcount)
{
bestcount = thiscount;
- besttime = head.createdtime;
- best = head;
+ besttime = it.createdtime;
+ best = it;
}
- else if (thiscount == bestcount && besttime < head.createdtime)
+ else if(thiscount == bestcount && besttime < it.createdtime)
{
- besttime = head.createdtime;
- best = head;
+ besttime = it.createdtime;
+ best = it;
}
- head = head.chain;
- }
+ });
+ if(!bcount)
+ return; // no bots to remove
currentbots = currentbots - 1;
dropclient(best);
}
void bot_removenewest()
{
- float besttime;
- entity best, head;
-
if(teamplay)
{
bot_removefromlargestteam();
return;
}
- head = findchainfloat(isbot, true);
- if (!head)
- return;
- best = head;
- besttime = head.createdtime;
- while (head)
+ float besttime = 0;
+ entity best = NULL;
+ int bcount = 0;
+
+ FOREACH_CLIENT(it.isbot,
{
- if (besttime < head.createdtime)
+ ++bcount;
+
+ if(!best)
{
- besttime = head.createdtime;
- best = head;
+ best = it;
+ besttime = it.createdtime;
}
- head = head.chain;
- }
+
+ if(besttime < it.createdtime)
+ {
+ besttime = it.createdtime;
+ best = it;
+ }
+ });
+
+ if(!bcount)
+ return; // no bots to remove
+
currentbots = currentbots - 1;
dropclient(best);
}
{
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);
+ ));
LOG_TRACE("autoskill: best player got ", ftos(bestplayer), ", ");
LOG_TRACE("best bot got ", ftos(bestbot), "; ");
if(bestbot < 0 || bestplayer < 0)
{
- LOG_TRACE("not doing anything\n");
+ LOG_TRACE("not doing anything");
// don't return, let it reset all counters below
}
else if(bestbot <= bestplayer * factor - 2)
{
if(autocvar_skill < 17)
{
- LOG_TRACE("2 frags difference, increasing skill\n");
+ LOG_TRACE("2 frags difference, increasing skill");
cvar_set("skill", ftos(autocvar_skill + 1));
bprint("^2SKILL UP!^7 Now at level ", ftos(autocvar_skill), "\n");
}
{
if(autocvar_skill > 0)
{
- LOG_TRACE("2 frags difference, decreasing skill\n");
+ LOG_TRACE("2 frags difference, decreasing skill");
cvar_set("skill", ftos(autocvar_skill - 1));
bprint("^1SKILL DOWN!^7 Now at level ", ftos(autocvar_skill), "\n");
}
}
else
{
- LOG_TRACE("not doing anything\n");
+ LOG_TRACE("not doing anything");
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 +
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 = M_ARGV(0, int);
+ realplayers = M_ARGV(1, int);
+ } 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
// usually haven't rejoined yet
bots_would_leave = false;
- if (teamplay && autocvar_bot_vs_human && (c3==-1 && c4==-1))
+ if (teamplay && autocvar_bot_vs_human && AvailableTeams() == 2)
bots = min(ceil(fabs(autocvar_bot_vs_human) * activerealplayers), maxclients - realplayers);
else if ((realplayers || autocvar_bot_join_empty || (currentbots > 0 && time < 5)))
{
//dprint(ftos(bots), " ? ", ftos(currentbots), "\n");
while (currentbots < bots)
{
- if (bot_spawn() == world)
+ if (bot_spawn() == NULL)
{
bprint("Can not add bot, server full.\n");
return false;
else
{
// TODO: Make this check cleaner
- entity wp = findchain(classname, "waypoint");
- if(time - wp.nextthink > 10)
+ IL_EACH(g_waypoints, time - it.nextthink > 10,
+ {
waypoint_save_links();
+ break;
+ });
}
}
else