ifLaMaster
Chieftain
- Joined
- Jan 21, 2015
- Messages
- 24
Oh, i see. Well, at least it work. 

local iResolutionWorldLeader = GameInfoTypes.RESOLUTION_DIPLOMATIC_VICTORY
local iResolutionHost = GameInfoTypes.RESOLUTION_CHANGE_LEAGUE_HOST
local iResolutionEmbargo = GameInfoTypes.RESOLUTION_PLAYER_EMBARGO
local sDecisionYesNo = "RESOLUTION_DECISION_YES_OR_NO"
local kChoiceNo = 0;
local kChoiceYes = 1;
--
-- [B]Main voting functions[/B] - World Leader, Host and Proposals
-- Return true if ALL remaining votes used
--
function [B]CastVotesForWorldLeader[/B](iPlayer, iLeague, proposal)
local pLeague = Game.GetLeague(iLeague)
local iNumVotes = pLeague:GetRemainingVotesForMember(iPlayer)
local iProposedPlayer = -1
print(string.format("CastVotesForWorldLeader: %s with %i votes", Players[iPlayer]:GetName(), iNumVotes))
------
------ FOR TESTING ONLY, USE THE SAME DECISION MAKING PROCESS AS FOR THE HOST
------
return CastVotesForHost(iPlayer, iLeague, proposal)
end
function [B]CastVotesForHost[/B](iPlayer, iLeague, proposal)
local pLeague = Game.GetLeague(iLeague)
local iCurrentHost = pLeague:GetHostMember()
local iNumVotes = pLeague:GetRemainingVotesForMember(iPlayer)
local iProposedPlayer = -1
print(string.format("CastVotesForHost: %s with %i votes", Players[iPlayer]:GetName(), iNumVotes))
-- Set iProposedPlayer to our preferred host, or leave at -1 for the standard (DLL hard-coded) AI decision
if (iCurrentHost == iPlayer) then
-- I'm the host, always vote for myself
iProposedPlayer = iCurrentHost
else
local pPlayer = Players[iPlayer]
if (pPlayer:IsDoF(iCurrentHost)) then
-- I have a DoF with the current host, so vote for them
iProposedPlayer = iCurrentHost
else
-- Including myself, find the player I have a DoF with who has the largest number of votes (in the case of a tie, the strongest) and vote for them
iProposedPlayer = iPlayer
local iMostVotes = iNumVotes
local iDecision = GameInfo.ResolutionDecisions[GameInfo.Resolutions[proposal.ID].VoterDecision].ID
for _, iChoice in ipairs(pLeague:GetChoicesForDecision(iDecision, iPlayer)) do
if (iChoice ~= iPlayer) then
if (pPlayer:IsDoF(iChoice)) then
local iVotes = pLeague:GetRemainingVotesForMember(iChoice)
-- I have a DoF with this player, are they in a better position to win?
if (iVotes > iMostVotes or (iVotes == iMostVotes and Players[iChoice]:GetPower() > Players[iProposedPlayer]:GetPower())) then
iProposedPlayer = iChoice
iMostVotes = iVotes
end
end
end
end
end
end
if (iProposedPlayer and iProposedPlayer ~= -1) then
print(string.format(" voting for %i (%s)", iProposedPlayer, Players[iProposedPlayer]:GetName()))
pLeague:DoVoteEnact(proposal.ID, iPlayer, iNumVotes, iProposedPlayer)
return true
end
return false
end
function [B]CastVotesForProposals[/B](iPlayer, iLeague, enactProposals, repealProposals)
local pLeague = Game.GetLeague(iLeague)
local iNumVotes = pLeague:GetRemainingVotesForMember(iPlayer)
print(string.format("CastVotesForProposals: %s with %i votes", Players[iPlayer]:GetName(), iNumVotes))
-- If not all votes are cast, the default logic in the DLL will allocate the rest
local bVoted = (
CastVotesAgainstEnactEmbargoMe(iPlayer, pLeague, enactProposals) or
CastVotesForEnactMyProposal(iPlayer, pLeague, enactProposals) or
CastVotesForRepealMyProposal(iPlayer, pLeague, repealProposals)
)
return bVoted
end
--
-- [B]Sub-functions for voting [/B]for/against specific proposals.
-- Return true if ALL remaining votes used
--
function [I]CastVotesAgainstEnactEmbargoMe[/I](iPlayer, pLeague, proposals)
local iNumVotes = pLeague:GetRemainingVotesForMember(iPlayer)
local temp = GetProposalsByTypeOnPlayer(proposals, iResolutionEmbargo, iPlayer)
if (#temp > 0) then
-- Vote against an embargo on me!
print(string.format("%s voting AGAINST an ENACT of an embargo on them", Players[iPlayer]:GetName()))
pLeague:DoVoteEnact(temp[1].ID, iPlayer, iNumVotes, kChoiceNo)
return true
end
return false
end
function [I]CastVotesForEnactMyProposal[/I](iPlayer, pLeague, proposals)
local iNumVotes = pLeague:GetRemainingVotesForMember(iPlayer)
local proposal = GetProposalByPlayer(proposals, iPlayer)
if (proposal and IsYesNoDecision(proposal)) then
-- Vote for my proposal
print(string.format("%s voting FOR their own proposal (ENACT)", Players[iPlayer]:GetName()))
pLeague:DoVoteEnact(proposal.ID, iPlayer, iNumVotes, kChoiceYes)
return true
end
return false
end
function [I]CastVotesForRepealMyProposal[/I](iPlayer, pLeague, proposals)
local iNumVotes = pLeague:GetRemainingVotesForMember(iPlayer)
local proposal = GetProposalByPlayer(proposals, iPlayer)
if (proposal and IsYesNoDecision(proposal)) then
-- Vote for my proposal
print(string.format("%s voting FOR their own proposal (REPEAL)", Players[iPlayer]:GetName()))
pLeague:DoVoteRepeal(proposal.ID, iPlayer, iNumVotes, kChoiceYes)
return true
end
return false
end
--
-- [B]Voting helper functions[/B]
--
function [I]GetProposalByPlayer[/I](proposals, iPlayer)
for _, proposal in ipairs(proposals) do
if (proposal.ProposalPlayer == iPlayer) then
return proposal
end
end
return nil
end
function [I]GetProposalsByTypeOnPlayer[/I](proposals, iType, iPlayer)
local temp = {}
for _, proposal in ipairs(proposals) do
if (proposal.Type == iType and proposal.ProposerDecision == iPlayer) then
table.insert(temp, proposal)
end
end
return temp
end
function [I]IsYesNoDecision[/I](proposal)
return (GameInfo.Resolutions[proposal.Type].VoterDecision == sDecisionYesNo)
end
--
-- [B]Main proposing function[/B]
-- Return true if ALL remaining proposals used
--
function [B]Propose[/B](iPlayer, pLeague)
local bProposed = (
ProposeRepealEmbargoMe(iPlayer, pLeague) or
ProposeRepealEmbargoHost(iPlayer, pLeague) or
ProposeEnactEmbargoHost(iPlayer, pLeague)
)
return bProposed
end
--
-- [B]Sub-functions for specific proposals[/B]
-- Return true if all proposals made
--
function [I]ProposeRepealEmbargoMe[/I](iPlayer, pLeague)
if (pLeague:IsPlayerEmbargoed(iPlayer)) then
RepealEmbargo(iPlayer, pLeague, iPlayer)
end
return (pLeague:GetRemainingProposalsForMember(iPlayer) == 0)
end
function [I]ProposeRepealEmbargoHost[/I](iPlayer, pLeague)
local iCurrentHost = pLeague:GetHostMember()
if (iCurrentHost ~= iPlayer and pLeague:IsPlayerEmbargoed(iCurrentHost)) then
local pPlayer = Players[iPlayer]
if (pPlayer:IsDoF(iCurrentHost)) then
RepealEmbargo(iPlayer, pLeague, iCurrentHost)
end
end
return (pLeague:GetRemainingProposalsForMember(iPlayer) == 0)
end
function [I]ProposeEnactEmbargoHost[/I](iPlayer, pLeague)
local iCurrentHost = pLeague:GetHostMember()
if (iCurrentHost ~= iPlayer and not pLeague:IsPlayerEmbargoed(iCurrentHost)) then
local pPlayer = Players[iPlayer]
-- If iPlayer is at war with, or really hates, the host ...
if (pPlayer:IsAtWarWith(iCurrentHost) or pPlayer:GetMajorCivApproach(iCurrentHost) == MajorCivApproachTypes.MAJOR_CIV_APPROACH_HOSTILE) then
EnactEmbargo(iPlayer, pLeague, iCurrentHost)
end
end
return (pLeague:GetRemainingProposalsForMember(iPlayer) == 0)
end
--
-- [B]Proposal helper functions[/B]
--
function [I]EnactEmbargo[/I](iPlayer, pLeague, iEmbargoedPlayer)
if (pLeague:CanProposeEnact(iResolutionEmbargo, iPlayer, iEmbargoedPlayer)) then
print(string.format("%s proposing to ENACT an embargo on %s", Players[iPlayer]:GetName(), Players[iEmbargoedPlayer]:GetName()))
pLeague:DoProposeEnact(iResolutionEmbargo, iPlayer, iEmbargoedPlayer)
end
end
function [I]RepealEmbargo[/I](iPlayer, pLeague, iEmbargoedPlayer)
local iProposal
for _, proposal in ipairs(pLeague:GetActiveResolutions()) do
if (proposal.Type == iResolutionEmbargo and proposal.ProposerDecision == iEmbargoedPlayer) then
iProposal = proposal.ID
break
end
end
if (iProposal and pLeague:CanProposeRepeal(iProposal, iPlayer)) then
print(string.format("%s proposing to REPEAL an embargo on %s", Players[iPlayer]:GetName(), Players[iEmbargoedPlayer]:GetName()))
pLeague:DoProposeRepeal(iProposal, iPlayer)
end
end
--
-- [B]Main event handlers[/B]
--
function [B]OnResolutionProposing[/B](iPlayer, iLeague)
print(string.format("OnResolutionProposing(%s)", Players[iPlayer]:GetName()))
local pLeague = Game.GetLeague(iLeague)
return Propose(iPlayer, pLeague)
end
GameEvents.ResolutionProposing.Add(OnResolutionProposing)
function [B]OnResolutionVoting[/B](iPlayer, iLeague)
print(string.format("OnResolutionVoting(%s)", Players[iPlayer]:GetName()))
local pLeague = Game.GetLeague(iLeague)
local enactProposals = pLeague:GetEnactProposals()
local repealProposals = pLeague:GetRepealProposals()
local iProposal = (#enactProposals == 1) and enactProposals[1].Type
local bVoted
if (#enactProposals == 1 and #repealProposals == 0 and (iProposal == iResolutionWorldLeader or iProposal == iResolutionHost)) then
if (iProposal == iResolutionWorldLeader) then
bVoted = CastVotesForWorldLeader(iPlayer, iLeague, enactProposals[1])
else
bVoted = CastVotesForHost(iPlayer, iLeague, enactProposals[1])
end
else
bVoted = CastVotesForProposals(iPlayer, iLeague, enactProposals, repealProposals)
end
return bReturn
end
GameEvents.ResolutionVoting.Add(OnResolutionVoting)
LUAAPIEXTN(IsOnFeature, bool, iFeatureType);
LUAAPIEXTN(IsAdjacentToFeature, bool, iFeatureType);
LUAAPIEXTN(IsWithinDistanceOfFeature, bool, iFeatureType, iDistance);
LUAAPIEXTN(IsOnImprovement, bool, iImprovementType);
LUAAPIEXTN(IsAdjacentToImprovement, bool, iImprovementType);
LUAAPIEXTN(IsWithinDistanceOfImprovement, bool, iImprovementType, iDistance);
LUAAPIEXTN(IsOnPlotType, bool, iPlotType);
LUAAPIEXTN(IsAdjacentToPlotType, bool, iPlotType);
LUAAPIEXTN(IsWithinDistanceOfPlotType, bool, iPlotType, iDistance);
LUAAPIEXTN(IsOnResource, bool, iResourceType);
LUAAPIEXTN(IsAdjacentToResource, bool, iResourceType);
LUAAPIEXTN(IsWithinDistanceOfResource, bool, iResourceType, iDistance);
LUAAPIEXTN(IsOnTerrain, bool, iTerrainType);
LUAAPIEXTN(IsAdjacentToTerrain, bool, iTerrainType);
LUAAPIEXTN(IsWithinDistanceOfTerrain, bool, iTerrainType, iDistance);
LUAAPIEXTN(CountFeature, int, iFeature);
LUAAPIEXTN(CountWorkedFeature, int, iFeature);
LUAAPIEXTN(CountImprovement, int, iImprovement);
LUAAPIEXTN(CountWorkedImprovement, int, iImprovement);
LUAAPIEXTN(CountPlotType, int, iPlotType);
LUAAPIEXTN(CountWorkedPlotType, int, iPlotType);
LUAAPIEXTN(CountResource, int, iResource);
LUAAPIEXTN(CountWorkedResource, int, iResource);
LUAAPIEXTN(CountTerrain, int, iTerrain);
LUAAPIEXTN(CountWorkedTerrain, int, iTerrain);
Displays a summary of key events as a tooltip on the date and turn indicators in the top panel
To be honest, often your sentences are quite short and we are not 100% clear what you meanI sometimes wonder why I write this stuff![]()
Thank you very much !And you can avoid the "plot maths" by using the plot iterator helper functions I wrote some years back
Yeah, it was as much a dig at myself as anyone - don't forget I'm British and we only do sarcasm as humourTo be honest, often your sentences are quite short and we are not 100% clear what you mean![]()
Maybe make another thread, post there a list of links to great stuff like this and pin the thread in your signature?![]()
Bookmarked, thanks
Trades only hold up for what seem like a couple of turns. I'll exchange luxuries with an AI, and then a couple of turns (maybe one turn? maybe five? certainly not 90) later I'll see a trade request from the same AI for the same luxury.
This.contact JdH directly
For the AI - Warmonger Adjustments, I set WARMONGER_THREAT_AGGRIEVED_PERCENT to 0. Yet I still get pretty substantial warmonger penalties after capturing cities from a civ that DOWed me. Is it supposed to be that way? How to I reduce it even further, preferably close to zero warmonger penalties? Can I put in a negative number?