[SDK] How to identify the source of the river

Refar

Deity
Joined
Apr 10, 2005
Messages
4,608
As the topic says... I need to identify the source of a river from CvPlot.

More precise i am interested in these two squares:
riverzb0.jpg


Can someone point me to something useful ? Or explain how the river code is working in general - i dont really understand it...
 
Take a look at CvMapGenerator.cpp ::doRiver . In fact the source of the river is this plot ( the X ) , relative to your circles :

oo
X_

A segment of river is always put on east or south of the tile (WestOfRiver or NorthOfRiver) .

This is a recursive function that do the river segment by segment . If you specify a direction , the function try to do a river with this direction if possible with the plot you specify for source else return none . If you don't specify a direction , it choose a starting direction if possible . Then the function is called for the next segment with the last direction of the river and check if a new segment is possible . Do the segment if possible and restart the process until he can't do a river segment . This mean you have reach a lake , sea or the border of the map .

Tcho !

PS : tell if you don't understand , i explain you with a concrete example , and sorry for my bad English . Or perhaps i've not answered your question ?
 
Thanks :D

I think your pointer (about a segment beeing S/E of the plot) was the peace of information i was missing.
 
Sorry , in fact i have made a big mistake . You were right , the source is one of the two circle . While trying to make a custom river i notice that i need to put a river ID on some plots and i have examined the function deeper . I've done many tests mapping the plot river ID and the river segments ... I will try to describe the process . That will not be easy :crazyeye: .

The doRiver function make the river segment by segment by a recursive way recalling itself until the river has reach water or the border of the map .

When called for the first time , the function just define the cardinal direction (called lastCardinalDirection in the function and in fact the direction of the segment you do ).
Then it recall itself with a StartPlot (noted S) and 2 cardinal directions . ( bestCardinalDirection and the first cardinal direction stored called OriginalCardinalDirection . This is used only when choosing the next cardinal direction to keep a global direction for the river ) .
RiverPlot (noted R) is the plot were the segment of river is done (on the south or east of the tile :mischief: ) .
The next start plot for the recursion is noted N ( note that in the function RiverPlot is replaced with this plot once the river segment is placed )
And the AdjacentPlot (noted A ) is used to check if you have reach water or the border of the map or if the river is able to begin .

There is four cases in function of the cardinal directions :

North : R = S

N
SA

the river segment is done between S and A.

East : N = R

SR
_A

the river segment is done between R and A.

South : N = R

S
RA

the river segment is done between R and A.
So on your example the river source is the left circle . :blush:

West : R = S

NS
_A

the river segment is done between S and A.

Something strange i have noticed is that the plot where the river ID is applied is always the StartPLot(S) even if the segment is done on another tile . So with the case South and East , the Source Plot is assigned to the riverID and this plot isn't river at all :eek: .

I hope i have been enough understandable ... and sorry for the mistake .

Tcho !
 
Yes i noticed this - kind of. In fact the two functions for Rivers - doRiver and addRiver handle that differently... With doRiver the passed startingPlot is the left of my circles (and curiously ends up without fresh water - this is what i wanted to fix in the first place)... Still your first pointer was enought to fill the gap, so dont worry about the small mistake. Thanks again.
 
Back
Top Bottom