]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'master' into Mario/invasion_types
authorMario <mario@smbclan.net>
Sat, 26 Aug 2017 15:19:52 +0000 (01:19 +1000)
committerMario <mario@smbclan.net>
Sat, 26 Aug 2017 15:19:52 +0000 (01:19 +1000)
# Conflicts:
# qcsrc/server/mutators/mutator/gamemode_invasion.qc

gamemodes-server.cfg
qcsrc/common/mapinfo.qh
qcsrc/server/g_world.qc
qcsrc/server/mutators/mutator/gamemode_invasion.qc
qcsrc/server/mutators/mutator/gamemode_invasion.qh

index cfe8e319e52abeaf75cbe1f865d407dfa62589f8..6790a3b4fb9575ab91e070c57bc984ac97609ba2 100644 (file)
@@ -521,3 +521,4 @@ set g_invasion_spawn_delay 0.25
 set g_invasion_spawnpoint_spawn_delay 0.5
 set g_invasion_teams 0 "number of teams in invasion (note: use mapinfo to set this)"
 set g_invasion_team_spawns 1 "use team spawns in teamplay invasion mode"
+set g_invasion_type 0 "type of invasion mode - 0: round-based, 1: hunting, 2: complete the stage (note: use mapinfo to set this)"
index 4c0fd782904bab4993f0839d428210bb42b2746d..2dd84596e46991e8f3f75daeb63b524273825d01 100644 (file)
@@ -458,7 +458,7 @@ REGISTER_GAMETYPE(KEEPAWAY, NEW(Keepaway));
 CLASS(Invasion, Gametype)
     INIT(Invasion)
     {
-        this.gametype_init(this, _("Invasion"),"inv","g_invasion",false,"","pointlimit=50 teams=0",_("Survive against waves of monsters"));
+        this.gametype_init(this, _("Invasion"),"inv","g_invasion",false,"","pointlimit=50 teams=0 type=0",_("Survive against waves of monsters"));
     }
     METHOD(Invasion, m_parse_mapinfo, bool(string k, string v))
     {
@@ -466,6 +466,9 @@ CLASS(Invasion, Gametype)
             case "teams":
                 cvar_set("g_invasion_teams", v);
                 return true;
+            case "type":
+                cvar_set("g_invasion_type", v);
+                return true;
         }
         return false;
     }
index 2812da09d08cd5b6e26a3c9407bc43d17bdf3a3b..4a851b18d08f76b25f2b73b00c5f449185f6352c 100644 (file)
@@ -272,6 +272,7 @@ void cvar_changes_init()
                BADCVAR("g_freezetag");
                BADCVAR("g_freezetag_teams");
                BADCVAR("g_invasion_teams");
+               BADCVAR("g_invasion_type");
                BADCVAR("g_jailbreak");
                BADCVAR("g_jailbreak_teams");
                BADCVAR("g_keepaway");
index fabcc26f62cb26bef62edda59104324330421a82..b7aa99498557c6035d0b3ed0be46e79d5d1448e5 100644 (file)
@@ -5,6 +5,9 @@
 
 #include <server/teamplay.qh>
 
+IntrusiveList g_invasion_roundends;
+STATIC_INIT(g_invasion_roundends) { g_invasion_roundends = IL_NEW(); }
+
 IntrusiveList g_invasion_waves;
 STATIC_INIT(g_invasion_waves) { g_invasion_waves = IL_NEW(); }
 
@@ -18,10 +21,46 @@ int autocvar_g_invasion_monster_count;
 bool autocvar_g_invasion_zombies_only;
 float autocvar_g_invasion_spawn_delay;
 
+bool victent_present;
+.bool inv_endreached;
+
 bool inv_warning_shown; // spammy
 
 .string spawnmob;
 
