]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/scripting.qc
Merge remote-tracking branch 'origin/divVerent/allow-override-item-model'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / scripting.qc
index d4773e81ea770c3fa65183c4f63ddf86b9c74d59..2fdbdd3f4fe8c0a1a7ea237ec1725cf3d1459c72 100644 (file)
@@ -153,11 +153,12 @@ entity bot_getplace(string placename)
 #define BOT_CMD_BARRIER         20
 #define BOT_CMD_CONSOLE                        21
 #define BOT_CMD_SOUND                  22
-#define BOT_CMD_WHILE                  23      // TODO: Not implemented yet
-#define BOT_CMD_WEND                   24      // TODO: Not implemented yet
-#define BOT_CMD_CHASE                  25      // TODO: Not implemented yet
+#define BOT_CMD_DEBUG_ASSERT_CANFIRE 23
+#define BOT_CMD_WHILE                  24      // TODO: Not implemented yet
+#define BOT_CMD_WEND                   25      // TODO: Not implemented yet
+#define BOT_CMD_CHASE                  26      // TODO: Not implemented yet
 
-#define BOT_CMD_COUNTER                        23      // Update this value if you add/remove a command
+#define BOT_CMD_COUNTER                        24      // Update this value if you add/remove a command
 
 // NOTE: Following commands should be implemented on the bot ai
 //              If a new command should be handled by the target ai(s) please declare it here
@@ -263,13 +264,16 @@ void bot_commands_init()
        bot_cmd_string[BOT_CMD_SOUND] = "sound";
        bot_cmd_parm_type[BOT_CMD_SOUND] = BOT_CMD_PARAMETER_STRING;
 
