]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/gamemodes/gamemode/clanarena/sv_clanarena.qc
Remove redundant .team initialization in MUTATOR_HOOKFUNCTION(ca, reset_map_players...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / clanarena / sv_clanarena.qc
index 3d0c292617f9596d0c0ce3c68d9cf374e23de8e5..7803108c6c00010cb896fce7fde81da0fbfebc00 100644 (file)
@@ -1,6 +1,6 @@
 #include "sv_clanarena.qh"
 
-float autocvar_g_ca_damage2score_multiplier;
+float autocvar_g_ca_damage2score = 100;
 bool autocvar_g_ca_spectate_enemies;
 
 float autocvar_g_ca_start_health = 200;
@@ -12,6 +12,8 @@ float autocvar_g_ca_start_ammo_cells = 180;
 float autocvar_g_ca_start_ammo_plasma = 180;
 float autocvar_g_ca_start_ammo_fuel = 0;
 
+.float ca_damage_counter;
+
 void CA_count_alive_players()
 {
        total_players = 0;
@@ -125,9 +127,9 @@ bool CA_CheckTeams()
 
 bool ca_isEliminated(entity e)
 {
-       if(e.caplayer == 1 && (IS_DEAD(e) || e.frags == FRAGS_PLAYER_OUT_OF_GAME))
+       if(INGAME_JOINED(e) && (IS_DEAD(e) || e.frags == FRAGS_PLAYER_OUT_OF_GAME))
                return true;
-       if(e.caplayer == 0.5)
+       if(INGAME_JOINING(e))
                return true;
        return false;
 }
@@ -154,7 +156,9 @@ MUTATOR_HOOKFUNCTION(ca, PlayerSpawn)
 {
        entity player = M_ARGV(0, entity);
 
-       player.caplayer = 1;
+       INGAME_STATUS_SET(player, INGAME_STATUS_JOINED);
+       if (time <= game_starttime) // reset on game restart, not on round start
+               player.ca_damage_counter = 0;
        if (!warmup_stage)
                eliminatedPlayers.SendFlags |= 1;
 }
@@ -166,7 +170,7 @@ MUTATOR_HOOKFUNCTION(ca, ForbidSpawn)
        // spectators / observers that weren't playing can join; they are
        // immediately forced to observe in the PutClientInServer hook
        // this way they are put in a team and can play in the next round
-       if (!allowed_to_spawn && player.caplayer)
+       if (!allowed_to_spawn && INGAME(player))
                return true;
        return false;
 }
@@ -178,9 +182,9 @@ MUTATOR_HOOKFUNCTION(ca, PutClientInServer)
        if (!allowed_to_spawn && IS_PLAYER(player)) // this is true even when player is trying to join
        {
                TRANSMUTE(Observer, player);
-               if (CS(player).jointime != time && !player.caplayer) // not when connecting
+               if (CS(player).jointime != time && !INGAME(player)) // not when connecting
                {
-                       player.caplayer = 0.5;
+                       INGAME_STATUS_SET(player, INGAME_STATUS_JOINING);
                        Send_Notification(NOTIF_ONE_ONLY, player, MSG_INFO, INFO_CA_JOIN_LATE);
                }
        }
@@ -190,15 +194,10 @@ MUTATOR_HOOKFUNCTION(ca, reset_map_players)
 {
        FOREACH_CLIENT(true, {
                CS(it).killcount = 0;
-               if (!it.caplayer && IS_BOT_CLIENT(it))
-               {
-                       it.team = -1;
-                       it.caplayer = 1;
-               }
-               if (it.caplayer)
+               if (INGAME(it) || IS_BOT_CLIENT(it))
                {
                        TRANSMUTE(Player, it);
-                       it.caplayer = 1;
+                       INGAME_STATUS_SET(it, INGAME_STATUS_JOINED);
                        PutClientInServer(it);
                }
        });
@@ -259,6 +258,7 @@ MUTATOR_HOOKFUNCTION(ca, PlayerDies)
        return true;
 }
 
+
 MUTATOR_HOOKFUNCTION(ca, ClientDisconnect)
 {
        entity player = M_ARGV(0, entity);
@@ -273,21 +273,21 @@ MUTATOR_HOOKFUNCTION(ca, MakePlayerObserver)
        entity player = M_ARGV(0, entity);
 
        bool is_forced = M_ARGV(1, bool);
-       if (is_forced && player.caplayer)
-               player.caplayer = 0;
+       if (is_forced && INGAME(player))
+               INGAME_STATUS_CLEAR(player);
 
        if (IS_PLAYER(player) && !IS_DEAD(player))
                ca_LastPlayerForTeam_Notify(player);
        if (player.killindicator_teamchange == -2) // player wants to spectate
        {
                entcs_update_players(player);
-               player.caplayer = 0;
+               INGAME_STATUS_CLEAR(player);
        }
-       if (player.caplayer)
+       if (INGAME(player))
                player.frags = FRAGS_PLAYER_OUT_OF_GAME;
        if (!warmup_stage)
                eliminatedPlayers.SendFlags |= 1;
-       if (!player.caplayer)
+       if (!INGAME(player))
                return false;  // allow team reset
        return true;  // prevent team reset
 }
@@ -364,28 +364,42 @@ MUTATOR_HOOKFUNCTION(ca, PlayerDamage_SplitHealthArmor)
 
        float excess = max(0, frag_damage - damage_take - damage_save);
 
-       //non-friendly fire
-       if (frag_target != frag_attacker && IS_PLAYER(frag_attacker) && DIFF_TEAM(frag_target, frag_attacker))
-               GameRules_scoring_add_team(frag_attacker, SCORE, (frag_damage - excess) * autocvar_g_ca_damage2score_multiplier);
-
-       //friendly fire
-       if (SAME_TEAM(frag_target, frag_attacker))
-               GameRules_scoring_add_team(frag_attacker, SCORE, (-1 * (frag_damage - excess)) * autocvar_g_ca_damage2score_multiplier);
-
-       //handle (environmental hazard) suiciding, check first if player has a registered attacker who most likely pushed them there to avoid punishing pushed players as pushers are already rewarded
-       //deathtypes:
-       //kill = suicide, drown = drown in water/liquid, hurttrigger = out of the map void or hurt triggers inside maps like electric sparks
-       //camp = campcheck, lava = lava, slime = slime
-       //team change / rebalance suicides are currently not included
-       if (!IS_PLAYER(frag_attacker) && (
-               frag_deathtype == DEATH_KILL.m_id ||
-               frag_deathtype == DEATH_DROWN.m_id ||
-               frag_deathtype == DEATH_HURTTRIGGER.m_id ||
-               frag_deathtype == DEATH_CAMP.m_id ||
-               frag_deathtype == DEATH_LAVA.m_id ||
-               frag_deathtype == DEATH_SLIME.m_id ||
-               frag_deathtype == DEATH_SWAMP.m_id))
-                       GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * autocvar_g_ca_damage2score_multiplier);
+       if (autocvar_g_ca_damage2score <= 0 || frag_damage - excess == 0) return;
+
+       entity scorer = NULL;
+       float scorer_damage = 0;
+
+       if (IS_PLAYER(frag_attacker))
+       {
+               if (DIFF_TEAM(frag_target, frag_attacker))
+                       scorer_damage = frag_damage - excess;
+               else // friendly fire
+                       scorer_damage = -(frag_damage - excess);
+
+               scorer = frag_attacker;
+       }
+       else
+       {
+               //handle (environmental hazard) suiciding, check first if player has a registered attacker who most likely pushed them there to avoid punishing pushed players as pushers are already rewarded
+               //deathtypes:
+               //kill = suicide, drown = drown in water/liquid, hurttrigger = out of the map void or hurt triggers inside maps like electric sparks
+               //camp = campcheck, lava = lava, slime = slime
+               //team change / rebalance suicides are currently not included
+               if (frag_deathtype == DEATH_KILL.m_id ||
+                       frag_deathtype == DEATH_DROWN.m_id ||
+                       frag_deathtype == DEATH_HURTTRIGGER.m_id ||
+                       frag_deathtype == DEATH_CAMP.m_id ||
+                       frag_deathtype == DEATH_LAVA.m_id ||
+                       frag_deathtype == DEATH_SLIME.m_id ||
+                       frag_deathtype == DEATH_SWAMP.m_id)
+               {
+                       scorer_damage = -(frag_damage - excess);
+                       scorer = frag_target;
+               }
+       }
+
+       if (scorer)
+               GameRules_scoring_add_float2int(scorer, SCORE, scorer_damage, ca_damage_counter, autocvar_g_ca_damage2score);
 }
 
 MUTATOR_HOOKFUNCTION(ca, CalculateRespawnTime)
