Thalassicus
Bytes and Nibblers
How do I associate a plot with a city, so when the city changes ownership the plot does too?
AFAIK you won't be able to know which plots are going to flip with the city, except the ones you've assigned with Plot:SetOwner()
for ii = 0, pCity:GetNumCityPlots() - 1, 1 do
local mPlot = pCity:GetCityIndexPlot( ii );
end
City:GetNumCityPlots() return all plots in the working range of a city, even if they belong to another city.
there could still be plots not worked in the shared area of 2 or more cities, and I don't know how to get those.
Plot:GetPlotCity() return nil if there isn't a city on the plot if I remember correctly...
include( "FLuaVector" )
function ShowCityPlots(hexX, hexY)
local mouseOverPlot = Map.GetPlot( hexX, hexY );
if (mouseOverPlot ~= nil and mouseOverPlot:IsCity() ) then
local mouseOverCity = mouseOverPlot:GetPlotCity()
for i = 0, mouseOverCity:GetNumCityPlots() - 1, 1 do
local plot = mouseOverCity:GetCityIndexPlot( i )
Events.SerialEventHexHighlight( ToHexFromGrid( Vector2( plot:GetX(), plot:GetY() ) ), true, Vector4( 1.0, 1.0, 1.0, 1 ) )
local city = plot:GetPlotCity()
print (city)
end
else
Events.ClearHexHighlights()
end
end
Events.SerialEventMouseOverHex.Add( ShowCityPlots )
function GetOwningCityForPlot(plot)
local workingCity = plot:GetWorkingCity()
if not workingCity:IsForcedWorkingPlot(plot) then
return workingCity
else
--get city from which this plot has been work-overridden (GetWorkingCityOverride???)
end
end