Class SeaFightService


  • @DependentInitialisation(ch.sahits.game.openpatrician.model.initialisation.StartNewGameBean.class)
    public class SeaFightService
    extends java.lang.Object
    The sea fight service helps calculating the winner of a sea fight based on two sets of ships. The central method is calculateOutcome(INavigableVessel, INavigableVessel, SeaFightContext). There are helper methods explodeShipList to convert the IShips to the required List of ships. There are further helper methods to collect the ships lists again after the fight.
    The only case the must be handled without the help of a helper method is if a single ship (not a group or convoy) of a player (AI or human) is attacked or defends and is victorious. This might result in a list of ships that should then all travel to the same destination as single ships.
    Author:
    Andi Hotz, (c) Sahits GmbH, 2015 Created on Dec 08, 2015
    • Constructor Summary

      Constructors 
      Constructor Description
      SeaFightService()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void calculateOutcome​(ch.sahits.game.openpatrician.model.ship.INavigableVessel attackingVessel, ch.sahits.game.openpatrician.model.ship.INavigableVessel defendingVessel, SeaFightContext context)
      Calculate the outcome of the fight.
      java.util.List<ch.sahits.game.openpatrician.model.ship.IShip> explodeShipList​(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
      Convert a vessel into a list of ships.
      ch.sahits.game.openpatrician.model.ship.IConvoy regroup​(java.util.List<ch.sahits.game.openpatrician.model.ship.IShip> ships, ch.sahits.game.openpatrician.model.ship.IConvoy oldConvoy)
      Update the convoy with the ships of the list.
      ch.sahits.game.openpatrician.model.ship.IShipGroup regroup​(java.util.List<ch.sahits.game.openpatrician.model.ship.IShip> ships, ch.sahits.game.openpatrician.model.ship.IShipGroup oldGroup)
      Create a group of ships from the list of ships.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SeaFightService

        public SeaFightService()
    • Method Detail

      • calculateOutcome

        public void calculateOutcome​(ch.sahits.game.openpatrician.model.ship.INavigableVessel attackingVessel,
                                     ch.sahits.game.openpatrician.model.ship.INavigableVessel defendingVessel,
                                     SeaFightContext context)
        Calculate the outcome of the fight. This includes damaging, destroying or capturing ships from either list.
        Parameters:
        attackingVessel - attacking vessel.
        defendingVessel - defending vessel.
      • explodeShipList

        public java.util.List<ch.sahits.game.openpatrician.model.ship.IShip> explodeShipList​(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
        Convert a vessel into a list of ships.
        Parameters:
        vessel - input vessel of type IConvoy, IShipGroup or simple IShip
        Returns:
        List of type IShip
      • regroup

        public ch.sahits.game.openpatrician.model.ship.IShipGroup regroup​(java.util.List<ch.sahits.game.openpatrician.model.ship.IShip> ships,
                                                                          ch.sahits.game.openpatrician.model.ship.IShipGroup oldGroup)
        Create a group of ships from the list of ships. As there might have been a group before the fight, this group should be updated with the current ship list. If there was no group, a new group will be created.
        Parameters:
        ships - List of ships
        oldGroup - previous group of ships to be updated, may be null.
        Returns:
        Updated oldGroup or a new instance containing the ships of the list
      • regroup

        public ch.sahits.game.openpatrician.model.ship.IConvoy regroup​(java.util.List<ch.sahits.game.openpatrician.model.ship.IShip> ships,
                                                                       ch.sahits.game.openpatrician.model.ship.IConvoy oldConvoy)
        Update the convoy with the ships of the list.
        Parameters:
        ships - List of ships
        oldConvoy - previous convoy that is to be updated.
        Returns:
        Updated oldConvoy.