R(B, E+1) && R(B, E+2) && (R(A, E) || R(A, E+1)) && (R(C, E+3) || R(C, E+2))
||
R(B, E+4) && R(B, E+5) && (R(A, E) || R(A, E+5)) && (R(C, E+3) || R(C, E+4))
bool sameRiver(Tile t, int e1, int e2)
{
//are e1 and e2 the same, or consecutive (necessarily connected)?
int dist = abs(e1-e2);
if (min(dist, 6-dist) < 2) return true;
//is there nothing but rivers between e1 and e2 clockwise?
bool allRiver = true;
for (int mid = (e1+1)%6;mid != e2;mid=(mid+1)%6)
if (!t.isRiver(mid))
{allRiver = false; break;}
if (allRiver) return true;
//if not, try the other way around
for (int mid = (e2+1)%6;mid != e1;mid=(mid+1)%6)
if (!t.isRiver(mid))
return false;
return true;
}
int riverEntryEdge(Tile t1, int e1, Tile t2)
{
int edgeToT2 = t1.edgeTo(t2);//<--hope you have something similar at hand
//is e1 the edge directly between t1 and t2?
if (e1 == edgeToT2)
return (e1+3)%6;
//if not, there are two possibilities left (on either side of the edge directly between t1 and t2)
if ((e1+1)%6 == edgeToT2 && t2.isRiver((e1+5)%6))
return (e1+5)%6;
if ((e1+5)%6 == edgeToT2 && t2.isRiver((e1+1)%6))
return (e1+1)%6;
return -1;
}
bool areConnectedByRiver(Tile a, Tile b, Tile c)
{
//for all river edges in a, for all river edges in c
for (int e1=0;e1<6;e1++)
if (a.isRiver(e1))
for (int e2=0;e2<6;e2++)
if (c.isRiver(e2))
{
//do e1 and e2 lead to tile b?
int eab = riverEntryEdge(a, e1, b);
if (eab < 0) continue;
int ecb = riverEntryEdge(c, e2, b);
if (ecb < 0) continue;
if (sameRiver(b, eab, ecb))
return true;
}
return false;
}
include("RiverConnections")
local gRiverManager = RiverManager:new()
local pPlots = gRiverManager:getRiverBankRoute(5, 4, 5, 1)
for _, pPlot in ipairs(pPlots) do
print(string.format("Plot: (%i, %i)", pPlot:GetX(), pPlot:GetY()))
end
I can add the +1 gold back in for tiles next to river by adding codes to the terrain.xml file.
Is that significant, and is it random which side is highlighted?
How did you work out the connections in the end?