net.sf.freecol.common.model
Class SimpleCombatModel

java.lang.Object
  extended by net.sf.freecol.common.model.SimpleCombatModel
All Implemented Interfaces:
CombatModel

public class SimpleCombatModel
extends java.lang.Object
implements CombatModel

This class implements the original Colonization combat model.


Nested Class Summary
 
Nested classes/interfaces inherited from interface net.sf.freecol.common.model.CombatModel
CombatModel.CombatOdds, CombatModel.CombatResult, CombatModel.CombatResultType
 
Field Summary
static java.lang.String ARTILLERY_AGAINST_RAID
           
static java.lang.String ARTILLERY_IN_THE_OPEN
           
static java.lang.String ATTACK_BONUS
           
static java.lang.String BIG_MOVEMENT_PENALTY
           
static java.lang.String FORTIFIED
           
private static java.util.logging.Logger logger
           
static int MAXIMUM_BOMBARD_POWER
          The maximum attack power of a Colony's fortifications against a naval unit.
static java.lang.String SMALL_MOVEMENT_PENALTY
           
 
Constructor Summary
SimpleCombatModel()
           
 
Method Summary
 void attack(Unit attacker, Unit defender, CombatModel.CombatResult result, int plunderGold, Location repairLocation)
          Attack a unit with the given outcome.
 void bombard(Colony colony, Unit defender, CombatModel.CombatResult result, Location repairLocation)
          Bombard a unit with the given outcome.
 CombatModel.CombatOdds calculateCombatOdds(Unit attacker, Unit defender)
          Calculates the chance of the outcomes of combat between the units.
 void captureColony(Unit attacker, Colony colony, int plunderGold, Location repairLocation)
          Captures an enemy colony and plunders gold.
private  void captureUnit(Unit unit, Unit enemyUnit)
          Capture a unit.
private  void damageAllShips(Colony colony, Unit attacker, Location repairLocation)
          Damages all ship located on this Colony's Tile.
private  void damageShip(Unit damagedShip, Colony attackerColony, Unit attackerUnit, Location repairLocation)
          Sets the damage to this ship and sends it to its repair location.
private  void demoteUnit(Unit unit, UnitType downgrade, Unit enemyUnit)
          Demotes a unit.
private  void destroySettlement(Unit attacker, IndianSettlement settlement)
          Destroys an Indian settlement.
private  void disarmUnit(Unit unit, EquipmentType typeToLose, Unit enemyUnit)
          Disarm a unit.
private  void enemyCapturesEquipment(Unit unit, Unit enemyUnit, EquipmentType typeToLose)
           
private  void evade(Unit defender, Colony attackerColony, Unit attackerUnit)
          Evade a naval engagement.
private  EquipmentType findEquipmentTypeToLose(Unit victim)
          Find the highest priority equipment carried by a unit, if any
 CombatModel.CombatResult generateAttackResult(Colony colony, Unit defender)
          Generates the result of a colony bombarding a Unit.
 CombatModel.CombatResult generateAttackResult(Unit attacker, Unit defender)
          Generates a result of an attack.
static java.lang.String getApparentOwnerName(Unit unit)
          Get the name of the apparent owner of this Unit, (like getOwner().getNationAsString() but handles pirates)
private  void getConvert(Unit attacker, IndianSettlement indianSettlement)
          Check whether some indian converts due to the attack or they burn all missions
 float getDefencePower(Colony colony, Unit defender)
          Return the defensive power of the defender versus the bombarding colony.
 float getDefencePower(Unit attacker, Unit defender)
          Return the defensive power of the defender versus the attacker.
 java.util.Set<Modifier> getDefensiveModifiers(Colony colony, Unit defender)
          Return a list of all defensive modifiers that apply to the defender versus the bombarding colony.
 java.util.Set<Modifier> getDefensiveModifiers(Unit attacker, Unit defender)
          Return a list of all defensive modifiers that apply to the defender versus the attacker.
 float getOffencePower(Colony colony, Unit defender)
          Returns the power for bombarding
 float getOffencePower(Unit attacker, Unit defender)
          Return the offensive power of the attacker versus the defender.
 java.util.Set<Modifier> getOffensiveModifiers(Colony colony, Unit defender)
          Return a list of all offensive modifiers that apply to the attacker versus the defender.
 java.util.Set<Modifier> getOffensiveModifiers(Unit attacker, Unit defender)
          Return a list of all offensive modifiers that apply to the attacker versus the defender.
private  void loseCombat(Unit unit, Unit enemyUnit)
          Lose a combat.
private  boolean losingEquipDiscardsUnit(Unit unit, EquipmentType typeToLose)
           
private  void pillageColony(Unit attacker, Colony colony, Location repairLocation)
          Damage a building or a ship or steal some goods or gold.
private  void promote(Unit unit)
          Promotes this unit.
private  void sinkShip(Unit sinkingShip, Colony attackerColony, Unit attackerUnit)
          Sinks this ship.
private  void slaughterUnit(Unit unit, Unit enemyUnit)
          Slaughter a unit.
 
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

