Checking if a City is adjacent to a River

Harkodos

Warlord
Joined
Feb 9, 2016
Messages
195
I've been working on a large-scale project but I've been stumbling across alot of hurdles.

One that has me stumped is that I'm trying to add a behind-the-scenes check to determine how many of the player's Cities are adjacent to Rivers (this is specifically for a display to show how much Happiness the player is receiving from the Sacred Waters pantheon (or any of a similar effect).

Here's what I've got right now:

Code:
local pCityPlot = pPlayer:GetCityByID():Plot();
local iCountRiverPlots = 0;
...
for pCity in pPlayer:Cities() do
...
    if (pCityPlot:IsRiver()) then
        iCountRiverPlots = iCountRiverPlots + 1;
    end
...
end
The code in the "..." doesn't really matter (it doesn't affect what I've got one way or the other). While what's here technically works, it also increments for cities not adjacent to Rivers, and I need it to only increment for cities adjacent to Rivers. Thoughts?

I've got this code is embeded in the Happiness section of the TopPanel code, in case you needed that clarification.
 
Last edited:
I've been working on a large-scale project but I've been stumbling across alot of hurdles.

One that has me stumped is that I'm trying to add a behind-the-scenes check to determine how many of the player's Cities are adjacent to Rivers (this is specifically for a display to show how much Happiness the player is receiving from the Sacred Waters pantheon (or any of a similar effect).

Here's what I've got right now:

Code:
local pCityPlot = pPlayer:GetCityByID():Plot();
local iCountRiverPlots = 0;
...
for pCity in pPlayer:Cities() do
...
    if (pCityPlot:IsRiver()) then
        iCountRiverPlots = iCountRiverPlots + 1;
    end
...
end
The code in the "..." doesn't really matter (it doesn't affect what I've got one way or the other). While what's here technically works, it also increments for cities not adjacent to Rivers, and I need it to only increment for cities adjacent to Rivers. Thoughts?

I've got this code is embeded in the Happiness section of the TopPanel code, in case you needed that clarification.
You need to update pCityPlot inside the loop
 
You need to update pCityPlot inside the loop
Ugh, you'd think after all the time I've sent with the Lua, that I'd know what that meant...

So, from my understanding, I tried changing:
Code:
local pCityPlot = pPlayer:GetCityByID():Plot();
to
Code:
local pCityPlot = nil;
and adding:
Code:
for pCity in pPlayer:Cities() do
...
   pCityPlot = pPlayer:GetCityByID():Plot();

   if (pCityPlot:IsRiver()) then
        iCountRiverPlots = iCountRiverPlots + 1;
    end
...
end
But same results. I guess something's just not clicking with me yet...
 
I think you need, inside the loop:
Code:
pCityPlot = pCity:Plot()

Sorry, I was just looking at the loop part before
 
Top Bottom