Skip to content

Commit

Permalink
Fix demand/bullying operations not being cancelled
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
RecursiveVision committed Jul 7, 2024
1 parent 894fbd4 commit e842ca1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 47 deletions.
6 changes: 1 addition & 5 deletions CvGameCoreDLL_Expansion2/CvDealClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5032,11 +5032,7 @@ void CvGameDeals::ActivateDeal(PlayerTypes eFromPlayer, PlayerTypes eToPlayer, C
continue;

bool bCareful = GET_PLAYER(vAttackingTeam[i]).CountNumDangerousMajorsAtWarWith(true, false) > 0 && GET_PLAYER(vAttackingTeam[i]).GetDiplomacyAI()->GetGlobalCoopWarAgainstState(vTargetTeam[j]) < COOP_WAR_STATE_PREPARING;

if (!GET_PLAYER(vAttackingTeam[i]).HasAnyOffensiveOperationsAgainstPlayer(vTargetTeam[j]))
{
GET_PLAYER(vAttackingTeam[i]).GetMilitaryAI()->RequestCityAttack(vTargetTeam[j], 2, bCareful);
}
GET_PLAYER(vAttackingTeam[i]).GetMilitaryAI()->RequestCityAttack(vTargetTeam[j], 2, bCareful);
}
}