MAXIMUM_BOMBARD_POWER

public static final int MAXIMUM_BOMBARD_POWER
The maximum attack power of a Colony's fortifications against a naval unit.

See Also:
Constant Field Values

SMALL_MOVEMENT_PENALTY

public static final java.lang.String SMALL_MOVEMENT_PENALTY
See Also:
Constant Field Values

BIG_MOVEMENT_PENALTY

public static final java.lang.String BIG_MOVEMENT_PENALTY
See Also:
Constant Field Values

ARTILLERY_IN_THE_OPEN

public static final java.lang.String ARTILLERY_IN_THE_OPEN
See Also:
Constant Field Values

ATTACK_BONUS

public static final java.lang.String ATTACK_BONUS
See Also:
Constant Field Values

FORTIFIED

public static final java.lang.String FORTIFIED
See Also:
Constant Field Values

ARTILLERY_AGAINST_RAID

public static final java.lang.String ARTILLERY_AGAINST_RAID
See Also:
Constant Field Values
Constructor Detail

SimpleCombatModel

public SimpleCombatModel()
Method Detail

getApparentOwnerName

public static java.lang.String getApparentOwnerName(Unit unit)
Get the name of the apparent owner of this Unit, (like getOwner().getNationAsString() but handles pirates)

Parameters:
unit - an Unit value
Returns:
The name of the owner of this Unit unless this is hidden.

calculateCombatOdds

public CombatModel.CombatOdds calculateCombatOdds(Unit attacker,
                                                  Unit defender)
Calculates the chance of the outcomes of combat between the units. Currently only calculates the chance of winning combat.

Specified by:
calculateCombatOdds in interface CombatModel
Parameters:
attacker - The attacking Unit.
defender - The defending unit.
Returns:
A CombatOdds value.

generateAttackResult

public CombatModel.CombatResult generateAttackResult(Unit attacker,
                                                     Unit defender)
Generates a result of an attack.

Specified by:
generateAttackResult in interface CombatModel
Parameters:
attacker - The Unit attacking.
defender - The defending unit.
Returns:
a CombatResult value

generateAttackResult

public CombatModel.CombatResult generateAttackResult(Colony colony,
                                                     Unit defender)
Generates the result of a colony bombarding a Unit.

Specified by:
generateAttackResult in interface CombatModel
Parameters:
colony - the bombarding Colony
defender - the defending Unit
Returns:
a CombatResult value

getOffencePower

public float getOffencePower(Colony colony,
                             Unit defender)
Returns the power for bombarding

Specified by:
getOffencePower in interface CombatModel
Parameters:
colony - a Colony value
defender - an Unit value
Returns:
the power for bombarding

getOffencePower

public float getOffencePower(Unit attacker,
                             Unit defender)
Return the offensive power of the attacker versus the defender. Null can be passed as the defender when only the attacker unit stats are required

Specified by:
getOffencePower in interface CombatModel
Parameters:
attacker - an Unit value
defender - an Unit value
Returns:
a float value

getOffensiveModifiers

public java.util.Set<Modifier> getOffensiveModifiers(Colony colony,
                                                     Unit defender)
Return a list of all offensive modifiers that apply to the attacker versus the defender. Null can be passed as the defender when only the attacker unit stats are required

Specified by:
getOffensiveModifiers in interface CombatModel
Parameters:
colony - an Colony value
defender - an Unit value
Returns:
a List of Modifiers

getOffensiveModifiers

public java.util.Set<Modifier> getOffensiveModifiers(Unit attacker,
                                                     Unit defender)
Return a list of all offensive modifiers that apply to the attacker versus the defender. Null can be passed as the defender when only the attacker unit stats are required

Specified by:
getOffensiveModifiers in interface CombatModel
Parameters:
attacker - an Unit value
defender - an Unit value
Returns:
a List of Modifiers

getDefencePower

public float getDefencePower(Colony colony,
                             Unit defender)
Return the defensive power of the defender versus the bombarding colony.

Specified by:
getDefencePower in interface CombatModel
Parameters:
colony - a Colony value
defender - a Unit value
Returns:
an float value

getDefencePower

public float getDefencePower(Unit attacker,
                             Unit defender)
Return the defensive power of the defender versus the attacker.

Specified by:
getDefencePower in interface CombatModel
Parameters:
attacker - an Unit value
defender - an Unit value
Returns:
an float value

getDefensiveModifiers

public java.util.Set<Modifier> getDefensiveModifiers(Colony colony,
                                                     Unit defender)
Return a list of all defensive modifiers that apply to the defender versus the bombarding colony.

Specified by:
getDefensiveModifiers in interface CombatModel
Parameters:
colony - a Colony value
defender - an Unit value
Returns:
a List of Modifiers

getDefensiveModifiers

public java.util.Set<Modifier> getDefensiveModifiers(Unit attacker,
                                                     Unit defender)
Return a list of all defensive modifiers that apply to the defender versus the attacker.

Specified by:
getDefensiveModifiers in interface CombatModel
Parameters:
attacker - an Unit value
defender - an Unit value
Returns:
a List of Modifiers

