]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Started work on coop survival.
authorLyberta <lyberta@lyberta.net>
Thu, 23 Mar 2017 10:55:34 +0000 (13:55 +0300)
committerLyberta <lyberta@lyberta.net>
Thu, 23 Mar 2017 10:55:34 +0000 (13:55 +0300)
qcsrc/server/mutators/mutator/gamemode_survival.qc
survival.cfg

index 0d626a55f7b81d2c92d70b132b7825429b8fce53..c5c1eb4b618435856c66785d16f3d1c48ca701b5 100644 (file)
@@ -14,6 +14,15 @@ const int SURVIVAL_TEAM_BITS = 3;
 const int SURVIVAL_COLOR_RED = NUM_TEAM_1 - 1; ///< Used to reference the red.
 const int SURVIVAL_COLOR_BLUE = NUM_TEAM_2 - 1; ///< Used to reference the blue.
 
+enum
+{
+       SURVIVAL_TYPE_COOP, ///< All humans are on the defender team.
+       SURVIVAL_TYPE_VERSUS ///< Humans take turns between attackers and defenders.
+};
+
+const string SURVIVAL_TYPE_COOP_VALUE = "coop"; ///< Cvar value for coop.
+const string SURVIVAL_TYPE_VERSUS_VALUE = "versus"; ///< Cvar value for versus.
+
 enum
 {
        /// \brief First round where there is timelimit set by the server.
@@ -136,6 +145,7 @@ float autocvar_g_surv_cannon_fodder_defense_scale;
 
 .entity surv_attack_sprite; ///< Holds the sprite telling attackers to attack.
 
+int surv_type; ///< Holds the type of survival. See SURVIVAL_TYPE constants.
 /// \brief Holds the type of the current round. See SURVIVAL_ROUND constants.
 int surv_roundtype;
 bool surv_isroundactive; ///< Holds whether the round is active.
@@ -199,6 +209,23 @@ void Surv_UpdateDefenderHealthStat();
 
 void Surv_Initialize()
 {
+       switch (cvar_string("g_surv_type"))
+       {
+               case SURVIVAL_TYPE_COOP_VALUE:
+               {
+                       surv_type = SURVIVAL_TYPE_COOP;
+                       break;
+               }
+               case SURVIVAL_TYPE_VERSUS_VALUE:
+               {
+                       surv_type = SURVIVAL_TYPE_VERSUS;
+                       break;
+               }
+               default:
+               {
+                       error("Invalid survival type.");
+               }
+       }
        surv_roundtype = SURVIVAL_ROUND_FIRST;
        surv_isroundactive = false;
        surv_roundstarttime = time;
@@ -783,14 +810,21 @@ void Surv_RoundCleanup()
        surv_allowed_to_spawn = false;
        surv_isroundactive = false;
        game_stopped = true;
-       FOREACH_CLIENT(true, {
+       FOREACH_CLIENT(true,
+       {
                if (it.surv_attack_sprite)
                {
                        WaypointSprite_Kill(it.surv_attack_sprite);
                }
        });
-       Surv_SwitchRoundType();
-       round_handler_Init(5, autocvar_g_surv_warmup, surv_timetobeat);
+       if (surv_type == SURVIVAL_TYPE_VERSUS)
+       {
+               Surv_SwitchRoundType();
+               round_handler_Init(5, autocvar_g_surv_warmup, surv_timetobeat);
+               return;
+       }
+       round_handler_Init(5, autocvar_g_surv_warmup,
+               autocvar_g_surv_round_timelimit);
 }
 
 /// \brief Swaps attacker and defender teams.
@@ -1014,6 +1048,11 @@ void Surv_RoundStart()
        {
                case SURVIVAL_ROUND_FIRST:
                {
+                       if (surv_type == SURVIVAL_TYPE_COOP)
+                       {
+                               defendmessage = "^3Defend yourself ^2as long as you can^3.";
+                               break;
+                       }
                        attackmessage = "^3First round. Eliminate the enemy team ^2as fast as you can^3.";
                        defendmessage = "^3First round. Defend yourself ^2as long as you can^3.";
                        break;
@@ -1138,6 +1177,16 @@ MUTATOR_HOOKFUNCTION(surv, CheckAllowedTeams, CBC_ORDER_EXCLUSIVE)
        LOG_TRACE("SURVIVAL: CheckAllowedTeams, player = ", player.netname);
        if (!IS_BOT_CLIENT(player))
        {
+               if (surv_type == SURVIVAL_TYPE_COOP)
+               {
+                       if (surv_numdefenderhumans < autocvar_g_surv_team_size)
+                       {
+                               M_ARGV(0, float) = surv_defenderteambit;
+                               return;
+                       }
+                       M_ARGV(0, float) = 0;
+                       return;
+               }
                int teambits = 0;
                if (surv_numattackerhumans < autocvar_g_surv_team_size)
                {
@@ -1276,7 +1325,10 @@ MUTATOR_HOOKFUNCTION(surv, reset_map_players)
 {
        LOG_TRACE("SURVIVAL: reset_map_players");
        //DebugPrintToChatAll("reset_map_players");
-       Surv_SwapTeams();
+       if (surv_type == SURVIVAL_TYPE_VERSUS)
+       {
+               Surv_SwapTeams();
+       }
        FOREACH_CLIENT(true,
        {
                it.killcount = 0;
@@ -1754,12 +1806,6 @@ MUTATOR_HOOKFUNCTION(surv, PlayerDamaged)
        WaypointSprite_UpdateHealth(target.surv_attack_sprite, target.health);
 }
 
-//MUTATOR_HOOKFUNCTION(surv, ClientKill)
-//{
-       //FOREACH_CLIENT(true, { centerprint(it, "ClientKill"); });
-       //entity player = M_ARGV(0, entity);
-//}
-
 /// \brief Hook which is called when the player dies.
 MUTATOR_HOOKFUNCTION(surv, PlayerDies)
 {
index 591def08348c5d0ad085c25b2a1dcb2767be7536..6cdf5c5e6ab2fc1fe99b8978f1a4966e782e94d6 100644 (file)
@@ -13,6 +13,7 @@ set g_surv_respawn_waves 0
 set g_surv_weapon_stay 0
 
 set g_surv 0 "Survival: survive as long as you can"
+set g_surv_type "versus" "Type of the survival gametype"
 set g_surv_warmup 10 "How long the players will have time to run around the map before the round starts"
 set g_surv_round_timelimit 300 "Round time limit in seconds"
 seta g_surv_point_limit -1 "Survival point limit overriding the mapinfo specified one (use 0 to play without limit, and -1 to use the mapinfo's limit)"