Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

svn #1378

Merged
merged 2 commits into from Jun 12, 2022
Merged

svn #1378

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 15 additions & 13 deletions Sources/CvDLLWidgetData.cpp
Expand Up @@ -3400,22 +3400,24 @@ void CvDLLWidgetData::parseActionHelp(CvWidgetDataStruct &widgetDataStruct, CvWS
// BUG - Delete All Action - start
else if (GC.getActionInfo(widgetDataStruct.m_iData1).getCommandType() == COMMAND_DELETE)
{
const CvUnit* pHeadSelectedUnit = gDLL->getInterfaceIFace()->getHeadSelectedUnit();

if (GC.getGame().isOption(GAMEOPTION_DOWNSIZING_IS_PROFITABLE)
//units have to be inside cultural borders
&& pHeadSelectedUnit->plot()->getOwner() == pHeadSelectedUnit->getOwner())
if (GC.getGame().isOption(GAMEOPTION_DOWNSIZING_IS_PROFITABLE))
{
int iGold = 0;
const CvUnit* pHeadSelectedUnit = gDLL->getInterfaceIFace()->getHeadSelectedUnit();

foreach_(const CvUnit* pSelectedUnit, gDLL->getInterfaceIFace()->getSelectionList()->units())
{
iGold += pSelectedUnit->calculateScrapValue();
}
if (iGold != 0)
//units have to be inside cultural borders
if (pHeadSelectedUnit->plot()->getOwner() == pHeadSelectedUnit->getOwner())
{
szBuffer.append(NEWLINE);
szBuffer.append(gDLL->getText("TXT_KEY_MISC_GOLD_FOR_DISBANDING", iGold));
int iGold = 0;

foreach_(const CvUnit* pSelectedUnit, gDLL->getInterfaceIFace()->getSelectionList()->units())
{
iGold += pSelectedUnit->calculateScrapValue();
}
if (iGold != 0)
{
szBuffer.append(NEWLINE);
szBuffer.append(gDLL->getText("TXT_KEY_MISC_GOLD_FOR_DISBANDING", iGold));
}
}
}
}
Expand Down
55 changes: 37 additions & 18 deletions Sources/CvInfoUtil.h
Expand Up @@ -29,7 +29,6 @@ struct CvInfoUtil
{
foreach_(const WrappedVar* wrapper, m_wrappedVars)
delete wrapper;
m_wrappedVars.clear();
}

void initDataMembers()
Expand Down Expand Up @@ -160,7 +159,7 @@ struct CvInfoUtil
/// Enum wrapper
///==============

template <typename Enum_t, DelayedResolutionTypes delayedResolutionOption>
template <typename Enum_t>
struct EnumWrapper : WrappedVar
{
friend struct CvInfoUtil;
Expand All @@ -180,17 +179,14 @@ struct CvInfoUtil
CheckSum(iSum, ref());
}

void readXml(CvXMLLoadUtility* pXML)
virtual void readXml(CvXMLLoadUtility* pXML)
{
CvXMLLoadUtility::SetOptionalInfoType<delayedResolutionOption>(pXML, ref(), m_tag.c_str());
CvXMLLoadUtility::SetOptionalInfoType<NO_DELAYED_RESOLUTION>(pXML, ref(), m_tag.c_str());
}

void copyNonDefaults(const WrappedVar* source)
virtual void copyNonDefaults(const WrappedVar* source)
{
if (delayedResolutionOption == USE_DELAYED_RESOLUTION)
GC.copyNonDefaultDelayedResolution(reinterpret_cast<int*>(&ref()), reinterpret_cast<int*>(&(static_cast<const EnumWrapper*>(source)->ref())));

else if (ref() == -1)
if (ref() == -1)
ref() = static_cast<const EnumWrapper*>(source)->ref();
}

Expand All @@ -204,13 +200,43 @@ struct CvInfoUtil
Enum_t& ref() const { return *static_cast<Enum_t*>(m_ptr); }
};

///======================================
/// Enum with delayed resolution wrapper
///======================================

template <typename Enum_t>
struct EnumWithDelayedResolutionWrapper : EnumWrapper<Enum_t>
{
friend struct CvInfoUtil;

protected:
EnumWithDelayedResolutionWrapper(Enum_t& var, const wchar_t* tag)
: EnumWrapper<Enum_t>(var, tag)
{}

void uninitVar()
{
GC.removeDelayedResolution(reinterpret_cast<int*>(&ref()));
}

void readXml(CvXMLLoadUtility* pXML)
{
CvXMLLoadUtility::SetOptionalInfoType<USE_DELAYED_RESOLUTION>(pXML, ref(), m_tag.c_str());
}

void copyNonDefaults(const WrappedVar* source)
{
GC.copyNonDefaultDelayedResolution(reinterpret_cast<int*>(&ref()), reinterpret_cast<int*>(&(static_cast<const EnumWithDelayedResolutionWrapper*>(source)->ref())));
}
};

