Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: Can you restrict a hullmod to a specific ship type or class?  (Read 1210 times)

rogerbacon

  • Commander
  • ***
  • Posts: 142
    • View Profile
Can you restrict a hullmod to a specific ship type or class?
« on: December 28, 2015, 06:28:34 AM »

So in Starfleet Battles the Romulans have a light cruiser called the SparrowHawk class. It's a modular cruiser with different modules for different tasks. I was thinking of implementing the various modules as exclusive hullmods and I was wondering if there was a way to restrict those mods to just that class of ship and also a way to make them exclusive to each other.
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: Can you restrict a hullmod to a specific ship type or class?
« Reply #1 on: December 28, 2015, 06:46:51 AM »

Example adapted from IntegratedTargetingUnit.java

Code: java
	@Override
public boolean isApplicableToShip(ShipAPI ship) {
return !ship.getVariant().getHullMods().contains("dedicated_targeting_core");
// you can also do other checks you need
// e.g. for hull ID: if (!ship.getHullSpec().getHullId().equals("my_special_hull")) return false;
}

(If you want to have one of your own hullmods block a vanilla mod or another mod's, it's a little harder. You basically have to remove the mod once it's installed.)
Spoiler
Code: java
    private static final Set<String> BLOCKED_HULLMODS = new HashSet<>();
   
    static
    {
        // These hullmods will automatically be removed
        // Not as elegant as blocking them in the first place, but
        // this method doesn't require editing every hullmod's script
        BLOCKED_HULLMODS.add("adaptiveshields");
        BLOCKED_HULLMODS.add("extendedshieldemitter");
    }

    @Override
    public void applyEffectsAfterShipCreation(ShipAPI ship, String id)
    {
        for (String tmp : BLOCKED_HULLMODS)
        {
            if (ship.getVariant().hasHullMod(tmp))
            {
                ship.getVariant().removeMod(tmp);
            }
        }
    }
[close]
Logged