]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/mutator/gamemode_invasion.qc
Remove unnecessary returns
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator / gamemode_invasion.qc
index 26a7b91dbb8536128c57a9d5c833476a2d1f03c5..c7cd48e8eeb6609182268e9be5f693d4bdc4db39 100644 (file)
@@ -1,3 +1,4 @@
+#include "gamemode_invasion.qh"
 #ifndef GAMEMODE_INVASION_H
 #define GAMEMODE_INVASION_H
 
@@ -18,7 +19,7 @@ REGISTER_MUTATOR(inv, false)
 
                cvar_settemp("g_monsters", "1");
 
-               SetLimits(autocvar_g_invasion_point_limit, -1, -1, -1);
+               SetLimits(autocvar_g_invasion_point_limit, autocvar_leadlimit_override, autocvar_timelimit_override, -1);
                if (autocvar_g_invasion_teams >= 2)
                {
                        ActivateTeamplay();
@@ -61,10 +62,10 @@ const float ST_INV_KILLS = 1;
 
 #ifdef IMPLEMENTATION
 
-#include "../../../common/monsters/spawn.qh"
-#include "../../../common/monsters/sv_monsters.qh"
+#include <common/monsters/spawn.qh>
+#include <common/monsters/sv_monsters.qh>
 
-#include "../../teamplay.qh"
+#include <server/teamplay.qh>
 
 
 float autocvar_g_invasion_round_timelimit;
@@ -76,13 +77,13 @@ float autocvar_g_invasion_spawn_delay;
 
 spawnfunc(invasion_spawnpoint)
 {
-       if(!g_invasion) { remove(self); return; }
+       if(!g_invasion) { remove(this); return; }
 
-       self.classname = "invasion_spawnpoint";
+       this.classname = "invasion_spawnpoint";
 
        if(autocvar_g_invasion_zombies_only) // precache only if it hasn't been already
-       if(self.monsterid) {
-               Monster mon = get_monsterinfo(self.monsterid);
+       if(this.monsterid) {
+               Monster mon = get_monsterinfo(this.monsterid);
                mon.mr_precache(mon);
        }
 }
@@ -140,7 +141,7 @@ void invasion_SpawnChosenMonster(float mon)
                        monster = spawnmonster("", mon, world, world, e.origin, false, false, 2);
                else return;
 
-               e.think = SUB_Remove_self;
+               setthink(e, SUB_Remove);
                e.nextthink = time + 0.1;
        }
        else
@@ -192,11 +193,9 @@ void invasion_SpawnMonsters(float supermonster_count)
 
 float Invasion_CheckWinner()
 {
-       entity head;
        if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
        {
-               FOR_EACH_MONSTER(head)
-                       Monster_Remove(head);
+               FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(Monster_Remove(it)));
 
                Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
                Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
@@ -206,21 +205,23 @@ float Invasion_CheckWinner()
 
        float total_alive_monsters = 0, supermonster_count = 0, red_alive = 0, blue_alive = 0, yellow_alive = 0, pink_alive = 0;
 
-       FOR_EACH_MONSTER(head) if(head.health > 0)
-       {
-               if((get_monsterinfo(head.monsterid)).spawnflags & MON_FLAG_SUPERMONSTER)
-                       ++supermonster_count;
-               ++total_alive_monsters;
-
-               if(teamplay)
-               switch(head.team)
+       FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
+               if(it.health > 0)
                {
-                       case NUM_TEAM_1: ++red_alive; break;
-                       case NUM_TEAM_2: ++blue_alive; break;
-                       case NUM_TEAM_3: ++yellow_alive; break;
-                       case NUM_TEAM_4: ++pink_alive; break;
+                       if((get_monsterinfo(it.monsterid)).spawnflags & MON_FLAG_SUPERMONSTER)
+                               ++supermonster_count;
+                       ++total_alive_monsters;
+
+                       if(teamplay)
+                       switch(it.team)
+                       {
+                               case NUM_TEAM_1: ++red_alive; break;
+                               case NUM_TEAM_2: ++blue_alive; break;
+                               case NUM_TEAM_3: ++yellow_alive; break;
+                               case NUM_TEAM_4: ++pink_alive; break;
+                       }
                }
-       }
+       ));
 
        if((total_alive_monsters + inv_numkilled) < inv_maxspawned && inv_maxcurrent < inv_maxspawned)
        {
@@ -262,25 +263,25 @@ float Invasion_CheckWinner()
                else { winner_team = NUM_TEAM_4; }
        }
        else
