Package net.sf.freecol.common.model
Class CombatModel
- java.lang.Object
-
- net.sf.freecol.common.model.CombatModel
-
- Direct Known Subclasses:
SimpleCombatModel
public abstract class CombatModel extends java.lang.Object
A abstract requirements for a FreeCol combat model.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CombatModel.CombatOdds
Odds a particular outcome will occur in combat.static class
CombatModel.CombatResult
-
Constructor Summary
Constructors Constructor Description CombatModel()
Empty constructor is sufficient.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract CombatModel.CombatOdds
calculateCombatOdds(FreeColGameObject attacker, FreeColGameObject defender)
Calculates the chance of the outcomes of a combat.boolean
combatIsAmphibious(FreeColGameObject attacker, FreeColGameObject defender)
Could this attack be an amphibious operation?boolean
combatIsAttack(FreeColGameObject attacker, FreeColGameObject defender)
Is this combat a normal attack?boolean
combatIsAttackMeasurement(FreeColGameObject attacker, FreeColGameObject defender)
Is this just a measurement of offence power?boolean
combatIsBombard(FreeColGameObject attacker, FreeColGameObject defender)
Is this combat a bombardment?boolean
combatIsDefenceMeasurement(FreeColGameObject attacker, FreeColGameObject defender)
Is this just a measurement of defence power?boolean
combatIsSettlementAttack(FreeColGameObject attacker, FreeColGameObject defender)
Is this combat a attack on a settlement? These happen on the client side only, for the purposes of the pre-combat display.boolean
combatIsWarOfIndependence(FreeColGameObject attacker, FreeColGameObject defender)
Is this a combat between a rebel player and the REF at a colony?abstract java.util.List<CombatModel.CombatResult>
generateAttackResult(java.util.Random random, FreeColGameObject attacker, FreeColGameObject defender)
Generates a list of results of an attack.abstract double
getDefencePower(FreeColGameObject attacker, FreeColGameObject defender)
Get the defensive power of a defender wrt an attacker.abstract java.util.Set<Modifier>
getDefensiveModifiers(FreeColGameObject attacker, FreeColGameObject defender)
Collect all defensive modifiers that apply to a unit defending against another.java.util.Comparator<Unit>
getMilitaryStrengthComparator()
Get a comparator to order units by relative military strength with respect to this combat model.abstract double
getOffencePower(FreeColGameObject attacker, FreeColGameObject defender)
Get the offensive power of a attacker wrt a defender.abstract java.util.Set<Modifier>
getOffensiveModifiers(FreeColGameObject attacker, FreeColGameObject defender)
Collect all the offensive modifiers that apply to an attack.
-
-
-
Method Detail
-
combatIsAttackMeasurement
public boolean combatIsAttackMeasurement(FreeColGameObject attacker, FreeColGameObject defender)
Is this just a measurement of offence power?- Parameters:
attacker
- The attacker.defender
- The defender.- Returns:
- True if no defender is provided.
-
combatIsDefenceMeasurement
public boolean combatIsDefenceMeasurement(FreeColGameObject attacker, FreeColGameObject defender)
Is this just a measurement of defence power?- Parameters:
attacker
- The attacker.defender
- The defender.- Returns:
- True if no attacker is provided.
-
combatIsAttack
public boolean combatIsAttack(FreeColGameObject attacker, FreeColGameObject defender)
Is this combat a normal attack?- Parameters:
attacker
- The attacker.defender
- The defender.- Returns:
- True if the combat is a normal attack.
-
combatIsSettlementAttack
public boolean combatIsSettlementAttack(FreeColGameObject attacker, FreeColGameObject defender)
Is this combat a attack on a settlement? These happen on the client side only, for the purposes of the pre-combat display. In these cases the actual defender unit is hidden from the attacker player, so the defender is shown as the settlement itself.- Parameters:
attacker
- The attacker.defender
- The defender.- Returns:
- True if the combat is a client-side attack on a settlement.
-
combatIsBombard
public boolean combatIsBombard(FreeColGameObject attacker, FreeColGameObject defender)
Is this combat a bombardment?- Parameters:
attacker
- The attacker.defender
- The defender.- Returns:
- True if the combat is a bombardment.
-
combatIsAmphibious
public boolean combatIsAmphibious(FreeColGameObject attacker, FreeColGameObject defender)
Could this attack be an amphibious operation?- Parameters:
attacker
- The attacker.defender
- The defender.- Returns:
- True if the attack is amphibious.
-
combatIsWarOfIndependence
public boolean combatIsWarOfIndependence(FreeColGameObject attacker, FreeColGameObject defender)
Is this a combat between a rebel player and the REF at a colony?- Parameters:
attacker
- The attacker object.defender
- The defender object.- Returns:
- True if the attack is a war of independence battle for a colony.
-
getMilitaryStrengthComparator
public final java.util.Comparator<Unit> getMilitaryStrengthComparator()
Get a comparator to order units by relative military strength with respect to this combat model.- Returns:
- A suitable unit
Comparator
.
-
calculateCombatOdds
public abstract CombatModel.CombatOdds calculateCombatOdds(FreeColGameObject attacker, FreeColGameObject defender)
Calculates the chance of the outcomes of a combat.- Parameters:
attacker
- The attacker.defender
- The defender.- Returns:
- The
CombatOdds
.
-
getOffencePower
public abstract double getOffencePower(FreeColGameObject attacker, FreeColGameObject defender)
Get the offensive power of a attacker wrt a defender. Null can be passed for the defender when only the attacker stats are required.- Parameters:
attacker
- The attacker.defender
- The defender.- Returns:
- The offensive power.
-
getDefencePower
public abstract double getDefencePower(FreeColGameObject attacker, FreeColGameObject defender)
Get the defensive power of a defender wrt an attacker.- Parameters:
attacker
- The attacker.defender
- The defender.- Returns:
- The defensive power.
-
getOffensiveModifiers
public abstract java.util.Set<Modifier> getOffensiveModifiers(FreeColGameObject attacker, FreeColGameObject defender)
Collect all the offensive modifiers that apply to an attack. Null can be passed as the defender when only the attacker unit stats are required.- Parameters:
attacker
- The attacker.defender
- The defender.- Returns:
- All the applicable offensive modifiers.
-
getDefensiveModifiers
public abstract java.util.Set<Modifier> getDefensiveModifiers(FreeColGameObject attacker, FreeColGameObject defender)
Collect all defensive modifiers that apply to a unit defending against another.- Parameters:
attacker
- The attacker.defender
- The defender.- Returns:
- All the applicable defensive modifiers.
-
generateAttackResult
public abstract java.util.List<CombatModel.CombatResult> generateAttackResult(java.util.Random random, FreeColGameObject attacker, FreeColGameObject defender)
Generates a list of results of an attack. The first must be one of NO_RESULT, LOSE or WIN. The rest can be any other CombatResult suitable to the situation. To be called by the server only.- Parameters:
random
- A pseudo-random number source.attacker
- The attacker.defender
- The defender.- Returns:
- The results of the combat.
-
-