dip.world
Class Province

java.lang.Object
  extended bydip.world.Province
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public class Province
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable

A Province represents a region on the map.

Provinces may be sea, coastal, or landlocked. Their connectivity and type (sea, coastal, or landlocked) is determined by the Adjacency data.

The types of provinces are:

The adjacency information is similar to that used by the Ken Lowe Judge software.

It is illegal to have a Province without any Coasts, to combine single-coast and multi-coast, or to have only multiple coasts without a land coast.

                L S N S W E 	(land / single / north / south / west / east)
                ===========
                x - - - - - 	landlocked
                - x - - - - 	seaspace ("sealocked")
                x x - - - - 	coastal land space (only 1 coast)
                - - ? ? ? ? 	INVALID
                - x ? ? ? ? 	INVALID
                x x ? ? ? ? 	INVALID
                x - ? ? ? ? 	see below

                other valid:
                        land + (!single) + (any combination of north/south/west/east)
        

If Supply Centers become more complex in the future, they may be handled as a separate object within the Province.

See Also:
Serialized Form

Nested Class Summary
protected static class Province.Adjacency
          Adjacency maintains the connectivity graph between provinces.
 
Constructor Summary
Province(java.lang.String fullName, java.lang.String[] shortNames, int index, boolean isConvoyableCoast)
          Creates a new Province object.
 
Method Summary
 boolean canTransit(Location fromLoc, Unit.Type unit, Phase phase, java.lang.Class orderClass)
          Checks if unit can transit from a Location to this Province.
 boolean canTransit(Phase phase, Order order)
          Convenient version of canTransit()
 int compareTo(java.lang.Object obj)
          Compares this province to another, by the full name, ignoring case
protected  Province.Adjacency getAdjacency()
          Gets the Adjacency data for this Province
 Location[] getAdjacentLocations(Coast coast)
          Gets the Locations adjacent to this province, given the specified coast.
 Location[] getAllAdjacent()
          Get all the Locations that are adjacent to this province.
 int getBaseMoveModifier(Location fromLoc)
          Looks through borders to determine if there is a baseMoveModifier.
 java.lang.String getFullName()
          Gets the full name (long name) of the Province
 int getIndex()
          Returns the Province index; this is an int between 0 (inclusive) and the total number of provinces (exclusive).
 java.lang.String getShortName()
          Gets the short name of the Province This returns the first short name if there are more than one.
 java.lang.String[] getShortNames()
          Gets all short names of the Province
 Border getTransit(Location fromLoc, Unit.Type unit, Phase phase, java.lang.Class orderClass)
          Checks if unit can transit from a Location to this Province.
 Border getTransit(Phase phase, Order order)
          Convenient version of getTransit()
 Coast[] getValidDirectionalCoasts()
          Return the coasts supported by this province.
 int hashCode()
          Implementation of Object.hashCode()
 boolean hasSupplyCenter()
          Determine if this Province contains a supply center
 boolean isAdjacent(Coast sourceCoast, Location dest)
          Checks connectivity between this and another province This method only determines if the current Province with the specified coast is connected to the destination Province and Coast.
 boolean isAdjacent(Coast sourceCoast, Province dest)
          Checks connectivity between this and another province This method only determines if the current Province with the specified coast is connected to the destination Province.
 boolean isCoastal()
          Determines if this Province is coastal (including multi-coastal).
 boolean isCoastValid(Coast coast)
          Determines if specified coast is allowed for this Province
 boolean isConvoyable()
          Indicates if this province is convoyable, either because it is a Sea province or a convoyable coast.
 boolean isConvoyableCoast()
          If this province is a convoyable coastal Province, this will return true.
 boolean isLand()
          Determines if this Province is a Land province (landlocked OR coastal)
 boolean isLandLocked()
          Determines if this Province is landlocked.
 boolean isMultiCoastal()
          Determines if this Province has multiple coasts (e.g., Spain).
 boolean isSea()
          Determines if this Province is a Sea province (no land, not coastal).
 boolean isTouching(Province province)
          Determines if two provinces are in any way adjacent (connected).
protected  void setBorders(Border[] value)
          Sets the Border data for this province.
protected  void setSupplyCenter(boolean value)
          Sets if this province has a supply center.
 java.lang.String toString()
          Returns the full name of the province
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Province

public Province(java.lang.String fullName,
                java.lang.String[] shortNames,
                int index,
                boolean isConvoyableCoast)
Creates a new Province object. Unless you are a WorldFactory (or subclass), it should (almost) never be nescessary to create a Province using new. In fact, to do so will break referential equality. to get a Province, use the Map.getProvince() and similar methods.

