#include <common/state.qh>
#include <common/physics/player.qh>
+#include <common/wepent.qh>
#include "bot.qh"
return;
buf_del(bot.bot_cmdqueuebuf);
bot.bot_cmdqueuebuf_allocated = false;
- LOG_TRACE("bot ", bot.netname, " queue cleared\n");
+ LOG_TRACE("bot ", bot.netname, " queue cleared");
}
void bot_queuecommand(entity bot, string cmdstring)
// Returns first bot with matching name
entity find_bot_by_name(string name)
{
- entity bot;
-
- bot = findchainflags(flags, FL_CLIENT);
- while (bot)
+ FOREACH_CLIENT(IS_BOT_CLIENT(it) && it.netname == name,
{
- if(IS_BOT_CLIENT(bot))
- if(bot.netname==name)
- return bot;
-
- bot = bot.chain;
- }
+ return it;
+ });
return NULL;
}
float bot_cmd_continue(entity this)
{
+ bot_relinkplayerlist();
this.bot_exec_status &= ~BOT_EXEC_STATUS_PAUSED;
return CMD_STATUS_FINISHED;
}
if(id < WEP_FIRST || id > WEP_LAST)
return CMD_STATUS_ERROR;
- if(client_hasweapon(this, Weapons_from(id), true, false))
- PS(this).m_switchweapon = Weapons_from(id);
- else
+ bool success = false;
+
+ for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+ {
+ .entity weaponentity = weaponentities[slot];
+ if(this.(weaponentity).m_weapon == WEP_Null && slot != 0)
+ continue;
+
+ if(client_hasweapon(this, Weapons_from(id), weaponentity, true, false))
+ {
+ success = true;
+ this.(weaponentity).m_switchweapon = Weapons_from(id);
+ }
+ }
+
+ if(!success)
return CMD_STATUS_ERROR;
return CMD_STATUS_FINISHED;
float bot_cmd_eval(entity this, string expr)
{
// Search for numbers
- if(strstrofs("0123456789", substring(expr, 0, 1), 0) >= 0)
- {
+ if(IS_DIGIT(substring(expr, 0, 1)))
return stof(expr);
- }
// Search for cvars
if(substring(expr, 0, 5)=="cvar.")
- {
return cvar(substring(expr, 5, strlen(expr)));
- }
// Search for fields
switch(expr)
this.movement = '0 0 0';
this.bot_cmd_keys = BOT_CMD_KEY_NONE;
+ bot_clear(this);
this.bot_exec_status |= BOT_EXEC_STATUS_PAUSED;
return CMD_STATUS_FINISHED;
}
{
float f = bot_cmd.bot_cmd_parm_float;
- int slot = 0;
+ int slot = 0; // TODO: unhardcode?
.entity weaponentity = weaponentities[slot];
if(this.(weaponentity).state != WS_READY)
{
if(f)
{
this.colormod = '0 8 8';
- LOG_INFO("Bot ", this.netname, " using ", this.weaponname, " wants to fire, inhibited by weaponentity state\n");
+ LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " wants to fire, inhibited by weaponentity state\n");
}
}
else if(ATTACK_FINISHED(this, slot) > time)
if(f)
{
this.colormod = '8 0 8';
- LOG_INFO("Bot ", this.netname, " using ", this.weaponname, " wants to fire, inhibited by ATTACK_FINISHED (", ftos(ATTACK_FINISHED(this, slot) - time), " seconds left)\n");
+ LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " wants to fire, inhibited by ATTACK_FINISHED (", ftos(ATTACK_FINISHED(this, slot) - time), " seconds left)\n");
}
}
- else if(this.tuba_note)
+ else if(this.(weaponentity).tuba_note)
{
if(f)
{
this.colormod = '8 0 0';
- LOG_INFO("Bot ", this.netname, " using ", this.weaponname, " wants to fire, bot still has an active tuba note\n");
+ LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " wants to fire, bot still has an active tuba note\n");
}
}
else
if(!f)
{
this.colormod = '8 8 0';
- LOG_INFO("Bot ", this.netname, " using ", this.weaponname, " thinks it has fired, but apparently did not; ATTACK_FINISHED says ", ftos(ATTACK_FINISHED(this, slot) - time), " seconds left\n");
+ LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " thinks it has fired, but apparently did not; ATTACK_FINISHED says ", ftos(ATTACK_FINISHED(this, slot) - time), " seconds left\n");
}
}
if(!this.bot_cmd_current)
{
this.bot_cmd_current = new_pure(bot_cmd);
- this.bot_cmd_current.is_bot_cmd = true;
}
bot_cmd = this.bot_cmd_current;
// Find command
bot_setcurrentcommand(this);
- // if we have no bot command, better return
- // old logic kept pressing previously pressed keys, but that has problems
- // (namely, it means you cannot make a bot "normal" ever again)
- // to keep a bot walking for a while, use the "wait" bot command
- if(bot_cmd == NULL)
- return false;
-
// Ignore all commands except continue when the bot is paused
- if(this.bot_exec_status & BOT_EXEC_STATUS_PAUSED)
- if(bot_cmd.bot_cmd_type!=BOT_CMD_CONTINUE)
+ if(!(self.bot_exec_status & BOT_EXEC_STATUS_PAUSED))
+ {
+ // if we have no bot command, better return
+ // old logic kept pressing previously pressed keys, but that has problems
+ // (namely, it means you cannot make a bot "normal" ever again)
+ // to keep a bot walking for a while, use the "wait" bot command
+ if(bot_cmd == world)
+ return 0;
+ }
+ else if(bot_cmd.bot_cmd_type != BOT_CMD_CONTINUE)
{
if(bot_cmd.bot_cmd_type!=BOT_CMD_NULL)
{