From 4568635f2fef99a890e351678733fb8a8abf1655 Mon Sep 17 00:00:00 2001 From: RecursiveVision <66801010+RecursiveVision@users.noreply.github.com> Date: Mon, 30 Oct 2023 12:54:54 -0400 Subject: [PATCH] Revert "Investment Bugfixes (#10399)" This reverts commit a89aa5b60072fef1da14af2ae2e44279458f6296. --- (2) Vox Populi/LUA/InfoTooltipInclude.lua | 19 +- (2) Vox Populi/LUA/ProductionPopup.lua | 6 +- (2) Vox Populi/LUA/TechButtonInclude.lua | 2 +- (3a) EUI Compatibility Files/LUA/CityView.lua | 2 - .../CvBuildingProductionAI.cpp | 3 +- CvGameCoreDLL_Expansion2/CvCity.cpp | 241 ++++++------------ CvGameCoreDLL_Expansion2/CvCity.h | 11 +- CvGameCoreDLL_Expansion2/Lua/CvLuaCity.cpp | 32 ++- 8 files changed, 112 insertions(+), 204 deletions(-) diff --git a/(2) Vox Populi/LUA/InfoTooltipInclude.lua b/(2) Vox Populi/LUA/InfoTooltipInclude.lua index ce4d256853..1e0ba706f4 100644 --- a/(2) Vox Populi/LUA/InfoTooltipInclude.lua +++ b/(2) Vox Populi/LUA/InfoTooltipInclude.lua @@ -5,7 +5,7 @@ print("This is the modded InfoTooltipInclude from CBP- CSD") -- UNIT -function GetHelpTextForUnit(iUnitID, bIncludeRequirementsInfo, pCity) +function GetHelpTextForUnit(iUnitID, bIncludeRequirementsInfo) local pUnitInfo = GameInfo.Units[iUnitID]; local pActivePlayer = Players[Game.GetActivePlayer()]; @@ -15,25 +15,14 @@ function GetHelpTextForUnit(iUnitID, bIncludeRequirementsInfo, pCity) -- Name strHelpText = strHelpText .. Locale.ToUpper(Locale.ConvertTextKey( pUnitInfo.Description )); - if (pCity ~= nil) then - if(pCity:GetUnitInvestment(iUnitID) > 0) then - strHelpText = strHelpText .. Locale.ConvertTextKey("TXT_KEY_INVESTED"); - end - end - + -- Cost strHelpText = strHelpText .. "[NEWLINE]----------------[NEWLINE]"; -- Skip cost if it's 0 if(pUnitInfo.Cost > 0) then - local iCost = pActivePlayer:GetUnitProductionNeeded(iUnitID); - if (pCity ~= nil) then - if(pCity:GetUnitInvestment(iUnitID) > 0) then - iCost = pCity:GetUnitInvestment(iUnitID); - end - end - strHelpText = strHelpText .. Locale.ConvertTextKey("TXT_KEY_PRODUCTION_COST", iCost); - end + strHelpText = strHelpText .. Locale.ConvertTextKey("TXT_KEY_PRODUCTION_COST", pActivePlayer:GetUnitProductionNeeded(iUnitID)); + end -- Moves if pUnitInfo.Domain ~= "DOMAIN_AIR" then diff --git a/(2) Vox Populi/LUA/ProductionPopup.lua b/(2) Vox Populi/LUA/ProductionPopup.lua index 7c3230cb28..d4a139c307 100644 --- a/(2) Vox Populi/LUA/ProductionPopup.lua +++ b/(2) Vox Populi/LUA/ProductionPopup.lua @@ -143,13 +143,13 @@ function ProductionSelected( ePurchaseEnum, iData) elseif (eOrder == OrderTypes.ORDER_CONSTRUCT) then if (city:IsCanPurchase(true, true, -1, iData, -1, eYield)) then Game.CityPurchaseBuilding(city, iData, eYield); + Network.SendUpdateCityCitizens(cityID); end elseif (eOrder == OrderTypes.ORDER_CREATE) then if (city:IsCanPurchase(true, true, -1, -1, iData, eYield)) then Game.CityPurchaseProject(city, iData, eYield); end end - Network.SendUpdateCityCitizens(cityID); if (eOrder == OrderTypes.ORDER_TRAIN or eOrder == OrderTypes.ORDER_CONSTRUCT or eOrder == OrderTypes.ORDER_CREATE) then if (eYield == YieldTypes.YIELD_GOLD) then @@ -824,7 +824,7 @@ function UpdateWindow( city ) Controls.ProductionPortrait:SetHide( false ); -- Info for this thing - strToolTip = Locale.ConvertTextKey(GetHelpTextForUnit(unitProduction, true, city)) .. "[NEWLINE][NEWLINE]" .. strToolTip; + strToolTip = Locale.ConvertTextKey(GetHelpTextForUnit(unitProduction, true)) .. "[NEWLINE][NEWLINE]" .. strToolTip; else Controls.ProductionPortrait:SetHide( true ); @@ -1237,7 +1237,7 @@ function AddProductionButton( id, description, orderType, turnsLeft, column, isD -- Tooltip local bIncludeRequirementsInfo = false; - local strToolTip = Locale.ConvertTextKey(GetHelpTextForUnit(id, bIncludeRequirementsInfo, pCity)); + local strToolTip = Locale.ConvertTextKey(GetHelpTextForUnit(id, bIncludeRequirementsInfo)); -- Disabled help text if (isDisabled) then diff --git a/(2) Vox Populi/LUA/TechButtonInclude.lua b/(2) Vox Populi/LUA/TechButtonInclude.lua index d91f2831d8..16f2a140f7 100644 --- a/(2) Vox Populi/LUA/TechButtonInclude.lua +++ b/(2) Vox Populi/LUA/TechButtonInclude.lua @@ -778,7 +778,7 @@ function AdjustArtOnGrantedUnitButton( thisButton, thisUnitInfo, textureSize ) -- Tooltip local bIncludeRequirementsInfo = true; - thisButton:SetToolTipString( GetHelpTextForUnit(thisUnitInfo.ID, bIncludeRequirementsInfo, nil) ); + thisButton:SetToolTipString( GetHelpTextForUnit(thisUnitInfo.ID, bIncludeRequirementsInfo) ); local portraitOffset, portraitAtlas = UI.GetUnitPortraitIcon(thisUnitInfo.ID); local textureOffset, textureSheet = IconLookup( portraitOffset, textureSize, portraitAtlas ); if textureOffset == nil then diff --git a/(3a) EUI Compatibility Files/LUA/CityView.lua b/(3a) EUI Compatibility Files/LUA/CityView.lua index 5c3bb06e14..760e9e28fb 100644 --- a/(3a) EUI Compatibility Files/LUA/CityView.lua +++ b/(3a) EUI Compatibility Files/LUA/CityView.lua @@ -1098,7 +1098,6 @@ local function SelectionPurchase( orderID, itemID, yieldID, soundKey ) if orderID == OrderTypes.ORDER_TRAIN then if cityIsCanPurchase( city, true, true, itemID, -1, -1, yieldID ) then Game.CityPurchaseUnit( city, itemID, yieldID ) - Network.SendUpdateCityCitizens( cityID ) isPurchase = true end elseif orderID == OrderTypes.ORDER_CONSTRUCT then @@ -1125,7 +1124,6 @@ local function SelectionPurchase( orderID, itemID, yieldID, soundKey ) elseif orderID == OrderTypes.ORDER_CREATE then if cityIsCanPurchase( city, true, true, -1, -1, itemID, yieldID ) then Game.CityPurchaseProject( city, itemID, yieldID ) - Network.SendUpdateCityCitizens( cityID ) isPurchase = true end end diff --git a/CvGameCoreDLL_Expansion2/CvBuildingProductionAI.cpp b/CvGameCoreDLL_Expansion2/CvBuildingProductionAI.cpp index bf814e5d72..038b14686f 100644 --- a/CvGameCoreDLL_Expansion2/CvBuildingProductionAI.cpp +++ b/CvGameCoreDLL_Expansion2/CvBuildingProductionAI.cpp @@ -686,6 +686,7 @@ int CvBuildingProductionAI::CheckBuildingBuildSanity(BuildingTypes eBuilding, in } +#if defined(MOD_BALANCE_CORE_BUILDING_INVESTMENTS) if (MOD_BALANCE_CORE_BUILDING_INVESTMENTS && !bIgnoreSituational) { //Virtually force this. @@ -695,7 +696,7 @@ int CvBuildingProductionAI::CheckBuildingBuildSanity(BuildingTypes eBuilding, in iBonus += 1000; } } - +#endif //Courthouse? Let's get it ASAP. bool bCourthouse = false; if(pkBuildingInfo->IsNoOccupiedUnhappiness()) diff --git a/CvGameCoreDLL_Expansion2/CvCity.cpp b/CvGameCoreDLL_Expansion2/CvCity.cpp index ca72ee8f75..43a53e4da7 100644 --- a/CvGameCoreDLL_Expansion2/CvCity.cpp +++ b/CvGameCoreDLL_Expansion2/CvCity.cpp @@ -469,9 +469,7 @@ CvCity::CvCity() : #if defined(MOD_BALANCE_CORE) , m_abOwedChosenBuilding() , m_abBuildingInvestment() - , m_aiBuildingCostInvestmentReduction() , m_abUnitInvestment() - , m_aiUnitCostInvestmentReduction() , m_abBuildingConstructed() , m_iBorderObstacleCity() , m_iBorderObstacleWater() @@ -1700,21 +1698,17 @@ void CvCity::reset(int iID, PlayerTypes eOwner, int iX, int iY, bool bConstructo #if defined(MOD_BALANCE_CORE) m_abOwedChosenBuilding.resize(GC.getNumBuildingClassInfos()); m_abBuildingInvestment.resize(GC.getNumBuildingClassInfos()); - m_aiBuildingCostInvestmentReduction.resize(GC.getNumBuildingClassInfos()); m_abUnitInvestment.resize(GC.getNumUnitClassInfos()); - m_aiUnitCostInvestmentReduction.resize(GC.getNumUnitClassInfos()); m_abBuildingConstructed.resize(GC.getNumBuildingClassInfos()); for (int iI = 0; iI < GC.getNumBuildingClassInfos(); iI++) { m_abOwedChosenBuilding[iI] = false; m_abBuildingInvestment[iI] = false; - m_aiBuildingCostInvestmentReduction[iI] = 0; m_abBuildingConstructed[iI] = false; } for (int iI = 0; iI < GC.getNumUnitClassInfos(); iI++) { m_abUnitInvestment[iI] = false; - m_aiUnitCostInvestmentReduction[iI] = 0; } #endif #if defined(MOD_BALANCE_CORE_JFD) @@ -11774,7 +11768,7 @@ int CvCity::getProductionNeeded() const } // -------------------------------------------------------------------------------- -int CvCity::getProductionNeeded(UnitTypes eUnit, bool bIgnoreInvestment) const +int CvCity::getProductionNeeded(UnitTypes eUnit) const { VALIDATE_OBJECT int iNumProductionNeeded = GET_PLAYER(getOwner()).getProductionNeeded(eUnit, false); @@ -11782,52 +11776,54 @@ int CvCity::getProductionNeeded(UnitTypes eUnit, bool bIgnoreInvestment) const if (eUnit != NO_UNIT) { CvUnitEntry* pGameUnit = GC.getUnitInfo(eUnit); - UnitClassTypes eUnitClass = (UnitClassTypes)pGameUnit->GetUnitClassType(); - if (MOD_RESOURCES_PRODUCTION_COST_MODIFIERS) - { - int iCostMod = 0; +#if defined(MOD_RESOURCES_PRODUCTION_COST_MODIFIERS) + int iCostMod = 0; - UnitCombatTypes eUnitCombat = (UnitCombatTypes)pGameUnit->GetUnitCombatType(); - EraTypes eUnitEra = (EraTypes)pGameUnit->GetEra(); + UnitCombatTypes eUnitCombat = (UnitCombatTypes)pGameUnit->GetUnitCombatType(); + EraTypes eUnitEra = (EraTypes)pGameUnit->GetEra(); - if (eUnitEra == NO_ERA) - { - eUnitEra = GET_PLAYER(getOwner()).GetCurrentEra(); - } + if (eUnitEra == NO_ERA) + { + eUnitEra = GET_PLAYER(getOwner()).GetCurrentEra(); + } - if (eUnitCombat != NO_UNITCOMBAT && eUnitEra != NO_ERA) + if (MOD_RESOURCES_PRODUCTION_COST_MODIFIERS && eUnitCombat != NO_UNITCOMBAT && eUnitEra != NO_ERA) + { + for (int iResourceLoop = 0; iResourceLoop < GC.getNumResourceInfos(); iResourceLoop++) { - for (int iResourceLoop = 0; iResourceLoop < GC.getNumResourceInfos(); iResourceLoop++) + const ResourceTypes eResource = static_cast(iResourceLoop); + CvResourceInfo* pkResource = GC.getResourceInfo(eResource); + if (pkResource && pkResource->isHasUnitCombatProductionCostModifiersLocal() && IsHasResourceLocal(eResource, false)) { - const ResourceTypes eResource = static_cast(iResourceLoop); - CvResourceInfo* pkResource = GC.getResourceInfo(eResource); - if (pkResource && pkResource->isHasUnitCombatProductionCostModifiersLocal() && IsHasResourceLocal(eResource, false)) - { - iCostMod += pkResource->getUnitCombatProductionCostModifiersLocal(eUnitCombat, eUnitEra); - } + iCostMod += pkResource->getUnitCombatProductionCostModifiersLocal(eUnitCombat, eUnitEra); } } - - // Cost modifiers must be applied before the investment code - iNumProductionNeeded *= (iCostMod + 100); - iNumProductionNeeded /= 100; } + // Cost modifiers must be applied before the investment code + iNumProductionNeeded *= (iCostMod + 100); + iNumProductionNeeded /= 100; +#endif +#if defined(MOD_BALANCE_CORE_UNIT_INVESTMENTS) if (MOD_BALANCE_CORE_UNIT_INVESTMENTS || (MOD_BALANCE_CORE && pGameUnit->GetSpaceshipProject() != NO_PROJECT)) { - if (IsUnitInvestment(eUnitClass) && !bIgnoreInvestment) + const UnitClassTypes eUnitClass = (UnitClassTypes)(pGameUnit->GetUnitClassType()); + if (IsUnitInvestment(eUnitClass)) { - iNumProductionNeeded -= GetUnitCostInvestmentReduction(eUnitClass); + int iTotalDiscount = (/*-50*/ GD_INT_GET(BALANCE_UNIT_INVESTMENT_BASELINE) + GET_PLAYER(getOwner()).GetPlayerTraits()->GetInvestmentModifier() + GET_PLAYER(getOwner()).GetInvestmentModifier()); + iNumProductionNeeded *= (iTotalDiscount + 100); + iNumProductionNeeded /= 100; } } +#endif } return max(1, iNumProductionNeeded); } // -------------------------------------------------------------------------------- -int CvCity::getProductionNeeded(BuildingTypes eBuilding, bool bIgnoreInvestment) const +int CvCity::getProductionNeeded(BuildingTypes eBuilding) const { VALIDATE_OBJECT int iNumProductionNeeded = GET_PLAYER(getOwner()).getProductionNeeded(eBuilding); @@ -11839,47 +11835,65 @@ int CvCity::getProductionNeeded(BuildingTypes eBuilding, bool bIgnoreInvestment) { const BuildingClassTypes eBuildingClass = (BuildingClassTypes)(pGameBuilding->GetBuildingClassType()); - if (MOD_RESOURCES_PRODUCTION_COST_MODIFIERS) +#if defined(MOD_RESOURCES_PRODUCTION_COST_MODIFIERS) + int iCostMod = 0; + EraTypes eBuildingEra = (EraTypes)pGameBuilding->GetEra(); + + bool bWonder = false; + if (eBuildingClass != NO_BUILDINGCLASS) + { + const CvBuildingClassInfo* pkBuildingClassInfo = GC.getBuildingClassInfo(eBuildingClass); + if (pkBuildingClassInfo) + { + bWonder = isWorldWonderClass(*pkBuildingClassInfo) || isTeamWonderClass(*pkBuildingClassInfo) || isNationalWonderClass(*pkBuildingClassInfo); + } + } + + if (eBuildingEra == NO_ERA) { - int iCostMod = 0; - EraTypes eBuildingEra = (EraTypes)pGameBuilding->GetEra(); + eBuildingEra = GET_PLAYER(getOwner()).GetCurrentEra(); + } - bool bWonder = false; - if (eBuildingClass != NO_BUILDINGCLASS) + if (MOD_RESOURCES_PRODUCTION_COST_MODIFIERS && !bWonder && eBuildingEra != NO_ERA) + { + for (int iResourceLoop = 0; iResourceLoop < GC.getNumResourceInfos(); iResourceLoop++) { - const CvBuildingClassInfo* pkBuildingClassInfo = GC.getBuildingClassInfo(eBuildingClass); - if (pkBuildingClassInfo) + const ResourceTypes eResource = static_cast(iResourceLoop); + CvResourceInfo* pkResource = GC.getResourceInfo(eResource); + if (pkResource && pkResource->isHasBuildingProductionCostModifiersLocal() && IsHasResourceLocal(eResource, false)) { - bWonder = isWorldWonderClass(*pkBuildingClassInfo) || isTeamWonderClass(*pkBuildingClassInfo) || isNationalWonderClass(*pkBuildingClassInfo); + iCostMod += pkResource->getBuildingProductionCostModifiersLocal(eBuildingEra); } } + } + + // Cost modifiers must be applied before the investment code + iNumProductionNeeded *= (iCostMod + 100); + iNumProductionNeeded /= 100; +#endif +#if defined(MOD_BALANCE_CORE_BUILDING_INVESTMENTS) + if (MOD_BALANCE_CORE_BUILDING_INVESTMENTS && eBuildingClass != NO_BUILDINGCLASS && IsBuildingInvestment(eBuildingClass)) + { + int iTotalDiscount = (/*-50*/ GD_INT_GET(BALANCE_BUILDING_INVESTMENT_BASELINE) + GET_PLAYER(getOwner()).GetPlayerTraits()->GetInvestmentModifier() + GET_PLAYER(getOwner()).GetInvestmentModifier()); + const CvBuildingClassInfo& kBuildingClassInfo = pGameBuilding->GetBuildingClassInfo(); + if (::isWorldWonderClass(kBuildingClassInfo)) - if (eBuildingEra == NO_ERA) { - eBuildingEra = GET_PLAYER(getOwner()).GetCurrentEra(); + iTotalDiscount /= 2; } + iNumProductionNeeded *= (iTotalDiscount + 100); + iNumProductionNeeded /= 100; - if (!bWonder && eBuildingEra != NO_ERA) + // Investment checks when AmountComplete >= 50 moved here + int AmountComplete = GetCityBuildings()->GetBuildingProduction(eBuilding); + int AmountNeeded = max(1, iNumProductionNeeded); + if (AmountComplete >= AmountNeeded) { - for (int iResourceLoop = 0; iResourceLoop < GC.getNumResourceInfos(); iResourceLoop++) - { - const ResourceTypes eResource = static_cast(iResourceLoop); - CvResourceInfo* pkResource = GC.getResourceInfo(eResource); - if (pkResource && pkResource->isHasBuildingProductionCostModifiersLocal() && IsHasResourceLocal(eResource, false)) - { - iCostMod += pkResource->getBuildingProductionCostModifiersLocal(eBuildingEra); - } - } + int iProductionDifference = getProductionDifference(iNumProductionNeeded, AmountComplete, getProductionModifier(), false, false); + return max(AmountNeeded, AmountComplete - iProductionDifference); //allow one turn of overflow } - - // Cost modifiers must be applied before the investment code - iNumProductionNeeded *= (iCostMod + 100); - iNumProductionNeeded /= 100; - } - if (MOD_BALANCE_CORE_BUILDING_INVESTMENTS && !bIgnoreInvestment && eBuildingClass != NO_BUILDINGCLASS && IsBuildingInvestment(eBuildingClass)) - { - iNumProductionNeeded -= GetBuildingCostInvestmentReduction(eBuildingClass); } +#endif } } @@ -12083,53 +12097,6 @@ void CvCity::SetBuildingInvestment(BuildingClassTypes eBuildingClass, bool bNewV } m_abBuildingInvestment[eBuildingClass] = bNewValue; - - if (bNewValue) - { - // calculate reduction of building production cost - BuildingTypes eBuilding = NO_BUILDING; - - if (MOD_BUILDINGS_THOROUGH_PREREQUISITES) - { - eBuilding = GetCityBuildings()->GetBuildingTypeFromClass(eBuildingClass); - } - else - { - eBuilding = (BuildingTypes)GC.getCivilizationInfo(getCivilizationType())->getCivilizationBuildings(eBuildingClass); - } - - int iNumProductionNeeded = getProductionNeeded(eBuilding); - int AmountNeededAfterInvestment = max(1, iNumProductionNeeded); - - int iTotalDiscount = (/*-50*/ GD_INT_GET(BALANCE_BUILDING_INVESTMENT_BASELINE) + GET_PLAYER(getOwner()).GetPlayerTraits()->GetInvestmentModifier() + GET_PLAYER(getOwner()).GetInvestmentModifier()); - if (::isWorldWonderClass(*GC.getBuildingClassInfo(eBuildingClass))) - { - iTotalDiscount /= 2; - } - AmountNeededAfterInvestment *= (iTotalDiscount + 100); - AmountNeededAfterInvestment /= 100; - - // Investment checks when AmountComplete >= 50 moved here - int AmountComplete = GetCityBuildings()->GetBuildingProduction(eBuilding); - if (AmountComplete >= AmountNeededAfterInvestment) - { - int iProductionDifference = getProductionDifference(AmountNeededAfterInvestment, AmountComplete, getProductionModifier(), false, false); - AmountNeededAfterInvestment = max(AmountNeededAfterInvestment, AmountComplete - iProductionDifference); //allow one turn of overflow - } - m_aiBuildingCostInvestmentReduction[eBuildingClass] = iNumProductionNeeded - AmountNeededAfterInvestment; - } - else - { - m_aiBuildingCostInvestmentReduction[eBuildingClass] = 0; - } -} -// --------------------------------------------------------------------------------- -int CvCity::GetBuildingCostInvestmentReduction(BuildingClassTypes eBuildingClass) const -{ - FAssert(eBuildingClass >= 0); - FAssert(eBuildingClass < GC.getNumBuildingClassInfos()); - - return m_aiBuildingCostInvestmentReduction[eBuildingClass]; } // -------------------------------------------------------------------------------- bool CvCity::IsProcessInternationalProject(ProcessTypes eProcess) const @@ -12164,41 +12131,8 @@ void CvCity::SetUnitInvestment(UnitClassTypes eUnitClass, bool bNewValue) } m_abUnitInvestment[eUnitClass] = bNewValue; - if (bNewValue) - { - // calculate reduction of unit production cost - UnitTypes eUnit = GET_PLAYER(getOwner()).GetSpecificUnitType(eUnitClass); - - int iNumProductionNeeded = getProductionNeeded(eUnit); - int AmountNeededAfterInvestment = max(1, iNumProductionNeeded); - - int iTotalDiscount = (/*-50*/ GD_INT_GET(BALANCE_UNIT_INVESTMENT_BASELINE) + GET_PLAYER(getOwner()).GetPlayerTraits()->GetInvestmentModifier() + GET_PLAYER(getOwner()).GetInvestmentModifier()); - - AmountNeededAfterInvestment *= (iTotalDiscount + 100); - AmountNeededAfterInvestment /= 100; - - // Investment checks when AmountComplete >= 50 moved here - int AmountComplete = getUnitProduction(eUnit); - if (AmountComplete >= AmountNeededAfterInvestment) - { - int iProductionDifference = getProductionDifference(AmountNeededAfterInvestment, AmountComplete, getProductionModifier(), false, false); - AmountNeededAfterInvestment = max(AmountNeededAfterInvestment, AmountComplete - iProductionDifference); //allow one turn of overflow - } - m_aiUnitCostInvestmentReduction[eUnitClass] = iNumProductionNeeded - AmountNeededAfterInvestment; - } - else - { - m_aiUnitCostInvestmentReduction[eUnitClass] = 0; - } } -// --------------------------------------------------------------------------------- -int CvCity::GetUnitCostInvestmentReduction(UnitClassTypes eUnitClass) const -{ - FAssert(eUnitClass >= 0); - FAssert(eUnitClass < GC.getNumUnitClassInfos()); - return m_aiUnitCostInvestmentReduction[eUnitClass]; -} // -------------------------------------------------------------------------------- bool CvCity::IsBuildingConstructed(BuildingClassTypes eBuildingClass) const { @@ -30437,23 +30371,6 @@ bool CvCity::hasOrder(OrderTypes eOrder, int iData1, int iData2) const return false; } -bool CvCity::hasOrder(OrderTypes eOrder, int iData1) const -{ - for (int iI = 0; iI < getOrderQueueLength(); iI++) - { - const OrderData* pOrder = getOrderFromQueue(iI); - if (pOrder != NULL) - { - if (pOrder->eOrderType == eOrder && pOrder->iData1 == iData1) - { - return true; - } - } - } - - return false; -} - // -------------------------------------------------------------------------------- void CvCity::startHeadOrder() @@ -31539,8 +31456,7 @@ bool CvCity::IsCanPurchase(const std::vector& vPreExistingBuildings, bool b // Unit if (eUnitType != NO_UNIT) { - bool bAlreadyUnderConstruction = getFirstUnitOrder(eUnitType) != -1; - if (!canTrain(eUnitType, bAlreadyUnderConstruction, !bTestTrainable, false /*bIgnoreCost*/, true /*bWillPurchase*/)) + if (!canTrain(eUnitType, false, !bTestTrainable, false /*bIgnoreCost*/, true /*bWillPurchase*/)) return false; iGoldCost = GetPurchaseCost(eUnitType); @@ -31993,10 +31909,9 @@ void CvCity::Purchase(UnitTypes eUnitType, BuildingTypes eBuildingType, ProjectT clearOrderQueue(); } - if (!hasOrder(ORDER_TRAIN, eUnitType)) + if (!hasOrder(ORDER_TRAIN, eUnitType, -1)) { - //we purchased it so let's assume it's urgent and put it at the head of the list - pushOrder(ORDER_TRAIN, eUnitType, -1, false, false, false); + pushOrder(ORDER_TRAIN, eUnitType, -1, false, false, true, false); } } } @@ -33357,9 +33272,7 @@ void CvCity::Serialize(City& city, Visitor& visitor) visitor(city.m_abYieldRankValid); visitor(city.m_abOwedChosenBuilding); visitor(city.m_abBuildingInvestment); - visitor(city.m_aiBuildingCostInvestmentReduction); visitor(city.m_abUnitInvestment); - visitor(city.m_aiUnitCostInvestmentReduction); visitor(city.m_abBuildingConstructed); visitor(city.m_aiBonusSightEspionage); diff --git a/CvGameCoreDLL_Expansion2/CvCity.h b/CvGameCoreDLL_Expansion2/CvCity.h index f0abd8c5e9..710d0e21ab 100644 --- a/CvGameCoreDLL_Expansion2/CvCity.h +++ b/CvGameCoreDLL_Expansion2/CvCity.h @@ -399,8 +399,8 @@ class CvCity int getProduction() const; int getProductionTimes100() const; int getProductionNeeded() const; - int getProductionNeeded(UnitTypes eUnit, bool bIgnoreInvestment = false) const; - int getProductionNeeded(BuildingTypes eBuilding, bool bIgnoreInvestment = false) const; + int getProductionNeeded(UnitTypes eUnit) const; + int getProductionNeeded(BuildingTypes eBuilding) const; int getProductionNeeded(ProjectTypes eProject) const; int getProductionNeeded(SpecialistTypes eSpecialist) const; int getProductionTurnsLeft() const; @@ -414,13 +414,11 @@ class CvCity #endif #if defined(MOD_BALANCE_CORE) void SetBuildingInvestment(BuildingClassTypes eBuildingClass, bool bValue); - int GetBuildingCostInvestmentReduction(BuildingClassTypes eBuildingClass) const; bool IsBuildingInvestment(BuildingClassTypes eBuildingClass) const; bool IsProcessInternationalProject(ProcessTypes eProcess) const; void SetUnitInvestment(UnitClassTypes eUnitClass, bool bValue); - int GetUnitCostInvestmentReduction(UnitClassTypes eUnitClass) const; bool IsUnitInvestment(UnitClassTypes eUnitClass) const; void SetBuildingConstructed(BuildingClassTypes eBuildingClass, bool bValue); @@ -1538,7 +1536,6 @@ class CvCity void popOrder(int iNum, bool bFinish = false, bool bChoose = false); void swapOrder(int iNum); bool hasOrder(OrderTypes eOrder, int iData1, int iData2) const; - bool hasOrder(OrderTypes eOrder, int iData1) const; void startHeadOrder(); void stopHeadOrder(); int getOrderQueueLength() const; @@ -2152,9 +2149,7 @@ class CvCity #if defined(MOD_BALANCE_CORE) std::vector m_abOwedChosenBuilding; std::vector m_abBuildingInvestment; - std::vector m_aiBuildingCostInvestmentReduction; std::vector m_abUnitInvestment; - std::vector m_aiUnitCostInvestmentReduction; std::vector m_abBuildingConstructed; std::vector m_aiBonusSightEspionage; #endif @@ -2495,9 +2490,7 @@ SYNC_ARCHIVE_VAR(std::vector, m_aiYieldRank) SYNC_ARCHIVE_VAR(std::vector, m_abYieldRankValid) SYNC_ARCHIVE_VAR(std::vector, m_abOwedChosenBuilding) SYNC_ARCHIVE_VAR(std::vector, m_abBuildingInvestment) -SYNC_ARCHIVE_VAR(std::vector, m_aiBuildingCostInvestmentReduction) SYNC_ARCHIVE_VAR(std::vector, m_abUnitInvestment) -SYNC_ARCHIVE_VAR(std::vector, m_aiUnitCostInvestmentReduction) SYNC_ARCHIVE_VAR(std::vector, m_abBuildingConstructed) SYNC_ARCHIVE_VAR(std::vector, m_aiBonusSightEspionage) SYNC_ARCHIVE_END() diff --git a/CvGameCoreDLL_Expansion2/Lua/CvLuaCity.cpp b/CvGameCoreDLL_Expansion2/Lua/CvLuaCity.cpp index 0b485f0d0f..273baf3ef2 100644 --- a/CvGameCoreDLL_Expansion2/Lua/CvLuaCity.cpp +++ b/CvGameCoreDLL_Expansion2/Lua/CvLuaCity.cpp @@ -1239,7 +1239,8 @@ int CvLuaCity::lGetPurchaseUnitTooltip(lua_State* L) const UnitClassTypes eUnitClass = (UnitClassTypes)thisUnitInfo->GetUnitClassType(); if (pkCity->IsUnitInvestment(eUnitClass)) { - int iValue = 100 * pkCity->GetUnitCostInvestmentReduction(eUnitClass) / pkCity->getProductionNeeded(eUnit, true); + int iValue = (/*-50*/ GD_INT_GET(BALANCE_UNIT_INVESTMENT_BASELINE) + GET_PLAYER(pkCity->getOwner()).GetPlayerTraits()->GetInvestmentModifier() + GET_PLAYER(pkCity->getOwner()).GetInvestmentModifier()); + iValue *= -1; Localization::String localizedText = Localization::Lookup("TXT_KEY_ALREADY_INVESTED_UNIT"); localizedText << iValue; @@ -1415,7 +1416,13 @@ int CvLuaCity::lGetPurchaseBuildingTooltip(lua_State* L) const BuildingClassTypes eBuildingClass = (BuildingClassTypes)(pGameBuilding->GetBuildingClassType()); if (pkCity->IsBuildingInvestment(eBuildingClass)) { - int iValue = 100 * pkCity->GetBuildingCostInvestmentReduction(eBuildingClass) / pkCity->getProductionNeeded(eBuilding, true); + int iValue = (/*-50*/ GD_INT_GET(BALANCE_BUILDING_INVESTMENT_BASELINE) + GET_PLAYER(pkCity->getOwner()).GetPlayerTraits()->GetInvestmentModifier() + GET_PLAYER(pkCity->getOwner()).GetInvestmentModifier()); + iValue *= -1; + const CvBuildingClassInfo& kBuildingClassInfo = pGameBuilding->GetBuildingClassInfo(); + if (::isWorldWonderClass(kBuildingClassInfo)) + { + iValue /= 2; + } Localization::String localizedText = Localization::Lookup("TXT_KEY_ALREADY_INVESTED"); localizedText << iValue; @@ -1728,11 +1735,7 @@ int CvLuaCity::lGetProductionTimes100(lua_State* L) //int getProductionNeeded(); int CvLuaCity::lGetProductionNeeded(lua_State* L) { - CvCity* pkCity = GetInstance(L); - const int iResult = pkCity->getProductionNeeded(); - - lua_pushinteger(L, iResult); - return 1; + return BasicLuaMethod(L, &CvCity::getProductionNeeded); } //------------------------------------------------------------------------------ //int GetUnitProductionNeeded(); @@ -1773,7 +1776,15 @@ int CvLuaCity::lGetBuildingInvestment(lua_State* L) const BuildingClassTypes eBuildingClass = (BuildingClassTypes)(pGameBuilding->GetBuildingClassType()); if (pkCity->IsBuildingInvestment(eBuildingClass)) { - iResult = pkCity->getProductionNeeded(eBuildingType, true) - pkCity->GetBuildingCostInvestmentReduction(eBuildingClass); + iResult = GET_PLAYER(pkCity->getOwner()).getProductionNeeded(eBuildingType); + iTotalDiscount = (/*-50*/ GD_INT_GET(BALANCE_BUILDING_INVESTMENT_BASELINE) + GET_PLAYER(pkCity->getOwner()).GetPlayerTraits()->GetInvestmentModifier() + GET_PLAYER(pkCity->getOwner()).GetInvestmentModifier()); + const CvBuildingClassInfo& kBuildingClassInfo = pGameBuilding->GetBuildingClassInfo(); + if (::isWorldWonderClass(kBuildingClassInfo)) + { + iTotalDiscount /= 2; + } + iResult *= (iTotalDiscount + 100); + iResult /= 100; } } @@ -1948,7 +1959,10 @@ int CvLuaCity::lGetUnitInvestment(lua_State* L) const UnitClassTypes eUnitClass = (UnitClassTypes)(pGameUnit->GetUnitClassType()); if(pkCity->IsUnitInvestment(eUnitClass)) { - iResult = pkCity->getProductionNeeded(eUnitType, true) - pkCity->GetUnitCostInvestmentReduction(eUnitClass); + iResult = GET_PLAYER(pkCity->getOwner()).getProductionNeeded(eUnitType, false); + iTotalDiscount = (/*-50*/ GD_INT_GET(BALANCE_BUILDING_INVESTMENT_BASELINE) + GET_PLAYER(pkCity->getOwner()).GetPlayerTraits()->GetInvestmentModifier() + GET_PLAYER(pkCity->getOwner()).GetInvestmentModifier()); + iResult *= (iTotalDiscount + 100); + iResult /= 100; } lua_pushinteger(L, iResult);