Class 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.
    • 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
    • Constructor Detail

      • SimpleCombatModel

        public SimpleCombatModel()
        Deliberately empty constructor.
    • Method Detail

      • getOffencePower

        public double getOffencePower​(FreeColGameObject attacker,
                                      FreeColGameObject defender)
        Get the offensive power of a unit attacking another.
        Specified by:
        getOffencePower in class CombatModel
        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 - The LogBuilder to log to.
        modSet - A set of Modifiers 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 optional LogBuilder to log to.
        Returns:
        The offensive 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 optional LogBuilder 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 class CombatModel
        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 - The Colony under attack.
        attacker - The attacking Unit.
        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 attacker Unit.
        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 class CombatModel
        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 defender Unit.
        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 - The FreeColObject 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 defender Unit.
        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 class CombatModel
        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 winning Unit.
        loser - The losing Unit.
        great - True if this is a great win/loss.
        r - A "residual" random value (for convert/burn mission).
        crs - A list of CombatResults 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.