Class CombatUtils

Object
CombatUtils

public class CombatUtils extends Object
Contains methods that deal with the battle map in general. These methods do not respect fog of war, and assume that you are in combat (Global.getCombatEngine() != null). If you wish to check fog of war visibility you should use the methods in AIUtils.
Since:
1.0
Author:
LazyWizard
See Also:
  • Method Details

    • getFleetMember

      @Nullable public static FleetMemberAPI getFleetMember(ShipAPI ship)
      Find a ShipAPI's corresponding FleetMemberAPI. Due to the way the game keeps tracks of ship ownership, this will be extremely slow when used with hulks.
      Parameters:
      ship - The ShipAPI whose corresponding FleetMemberAPI we are trying to find.
      Returns:
      The FleetMemberAPI that represents this ShipAPI in the campaign, or null if no match is found.
      Since:
      1.5
    • isVisibleToSide

      public static boolean isVisibleToSide(CombatEntityAPI entity, int side)
      Checks if a CombatEntityAPI is visible to a side of battle. Note1: Allied and neutral entities are always visible. Note2: All AIUtils methods already filter by visibility, so use of this method is not necessary on their results.
      Parameters:
      entity - The CombatEntityAPI to check visibility of.
      side - The side whose fog of war will be tested.
      Returns:
      true if entity is visible to side, false otherwise.
      Since:
      1.7
    • getProjectilesWithinRange

      public static List<DamagingProjectileAPI> getProjectilesWithinRange(Vector2f location, float range)
      Returns all projectiles in range of a given location, excluding missiles.
      Parameters:
      location - The location to search around.
      range - How far around location to search.
      Returns:
      A List of DamagingProjectileAPIs within range of location.
      Since:
      1.0
    • getMissilesWithinRange

      public static List<MissileAPI> getMissilesWithinRange(Vector2f location, float range)
      Returns all missiles in range of a given location.
      Parameters:
      location - The location to search around.
      range - How far around location to search.
      Returns:
      A List of MissileAPIs within range of location.
      Since:
      1.0
    • getShipsWithinRange

      public static List<ShipAPI> getShipsWithinRange(Vector2f location, float range)
      Returns all ships in range of a given location, excluding the shuttle pod.
      Parameters:
      location - The location to search around.
      range - How far around location to search.
      Returns:
      A List of ShipAPIs within range of location.
      Since:
      1.0
    • getAsteroidsWithinRange

      public static List<CombatEntityAPI> getAsteroidsWithinRange(Vector2f location, float range)
      Returns all asteroids in range of a given location.
      Parameters:
      location - The location to search around.
      range - How far around location to search.
      Returns:
      A List of asteroids within range of location.
      Since:
      1.0
    • getObjectivesWithinRange

      public static List<BattleObjectiveAPI> getObjectivesWithinRange(Vector2f location, float range)
      Returns all objectives in range of a given location.
      Parameters:
      location - The location to search around.
      range - How far around location to search.
      Returns:
      A List of BattleObjectiveAPIs within range of location.
      Since:
      1.0
    • getEntitiesWithinRange

      public static List<CombatEntityAPI> getEntitiesWithinRange(Vector2f location, float range)
      Returns all entities in range of a given location. This includes ships, projectiles, missiles, and asteroids.
      Parameters:
      location - The location to search around.
      range - How far around location to search.
      Returns:
      A List of CombatEntityAPIs within range of location.
      Since:
      1.0
    • spawnShipOrWingDirectly

      public static ShipAPI spawnShipOrWingDirectly(String variantId, FleetMemberType type, FleetSide side, float combatReadiness, Vector2f location, float facing)
      Spawns a ship directly onto the battle map, bypassing the fleet reserves. NOTE: this method will not work out of the box in the campaign (.6.2a) due to an after-battle crash in the default FleetEncounterContextPlugin caused by spawned ships not being registered with the fleet.
      Parameters:
      variantId - The ID of the ship variant to spawn.
      type - Whether this is a ship or a fighter wing.
      side - What side of the battle this ship should fight on.
      combatReadiness - The CR the ship should start with.
      location - The location on the battle map the ship should spawn at.
      facing - The initial facing of the ship on the battle map.
      Returns:
      The ShipAPI that was spawned by this method.
      Since:
      1.9
    • centerViewport

      public static void centerViewport(Vector2f newCenter)
      Recenters the viewport at a specific point.
      Parameters:
      newCenter - The new center point of the ViewportAPI.
      Since:
      2.0
    • toWorldCoordinates

      public static Vector2f toWorldCoordinates(Vector2f screenCoordinates)
      Converts screenspace coordinates to world coordinates.
      Parameters:
      screenCoordinates - The screenspace coordinates to convert.
      Returns:
      screenCoordinates converted to world coordinates.
      Since:
      2.3
    • toScreenCoordinates

      public static Vector2f toScreenCoordinates(Vector2f worldCoordinates)
      Converts worldspace coordinates to screen coordinates.
      Parameters:
      worldCoordinates - The worldspace coordinates to convert.
      Returns:
      worldCoordinates converted to screen coordinates.
      Since:
      2.3
    • applyForce

      public static void applyForce(CombatEntityAPI entity, Vector2f direction, float force)
      Apply force to an object. Remember Newton's Second Law.

      Force is multiplied by 100 to avoid requiring ridiculous force amounts.

      Parameters:
      entity - The CombatEntityAPI to apply the force to.
      direction - The directional vector of the force (this will automatically be normalized).
      force - How much force to apply. Unit is how much it takes to modify a 100 weight object's velocity by 1 su/sec.
      Since:
      1.2
    • applyForce

      public static void applyForce(CombatEntityAPI entity, float direction, float force)
      Apply force to an object. Remember Newton's Second Law.

      Force is multiplied by 100 to avoid requiring ridiculous force amounts.

      Parameters:
      entity - The CombatEntityAPI to apply the force to.
      direction - The angle the force will be applied towards.
      force - How much force to apply. Unit is how much it takes to modify a 100 weight object's velocity by 1 su/sec.
      Since:
      1.2