Hey all,
I'm glad to be returning to Starsector after some absence and find good progress has been made.
To get to the point, I've been trying to port a mod of mine from an older version.
Problem #1 - Solved, see posts following of Alex and mine if looking for a solution to a problem of runtime null reference exceptions pointing to renderWeapons.When my mod is enabled, I get a null reference error at a seemingly unpredictable time. As far as I can tell, the stack trace doesn't lead to anything of much use as I've searched for renderWeapons in the API but couldn't find anything.
Spoiler
...
java.lang.NullPointerException
at com.fs.starfarer.campaign.fleet.CampaignFleetMemberView.renderWeapons(Unknown Source)
at com.fs.starfarer.campaign.fleet.CampaignFleetMemberView.renderSingle(Unknown Source)
at com.fs.starfarer.campaign.fleet.CampaignFleetMemberView.render(Unknown Source)
at com.fs.starfarer.campaign.fleet.CampaignFleetView.render(Unknown Source)
at com.fs.starfarer.campaign.fleet.CampaignFleet.render(Unknown Source)
at com.fs.starfarer.campaign.BaseCampaignEntity.render(Unknown Source)
at com.fs.graphics.LayeredRenderer.render(Unknown Source)
at com.fs.starfarer.campaign.BaseLocation.render(Unknown Source)
at com.fs.starfarer.campaign.CampaignEngine.render(Unknown Source)
at com.fs.starfarer.campaign.CampaignState.render(Unknown Source)
at com.fs.starfarer.BaseGameState.traverse(Unknown Source)
at com.fs.state.AppDriver.begin(Unknown Source)
at com.fs.starfarer.combat.CombatMain.main(Unknown Source)
at com.fs.starfarer.StarfarerLauncher$2.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I do have weapons in my mod, so I can only guess it's something to do with that causing the problem, but I don't know where to start with finding the culprit due to a lack of information.
Having checked my weapons list in the codex, I can find a couple of possible culprits:
• I have a weapon that is almost a copy of the Dual Flak Cannon, with some stat differences. It has a unique ID but the name is the same. If the game identifies weapons by name alone at any point, this may be the cause of the problem.
• The sprite paths for a built-in weapon which doesn't need a sprite are set as "" (empty double quotes).
Problem #2 - Solved once again with the help of Alex! To add to a stations' cargo, you now have to do, for example: .getMarket().getSubmarket("generic_military").getCargo(), then add the ships as normal with e.g.; addMothballedShipsOriginally, ships which are added by my mod were delivered to a custom station which was inserted into Corvus along with a race to fulfil this. At some point, it seems there were big changes to the way delivering ships to stations in the campaign works, which makes sense, considering how complex the markets are and the size of the game world now. However, I cannot get this to work anymore. In fact, I cannot even get my ships to be added to the station inventory at the start of the game. Here's what my code is at the moment:
Spoiler
public class ShipPackSectorGen implements SectorGeneratorPlugin
{
public void generate(SectorAPI sector)
{
StarSystemAPI system = sector.getStarSystem("Corvus");
SectorEntityToken centre = system.createToken(0, 0);
CargoAPI cargo;
SectorEntityToken station = system.addCustomEntity("trade_shipyard",
"Trade Shipyard", "station_jangala_type", "shippackfaction");
station.setCircularOrbitPointingDown(centre, 55, 4750, 100);
station.setCustomDescriptionId("station_jangala");
SectorEntityToken convoyLocation = system.createToken(5000,5000);
MarketAPI market = Global.getFactory().createMarket("corvus_shippack_market", station.getName(), 0);
market.setPrimaryEntity(station);
market.setFactionId(station.getFaction().getId());
market.addSubmarket(Submarkets.SUBMARKET_OPEN);
station.setMarket(market);
cargo = station.getCargo();
int shipQuantity = 48;
SelectShips(cargo,randomDecentShips,shipQuantity);
...
}
private void SelectShips(CargoAPI cargo, String inShipsList[], int inShipQuantity)
{
for (int i=0; i < inShipQuantity; i++)
{
String selectedShipName = inShipsList[(int) (inShipsList.length*Math.random())];
cargo.getMothballedShips().addFleetMember(Global.getFactory().createFleetMember
(FleetMemberType.SHIP, selectedShipName));
//Deprecated?
//cargo.addMothballedShip(FleetMemberType.SHIP,inShipsList[(int)
(inShipsList.length*Math.random())],null);
}
}
private static String [] randomDecentShips =
{
//Contains about 10 ship hull names which all belong to the mod in question
};
}
What I'd like to know is if I could at least get ships to be in the inventory at the start of the game, fully understanding there's no gaurantee other fleets won't take them all before the player has a chance. What would be even better is if I could get a delivery fleet to work as before, and if that is possible I'll include the code for that as well.