I didn't find anything after fiddling around a bit, and neither did I find an answer with the search function, so it's "ask someone who has a clue"-time:
I am trying to make a hull mod that buffs various aspects of a ship depending on the number of crew aboard. My problem is, I don't know how to get the current number of crew on a given ship to determine the bonus.
So far, I have tried to get the CrewFraction from the FleetMemberAPI, and multiplying the fraction by the minimum crew to get the total. However, my call to ship.getMember() always returns null. Is the FleetMemberAPI only available in combat? If so, is there any way to get the actual number of crew on a specific ship for use in a hull mod?
my idea in code:
Spoiler
public float getCrew(ShipAPI ship) {
FleetMemberAPI memberAPI = ship.getFleetMember();
float crewFraction = memberAPI.getCrewFraction();
float neededCrew = memberAPI.getMinCrew();
float totalCrew = neededCrew * crewFraction;
return totalCrew;
}
My second guess is, that CrewCompositionAPI.getCrew() would also do what I want, but again, I have not found a way to access it.
edit: This does actually work, but seems to be a convoluted and not very fool-proof way. Duplicate names would cause a problem.
Spoiler
public float getCrew(ShipAPI ship) {
logger.info(ship);
FleetMemberAPI memberAPI = ship.getFleetMember();
logger.info("first try: " + memberAPI);
List<FleetMemberAPI> ships = Global.getSector().getPlayerFleet().getFleetData().getMembersListCopy();
for (FleetMemberAPI fleetShip : ships){
logger.info(fleetShip);
if (fleetShip.getShipName().equals(ship.getName())) {
memberAPI = fleetShip;
logger.info("found match");
}
}
logger.info("second try: " + memberAPI);
currentMember = memberAPI;
float crewFraction = memberAPI.getCrewFraction();
float neededCrew = memberAPI.getMinCrew();
float totalCrew = neededCrew * crewFraction;
crew = totalCrew;
return totalCrew;
}