attack

public void attack(Unit attacker,
                   Unit defender,
                   CombatModel.CombatResult result,
                   int plunderGold,
                   Location repairLocation)
Attack a unit with the given outcome. This method ignores the damage parameter.

Specified by:
attack in interface CombatModel
Parameters:
attacker - an Unit value
defender - The Unit defending against attack.
result - The result of the attack.
plunderGold - an int value
repairLocation - a Location value

bombard

public void bombard(Colony colony,
                    Unit defender,
                    CombatModel.CombatResult result,
                    Location repairLocation)
Bombard a unit with the given outcome.

Specified by:
bombard in interface CombatModel
Parameters:
colony - a Colony value
defender - The Unit defending against bombardment.
result - The result of the bombardment.

captureColony

public void captureColony(Unit attacker,
                          Colony colony,
                          int plunderGold,
                          Location repairLocation)
Captures an enemy colony and plunders gold.

Parameters:
attacker - an Unit value
colony - a Colony value
plunderGold - The amount of gold to plunder.

damageAllShips

private void damageAllShips(Colony colony,
                            Unit attacker,
                            Location repairLocation)
Damages all ship located on this Colony's Tile. That is: they are sent to the closest location for repair.

See Also:
damageShip(net.sf.freecol.common.model.Unit, net.sf.freecol.common.model.Colony, net.sf.freecol.common.model.Unit, net.sf.freecol.common.model.Location)

pillageColony

private void pillageColony(Unit attacker,
                           Colony colony,
                           Location repairLocation)
Damage a building or a ship or steal some goods or gold. It's called from attack when an indian attacks a colony and lose the combat with LOSS as result

Parameters:
colony - The attacked colony

destroySettlement

private void destroySettlement(Unit attacker,
                               IndianSettlement settlement)
Destroys an Indian settlement.

Parameters:
attacker - an Unit value
settlement - an IndianSettlement value

getConvert

private void getConvert(Unit attacker,
                        IndianSettlement indianSettlement)
Check whether some indian converts due to the attack or they burn all missions

Parameters:
indianSettlement - The attacked indian settlement

evade

private void evade(Unit defender,
                   Colony attackerColony,
                   Unit attackerUnit)
Evade a naval engagement.

Parameters:
defender - A naval unit that evades the attacker
attackerColony - A colony that may have bombarded the defender
attackerUnit - A unit that may have attacked the defender

damageShip

private void damageShip(Unit damagedShip,
                        Colony attackerColony,
                        Unit attackerUnit,
                        Location repairLocation)
Sets the damage to this ship and sends it to its repair location.

Parameters:
damagedShip - A ship that is loosing a battle and getting damaged
attackerColony - The colony that may have opened fire on this unit
attackerUnit - A unit which may have damaged the ship

sinkShip

private void sinkShip(Unit sinkingShip,
                      Colony attackerColony,
                      Unit attackerUnit)
Sinks this ship.

Parameters:
sinkingShip - the Unit that is going to sink
attackerColony - The colony that may have opened fire on this unit
attackerUnit - The unit which may have attacked the ship

findEquipmentTypeToLose

private EquipmentType findEquipmentTypeToLose(Unit victim)
Find the highest priority equipment carried by a unit, if any

Parameters:
victim - a Unit that is about to lose equipment
Returns:
The highest priority EquipmentType carried by a unit, or null if none.

loseCombat

private void loseCombat(Unit unit,
                        Unit enemyUnit)
Lose a combat. Units can be disarmed, demoted, captured or slaughtered. The enemy may plunder equipment.

Parameters:
unit - a Unit that has lost a combat
enemyUnit - a Unit that has won a combat

losingEquipDiscardsUnit

private boolean losingEquipDiscardsUnit(Unit unit,
                                        EquipmentType typeToLose)

captureUnit

private void captureUnit(Unit unit,
                         Unit enemyUnit)
Capture a unit.

Parameters:
unit - a Unit to be captured
enemyUnit - a Unit that is capturing

demoteUnit

private void demoteUnit(Unit unit,
                        UnitType downgrade,
                        Unit enemyUnit)
Demotes a unit.

Parameters:
unit - a Unit to demote
downgrade - the UnitType to downgrade the init to
enemyUnit - a Unit that caused the demotion

disarmUnit

private void disarmUnit(Unit unit,
                        EquipmentType typeToLose,
                        Unit enemyUnit)
Disarm a unit.

Parameters:
unit - a Unit to be disarmed
typeToLose - the EquipmentType to lose
enemyUnit - a Unit that is disarming

enemyCapturesEquipment

private void enemyCapturesEquipment(Unit unit,
                                    Unit enemyUnit,
                                    EquipmentType typeToLose)

slaughterUnit

private void slaughterUnit(Unit unit,
                           Unit enemyUnit)
Slaughter a unit.

Parameters:
unit - a Unit to slaughter
enemyUnit - a Unit that is slaughtering

promote

private void promote(Unit unit)
Promotes this unit.

Parameters:
unit - an Unit value