Counting the number of a specific tile in the city radius.

turingmachine

Emperor
Joined
May 4, 2008
Messages
1,438
Okay, I know I can use:

Code:
for i = 0, pCity:GetNumCityPlots() - 1, 1 do
  local plot = pCity:GetCityIndexPlot( i )
  if plot:GetFeatureType() == GameInfoTypes.FEATURE_FOREST then

To check all the plots of the city radius and find out if a forest tile is present.

However, for a mod I need to know exactly how many forest tiles are present in the city radius and return that number. Can anybody give me some advice on how to count this?

(Sorry, I know this is probably a more general lua question than a civ specific question. Still learning lua as I go).
 
You can use printf to print to your screen.

No but I need to get the number so I can then do something with it in the next step of the lua.

Like if there are 5 forest tiles around the city, then grant the city +5 gold, or spawn 5 units, etc.

It would then check these tiles every turn and update the number accordingly. So if I chopped one tile down, the next turn would only get 4 tiles and only then grant +4 gold, or spawn 4 units, etc.
 
I'm pretty sure that I am misinterpreting your question, but all you need to do is add these lines.

Code:
local count = 0;
for i = 0, pCity:GetNumCityPlots() - 1, 1 do
  local plot = pCity:GetCityIndexPlot( i )
  if plot:GetFeatureType() == GameInfoTypes.FEATURE_FOREST then
    count = count + 1;
  end
end
 
I'm pretty sure that I am misinterpreting your question, but all you need to do is add these lines.

Code:
local count = 0;
for i = 0, pCity:GetNumCityPlots() - 1, 1 do
  local plot = pCity:GetCityIndexPlot( i )
  if plot:GetFeatureType() == GameInfoTypes.FEATURE_FOREST then
    count = count + 1;
  end
end

That's actually exactly what I needed. Sigh, I know I'm missing some lua basics :sad:. Thanks for helping out with such a simple question. I'll try it out later today.
 
Back
Top Bottom