Skip to content

Commit

Permalink
Sanitize early AI policy/tech choices
Browse files Browse the repository at this point in the history
  • Loading branch information
RecursiveVision committed Oct 5, 2023
1 parent c9ef988 commit e6e7243
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 73 deletions.
56 changes: 29 additions & 27 deletions CvGameCoreDLL_Expansion2/CvDiplomacyAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9805,27 +9805,14 @@ void CvDiplomacyAI::DoUpdateCurrentVictoryPursuit()
return;
}

AIGrandStrategyTypes eMyGrandStrategy = GetPlayer()->GetGrandStrategyAI()->GetActiveGrandStrategy();
AIGrandStrategyTypes eDomination = (AIGrandStrategyTypes) GC.getInfoTypeForString("AIGRANDSTRATEGY_CONQUEST");
AIGrandStrategyTypes eDiplomacy = (AIGrandStrategyTypes) GC.getInfoTypeForString("AIGRANDSTRATEGY_UNITED_NATIONS");
AIGrandStrategyTypes eCulture = (AIGrandStrategyTypes) GC.getInfoTypeForString("AIGRANDSTRATEGY_CULTURE");
AIGrandStrategyTypes eScience = (AIGrandStrategyTypes) GC.getInfoTypeForString("AIGRANDSTRATEGY_SPACESHIP");

AIGrandStrategyTypes eMyGrandStrategy = GetPlayer()->GetGrandStrategyAI()->GetActiveGrandStrategy();
bool bDontCareAboutWinning = !IsCompetingForVictory() || eMyGrandStrategy == NO_AIGRANDSTRATEGY || GetPlayer()->GetGrandStrategyAI()->GetGrandStrategyPriority(eMyGrandStrategy) <= 500;
int iGameEra = GC.getGame().getCurrentEra();

// AI isn't too focused on victory in the early game
if (eMyGrandStrategy == eDomination && iGameEra < 2 && GetPlayer()->GetNumCapitalCities() <= 0)
{
bDontCareAboutWinning = true;
}
else if (iGameEra < 3)
{
bDontCareAboutWinning = true;
}

