There's still a slight issue with your Hungarian Notation --
iActivePlayer is not actually an integer in this case, because you've assigned it a value within the
Players table, thus turning it into the
player game object, and in this case, would be referred to as
pActivePlayer. If you don't quite understand the differences, it might be easier for you to discard it entirely and come up with your own naming convention. The important thing is that it is
consistent and won't cause confusion for anyone reading your code.
As far as the semicolons go, they are unnecessary in Lua, although it doesn't hurt anything to leave them in. Semicolons may be useful if you want to stick multiple Lua commands on one line, but I find it's easier to read and organize if I simply give them each their own line.
Be careful about removing arguments from a function.
Yes, you
can do so, but it won't work in the way you seem to be expecting them to.
Functions, when defined with arguments to accept, must accept those arguments in the order given. For example, I have a function in my Holo Civ used to determine specific things about a plot, the simplest one being the plot owner:
Code:
local function PlotOwner(pPlot, iPlayer)
As you can see, I have defined my function to accept two arguments:
pPlot, and
iPlayer. When I call this function, I
must give it these two pieces of information
in this exact order. If I don't, Lua will complain and give me an error. If I give it more than the two pieces of information, it'll take the first two, and ignore the rest because it's not set up to interpret anything beyond the first two arguments.
Similarly, when a function is set to
return a specific set of values, it will
always return those values
in the same order as defined in the return statement!
This means that when the
game returns arguments to your function to use via
Events.WarStateChanged it will always return information for
team1,
team2, and
bWar in this exact order. It is up to your function to interpret these pieces of information.
Normally, your function would be set up to retrieve all three pieces of information.
However, if you decide you only want the value of
bWar and you remove
team1 and
team2 from your function's list of "input arguments," this is where you run into issues.
Recall that I just said that a function will give you information in the exact order that was given. It doesn't care, and neither does Lua, what you call these pieces of information. This means that your new function, if set up like this:
What will actually happen is that since
bWar is occupying the "first" argument slot,
bWar contains the value for team1! It doesn't matter if you called it
iLikeCats, all that would mean is that then
iLikeCats would have the value of
team1.
In summary, you can choose to ignore specific returned values,
but only for values at the end! If you only wanted the value of
team1, then all you'd need to do, since it is the
first value returned, is to make sure your function accepts value #1. #2 and #3 would then be ignored and lost with no consequence because you didn't want to use them. However, if you wanted only
value #2, then you would need a "dummy" variable to accept value #1 (and simply not use it) and then have your real variable take the data for value #2.
WarStateChanged also fires twice, I believe, since it needs to fire once for each player involved in a new war.
I am not entirely sure how to change free military units, since that area is a bit tricky, and Firaxis never needed to do so with the stock Civs, so their unit and maintenance related methods are all global. If it's going to be a static number of free units (without restriction on which types) then you can try to go for a dummy policy which mimics Volunteer Army.