]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/scripting.qc
#includes: cleanup server
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / scripting.qc
index b1425c1a821dadaf447b5d291c539079e3fc83bb..c3484e1d4c47e9c4bc1dc7753630dada4104b309 100644 (file)
@@ -1,8 +1,9 @@
 #include "scripting.qh"
-#include "../_all.qh"
 
 #include "bot.qh"
 
+.int state;
+
 .float bot_cmdqueuebuf_allocated;
 .float bot_cmdqueuebuf;
 .float bot_cmdqueuebuf_start;
@@ -14,7 +15,7 @@ void bot_clearqueue(entity bot)
                return;
        buf_del(bot.bot_cmdqueuebuf);
        bot.bot_cmdqueuebuf_allocated = false;
-       dprint("bot ", bot.netname, " queue cleared\n");
+       LOG_TRACE("bot ", bot.netname, " queue cleared\n");
 }
 
 void bot_queuecommand(entity bot, string cmdstring)
@@ -101,7 +102,7 @@ const int MAX_BOT_PLACES = 4;
 .entity bot_places[MAX_BOT_PLACES];
 .string bot_placenames[MAX_BOT_PLACES];
 entity bot_getplace(string placename)
-{
+{SELFPARAM();
        entity e;
        if(substring(placename, 0, 1) == "@")
        {
@@ -123,7 +124,7 @@ entity bot_getplace(string placename)
                }
                e = find(world, targetname, s);
                if(!e)
-                       print("invalid place ", s, "\n");
+                       LOG_INFO("invalid place ", s, "\n");
                if(i < MAX_BOT_PLACES)
                {
                        self.(bot_placenames[i]) = strzone(placename);
@@ -136,7 +137,7 @@ entity bot_getplace(string placename)
        {
                e = find(world, targetname, placename);
                if(!e)
-                       print("invalid place ", placename, "\n");
+                       LOG_INFO("invalid place ", placename, "\n");
                return e;
        }
 }
@@ -292,7 +293,7 @@ float bot_decodecommand(string cmdstring)
 
                if(cmd_parm_type!=BOT_CMD_PARAMETER_NONE&&parm=="")
                {
-                       print("ERROR: A parameter is required for this command\n");
+                       LOG_INFO("ERROR: A parameter is required for this command\n");
                        return 0;
                }
 
@@ -318,7 +319,7 @@ float bot_decodecommand(string cmdstring)
                }
                return 1;
        }
-       print("ERROR: No such command '", cmdstring, "'\n");
+       LOG_INFO("ERROR: No such command '", cmdstring, "'\n");
        return 0;
 }
 
@@ -353,87 +354,87 @@ void bot_cmdhelp(string scmd)
                                break;
                }
 
-               print(strcat("Command: ",bot_cmd_string[i],"\nParameter: <",stype,"> \n"));
+               LOG_INFO(strcat("Command: ",bot_cmd_string[i],"\nParameter: <",stype,"> \n"));
 
