]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/command/common.qc
Merge branch 'master' into Mario/overkill
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / common.qc
index 42420ee2dd7359e393f708ec8664ce239cb0749c..a21feffcb2a976ef491dac7cdf00fdccbb9da21a 100644 (file)
@@ -1,11 +1,12 @@
-#include "../../common/command/command.qh"
+#include "common.qh"
+#include <common/command/_mod.qh>
 #include "common.qh"
 
 #include "../scores.qh"
 
-#include "../../common/monsters/all.qh"
-#include "../../common/notifications.qh"
-#include "../../lib/warpzone/common.qh"
+#include <common/monsters/_mod.qh>
+#include <common/notifications/all.qh>
+#include <lib/warpzone/common.qh>
 
 
 // ====================================================
@@ -79,7 +80,7 @@ entity GetIndexedEntity(float argc, float start_index)
 
        next_token = -1;
        index = start_index;
-       selection = world;
+       selection = NULL;
 
        if (argc > start_index)
        {
@@ -146,7 +147,7 @@ entity GetFilteredEntity(string input)
        }
        else
        {
-               selection = world;
+               selection = NULL;
                FOREACH_CLIENT(true, LAMBDA(
                        if(strdecolorize(it.netname) == strdecolorize(input))
                        {
@@ -182,35 +183,34 @@ void print_to(entity to, string input)
 // ==========================================
 
 // used by CommonCommand_timeout() and CommonCommand_timein() to handle game pausing and messaging and such.
-void timeout_handler_reset()
+void timeout_handler_reset(entity this)
 {
-       SELFPARAM();
-       timeout_caller = world;
+       timeout_caller = NULL;
        timeout_time = 0;
        timeout_leadtime = 0;
 
-       remove(self);
+       delete(this);
 }
 
-void timeout_handler_think()
+void timeout_handler_think(entity this)
 {
-       SELFPARAM();
        switch (timeout_status)
        {
                case TIMEOUT_ACTIVE:
                {
                        if (timeout_time > 0)  // countdown is still going
                        {
-                               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_TIMEOUT_ENDING, timeout_time);
+                               Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_TIMEOUT_ENDING, timeout_time);
 
                                if (timeout_time == autocvar_sv_timeout_resumetime) // play a warning sound when only <sv_timeout_resumetime> seconds are left
-                                       Send_Notification(NOTIF_ALL, world, MSG_ANNCE, ANNCE_PREPARE);
+                                       Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_PREPARE);
 
-                               self.nextthink = time + TIMEOUT_SLOWMO_VALUE;       // think again in one second
+                               this.nextthink = time + TIMEOUT_SLOWMO_VALUE;       // think again in one second
                                timeout_time -= 1;                                  // decrease the time counter
                        }
                        else  // time to end the timeout
                        {
+                               Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_TIMEIN);
                                timeout_status = TIMEOUT_INACTIVE;
 
                                // reset the slowmo value back to normal
@@ -221,7 +221,7 @@ void timeout_handler_think()
                                        it.fixangle = false;
                                ));
 
-                               timeout_handler_reset();
+                               timeout_handler_reset(this);
                        }
 
                        return;
@@ -231,9 +231,9 @@ void timeout_handler_think()
                {
                        if (timeout_leadtime > 0)  // countdown is still going
                        {
-                               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_TIMEOUT_BEGINNING, timeout_leadtime);
+                               Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_TIMEOUT_BEGINNING, timeout_leadtime);
 
-                               self.nextthink = time + 1; // think again in one second
+                               this.nextthink = time + 1; // think again in one second
                                timeout_leadtime -= 1;     // decrease the time counter
                        }
                        else  // time to begin the timeout
@@ -245,7 +245,7 @@ void timeout_handler_think()
 
                                // reset all the flood variables
                                FOREACH_CLIENT(true, LAMBDA(
-                                       it.nickspamcount = it.nickspamtime = it.floodcontrol_chat = 
+                                       it.nickspamcount = it.nickspamtime = it.floodcontrol_chat =
                                                it.floodcontrol_chatteam = it.floodcontrol_chattell =
                                                        it.floodcontrol_voice = it.floodcontrol_voiceteam = 0;
                                ));
