War detection

Bezilon

Chieftain
Joined
Apr 2, 2013
Messages
3
Hi!

I would like to know if there is a way to detect if my custom civilization is in war or not both as player and ai. I would like to add abilities to a special unit for a few turns if the civilization engages/engaged in war.
I have complete understanding of c++ and though I've never written anything in lua, but I understand how it is.
 
Not easily. Firaxis added the CanDeclareWar game event (because they needed it for a scenario) but failed to add the DeclareWar game event :(

So short of looping over every other player at the start of every turn and seeing if you're at war with them ...
 
Not easily. Firaxis added the CanDeclareWar game event (because they needed it for a scenario) but failed to add the DeclareWar game event :(

So short of looping over every other player at the start of every turn and seeing if you're at war with them ...

Would this negatively affect something? Or is it just such a pain it's not a realistic option?
 
I thought CanDeclareWar was for deciding whether the diplomacy UI button for it was shown, or ghosted?

To add to the questions - is there a method(s) for detecting who declared war on whom, which turn etc?
 
there is an event for war/peace detection, but I can't remember it's name... I'll post it when back from work.
 
Here it is:

Events.WarStateChanged(TeamID team1, TeamID team2, bool war)
 
Thanks for everything so far, but I still have a few questions remaining:

-How can I get the ID of a civ/team which is a specific civ, for example the id of the team that has Egypt in it, to put it into the war detection as one of the civ/teams for testing?

-Is there an event for detecting the start or the end of a turn for any type of players? (AI or Human)

-And what is the best method for getting the right number of civs/teams and their ID's for a loop to go through all the civs besides the Egyptians to test their warstatus changes?
 
In my mod, I use:

Code:
if (DenmarkTeam:IsAtWar(AnglesTeamID)) then

print (Denmark:GetName() ,"...is at war with... ", Angles:GetName());

end

..to help debug the DoWs I've created via lua.

I suppose using this and going through all the civs might be used to show the various wars one might be engaged in.

(note, the above is only a partial code... one would have to go through the players and then determine the teams and then do the above part of the code).
 
That's cool, but how do you detect who's playing? How many are them there (AI + Player(s)). I can write my own loops and stuff, I just have no clue what functions to use and how to get the reference of a civ object to perform checks and stuff, because there are no tutorial or documentation that would tell exactly where and how to start...
 
That's cool, but how do you detect who's playing? How many are them there (AI + Player(s)). I can write my own loops and stuff, I just have no clue what functions to use and how to get the reference of a civ object to perform checks and stuff, because there are no tutorial or documentation that would tell exactly where and how to start...

Actually there is some information out there. For one, there is a better wiki than the 2K one: http://modiki.civfanatics.com/index.php/Lua_and_UI_Reference

But it's still bad.

Also, the DLC in your steam folder if you have any, is full of lua examples of function usage from the SDK. I often grep it for specific syntax examples once I know the method I want to call. All the major objects in Civ are globals, usually static. So you would subscribe to the event like:
Code:
function WarChange(team1, team2, war)
 -- do your thing
end

Events.WarStateChanged.Add(WarChange)
 
Thanks for everything so far, but I still have a few questions remaining:

-How can I get the ID of a civ/team which is a specific civ, for example the id of the team that has Egypt in it, to put it into the war detection as one of the civ/teams for testing?

-Is there an event for detecting the start or the end of a turn for any type of players? (AI or Human)

-And what is the best method for getting the right number of civs/teams and their ID's for a loop to go through all the civs besides the Egyptians to test their warstatus changes?

Take a look at some of the Lua code I just wrote for the new UA in my American Domination mod. May not be the best, but it may help.

http://forums.civfanatics.com/showthread.php?p=12372671#post12372671
 
Back
Top Bottom