Class CampaignUtils

Object
CampaignUtils

public class CampaignUtils extends Object
Contains methods for working with campaign objects. Unless noted otherwise, all methods in this class only deal with the LocationAPI the specified token is located in.
Since:
2.0
Author:
LazyWizard
See Also:
  • Method Details

    • isPlayer

      public static boolean isPlayer(CampaignFleetAPI fleet)
      Checks if a fleet is the player fleet.
      Parameters:
      fleet - The CampaignFleetAPI to be checked.
      Returns:
      true if fleet is the player fleet, false otherwise.
      Since:
      1.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
    • getRelation

      public static float getRelation(SectorEntityToken token1, SectorEntityToken token2)
      Returns the faction relationship between two campaign objects. Equivalent to calling token1.getFaction().getRelationship(token2.getFaction().getId()), but much more readable.
      Parameters:
      token1 - A SectorEntityToken whose faction relationship will be tested.
      token2 - The SectorEntityToken to test relationship with.
      Returns:
      The faction relationship between token1 and token2.
      Since:
      1.7
    • getReputation

      public static RepLevel getReputation(SectorEntityToken token1, SectorEntityToken token2)
      Returns the faction relationship between two campaign objects. Equivalent to calling token1.getFaction().getRelationshipLevel(token2.getFaction()), but much more readable.
      Parameters:
      token1 - A SectorEntityToken whose faction reputation will be tested.
      token2 - The SectorEntityToken to test reputation with.
      Returns:
      The faction reputation between token1 and token2.
      Since:
      2.0
    • areSameFaction

      public static boolean areSameFaction(SectorEntityToken token1, SectorEntityToken token2)
      Checks if two campaign objects are owned by the same faction.
      Parameters:
      token1 - The first SectorEntityToken to check.
      token2 - The second SectorEntityToken to check.
      Returns:
      true if both tokens share a faction, false otherwise.
      Since:
      2.0
    • areAtRep

      public static boolean areAtRep(SectorEntityToken token1, SectorEntityToken token2, CampaignUtils.IncludeRep include, RepLevel rep)
      Checks if two campaign objects have a specific reputation with each other.
      Parameters:
      token1 - The first SectorEntityToken to check.
      token2 - The second SectorEntityToken to check.
      include - What relative range of reputations to include.
      rep - The base reputation level token1 and {token2} must be at with each other for this to return true, modified by include.
      Returns:
      true if both tokens share a faction, false otherwise.
      Since:
      2.0
    • isShipInFleet

      public static boolean isShipInFleet(String fleetMemberId, CampaignFleetAPI fleet)
      Checks if a fleet contains a specific ship in its roster. Does NOT check mothballed ships - call CargoUtils.isShipInMothballed(java.lang.String, com.fs.starfarer.api.campaign.CargoAPI) for that.
      Parameters:
      fleetMemberId - The fleet member ID of the ship to check. This can be retrieved with ShipAPI.getFleetMemberId() or FleetMemberAPI.getId().
      fleet - The fleet to check for the presence of this ship in.
      Returns:
      true if fleet contains a ship with this ID, false otherwise.
      Since:
      1.8
    • addShipToFleet

      public static FleetMemberAPI addShipToFleet(String wingOrVariantId, FleetMemberType type, CampaignFleetAPI fleet)
      Adds a fully crewed, fully combat ready ship to the designated fleet.
      Parameters:
      wingOrVariantId - The wing or variant ID to create.
      type - Whether to add a fighter wing or a ship.
      fleet - The fleet to add this ship to.
      Returns:
      The FleetMemberAPI of the created ship.
      Since:
      2.1
    • getNearestHostileFleet

      @Nullable public static CampaignFleetAPI getNearestHostileFleet(SectorEntityToken token)
      Find the closest hostile fleet to a SectorEntityToken.
      Parameters:
      token - The SectorEntityToken to search around.
      Returns:
      The hostile CampaignFleetAPI closest to token, or null if none are found.
      Since:
      1.2
    • getNearbyHostileFleets

      public static List<CampaignFleetAPI> getNearbyHostileFleets(SectorEntityToken token, float range)
      Finds all visible hostile fleets within a certain range around a SectorEntityToken.
      Parameters:
      token - The entity to search around.
      range - How far around token to search.
      Returns:
      A List containing all fleets within range that are hostile towards token and can be seen by it.
      Since:
      1.2
    • getHostileFleetsInSystem

      public static List<CampaignFleetAPI> getHostileFleetsInSystem(SectorEntityToken token)
      Find all hostile fleets towards a SectorEntityToken present in that token's location.
      Parameters:
      token - The SectorEntityToken to find enemies of.
      Returns:
      All enemies of token in the system that are actively hostile.
      Since:
      1.2
    • getNearestEntityWithTag

      @Nullable public static <T extends SectorEntityToken> T getNearestEntityWithTag(SectorEntityToken token, String entityTag)
      Find the closest entity with a specifc tag to a SectorEntityToken, excluding itself.
      Parameters:
      token - The SectorEntityToken to search around.
      entityTag - The tag we should be searching for; for example: Tags.STATION or Tags.JUMP_POINT.
      Returns:
      The object with tag entityTag closest to token, or null if none are found.
      Since:
      2.0
    • getNearbyEntitiesWithTag

      public static <T extends SectorEntityToken> List<T> getNearbyEntitiesWithTag(SectorEntityToken token, float range, String entityTag)
      Find entities with a specific tag near a SectorEntityToken, excluding itself.
      Parameters:
      token - The SectorEntityToken to search around.
      range - How far around token to search.
      entityTag - The tag we should be searching for; for example: Tags.STATION or Tags.JUMP_POINT.
      Returns:
      All objects with tag entityTag within range of token.
      Since:
      2.0
    • getNearestEntityFromFaction

      @Nullable public static <T extends SectorEntityToken> T getNearestEntityFromFaction(SectorEntityToken token, String entityTag, FactionAPI faction)
      Find the closest entity with a specific tag and faction near a SectorEntityToken, excluding itself.
      Parameters:
      token - The SectorEntityToken to search around.
      entityTag - The tag we should be searching for; for example: Tags.STATION or Tags.JUMP_POINT.
      faction - The faction ownership we are looking for.
      Returns:
      The object with tag entityTag closest to token that is owned by faction, or null if none are found.
      Since:
      2.0
    • getNearbyEntitiesFromFaction

      public static <T extends SectorEntityToken> List<T> getNearbyEntitiesFromFaction(SectorEntityToken token, float range, String entityTag, FactionAPI faction)
      Find entities with a specific tag and from a specific faction near a SectorEntityToken, excluding itself.
      Parameters:
      token - The SectorEntityToken to search around.
      range - How far around token to search.
      entityTag - The tag we should be searching for; for example: Tags.STATION or Tags.JUMP_POINT.
      faction - What faction the entity must be owned by.
      Returns:
      All objects with tag entityTag and faction faction within range of token.
      Since:
      2.0
    • getEntitiesFromFaction

      public static <T extends SectorEntityToken> List<T> getEntitiesFromFaction(LocationAPI location, String entityTag, FactionAPI faction)
      Find all entities with a specific tag and faction within a location.
      Parameters:
      location - The LocationAPI to search in.
      entityTag - The tag we should be searching for; for example: Tags.STATION or Tags.JUMP_POINT.
      faction - What faction entities must belong to.
      Returns:
      All objects of faction faction and with tag entityTag within location.
      Since:
      2.0
    • getNearestEntityWithRep

      @Nullable public static <T extends SectorEntityToken> T getNearestEntityWithRep(SectorEntityToken token, String entityTag, CampaignUtils.IncludeRep include, RepLevel rep)
      Find the closest entity with a specific tag and reputation with a SectorEntityToken, excluding itself.
      Parameters:
      token - The SectorEntityToken to search around.
      entityTag - The tag we should be searching for; for example: Tags.STATION or Tags.JUMP_POINT.
      include - What range of RepLevels to accept, relative to rep.
      rep - The base reputation to check against.
      Returns:
      The object with tag entityTag closest to token within the reputation range specified by include and rep, or null if none are found.
      Since:
      2.0
    • getNearbyEntitiesWithRep

      public static <T extends SectorEntityToken> List<T> getNearbyEntitiesWithRep(SectorEntityToken token, float range, String entityTag, CampaignUtils.IncludeRep include, RepLevel rep)
      Find nearby entities with a specific tag and reputation with a SectorEntityToken, excluding itself.
      Parameters:
      token - The SectorEntityToken to search around.
      range - How far around token to search.
      entityTag - The tag we should be searching for; for example: Tags.STATION or Tags.JUMP_POINT.
      include - What range of RepLevels to accept, relative to rep.
      rep - The base reputation to check against.
      Returns:
      All objects with tag entityTag within range of token.
      Since:
      2.0
    • getEntitiesWithRep

      public static <T extends SectorEntityToken> List<T> getEntitiesWithRep(SectorEntityToken token, String entityTag, CampaignUtils.IncludeRep include, RepLevel rep)
      Find all entities with a specific tag and reputation with a SectorEntityToken in that token's location, excluding itself.
      Parameters:
      token - The SectorEntityToken to search around.
      entityTag - The tag we should be searching for; for example: Tags.STATION or Tags.JUMP_POINT.
      include - What range of RepLevels to accept, relative to rep.
      rep - The base reputation to check against.
      Returns:
      All objects with tag entityTag within range of token.
      Since:
      2.0
    • getNearbyFleets

      public static List<CampaignFleetAPI> getNearbyFleets(SectorEntityToken token, float range)
      Finds all visible fleets within a certain range around a SectorEntityToken.
      Parameters:
      token - The entity to search around.
      range - How far around token to search.
      Returns:
      A List containing all fleets within range that token can see, excluding itself if it is a CampaignFleetAPI.
      Since:
      1.7