@@ -255,7 +255,7 @@ void timeout_handler_think()
                                        it.lastV_angle = it.v_angle;
                                ));
 
-                               self.nextthink = time;  // think again next frame to handle it under TIMEOUT_ACTIVE code
+                               this.nextthink = time;  // think again next frame to handle it under TIMEOUT_ACTIVE code
                        }
 
                        return;
@@ -265,7 +265,7 @@ void timeout_handler_think()
                case TIMEOUT_INACTIVE:
                default:
                {
-                       timeout_handler_reset();
+                       timeout_handler_reset(this);
                        return;
                }
        }
@@ -320,7 +320,6 @@ void CommonCommand_cvar_purechanges(float request, entity caller)
 
 void CommonCommand_editmob(int request, entity caller, int argc)
 {
-       SELFPARAM();
        switch (request)
        {
                case CMD_REQUEST_COMMAND:
@@ -330,8 +329,8 @@ void CommonCommand_editmob(int request, entity caller, int argc)
 
                        if (caller)
                        {
-                               makevectors(self.v_angle);
-                               WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * 100, MOVE_NORMAL, self);
+                               makevectors(caller.v_angle);
+                               WarpZone_TraceLine(caller.origin + caller.view_ofs, caller.origin + caller.view_ofs + v_forward * 100, MOVE_NORMAL, caller);
                        }
 
                        entity mon = trace_ent;
@@ -363,37 +362,36 @@ void CommonCommand_editmob(int request, entity caller, int argc)
                                        int moveflag, tmp_moncount = 0;
                                        string arg_lower = strtolower(argument);
                                        moveflag = (argv(3)) ? stof(argv(3)) : 1;  // follow owner if not defined
-                                       ret_string = "Monster spawning is currently disabled by a mutator";
 
                                        if (arg_lower == "list") { print_to(caller, monsterlist_reply); return; }
 
-                                       FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
-                                               if(it.realowner == caller)
-                                                       ++tmp_moncount;
-                                       ));
+                                       IL_EACH(g_monsters, it.realowner == caller,
+                                       {
+                                               ++tmp_moncount;
+                                       });
 
                                        if (!autocvar_g_monsters) { print_to(caller, "Monsters are disabled"); return; }
                                        if (autocvar_g_monsters_max <= 0 || autocvar_g_monsters_max_perplayer <= 0) { print_to(caller, "Monster spawning is disabled"); return; }
                                        if (!IS_PLAYER(caller)) { print_to(caller, "You must be playing to spawn a monster"); return; }
-                                       if (MUTATOR_CALLHOOK(AllowMobSpawning)) { print_to(caller, ret_string); return; }
+                                       if (MUTATOR_CALLHOOK(AllowMobSpawning, caller)) { print_to(caller, M_ARGV(1, string)); return; }
                                        if (caller.vehicle) { print_to(caller, "You can't spawn monsters while driving a vehicle"); return; }
-                                       if (caller.frozen) { print_to(caller, "You can't spawn monsters while frozen"); return; }
-                                       if (caller.deadflag != DEAD_NO) { print_to(caller, "You can't spawn monsters while dead"); return; }
+                                       if (STAT(FROZEN, caller)) { print_to(caller, "You can't spawn monsters while frozen"); return; }
+                                       if (IS_DEAD(caller)) { print_to(caller, "You can't spawn monsters while dead"); return; }
                                        if (tmp_moncount >= autocvar_g_monsters_max) { print_to(caller, "The maximum monster count has been reached"); return; }
                                        if (tmp_moncount >= autocvar_g_monsters_max_perplayer) { print_to(caller, "You can't spawn any more monsters"); return; }
 
                                        bool found = false;
-                                       for (int i = MON_FIRST; i <= MON_LAST; ++i)
+                                       FOREACH(Monsters, it != MON_Null && it.netname == arg_lower,
                                        {
-                                               mon = get_monsterinfo(i);
-                                               if (mon.netname == arg_lower) { found = true; break; }
-                                       }
+                                               found = true;
+                                               break;
+                                       });
 
                                        if (!found && arg_lower != "random") { print_to(caller, "Invalid monster"); return; }
 
                                        totalspawned += 1;
                                        WarpZone_TraceBox(CENTER_OR_VIEWOFS(caller), caller.mins, caller.maxs, CENTER_OR_VIEWOFS(caller) + v_forward * 150, true, caller);
