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: Hello, how would you edit or make a hull mod?  (Read 2734 times)

Eidon

  • Ensign
  • *
  • Posts: 2
    • View Profile
Hello, how would you edit or make a hull mod?
« on: January 16, 2020, 12:58:11 AM »

Hello, I am trying to guess how to edit a hull mod without any luck so I decided to make a account and ask for help here.
What I want is simple, I want to edit a existing hull mod or make a new edited duplicate of it. But google came up empty as the only information I could find was how to make a ship, so what i want is to make the converted hangar bay work without the debuffs and make it work on carrier class ships so that i can get one extra slot of fighters. I am not sure how simple or hard that will be, the java file got this code.

package data.hullmods;

import java.util.HashMap;
import java.util.Map;

import com.fs.starfarer.api.combat.BaseHullMod;
import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.combat.ShipAPI.HullSize;
import com.fs.starfarer.api.impl.campaign.ids.HullMods;
import com.fs.starfarer.api.impl.campaign.ids.Stats;
import com.fs.starfarer.api.impl.hullmods.DefectiveManufactory;

public class ConvertedHangar extends BaseHullMod {

   public static final int CREW_REQ = 20;
   //public static final int CARGO_REQ = 80;
   public static final int ALL_FIGHTER_COST_PERCENT = 50;
   public static final int BOMBER_COST_PERCENT = 100;
   
   private static Map mag = new HashMap();
   static {
      mag.put(HullSize.FRIGATE, 0f);
      mag.put(HullSize.DESTROYER, 75f);
      mag.put(HullSize.CRUISER, 50f);
      mag.put(HullSize.CAPITAL_SHIP, 25f);
   }
   
   public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
      //stats.getFighterRefitTimeMult().modifyPercent(id, ((Float) mag.get(hullSize)));
      stats.getNumFighterBays().modifyFlat(id, 1f);

      stats.getMinCrewMod().modifyFlat(id, CREW_REQ);
      //stats.getDynamic().getMod(Stats.ALL_FIGHTER_COST_MOD).modifyPercent(id, ALL_FIGHTER_COST_PERCENT);
      stats.getDynamic().getMod(Stats.BOMBER_COST_MOD).modifyPercent(id, BOMBER_COST_PERCENT);
      stats.getDynamic().getMod(Stats.FIGHTER_COST_MOD).modifyPercent(id, ALL_FIGHTER_COST_PERCENT);
      stats.getDynamic().getMod(Stats.INTERCEPTOR_COST_MOD).modifyPercent(id, ALL_FIGHTER_COST_PERCENT);
      stats.getDynamic().getMod(Stats.SUPPORT_COST_MOD).modifyPercent(id, ALL_FIGHTER_COST_PERCENT);
      //stats.getCargoMod().modifyFlat(id, -CARGO_REQ);
   }
   
   public boolean isApplicableToShip(ShipAPI ship) {
      //if (ship.getMutableStats().getCargoMod().computeEffective(ship.getHullSpec().getCargo()) < CARGO_REQ) return false;
      
      return ship != null && !ship.isFrigate() && ship.getHullSpec().getFighterBays() <= 0 &&
                        //ship.getNumFighterBays() <= 0 &&
                        !ship.getVariant().hasHullMod(HullMods.CONVERTED_BAY) &&
                        !ship.getVariant().hasHullMod(HullMods.PHASE_FIELD);
                        //ship.getHullSpec().getShieldType() != ShieldType.PHASE;      
   }
   
   public String getUnapplicableReason(ShipAPI ship) {
      if (ship != null && ship.isFrigate()) return "Can not be installed on a frigate";
      if (ship != null && ship.getHullSpec().getFighterBays() > 0) return "Ship has standard fighter bays";
      if (ship != null && ship.getVariant().hasHullMod(HullMods.CONVERTED_BAY)) return "Ship has fighter bays";
      //if (ship != null && ship.getNumFighterBays() > 0) return "Ship has fighter bays";
      return "Can not be installed on a phase ship";
   }
   
   public void applyEffectsToFighterSpawnedByShip(ShipAPI fighter, ShipAPI ship, String id) {
      new DefectiveManufactory().applyEffectsToFighterSpawnedByShip(fighter, ship, id);
   }
   
   public String getDescriptionParam(int index, HullSize hullSize, ShipAPI ship) {
      if (index == 2) return "" + CREW_REQ;
      if (index == 3) return "" + BOMBER_COST_PERCENT + "%";
      if (index == 4) return "" + ALL_FIGHTER_COST_PERCENT + "%";
      return new DefectiveManufactory().getDescriptionParam(index, hullSize, ship);
//      if (index == 0) return "" + ((Float) mag.get(HullSize.DESTROYER)).intValue() + "%";
//      if (index == 1) return "" + ((Float) mag.get(HullSize.CRUISER)).intValue() + "%";
//      if (index == 2) return "" + ((Float) mag.get(HullSize.CAPITAL_SHIP)).intValue() + "%";
//      if (index == 3) return "" + CREW_REQ;
//      return null;
      //if (index == 0) return "" + ((Float) mag.get(hullSize)).intValue();
      //return null;
   }
   
   @Override
   public boolean affectsOPCosts() {
      return true;
   }
}



