Skip to content

Commit

Permalink
fix some suicidal tendencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteroi authored and RecursiveVision committed Jan 20, 2025
1 parent bcf6fff commit e5bbee0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
9 changes: 3 additions & 6 deletions CvGameCoreDLL_Expansion2/CvHomelandAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2414,9 +2414,7 @@ bool CvHomelandAI::ExecuteExplorerMoves(CvUnit* pUnit)

//if there is an improvement to plunder and we can flee
if (tile->iMovesLeft > GD_INT_GET(MOVE_DENOMINATOR) &&
pEvalPlot->getRevealedImprovementType(pUnit->getTeam()) != NO_IMPROVEMENT &&
pEvalPlot->getResourceType() != NO_RESOURCE &&
!pEvalPlot->IsImprovementPillaged() &&
pUnit->canPillage(pEvalPlot) &&
pUnit->GetDanger(pEvalPlot) < pUnit->GetCurrHitPoints())
{
pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), pEvalPlot->getX(), pEvalPlot->getY());
Expand Down Expand Up @@ -2590,7 +2588,8 @@ bool CvHomelandAI::ExecuteExplorerMoves(CvUnit* pUnit)

//in case it was non-native scout, reset the unit AI
pUnit->AI_setUnitAIType(pUnit->getUnitInfo().GetDefaultUnitAIType());
return true; //nothing left to do
ExecuteMovesToSafestPlot(pUnit);
return true;
}
}

Expand Down Expand Up @@ -6208,7 +6207,6 @@ const char* homelandMoveNames[] =
"H_MOVE_SENTRY",
"H_MOVE_SENTRY_NAVAL",
"H_MOVE_WORKER",
"H_MOVE_WORKER_SEA",
"H_MOVE_PATROL",
"H_MOVE_UPGRADE",
"H_MOVE_WRITER",
Expand All @@ -6230,7 +6228,6 @@ const char* homelandMoveNames[] =
"H_MOVE_DIPLOMAT_EMBASSY",
"H_MOVE_MESSENGER",
"H_MOVE_SECONDARY_SETTLER",
"H_MOVE_SECONDARY_WORKER",
};

const char* directiveNames[] =
Expand Down
12 changes: 8 additions & 4 deletions CvGameCoreDLL_Expansion2/CvTacticalAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6709,6 +6709,10 @@ bool TacticalAIHelpers::IsGoodPlotForStaging(CvPlayer* pPlayer, CvPlot* pCandida
if (iPassableNeighbors<3)
return false;

//we don't know the unit, so use a rough estimation ...
if (pPlayer->GetPlotDanger(*pCandidate, false) > /*10*/ GD_INT_GET(NEUTRAL_HEAL_RATE))
return false;

return true;
}

Expand Down Expand Up @@ -6755,7 +6759,7 @@ CvPlot* TacticalAIHelpers::FindClosestSafePlotForHealing(CvUnit* pUnit, bool bCo
//don't check movement, don't need to heal right now
if (pUnit->getDomainType() == DOMAIN_LAND)
{
if (!pUnit->canHeal(pPlot, true))
if (!pUnit->canHeal(pPlot, false))
continue;

//don't mess with (ranged) garrisons if enemies are around
Expand Down Expand Up @@ -6793,9 +6797,9 @@ CvPlot* TacticalAIHelpers::FindClosestSafePlotForHealing(CvUnit* pUnit, bool bCo

//make up a score function
//this is difficult, danger does not consider cover from our own units
//on the other hand, our covering units might run away ...
int iRemainingDanger = iDanger - nFriends * 50 + pUnit->GetCurrHitPoints();
int iScore = (iHealRate - iRemainingDanger) * 10;
//on the other hand, our covering units might run away ... just assume an even spread
int iRemainingDanger = iDanger / (nFriends+1);
int iScore = (pUnit->GetCurrHitPoints() + iHealRate - iRemainingDanger) * 10;
//is this safe enough?
if (iScore > 0)
{
Expand Down
7 changes: 7 additions & 0 deletions CvGameCoreDLL_Expansion2/CvUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7574,6 +7574,13 @@ bool CvUnit::canHeal(const CvPlot* pPlot, bool bCheckMovement) const
if (isBarbarian())
return false;

if (pPlot == NULL)
return false;

//if this is a hypothetical check, hitpoints don't matter
if (pPlot == plot() && !IsHurt())
return false;

CvPlayer& kPlayer = GET_PLAYER(getOwner());
if (MOD_BALANCE_CORE_MILITARY_RESOURCES && kPlayer.isMajorCiv())
{
Expand Down

0 comments on commit e5bbee0

Please sign in to comment.