-                                       mon = spawnmonster(arg_lower, 0, caller, caller, trace_endpos, false, false, moveflag);
+                                       mon = spawnmonster(spawn(), arg_lower, 0, caller, caller, trace_endpos, false, false, moveflag);
                                        print_to(caller, strcat("Spawned ", mon.monster_name));
                                        return;
                                }
@@ -403,7 +401,7 @@ void CommonCommand_editmob(int request, entity caller, int argc)
                                        if (mon.realowner != caller && autocvar_g_monsters_edit < 2) { print_to(caller, "This monster does not belong to you"); return; }
                                        if (!is_visible) { print_to(caller, "You must look at your monster to edit it"); return; }
 
-                                       Damage(mon, world, world, mon.health + mon.max_health + 200, DEATH_KILL.m_id, mon.origin, '0 0 0');
+                                       Damage(mon, NULL, NULL, mon.health + mon.max_health + 200, DEATH_KILL.m_id, mon.origin, '0 0 0');
                                        print_to(caller, strcat("Your pet '", mon.monster_name, "' has been brutally mutilated"));
                                        return;
                                }
@@ -435,14 +433,16 @@ void CommonCommand_editmob(int request, entity caller, int argc)
                                case "butcher":
                                {
                                        if (caller) { print_to(caller, "This command is not available to players"); return; }
-                                       if (MUTATOR_CALLHOOK(AllowMobButcher)) { LOG_INFO(ret_string, "\n"); return; }
+                                       if (MUTATOR_CALLHOOK(AllowMobButcher)) { LOG_INFO(M_ARGV(0, string), "\n"); return; }
 
                                        int tmp_remcount = 0;
 
-                                       FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
+                                       IL_EACH(g_monsters, true,
+                                       {
                                                Monster_Remove(it);
                                                ++tmp_remcount;
-                                       ));
+                                       });
+                                       IL_CLEAR(g_monsters);
 
                                        monsters_total = monsters_killed = totalspawned = 0;
 
@@ -473,7 +473,7 @@ void CommonCommand_info(float request, entity caller, float argc)
                {
                        string command = builtin_cvar_string(strcat("sv_info_", argv(1)));
 
-                       if (command) wordwrap_sprint(command, 1000);
+                       if (command) wordwrap_sprint(caller, command, 1000);
                        else print_to(caller, "ERROR: unsupported info command");
 
                        return;  // never fall through to usage
@@ -575,8 +575,14 @@ void CommonCommand_records(float request, entity caller)
        {
                case CMD_REQUEST_COMMAND:
                {
-                       for (int i = 0; i < 10; ++i)
-                               if (records_reply[i] != "") print_to(caller, records_reply[i]);
+                       int num = stoi(argv(1));
+                       if(num > 0 && num <= 10 && records_reply[num - 1] != "")
+                               print_to(caller, records_reply[num - 1]);
+                       else
+                       {
+                               for (int i = 0; i < 10; ++i)
+                                       if (records_reply[i] != "") print_to(caller, records_reply[i]);
+                       }
 
                        return;  // never fall through to usage
                }
@@ -740,10 +746,10 @@ void CommonCommand_timeout(float request, entity caller)  // DEAR GOD THIS COMMA
                                        timeout_leadtime = autocvar_sv_timeout_leadtime;
 
                                        timeout_handler = spawn();
-                                       timeout_handler.think = timeout_handler_think;
+                                       setthink(timeout_handler, timeout_handler_think);
                                        timeout_handler.nextthink = time;  // always let the entity think asap
 
-                                       Send_Notification(NOTIF_ALL, world, MSG_ANNCE, ANNCE_TIMEOUT);
+                                       Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_TIMEOUT);
                                }
                        }
                        else { print_to(caller, "^1Timeouts are not allowed to be called, enable them with sv_timeout 1.\n"); }