Hullmod code call-order

From Starsector Wiki
Jump to navigation Jump to search

This article is dedicated to down the specific order in which a hullmod's functions are called within the refit screen as accurately as possible, and any oddities that may follow due to this. Feel free to add to this page should you uncover any new information or a correction for previous information.

Call order

applyEffectsBeforeShipCreation() is the first function to be called on a hullmod. It is unsure which order hullmods call these in, but it's before any "ship" has been created; just before calling this function on all hullmods in some order, the engine creates a MutableShipStatsAPI, which it passes into all the applyEffectsBeforeShipCreation() calls. It also saves a HullSize, which the stats can access, but which cannot be modified, depending on the hullsize the ship will later have.

All the hullmods take turns to modify this MutableShipStatsAPI. It's really not recommended to check the stats during this call, since you don't know which hullmods are run after and before you, but it's theoretically possible.

Once this is done on all hullmods, the ship is actually generated; it gets the modified MutableShipStatsAPI passed in as a modifier against its HullSpecAPI, and combines the two for its actual stats. Some things are saved between two "creations" of a ship, such as hullmods, name, officer and CR, but that's stored in a different position (either MissionData[unsure about that one, someone might wanna double-check] or FleetMemberAPI). At this point, the ship's out-of-combat stats are locked, as is its stats on the Codex stat-card; changing them at a later time does not affect the campaign layer or the codex stat-card.

The next function to be called is applyEffectsAfterShipCreation(). It is called in a similar manner to the first one, but unlike applyEffectsBeforeShipCreation() it does not pass in a MutableShipStatsAPI(), but rather the ShipAPI itself. This ShipAPI is near-complete, and has all its variant information loaded in, meaning you can access which weapons and hullmods the ship has within applyEffectsAfterShipCreation(), and it is also possible to check the ship's modified stats.

However, since many of the ship's stats are already locked at this stage, stats should ideally not be modified in this function. Instead, effects within this function should ideally affect either weapon mounts, fighter bays or hullmods; this is where hullmod incompatibility between mods is most commonly implemented.

If any change is made to the ship's hullmods at this point, the ship will restart the entire creation process from the beginning (thus saving variant loadout data, removing the ShipAPI and going back to the beginning of the call-order). It may also do this for other variant-related changes, but this does not seem to happen when weapons are changed; the exact specifics of when it restarts have not yet been determined. Adding a random weapon to a slot each time the function is called does not create an infinite loop, but adding a random hullmod each function call might.

Icon cross.png
At least two versions out of date. Last verified for version 0.8.1a. Please refer to Version History and update this page.

---

Return to Modding