Logged

AxleMC131

  • Admiral
  • *****
  • Posts: 1722
  • Amateur World-Builder
    • View Profile
Re: Hello, how would you edit or make a hull mod?
« Reply #1 on: January 16, 2020, 01:45:22 AM »

what i want is to make the converted hangar bay work without the debuffs...

Easy enough. Not all the game's hullmod scripts (the code files) are accessible to be changed with ease, but Converted Hangar is one of them so you don't have to do anything silly with an IDE.

I'mma quickly put together an annotated (commented) version of the file for you to take a look at - don't have the time for a full tutorial right now, but it'll help you get started.

EDIT: Here, try this on for size. https://bitbucket.org/AxleMC131/starsector_modding/downloads/ConvertedHangar_Annotated.java

Spoiler

Quote
package data.hullmods;   // Location where this file is.

// "import" grabs functions and methods (chunks of code that do stuff) from other files.
import java.util.HashMap;
import java.util.Map;

import com.fs.starfarer.api.combat.BaseHullMod;
import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.combat.ShipAPI.HullSize;
import com.fs.starfarer.api.impl.campaign.ids.HullMods;
import com.fs.starfarer.api.impl.campaign.ids.Stats;
import com.fs.starfarer.api.impl.hullmods.DefectiveManufactory;

// The actual hullmod script starts here.
// The new class being created, "ConvertedHangar", extends an existing class called "BaseHullMod", which is basically a template.
// All we're doing is taking that template and adding specifics, like particular stats to change and values to insert.
// The new class carries all the same code as the template class, and adds everything in this file.
// We don't need to worry about the ins-and-outs of classes and extensions and such right now, but it's worth knowing what this line means.
public class ConvertedHangar extends BaseHullMod {

   // Now we can define some variable values. Do you remember learning algebra in school, where letters like a, b, x and y correspond to numbers?
   // Same thing going on here. The bits in all-caps are the variable name, and the numbers after them are the number assigned to that variable.

   public static final int CREW_REQ = 20;   // Increase in minimum crew requirement
   public static final int ALL_FIGHTER_COST_PERCENT = 50;   // Increase in OP cost for fighters (that aren't bombers)
   public static final int BOMBER_COST_PERCENT = 100;   // Increase in OP cost for bombers
   
   private static Map mag = new HashMap();   // Increase in fighter rebuild time - a different value for each hull size!
   static {
      mag.put(HullSize.FRIGATE, 0f);
      mag.put(HullSize.DESTROYER, 75f);
      mag.put(HullSize.CRUISER, 50f);
      mag.put(HullSize.CAPITAL_SHIP, 25f);
   }
   
   // These effects are the actual "meat" of the hullmod, and carry the primary stat buffs/debuffs to the ship.
   public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
      stats.getNumFighterBays().modifyFlat(id, 1f);   // Adds one fighter bay to the ship

      stats.getMinCrewMod().modifyFlat(id, CREW_REQ);   // Increases the minimum crew required by the value we gave it earlier
      
