From 5af44fa27a76624ccdd1c7038453bee0028dec7b Mon Sep 17 00:00:00 2001 From: Kp Date: Thu, 14 Jul 2016 01:59:03 +0000 Subject: [PATCH] Refactor to propagate MultiLevelInv_Count `initial` All callers of MultiLevelInv_Count passed a constant value. Factor out the top level blocks of MultiLevelInv_Count into helper functions, then create two new functions corresponding to MultiLevelInv_Count(0) and MultiLevelInv_Count(1), implemented by calling the appropriate new helper functions. --- common/main/multi.h | 3 ++- similar/main/fireball.cpp | 2 +- similar/main/multi.cpp | 29 +++++++++++++++++++---------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/common/main/multi.h b/common/main/multi.h index 8ef110939..ce1b9e4fb 100644 --- a/common/main/multi.h +++ b/common/main/multi.h @@ -735,7 +735,8 @@ extern struct netgame_info Netgame; void change_playernum_to(int new_pnum); // Multiplayer powerup capping -extern void MultiLevelInv_Count(bool initial); +void MultiLevelInv_InitializeCount(); +void MultiLevelInv_Recount(); extern bool MultiLevelInv_AllowSpawn(powerup_type_t powerup_type); extern void MultiLevelInv_Repopulate(fix frequency); #ifdef dsx diff --git a/similar/main/fireball.cpp b/similar/main/fireball.cpp index 6941c8c5f..d659c23a4 100644 --- a/similar/main/fireball.cpp +++ b/similar/main/fireball.cpp @@ -610,7 +610,7 @@ void maybe_drop_net_powerup(powerup_type_t powerup_type, bool adjust_cap, bool r if ((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_COOP)) { if ((Game_mode & GM_NETWORK) && adjust_cap) { - MultiLevelInv_Count(0); // recount current items + MultiLevelInv_Recount(); // recount current items if (!MultiLevelInv_AllowSpawn(powerup_type)) return; } diff --git a/similar/main/multi.cpp b/similar/main/multi.cpp index ba4f69174..2b6e70e40 100644 --- a/similar/main/multi.cpp +++ b/similar/main/multi.cpp @@ -3316,7 +3316,7 @@ void multi_prep_level_objects() } // After everything is done, count initial level inventory. - MultiLevelInv_Count(1); + MultiLevelInv_InitializeCount(); } void multi_prep_level_player(void) @@ -4909,12 +4909,10 @@ static void multi_do_player_inventory(const playernum_t pnum, const ubyte *buf) * In 'current', also consider player inventories (and the thief bot). * NOTE: We add actual ammo amount - we do not want to count in 'amount of powerups'. Makes it easier to keep track of overhead (proximities, vulcan ammo) */ -void MultiLevelInv_Count(bool initial) +static void MultiLevelInv_CountLevelPowerups() { if (!(Game_mode & GM_MULTI) || (Game_mode & GM_MULTI_COOP)) return; - if (initial) - MultiLevelInv = {}; MultiLevelInv.Current = {}; range_for (const auto &&objp, vobjptridx) @@ -4992,11 +4990,10 @@ void MultiLevelInv_Count(bool initial) break; // All other items either do not exist or we NEVER want to have them respawn. } } +} - if (initial) // Copy current to initial - MultiLevelInv.Initial = MultiLevelInv.Current; - else // Add player inventories to current - { +static void MultiLevelInv_CountPlayerInventory() +{ for (playernum_t i = 0; i < MAX_PLAYERS; i++) { if (Players[i].connected != CONNECT_PLAYING) @@ -5096,7 +5093,19 @@ void MultiLevelInv_Count(bool initial) } } #endif - } +} + +void MultiLevelInv_InitializeCount() +{ + MultiLevelInv = {}; + MultiLevelInv_CountLevelPowerups(); + MultiLevelInv.Initial = MultiLevelInv.Current; +} + +void MultiLevelInv_Recount() +{ + MultiLevelInv_CountLevelPowerups(); + MultiLevelInv_CountPlayerInventory(); } // Takes a powerup type and checks if we are allowed to spawn it. @@ -5129,7 +5138,7 @@ void MultiLevelInv_Repopulate(fix frequency) if (!multi_i_am_master() || (Game_mode & GM_MULTI_COOP) || Control_center_destroyed || (Network_status == NETSTAT_ENDLEVEL)) return; - MultiLevelInv_Count(0); // recount current items + MultiLevelInv_Recount(); // recount current items for (unsigned i = 0; i < MAX_POWERUP_TYPES; i++) { if (MultiLevelInv_AllowSpawn((powerup_type_t)i))