public static void addRiver(IBoard board,HashMap<IHex,Point> reverseHex){
  int minElevation=Integer.MAX_VALUE;
  HashSet<IHex> riverHexes=new HashSet<IHex>();
  IHex field;
  Point p=null;
  int direction=0;
  int nextLeft=0;
  int nextRight=0;
  int width=board.getWidth();
  int height=board.getHeight();
  if ((width < 5) || (height < 5)) {
    return;
  }
switch (Compute.randomInt(4)) {
case 0:
    p=new Point(0,Compute.randomInt(5) - 2 + height / 2);
  direction=Compute.randomInt(2) + 1;
nextLeft=direction - 1;
nextRight=direction + 1;
break;
case 1:
p=new Point(width - 1,Compute.randomInt(5) - 2 + height / 2);
direction=Compute.randomInt(2) + 4;
nextLeft=direction - 1;
nextRight=(direction + 1) % 6;
break;
case 2:
case 3:
p=new Point(Compute.randomInt(5) - 2 + width / 2,0);
direction=2;
nextRight=3;
nextLeft=4;
break;
}
field=board.getHex(p.x,p.y);
ITerrainFactory f=Terrains.getTerrainFactory();
do {
field.removeAllTerrains();
field.addTerrain(f.createTerrain(Terrains.WATER,1));
riverHexes.add(field);
p=reverseHex.get(field);
riverHexes.addAll(extendRiverToSide(board,p,Compute.randomInt(3),nextLeft,reverseHex));
riverHexes.addAll(extendRiverToSide(board,p,Compute.randomInt(3),nextRight,reverseHex));
switch (Compute.randomInt(4)) {
case 0:
field=board.getHexInDir(p.x,p.y,(direction + 5) % 6);
break;
case 1:
field=board.getHexInDir(p.x,p.y,(direction + 1) % 6);
break;
default :
field=board.getHexInDir(p.x,p.y,direction);
break;
}
}
 while (field != null);
HashSet<IHex> tmpRiverHexes=new HashSet<IHex>(riverHexes);
while (!tmpRiverHexes.isEmpty()) {
Iterator<IHex> iter=tmpRiverHexes.iterator();
field=iter.next();
if (field.getLevel() < minElevation) {
minElevation=field.getLevel();
}
tmpRiverHexes.remove(field);
Point thisHex=reverseHex.get(field);
for (int i=0; i < 6; i++) {
field=board.getHexInDir(thisHex.x,thisHex.y,i);
if ((field != null) && (field.getLevel() < minElevation)) {
minElevation=field.getLevel();
}
tmpRiverHexes.remove(field);
}
}
Iterator<IHex> iter=riverHexes.iterator();
while (iter.hasNext()) {
field=iter.next();
field.setLevel(minElevation);
}
return;
}

public static void addRiver ( IBoard board , HashMap < IHex , Point > reverseHex ) { int minElevation = Integer . MAX_VALUE ; HashSet < IHex > riverHexes = new HashSet < IHex > ( ) ; IHex field ; Point p = null ; int direction = 0 ; int nextLeft = 0 ; int nextRight = 0 ; int width = board . getWidth ( ) ; int height = board . getHeight ( ) ; if ( ( width < 5 ) || ( height < 5 ) ) { return ; } switch ( Compute . randomInt ( 4 ) ) { case 0 : p = new Point ( 0 , Compute . randomInt ( 5 ) - 2 + height / 2 ) ; direction = Compute . randomInt ( 2 ) + 1 ; nextLeft = direction - 1 ; nextRight = direction + 1 ; break ; case 1 : p = new Point ( width - 1 , Compute . randomInt ( 5 ) - 2 + height / 2 ) ; direction = Compute . randomInt ( 2 ) + 4 ; nextLeft = direction - 1 ; nextRight = ( direction + 1 ) % 6 ; break ; case 2 : case 3 : p = new Point ( Compute . randomInt ( 5 ) - 2 + width / 2 , 0 ) ; direction = 2 ; nextRight = 3 ; nextLeft = 4 ; break ; } field = board . getHex ( p . x , p . y ) ; ITerrainFactory f = Terrains . getTerrainFactory ( ) ; do { field . removeAllTerrains ( ) ; field . addTerrain ( f . createTerrain ( Terrains . WATER , 1 ) ) ; riverHexes . add ( field ) ; p = reverseHex . get ( field ) ; riverHexes . addAll ( extendRiverToSide ( board , p , Compute . randomInt ( 3 ) , nextLeft , reverseHex ) ) ; riverHexes . addAll ( extendRiverToSide ( board , p , Compute . randomInt ( 3 ) , nextRight , reverseHex ) ) ; switch ( Compute . randomInt ( 4 ) ) { case 0 : field = board . getHexInDir ( p . x , p . y , ( direction + 5 ) % 6 ) ; break ; case 1 : field = board . getHexInDir ( p . x , p . y , ( direction + 1 ) % 6 ) ; break ; default : field = board . getHexInDir ( p . x , p . y , direction ) ; break ; } } while ( field != null ) ; HashSet < IHex > tmpRiverHexes = new HashSet < IHex > ( riverHexes ) ; while ( ! tmpRiverHexes . isEmpty ( ) ) { Iterator < IHex > iter = tmpRiverHexes . iterator ( ) ; field = iter . next ( ) ; if ( field . getLevel ( ) < minElevation ) { minElevation = field . getLevel ( ) ; } tmpRiverHexes . remove ( field ) ; Point thisHex = reverseHex . get ( field ) ; for ( int i = 0 ; i < 6 ; i ++ ) { field = board . getHexInDir ( thisHex . x , thisHex . y , i ) ; if ( ( field != null ) && ( field . getLevel ( ) < minElevation ) ) { minElevation = field . getLevel ( ) ; } tmpRiverHexes . remove ( field ) ; } } Iterator < IHex > iter = riverHexes . iterator ( ) ; while ( iter . hasNext ( ) ) { field = iter . next ( ) ; field . setLevel ( minElevation ) ; } return ; }
adds an river to the map ( if the map is at least 5x5 hexes big ) . the river has an width of 1 - 3 hexes ( everything else is no more a river ) . the river goes from one border to another . nor params , no results .