      // Increases the OP cost of fighter wings (bombers and other types) by the values we gave them earlier
      stats.getDynamic().getMod(Stats.BOMBER_COST_MOD).modifyPercent(id, BOMBER_COST_PERCENT);
      stats.getDynamic().getMod(Stats.FIGHTER_COST_MOD).modifyPercent(id, ALL_FIGHTER_COST_PERCENT);
      stats.getDynamic().getMod(Stats.INTERCEPTOR_COST_MOD).modifyPercent(id, ALL_FIGHTER_COST_PERCENT);
      stats.getDynamic().getMod(Stats.SUPPORT_COST_MOD).modifyPercent(id, ALL_FIGHTER_COST_PERCENT);
   }
   
   // A series of conditions that a ship must fulfill in order to be able to mount this hullmod.
   public boolean isApplicableToShip(ShipAPI ship) {
      return ship != null && !ship.isFrigate() && ship.getHullSpec().getFighterBays() <= 0 &&
                        !ship.getVariant().hasHullMod(HullMods.CONVERTED_BAY) &&
                        !ship.getVariant().hasHullMod(HullMods.PHASE_FIELD);   
      // Specifically, the conditions are:
      // - The ship is not null (important for code stuff, sometimes things don't exist)
      // - The ship is NOT a frigate
      // - The ship has LESS THAN or EQUAL TO zero fighter bays already
      // - The ship does NOT already have Converted Hangar installed
      // - The ship does NOT have the Phase Field hullmod (ie. the ship is not a phase ship)
   }
   
   // These different strings ("text") display to the player WHY the hullmod is incompatible, if one of the above conditions is not met.
   public String getUnapplicableReason(ShipAPI ship) {
      if (ship != null && ship.isFrigate()) return "Can not be installed on a frigate";
      if (ship != null && ship.getHullSpec().getFighterBays() > 0) return "Ship has standard fighter bays";
      if (ship != null && ship.getVariant().hasHullMod(HullMods.CONVERTED_BAY)) return "Ship has fighter bays";
      return "Can not be installed on a phase ship";
   }
   
   // This bit makes launched fighters appear damaged and have reduced stats.
   public void applyEffectsToFighterSpawnedByShip(ShipAPI fighter, ShipAPI ship, String id) {
      new DefectiveManufactory().applyEffectsToFighterSpawnedByShip(fighter, ship, id);
   }
   
   // Snippets of text which are grabbed by the description of the hullmod, so you don't have to change the numbers in it everytime you
   // change them here.
   public String getDescriptionParam(int index, HullSize hullSize, ShipAPI ship) {
      if (index == 2) return "" + CREW_REQ;
      if (index == 3) return "" + BOMBER_COST_PERCENT + "%";
      if (index == 4) return "" + ALL_FIGHTER_COST_PERCENT + "%";
      return new DefectiveManufactory().getDescriptionParam(index, hullSize, ship);
   }
   
   // This should be self-explanatory. :P Regardless...
   // "Does this hullmod affect the Ordnance Point cost of things?"
   // "Yes."
   @Override
   public boolean affectsOPCosts() {
      return true;
   }
}

[close]
« Last Edit: January 16, 2020, 01:58:16 AM by AxleMC131 »
Logged

Eidon

  • Ensign
  • *
  • Posts: 2
    • View Profile
Re: Hello, how would you edit or make a hull mod?
« Reply #2 on: January 16, 2020, 09:53:05 AM »

what i want is to make the converted hangar bay work without the debuffs...

Easy enough. Not all the game's hullmod scripts (the code files) are accessible to be changed with ease, but Converted Hangar is one of them so you don't have to do anything silly with an IDE.

I'mma quickly put together an annotated (commented) version of the file for you to take a look at - don't have the time for a full tutorial right now, but it'll help you get started.

EDIT: Here, try this on for size. https://bitbucket.org/AxleMC131/starsector_modding/downloads/ConvertedHangar_Annotated.java

Spoiler

Quote
package data.hullmods;   // Location where this file is.

// "import" grabs functions and methods (chunks of code that do stuff) from other files.
import java.util.HashMap;
import java.util.Map;

import com.fs.starfarer.api.combat.BaseHullMod;
import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.combat.ShipAPI.HullSize;
import com.fs.starfarer.api.impl.campaign.ids.HullMods;
import com.fs.starfarer.api.impl.campaign.ids.Stats;
import com.fs.starfarer.api.impl.hullmods.DefectiveManufactory;

// The actual hullmod script starts here.
// The new class being created, "ConvertedHangar", extends an existing class called "BaseHullMod", which is basically a template.
// All we're doing is taking that template and adding specifics, like particular stats to change and values to insert.
// The new class carries all the same code as the template class, and adds everything in this file.
// We don't need to worry about the ins-and-outs of classes and extensions and such right now, but it's worth knowing what this line means.
public class ConvertedHangar extends BaseHullMod {

   // Now we can define some variable values. Do you remember learning algebra in school, where letters like a, b, x and y correspond to numbers?
   // Same thing going on here. The bits in all-caps are the variable name, and the numbers after them are the number assigned to that variable.

   public static final int CREW_REQ = 20;   // Increase in minimum crew requirement
   public static final int ALL_FIGHTER_COST_PERCENT = 50;   // Increase in OP cost for fighters (that aren't bombers)
   public static final int BOMBER_COST_PERCENT = 100;   // Increase in OP cost for bombers
   
