Skip to content

Commit

Permalink
AI should be more careful with prophets and archeologists
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteroi authored and RecursiveVision committed Dec 15, 2023
1 parent 5ca6ac6 commit c12b085
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CvGameCoreDLL_Expansion2/CvDealAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CvDealAI
int GetGPTForForValueExchange(int iGPTorValue, bool bNumGPTFromValue, int iNumTurns, bool bFromMe, PlayerTypes eOtherPlayer);
int GetResourceValue(ResourceTypes eResource, int iResourceQuantity, int iNumTurns, bool bFromMe, PlayerTypes eOtherPlayer, int iCurrentNetGoldOfReceivingPlayer);
int GetLuxuryResourceValue(ResourceTypes eResource, int iNumTurns, bool bFromMe, PlayerTypes eOtherPlayer, int iCurrentNetGoldOfReceivingPlayer);
vector<int> CvDealAI::GetStrategicResourceItemList(ResourceTypes eResource, int iNumTurns, bool bFromMe, int iNumAvailable, bool bPeaceDeal);
vector<int> GetStrategicResourceItemList(ResourceTypes eResource, int iNumTurns, bool bFromMe, int iNumAvailable, bool bPeaceDeal);
int GetStrategicResourceValue(ResourceTypes eResource, int iResourceQuantity, int iNumTurns, bool bFromMe, PlayerTypes eOtherPlayer, int iCurrentNetGoldOfReceivingPlayer);
int GetEmbassyValue(bool bFromMe, PlayerTypes eOtherPlayer);
int GetOpenBordersValue(bool bFromMe, PlayerTypes eOtherPlayer);
Expand Down
6 changes: 3 additions & 3 deletions CvGameCoreDLL_Expansion2/CvHomelandAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3266,7 +3266,7 @@ void CvHomelandAI::ExecuteMusicianMoves()
switch(eDirective)
{
case GREAT_PEOPLE_DIRECTIVE_TOURISM_BLAST:
break;
break; //we have an (escorted) AI operation for this

case GREAT_PEOPLE_DIRECTIVE_USE_POWER:
{
Expand Down Expand Up @@ -5342,8 +5342,8 @@ CvPlot* CvHomelandAI::FindArchaeologistTarget(CvUnit *pUnit)
}
}

int iTurns = pUnit->TurnsToReachTarget(pTarget, CvUnit::MOVEFLAG_NO_ENEMY_TERRITORY|CvUnit::MOVEFLAG_TURN_END_IS_NEXT_TURN, iBestTurns);
if (iTurns < iBestTurns)
int iTurns = INT_MAX;
if (pUnit->GeneratePath(pTarget, CvUnit::MOVEFLAG_NO_ENEMY_TERRITORY | CvUnit::MOVEFLAG_TURN_END_IS_NEXT_TURN, iBestTurns, &iTurns) && pUnit->CachedPathIsSafeForCivilian())
{
pBestTarget = pTarget;
iBestTurns = iTurns;
Expand Down
12 changes: 7 additions & 5 deletions CvGameCoreDLL_Expansion2/CvReligionClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6710,18 +6710,17 @@ CvCity *CvReligionAI::ChooseProphetConversionCity(CvUnit* pUnit, int* piTurns) c
std::reverse(vCandidates.begin(),vCandidates.end());

//look at the top two and take the one that is closest
int iFlags = CvUnit::MOVEFLAG_NO_ENEMY_TERRITORY | CvUnit::MOVEFLAG_APPROX_TARGET_RING1 | CvUnit::MOVEFLAG_ABORT_IF_NEW_ENEMY_REVEALED;
if (pUnit && vCandidates.size()>1)
{
int iFlags = CvUnit::MOVEFLAG_NO_ENEMY_TERRITORY | CvUnit::MOVEFLAG_APPROX_TARGET_RING1 | CvUnit::MOVEFLAG_ABORT_IF_NEW_ENEMY_REVEALED;

int iTurnsToTargetA = INT_MAX;
int iTurnsToTargetB = INT_MAX;
int iScoreA = 0;
int iScoreB = 0;

if (pUnit->GeneratePath(vCandidates[0].pPlot, iFlags, INT_MAX, &iTurnsToTargetA))
if (pUnit->GeneratePath(vCandidates[0].pPlot, iFlags, INT_MAX, &iTurnsToTargetA) && pUnit->CachedPathIsSafeForCivilian())
iScoreA = vCandidates[0].score / (iTurnsToTargetA + 3); //add some bias for close targets
if (pUnit->GeneratePath(vCandidates[1].pPlot, iFlags, INT_MAX, &iTurnsToTargetB))
if (pUnit->GeneratePath(vCandidates[1].pPlot, iFlags, INT_MAX, &iTurnsToTargetB) && pUnit->CachedPathIsSafeForCivilian())
iScoreB = vCandidates[1].score / (iTurnsToTargetB + 3); //add some bias for close targets

if (iScoreA > 0 && iScoreA > iScoreB)
Expand All @@ -6738,7 +6737,10 @@ CvCity *CvReligionAI::ChooseProphetConversionCity(CvUnit* pUnit, int* piTurns) c
}
}
else if (!vCandidates.empty())
return vCandidates.front().pPlot->getPlotCity();
{
if (pUnit->GeneratePath(vCandidates[0].pPlot, iFlags, INT_MAX) && pUnit->CachedPathIsSafeForCivilian())
return vCandidates.front().pPlot->getPlotCity();
}

return NULL;
}
Expand Down
7 changes: 7 additions & 0 deletions CvGameCoreDLL_Expansion2/CvUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31050,6 +31050,13 @@ const CvPathNodeArray& CvUnit::GetLastPath() const
return m_kLastPath;
}

bool CvUnit::CachedPathIsSafeForCivilian() const
{
//check if the unit can be captured this turn
CvPlot* pCheck = GetPathEndFirstTurnPlot();
return !pCheck || GET_PLAYER(m_eOwner).GetPlotDanger(*pCheck,false) < GetCurrHitPoints();
}

// PRIVATE METHODS

// --------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions CvGameCoreDLL_Expansion2/CvUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1911,6 +1911,7 @@ class CvUnit
int GetMovementPointsAtCachedTarget() const;
CvPlot* GetLastValidDestinationPlotInCachedPath() const;
const CvPathNodeArray& GetLastPath() const;
bool CachedPathIsSafeForCivilian() const;

bool IsEmbarkAllWater() const;
void ChangeEmbarkAllWaterCount(int iValue);
Expand Down

0 comments on commit c12b085

Please sign in to comment.