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 a Hullmod add a built-in wing automatically?  (Read 1621 times)

IonDragonX

  • Admiral
  • *****
  • Posts: 816
    • View Profile
Can a Hullmod add a built-in wing automatically?
« on: December 31, 2020, 12:45:30 PM »

Hi, guys. I would like to add a specific Fighter Wing to the Converted Hangar code.

This is the starsector-core code for Converted Hangar:
Spoiler
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;
   }
}
[close]

Could this be simple to mod? Will adding a line after " stats.getNumFighterBays().modifyFlat(id, 1f); " work? I think that

   ship.getVariant().setWingId(0, ssx_drone_pod_wing);

might work? Wouldn't it? The " ship.getVariant() " is already used in the original and " void setWingId(int index, String wingId); " is a function of ShipVariantAPI.

If it does work, then I might have follow up questions.
Logged

IonDragonX

  • Admiral
  • *****
  • Posts: 816
    • View Profile
Re: Can a Hullmod add a built-in wing automatically?
« Reply #1 on: January 01, 2021, 11:58:17 AM »

I have found that this code actually works:

Spoiler
import com.fs.starfarer.api.combat.ShipVariantAPI;
   public void applyEffectsAfterShipCreation(ShipAPI ship, String id) {
      ShipVariantAPI variant = ship.getVariant();
      variant.setWingId(0, "ssx_drone_pod_wing");
   }
[close]

That said, does anybody know how to lock the wing as if it was a Built-In Wing? The Refit window won't actually allow the player to change the wing but it teases you as if you can.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Can a Hullmod add a built-in wing automatically?
« Reply #2 on: January 01, 2021, 12:01:08 PM »

I don't think that's possible, no. I'm actually kind of surprised it doesn't let you change it! It's possible that if the player tries to install the wing, it's removed from their inventory and then overwritten by the hullmod (and thus lost completely). You might also get infinite wing LPCs by repeatedly removing the one the hullmod adds. At least, I wouldn't be surprised if this was the case.
Logged

IonDragonX

  • Admiral
  • *****
  • Posts: 816
    • View Profile
Re: Can a Hullmod add a built-in wing automatically?
« Reply #3 on: January 01, 2021, 02:42:05 PM »

You might also get infinite wing LPCs by repeatedly removing the one the hullmod adds. At least, I wouldn't be surprised if this was the case.
Sadly, correct. I had thought that I could get advice on adding a built-in wing instead of a regular wing. I know that a skin can do it but I'm trying to make it a hullmod.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Can a Hullmod add a built-in wing automatically?
« Reply #4 on: January 01, 2021, 02:52:19 PM »

Ah - unless I'm missing a creative workaround, I don't think this is possible.
Logged

Amazigh

  • Captain
  • ****
  • Posts: 284
    • View Profile
Re: Can a Hullmod add a built-in wing automatically?
« Reply #5 on: January 01, 2021, 03:55:50 PM »

Might want to check the Yuri Expedition Mod, and it's Drone Auxillary hullmod.
It adds a built-in fighter wing to a ship, but (i assume) is somewhat hacky, as it requires a reboot of the game after installing the hullmod to actually function correctly.
Logged

IonDragonX

  • Admiral
  • *****
  • Posts: 816
    • View Profile
Re: Can a Hullmod add a built-in wing automatically?
« Reply #6 on: January 01, 2021, 04:27:43 PM »

@Amazigh
Thanks, I'll investigate it.
EDIT: Whoa, that's too hacky for me. Its using " import org.apache.log4j.Logger " and has lots of commented out code in the hullmod.java.
« Last Edit: January 01, 2021, 04:44:15 PM by IonDragonX »
Logged

Thaago

  • Global Moderator
  • Admiral
  • *****
  • Posts: 7174
  • Harpoon Affectionado
    • View Profile
Re: Can a Hullmod add a built-in wing automatically?
« Reply #7 on: January 01, 2021, 05:33:14 PM »

Well that imported class is just a logger - it lets you output messages to the log easily for debugging! But needing to reboot for it to work... yeah thats pointing to some interesting workarounds happening!
Logged

IonDragonX

  • Admiral
  • *****
  • Posts: 816
    • View Profile
Re: Can a Hullmod add a built-in wing automatically?
« Reply #8 on: January 01, 2021, 10:34:57 PM »

Ah - unless I'm missing a creative workaround, I don't think this is possible.
Well, I found a generically OK way to stop the player from selecting any other wing. Now all I need is a way to take out the trash. In the CargoAPI, there is a function to addFighters() but is there a function to removeFighters() ?
Logged

IonDragonX

  • Admiral
  • *****
  • Posts: 816
    • View Profile
Re: Can a Hullmod add a built-in wing automatically?
« Reply #9 on: January 02, 2021, 06:54:34 PM »

Ah - unless I'm missing a creative workaround, I don't think this is possible.
Thank you for your help with this, Alex.  :D  I seem to have a mod that seems to "do what I want". Now to play a campaign before my nonsense glue-and-chicken-wire solution blows up on me.
Logged