From c12b085b88f290ddf8c7d8e0bdd4052bae009f4b Mon Sep 17 00:00:00 2001 From: ilteroi Date: Thu, 14 Dec 2023 20:40:54 +0100 Subject: [PATCH] AI should be more careful with prophets and archeologists --- CvGameCoreDLL_Expansion2/CvDealAI.h | 2 +- CvGameCoreDLL_Expansion2/CvHomelandAI.cpp | 6 +++--- CvGameCoreDLL_Expansion2/CvReligionClasses.cpp | 12 +++++++----- CvGameCoreDLL_Expansion2/CvUnit.cpp | 7 +++++++ CvGameCoreDLL_Expansion2/CvUnit.h | 1 + 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/CvGameCoreDLL_Expansion2/CvDealAI.h b/CvGameCoreDLL_Expansion2/CvDealAI.h index 6e6b3cc432..73f668a116 100644 --- a/CvGameCoreDLL_Expansion2/CvDealAI.h +++ b/CvGameCoreDLL_Expansion2/CvDealAI.h @@ -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 CvDealAI::GetStrategicResourceItemList(ResourceTypes eResource, int iNumTurns, bool bFromMe, int iNumAvailable, bool bPeaceDeal); + vector 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); diff --git a/CvGameCoreDLL_Expansion2/CvHomelandAI.cpp b/CvGameCoreDLL_Expansion2/CvHomelandAI.cpp index 9d3db7d26b..78d26d1b87 100644 --- a/CvGameCoreDLL_Expansion2/CvHomelandAI.cpp +++ b/CvGameCoreDLL_Expansion2/CvHomelandAI.cpp @@ -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: { @@ -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; diff --git a/CvGameCoreDLL_Expansion2/CvReligionClasses.cpp b/CvGameCoreDLL_Expansion2/CvReligionClasses.cpp index 1094c4fe16..0ae9002522 100644 --- a/CvGameCoreDLL_Expansion2/CvReligionClasses.cpp +++ b/CvGameCoreDLL_Expansion2/CvReligionClasses.cpp @@ -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) @@ -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; } diff --git a/CvGameCoreDLL_Expansion2/CvUnit.cpp b/CvGameCoreDLL_Expansion2/CvUnit.cpp index 5ec312ef6b..95982cf41e 100644 --- a/CvGameCoreDLL_Expansion2/CvUnit.cpp +++ b/CvGameCoreDLL_Expansion2/CvUnit.cpp @@ -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 // -------------------------------------------------------------------------------- diff --git a/CvGameCoreDLL_Expansion2/CvUnit.h b/CvGameCoreDLL_Expansion2/CvUnit.h index 71921c088a..a59736e134 100644 --- a/CvGameCoreDLL_Expansion2/CvUnit.h +++ b/CvGameCoreDLL_Expansion2/CvUnit.h @@ -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);