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 FleetMemberAPI
addShipToFleet
(String wingOrVariantId, FleetMemberType type, CampaignFleetAPI fleet) Adds a fully crewed, fully combat ready ship to the designated fleet.static boolean
areAtRep
(SectorEntityToken token1, SectorEntityToken token2, CampaignUtils.IncludeRep include, RepLevel rep) Checks if two campaign objects have a specific reputation with each other.static boolean
areSameFaction
(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 aSectorEntityToken
in that token's location, excluding itself.static List<CampaignFleetAPI>
Find all hostile fleets towards aSectorEntityToken
present 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 CampaignFleetAPI
Find the closest hostile fleet to aSectorEntityToken
.static float
getRelation
(SectorEntityToken token1, SectorEntityToken token2) Returns the faction relationship between two campaign objects.static RepLevel
getReputation
(SectorEntityToken token1, SectorEntityToken token2) Returns the faction relationship between two campaign objects.static boolean
isPlayer
(CampaignFleetAPI fleet) Checks if a fleet is the player fleet.static boolean
isShipInFleet
(String fleetMemberId, CampaignFleetAPI fleet) Checks if a fleet contains a specific ship in its roster.static Vector2f
toScreenCoordinates
(Vector2f worldCoordinates) Converts worldspace coordinates to screen coordinates.static Vector2f
toWorldCoordinates
(Vector2f screenCoordinates) Converts screenspace coordinates to world coordinates.
-
Method Details
-
isPlayer
Checks if a fleet is the player fleet.- Parameters:
fleet
- TheCampaignFleetAPI
to be checked.- Returns:
true
iffleet
is the player fleet,false
otherwise.- Since:
- 1.0
-
toWorldCoordinates
Converts screenspace coordinates to world coordinates.- Parameters:
screenCoordinates
- The screenspace coordinates to convert.- Returns:
screenCoordinates
converted to world coordinates.- Since:
- 2.3
-
toScreenCoordinates
Converts worldspace coordinates to screen coordinates.- Parameters:
worldCoordinates
- The worldspace coordinates to convert.- Returns:
worldCoordinates
converted 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
- ASectorEntityToken
whose faction relationship will be tested.token2
- TheSectorEntityToken
to test relationship with.- Returns:
- The faction relationship between
token1
andtoken2
. - 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
- ASectorEntityToken
whose faction reputation will be tested.token2
- TheSectorEntityToken
to test reputation with.- Returns:
- The faction reputation between
token1
andtoken2
. - Since:
- 2.0
-
areSameFaction
Checks if two campaign objects are owned by the same faction.- Parameters:
token1
- The firstSectorEntityToken
to check.token2
- The secondSectorEntityToken
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 firstSectorEntityToken
to check.token2
- The secondSectorEntityToken
to check.include
- What relative range of reputations to include.rep
- The base reputation leveltoken1
and {token2} must be at with each other for this to returntrue
, modified byinclude
.- Returns:
true
if both tokens share a faction,false
otherwise.- 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:
true
iffleet
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
Find the closest hostile fleet to aSectorEntityToken
.- Parameters:
token
- TheSectorEntityToken
to search around.- Returns:
- The hostile
CampaignFleetAPI
closest totoken
, ornull
if 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 aroundtoken
to search.- Returns:
- A
List
containing all fleets within range that are hostile towardstoken
and can be seen by it. - Since:
- 1.2
-
getHostileFleetsInSystem
Find all hostile fleets towards aSectorEntityToken
present in that token's location.- Parameters:
token
- TheSectorEntityToken
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 aSectorEntityToken
, excluding itself.- Parameters:
token
- TheSectorEntityToken
to search around.entityTag
- The tag we should be searching for; for example:Tags.STATION
orTags.JUMP_POINT
.- Returns:
- The object with tag
entityTag
closest totoken
, ornull
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 aSectorEntityToken
, excluding itself.- Parameters:
token
- TheSectorEntityToken
to search around.range
- How far aroundtoken
to search.entityTag
- The tag we should be searching for; for example:Tags.STATION
orTags.JUMP_POINT
.- Returns:
- All objects with tag
entityTag
within 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
- TheSectorEntityToken
to search around.entityTag
- The tag we should be searching for; for example:Tags.STATION
orTags.JUMP_POINT
.faction
- The faction ownership we are looking for.- Returns:
- The object with tag
entityTag
closest totoken
that is owned byfaction
, ornull
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 aSectorEntityToken
, excluding itself.- Parameters:
token
- TheSectorEntityToken
to search around.range
- How far aroundtoken
to search.entityTag
- The tag we should be searching for; for example:Tags.STATION
orTags.JUMP_POINT
.faction
- What faction the entity must be owned by.- Returns:
- All objects with tag
entityTag
and factionfaction
within 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
- TheLocationAPI
to search in.entityTag
- The tag we should be searching for; for example:Tags.STATION
orTags.JUMP_POINT
.faction
- What faction entities must belong to.- Returns:
- All objects of faction
faction
and with tagentityTag
withinlocation
. - 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
- TheSectorEntityToken
to search around.entityTag
- The tag we should be searching for; for example:Tags.STATION
orTags.JUMP_POINT
.include
- What range ofRepLevel
s to accept, relative torep
.rep
- The base reputation to check against.- Returns:
- The object with tag
entityTag
closest totoken
within the reputation range specified byinclude
andrep
, ornull
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 aSectorEntityToken
, excluding itself.- Parameters:
token
- TheSectorEntityToken
to search around.range
- How far aroundtoken
to search.entityTag
- The tag we should be searching for; for example:Tags.STATION
orTags.JUMP_POINT
.include
- What range ofRepLevel
s to accept, relative torep
.rep
- The base reputation to check against.- Returns:
- All objects with tag
entityTag
within 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 aSectorEntityToken
in that token's location, excluding itself.- Parameters:
token
- TheSectorEntityToken
to search around.entityTag
- The tag we should be searching for; for example:Tags.STATION
orTags.JUMP_POINT
.include
- What range ofRepLevel
s to accept, relative torep
.rep
- The base reputation to check against.- Returns:
- All objects with tag
entityTag
within 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 aroundtoken
to search.- Returns:
- A
List
containing all fleets within range thattoken
can see, excluding itself if it is aCampaignFleetAPI
. - Since:
- 1.7
-