template <typename Enum_t>
CvInfoUtil& addEnum(Enum_t& var, const wchar_t* tag)
{
if (GC.isDelayedResolutionRequired(m_eInfoClass, InfoClassTraits<Enum_t>::InfoClassEnum))
m_wrappedVars.push_back(new EnumWrapper<Enum_t, USE_DELAYED_RESOLUTION>(var, tag));
m_wrappedVars.push_back(new EnumWithDelayedResolutionWrapper<Enum_t>(var, tag));
else
m_wrappedVars.push_back(new EnumWrapper<Enum_t, NO_DELAYED_RESOLUTION>(var, tag));
m_wrappedVars.push_back(new EnumWrapper<Enum_t>(var, tag));
return *this;
}

Expand Down Expand Up @@ -361,13 +387,6 @@ struct CvInfoUtil
{
ref().copyNonDefaultDelayedResolution(static_cast<const IDValueMapWithDelayedResolutionWrapper*>(source)->ref());
}

void checkSum(uint32_t& iSum) const
{
CheckSumC(iSum, ref());
}

IDValueMap_T& ref() const { return *static_cast<IDValueMap_T*>(m_ptr); }
};

template <typename T1, int default_>
Expand Down
80 changes: 19 additions & 61 deletions Sources/CvPlayerAI.cpp
Expand Up @@ -635,8 +635,6 @@ void CvPlayerAI::AI_doTurnUnitsPost()
foreach_(CvUnit * unit, units_safe() | filtered(CvUnit::fn::isPromotionReady()))
{
unit->AI_promote();
// Upgrade replaces the original unit with a new one, so old unit must be killed
unit->doDelayedDeath();
}
}

Expand Down Expand Up @@ -727,22 +725,22 @@ void CvPlayerAI::AI_doTurnUnitsPost()
return;
}

const bool bAnyWar = (GET_TEAM(getTeam()).getAnyWarPlanCount(true) > 0);
const bool bAnyWar = GET_TEAM(getTeam()).getAnyWarPlanCount(true) > 0;
const int64_t iStartingGold = getGold();
const int iTargetGold = AI_goldTarget();
int64_t iUpgradeBudget = (AI_goldToUpgradeAllUnits() / (bAnyWar ? 1 : 2));
int64_t iUpgradeBudget = AI_goldToUpgradeAllUnits() / (bAnyWar ? 1 : 2);

iUpgradeBudget = std::min<int64_t>(iUpgradeBudget, (iStartingGold - iTargetGold < iUpgradeBudget) ? (iStartingGold - iTargetGold) : iStartingGold / 2);
iUpgradeBudget = std::max<int64_t>(0, iUpgradeBudget);

if (gPlayerLogLevel > 2)
if (AI_isFinancialTrouble())
{
logBBAI(" %S calculates upgrade budget of %d from %d current gold, %d target", getCivilizationDescription(0), iUpgradeBudget, iStartingGold, iTargetGold);
iUpgradeBudget /= 3;
}

if (AI_isFinancialTrouble())
if (gPlayerLogLevel > 2)
{
iUpgradeBudget /= 3;
logBBAI(" %S calculates upgrade budget of %I64d from %I64d current gold, %d target", getCivilizationDescription(0), iUpgradeBudget, iStartingGold, iTargetGold);
}

// Always willing to upgrade 1 unit if we have the money
Expand Down Expand Up @@ -896,7 +894,7 @@ void CvPlayerAI::AI_doTurnUnitsPost()
if (gPlayerLogLevel > 2 && iStartingGold - getGold() > 0)
{
logBBAI(
" %S spends %d on unit upgrades out of budget of %d, %d effective gold remaining",
" %S spends %I64d on unit upgrades out of budget of %I64d, %I64d effective gold remaining",
getCivilizationDescription(0), iStartingGold - getGold(), iUpgradeBudget, getGold()
);
}
Expand Down Expand Up @@ -10893,19 +10891,13 @@ int CvPlayerAI::AI_unitValue(UnitTypes eUnit, UnitAITypes eUnitAI, const CvArea*
iValue = 0;
break;
}
/************************************************************************************************/
/* BETTER_BTS_AI_MOD 06/12/09 jdog5000 */
/* */
/* Unit AI */
/************************************************************************************************/

iFastMoverMultiplier = AI_isDoStrategy(AI_STRATEGY_FASTMOVERS) ? 3 : 1;

iValue += iCombatValue;
iValue += ((iCombatValue * (kUnitInfo.getMoves() - 1) * iFastMoverMultiplier) / 3); // K-Mod put in -1 !
/************************************************************************************************/
/* BETTER_BTS_AI_MOD END */
/************************************************************************************************/
iValue += ((iCombatValue * (kUnitInfo.getMoves() - 1) * iFastMoverMultiplier) / 3);
iValue += ((iCombatValue * kUnitInfo.getWithdrawalProbability()) / 100);

