Skip to content

Commit

Permalink
Fix bug in vassal UI (#11181)
Browse files Browse the repository at this point in the history
  • Loading branch information
axatin authored and RecursiveVision committed Aug 1, 2024
1 parent c1f7c5a commit fd54ab1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions (2) Vox Populi/Core Files/New UI/VassalageOverview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ function DoVassalStatistics( ePlayer )
local pPlayer = Players[ ePlayer ];

-- Population
Controls.VassalStatsPopulation:SetText( "([COLOR_NEGATIVE_TEXT]-" .. math.floor(math.pow(pPlayer:GetTotalPopulation(), 0.8)) .. "[ENDCOLOR][ICON_GOLD]) " .. pPlayer:GetTotalPopulation() );
Controls.VassalStatsPopulation:SetText( "([COLOR_NEGATIVE_TEXT]-" .. g_pPlayer:GetVassalGoldMaintenance(pPlayer:GetTeam(), true, false) .. "[ENDCOLOR][ICON_GOLD]) " .. pPlayer:GetTotalPopulation() );
Controls.VassalStatsPopulation:SetToolTipString( Locale.ConvertTextKey("TXT_KEY_VO_POPULATION_MAINTENANCE") );
local iHappiness = pPlayer:GetExcessHappiness();
local szHappinessLabel = "";
Expand All @@ -584,7 +584,7 @@ function DoVassalStatistics( ePlayer )

-- Economic
Controls.VassalStatsGross:SetText( pPlayer:CalculateGrossGold() );
Controls.VassalStatsGold:SetText( "([COLOR_NEGATIVE_TEXT]-" .. math.floor(pPlayer:CalculateUnitCost()*0.1) .. "[ENDCOLOR][ICON_GOLD]) " .. pPlayer:CalculateGoldRate() );
Controls.VassalStatsGold:SetText( "([COLOR_NEGATIVE_TEXT]-" .. g_pPlayer:GetVassalGoldMaintenance(pPlayer:GetTeam(), false, true) .. "[ENDCOLOR][ICON_GOLD]) " .. pPlayer:CalculateGoldRate() );
Controls.VassalStatsGold:SetToolTipString( Locale.ConvertTextKey("TXT_KEY_VO_UNIT_MAINTENANCE") );
Controls.VassalStatsTradeRoutes:LocalizeAndSetText( "TXT_KEY_VO_TRADE_ROUTES_LABEL", pPlayer:GetNumInternationalTradeRoutesUsed(), pPlayer:GetNumInternationalTradeRoutesAvailable() );

Expand Down
30 changes: 15 additions & 15 deletions CvGameCoreDLL_Expansion2/CvTreasury.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ int CvTreasury::GetContractGoldMaintenance()
#endif

// What are our gold maintenance costs because of Vassals?
int CvTreasury::GetVassalGoldMaintenance(TeamTypes eTeam) const
int CvTreasury::GetVassalGoldMaintenance(TeamTypes eTeam, bool bIncludePopulationMaintenance, bool bIncludeUnitMaintenance) const
{
int iNumTeamMembers = GET_TEAM(m_pPlayer->getTeam()).getAliveCount();
if (iNumTeamMembers == 0)
Expand All @@ -987,38 +987,38 @@ int CvTreasury::GetVassalGoldMaintenance(TeamTypes eTeam) const
int iTotalExpenseOtherVassals = 0;
for (int iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)
{
PlayerTypes eLoopPlayer = (PlayerTypes) iPlayerLoop;
PlayerTypes eLoopPlayer = (PlayerTypes)iPlayerLoop;
TeamTypes eLoopTeam = GET_PLAYER(eLoopPlayer).getTeam();
if (GET_TEAM(eLoopTeam).GetMaster() != m_pPlayer->getTeam())
continue;

int iLoop = 0;
if (eTeam == NO_TEAM || eTeam == eLoopTeam)
int iExpense = 0;

// Loop through our vassal's cities
if (bIncludePopulationMaintenance)
{
int iExpense = 0;
// Loop through our vassal's cities
int iLoop = 0;
for (CvCity* pLoopCity = GET_PLAYER(eLoopPlayer).firstCity(&iLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER(eLoopPlayer).nextCity(&iLoop))
{
int iCityPop = pLoopCity->getPopulation();
iExpense += std::max(0, (int)(pow((double)iCityPop, (double) /*0.8f*/ GD_FLOAT_GET(VASSALAGE_VASSAL_CITY_POP_EXPONENT))));
}
}

if (bIncludeUnitMaintenance)
{
iExpense += std::max(0, GET_PLAYER(eLoopPlayer).GetTreasury()->GetExpensePerTurnUnitMaintenance() * /*10*/ GD_INT_GET(VASSALAGE_VASSAL_UNIT_MAINT_COST_PERCENT) / 100);
}

if (eTeam == NO_TEAM || eTeam == eLoopTeam)
{
iTotalExpense += iExpense;
}
else
{
int iExpense = 0;
// Loop through our vassal's cities
for (CvCity* pLoopCity = GET_PLAYER(eLoopPlayer).firstCity(&iLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER(eLoopPlayer).nextCity(&iLoop))
{
int iCityPop = pLoopCity->getPopulation();
iExpense += std::max(0, (int)(pow((double)iCityPop, (double) /*0.8f*/ GD_FLOAT_GET(VASSALAGE_VASSAL_CITY_POP_EXPONENT))));
}

iExpense += std::max(0, GET_PLAYER(eLoopPlayer).GetTreasury()->GetExpensePerTurnUnitMaintenance() * /*10*/ GD_INT_GET(VASSALAGE_VASSAL_UNIT_MAINT_COST_PERCENT) / 100);
iTotalExpenseOtherVassals += iExpense;
}

}

// What is my share of this maintenance?
Expand Down
2 changes: 1 addition & 1 deletion CvGameCoreDLL_Expansion2/CvTreasury.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class CvTreasury
int AverageIncome100(int iTurns);
void LogExpenditure(const CvString& strExpenditure, int iAmount, int iColumn);

int GetVassalGoldMaintenance(TeamTypes eTeam = NO_TEAM) const;
int GetVassalGoldMaintenance(TeamTypes eTeam = NO_TEAM, bool bIncludePopulationMaintenance = true, bool bIncludeUnitMaintenance = true) const;

int GetMyShareOfVassalTaxes(TeamTypes eTeam = NO_TEAM, int iProjectedTaxRate = -1) const;
int GetVassalTaxContributionTimes100(PlayerTypes ePlayer) const;
Expand Down
5 changes: 4 additions & 1 deletion CvGameCoreDLL_Expansion2/Lua/CvLuaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16708,8 +16708,11 @@ int CvLuaPlayer::lGetYieldPerTurnFromVassals(lua_State* L)
int CvLuaPlayer::lGetVassalGoldMaintenance(lua_State* L)
{
CvPlayerAI* pkPlayer = GetInstance(L);
TeamTypes eTeam = (TeamTypes)luaL_optint(L, 2, -1);
bool bIncludePopulationMaintenance = luaL_optbool(L, 3, true);
bool bIncludeUnitMaintenance = luaL_optbool(L, 4, true);

const int iResult = pkPlayer->GetTreasury()->GetVassalGoldMaintenance(NO_TEAM);
const int iResult = pkPlayer->GetTreasury()->GetVassalGoldMaintenance(eTeam, bIncludePopulationMaintenance, bIncludeUnitMaintenance);
lua_pushinteger(L, iResult);
return 1;
}
Expand Down

0 comments on commit fd54ab1

Please sign in to comment.