Package org.lazywizard.lazylib.campaign
Class CampaignUtils
Object
CampaignUtils
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum -
Method Summary
Modifier and TypeMethodDescriptionstatic FleetMemberAPIaddShipToFleet(String wingOrVariantId, FleetMemberType type, CampaignFleetAPI fleet) Adds a fully crewed, fully combat ready ship to the designated fleet.static booleanareAtRep(SectorEntityToken token1, SectorEntityToken token2, CampaignUtils.IncludeRep include, RepLevel rep) Checks if two campaign objects have a specific reputation with each other.static booleanareSameFaction(SectorEntityToken token1, SectorEntityToken token2) Checks if two campaign objects are owned by the same faction.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.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 aSectorEntityTokenin that token's location, excluding itself.static List<CampaignFleetAPI>Find all hostile fleets towards aSectorEntityTokenpresent in that token's location.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 aSectorEntityToken, excluding itself.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 aSectorEntityToken, excluding itself.static <T extends SectorEntityToken>
List<T>getNearbyEntitiesWithTag(SectorEntityToken token, float range, String entityTag) Find entities with a specific tag near aSectorEntityToken, excluding itself.static List<CampaignFleetAPI>getNearbyFleets(SectorEntityToken token, float range) Finds all visible fleets within a certain range around aSectorEntityToken.static List<CampaignFleetAPI>getNearbyHostileFleets(SectorEntityToken token, float range) Finds all visible hostile fleets within a certain range around aSectorEntityToken.static <T extends SectorEntityToken>
TgetNearestEntityFromFaction(SectorEntityToken token, String entityTag, FactionAPI faction) Find the closest entity with a specific tag and faction near aSectorEntityToken, excluding itself.static <T extends SectorEntityToken>
TgetNearestEntityWithRep(SectorEntityToken token, String entityTag, CampaignUtils.IncludeRep include, RepLevel rep) Find the closest entity with a specific tag and reputation with aSectorEntityToken, excluding itself.static <T extends SectorEntityToken>
TgetNearestEntityWithTag(SectorEntityToken token, String entityTag) Find the closest entity with a specifc tag to aSectorEntityToken, excluding itself.static CampaignFleetAPIFind the closest hostile fleet to aSectorEntityToken.static floatgetRelation(SectorEntityToken token1, SectorEntityToken token2) Returns the faction relationship between two campaign objects.static RepLevelgetReputation(SectorEntityToken token1, SectorEntityToken token2) Returns the faction relationship between two campaign objects.static booleanisPlayer(CampaignFleetAPI fleet) Checks if a fleet is the player fleet.static booleanisShipInFleet(String fleetMemberId, CampaignFleetAPI fleet) Checks if a fleet contains a specific ship in its roster.static Vector2ftoScreenCoordinates(Vector2f worldCoordinates) Converts worldspace coordinates to screen coordinates.static Vector2ftoWorldCoordinates(Vector2f screenCoordinates) Converts screenspace coordinates to world coordinates.
-
Method Details
-
isPlayer
Checks if a fleet is the player fleet.- Parameters:
fleet- TheCampaignFleetAPIto be checked.- Returns:
trueiffleetis the player fleet,falseotherwise.- Since:
- 1.0
-
toWorldCoordinates
Converts screenspace coordinates to world coordinates.- Parameters:
screenCoordinates- The screenspace coordinates to convert.- Returns:
screenCoordinatesconverted to world coordinates.- Since:
- 2.3
-
toScreenCoordinates
Converts worldspace coordinates to screen coordinates.- Parameters:
worldCoordinates- The worldspace coordinates to convert.- Returns:
worldCoordinatesconverted to screen coordinates.- Since:
- 2.3
-
getRelation
Returns the faction relationship between two campaign objects. Equivalent to calling token1.getFaction().getRelationship(token2.getFaction().getId()), but much more readable.- Parameters:
token1- ASectorEntityTokenwhose faction relationship will be tested.token2- TheSectorEntityTokento test relationship with.- Returns:
- The faction relationship between
token1andtoken2. - Since:
- 1.7
-
getReputation
Returns the faction relationship between two campaign objects. Equivalent to calling token1.getFaction().getRelationshipLevel(token2.getFaction()), but much more readable.- Parameters:
token1- ASectorEntityTokenwhose faction reputation will be tested.token2- TheSectorEntityTokento test reputation with.- Returns:
- The faction reputation between
token1andtoken2. - Since:
- 2.0
-
areSameFaction
Checks if two campaign objects are owned by the same faction.- Parameters:
token1- The firstSectorEntityTokento check.token2- The secondSectorEntityTokento check.- Returns:
trueif both tokens share a faction,falseotherwise.- 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 firstSectorEntityTokento check.token2- The secondSectorEntityTokento check.include- What relative range of reputations to include.rep- The base reputation leveltoken1and {token2} must be at with each other for this to returntrue, modified byinclude.- Returns:
trueif both tokens share a faction,falseotherwise.- Since:
- 2.0
-
isShipInFleet
Checks if a fleet contains a specific ship in its roster. Does NOT check mothballed ships - callCargoUtils.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 withShipAPI.getFleetMemberId()orFleetMemberAPI.getId().fleet- The fleet to check for the presence of this ship in.- Returns:
trueiffleetcontains a ship with this ID,falseotherwise.- 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
FleetMemberAPIof the created ship. - Since:
- 2.1
-
getNearestHostileFleet
Find the closest hostile fleet to aSectorEntityToken.- Parameters:
token- TheSectorEntityTokento search around.- Returns:
- The hostile
CampaignFleetAPIclosest totoken, ornullif none are found. - Since:
- 1.2
-
getNearbyHostileFleets
Finds all visible hostile fleets within a certain range around aSectorEntityToken.- Parameters:
token- The entity to search around.range- How far aroundtokento search.- Returns:
- A
Listcontaining all fleets within range that are hostile towardstokenand can be seen by it. - Since:
- 1.2
-
getHostileFleetsInSystem
Find all hostile fleets towards aSectorEntityTokenpresent in that token's location.- Parameters:
token- TheSectorEntityTokento find enemies of.- Returns:
- All enemies of
tokenin 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 aSectorEntityToken, excluding itself.- Parameters:
token- TheSectorEntityTokento search around.entityTag- The tag we should be searching for; for example:Tags.STATIONorTags.JUMP_POINT.- Returns:
- The object with tag
entityTagclosest totoken, ornullif 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 aSectorEntityToken, excluding itself.- Parameters:
token- TheSectorEntityTokento search around.range- How far aroundtokento search.entityTag- The tag we should be searching for; for example:Tags.STATIONorTags.JUMP_POINT.- Returns:
- All objects with tag
entityTagwithin range oftoken. - 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 aSectorEntityToken, excluding itself.- Parameters:
token- TheSectorEntityTokento search around.entityTag- The tag we should be searching for; for example:Tags.STATIONorTags.JUMP_POINT.faction- The faction ownership we are looking for.- Returns:
- The object with tag
entityTagclosest totokenthat is owned byfaction, ornullif 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 aSectorEntityToken, excluding itself.- Parameters:
token- TheSectorEntityTokento search around.range- How far aroundtokento search.entityTag- The tag we should be searching for; for example:Tags.STATIONorTags.JUMP_POINT.faction- What faction the entity must be owned by.- Returns:
- All objects with tag
entityTagand factionfactionwithin range oftoken. - 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- TheLocationAPIto search in.entityTag- The tag we should be searching for; for example:Tags.STATIONorTags.JUMP_POINT.faction- What faction entities must belong to.- Returns:
- All objects of faction
factionand with tagentityTagwithinlocation. - 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 aSectorEntityToken, excluding itself.- Parameters:
token- TheSectorEntityTokento search around.entityTag- The tag we should be searching for; for example:Tags.STATIONorTags.JUMP_POINT.include- What range ofRepLevels to accept, relative torep.rep- The base reputation to check against.- Returns:
- The object with tag
entityTagclosest totokenwithin the reputation range specified byincludeandrep, ornullif 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 aSectorEntityToken, excluding itself.- Parameters:
token- TheSectorEntityTokento search around.range- How far aroundtokento search.entityTag- The tag we should be searching for; for example:Tags.STATIONorTags.JUMP_POINT.include- What range ofRepLevels to accept, relative torep.rep- The base reputation to check against.- Returns:
- All objects with tag
entityTagwithin range oftoken. - 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 aSectorEntityTokenin that token's location, excluding itself.- Parameters:
token- TheSectorEntityTokento search around.entityTag- The tag we should be searching for; for example:Tags.STATIONorTags.JUMP_POINT.include- What range ofRepLevels to accept, relative torep.rep- The base reputation to check against.- Returns:
- All objects with tag
entityTagwithin range oftoken. - Since:
- 2.0
-
getNearbyFleets
Finds all visible fleets within a certain range around aSectorEntityToken.- Parameters:
token- The entity to search around.range- How far aroundtokento search.- Returns:
- A
Listcontaining all fleets within range thattokencan see, excluding itself if it is aCampaignFleetAPI. - Since:
- 1.7
-