How to change improvement yield with Lua?

identity0

Chieftain
Joined
Aug 3, 2017
Messages
1
I'm making a new improvement, but I want it's behaviour to be a little more complex than the improvements in the game right now. Specifically, I want to make a town whose yield is based off of it's neighbouring tiles' yields. I've done all the XML, but how would I do it in Lua?
 
Why don't you just use the CP DLL where the XML already exist for the effect you look for?
 
Why don't you just use the CP DLL where the XML already exist for the effect you look for?

Because DLL dependency where not necessary is rood :tibs1:

I'm making a new improvement, but I want it's behaviour to be a little more complex than the improvements in the game right now. Specifically, I want to make a town whose yield is based off of it's neighbouring tiles' yields. I've done all the XML, but how would I do it in Lua?

Assuming that you just want a single yield to be increased, you'll need six improvements; if you're wanting something more complex, then you'll need more improvements but you'll follow the same idea.

You'll want to iterate through all the plots adjacent to your improvement. WHoward's PlotIterators will work, although is unnecessary. Instead:

Code:
for direction = 0, DirectionTypes.NUM_DIRECTION_TYPES -1, 1 do
local pAdjPlot = Map.PlotDirection(pPlot:GetX(), pPlot:GetY(), direction)
-- yada yara
end
where pPlot is the improvement's plot.
You'll want to collect information from each plot and save it outside the iterator, and then based off of this data you can then choose which improvement to place using pPlot:SetImprovementType(IMPROVEMENT ID, true). You'll want to hook this onto GameEvents.BuildFinished, which iirc has the arguments playerID, UnitID, ImprovementID, iX, iY. Choosing the improvement can be done either through a series of if - elseif statements, or by storing the improvements in a table.
 
Back
Top Bottom