Expand Down
77 changes: 35 additions & 42 deletions CvGameCoreDLL_Expansion2/CvDiplomacyAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9593,15 +9593,15 @@ void CvDiplomacyAI::DoStartCoopWar(PlayerTypes eAllyPlayer, PlayerTypes eTargetP
{
if (!GetPlayer()->isHuman())
{
GetPlayer()->GetMilitaryAI()->RequestCityAttack(eTargetPlayer, 3, GetPlayer()->HasAnyOffensiveOperationsAgainstPlayer(eTargetPlayer));
GetPlayer()->GetMilitaryAI()->RequestCityAttack(eTargetPlayer, 3, false);
}

// Their war declaration
if (GET_PLAYER(eAllyPlayer).IsAtWarWith(eTargetPlayer) || GET_PLAYER(eAllyPlayer).GetDiplomacyAI()->DeclareWar(eTargetPlayer))
{
if (!GET_PLAYER(eAllyPlayer).isHuman())
{
GET_PLAYER(eAllyPlayer).GetMilitaryAI()->RequestCityAttack(eTargetPlayer, 3, GET_PLAYER(eAllyPlayer).HasAnyOffensiveOperationsAgainstPlayer(eTargetPlayer));
GET_PLAYER(eAllyPlayer).GetMilitaryAI()->RequestCityAttack(eTargetPlayer, 3, false);
}

int iMyTurnsAtWar = GET_TEAM(GetTeam()).GetNumTurnsAtWar(GET_PLAYER(eTargetPlayer).getTeam());
Expand Down Expand Up @@ -25489,11 +25489,15 @@ void CvDiplomacyAI::SelectBestApproachTowardsMinorCiv(PlayerTypes ePlayer, std::
vApproachScores[CIV_APPROACH_WAR] = 0;
}

// If we're in bad shape, don't waste time trying to conquer City-States.
// If we're in bad shape, don't waste time trying to go after City-States.
if (GetPlayer()->IsNoNewWars() && (!bTheyCapturedFromUs || GetPlayer()->IsInTerribleShapeForWar()))
{
vApproachScores[CIV_APPROACH_WAR] = 0;
}
if (GetPlayer()->IsNoNewWars())
{
vApproachScores[CIV_APPROACH_HOSTILE] = 0;
}

// If we're already at war with this City-State and the war is going badly, abort!
if (IsAtWar(ePlayer))
Expand Down Expand Up @@ -27933,11 +27937,8 @@ void CvDiplomacyAI::DoMakeWarOnPlayer(PlayerTypes eTargetPlayer)
// Minor Civ
if (GET_PLAYER(eTargetPlayer).isMinorCiv())
{
if (!GetPlayer()->IsNoNewWars())
{
bWantToAttack = GetCSWarTargetPlayer() == eTargetPlayer;
bWantShowOfForce = GetCSBullyTargetPlayer() == eTargetPlayer;
}
bWantToAttack = GetCSWarTargetPlayer() == eTargetPlayer;
bWantShowOfForce = GetCSBullyTargetPlayer() == eTargetPlayer;
}
// Major Civ
else
Expand Down Expand Up @@ -27968,11 +27969,16 @@ void CvDiplomacyAI::DoMakeWarOnPlayer(PlayerTypes eTargetPlayer)
}
else
{
//hmm, seems we changed our mind. abort the operation if it's still ongoing
if (GET_PLAYER(eTargetPlayer).isMajorCiv())
SetCivApproach(eTargetPlayer, GetHighestValueApproach(eTargetPlayer, true, true));
else
SetCivApproach(eTargetPlayer, CIV_APPROACH_NEUTRAL);
//it's possible for an operation to be ongoing here if it was a demand, so cancel it
//sneak attacks vs. major civs are aborted when DoUpdateWarTargets() calls SetCivApproach()
//sneak attacks vs. minor civs are aborted in SelectBestApproachTowardsMinorCiv() or DoUpdateMinorCivApproaches()
CvAIOperation* pCurrentDemandOperation = GetPlayer()->getFirstOffensiveAIOperation(ePlayer);
if (pCurrentDemandOperation)
{
pCurrentDemandOperation->LogOperationSpecialMessage("Show of force cancelled, probably preoccupied with something else");
GetPlayer()->StopAllLandOffensiveOperationsAgainstPlayer(ePlayer,AI_ABORT_DIPLO_OPINION_CHANGE);
GetPlayer()->StopAllSeaOffensiveOperationsAgainstPlayer(ePlayer,AI_ABORT_DIPLO_OPINION_CHANGE);
}
}
}
else
Expand All @@ -27984,35 +27990,32 @@ void CvDiplomacyAI::DoMakeWarOnPlayer(PlayerTypes eTargetPlayer)
if (GET_PLAYER(eTargetPlayer).isMinorCiv())
{
bool bCareful = GetPlayer()->CountNumDangerousMajorsAtWarWith(true, false) > 0;

if (!GetPlayer()->HasAnyOffensiveOperationsAgainstPlayer(eTargetPlayer))
{
GetPlayer()->GetMilitaryAI()->RequestCityAttack(eTargetPlayer, 1, bCareful);
}
GetPlayer()->GetMilitaryAI()->RequestCityAttack(eTargetPlayer, 1, bCareful);
}
// Attack on major
else
{
bool bCareful = (GetPlayer()->IsNoNewWars() || GetPlayer()->CountNumDangerousMajorsAtWarWith(true, true) > 0) && GetGlobalCoopWarAgainstState(eTargetPlayer) < COOP_WAR_STATE_PREPARING;

if (!GetPlayer()->HasAnyOffensiveOperationsAgainstPlayer(eTargetPlayer))
{
GetPlayer()->GetMilitaryAI()->RequestCityAttack(eTargetPlayer, 3, bCareful);
}
GetPlayer()->GetMilitaryAI()->RequestCityAttack(eTargetPlayer, 3, bCareful);
}
}
//we just want to scare them
else if (bWantShowOfForce)
{
GetPlayer()->GetMilitaryAI()->RequestBullyingOperation(eTargetPlayer);
}
//we don't want to attack. abort any ongoing operation.
else if (GetCivApproach(eTargetPlayer) == CIV_APPROACH_WAR)
else
{
if (GET_PLAYER(eTargetPlayer).isMajorCiv())
SetCivApproach(eTargetPlayer, GetHighestValueApproach(eTargetPlayer, true, true));
else
SetCivApproach(eTargetPlayer, CIV_APPROACH_NEUTRAL);
//it's possible for an operation to be ongoing here if it was a demand, so cancel it
//sneak attacks vs. major civs are aborted when DoUpdateWarTargets() calls SetCivApproach()
//sneak attacks vs. minor civs are aborted in SelectBestApproachTowardsMinorCiv() or DoUpdateMinorCivApproaches()
CvAIOperation* pCurrentDemandOperation = GetPlayer()->getFirstOffensiveAIOperation(ePlayer);
if (pCurrentDemandOperation)
{
pCurrentDemandOperation->LogOperationSpecialMessage("Show of force cancelled, probably preoccupied with something else");
GetPlayer()->StopAllLandOffensiveOperationsAgainstPlayer(ePlayer,AI_ABORT_DIPLO_OPINION_CHANGE);
GetPlayer()->StopAllSeaOffensiveOperationsAgainstPlayer(ePlayer,AI_ABORT_DIPLO_OPINION_CHANGE);
}
}
}
}
Expand Down Expand Up @@ -30233,11 +30236,7 @@ void CvDiplomacyAI::DoSendStatementToPlayer(PlayerTypes ePlayer, DiploStatementT
{
pDeal->ClearItems();
bool bCareful = GetPlayer()->CountNumDangerousMajorsAtWarWith(true, true) > 0 && GetGlobalCoopWarAgainstState(ePlayer) < COOP_WAR_STATE_PREPARING;

if (!GetPlayer()->HasAnyOffensiveOperationsAgainstPlayer(ePlayer))
{
GetPlayer()->GetMilitaryAI()->RequestCityAttack(ePlayer, 3, bCareful);
}
GetPlayer()->GetMilitaryAI()->RequestCityAttack(ePlayer, 3, bCareful);
}
}
}
Expand Down Expand Up @@ -30852,10 +30851,7 @@ void CvDiplomacyAI::DoSendStatementToPlayer(PlayerTypes ePlayer, DiploStatementT
if (!bCanBluff && DeclareWar(ePlayer))
{
bool bCareful = iCurrentWars > 0 && GetGlobalCoopWarAgainstState(ePlayer) < COOP_WAR_STATE_PREPARING;
if (!GetPlayer()->HasAnyOffensiveOperationsAgainstPlayer(ePlayer))
{
GetPlayer()->GetMilitaryAI()->RequestCityAttack(ePlayer, 3, bCareful);
}
GetPlayer()->GetMilitaryAI()->RequestCityAttack(ePlayer, 3, bCareful);
}
}
}
Expand Down Expand Up @@ -38835,10 +38831,7 @@ void CvDiplomacyAI::DoFromUIDiploEvent(PlayerTypes eFromPlayer, FromUIDiploEvent
if (!bCanBluff && DeclareWar(eFromPlayer))
{
bool bCareful = iCurrentWars > 0 && GetGlobalCoopWarAgainstState(eFromPlayer) < COOP_WAR_STATE_PREPARING;
if (!GetPlayer()->HasAnyOffensiveOperationsAgainstPlayer(eFromPlayer))
{
GetPlayer()->GetMilitaryAI()->RequestCityAttack(eFromPlayer, 3, bCareful);
}
GetPlayer()->GetMilitaryAI()->RequestCityAttack(eFromPlayer, 3, bCareful);
}
else
bDeclareWar = false;
Expand Down

2 comments on commit e842ca1

@JohnsterID
Copy link
Contributor

@JohnsterID JohnsterID commented on e842ca1 Jul 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RecursiveVision if not already seen, build failed.
https://github.com/LoneGazebo/Community-Patch-DLL/actions/runs/9823065419/job/27120518947

1>CvDiplomacyAI.cpp(27975): error C2065: 'ePlayer' : undeclared identifier
1>CvDiplomacyAI.cpp(27979): error C2065: 'ePlayer' : undeclared identifier
1>CvDiplomacyAI.cpp(27980): error C2065: 'ePlayer' : undeclared identifier
1>CvDiplomacyAI.cpp(28012): error C2065: 'ePlayer' : undeclared identifier
1>CvDiplomacyAI.cpp(28016): error C2065: 'ePlayer' : undeclared identifier
1>CvDiplomacyAI.cpp(28017): error C2065: 'ePlayer' : undeclared identifier

https://productionresultssa0.blob.core.windows.net/actions-results/f96c5c3e-3037-43c5-8854-c0e9bdd96a09/workflow-job-run-c10d9e2f-60df-5bcc-d6bc-33b4959e8306/logs/job/job-logs.txt?rsct=text%2Fplain&se=2024-07-07T01%3A22%3A02Z&sig=Oi2oeU8BqFxLBK5oz9kCpFjGxWUdz9NthZZ9EuhnX6A%3D&ske=2024-07-07T10%3A43%3A05Z&skoid=ca7593d4-ee42-46cd-af88-8b886a2f84eb&sks=b&skt=2024-07-06T22%3A43%3A05Z&sktid=398a6654-997b-47e9-b12b-9515b896b4de&skv=2023-11-03&sp=r&spr=https&sr=b&st=2024-07-07T01%3A11%3A57Z&sv=2023-11-03

2024-07-07T00:19:44.3983277Z ==== D:\a\Community-Patch-DLL\Community-Patch-DLL\CvGameCoreDLL_Expansion2\CvDiplomacyAI.cpp ====
2024-07-07T00:19:44.3984764Z D:\a\Community-Patch-DLL\Community-Patch-DLL\CvGameCoreDLL_Expansion2\CvDiplomacyAI.cpp(23255,5) : warning: variable 'iPrimeScore' set but not used [-Wunused-but-set-variable]
2024-07-07T00:19:44.3985882Z  23255 |         int iPrimeScore = 0;
2024-07-07T00:19:44.3986869Z        |             ^
2024-07-07T00:19:44.3989011Z D:\a\Community-Patch-DLL\Community-Patch-DLL\CvGameCoreDLL_Expansion2\CvDiplomacyAI.cpp(27975,86) : error: use of undeclared identifier 'ePlayer'
2024-07-07T00:19:44.3990686Z  27975 |                         CvAIOperation* pCurrentDemandOperation = GetPlayer()->getFirstOffensiveAIOperation(ePlayer);
2024-07-07T00:19:44.3991573Z        |                                                                                                            ^
2024-07-07T00:19:44.3992809Z D:\a\Community-Patch-DLL\Community-Patch-DLL\CvGameCoreDLL_Expansion2\CvDiplomacyAI.cpp(27979,61) : error: use of undeclared identifier 'ePlayer'
2024-07-07T00:19:44.3994372Z  27979 |                                 GetPlayer()->StopAllLandOffensiveOperationsAgainstPlayer(ePlayer,AI_ABORT_DIPLO_OPINION_CHANGE);
2024-07-07T00:19:44.3995521Z        |                                                                                          ^
2024-07-07T00:19:44.3997158Z D:\a\Community-Patch-DLL\Community-Patch-DLL\CvGameCoreDLL_Expansion2\CvDiplomacyAI.cpp(27980,60) : error: use of undeclared identifier 'ePlayer'
2024-07-07T00:19:44.3998674Z  27980 |                                 GetPlayer()->StopAllSeaOffensiveOperationsAgainstPlayer(ePlayer,AI_ABORT_DIPLO_OPINION_CHANGE);
2024-07-07T00:19:44.3999706Z        |                                                                                         ^
2024-07-07T00:19:44.4001098Z D:\a\Community-Patch-DLL\Community-Patch-DLL\CvGameCoreDLL_Expansion2\CvDiplomacyAI.cpp(28012,86) : error: use of undeclared identifier 'ePlayer'
2024-07-07T00:19:44.4002525Z  28012 |                         CvAIOperation* pCurrentDemandOperation = GetPlayer()->getFirstOffensiveAIOperation(ePlayer);
2024-07-07T00:19:44.4003354Z        |                                                                                                            ^
2024-07-07T00:19:44.4005405Z D:\a\Community-Patch-DLL\Community-Patch-DLL\CvGameCoreDLL_Expansion2\CvDiplomacyAI.cpp(28016,61) : error: use of undeclared identifier 'ePlayer'
2024-07-07T00:19:44.4006410Z  28016 |                                 GetPlayer()->StopAllLandOffensiveOperationsAgainstPlayer(ePlayer,AI_ABORT_DIPLO_OPINION_CHANGE);
2024-07-07T00:19:44.4007559Z        |                                                                                          ^
2024-07-07T00:19:44.4009251Z D:\a\Community-Patch-DLL\Community-Patch-DLL\CvGameCoreDLL_Expansion2\CvDiplomacyAI.cpp(28017,60) : error: use of undeclared identifier 'ePlayer'
2024-07-07T00:19:44.4010289Z  28017 |                                 GetPlayer()->StopAllSeaOffensiveOperationsAgainstPlayer(ePlayer,AI_ABORT_DIPLO_OPINION_CHANGE);
2024-07-07T00:19:44.4011287Z        |                                                                                         ^
2024-07-07T00:19:44.4013563Z D:\a\Community-Patch-DLL\Community-Patch-DLL\CvGameCoreDLL_Expansion2\CvDiplomacyAI.cpp(29487,6) : warning: variable 'bMajorAttackedMajor' set but not used [-Wunused-but-set-variable]
2024-07-07T00:19:44.4013839Z  29487 |         bool bMajorAttackedMajor = false;
2024-07-07T00:19:44.4015260Z        |              ^
2024-07-07T00:19:44.4017821Z D:\a\Community-Patch-DLL\Community-Patch-DLL\CvGameCoreDLL_Expansion2\CvDiplomacyAI.cpp(32241,5) : warning: variable 'iData2' set but not used [-Wunused-but-set-variable]
2024-07-07T00:19:44.4018769Z  32241 |         int iData2 = 0;
2024-07-07T00:19:44.4020797Z        |             ^
2024-07-07T00:19:44.4024373Z D:\a\Community-Patch-DLL\Community-Patch-DLL\CvGameCoreDLL_Expansion2\CvDiplomacyAI.cpp(32648,7) : warning: variable 'bWantsToBullyGoldFromThisMinor' set but not used [-Wunused-but-set-variable]
2024-07-07T00:19:44.4024932Z  32648 |                 bool bWantsToBullyGoldFromThisMinor = false;
2024-07-07T00:19:44.4026445Z        |                      ^
2024-07-07T00:19:44.4028706Z D:\a\Community-Patch-DLL\Community-Patch-DLL\CvGameCoreDLL_Expansion2\CvDiplomacyAI.cpp(56382,5) : warning: variable 'iNumCaps' set but not used [-Wunused-but-set-variable]
2024-07-07T00:19:44.4028930Z  56382 |         int iNumCaps = 0;
2024-07-07T00:19:44.4030373Z        |             ^
2024-07-07T00:19:44.4032581Z D:\a\Community-Patch-DLL\Community-Patch-DLL\CvGameCoreDLL_Expansion2\CvDiplomacyAI.cpp(56542,5) : warning: variable 'iTheirCivs' set but not used [-Wunused-but-set-variable]
2024-07-07T00:19:44.4032813Z  56542 |         int iTheirCivs = 0;
2024-07-07T00:19:44.4034267Z        |             ^
2024-07-07T00:19:44.4035444Z 6 warnings and 6 errors generated.

@RecursiveVision
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I fixed.

Please sign in to comment.