These are created by a WorldFactory, or through de-serialization. Null names are not allowed. At least one shortName is required.

Method Detail

setBorders

protected void setBorders(Border[] value)
Sets the Border data for this province.


setSupplyCenter

protected void setSupplyCenter(boolean value)
Sets if this province has a supply center.


getIndex

public final int getIndex()
Returns the Province index; this is an int between 0 (inclusive) and the total number of provinces (exclusive). It is never negative.


getAdjacency

protected final Province.Adjacency getAdjacency()
Gets the Adjacency data for this Province


getAllAdjacent

public Location[] getAllAdjacent()
Get all the Locations that are adjacent to this province. Note that if you are only interested in adjacent provinces, getAdjacentLocations(Coast.WING or Coast.TOUCHING) is more appropriate and faster; however, all Locations returned will be of Coast.WING. This method will return all truly adjacent locations, which have their correct coasts. No duplicate Locations will be present in the returned array. All arrays will be zero-length or higher; a null array is never returned.


getAdjacentLocations

public Location[] getAdjacentLocations(Coast coast)
Gets the Locations adjacent to this province, given the specified coast.


getFullName

public final java.lang.String getFullName()
Gets the full name (long name) of the Province


getShortName

public final java.lang.String getShortName()
Gets the short name of the Province

This returns the first short name if there are more than one.


getShortNames

public final java.lang.String[] getShortNames()
Gets all short names of the Province


hasSupplyCenter

public boolean hasSupplyCenter()
Determine if this Province contains a supply center


isTouching

public boolean isTouching(Province province)
Determines if two provinces are in any way adjacent (connected).

If two provinces are adjacent, by any coast, this will return true. This implies connectivity in the broadest sense. No coast information is required or needed in this or the Province that is compared. because Coasts are ignored, this method should generally not be used to determine adjacency for the movement of units.

This now uses the "Wing" ("Touching") Coast which is equivalent.


isAdjacent

public boolean isAdjacent(Coast sourceCoast,
                          Province dest)
Checks connectivity between this and another province

This method only determines if the current Province with the specified coast is connected to the destination Province.


isAdjacent

public boolean isAdjacent(Coast sourceCoast,
                          Location dest)
Checks connectivity between this and another province

This method only determines if the current Province with the specified coast is connected to the destination Province and Coast.

This is a stricter version of isAdjacent(Coast, Province)


isLandLocked

public boolean isLandLocked()
Determines if this Province is landlocked.


isCoastal

public boolean isCoastal()
Determines if this Province is coastal (including multi-coastal).


isLand

public boolean isLand()
Determines if this Province is a Land province (landlocked OR coastal)


isSea

public boolean isSea()
Determines if this Province is a Sea province (no land, not coastal).


isMultiCoastal

public boolean isMultiCoastal()
Determines if this Province has multiple coasts (e.g., Spain).


getValidDirectionalCoasts

public Coast[] getValidDirectionalCoasts()
Return the coasts supported by this province. If not multicoastal, returns an empty Coast array.


isCoastValid

public boolean isCoastValid(Coast coast)
Determines if specified coast is allowed for this Province


hashCode

public int hashCode()
Implementation of Object.hashCode()


canTransit

public boolean canTransit(Location fromLoc,
                          Unit.Type unit,
                          Phase phase,
                          java.lang.Class orderClass)
Checks if unit can transit from a Location to this Province.


canTransit

public boolean canTransit(Phase phase,
                          Order order)
Convenient version of canTransit()


getTransit

public Border getTransit(Location fromLoc,
                         Unit.Type unit,
                         Phase phase,
                         java.lang.Class orderClass)
Checks if unit can transit from a Location to this Province. Returns the first failing Border order; returns null if Transit is successfull.


getTransit

public Border getTransit(Phase phase,
                         Order order)
Convenient version of getTransit()


getBaseMoveModifier

public int getBaseMoveModifier(Location fromLoc)
Looks through borders to determine if there is a baseMoveModifier. that fits. Note that the first matching non-zero baseMoveModifier is returned if there are more than one, which is not recommended.


isConvoyableCoast

public boolean isConvoyableCoast()
If this province is a convoyable coastal Province, this will return true.


isConvoyable

public boolean isConvoyable()
Indicates if this province is convoyable, either because it is a Sea province or a convoyable coast.

No transit checking is performed.


toString

public java.lang.String toString()
Returns the full name of the province


compareTo

public int compareTo(java.lang.Object obj)
Compares this province to another, by the full name, ignoring case

Specified by:
compareTo in interface java.lang.Comparable


Copyright 2002-2004 Zachary DelProposto / jDip Development Team. All Rights Reserved.