Skip to content

Commit

Permalink
fix repairing GPTI being instantaneous (#11098)
Browse files Browse the repository at this point in the history
repair time now only caps at improve time if there exists a build for the improvement that doesn't kill the builder
  • Loading branch information
azum4roll authored Jul 8, 2024
1 parent 200f72c commit 847bda3
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions CvGameCoreDLL_Expansion2/CvPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3185,7 +3185,7 @@ int CvPlot::getBuildTime(BuildTypes eBuild, PlayerTypes ePlayer) const
iTime += pkBuildInfo->getFeatureTime(getFeatureType());
}

// If repair, take the shorter time of repair and improve
// If repair, take the shorter time of repair and improve (but not for builds that kill the builder)
// We keep track of the improve time first, then compare at the end after all multipliers
if (pkBuildInfo->isRepair())
{
Expand All @@ -3195,22 +3195,31 @@ int CvPlot::getBuildTime(BuildTypes eBuild, PlayerTypes ePlayer) const

for (int iBuildLoop = 0; iBuildLoop < GC.getNumBuildInfos(); iBuildLoop++)
{
CvBuildInfo* pkBuildInfoLoop = GC.getBuildInfo(static_cast<BuildTypes>(iBuildLoop));
BuildTypes eBuild = static_cast<BuildTypes>(iBuildLoop);
CvBuildInfo* pkBuildInfoLoop = GC.getBuildInfo(eBuild);
if (!pkBuildInfoLoop)
continue;

if (IsImprovementPillaged())
{
if (pkBuildInfoLoop->getImprovement() == eImprovement)
{
if (pkBuildInfoLoop->isKill())
continue;

iImproveTime = pkBuildInfoLoop->getTime();
break;
}
}
else if (IsRoutePillaged())
{
if (pkBuildInfoLoop->getRoute() == eRoute)
{
if (pkBuildInfoLoop->isKill())
continue;

iImproveTime = pkBuildInfoLoop->getTime();
break;
}
}
}
Expand Down Expand Up @@ -3288,16 +3297,13 @@ int CvPlot::getBuildTurnsLeft(BuildTypes eBuild, PlayerTypes ePlayer, int iNowEx
// --------------------------------------------------------------------------------
int CvPlot::getBuildTurnsTotal(BuildTypes eBuild, PlayerTypes ePlayer) const
{
const IDInfo* pUnitNode = NULL;
const CvUnit* pLoopUnit = NULL;
int iBuildRate = 0;
int iBuildTime = getBuildTime(eBuild, ePlayer);

pUnitNode = headUnitNode();

while (pUnitNode != NULL)
const IDInfo* pUnitNode = headUnitNode();
while (pUnitNode)
{
pLoopUnit = GetPlayerUnit(*pUnitNode);
const CvUnit* pLoopUnit = GetPlayerUnit(*pUnitNode);
pUnitNode = nextUnitNode(pUnitNode);

if (pLoopUnit && pLoopUnit->getBuildType() == eBuild)
Expand All @@ -3310,7 +3316,7 @@ int CvPlot::getBuildTurnsTotal(BuildTypes eBuild, PlayerTypes ePlayer) const
return INT_MAX;
}

iBuildTime = std::max(1, getBuildTime(eBuild, ePlayer));
iBuildTime = std::max(1, iBuildTime);

// Rounds up
return (iBuildTime - 1) / iBuildRate + 1;
Expand Down

0 comments on commit 847bda3

Please sign in to comment.