+       bot_cmd_string[BOT_CMD_DEBUG_ASSERT_CANFIRE] = "debug_assert_canfire";
+       bot_cmd_parm_type[BOT_CMD_DEBUG_ASSERT_CANFIRE] = BOT_CMD_PARAMETER_FLOAT;
+
        bot_cmds_initialized = TRUE;
 }
 
 // Returns first bot with matching name
 entity find_bot_by_name(string name)
 {
-       local entity bot;
+       entity bot;
 
        bot = findchainflags(flags, FL_CLIENT);
        while (bot)
@@ -287,8 +291,8 @@ entity find_bot_by_name(string name)
 // Returns a bot by number on list
 entity find_bot_by_number(float number)
 {
-       local entity bot;
-       local float c;
+       entity bot;
+       float c;
 
        if(!number)
                return world;
@@ -309,7 +313,7 @@ entity find_bot_by_number(float number)
 
 float bot_decodecommand(string cmdstring)
 {
-       local float cmd_parm_type, i;
+       float cmd_parm_type, i;
        float sp;
        string parm;
 
@@ -368,8 +372,8 @@ float bot_decodecommand(string cmdstring)
 
 void bot_cmdhelp(string scmd)
 {
-       local float i, ntype;
-       local string stype;
+       float i, ntype;
+       string stype;
 
        if(!bot_cmds_initialized)
                bot_commands_init();
@@ -470,6 +474,9 @@ void bot_cmdhelp(string scmd)
                        case BOT_CMD_SOUND:
                                print("play sound file at bot location");
                                break;
+                       case BOT_CMD_DEBUG_ASSERT_CANFIRE:
+                               print("verify the state of the weapon entity");
+                               break;
                        default:
                                print("This command has no description yet.");
                                break;
@@ -480,14 +487,14 @@ void bot_cmdhelp(string scmd)
 
 void bot_list_commands()
 {
-       local float i;
-       local string ptype;
+       float i;
+       string ptype;
 
        if(!bot_cmds_initialized)
                bot_commands_init();
 
        print("List of all available commands:\n");
-       print(" Command\t\t\t\tParameter Type\n");
+       print("  Command - Parameter Type\n");
 
        for(i=1;i<BOT_CMD_COUNTER;++i)
        {
@@ -506,7 +513,7 @@ void bot_list_commands()
                                ptype = "none";
                                break;
                }
-               print(strcat(" ",bot_cmd_string[i],"\t\t\t\t<",ptype,"> \n"));
+               print(strcat("  ",bot_cmd_string[i]," - <",ptype,"> \n"));
        }
 }
 
@@ -618,7 +625,7 @@ float bot_cmd_turn()
 
 float bot_cmd_select_weapon()
 {
-       local float id;
+       float id;
 
        id = bot_cmd.bot_cmd_parm_float;
 
@@ -672,8 +679,8 @@ float bot_cmd_eval(string expr)
 
 float bot_cmd_if()
 {
-       local string expr, val_a, val_b;
-       local float cmpofs;
+       string expr, val_a, val_b;
+       float cmpofs;
 
        if(self.bot_cmd_condition_status != CMD_CONDITION_NONE)
        {
@@ -770,7 +777,7 @@ float bot_cmd_aim()
        // Current direction
        if(self.bot_cmd_aim_endtime)
        {
-               local float progress;
+               float progress;
 
                progress = min(1 - (self.bot_cmd_aim_endtime - time) / (self.bot_cmd_aim_endtime - self.bot_cmd_aim_begintime),1);
                self.v_angle = self.bot_cmd_aim_begin + ((self.bot_cmd_aim_end - self.bot_cmd_aim_begin) * progress);
@@ -785,25 +792,25 @@ float bot_cmd_aim()
        }
 
        // New aiming direction
-       local string parms;
-       local float tokens, step;
+       string parms;
+       float tokens, step;
 
        parms = bot_cmd.bot_cmd_parm_string;
 
        tokens = tokenizebyseparator(parms, " ");
 
-       if(tokens==2)
+       if(tokens<2||tokens>3)
+               return CMD_STATUS_ERROR;
+
+       step = (tokens == 3) ? stof(argv(2)) : 0;
+
+       if(step == 0)
        {
                self.v_angle_x -= stof(argv(1));
                self.v_angle_y += stof(argv(0));
                return CMD_STATUS_FINISHED;
        }
 
-       if(tokens<2||tokens>3)
-               return CMD_STATUS_ERROR;
-
-       step = stof(argv(2));
-
        self.bot_cmd_aim_begin = self.v_angle;
 
        self.bot_cmd_aim_end_x = self.v_angle_x - stof(argv(1));
@@ -823,10 +830,10 @@ float bot_cmd_aimtarget()
                return bot_cmd_aim();
        }
 
-       local entity e;
-       local string parms;
-       local vector v;
-       local float tokens, step;
+       entity e;
+       string parms;
+       vector v;
+       float tokens, step;
 
        parms = bot_cmd.bot_cmd_parm_string;
 
@@ -1020,7 +1027,7 @@ float bot_cmd_keypress_handler(string key, float enabled)
 
 float bot_cmd_presskey()
 {
-       local string key;
+       string key;
 
        key = bot_cmd.bot_cmd_parm_string;
 
@@ -1031,7 +1038,7 @@ float bot_cmd_presskey()
 
 float bot_cmd_releasekey()
 {
-       local string key;
+       string key;
 
        key = bot_cmd.bot_cmd_parm_string;
 
@@ -1088,6 +1095,48 @@ float bot_cmd_sound()
        return CMD_STATUS_FINISHED;
 }
 
+.entity tuba_note;
+float bot_cmd_debug_assert_canfire()
+{
+       float f;
+       f = bot_cmd.bot_cmd_parm_float;
+
+       if(self.weaponentity.state != WS_READY)
+       {
+               if(f)
+               {
+                       self.colormod = '0 8 8';
+                       print("Bot wants to fire, inhibited by weaponentity state\n");
+               }
+       }
+       else if(ATTACK_FINISHED(self) > time)
+       {
+               if(f)
+               {
+                       self.colormod = '8 0 8';
+                       print("Bot wants to fire, inhibited by ATTACK_FINISHED\n");
+               }
+       }
+       else if(self.tuba_note)
+       {
+               if(f)
+               {
+                       self.colormod = '8 0 0';
+                       print("Bot wants to fire, bot still has an active tuba note\n");
+               }
+       }
+       else
+       {
+               if(!f)
+               {
+                       self.colormod = '8 8 0';
+                       print("Bot thinks it has fired, but apparently did not\n");
+               }
+       }
+
+       return CMD_STATUS_FINISHED;
+}
+
 //
 
 void bot_command_executed(float rm)
@@ -1164,11 +1213,18 @@ void bot_resetqueues()
 // NOTE: Of course you need to include your commands here too :)
 float bot_execute_commands_once()
 {
-       local float status, ispressingkey;
+       float status, ispressingkey;
 
        // Find command
        bot_setcurrentcommand();
 
+       // 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 FALSE;
+
        // Ignore all commands except continue when the bot is paused
        if(self.bot_exec_status & BOT_EXEC_STATUS_PAUSED)
        if(bot_cmd.bot_cmd_type!=BOT_CMD_CONTINUE)
@@ -1184,9 +1240,6 @@ float bot_execute_commands_once()
        // Keep pressing keys raised by the "presskey" command
        ispressingkey = !!bot_presskeys();
 
-       if(bot_cmd==world)
-               return ispressingkey;
-
        // Handle conditions
        if not(bot_cmd.bot_cmd_type==BOT_CMD_FI||bot_cmd.bot_cmd_type==BOT_CMD_ELSE)
        if(self.bot_cmd_condition_status & CMD_CONDITION_TRUE && self.bot_cmd_condition_status & CMD_CONDITION_FALSE_BLOCK)
@@ -1273,6 +1326,9 @@ float bot_execute_commands_once()
                case BOT_CMD_SOUND:
                        status = bot_cmd_sound();
                        break;
+               case BOT_CMD_DEBUG_ASSERT_CANFIRE:
+                       status = bot_cmd_debug_assert_canfire();
+                       break;
                default:
                        print(strcat("ERROR: Invalid command on queue with id '",ftos(bot_cmd.bot_cmd_type),"'\n"));
                        return 0;
@@ -1290,7 +1346,7 @@ float bot_execute_commands_once()
        {
                if(autocvar_g_debug_bot_commands)
                {
-                       local string parms;
+                       string parms;
 
                        switch(bot_cmd_parm_type[bot_cmd.bot_cmd_type])
                        {