Skip to content

Commit

Permalink
Rewrite help for resource reqs of routes
Browse files Browse the repository at this point in the history
Seems that this was never tested. Not sure if it works exactly as originally intended now. I've used the code for building resource requirements as a template.
  • Loading branch information
f1rpo committed Aug 23, 2022
1 parent 329f390 commit fcd1d0e
Showing 1 changed file with 34 additions and 35 deletions.
69 changes: 34 additions & 35 deletions CvGameCoreDLL/CvGameTextMgr.cpp
Expand Up @@ -20158,7 +20158,6 @@ void CvGameTextMgr::setRouteHelp(CvWStringBuffer &szBuffer, RouteTypes eRoute, b
{
CvWString szTempBuffer;
CvWString szFirstBuffer;
int iI;

if (NO_ROUTE == eRoute)
{
Expand Down Expand Up @@ -20204,47 +20203,47 @@ void CvGameTextMgr::setRouteHelp(CvWStringBuffer &szBuffer, RouteTypes eRoute, b
szBuffer.append(gDLL->getText("TXT_KEY_ROUTE_FLAT_MOVEMENT_COST", info.getFlatMovementCost()));
}

if (info.getPrereqBonus() != NO_BONUS)
/* <f1rpo> Resource reqs. Existing code was largely incorrect, probably had
never been tested. Rewritten based on buildBuildingRequiresString and
CvPlot::canBuild. The TXT_KEY_ROUTE_REQUIRES... texts are also erroneous;
no longer used. The hasBonus checks are based on cities - while canBuild
actually requires the resource to be available at the (non-city) plot;
it's the best we can do. */
CvPlayer const* pActive = (GC.getGame().getActivePlayer() == NO_PLAYER ? NULL
: &GET_PLAYER(GC.getGame().getActivePlayer()));
{
if ((GC.getGame().getActivePlayer()!= NO_PLAYER && !GET_PLAYER(GC.getGame().getActivePlayer()).hasBonus((BonusTypes)info.getPrereqBonus())) || GC.getGame().getActivePlayer() == NO_PLAYER)
BonusTypes const eAndReq = (BonusTypes)info.getPrereqBonus();
if (eAndReq != NO_BONUS)
{
if (info.isAnyPrereqOrBonus())
{
bool bQualified = true;
if ((GC.getGame().getActivePlayer()!= NO_PLAYER && !GET_PLAYER(GC.getGame().getActivePlayer()).hasBonus((BonusTypes)info.getPrereqBonus())) || GC.getGame().getActivePlayer() == NO_PLAYER)
{
for (iI = 0; iI < GC.getNumBonusInfos(); iI++)
{
BonusTypes eBonusOrPrereq = (BonusTypes)iI;
if (GET_PLAYER(GC.getGame().getActivePlayer()).hasBonus((BonusTypes)info.getPrereqOrBonus(eBonusOrPrereq)))
{
bQualified = false;
}
}
if (bQualified)
{
szBuffer.append(NEWLINE);
szBuffer.append(gDLL->getText("TXT_KEY_ROUTE_REQUIRES_BONUS", GC.getBonusInfo((BonusTypes)info.getPrereqBonus()).getTextKeyWide()));

for (iI = 0; iI < GC.getNumBonusInfos(); iI++)
{
BonusTypes eBonusOrPrereq = (BonusTypes)iI;
if ((GC.getGame().getActivePlayer()!= NO_PLAYER && !GET_PLAYER(GC.getGame().getActivePlayer()).hasBonus((BonusTypes)info.getPrereqOrBonus(eBonusOrPrereq))) || GC.getGame().getActivePlayer() != NO_PLAYER)
{
szBuffer.append(gDLL->getText("TXT_KEY_ROUTE_REQUIRES_BONUS_OR", GC.getBonusInfo((BonusTypes)info.getPrereqOrBonus(eBonusOrPrereq)).getTextKeyWide()));
}
}
}
}
}
else
if (pActive == NULL || !pActive->hasBonus(eAndReq))
{
szBuffer.append(NEWLINE);
szBuffer.append(gDLL->getText("TXT_KEY_ROUTE_REQUIRES_BONUS", GC.getBonusInfo((BonusTypes)info.getPrereqBonus()).getTextKeyWide()));
szBuffer.append(gDLL->getText("TXT_KEY_UNIT_REQUIRES_STRING",
GC.getInfo(eAndReq).getTextKeyWide()));
}
}
}

CvWStringBuffer szOrReqs;
bool bFirst = true;
bool bAnyOrReqMet = false;
for (int i = 0; i < GC.getNUM_ROUTE_PREREQ_OR_BONUSES(); i++)
{
BonusTypes const eOrReq = (BonusTypes)GC.getInfo(eRoute).getPrereqOrBonus(i);
if (eOrReq == NO_BONUS)
continue;
szTempBuffer.Format(L"%s%s", NEWLINE,
gDLL->getText("TXT_KEY_REQUIRES").c_str());
setListHelp(szOrReqs, szTempBuffer, GC.getInfo(eOrReq).getDescription(),
gDLL->getText("TXT_KEY_OR"), bFirst);
bFirst = false;
if (pActive != NULL && pActive->hasBonus(eOrReq))
bAnyOrReqMet = true;
}
if (!bFirst && !bAnyOrReqMet)
{
szBuffer.append(ENDCOLR);
szBuffer.append(szOrReqs);
} // </f1rpo>

info.getPropertyManipulators()->buildDisplayString(szBuffer);
}
Expand Down

0 comments on commit fcd1d0e

Please sign in to comment.