@@ -411,7 +425,7 @@ MUTATOR_HOOKFUNCTION(ca, SpectateSet)
        entity client = M_ARGV(0, entity);
        entity targ = M_ARGV(1, entity);
 
-       if (!autocvar_g_ca_spectate_enemies && client.caplayer)
+       if (!autocvar_g_ca_spectate_enemies && INGAME(client))
        if (DIFF_TEAM(targ, client))
                return true;
 }
@@ -420,7 +434,7 @@ MUTATOR_HOOKFUNCTION(ca, SpectateNext)
 {
        entity client = M_ARGV(0, entity);
 
-       if (!autocvar_g_ca_spectate_enemies && client.caplayer
+       if (!autocvar_g_ca_spectate_enemies && INGAME(client)
                && Team_GetNumberOfAlivePlayers(Entity_GetTeam(client)))
        {
                entity targ = M_ARGV(1, entity);
@@ -435,7 +449,7 @@ MUTATOR_HOOKFUNCTION(ca, SpectatePrev)
        entity targ = M_ARGV(1, entity);
        entity first = M_ARGV(2, entity);
 
-       if (!autocvar_g_ca_spectate_enemies && client.caplayer
+       if (!autocvar_g_ca_spectate_enemies && INGAME(client)
                && Team_GetNumberOfAlivePlayers(Entity_GetTeam(client)))
        {
                do { targ = targ.chain; }
@@ -460,7 +474,7 @@ MUTATOR_HOOKFUNCTION(ca, SpectatePrev)
 MUTATOR_HOOKFUNCTION(ca, Bot_FixCount, CBC_ORDER_EXCLUSIVE)
 {
        FOREACH_CLIENT(IS_REAL_CLIENT(it), {
-               if (IS_PLAYER(it) || it.caplayer == 1)
+               if (IS_PLAYER(it) || INGAME_JOINED(it))
                        ++M_ARGV(0, int);
                ++M_ARGV(1, int);
        });
@@ -471,7 +485,7 @@ MUTATOR_HOOKFUNCTION(ca, ClientCommand_Spectate)
 {
        entity player = M_ARGV(0, entity);
 
-       if (player.caplayer)
+       if (INGAME(player))
        {
                // they're going to spec, we can do other checks
                if (autocvar_sv_spectate && (IS_SPEC(player) || IS_OBSERVER(player)))
@@ -487,13 +501,6 @@ MUTATOR_HOOKFUNCTION(ca, HideTeamNagger)
        return true; // doesn't work well with the whole spectator as player thing
 }
 
-MUTATOR_HOOKFUNCTION(ca, GetPlayerStatus)
-{
-       entity player = M_ARGV(0, entity);
-
-       return player.caplayer == 1;
-}
-
 MUTATOR_HOOKFUNCTION(ca, SetWeaponArena)
 {
        if (M_ARGV(0, string) == "0" || M_ARGV(0, string) == "")