// If we don't care about winning, use our primary victory pursuit based on flavors
if (bDontCareAboutWinning)
if (!IsSeriousAboutVictory())
{
switch (GetPrimaryVictoryPursuit())
{
Expand Down Expand Up @@ -9871,6 +9858,26 @@ void CvDiplomacyAI::DoUpdateCurrentVictoryPursuit()
SetCurrentVictoryPursuit(VICTORY_PURSUIT_DOMINATION);
}

bool CvDiplomacyAI::IsSeriousAboutVictory() const
{
AIGrandStrategyTypes eDomination = (AIGrandStrategyTypes) GC.getInfoTypeForString("AIGRANDSTRATEGY_CONQUEST");
AIGrandStrategyTypes eMyGrandStrategy = GetPlayer()->GetGrandStrategyAI()->GetActiveGrandStrategy();
bool bDontCareAboutWinning = !IsCompetingForVictory() || eMyGrandStrategy == NO_AIGRANDSTRATEGY || GetPlayer()->GetGrandStrategyAI()->GetGrandStrategyPriority(eMyGrandStrategy) <= 500;
int iGameEra = GC.getGame().getCurrentEra();

// AI isn't too focused on victory in the early game
if (eMyGrandStrategy == eDomination && iGameEra < 2 && GetPlayer()->GetNumCapitalCities() <= 0)
{
bDontCareAboutWinning = true;
}
else if (iGameEra < 3)
{
bDontCareAboutWinning = true;
}

return !bDontCareAboutWinning;
}

/// Do we consider any players to be expanding too recklessly?
void CvDiplomacyAI::DoUpdateRecklessExpanders()
{
Expand Down Expand Up @@ -10350,11 +10357,7 @@ void CvDiplomacyAI::DoUpdateVictoryDisputeLevels()
if (GC.getGame().getGameTurn() <= 150)
return;

AIGrandStrategyTypes eMyGrandStrategy = GetPlayer()->GetGrandStrategyAI()->GetActiveGrandStrategy();
bool bDontCare = !IsCompetingForVictory() || eMyGrandStrategy == NO_AIGRANDSTRATEGY || GetPlayer()->GetGrandStrategyAI()->GetGrandStrategyPriority(eMyGrandStrategy) <= 500;
int iGameEra = GC.getGame().getCurrentEra();

if (bDontCare)
if (!IsSeriousAboutVictory())
{
for (int iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)
{
Expand All @@ -10364,6 +10367,8 @@ void CvDiplomacyAI::DoUpdateVictoryDisputeLevels()
return;
}

AIGrandStrategyTypes eMyGrandStrategy = GetPlayer()->GetGrandStrategyAI()->GetActiveGrandStrategy();

// Loop through all (valid) Players
for (int iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)
{
Expand Down Expand Up @@ -10400,7 +10405,7 @@ void CvDiplomacyAI::DoUpdateVictoryDisputeLevels()
}

// Reduce competitiveness in earlier eras
iVictoryDisputeWeight -= (6 - iGameEra);
iVictoryDisputeWeight -= (6 - GC.getGame().getCurrentEra());

if (iVictoryDisputeWeight > 0)
{
Expand Down Expand Up @@ -10439,11 +10444,7 @@ void CvDiplomacyAI::DoUpdateVictoryBlockLevels()
if (GC.getGame().getGameTurn() <= 150)
return;

AIGrandStrategyTypes eMyGrandStrategy = GetPlayer()->GetGrandStrategyAI()->GetActiveGrandStrategy();
bool bDontCare = !IsCompetingForVictory() || eMyGrandStrategy == NO_AIGRANDSTRATEGY || GetPlayer()->GetGrandStrategyAI()->GetGrandStrategyPriority(eMyGrandStrategy) <= 500;
int iGameEra = GC.getGame().getCurrentEra();

if (bDontCare)
if (!IsSeriousAboutVictory())
{
for (int iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)
{
Expand All @@ -10453,6 +10454,7 @@ void CvDiplomacyAI::DoUpdateVictoryBlockLevels()
return;
}

AIGrandStrategyTypes eMyGrandStrategy = GetPlayer()->GetGrandStrategyAI()->GetActiveGrandStrategy();
AIGrandStrategyTypes eConquestGrandStrategy = (AIGrandStrategyTypes) GC.getInfoTypeForString("AIGRANDSTRATEGY_CONQUEST");
AIGrandStrategyTypes eCultureGrandStrategy = (AIGrandStrategyTypes) GC.getInfoTypeForString("AIGRANDSTRATEGY_CULTURE");
AIGrandStrategyTypes eUNGrandStrategy = (AIGrandStrategyTypes) GC.getInfoTypeForString("AIGRANDSTRATEGY_UNITED_NATIONS");
Expand Down Expand Up @@ -10587,7 +10589,7 @@ void CvDiplomacyAI::DoUpdateVictoryBlockLevels()

// Add weight for Player's victory competitiveness, meanness and diplobalance desires (1 - 10)
// Average of each is 5, and era goes up by one throughout game.
iVictoryBlockWeight += GetVictoryCompetitiveness() + GetMeanness() + GetDiploBalance() + iGameEra;
iVictoryBlockWeight += GetVictoryCompetitiveness() + GetMeanness() + GetDiploBalance() + GC.getGame().getCurrentEra();
iVictoryBlockWeight += DifficultyModifier;

// Now see what our new Block Level should be
Expand Down
1 change: 1 addition & 0 deletions CvGameCoreDLL_Expansion2/CvDiplomacyAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,7 @@ class CvDiplomacyAI
bool IsEndgameAggressive() const;

void DoUpdateCurrentVictoryPursuit();
bool IsSeriousAboutVictory() const;
void DoUpdateRecklessExpanders();
void DoUpdateWonderSpammers();
void DoUpdateVictoryDisputeLevels();
Expand Down
45 changes: 11 additions & 34 deletions CvGameCoreDLL_Expansion2/CvPolicyAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4812,40 +4812,17 @@ int CvPolicyAI::WeighPolicy(CvPlayer* pPlayer, PolicyTypes ePolicy)
iScienceValue *= (100 + (iScienceInterest / 10));
iScienceValue /= 100;

//And now add them in. Halve if not our main focus.
if (pPlayer->GetDiplomacyAI()->IsGoingForCultureVictory() || pPlayer->GetDiplomacyAI()->IsCloseToCultureVictory())
{
iWeight += iCultureValue;
}
else
{
iWeight += (iCultureValue / 2);
}
if (pPlayer->GetDiplomacyAI()->IsGoingForDiploVictory() || pPlayer->GetDiplomacyAI()->IsCloseToDiploVictory())
{
iWeight += iDiploValue;
}
else
{
iWeight += (iDiploValue / 2);
}
if (pPlayer->GetDiplomacyAI()->IsGoingForSpaceshipVictory() || pPlayer->GetDiplomacyAI()->IsCloseToSpaceshipVictory())
{
iWeight += iScienceValue;
}
else
{
iWeight += (iScienceValue / 2);
}

if (pPlayer->GetDiplomacyAI()->IsGoingForWorldConquest() || pPlayer->GetDiplomacyAI()->IsCloseToWorldConquest())
{
iWeight += iConquestValue;
}
else
{
iWeight += (iConquestValue / 2);
}
bool bSeriousMode = pPlayer->GetDiplomacyAI()->IsSeriousAboutVictory();
bool bConquestFocus = (bSeriousMode && pPlayer->GetDiplomacyAI()->IsGoingForWorldConquest()) || (!bSeriousMode && pPlayer->GetPlayerTraits()->IsWarmonger()) || pPlayer->GetDiplomacyAI()->IsCloseToWorldConquest();
bool bDiploFocus = (bSeriousMode && pPlayer->GetDiplomacyAI()->IsGoingForDiploVictory()) || (!bSeriousMode && pPlayer->GetPlayerTraits()->IsDiplomat()) || pPlayer->GetDiplomacyAI()->IsCloseToDiploVictory();
bool bScienceFocus = (bSeriousMode && pPlayer->GetDiplomacyAI()->IsGoingForSpaceshipVictory()) || (!bSeriousMode && pPlayer->GetPlayerTraits()->IsNerd()) || pPlayer->GetDiplomacyAI()->IsCloseToSpaceshipVictory();
bool bCultureFocus = (bSeriousMode && pPlayer->GetDiplomacyAI()->IsGoingForCultureVictory()) || (!bSeriousMode && pPlayer->GetPlayerTraits()->IsTourism()) || pPlayer->GetDiplomacyAI()->IsCloseToCultureVictory();

// And now add them in. Halve if not our main focus.
iWeight += bConquestFocus ? iConquestValue : iConquestValue / 2;
iWeight += bDiploFocus ? iDiploValue : iDiploValue / 2;
iWeight += bScienceFocus ? iScienceValue : iScienceValue / 2;
iWeight += bCultureFocus ? iCultureValue : iCultureValue / 2;

//If this is an ideology policy, let's snap those up.
if (m_pCurrentPolicies->GetPolicies()->GetPolicyEntry(ePolicy)->GetLevel() > 0)
Expand Down
25 changes: 13 additions & 12 deletions CvGameCoreDLL_Expansion2/CvTechClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1296,10 +1296,11 @@ void CvPlayerTechs::SetGSPriorities()
}

// == Grand Strategy ==
bool bSeekingDiploVictory = m_pPlayer->GetDiplomacyAI()->IsGoingForDiploVictory() || m_pPlayer->GetDiplomacyAI()->IsCloseToDiploVictory() || m_pPlayer->GetPlayerTraits()->IsDiplomat();
bool bSeekingConquestVictory = m_pPlayer->GetDiplomacyAI()->IsGoingForWorldConquest() || m_pPlayer->GetDiplomacyAI()->IsCloseToWorldConquest() || m_pPlayer->GetPlayerTraits()->IsWarmonger();
bool bSeekingCultureVictory = m_pPlayer->GetDiplomacyAI()->IsGoingForCultureVictory() || m_pPlayer->GetDiplomacyAI()->IsCloseToCultureVictory() || m_pPlayer->GetPlayerTraits()->IsTourism();
bool bSeekingScienceVictory = m_pPlayer->GetDiplomacyAI()->IsGoingForSpaceshipVictory() || m_pPlayer->GetDiplomacyAI()->IsCloseToSpaceshipVictory() || m_pPlayer->GetPlayerTraits()->IsNerd();
bool bSeriousMode = m_pPlayer->GetDiplomacyAI()->IsSeriousAboutVictory();
bool bConquestFocus = (bSeriousMode && m_pPlayer->GetDiplomacyAI()->IsGoingForWorldConquest()) || (!bSeriousMode && m_pPlayer->GetPlayerTraits()->IsWarmonger()) || m_pPlayer->GetDiplomacyAI()->IsCloseToWorldConquest();
bool bDiploFocus = (bSeriousMode && m_pPlayer->GetDiplomacyAI()->IsGoingForDiploVictory()) || (!bSeriousMode && m_pPlayer->GetPlayerTraits()->IsDiplomat()) || m_pPlayer->GetDiplomacyAI()->IsCloseToDiploVictory();
bool bScienceFocus = (bSeriousMode && m_pPlayer->GetDiplomacyAI()->IsGoingForSpaceshipVictory()) || (!bSeriousMode && m_pPlayer->GetPlayerTraits()->IsNerd()) || m_pPlayer->GetDiplomacyAI()->IsCloseToSpaceshipVictory();
bool bCultureFocus = (bSeriousMode && m_pPlayer->GetDiplomacyAI()->IsGoingForCultureVictory()) || (!bSeriousMode && m_pPlayer->GetPlayerTraits()->IsTourism()) || m_pPlayer->GetDiplomacyAI()->IsCloseToCultureVictory();
for(int iTechLoop = 0; iTechLoop < GetTechs()->GetNumTechs(); iTechLoop++)
{
TechTypes eTech = (TechTypes)iTechLoop;
Expand All @@ -1318,13 +1319,13 @@ void CvPlayerTechs::SetGSPriorities()

if(pkTechInfo->GetFlavorValue(eFlavor) > 0)
{
if (bSeekingDiploVictory && (GC.getFlavorTypes((FlavorTypes)iFlavor) == "FLAVOR_DIPLOMACY"
if (bDiploFocus && (GC.getFlavorTypes((FlavorTypes)iFlavor) == "FLAVOR_DIPLOMACY"
|| GC.getFlavorTypes((FlavorTypes)iFlavor) == "FLAVOR_GOLD"
|| GC.getFlavorTypes((FlavorTypes)iFlavor) == "FLAVOR_ESPIONAGE"))
{
m_piGSTechPriority[iTechLoop]++;
}
if(bSeekingConquestVictory && (
if(bConquestFocus && (
GC.getFlavorTypes((FlavorTypes)iFlavor) == "FLAVOR_OFFENSE" ||
GC.getFlavorTypes((FlavorTypes)iFlavor) == "FLAVOR_MILITARY_TRAINING" ||
GC.getFlavorTypes((FlavorTypes)iFlavor) == "FLAVOR_MOBILE" ||
Expand All @@ -1344,14 +1345,14 @@ void CvPlayerTechs::SetGSPriorities()
{
m_piGSTechPriority[iTechLoop]++;
}
if(bSeekingCultureVictory && (
if(bCultureFocus && (
GC.getFlavorTypes((FlavorTypes)iFlavor) == "FLAVOR_CULTURE" ||
GC.getFlavorTypes((FlavorTypes)iFlavor) == "FLAVOR_GREAT_PEOPLE" ||
GC.getFlavorTypes((FlavorTypes)iFlavor) == "FLAVOR_WONDER"))
{
m_piGSTechPriority[iTechLoop]++;
}
if(bSeekingScienceVictory && (GC.getFlavorTypes((FlavorTypes)iFlavor) == "FLAVOR_SCIENCE" || GC.getFlavorTypes((FlavorTypes)iFlavor) == "FLAVOR_SPACESHIP"))
if(bScienceFocus && (GC.getFlavorTypes((FlavorTypes)iFlavor) == "FLAVOR_SCIENCE" || GC.getFlavorTypes((FlavorTypes)iFlavor) == "FLAVOR_SPACESHIP"))
{
m_piGSTechPriority[iTechLoop]++;
}
Expand Down Expand Up @@ -1397,22 +1398,22 @@ void CvPlayerTechs::SetGSPriorities()
{
m_piGSTechPriority[iTechLoop]+= max(1, 10 - m_pPlayer->getNumCities());
}
if (bSeekingConquestVictory)
if (bConquestFocus)
{
if (pkUnitInfo->GetCombat() > 0 || pkUnitInfo->GetRangedCombat() > 0)
{
m_piGSTechPriority[iTechLoop]++;
}
}
if (bSeekingScienceVictory && pkUnitInfo->GetSpaceshipProject() != NO_PROJECT)
if (bScienceFocus && pkUnitInfo->GetSpaceshipProject() != NO_PROJECT)
{
m_piGSTechPriority[iTechLoop]++;
}
if (bSeekingDiploVictory && pkUnitInfo->IsTrade() || pkUnitInfo->GetBaseGold() > 0 || pkUnitInfo->GetDefaultUnitAIType() == UNITAI_MESSENGER)
if (bDiploFocus && pkUnitInfo->IsTrade() || pkUnitInfo->GetBaseGold() > 0 || pkUnitInfo->GetDefaultUnitAIType() == UNITAI_MESSENGER)
{
m_piGSTechPriority[iTechLoop]++;
}
if (bSeekingCultureVictory && pkUnitInfo->GetDefaultUnitAIType() == UNITAI_ARCHAEOLOGIST)
if (bCultureFocus && pkUnitInfo->GetDefaultUnitAIType() == UNITAI_ARCHAEOLOGIST)
{
m_piGSTechPriority[iTechLoop]++;
}
Expand Down

0 comments on commit e6e7243

Please sign in to comment.