X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fserver%2Fbot%2Fdefault%2Fscripting.qc;h=252708a1189f0401c7af68b0ff4ff047759e1950;hp=ffb7e58132d0348a439d62d866fc84cb8fffddd0;hb=64f2b309aa5be8aafb9ad2137174bb6d99aeb876;hpb=a73f79e356dd25b6ea678379e7884ee45cc1977b diff --git a/qcsrc/server/bot/default/scripting.qc b/qcsrc/server/bot/default/scripting.qc index ffb7e58132..252708a118 100644 --- a/qcsrc/server/bot/default/scripting.qc +++ b/qcsrc/server/bot/default/scripting.qc @@ -4,6 +4,7 @@ #include #include +#include #include "bot.qh" @@ -230,17 +231,10 @@ void bot_commands_init() // 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; } @@ -575,9 +569,22 @@ float bot_cmd_select_weapon(entity this) 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; @@ -594,16 +601,12 @@ const int CMD_CONDITION_false_BLOCK = 8; 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) @@ -1058,14 +1061,14 @@ float bot_cmd_debug_assert_canfire(entity this) { 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) @@ -1073,15 +1076,15 @@ float bot_cmd_debug_assert_canfire(entity this) 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 @@ -1089,7 +1092,7 @@ float bot_cmd_debug_assert_canfire(entity this) 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"); } } @@ -1117,7 +1120,6 @@ void bot_setcurrentcommand(entity this) 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; @@ -1172,16 +1174,17 @@ float bot_execute_commands_once(entity this) // 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) {