Bug with rivers flowing out of lakes

whoward69

DLL Minion
Joined
May 30, 2011
Messages
8,729
Location
Near Portsmouth, UK
pPlot:IsRiverCrossing(DirectionTypes) is bugged for a river flowing out of a lake

attachment.php


For the plot with the archer, pPlot:IsWOfRiver() and pPlot:GetRiverEFlowDirection() both report the correct values (true and south respectively) but pPlot:IsRiverCrossing(EAST) incorrectly reports false.

For the plot with the warrior, everything is correct

I suspect the UI code to draw headwaters/outflows for rivers is "fixing" the internal plot data somewhere, but can't track it down in the C++ code.

Probably only of interest if you are trying to work out a river connection algorithm ;)

Code:
> FlowDirectionTypes.FLOWDIRECTION_SOUTH
3

> pPlot = Map.GetPlot(15, 10)
> pPlot:GetUnit(0):GetName()
Archer
> pPlot:IsWOfRiver()
true
> pPlot:GetRiverEFlowDirection()
3
> print(pPlot:IsRiverCrossing(DirectionTypes.DIRECTION_EAST))
 WorldView: [COLOR="Red"][B][SIZE="3"]false[/SIZE][/B][/COLOR]

> pPlot = Map.GetPlot(14, 9)
> pPlot:GetUnit(0):GetName()
Warrior
> pPlot:IsWOfRiver()
true
> pPlot:GetRiverEFlowDirection()
3
> print(pPlot:IsRiverCrossing(DirectionTypes.DIRECTION_EAST))
 WorldView: true
 

Attachments

  • RiversBug.jpg
    RiversBug.jpg
    62 KB · Views: 284
Doesn't matter if it's flowing into or out of the lake, there is ALWAYS a river crossing to the East of the tile with the Archers in, so either way it's bugged.

If it was flowing into the lake, pPlot:GetRiverEFlowDirection() should return "Flow North" (not "Flow South"). Internally Firaxis duplicate the storage of river information for a plot (very bad programming practice) - some code somewhere is updating one of these values and failing to keep the other in sync, which is causing the bug.

Fortunately, once you know it's bugged, you can simply avoid the using IsRiverCrossing() and just work the same info out from the non-bugged methods.
 
Does this issue only crop up with this specific set of directions? (River to the east flowing into a lake to the north?) or all 'last edge' rivers into lakes?

I didn't test all 6 variations, but it also affects a river leaving a lake at the SW corner. The work-around, although not as pretty as a single API call, is straight forward

Code:
function HasRiverOnSide(pPlot, iDirection)
  if (iDirection == DirectionTypes.DIRECTION_EAST) then
    return pPlot:IsWOfRiver()
  elseif (iDirection == DirectionTypes.DIRECTION_SOUTHEAST) then
    return pPlot:IsNWOfRiver()
  elseif (iDirection == DirectionTypes.DIRECTION_SOUTHWEST) then
    return pPlot:IsNEOfRiver()
  else
    local pAdjacentPlot = Map.PlotDirection(pPlot:GetX(), pPlot:GetY(), iDirection)

    if (pAdjacentPlot) then
      if (iDirection == DirectionTypes.DIRECTION_WEST) then
        return pAdjacentPlot:IsWOfRiver()
      elseif (iDirection == DirectionTypes.DIRECTION_NORTHWEST) then
        return pAdjacentPlot:IsNWOfRiver()
      elseif (iDirection == DirectionTypes.DIRECTION_NORTHEAST) then
        return pAdjacentPlot:IsNEOfRiver()
      end
    end
  end

  return false
end
 
Back
Top Bottom