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: New music for Galatia Academy (06/12/24)

Author Topic: How to create a hullmod that provides benefit based on hull size  (Read 631 times)

rogerbacon

  • Commander
  • ***
  • Posts: 151
    • View Profile
How to create a hullmod that provides benefit based on hull size
« on: December 08, 2022, 03:44:44 PM »

I want to create a hull mode that reduces the fuel used by small ships. I assume I do that in applyEffectsAfterShipCreation() like many examples I've seen. However, I need a reference to the shipAPI for the ship the mod is going on, right? How do I get that?
Once I have it I think I can use ship.getMutableStats().getFuelUseMod().modifyFlat(id, -1f); to do what I want.

Thanks in advance for any help.
Logged

Ruddygreat

  • Admiral
  • *****
  • Posts: 544
  • Seals :^)
    • View Profile
Re: How to create a hullmod that provides benefit based on hull size
« Reply #1 on: December 08, 2022, 04:20:25 PM »

look at other hullmods that do the same thing (esp. in vanilla)

you'll want to extend BaseHullMod, then applyEffectsAfterShipCreation() provides a shipAPI that you can do stat mods to
though you'll probably want to do it in applyEffectsBeforeShipCreation(), then variant.getMutableStats, shipAPIs don't really exist in the campaign layer as far as I know

rogerbacon

  • Commander
  • ***
  • Posts: 151
    • View Profile
Re: How to create a hullmod that provides benefit based on hull size
« Reply #2 on: December 09, 2022, 12:14:06 PM »

I usually put my hull mods that affect mutableStats in applyEffectsBeforeShipCreation() and it works fine. I tried putting the one that is conditional on ship size in applyEffectsAfterShipCreation() because it has ShipAPI as  param but it didn't work.
What do you mean by variant.getMutableStats?

Edit
I added this:
public void applyEffectsAfterShipCreation(ShipAPI ship, String id) {
      if (ship.getHullSpec().getHullSize() < HullSize.DESTROYER)
      {
         ship.getMutableStats().getMinCrewMod().modifyMult(id, 0.0f);
         ship.getMutableStats().getSuppliesPerMonth().modifyMult(id, 0.0f);
      }
   }

and I get the error message "Operator '<' not allowed on reference operands."
HULLSIZE is an enum, right? Shouldn't that be the correct format?
« Last Edit: December 09, 2022, 12:24:43 PM by rogerbacon »
Logged

Amoebka

  • Admiral
  • *****
  • Posts: 1374
    • View Profile
Re: How to create a hullmod that provides benefit based on hull size
« Reply #3 on: December 09, 2022, 12:49:56 PM »

Shouldn't that be the correct format?
Negotiating with the compiler on what is or isn't correct is futile. Just rewrite it to a pair of "equals to".
Logged

Ruddygreat

  • Admiral
  • *****
  • Posts: 544
  • Seals :^)
    • View Profile
Re: How to create a hullmod that provides benefit based on hull size
« Reply #4 on: December 09, 2022, 05:20:44 PM »

What do you mean by variant.getMutableStats?

derp, it's been a while since I've worked with hullmods & I thought that they gave a variant instead of a direct mutableStats.

and yeah, you'll just want to do a switch case / check the ordinal values (ShipAPI.HullSize.FRIGATE.ordinal(); for instance) against eachother, you can't directly compare enums like that.