+void target_invasion_roundend_use(entity this, entity actor, entity trigger)
+{
+       if(!IS_PLAYER(actor)) { return; }
+
+       actor.inv_endreached = true;
+
+       int plnum = 0;
+       int realplnum = 0;
+       // let's not count bots
+       FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
+               ++realplnum;
+               if(it.inv_endreached)
+                       ++plnum;
+       });
+       if(plnum < ceil(realplnum * min(1, this.count))) // 70% of players
+               return;
+
+       this.winning = true;
+}
+
+spawnfunc(target_invasion_roundend)
+{
+       if(!g_invasion) { delete(this); return; }
+
+       victent_present = true; // a victory entity is present, we don't need to rely on monster count TODO: merge this with the intrusive list (can check empty)
+
+       if(!this.count) { this.count = 0.7; } // require at least 70% of the players to reach the end before triggering victory
+
+       this.use = target_invasion_roundend_use;
+
+       IL_PUSH(g_invasion_roundends, this);
+}
+
 spawnfunc(invasion_wave)
 {
        if(!g_invasion) { delete(this); return; }
@@ -37,6 +76,58 @@ spawnfunc(invasion_spawnpoint)
        IL_PUSH(g_invasion_spawns, this);
 }
 
+// Invasion stage mode winning condition: If the attackers triggered a round end (by fulfilling all objectives)
+// they win.
+int WinningCondition_Invasion()
+{
+       WinningConditionHelper(NULL); // set worldstatus
+
+       int status = WINNING_NO;
+
+       if(autocvar_g_invasion_type == INV_TYPE_STAGE)
+       {
+               SetWinners(inv_endreached, true);
+
+               int found = 0;
+               IL_EACH(g_invasion_roundends, true,
+               {
+                       ++found;
+                       if(it.winning)
+                       {
+                               bprint("Invasion: round completed.\n");
+                               // winners already set (TODO: teamplay support)
+
+                               status = WINNING_YES;
+                               break;
+                       }
+               });
+
+               if(!found)
+                       status = WINNING_YES; // just end it? TODO: should warn mapper!
+       }
+       else if(autocvar_g_invasion_type == INV_TYPE_HUNT)
+       {
+               ClearWinners();
+
+               int found = 0; // NOTE: this ends the round if no monsters are placed
+               IL_EACH(g_monsters, !(it.spawnflags & MONSTERFLAG_RESPAWNED),
+               {
+                       ++found;
+               });
+
+               if(found <= 0)
+               {
+                       FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it),
+                       {
+                               it.winning = true;
+                       });
+                       status = WINNING_YES;
+               }
+       }
+
+       return status;
+}
+
 Monster invasion_PickMonster(int supermonster_count)
 {
        RandomSelection_Init();
@@ -328,8 +419,11 @@ MUTATOR_HOOKFUNCTION(inv, MonsterDies)
 
        if(!(frag_target.spawnflags & MONSTERFLAG_RESPAWNED))
        {
-               inv_numkilled += 1;
-               inv_maxcurrent -= 1;
+               if(autocvar_g_invasion_type == INV_TYPE_ROUND)
+               {
+                       inv_numkilled += 1;
+                       inv_maxcurrent -= 1;
+               }
                if(teamplay) { inv_monsters_perteam[frag_target.team] -= 1; }
 
                if(IS_PLAYER(frag_attacker))
@@ -347,6 +441,10 @@ MUTATOR_HOOKFUNCTION(inv, MonsterDies)
 MUTATOR_HOOKFUNCTION(inv, MonsterSpawn)
 {
        entity mon = M_ARGV(0, entity);
+       mon.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_BOTCLIP | DPCONTENTS_MONSTERCLIP;
+
+       if(autocvar_g_invasion_type == INV_TYPE_HUNT)
+               return false; // allowed
 
        if(!(mon.spawnflags & MONSTERFLAG_SPAWNED))
                return true;
@@ -361,29 +459,20 @@ MUTATOR_HOOKFUNCTION(inv, MonsterSpawn)
 
        if((get_monsterinfo(mon.monsterid)).spawnflags & MON_FLAG_SUPERMONSTER)
                Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_INVASION_SUPERMONSTER, mon.monster_name);
-
-       mon.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_BOTCLIP | DPCONTENTS_MONSTERCLIP;
-}
-
-MUTATOR_HOOKFUNCTION(inv, OnEntityPreSpawn)
-{
-       entity ent = M_ARGV(0, entity);
-
-       // TODO: allow these as "rogues" or something
-       if(startsWith(ent.classname, "monster_"))
-       if(!(ent.spawnflags & MONSTERFLAG_SPAWNED))
-               return true;
 }
 
 MUTATOR_HOOKFUNCTION(inv, SV_StartFrame)
 {
+       if(autocvar_g_invasion_type != INV_TYPE_ROUND)
+               return; // uses map spawned monsters
+
        monsters_total = inv_maxspawned; // TODO: make sure numspawned never exceeds maxspawned
        monsters_killed = inv_numkilled;
 }
 
 MUTATOR_HOOKFUNCTION(inv, PlayerRegen)
 {
-       // no regeneration in invasion
+       // no regeneration in invasion, regardless of the game type
        return true;
 }
 
@@ -413,28 +502,6 @@ MUTATOR_HOOKFUNCTION(inv, Damage_Calculate)
        }
 }
 