if (kUnitInfo.getCombatLimit() < 100)
{
iValue -= (iCombatValue * (125 - kUnitInfo.getCombatLimit())) / 100;
Expand Down Expand Up @@ -11422,12 +11414,7 @@ int CvPlayerAI::AI_unitValue(UnitTypes eUnit, UnitAITypes eUnitAI, const CvArea*
iValue += ((iCombatValue * kUnitInfo.getUnitCombatModifier(iI) * AI_getUnitCombatWeight((UnitCombatTypes)iI)) / 10000);
iValue += ((iCombatValue * (kUnitInfo.getDefenderUnitCombat(iI) ? 50 : 0)) / 100);
}
/************************************************************************************************/
/* BETTER_BTS_AI_MOD 03/20/10 jdog5000 */
/* */
/* War strategy AI */
/************************************************************************************************/
//iValue += (kUnitInfo.getInterceptionProbability() * 3);

if (kUnitInfo.getInterceptionProbability() > 0)
{
int iTempValue = kUnitInfo.getInterceptionProbability();
Expand Down Expand Up @@ -11488,15 +11475,8 @@ int CvPlayerAI::AI_unitValue(UnitTypes eUnit, UnitAITypes eUnitAI, const CvArea*
break;
}
}
/************************************************************************************************/
/* BETTER_BTS_AI_MOD 03/08/10 jdog5000 */
/* */
/* Victory Strategy AI */
/************************************************************************************************/

if (AI_isDoVictoryStrategy(AI_VICTORY_CULTURE2))
/************************************************************************************************/
/* BETTER_BTS_AI_MOD END */
/************************************************************************************************/
{
int iTempValue = 0;
for (iI = 0; iI < GC.getNumReligionInfos(); iI++)
Expand All @@ -11515,19 +11495,11 @@ int CvPlayerAI::AI_unitValue(UnitTypes eUnit, UnitAITypes eUnitAI, const CvArea*
if (kUnitInfo.getCorporationSpreads(iI) > 0)
{
iValue += (5 * kUnitInfo.getCorporationSpreads(iI)) / 2;
/************************************************************************************************/
/* UNOFFICIAL_PATCH 06/03/09 jdog5000 */
/* */
/* Bugfix */
/************************************************************************************************/
// Fix potential crash, probably would only happen in mods

if (pArea != NULL)
{
iValue += 300 / std::max(1, pArea->countHasCorporation((CorporationTypes)iI, getID()));
}
/************************************************************************************************/
/* UNOFFICIAL_PATCH END */
/************************************************************************************************/
}
}
}
Expand Down Expand Up @@ -11566,28 +11538,21 @@ int CvPlayerAI::AI_unitValue(UnitTypes eUnit, UnitAITypes eUnitAI, const CvArea*
break;

case UNITAI_ESCORT_SEA:
{
iValue += iCombatValue;
iValue += iCombatValue * kUnitInfo.getMoves();
iValue += kUnitInfo.getInterceptionProbability() * 3;
if (kUnitInfo.getNumSeeInvisibleTypes() > 0)
{
iValue += 200;
}
/************************************************************************************************/
/* UNOFFICIAL_PATCH 06/03/09 jdog5000 */
/* */
/* General AI */
/************************************************************************************************/
// Boats which can't be seen don't play defense, don't make good escorts
// Boats which can't be seen don't play defense, don't make good escorts
if (kUnitInfo.getInvisibleType() != NO_INVISIBLE)
{
iValue /= 2;
}
/************************************************************************************************/
/* UNOFFICIAL_PATCH END */
/************************************************************************************************/
break;

}
case UNITAI_EXPLORE_SEA:
{
int iExploreValue = 100;
Expand All @@ -11614,21 +11579,14 @@ int CvPlayerAI::AI_unitValue(UnitTypes eUnit, UnitAITypes eUnitAI, const CvArea*
case UNITAI_SETTLER_SEA:
case UNITAI_MISSIONARY_SEA:
case UNITAI_SPY_SEA:
{
iValue += (iCombatValue / 2);
iValue += (kUnitInfo.getMoves() * 200);
iValue += (kUnitInfo.getCargoSpace() * 300);
/************************************************************************************************/
/* BETTER_BTS_AI_MOD 05/18/09 jdog5000 */
/* */
/* City AI */
/************************************************************************************************/
// Never build galley transports when ocean faring ones exist (issue mainly for Carracks)
// Never build galley transports when ocean faring ones exist (issue mainly for Carracks)
iValue /= (1 + AI_unitImpassableCount(eUnit));
/************************************************************************************************/
/* BETTER_BTS_AI_MOD END */
/************************************************************************************************/
break;

}
case UNITAI_CARRIER_SEA:
iValue += iCombatValue;
iValue += (kUnitInfo.getMoves() * 50);
Expand Down