   private static Map mag = new HashMap();   // Increase in fighter rebuild time - a different value for each hull size!
   static {
      mag.put(HullSize.FRIGATE, 0f);
      mag.put(HullSize.DESTROYER, 75f);
      mag.put(HullSize.CRUISER, 50f);
      mag.put(HullSize.CAPITAL_SHIP, 25f);
   }
   
   // These effects are the actual "meat" of the hullmod, and carry the primary stat buffs/debuffs to the ship.
   public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
      stats.getNumFighterBays().modifyFlat(id, 1f);   // Adds one fighter bay to the ship

      stats.getMinCrewMod().modifyFlat(id, CREW_REQ);   // Increases the minimum crew required by the value we gave it earlier
      
      // Increases the OP cost of fighter wings (bombers and other types) by the values we gave them earlier
      stats.getDynamic().getMod(Stats.BOMBER_COST_MOD).modifyPercent(id, BOMBER_COST_PERCENT);
      stats.getDynamic().getMod(Stats.FIGHTER_COST_MOD).modifyPercent(id, ALL_FIGHTER_COST_PERCENT);
      stats.getDynamic().getMod(Stats.INTERCEPTOR_COST_MOD).modifyPercent(id, ALL_FIGHTER_COST_PERCENT);
      stats.getDynamic().getMod(Stats.SUPPORT_COST_MOD).modifyPercent(id, ALL_FIGHTER_COST_PERCENT);
   }
   
   // A series of conditions that a ship must fulfill in order to be able to mount this hullmod.
   public boolean isApplicableToShip(ShipAPI ship) {
      return ship != null && !ship.isFrigate() && ship.getHullSpec().getFighterBays() <= 0 &&
                        !ship.getVariant().hasHullMod(HullMods.CONVERTED_BAY) &&
                        !ship.getVariant().hasHullMod(HullMods.PHASE_FIELD);   
      // Specifically, the conditions are:
      // - The ship is not null (important for code stuff, sometimes things don't exist)
      // - The ship is NOT a frigate
      // - The ship has LESS THAN or EQUAL TO zero fighter bays already
      // - The ship does NOT already have Converted Hangar installed
      // - The ship does NOT have the Phase Field hullmod (ie. the ship is not a phase ship)
   }
   
   // These different strings ("text") display to the player WHY the hullmod is incompatible, if one of the above conditions is not met.
   public String getUnapplicableReason(ShipAPI ship) {
      if (ship != null && ship.isFrigate()) return "Can not be installed on a frigate";
      if (ship != null && ship.getHullSpec().getFighterBays() > 0) return "Ship has standard fighter bays";
      if (ship != null && ship.getVariant().hasHullMod(HullMods.CONVERTED_BAY)) return "Ship has fighter bays";
      return "Can not be installed on a phase ship";
   }
   
   // This bit makes launched fighters appear damaged and have reduced stats.
   public void applyEffectsToFighterSpawnedByShip(ShipAPI fighter, ShipAPI ship, String id) {
      new DefectiveManufactory().applyEffectsToFighterSpawnedByShip(fighter, ship, id);
   }
   
   // Snippets of text which are grabbed by the description of the hullmod, so you don't have to change the numbers in it everytime you
   // change them here.
   public String getDescriptionParam(int index, HullSize hullSize, ShipAPI ship) {
      if (index == 2) return "" + CREW_REQ;
      if (index == 3) return "" + BOMBER_COST_PERCENT + "%";
      if (index == 4) return "" + ALL_FIGHTER_COST_PERCENT + "%";
      return new DefectiveManufactory().getDescriptionParam(index, hullSize, ship);
   }
   
   // This should be self-explanatory. :P Regardless...
   // "Does this hullmod affect the Ordnance Point cost of things?"
   // "Yes."
   @Override
   public boolean affectsOPCosts() {
      return true;
   }
}

[close]

Thanks for the help but not sure why but it still wont let me add it to carriers, I can increase the number of fighter bays I get on a ship and reduce the cost of those fighters and bombers tho and I guess that will just have to do for now.
« Last Edit: January 16, 2020, 10:27:12 AM by Eidon »
Logged

Rasip

  • Ensign
  • *
  • Posts: 32
    • View Profile
Re: Hello, how would you edit or make a hull mod?
« Reply #3 on: January 17, 2020, 04:25:54 PM »

That "ship.getHullSpec().getFighterBays() <= 0" is the part that tells it you can't add it to anything that already has fighterbays. Change the 0 to 6 and it should be addable to every carrier.
Logged