]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/gamemode_invasion.qc
mapinfo: remove some IS_GAMETYPE macros
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / gamemode_invasion.qc
index c5f71ea1f376ed60487ec1e841b41b4c51a33fe0..e752da96eba32a61aba4a058d90b60d5c572f827 100644 (file)
@@ -1,26 +1,41 @@
 #include "gamemode_invasion.qh"
-#include "../_all.qh"
 
 #include "gamemode.qh"
 
 #include "../../common/monsters/spawn.qh"
 #include "../../common/monsters/sv_monsters.qh"
 
-void spawnfunc_invasion_spawnpoint()
+#include "../teamplay.qh"
+
+bool g_invasion;
+
+float autocvar_g_invasion_round_timelimit;
+int autocvar_g_invasion_teams;
+bool autocvar_g_invasion_team_spawns;
+float autocvar_g_invasion_spawnpoint_spawn_delay;
+#define autocvar_g_invasion_point_limit cvar("g_invasion_point_limit")
+float autocvar_g_invasion_warmup;
+int autocvar_g_invasion_monster_count;
+bool autocvar_g_invasion_zombies_only;
+float autocvar_g_invasion_spawn_delay;
+
+spawnfunc(invasion_spawnpoint)
 {
        if(!g_invasion) { remove(self); return; }
 
        self.classname = "invasion_spawnpoint";
 
        if(autocvar_g_invasion_zombies_only) // precache only if it hasn't been already
-       if(self.monsterid)
-               MON_ACTION(self.monsterid, MR_PRECACHE);
+       if(self.monsterid) {
+               Monster mon = get_monsterinfo(self.monsterid);
+               mon.mr_precache(mon);
+       }
 }
 
 float invasion_PickMonster(float supermonster_count)
 {
        if(autocvar_g_invasion_zombies_only)
-               return MON_ZOMBIE;
+               return MON_ZOMBIE.monsterid;
 
        float i;
        entity mon;
@@ -62,7 +77,7 @@ void invasion_SpawnChosenMonster(float mon)
 
        if(spawn_point == world)
        {
-               dprint("Warning: couldn't find any invasion_spawnpoint spawnpoints, attempting to spawn monsters in random locations\n");
+               LOG_TRACE("Warning: couldn't find any invasion_spawnpoint spawnpoints, attempting to spawn monsters in random locations\n");
                entity e = spawn();
                setsize(e, (get_monsterinfo(mon)).mins, (get_monsterinfo(mon)).maxs);
 
@@ -126,7 +141,7 @@ float Invasion_CheckWinner()
        if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
        {
                FOR_EACH_MONSTER(head)
-                       monster_remove(head);
+                       Monster_Remove(head);
 
                Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
                Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
@@ -203,7 +218,7 @@ float Invasion_CheckWinner()
        }
 
        FOR_EACH_MONSTER(head)
-               monster_remove(head);
+               Monster_Remove(head);
 
        if(teamplay)
        {
@@ -260,8 +275,8 @@ void Invasion_RoundStart()
        }
 }
 
-MUTATOR_HOOKFUNCTION(invasion_MonsterDies)
-{
+MUTATOR_HOOKFUNCTION(invMonsterDies)
+{SELFPARAM();
        if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
        {
                inv_numkilled += 1;
@@ -282,8 +297,8 @@ MUTATOR_HOOKFUNCTION(invasion_MonsterDies)
        return false;
 }
 
-MUTATOR_HOOKFUNCTION(invasion_MonsterSpawn)
-{
+MUTATOR_HOOKFUNCTION(invMonsterSpawn)
+{SELFPARAM();
        if(!(self.spawnflags & MONSTERFLAG_SPAWNED))
                return true;
 
@@ -296,15 +311,15 @@ MUTATOR_HOOKFUNCTION(invasion_MonsterSpawn)
        self.monster_skill = inv_monsterskill;
 
        if((get_monsterinfo(self.monsterid)).spawnflags & MON_FLAG_SUPERMONSTER)
-               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_INVASION_SUPERMONSTER, M_NAME(self.monsterid));
+               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_INVASION_SUPERMONSTER, self.monster_name);
 
        self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_BOTCLIP | DPCONTENTS_MONSTERCLIP;
 
        return false;
 }
 
-MUTATOR_HOOKFUNCTION(invasion_OnEntityPreSpawn)
-{
+MUTATOR_HOOKFUNCTION(invOnEntityPreSpawn)
+{SELFPARAM();
        if(startsWith(self.classname, "monster_"))
        if(!(self.spawnflags & MONSTERFLAG_SPAWNED))
                return true;
@@ -312,7 +327,7 @@ MUTATOR_HOOKFUNCTION(invasion_OnEntityPreSpawn)
        return false;
 }
 
-MUTATOR_HOOKFUNCTION(invasion_StartFrame)
+MUTATOR_HOOKFUNCTION(inv, SV_StartFrame)
 {
        monsters_total = inv_maxspawned; // TODO: make sure numspawned never exceeds maxspawned
        monsters_killed = inv_numkilled;
@@ -320,19 +335,19 @@ MUTATOR_HOOKFUNCTION(invasion_StartFrame)
        return false;
 }
 
-MUTATOR_HOOKFUNCTION(invasion_PlayerRegen)
+MUTATOR_HOOKFUNCTION(invPlayerRegen)
 {
        // no regeneration in invasion
        return true;
 }
 
-MUTATOR_HOOKFUNCTION(invasion_PlayerSpawn)
-{
+MUTATOR_HOOKFUNCTION(invPlayerSpawn)
+{SELFPARAM();
        self.bot_attack = false;
        return false;
 }
 
-MUTATOR_HOOKFUNCTION(invasion_PlayerDamage)
+MUTATOR_HOOKFUNCTION(inv, PlayerDamage_Calculate)
 {
        if(IS_PLAYER(frag_attacker) && IS_PLAYER(frag_target) && frag_attacker != frag_target)
        {
@@ -343,8 +358,8 @@ MUTATOR_HOOKFUNCTION(invasion_PlayerDamage)
        return false;
 }
 
-MUTATOR_HOOKFUNCTION(invasion_PlayerCommand)
-{
+MUTATOR_HOOKFUNCTION(inv, SV_ParseClientCommand)
+{SELFPARAM();
        if(MUTATOR_RETURNVALUE) // command was already handled?
                return false;
 
@@ -364,41 +379,46 @@ MUTATOR_HOOKFUNCTION(invasion_PlayerCommand)
        return false;
 }
 
-MUTATOR_HOOKFUNCTION(invasion_BotShouldAttack)
+MUTATOR_HOOKFUNCTION(invBotShouldAttack)
 {
-       if(!(checkentity.flags & FL_MONSTER))
+       if(!IS_MONSTER(checkentity))
                return true;
 
        return false;
 }
 
-MUTATOR_HOOKFUNCTION(invasion_SetStartItems)
+MUTATOR_HOOKFUNCTION(invSetStartItems)
 {
        start_health = 200;
        start_armorvalue = 200;
-
        return false;
 }
 
-MUTATOR_HOOKFUNCTION(invasion_AccuracyTargetValid)
+MUTATOR_HOOKFUNCTION(invAccuracyTargetValid)
 {
-       if(frag_target.flags & FL_MONSTER)
+       if(IS_MONSTER(frag_target))
                return MUT_ACCADD_INVALID;
        return MUT_ACCADD_INDIFFERENT;
 }
 
-MUTATOR_HOOKFUNCTION(invasion_AllowMobSpawning)
+MUTATOR_HOOKFUNCTION(invAllowMobSpawning)
 {
        // monster spawning disabled during an invasion
        return true;
 }
 
-MUTATOR_HOOKFUNCTION(invasion_GetTeamCount)
+MUTATOR_HOOKFUNCTION(inv, GetTeamCount, CBC_ORDER_EXCLUSIVE)
 {
        ret_float = invasion_teams;
        return false;
 }
 
+MUTATOR_HOOKFUNCTION(inv, AllowMobButcher)
+{
+       ret_string = "This command does not work during an invasion!";
+       return true;
+}
+
 void invasion_ScoreRules(float inv_teams)
 {
        if(inv_teams) { CheckAllowedTeams(world); }
@@ -430,9 +450,10 @@ void invasion_DelayedInit() // Do this check with a delay so we can wait for tea
 
 void invasion_Initialize()
 {
-       if(autocvar_g_invasion_zombies_only)
-               MON_ACTION(MON_ZOMBIE, MR_PRECACHE);
-       else
+       if(autocvar_g_invasion_zombies_only) {
+               Monster mon = MON_ZOMBIE;
+               mon.mr_precache(mon);
+       } else
        {
                float i;
                entity mon;
@@ -442,33 +463,28 @@ void invasion_Initialize()
                        if((mon.spawnflags & MONSTER_TYPE_FLY) || (mon.spawnflags & MONSTER_TYPE_SWIM))
                                continue; // flying/swimming monsters not yet supported
 
-                       MON_ACTION(i, MR_PRECACHE);
+                       mon.mr_precache(mon);
                }
        }
 
        InitializeEntity(world, invasion_DelayedInit, INITPRIO_GAMETYPE);
 }
 
-MUTATOR_DEFINITION(gamemode_invasion)
+REGISTER_MUTATOR(inv, IS_GAMETYPE(INVASION))
 {
-       MUTATOR_HOOK(MonsterDies, invasion_MonsterDies, CBC_ORDER_ANY);
-       MUTATOR_HOOK(MonsterSpawn, invasion_MonsterSpawn, CBC_ORDER_ANY);
-       MUTATOR_HOOK(OnEntityPreSpawn, invasion_OnEntityPreSpawn, CBC_ORDER_ANY);
-       MUTATOR_HOOK(SV_StartFrame, invasion_StartFrame, CBC_ORDER_ANY);
-       MUTATOR_HOOK(PlayerRegen, invasion_PlayerRegen, CBC_ORDER_ANY);
-       MUTATOR_HOOK(PlayerSpawn, invasion_PlayerSpawn, CBC_ORDER_ANY);
-       MUTATOR_HOOK(PlayerDamage_Calculate, invasion_PlayerDamage, CBC_ORDER_ANY);
-       MUTATOR_HOOK(SV_ParseClientCommand, invasion_PlayerCommand, CBC_ORDER_ANY);
-       MUTATOR_HOOK(BotShouldAttack, invasion_BotShouldAttack, CBC_ORDER_ANY);
-       MUTATOR_HOOK(SetStartItems, invasion_SetStartItems, CBC_ORDER_ANY);
-       MUTATOR_HOOK(AccuracyTargetValid, invasion_AccuracyTargetValid, CBC_ORDER_ANY);
-       MUTATOR_HOOK(AllowMobSpawning, invasion_AllowMobSpawning, CBC_ORDER_ANY);
-       MUTATOR_HOOK(GetTeamCount, invasion_GetTeamCount, CBC_ORDER_ANY);
+       SetLimits(autocvar_g_invasion_point_limit, -1, -1, -1);
+       if(autocvar_g_invasion_teams >= 2)
+       {
+               ActivateTeamplay();
+               if(autocvar_g_invasion_team_spawns)
+                       have_team_spawns = -1; // request team spawns
+       }
 
        MUTATOR_ONADD
        {
                if(time > 1) // game loads at time 1
                        error("This is a game type and it cannot be added at runtime.");
+               g_invasion = true;
                invasion_Initialize();
 
                cvar_settemp("g_monsters", "1");
@@ -483,7 +499,7 @@ MUTATOR_DEFINITION(gamemode_invasion)
 
        MUTATOR_ONREMOVE
        {
-               print("This is a game type and it cannot be removed at runtime.");
+               LOG_INFO("This is a game type and it cannot be removed at runtime.");
                return -1;
        }