Skip to content

Commit

Permalink
Deal fixes (#11050)
Browse files Browse the repository at this point in the history
Consider a deal for renewal only if all items can be renewed
Fix issues with deal lengths
  • Loading branch information
axatin authored Jun 28, 2024
1 parent a312f61 commit ea9504d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 65 deletions.
15 changes: 8 additions & 7 deletions (1) Community Patch/LUA/TradeLogic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local g_ThemPocketVoteIM = InstanceManager:new( "PocketVote", "Button", Controls
local g_bAlwaysWar = Game.IsOption( GameOptionTypes.GAMEOPTION_ALWAYS_WAR );
local g_bAlwaysPeace = Game.IsOption( GameOptionTypes.GAMEOPTION_ALWAYS_PEACE );
local g_bNoChangeWar = Game.IsOption( GameOptionTypes.GAMEOPTION_NO_CHANGING_WAR_PEACE );
local g_PeaceDealDuration = GameInfo.GameSpeeds[PreGame.GetGameSpeed()].PeaceDealDuration;

local g_bDisableScience = Game.IsOption("GAMEOPTION_NO_SCIENCE");
local g_bDisableLeague = Game.IsOption("GAMEOPTION_NO_LEAGUES");
Expand Down Expand Up @@ -424,8 +425,8 @@ function OnOpenPlayerDealScreen( iOtherPlayer )
g_Deal:SetToPlayer( g_iThem );

if( g_pUsTeam:IsAtWar( g_iThemTeam ) ) then
g_Deal:AddPeaceTreaty( g_iUs, GameDefines.PEACE_TREATY_LENGTH );
g_Deal:AddPeaceTreaty( g_iThem, GameDefines.PEACE_TREATY_LENGTH );
g_Deal:AddPeaceTreaty( g_iUs, g_PeaceDealDuration );
g_Deal:AddPeaceTreaty( g_iThem, g_PeaceDealDuration );
end

DoUpdateButtons();
Expand Down Expand Up @@ -3580,7 +3581,7 @@ function LeaderSelected( iOtherPlayer, isUs )
if( mode == WAR ) then
g_Deal:AddThirdPartyWar( iWho, iOtherTeam );
else
g_Deal:AddThirdPartyPeace( iWho, iOtherTeam, GameDefines.PEACE_TREATY_LENGTH );
g_Deal:AddThirdPartyPeace( iWho, iOtherTeam, g_PeaceDealDuration );
end

DisplayDeal();
Expand Down Expand Up @@ -3753,10 +3754,10 @@ end
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------

Controls.UsMakePeaceDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", 15 );
Controls.UsDeclareWarDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", 15 );
Controls.ThemMakePeaceDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", 15 );
Controls.ThemDeclareWarDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", 15 );
Controls.UsMakePeaceDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", g_PeaceDealDuration);
Controls.UsDeclareWarDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", g_PeaceDealDuration);
Controls.ThemMakePeaceDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", g_PeaceDealDuration);
Controls.ThemDeclareWarDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", g_PeaceDealDuration);

ResetDisplay();
DisplayDeal();
15 changes: 8 additions & 7 deletions (2) Vox Populi/LUA/TradeLogic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ local g_bAlwaysWar = Game.IsOption( GameOptionTypes.GAMEOPTION_ALWAYS_WAR );
local g_bAlwaysPeace = Game.IsOption( GameOptionTypes.GAMEOPTION_ALWAYS_PEACE );
local g_bNoChangeWar = Game.IsOption( GameOptionTypes.GAMEOPTION_NO_CHANGING_WAR_PEACE );

local g_PeaceDealDuration = GameInfo.GameSpeeds[PreGame.GetGameSpeed()].PeaceDealDuration;
local g_bAllowResearchAgreements = Game.IsOption("GAMEOPTION_RESEARCH_AGREEMENTS");
local g_bDisableScience = Game.IsOption("GAMEOPTION_NO_SCIENCE");
local g_bDisableTechTrading = Game.IsOption("GAMEOPTION_NO_TECH_TRADING");
Expand Down Expand Up @@ -439,8 +440,8 @@ function OnOpenPlayerDealScreen( iOtherPlayer )
g_Deal:SetToPlayer( g_iThem );

if( g_pUsTeam:IsAtWar( g_iThemTeam ) ) then
g_Deal:AddPeaceTreaty( g_iUs, GameDefines.PEACE_TREATY_LENGTH );
g_Deal:AddPeaceTreaty( g_iThem, GameDefines.PEACE_TREATY_LENGTH );
g_Deal:AddPeaceTreaty( g_iUs, g_PeaceDealDuration );
g_Deal:AddPeaceTreaty( g_iThem, g_PeaceDealDuration );
end

DoUpdateButtons();
Expand Down Expand Up @@ -4288,7 +4289,7 @@ function LeaderSelected( iOtherPlayer, isUs )
if( mode == WAR ) then
g_Deal:AddThirdPartyWar( iWho, iOtherTeam );
else
g_Deal:AddThirdPartyPeace( iWho, iOtherTeam, GameDefines.PEACE_TREATY_LENGTH );
g_Deal:AddThirdPartyPeace( iWho, iOtherTeam, g_PeaceDealDuration );
end

DisplayDeal();
Expand Down Expand Up @@ -4461,10 +4462,10 @@ end
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------

Controls.UsMakePeaceDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", 15 );
Controls.UsDeclareWarDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", 15 );
Controls.ThemMakePeaceDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", 15 );
Controls.ThemDeclareWarDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", 15 );
Controls.UsMakePeaceDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", g_PeaceDealDuration);
Controls.UsDeclareWarDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", g_PeaceDealDuration);
Controls.ThemMakePeaceDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", g_PeaceDealDuration);
Controls.ThemDeclareWarDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", g_PeaceDealDuration);

ResetDisplay();
DisplayDeal();
15 changes: 8 additions & 7 deletions (3a) EUI Compatibility Files/LUA/TradeLogic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ local g_bAlwaysWar = Game.IsOption( GameOptionTypes.GAMEOPTION_ALWAYS_WAR );
local g_bAlwaysPeace = Game.IsOption( GameOptionTypes.GAMEOPTION_ALWAYS_PEACE );
local g_bNoChangeWar = Game.IsOption( GameOptionTypes.GAMEOPTION_NO_CHANGING_WAR_PEACE );

local g_PeaceDealDuration = GameInfo.GameSpeeds[PreGame.GetGameSpeed()].PeaceDealDuration;
local g_bAllowResearchAgreements = Game.IsOption("GAMEOPTION_RESEARCH_AGREEMENTS");
local g_bDisableScience = Game.IsOption("GAMEOPTION_NO_SCIENCE");
local g_bDisableTechTrading = Game.IsOption("GAMEOPTION_NO_TECH_TRADING");
Expand Down Expand Up @@ -440,8 +441,8 @@ function OnOpenPlayerDealScreen( iOtherPlayer )
g_Deal:SetToPlayer( g_iThem );

if( g_pUsTeam:IsAtWar( g_iThemTeam ) ) then
g_Deal:AddPeaceTreaty( g_iUs, GameDefines.PEACE_TREATY_LENGTH );
g_Deal:AddPeaceTreaty( g_iThem, GameDefines.PEACE_TREATY_LENGTH );
g_Deal:AddPeaceTreaty( g_iUs, g_PeaceDealDuration );
g_Deal:AddPeaceTreaty( g_iThem, g_PeaceDealDuration );
end

DoUpdateButtons();
Expand Down Expand Up @@ -4291,7 +4292,7 @@ function LeaderSelected( iOtherPlayer, isUs )
if( mode == WAR ) then
g_Deal:AddThirdPartyWar( iWho, iOtherTeam );
else
g_Deal:AddThirdPartyPeace( iWho, iOtherTeam, GameDefines.PEACE_TREATY_LENGTH );
g_Deal:AddThirdPartyPeace( iWho, iOtherTeam, g_PeaceDealDuration );
end

DisplayDeal();
Expand Down Expand Up @@ -4464,10 +4465,10 @@ end
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------

Controls.UsMakePeaceDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", 15 );
Controls.UsDeclareWarDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", 15 );
Controls.ThemMakePeaceDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", 15 );
Controls.ThemDeclareWarDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", 15 );
Controls.UsMakePeaceDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", g_PeaceDealDuration);
Controls.UsDeclareWarDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", g_PeaceDealDuration);
Controls.ThemMakePeaceDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", g_PeaceDealDuration);
Controls.ThemDeclareWarDuration:LocalizeAndSetText( "TXT_KEY_DIPLO_TURNS", g_PeaceDealDuration);

ResetDisplay();
DisplayDeal();
10 changes: 5 additions & 5 deletions CvGameCoreDLL_Expansion2/CvDealClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3808,10 +3808,10 @@ bool CvDeal::IsPotentiallyRenewable()
TradedItemList::iterator it;
for(it = m_TradedItems.begin(); it != m_TradedItems.end(); ++it)
{
if (GetItemTradeableState(it->m_eItemType) == DEAL_RENEWABLE)
return true;
if (GetItemTradeableState(it->m_eItemType) == DEAL_NONRENEWABLE)
return false;
}
return false;
return true;
}

bool CvDeal::IsCheckedForRenewal()
Expand Down Expand Up @@ -5119,7 +5119,7 @@ void CvGameDeals::DoTurn()

int iGameTurn = GC.getGame().getGameTurn();

// Check to see if any of our RENEWABLE TradeItems in any of our Deals expire this turn
// Find the deals which don't have any non-renewable items and for which one of the trade items expires this turn
for (it = m_CurrentDeals.begin(); it != m_CurrentDeals.end(); ++it)
{
it->m_bConsideringForRenewal = false;
Expand All @@ -5129,7 +5129,7 @@ void CvGameDeals::DoTurn()
if (GET_PLAYER(it->GetFromPlayer()).isHuman() && GET_PLAYER(it->GetToPlayer()).isHuman())
bHumanToHuman = true;

//if we can renew this deal, we're going to send it to the Diplo AI first.
// if there are non-renewable items in the deal, move on
if (!bHumanToHuman && !it->IsPotentiallyRenewable())
continue;

Expand Down
39 changes: 0 additions & 39 deletions CvGameCoreDLL_Expansion2/CvDiplomacyAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34845,45 +34845,6 @@ CvDeal* CvDiplomacyAI::DoRenewExpiredDeal(PlayerTypes ePlayer, DiploStatementTyp
continue;
}

// if the deal can be fully renewed
TradedItemList tradedItems = pCurrentDeal->m_TradedItems;
TradedItemList::iterator it;

for(it = tradedItems.begin(); it != tradedItems.end(); ++it)
{
PlayerTypes eOtherPlayer;
if (it->m_eFromPlayer == pCurrentDeal->m_eFromPlayer)
{
eOtherPlayer = pCurrentDeal->m_eToPlayer;
}
else
{
eOtherPlayer = pCurrentDeal->m_eFromPlayer;
}

//exclude items that can't be renewed:
if (it->m_eItemType == TRADE_ITEM_GOLD ||
it->m_eItemType == TRADE_ITEM_GOLD_PER_TURN ||
it->m_eItemType == TRADE_ITEM_RESOURCES ||
it->m_eItemType == TRADE_ITEM_OPEN_BORDERS ||
it->m_eItemType == TRADE_ITEM_ALLOW_EMBASSY ||
it->m_eItemType == TRADE_ITEM_DEFENSIVE_PACT)
{
continue;
}

//otherwise remove it.
pCurrentDeal->RemoveByType(it->m_eItemType, it->m_eFromPlayer);

}

//we emptied the deal? whoops.
if (pCurrentDeal->GetNumItems() <= 0)
{
badDeals.push_back(pCurrentDeal);
continue;
}

//Set as considered for renewal.
pCurrentDeal->m_iFinalTurn = -1;

Expand Down

0 comments on commit ea9504d

Please sign in to comment.