public int evolveRiver(Field start) {startpos = start.getPosition();return evolveRiver(start,0,1);}
/** Performs the calculations described above. */
private int evolveRiver(Field start,int stoppoints,int depth)
{
start.setWaterFlow(start.getHumidity());
Coordinate thiscoord = start.getPosition();
if(stop(stoppoints))
return start.getHumidity();
int otherfieldsflow = 0;
Coordinate[] nextcoord = new Coordinate[4];
int[] flowdirections = new int[4];
int[] antiflowdirections = new int[4];
for(int n = 0;n < 4;n++)
{
nextcoord[n] = null;
flowdirections[n] = antiflowdirections[n] = Direction.UNDEFINED;
}
for(int n = 0;n < 4;n++)
{
int currindex = 0;
while(true)
{
currindex = randomgen.nextInt(4);
if(nextcoord[currindex] == null)
break;
}
switch(n)
{
case 0: nextcoord[currindex] = thiscoord.add(north);
break;
case 1: nextcoord[currindex] = thiscoord.add(east);
break;
case 2: nextcoord[currindex] = thiscoord.add(south);
break;
case 3: nextcoord[currindex] = thiscoord.add(west);
}
}
int recnumber = 0;
for(int n = 0;n < 4;n++)
{
nextcoord[n] = mapdata.adjustToMapSize(nextcoord[n]);
if(nextcoord[n] != null)
{
Field nextfield = mapdata.getField(nextcoord[n]);
if((nextfield.getWaterFlow() < 0) && (nextfield.isLand()))
{
int probability = -1;
int from = config.UNDEFINED;
int to = config.UNDEFINED;
from = config.getHeightConstant(start);
to = config.getHeightConstant(nextfield);
if((from != config.UNDEFINED) && (to != config.UNDEFINED)
&& (randomgen.nextDouble() < config.probevprobs[from][to]))
{
if(config.probev_seastopprobsuse)
{
int nextdst = nextfield.getDistanceToSea();
double [] probs = config.probev_seastopprobs;
int [] mindepth = config.probev_seastopprobsmindepth;
if((nextdst <= probs.length)
&& (depth >= mindepth[nextdst - 1])
&& (randomgen.nextDouble() <= probs[nextdst - 1]))
continue;
}
int nstoppoints = stoppoints +
config.probev_callstoppoints[recnumber];
if(config.probev_spforturnarounduse)
{
Coordinate s = start.getPosition();
int dst = Math.abs(startpos.x - nextcoord[n].x) +
Math.abs(startpos.y - nextcoord[n].y);
int olddst = Math.abs(startpos.x - s.x) +
Math.abs(startpos.y - s.y);
if((dst < olddst)