-       FOR_EACH_PLAYER(head)
        {
-               float cs = PlayerScore_Add(head, SP_KILLS, 0);
-               if(cs > winning_score)
-               {
-                       winning_score = cs;
-                       winner = head;
-               }
+               FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+                       float cs = PlayerScore_Add(it, SP_KILLS, 0);
+                       if(cs > winning_score)
+                       {
+                               winning_score = cs;
+                               winner = it;
+                       }
+               ));
        }
 
-       FOR_EACH_MONSTER(head)
-               Monster_Remove(head);
+       FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(Monster_Remove(it)));
 
        if(teamplay)
        {
                if(winner_team)
                {
-                       Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
-                       Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
+                       Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
+                       Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
                }
        }
        else if(winner)
@@ -294,20 +295,18 @@ float Invasion_CheckWinner()
        return 1;
 }
 
-float Invasion_CheckPlayers()
+bool Invasion_CheckPlayers()
 {
        return true;
 }
 
 void Invasion_RoundStart()
 {
-       entity e;
-       float numplayers = 0;
-       FOR_EACH_PLAYER(e)
-       {
-               e.player_blocked = 0;
+       int numplayers = 0;
+       FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+               it.player_blocked = false;
                ++numplayers;
-       }
+       ));
 
        if(inv_roundcnt < inv_maxrounds)
                inv_roundcnt += 1; // a limiter to stop crazy counts
@@ -331,15 +330,18 @@ void Invasion_RoundStart()
 }
 
 MUTATOR_HOOKFUNCTION(inv, MonsterDies)
