net.sf.freecol.server.generator
Class River

java.lang.Object
  extended by net.sf.freecol.server.generator.River

public class River
extends java.lang.Object

A river for the map generator.


Nested Class Summary
private static class River.DirectionChange
          Possible direction changes for a river.
 
Field Summary
private  boolean connected
          Whether the river is connected to Europe.
private  Map.Direction direction
          Current direction the river is flowing in.
private static java.util.logging.Logger logger
           
private  Map map
          The map on which the river flows.
private  River nextRiver
          The next river.
private  java.util.Random random
          The random number source.
private  ServerRegion region
          The ServerRegion this River belongs to.
private  java.util.Map<Map.Position,River> riverMap
          A hashtable of position-river pairs.
private  TileImprovementType riverType
           
private  java.util.List<RiverSection> sections
          A list of river sections.
 
Constructor Summary
River(Map map, java.util.Map<Map.Position,River> riverMap, ServerRegion region, java.util.Random random)
          Constructor.
 
Method Summary
 void add(Map.Position position, Map.Direction direction)
          Adds a new section to this river.
 boolean contains(Map.Position p)
          Returns true if this river already contains the given position.
private  void createDelta(Map.Position position, Map.Direction direction, RiverSection section)
          Describe createDelta method here.
private  void delta(Map.Position position, Map.Direction direction, RiverSection section, Map.Direction d)
           
private  void drawToMap(java.util.List<RiverSection> sections)
          Draws the completed river to the map.
private  boolean flow(Map.Position source)
          Lets the river flow from the given position.
 boolean flowFromSource(Map.Position position)
          Creates a river flowing from the given position if possible.
 RiverSection getLastSection()
           
 int getLength()
          Returns the length of this river.
 ServerRegion getRegion()
          Get the ServerRegion value.
 java.util.List<RiverSection> getSections()
           
 void grow(RiverSection lastSection, Map.Position position)
          Increases the size of this river.
 boolean isNextToSelf(Map.Position p)
          Returns true if the given position is next to this river.
 boolean isNextToWater(Map.Position p)
          Returns true if the given position is next to a river, lake or sea.
 void setRegion(ServerRegion newServerRegion)
          Set the ServerRegion value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

riverType

private TileImprovementType riverType

direction

private Map.Direction direction
Current direction the river is flowing in.


map

private Map map
The map on which the river flows.


sections

private java.util.List<RiverSection> sections
A list of river sections.


nextRiver

private River nextRiver
The next river.


region

private ServerRegion region
The ServerRegion this River belongs to.


random

private final java.util.Random random
The random number source.


riverMap

private java.util.Map<Map.Position,River> riverMap
A hashtable of position-river pairs.


connected

private boolean connected
Whether the river is connected to Europe.

Constructor Detail

River

public River(Map map,
             java.util.Map<Map.Position,River> riverMap,
             ServerRegion region,
             java.util.Random random)
Constructor.

Parameters:
map - The map on which the river flows.
riverMap - A hashtable of position-river pairs.
region - The region for this river.
random - The Random number source to use.
Method Detail

getSections

public java.util.List<RiverSection> getSections()

getLength

public int getLength()
Returns the length of this river.

Returns:
the length of this river.

getLastSection

public RiverSection getLastSection()

getRegion

public final ServerRegion getRegion()
Get the ServerRegion value.

Returns:
a ServerRegion value

setRegion

public final void setRegion(ServerRegion newServerRegion)
Set the ServerRegion value.

Parameters:
newServerRegion - The new ServerRegion value.

add

public void add(Map.Position position,
                Map.Direction direction)
Adds a new section to this river.

Parameters:
position - Where this section is located.
direction - The direction the river is flowing in.

grow

public void grow(RiverSection lastSection,
                 Map.Position position)
Increases the size of this river.

Parameters:
lastSection - The last section of the river flowing into this one.
position - The position of the confluence.

isNextToSelf

public boolean isNextToSelf(Map.Position p)
Returns true if the given position is next to this river.

Parameters:
p - A map position.
Returns:
true if the given position is next to this river.

isNextToWater

public boolean isNextToWater(Map.Position p)
Returns true if the given position is next to a river, lake or sea.

Parameters:
p - A map position.
Returns:
true if the given position is next to a river, lake or sea.

contains

public boolean contains(Map.Position p)
Returns true if this river already contains the given position.

Parameters:
p - A map position.
Returns:
true if this river already contains the given position.

flowFromSource

public boolean flowFromSource(Map.Position position)
Creates a river flowing from the given position if possible.

Parameters:
position - A map position.
Returns:
true if a river was created, false otherwise.

flow

private boolean flow(Map.Position source)
Lets the river flow from the given position.

Parameters:
source - A map position.
Returns:
true if a river was created, false otherwise.

createDelta

private void createDelta(Map.Position position,
                         Map.Direction direction,
                         RiverSection section)
Describe createDelta method here.

Parameters:
position - a Position value
direction - a Direction value

delta

private void delta(Map.Position position,
                   Map.Direction direction,
                   RiverSection section,
                   Map.Direction d)

drawToMap

private void drawToMap(java.util.List<RiverSection> sections)
Draws the completed river to the map.