-MUTATOR_HOOKFUNCTION(inv, SV_ParseClientCommand)
-{
-       if(MUTATOR_RETURNVALUE) // command was already handled?
-               return;
-
-       entity player = M_ARGV(0, entity);
-       string cmd_name = M_ARGV(1, string);
-
-       if(cmd_name == "debuginvasion")
-       {
-               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;
-       }
-}
-
 MUTATOR_HOOKFUNCTION(inv, BotShouldAttack)
 {
        entity targ = M_ARGV(1, entity);
@@ -445,8 +512,11 @@ MUTATOR_HOOKFUNCTION(inv, BotShouldAttack)
 
 MUTATOR_HOOKFUNCTION(inv, SetStartItems)
 {
-       start_health = 200;
-       start_armorvalue = 200;
+       if(autocvar_g_invasion_type == INV_TYPE_ROUND)
+       {
+               start_health = 200;
+               start_armorvalue = 200;
+       }
 }
 
 MUTATOR_HOOKFUNCTION(inv, AccuracyTargetValid)
@@ -465,6 +535,15 @@ MUTATOR_HOOKFUNCTION(inv, AllowMobSpawning)
        return true;
 }
 
+MUTATOR_HOOKFUNCTION(inv, CheckRules_World)
+{
+       if(autocvar_g_invasion_type == INV_TYPE_ROUND)
+               return false;
+
+       M_ARGV(0, float) = WinningCondition_Invasion();
+       return true;
+}
+
 MUTATOR_HOOKFUNCTION(inv, CheckAllowedTeams, CBC_ORDER_EXCLUSIVE)
 {
        M_ARGV(0, float) = invasion_teams;
@@ -487,6 +566,9 @@ void invasion_ScoreRules(int inv_teams)
 
 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_type == INV_TYPE_HUNT || autocvar_g_invasion_type == INV_TYPE_STAGE)
+               cvar_set("fraglimit", "0");
+
        if(autocvar_g_invasion_teams)
        {
                invasion_teams = bound(2, autocvar_g_invasion_teams, 4);
@@ -507,11 +589,14 @@ void invasion_DelayedInit(entity this) // Do this check with a delay so we can w
 
        independent_players = 0;
 
-       round_handler_Spawn(Invasion_CheckPlayers, Invasion_CheckWinner, Invasion_RoundStart);
-       round_handler_Init(5, autocvar_g_invasion_warmup, autocvar_g_invasion_round_timelimit);
+       if(autocvar_g_invasion_type == INV_TYPE_ROUND)
+       {
+               round_handler_Spawn(Invasion_CheckPlayers, Invasion_CheckWinner, Invasion_RoundStart);
+               round_handler_Init(5, autocvar_g_invasion_warmup, autocvar_g_invasion_round_timelimit);
 
-       inv_roundcnt = 0;
-       inv_maxrounds = 15; // 15?
+               inv_roundcnt = 0;
+               inv_maxrounds = 15; // 15?
+       }
 }
 
 void invasion_Initialize()
index e934f8745a4e29bfbcee542ee2c9b1793ea815df..98322bcac0fcbcbb0ebfc570ff9c61b6449c3f9b 100644 (file)
@@ -4,6 +4,7 @@
 
 #define autocvar_g_invasion_point_limit cvar("g_invasion_point_limit")
 int autocvar_g_invasion_teams;
+int autocvar_g_invasion_type;
 bool autocvar_g_invasion_team_spawns;
 bool g_invasion;
 void invasion_Initialize();
@@ -58,3 +59,7 @@ float inv_monsters_perteam[17];
 float inv_monsterskill;
 
 const float ST_INV_KILLS = 1;
+
+const int INV_TYPE_ROUND = 0; // round-based waves of enemies
+const int INV_TYPE_HUNT = 1; // clear the map of placed enemies
+const int INV_TYPE_STAGE = 2; // reach the end of the level