-{SELFPARAM();
-       if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
+{
+       entity frag_target = M_ARGV(0, entity);
+       entity frag_attacker = M_ARGV(1, entity);
+
+       if(!(frag_target.spawnflags & MONSTERFLAG_RESPAWNED))
        {
                inv_numkilled += 1;
                inv_maxcurrent -= 1;
-               if(teamplay) { inv_monsters_perteam[self.team] -= 1; }
+               if(teamplay) { inv_monsters_perteam[frag_target.team] -= 1; }
 
                if(IS_PLAYER(frag_attacker))
-               if(SAME_TEAM(frag_attacker, self)) // in non-teamplay modes, same team = same player, so this works
+               if(SAME_TEAM(frag_attacker, frag_target)) // in non-teamplay modes, same team = same player, so this works
                        PlayerScore_Add(frag_attacker, SP_KILLS, -1);
                else
                {
@@ -348,46 +350,42 @@ MUTATOR_HOOKFUNCTION(inv, MonsterDies)
                                TeamScore_AddToTeam(frag_attacker.team, ST_INV_KILLS, +1);
                }
        }
-
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(inv, MonsterSpawn)
-{SELFPARAM();
-       if(!(self.spawnflags & MONSTERFLAG_SPAWNED))
+{
+       entity mon = M_ARGV(0, entity);
+
+       if(!(mon.spawnflags & MONSTERFLAG_SPAWNED))
                return true;
 
-       if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
+       if(!(mon.spawnflags & MONSTERFLAG_RESPAWNED))
        {
                inv_numspawned += 1;
                inv_maxcurrent += 1;
        }
 
-       self.monster_skill = inv_monsterskill;
-
-       if((get_monsterinfo(self.monsterid)).spawnflags & MON_FLAG_SUPERMONSTER)
-               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_INVASION_SUPERMONSTER, self.monster_name);
+       mon.monster_skill = inv_monsterskill;
 
-       self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_BOTCLIP | DPCONTENTS_MONSTERCLIP;
+       if((get_monsterinfo(mon.monsterid)).spawnflags & MON_FLAG_SUPERMONSTER)
+               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_INVASION_SUPERMONSTER, mon.monster_name);
 
-       return false;
+       mon.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_BOTCLIP | DPCONTENTS_MONSTERCLIP;
 }
 
 MUTATOR_HOOKFUNCTION(inv, OnEntityPreSpawn)
-{SELFPARAM();
-       if(startsWith(self.classname, "monster_"))
-       if(!(self.spawnflags & MONSTERFLAG_SPAWNED))
-               return true;
+{
+       entity ent = M_ARGV(0, entity);
 
-       return false;
+       if(startsWith(ent.classname, "monster_"))
+       if(!(ent.spawnflags & MONSTERFLAG_SPAWNED))
+               return true;
 }
 
 MUTATOR_HOOKFUNCTION(inv, SV_StartFrame)
 {
        monsters_total = inv_maxspawned; // TODO: make sure numspawned never exceeds maxspawned
        monsters_killed = inv_numkilled;
-
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(inv, PlayerRegen)
@@ -397,60 +395,69 @@ MUTATOR_HOOKFUNCTION(inv, PlayerRegen)
 }
 
 MUTATOR_HOOKFUNCTION(inv, PlayerSpawn)
-{SELFPARAM();
-       self.bot_attack = false;
-       return false;
+{
+       entity player = M_ARGV(0, entity);
+
+       player.bot_attack = false;
 }
 
 MUTATOR_HOOKFUNCTION(inv, PlayerDamage_Calculate)
 {
+       entity frag_attacker = M_ARGV(1, entity);
+       entity frag_target = M_ARGV(2, entity);
+       float frag_damage = M_ARGV(4, float);
+       vector frag_force = M_ARGV(6, vector);
+
        if(IS_PLAYER(frag_attacker) && IS_PLAYER(frag_target) && frag_attacker != frag_target)
        {
                frag_damage = 0;
                frag_force = '0 0 0';
-       }
 
-       return false;
+               M_ARGV(4, float) = frag_damage;
+               M_ARGV(6, vector) = frag_force;
+       }
 }
 
 MUTATOR_HOOKFUNCTION(inv, SV_ParseClientCommand)
-{SELFPARAM();
+{
        if(MUTATOR_RETURNVALUE) // command was already handled?
-               return false;
+               return;
+
+       entity player = M_ARGV(0, entity);
+       string cmd_name = M_ARGV(1, string);
 
        if(cmd_name == "debuginvasion")
        {
-               sprint(self, strcat("inv_maxspawned = ", ftos(inv_maxspawned), "\n"));
-               sprint(self, strcat("inv_numspawned = ", ftos(inv_numspawned), "\n"));
-               sprint(self, strcat("inv_numkilled = ", ftos(inv_numkilled), "\n"));
-               sprint(self, strcat("inv_roundcnt = ", ftos(inv_roundcnt), "\n"));
-               sprint(self, strcat("monsters_total = ", ftos(monsters_total), "\n"));
-               sprint(self, strcat("monsters_killed = ", ftos(monsters_killed), "\n"));
-               sprint(self, strcat("inv_monsterskill = ", ftos(inv_monsterskill), "\n"));
+               sprint(player, strcat("inv_maxspawned = ", ftos(inv_maxspawned), "\n"));
+               sprint(player, strcat("inv_numspawned = ", ftos(inv_numspawned), "\n"));
+               sprint(player, strcat("inv_numkilled = ", ftos(inv_numkilled), "\n"));
+               sprint(player, strcat("inv_roundcnt = ", ftos(inv_roundcnt), "\n"));
+               sprint(player, strcat("monsters_total = ", ftos(monsters_total), "\n"));
+               sprint(player, strcat("monsters_killed = ", ftos(monsters_killed), "\n"));
+               sprint(player, strcat("inv_monsterskill = ", ftos(inv_monsterskill), "\n"));
 
                return true;
        }
-
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(inv, BotShouldAttack)
 {
-       if(!IS_MONSTER(checkentity))
-               return true;
+       entity targ = M_ARGV(1, entity);
 
-       return false;
+       if(!IS_MONSTER(targ))
+               return true;
 }
 
 MUTATOR_HOOKFUNCTION(inv, SetStartItems)
 {
        start_health = 200;
        start_armorvalue = 200;
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(inv, AccuracyTargetValid)
 {
+       entity frag_target = M_ARGV(1, entity);
+
        if(IS_MONSTER(frag_target))
                return MUT_ACCADD_INVALID;
        return MUT_ACCADD_INDIFFERENT;
@@ -459,18 +466,18 @@ MUTATOR_HOOKFUNCTION(inv, AccuracyTargetValid)
 MUTATOR_HOOKFUNCTION(inv, AllowMobSpawning)
 {
        // monster spawning disabled during an invasion
+       M_ARGV(1, string) = "You cannot spawn monsters during an invasion!";
        return true;
 }
 
 MUTATOR_HOOKFUNCTION(inv, GetTeamCount, CBC_ORDER_EXCLUSIVE)
 {
-       ret_float = invasion_teams;
-       return false;
+       M_ARGV(0, float) = invasion_teams;
 }
 
 MUTATOR_HOOKFUNCTION(inv, AllowMobButcher)
 {
-       ret_string = "This command does not work during an invasion!";
+       M_ARGV(0, string) = "This command does not work during an invasion!";
        return true;
 }
 
@@ -483,7 +490,7 @@ void invasion_ScoreRules(float inv_teams)
        ScoreRules_basics_end();
 }
 
-void invasion_DelayedInit() // Do this check with a delay so we can wait for teams to be set up.
+void invasion_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up.
 {
        if(autocvar_g_invasion_teams)
                invasion_teams = bound(2, autocvar_g_invasion_teams, 4);