-               print("Description: ");
+               LOG_INFO("Description: ");
                switch(i)
                {
                        case BOT_CMD_PAUSE:
-                               print("Stops the bot completely. Any command other than 'continue' will be ignored.");
+                               LOG_INFO("Stops the bot completely. Any command other than 'continue' will be ignored.");
                                break;
                        case BOT_CMD_CONTINUE:
-                               print("Disable paused status");
+                               LOG_INFO("Disable paused status");
                                break;
                        case BOT_CMD_WAIT:
-                               print("Pause command parsing and bot ai for N seconds. Pressed key will remain pressed");
+                               LOG_INFO("Pause command parsing and bot ai for N seconds. Pressed key will remain pressed");
                                break;
                        case BOT_CMD_WAIT_UNTIL:
-                               print("Pause command parsing and bot ai until time is N from the last barrier. Pressed key will remain pressed");
+                               LOG_INFO("Pause command parsing and bot ai until time is N from the last barrier. Pressed key will remain pressed");
                                break;
                        case BOT_CMD_BARRIER:
-                               print("Waits till all bots that have a command queue reach this command. Pressed key will remain pressed");
+                               LOG_INFO("Waits till all bots that have a command queue reach this command. Pressed key will remain pressed");
                                break;
                        case BOT_CMD_TURN:
-                               print("Look to the right or left N degrees. For turning to the left use positive numbers.");
+                               LOG_INFO("Look to the right or left N degrees. For turning to the left use positive numbers.");
                                break;
                        case BOT_CMD_MOVETO:
-                               print("Walk to an specific coordinate on the map. Usage: moveto \"x y z\"");
+                               LOG_INFO("Walk to an specific coordinate on the map. Usage: moveto \"x y z\"");
                                break;
                        case BOT_CMD_MOVETOTARGET:
-                               print("Walk to the specific target on the map");
+                               LOG_INFO("Walk to the specific target on the map");
                                break;
                        case BOT_CMD_RESETGOAL:
-                               print("Resets the goal stack");
+                               LOG_INFO("Resets the goal stack");
                                break;
                        case BOT_CMD_CC:
-                               print("Execute client command. Examples: cc \"say something\"; cc god; cc \"name newnickname\"; cc kill;");
+                               LOG_INFO("Execute client command. Examples: cc \"say something\"; cc god; cc \"name newnickname\"; cc kill;");
                                break;
                        case BOT_CMD_IF:
-                               print("Perform simple conditional execution.\n");
-                               print("Syntax: \n");
-                               print("        sv_cmd .. if \"condition\"\n");
-                               print("        sv_cmd ..        <instruction if true>\n");
-                               print("        sv_cmd ..        <instruction if true>\n");
-                               print("        sv_cmd .. else\n");
-                               print("        sv_cmd ..        <instruction if false>\n");
-                               print("        sv_cmd ..        <instruction if false>\n");
-                               print("        sv_cmd .. fi\n");
-                               print("Conditions: a=b, a>b, a<b, a\t\t(spaces not allowed)\n");
-                               print("            Values in conditions can be numbers, cvars in the form cvar.cvar_string or special fields\n");
-                               print("Fields: health, speed, flagcarrier\n");
-                               print("Examples: if health>50; if health>cvar.g_balance_laser_primary_damage; if flagcarrier;");
+                               LOG_INFO("Perform simple conditional execution.\n");
+                               LOG_INFO("Syntax: \n");
+                               LOG_INFO("        sv_cmd .. if \"condition\"\n");
+                               LOG_INFO("        sv_cmd ..     <instruction if true>\n");
+                               LOG_INFO("        sv_cmd ..     <instruction if true>\n");
+                               LOG_INFO("        sv_cmd .. else\n");
+                               LOG_INFO("        sv_cmd ..     <instruction if false>\n");
+                               LOG_INFO("        sv_cmd ..     <instruction if false>\n");
+                               LOG_INFO("        sv_cmd .. fi\n");
+                               LOG_INFO("Conditions: a=b, a>b, a<b, a\t\t(spaces not allowed)\n");
+                               LOG_INFO("            Values in conditions can be numbers, cvars in the form cvar.cvar_string or special fields\n");
+                               LOG_INFO("Fields: health, speed, flagcarrier\n");
+                               LOG_INFO("Examples: if health>50; if health>cvar.g_balance_laser_primary_damage; if flagcarrier;");
                                break;
                        case BOT_CMD_RESETAIM:
-                               print("Points the aim to the coordinates x,y 0,0");
+                               LOG_INFO("Points the aim to the coordinates x,y 0,0");
                                break;
                        case BOT_CMD_AIM:
-                               print("Move the aim x/y (horizontal/vertical) degrees relatives to the bot\n");
-                               print("There is a 3rd optional parameter telling in how many seconds the aim has to reach the new position\n");
-                               print("Examples: aim \"90 0\"   // Turn 90 degrees inmediately (positive numbers move to the left/up)\n");
-                               print("          aim \"0 90 2\" // Will gradually look to the sky in the next two seconds");
+                               LOG_INFO("Move the aim x/y (horizontal/vertical) degrees relatives to the bot\n");
+                               LOG_INFO("There is a 3rd optional parameter telling in how many seconds the aim has to reach the new position\n");
+                               LOG_INFO("Examples: aim \"90 0\"        // Turn 90 degrees inmediately (positive numbers move to the left/up)\n");
+                               LOG_INFO("          aim \"0 90 2\"      // Will gradually look to the sky in the next two seconds");
                                break;
                        case BOT_CMD_AIMTARGET:
-                               print("Points the aim to given target");
+                               LOG_INFO("Points the aim to given target");
                                break;
                        case BOT_CMD_PRESSKEY:
-                               print("Press one of the following keys: forward, backward, left, right, jump, crouch, attack1, attack2, use\n");
-                               print("Multiple keys can be pressed at time (with many presskey calls) and it will remain pressed until the command \"releasekey\" is called");
-                               print("Note: The script will not return the control to the bot ai until all keys are released");
+                               LOG_INFO("Press one of the following keys: forward, backward, left, right, jump, crouch, attack1, attack2, use\n");
+                               LOG_INFO("Multiple keys can be pressed at time (with many presskey calls) and it will remain pressed until the command \"releasekey\" is called");
+                               LOG_INFO("Note: The script will not return the control to the bot ai until all keys are released");
                                break;
                        case BOT_CMD_RELEASEKEY:
-                               print("Release previoulsy used keys. Use the parameter \"all\" to release all keys");
+                               LOG_INFO("Release previoulsy used keys. Use the parameter \"all\" to release all keys");
                                break;
                        case BOT_CMD_SOUND:
-                               print("play sound file at bot location");
+                               LOG_INFO("play sound file at bot location");
                                break;
                        case BOT_CMD_DEBUG_ASSERT_CANFIRE:
-                               print("verify the state of the weapon entity");
+                               LOG_INFO("verify the state of the weapon entity");
                                break;
                        default:
-                               print("This command has no description yet.");
+                               LOG_INFO("This command has no description yet.");
                                break;
                }
