Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.96a is out! (05/05/23); Blog post: Colony Crises (11/24/23)

Author Topic: [0.9.1a] Hullmod Guide  (Read 3033 times)

PureTilt

  • Lieutenant
  • **
  • Posts: 53
    • View Profile
[0.9.1a] Hullmod Guide
« on: October 19, 2020, 09:00:04 AM »

Overview of hullmod.csv

Spoiler
name,
Name displayed in game

id,
ID for game, should be unique, it's recommended to add a prefix of some kind to avoid issues with a lot of mods enabled

tier,
This partly controls the store availability of the hullmod. Normal values range between 0-3 with a special case at 5. Tier 0 are ubiquitous & can be bought on the open market; anything higher requires a progressively higher relationship with the faction for purchase on a military submarket. Tier >=5 cannot appear in markets for purchase at all.

rarity,
Between 0 and 1 with higher being rarer.

tags,
mostly for autofit, req_spaceport makes hullmod require functioning spaceport to be able to put it onto a ship

uiTags,
Hullmod tags for refit screen
Look at vanilla's hullmods.csv for tags used by existing hullmods

base value,
Base price in credits

unlocked,
Controls if hullmod is unlock by player by default

hidden,
If TRUE, hullmod cannot be obtained by player

hiddenEverywhere,
If TRUE, hullmod cannot be obtained by player and isn't visible on ships

tech/manufacturer,
If left empty, its design type will be Common, just like all vanilla hullmods, if you type in something here, hullmod will appear in new tab in refit screen

cost_frigate,
cost_dest,
cost_cruiser,
cost_capital,
OP cost per ship size

script,
Path to hullmod's script

desc,
Description you see in-game

short,
Short description not used in game

sprite
Path to hullmod's icon
[close]
For this part you need to have already installed and setup an IDE and have CSV editor like Ron's Editor (Excel's default settings break Starsector's CSV files), without IDE you need to write imports yourself and you can't use some of hullmod's functionality.
All example code taken from More Hullmods

Copy any vanilla hullmod for basic structure and imports
Main methods:
Spoiler
applyEffectsBeforeShipCreation
It's used to change mutable stats of a ship (link stats list)

advanceInCombat
It's used on hullmods that do something in combat layer

advanceInCampaign
It's used on hullmods that do something in campaign layer

getDescriptionParam
It's used to import values to description, imported values get highlighted

isApplicableToShip
Used to set incompability with other hullmods and ships

getUnapplicableReason
Allows you to write why you can't put this hullmod on this ship
[close]
examples:
Spoiler
Basic hullmod:
Spoiler

package:   path to scripts folder
imports:   stuff needed for script to work
Name of class should be same as file name of the script

example use of applyEffectsBeforeShipCreation method:

   public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
      stats.getProjectileSpeedMult().modifyPercent(id , SpeedBonus);
   }
[close]
Descriptions:
Spoiler
Description in hullmods.csv file:
Reduces ballistic weapon flux generated by %s. Reduces ballistic weapon damage by %s.
%s is used to import values from script

   public String getDescriptionParam(int index, HullSize hullSize) {
        if (index == 0) return Math.round((1f - FluxUsage) * 100) + "%";
      if (index == 1) return Math.round((1f - ROF) * 100) + "%";
        return null;
    }
Index equals order of %s so first %s = 0 first %s = 1 second %s = 2 etc
Description in game:
[close]
applyEffectsAfterShipCreation:
Spoiler
Allow you to check ship's stats and change hullmod behavior depending on it:

    public void applyEffectsAfterShipCreation(ShipAPI ship, String id) {
        if (ship.getArmorGrid().getArmorRating() * MinArmor > maxminarmor.get(ship.getHullSize())){
            ship.getMutableStats().getMinArmorFraction().modifyFlat(id,maxminarmor.get(ship.getHullSize()) / ship.getArmorGrid().getArmorRating());
        }else {
            ship.getMutableStats().getMinArmorFraction().modifyFlat(id,MinArmor);
        }
    }
[close]
advanceInCombat:
Spoiler
For hullmods that do something in combat

This increases weapon rate of fire depending on flux level

   public void advanceInCombat(ShipAPI ship, float amount){
      if (!ship.isAlive()) return;
      ship.getMutableStats().getBallisticRoFMult().modifyPercent("Overcharged", ATKSpeedBonus * ship.getFluxLevel());
      ship.getMutableStats().getEnergyRoFMult().modifyPercent("Overcharged", ATKSpeedBonus * ship.getFluxLevel());
      if (ship == Global.getCombatEngine().getPlayerShip())
         Global.getCombatEngine().maintainStatusForPlayerShip("MHMods_FluxOverdrive", "graphics/icons/hullsys/ammo_feeder.png", "Overcharge boost", Math.round(ATKSpeedBonus * ship.getFluxLevel()) + "%", false);
   }
maintainStatusForPlayerShip in combat:
[close]
Transfering data between frames:
Spoiler
For when you have to store data in combat layer.
All ships share same instance of hullmod, so they have same variables, which means that if hullmod changes variable while processing one ship, it's going to affect every ship with this hullmod currently deployed in combat. If you want to prevent this behavior you have to store data with following method.

   public void advanceInCombat(ShipAPI ship, float amount){
   
      Map<String, Object> customCombatData = Global.getCombatEngine().getCustomData();
      
      float ShieldStart = 0f;      
      if (customCombatData.get("MHMods_ShieldStart" + ship.getId()) instanceof Float)
         ShieldStart = (float) customCombatData.getCustomData().get("MHMods_ShieldStart" + ship.getId());
         
      [do what you need with stuff]
      
      customCombatData.put("MHMods_ShieldStart" + ship.getId(), ShieldStart)      
   }
[close]
Preventing a hullmod from being put if conditions are met:
Spoiler
If conditions are met, hullmod can't be put on the ship

Disallow hullmod if ship already has Safety Overrides hullmod on it
   public boolean isApplicableToShip(ShipAPI ship) {
      return ship != null &&
         (!ship.getVariant().getHullMods().contains("safetyoverrides"));
   }

This shows text if conditions are met (ADD PIC)
   public String getUnapplicableReason(ShipAPI ship) {
      if (ship.getVariant().hasHullMod("safetyoverrides"))
         return "Incompatible with Safety Overrides";
      return null;
   }

How to prevent hullmod from being put on ship without a shield
   public boolean isApplicableToShip(ShipAPI ship) {
      return ship != null && ship.getShield() != null;
   }

And explaination for ship that has no shield (ADD PIC)
   public String getUnapplicableReason(ShipAPI ship) {
      if ((ship.getShield() == null))
         return "Ship Has No Shield";
      return null;
   }
[close]
Logistic hullmods
Spoiler
To make hullmod make properly count as logistic you need to:

Make hullmod class extend BaseLogisticsHullMod instead of BaseHullMod.

and add Logistics to uiTags in hull_mods.csv
[close]
[close]
« Last Edit: October 22, 2021, 02:08:56 AM by PureTilt »
Logged




Hatter

  • Commander
  • ***
  • Posts: 219
    • View Profile
Re: [0.9.1a] Hullmod Guide
« Reply #1 on: March 30, 2021, 06:59:58 PM »

How much of this is still applicable in 0.95a?
Logged

PureTilt

  • Lieutenant
  • **
  • Posts: 53
    • View Profile
Re: [0.9.1a] Hullmod Guide
« Reply #2 on: May 12, 2021, 11:54:23 AM »

How much of this is still applicable in 0.95a?

0.95a just add some new thing but didn't changed anything for Hmods so its satill applicable
Logged