Package net.sf.freecol.common.model
Class SimpleCombatModel
- java.lang.Object
-
- net.sf.freecol.common.model.CombatModel
-
- net.sf.freecol.common.model.SimpleCombatModel
-
public class SimpleCombatModel extends CombatModel
This class implements the original Colonization combat model. The name of this class is laughably wrong. Note that the damage part of any CombatResult is ignored throughout.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.sf.freecol.common.model.CombatModel
CombatModel.CombatOdds, CombatModel.CombatResult
-
-
Field Summary
Fields Modifier and Type Field Description 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 int
STRONG_DEFENCE_THRESHOLD
A defence percentage bonus that disables the fortification bonus.static Modifier
UNKNOWN_DEFENCE_MODIFIER
-
Constructor Summary
Constructors Constructor Description SimpleCombatModel()
Deliberately empty constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addLandDefensiveModifiers(FreeColGameObject attacker, Unit defender, java.util.Set<Modifier> result)
Add all the defensive modifiers that apply to a land attack.private void
addLandOffensiveModifiers(Unit attacker, FreeColGameObject defender, java.util.Set<Modifier> result)
Add all the offensive modifiers that apply to a land attack.private void
addNavalDefensiveModifiers(Unit defender, java.util.Set<Modifier> result)
Add all the defensive modifiers that apply to a naval attack.private void
addNavalOffensiveModifiers(Unit attacker, java.util.Set<Modifier> result)
Add all the offensive modifiers that apply to a naval attack.private void
addPopularSupportBonus(Colony colony, Unit attacker, java.util.Set<Modifier> result)
Add the popular support bonus to the result set if applicable.CombatModel.CombatOdds
calculateCombatOdds(FreeColGameObject attacker, FreeColGameObject defender)
Calculates the odds of success in combat.private CombatModel.CombatOdds
calculateCombatOdds(FreeColGameObject attacker, FreeColGameObject defender, LogBuilder lb)
Calculates the odds of success in combat.java.util.List<CombatModel.CombatResult>
generateAttackResult(java.util.Random random, FreeColGameObject attacker, FreeColGameObject defender)
Generates a result of a unit attacking.double
getDefencePower(FreeColGameObject attacker, FreeColGameObject defender)
Get the defensive power wrt an attacker.double
getDefencePower(FreeColGameObject attacker, FreeColGameObject defender, LogBuilder lb)
Get the defensive power wrt an attacker.java.util.Set<Modifier>
getDefensiveModifiers(FreeColGameObject attacker, FreeColGameObject defender)
Collect all defensive modifiers when defending against an attack.double
getOffencePower(FreeColGameObject attacker, FreeColGameObject defender)
Get the offensive power of a unit attacking another.private double
getOffencePower(FreeColGameObject attacker, FreeColGameObject defender, LogBuilder lb)
Get the offensive power of a unit attacking another.java.util.Set<Modifier>
getOffensiveModifiers(FreeColGameObject attacker, FreeColGameObject defender)
Collect all the offensive modifiers that apply to an attack.private boolean
hasStrongDefenceModifier(FreeColObject fco)
Does a given object provide a strong defence bonus?private boolean
isAmbush(FreeColGameObject attacker, FreeColGameObject defender)
Could this attack be an ambush?private void
logModifiers(LogBuilder lb, java.util.Set<Modifier> modSet)
Helper to log modifiers with.private void
resolveAttack(Unit winner, Unit loser, boolean great, double r, java.util.List<CombatModel.CombatResult> crs)
Resolve all the consequences of a normal attack.-
Methods inherited from class net.sf.freecol.common.model.CombatModel
combatIsAmphibious, combatIsAttack, combatIsAttackMeasurement, combatIsBombard, combatIsDefenceMeasurement, combatIsSettlementAttack, combatIsWarOfIndependence, getMilitaryStrengthComparator
-
-
-
-
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
-
STRONG_DEFENCE_THRESHOLD
public static final int STRONG_DEFENCE_THRESHOLD
A defence percentage bonus that disables the fortification bonus.- See Also:
- Constant Field Values
-
UNKNOWN_DEFENCE_MODIFIER
public static final Modifier UNKNOWN_DEFENCE_MODIFIER
-
-
Method Detail
-
calculateCombatOdds
public CombatModel.CombatOdds calculateCombatOdds(FreeColGameObject attacker, FreeColGameObject defender)
Calculates the odds of success in combat.- Specified by:
calculateCombatOdds
in classCombatModel
- Parameters:
attacker
- The attacker.defender
- The defender.- Returns:
- The combat odds.
-
calculateCombatOdds
private CombatModel.CombatOdds calculateCombatOdds(FreeColGameObject attacker, FreeColGameObject defender, LogBuilder lb)
Calculates the odds of success in combat.- Parameters:
attacker
- The attacker.defender
- The defender.lb
- An optionalLogBuilder
to log to.- Returns:
- The combat odds.
-
getOffencePower
public double getOffencePower(FreeColGameObject attacker, FreeColGameObject defender)
Get the offensive power of a unit attacking another.- Specified by:
getOffencePower
in classCombatModel
- Parameters:
attacker
- The attacker.defender
- The defender.- Returns:
- The offensive power.
-
logModifiers
private void logModifiers(LogBuilder lb, java.util.Set<Modifier> modSet)
Helper to log modifiers with.- Parameters:
lb
- TheLogBuilder
to log to.modSet
- A set ofModifiers
to log.
-
getOffencePower
private double getOffencePower(FreeColGameObject attacker, FreeColGameObject defender, LogBuilder lb)
Get the offensive power of a unit attacking another.- Parameters:
attacker
- The attacker.defender
- The defender.lb
- An optionalLogBuilder
to log to.- Returns:
- The offensive power.
-
getDefencePower
public double getDefencePower(FreeColGameObject attacker, FreeColGameObject defender)
Get the defensive power wrt an attacker.- Specified by:
getDefencePower
in classCombatModel
- Parameters:
attacker
- The attacker.defender
- The defender.- Returns:
- The defensive power.
-
getDefencePower
public double getDefencePower(FreeColGameObject attacker, FreeColGameObject defender, LogBuilder lb)
Get the defensive power wrt an attacker.- Parameters:
attacker
- The attacker.defender
- The defender.lb
- An optionalLogBuilder
to log to.- Returns:
- The defensive power.
-
getOffensiveModifiers
public java.util.Set<Modifier> getOffensiveModifiers(FreeColGameObject attacker, FreeColGameObject defender)
Collect all the offensive modifiers that apply to an attack.- Specified by:
getOffensiveModifiers
in classCombatModel
- Parameters:
attacker
- The attacker.defender
- The defender.- Returns:
- All the applicable offensive modifiers.
-
addNavalOffensiveModifiers
private void addNavalOffensiveModifiers(Unit attacker, java.util.Set<Modifier> result)
Add all the offensive modifiers that apply to a naval attack.- Parameters:
attacker
- The attacker.result
- The set of modifiers to add to.
-
addPopularSupportBonus
private void addPopularSupportBonus(Colony colony, Unit attacker, java.util.Set<Modifier> result)
Add the popular support bonus to the result set if applicable.- Parameters:
colony
- TheColony
under attack.attacker
- The attackingUnit
.result
- The set of modifiers to add to.
-
addLandOffensiveModifiers
private void addLandOffensiveModifiers(Unit attacker, FreeColGameObject defender, java.util.Set<Modifier> result)
Add all the offensive modifiers that apply to a land attack.- Parameters:
attacker
- The attackerUnit
.defender
- The defender.result
- The set of modifiers to add to.
-
getDefensiveModifiers
public java.util.Set<Modifier> getDefensiveModifiers(FreeColGameObject attacker, FreeColGameObject defender)
Collect all defensive modifiers when defending against an attack.- Specified by:
getDefensiveModifiers
in classCombatModel
- Parameters:
attacker
- The attacker.defender
- The defender.- Returns:
- All the applicable defensive modifiers.
-
addNavalDefensiveModifiers
private void addNavalDefensiveModifiers(Unit defender, java.util.Set<Modifier> result)
Add all the defensive modifiers that apply to a naval attack.- Parameters:
defender
- The defenderUnit
.result
- The set of modifiers to add to.
-
hasStrongDefenceModifier
private boolean hasStrongDefenceModifier(FreeColObject fco)
Does a given object provide a strong defence bonus?- Parameters:
fco
- TheFreeColObject
to check.- Returns:
- True if a strong defence bonus is present.
-
addLandDefensiveModifiers
private void addLandDefensiveModifiers(FreeColGameObject attacker, Unit defender, java.util.Set<Modifier> result)
Add all the defensive modifiers that apply to a land attack.- Parameters:
attacker
- The attacker.defender
- The defenderUnit
.result
- The set of modifiers to add to.
-
generateAttackResult
public java.util.List<CombatModel.CombatResult> generateAttackResult(java.util.Random random, FreeColGameObject attacker, FreeColGameObject defender)
Generates a result of a unit attacking. Takes care to only call the pseudo-random source *once*.- Specified by:
generateAttackResult
in classCombatModel
- Parameters:
random
- A pseudo-random number source.attacker
- The attacker.defender
- The defender.- Returns:
- The results of the combat.
-
resolveAttack
private void resolveAttack(Unit winner, Unit loser, boolean great, double r, java.util.List<CombatModel.CombatResult> crs)
Resolve all the consequences of a normal attack.- Parameters:
winner
- The winningUnit
.loser
- The losingUnit
.great
- True if this is a great win/loss.r
- A "residual" random value (for convert/burn mission).crs
- A list ofCombatResult
s to add to.
-
isAmbush
private boolean isAmbush(FreeColGameObject attacker, FreeColGameObject defender)
Could this attack be an ambush?- Parameters:
attacker
- The attacker.defender
- The defender.- Returns:
- True if the attack can be an ambush.
-
-