-               print("\n");
+               LOG_INFO("\n");
        }
 }
 
@@ -445,8 +446,8 @@ void bot_list_commands()
        if(!bot_cmds_initialized)
                bot_commands_init();
 
-       print("List of all available commands:\n");
-       print("  Command - Parameter Type\n");
+       LOG_INFO("List of all available commands:\n");
+       LOG_INFO("  Command - Parameter Type\n");
 
        for(i=1;i<BOT_CMD_COUNTER;++i)
        {
@@ -465,7 +466,7 @@ void bot_list_commands()
                                ptype = "none";
                                break;
                }
-               print(strcat("  ",bot_cmd_string[i]," - <",ptype,"> \n"));
+               LOG_INFO(strcat("  ",bot_cmd_string[i]," - <",ptype,"> \n"));
        }
 }
 
@@ -480,20 +481,20 @@ float bot_cmd_cc()
 }
 
 float bot_cmd_impulse()
-{
+{SELFPARAM();
        self.impulse = bot_cmd.bot_cmd_parm_float;
        return CMD_STATUS_FINISHED;
 }
 
 float bot_cmd_continue()
-{
+{SELFPARAM();
        self.bot_exec_status &= ~BOT_EXEC_STATUS_PAUSED;
        return CMD_STATUS_FINISHED;
 }
 
 .float bot_cmd_wait_time;
 float bot_cmd_wait()
-{
+{SELFPARAM();
        if(self.bot_exec_status & BOT_EXEC_STATUS_WAITING)
        {
                if(time>=self.bot_cmd_wait_time)
@@ -511,7 +512,7 @@ float bot_cmd_wait()
 }
 
 float bot_cmd_wait_until()
-{
+{SELFPARAM();
        if(time < bot_cmd.bot_cmd_parm_float + bot_barriertime)
        {
                self.bot_exec_status |= BOT_EXEC_STATUS_WAITING;
@@ -522,7 +523,7 @@ float bot_cmd_wait_until()
 }
 
 float bot_cmd_barrier()
-{
+{SELFPARAM();
        entity cl;
 
        // 0 = no barrier, 1 = waiting, 2 = waiting finished
@@ -561,14 +562,14 @@ float bot_cmd_barrier()
 }
 
 float bot_cmd_turn()
-{
+{SELFPARAM();
        self.v_angle_y = self.v_angle.y + bot_cmd.bot_cmd_parm_float;
        self.v_angle_y = self.v_angle.y - floor(self.v_angle.y / 360) * 360;
        return CMD_STATUS_FINISHED;
 }
 
 float bot_cmd_select_weapon()
-{
+{SELFPARAM();
        float id;
 
        id = bot_cmd.bot_cmd_parm_float;
@@ -593,7 +594,7 @@ const int CMD_CONDITION_true_BLOCK = 4;
 const int CMD_CONDITION_false_BLOCK = 8;
 
 float bot_cmd_eval(string expr)
-{
+{SELFPARAM();
        // Search for numbers
        if(strstrofs("0123456789", substring(expr, 0, 1), 0) >= 0)
        {
@@ -617,19 +618,19 @@ float bot_cmd_eval(string expr)
                        return ((self.flagcarried!=world));
        }
 
-       print(strcat("ERROR: Unable to convert the expression '",expr,"' into a numeric value\n"));
+       LOG_INFO(strcat("ERROR: Unable to convert the expression '",expr,"' into a numeric value\n"));
        return 0;
 }
 
 float bot_cmd_if()
-{
+{SELFPARAM();
        string expr, val_a, val_b;
        float cmpofs;
 
        if(self.bot_cmd_condition_status != CMD_CONDITION_NONE)
        {
                // Only one "if" block is allowed at time
-               print("ERROR: Only one conditional block can be processed at time");
+               LOG_INFO("ERROR: Only one conditional block can be processed at time");
                bot_clearqueue(self);
                return CMD_STATUS_ERROR;
        }
@@ -693,20 +694,20 @@ float bot_cmd_if()
 }
 
 float bot_cmd_else()
-{
+{SELFPARAM();
        self.bot_cmd_condition_status &= ~CMD_CONDITION_true_BLOCK;
        self.bot_cmd_condition_status |= CMD_CONDITION_false_BLOCK;
        return CMD_STATUS_FINISHED;
 }
 
 float bot_cmd_fi()
-{
+{SELFPARAM();
        self.bot_cmd_condition_status = CMD_CONDITION_NONE;
        return CMD_STATUS_FINISHED;
 }
 
 float bot_cmd_resetaim()
-{
+{SELFPARAM();
        self.v_angle = '0 0 0';
        return CMD_STATUS_FINISHED;
 }
@@ -717,7 +718,7 @@ float bot_cmd_resetaim()
 .vector bot_cmd_aim_end;
 
 float bot_cmd_aim()
-{
+{SELFPARAM();
        // Current direction
        if(self.bot_cmd_aim_endtime)
        {
@@ -768,7 +769,7 @@ float bot_cmd_aim()
 }
 
 float bot_cmd_aimtarget()
-{
+{SELFPARAM();
        if(self.bot_cmd_aim_endtime)
        {
                return bot_cmd_aim();
@@ -827,7 +828,7 @@ const int BOT_CMD_KEY_CROUCH        = 512;
 const int BOT_CMD_KEY_CHAT             = 1024;
 
 float bot_presskeys()
-{
+{SELFPARAM();
        self.movement = '0 0 0';
        self.BUTTON_JUMP = false;
        self.BUTTON_CROUCH = false;
@@ -876,7 +877,7 @@ float bot_presskeys()
 
 
 float bot_cmd_keypress_handler(string key, float enabled)
-{
+{SELFPARAM();
        switch(key)
        {
                case "all":
@@ -990,7 +991,7 @@ float bot_cmd_releasekey()
 }
 
 float bot_cmd_pause()
-{
+{SELFPARAM();
        self.button1        = 0;
        self.button8        = 0;
        self.BUTTON_USE     = 0;
@@ -1009,12 +1010,12 @@ float bot_cmd_pause()
 }
 
 float bot_cmd_moveto()
-{
+{SELFPARAM();
        return self.cmd_moveto(bot_cmd.bot_cmd_parm_vector);
 }
 
 float bot_cmd_movetotarget()
-{
+{SELFPARAM();
        entity e;
        e = bot_getplace(bot_cmd.bot_cmd_parm_string);
        if(!e)
@@ -1023,13 +1024,13 @@ float bot_cmd_movetotarget()
 }
 
 float bot_cmd_resetgoal()
-{
+{SELFPARAM();
        return self.cmd_resetgoal();
 }
 
 
 float bot_cmd_sound()
-{
+{SELFPARAM();
        string f;
        f = bot_cmd.bot_cmd_parm_string;
 
@@ -1050,14 +1051,14 @@ float bot_cmd_sound()
                atten = stof(argv(2));
 
        precache_sound(f);
-       sound(self, chan, sample, vol, atten);
+       _sound(self, chan, sample, vol, atten);
 
        return CMD_STATUS_FINISHED;
 }
 
 .entity tuba_note;
 float bot_cmd_debug_assert_canfire()
-{
+{SELFPARAM();
        float f;
        f = bot_cmd.bot_cmd_parm_float;
 
@@ -1066,7 +1067,7 @@ float bot_cmd_debug_assert_canfire()
                if(f)
                {
                        self.colormod = '0 8 8';
-                       print("Bot ", self.netname, " using ", self.weaponname, " wants to fire, inhibited by weaponentity state\n");
+                       LOG_INFO("Bot ", self.netname, " using ", self.weaponname, " wants to fire, inhibited by weaponentity state\n");
                }
        }
        else if(ATTACK_FINISHED(self) > time)
@@ -1074,7 +1075,7 @@ float bot_cmd_debug_assert_canfire()
                if(f)
                {
                        self.colormod = '8 0 8';
-                       print("Bot ", self.netname, " using ", self.weaponname, " wants to fire, inhibited by ATTACK_FINISHED (", ftos(ATTACK_FINISHED(self) - time), " seconds left)\n");
+                       LOG_INFO("Bot ", self.netname, " using ", self.weaponname, " wants to fire, inhibited by ATTACK_FINISHED (", ftos(ATTACK_FINISHED(self) - time), " seconds left)\n");
                }
        }
        else if(self.tuba_note)
@@ -1082,7 +1083,7 @@ float bot_cmd_debug_assert_canfire()
                if(f)
                {
                        self.colormod = '8 0 0';
-                       print("Bot ", self.netname, " using ", self.weaponname, " wants to fire, bot still has an active tuba note\n");
+                       LOG_INFO("Bot ", self.netname, " using ", self.weaponname, " wants to fire, bot still has an active tuba note\n");
                }
        }
        else
@@ -1090,7 +1091,7 @@ float bot_cmd_debug_assert_canfire()
                if(!f)
                {
                        self.colormod = '8 8 0';
-                       print("Bot ", self.netname, " using ", self.weaponname, " thinks it has fired, but apparently did not; ATTACK_FINISHED says ", ftos(ATTACK_FINISHED(self) - time), " seconds left\n");
+                       LOG_INFO("Bot ", self.netname, " using ", self.weaponname, " thinks it has fired, but apparently did not; ATTACK_FINISHED says ", ftos(ATTACK_FINISHED(self) - time), " seconds left\n");
                }
        }
 
@@ -1100,7 +1101,7 @@ float bot_cmd_debug_assert_canfire()
 //
 
 void bot_command_executed(float rm)
-{
+{SELFPARAM();
        entity cmd;
 
        cmd = bot_cmd;
@@ -1112,7 +1113,7 @@ void bot_command_executed(float rm)
 }
 
 void bot_setcurrentcommand()
-{
+{SELFPARAM();
        bot_cmd = world;
 
        if(!self.bot_cmd_current)
@@ -1171,7 +1172,7 @@ void bot_resetqueues()
 // Here we map commands to functions and deal with complex interactions between commands and execution states
 // NOTE: Of course you need to include your commands here too :)
 float bot_execute_commands_once()
-{
+{SELFPARAM();
        float status, ispressingkey;
 
        // Find command
@@ -1191,7 +1192,7 @@ float bot_execute_commands_once()
                if(bot_cmd.bot_cmd_type!=BOT_CMD_NULL)
                {
                        bot_command_executed(true);
-                       print( "WARNING: Commands are ignored while the bot is paused. Use the command 'continue' instead.\n");
+                       LOG_INFO( "WARNING: Commands are ignored while the bot is paused. Use the command 'continue' instead.\n");
                }
                return 1;
        }
@@ -1289,12 +1290,12 @@ float bot_execute_commands_once()
                        status = bot_cmd_debug_assert_canfire();
                        break;
                default:
-                       print(strcat("ERROR: Invalid command on queue with id '",ftos(bot_cmd.bot_cmd_type),"'\n"));
+                       LOG_INFO(strcat("ERROR: Invalid command on queue with id '",ftos(bot_cmd.bot_cmd_type),"'\n"));
                        return 0;
        }
 
        if (status==CMD_STATUS_ERROR)
-               print(strcat("ERROR: The command '",bot_cmd_string[bot_cmd.bot_cmd_type],"' returned an error status\n"));
+               LOG_INFO(strcat("ERROR: The command '",bot_cmd_string[bot_cmd.bot_cmd_type],"' returned an error status\n"));
 
        // Move execution pointer
        if(status==CMD_STATUS_EXECUTING)