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: Hullmod to decrease surveying crew (Solved)  (Read 1328 times)

Lightweaver

  • Ensign
  • *
  • Posts: 8
    • View Profile
Hullmod to decrease surveying crew (Solved)
« on: October 17, 2019, 08:11:37 AM »

Hi all;

I've been working on a mod which adds a usable ship version of the Derelict Domain-Era Survey Probe. I'd like to give the ship a custom built-in hullmod which decreases the crew necessary to survey a planet by 200 (to represent the fact that the probes were able to survey planets autonomously, without the help of human crew). I've got the simple stuff (adding the mod to hull_mods.csv and applying it to my .ship file) working, but the script portion seems to be malfunctioning. As of right now, the hullmod does nothing.

Here's my code:

Code
package data.hullmods;

import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.ShipAPI.HullSize;
import com.fs.starfarer.api.impl.campaign.ids.Commodities;
import com.fs.starfarer.api.impl.campaign.ids.Stats;
import com.fs.starfarer.api.impl.hullmods.BaseLogisticsHullMod;

public class AutoSurvey extends BaseLogisticsHullMod {

    @Override
    public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
        stats.getDynamic().getMod(Stats.getSurveyCostReductionId(Commodities.CREW)).modifyFlat(id, (Float) 200f);
    }

    @Override
    public String getDescriptionParam(int index, HullSize hullSize) {
        return "" + ((Float) 200f);
    }
}

Can anyone point out where I went wrong? Thank you for your help!
« Last Edit: October 19, 2019, 07:50:07 AM by Lightweaver »
Logged

Sinosauropteryx

  • Captain
  • ****
  • Posts: 262
    • View Profile
Re: Hullmod to decrease surveying crew
« Reply #1 on: October 17, 2019, 01:45:19 PM »

If I were to guess, it's because you cast your floats to Float with a capital F, which is not the same as a float. You shouldn't need to cast it anyway. Try just removing (Float).
Logged

Lightweaver

  • Ensign
  • *
  • Posts: 8
    • View Profile
Re: Hullmod to decrease surveying crew
« Reply #2 on: October 17, 2019, 01:55:21 PM »

Thank you for your help! It's been forever since I've coded java; I'll probably be making a lot more stupid mistakes before this is through lol.

I've cleaned up the code, but unfortunately, the hullmod remains nonfunctional. Do you know if there's anything else that might be causing the issue?
Logged

Sinosauropteryx

  • Captain
  • ****
  • Posts: 262
    • View Profile
Re: Hullmod to decrease surveying crew
« Reply #3 on: October 17, 2019, 01:58:16 PM »

Try removing the @Overrides. I'm something of a javanoob myself, but just looking at vanilla and custom hullmods, none of them seem to have overrides.
Logged

Timid

  • Admiral
  • *****
  • Posts: 640
  • Personal Text
    • View Profile
Re: Hullmod to decrease surveying crew
« Reply #4 on: October 17, 2019, 02:17:48 PM »



It's data.scripts.hullmod

Lightweaver

  • Ensign
  • *
  • Posts: 8
    • View Profile
Re: Hullmod to decrease surveying crew
« Reply #5 on: October 17, 2019, 02:32:57 PM »

Removing the overrides doesn't seem to have worked. Techpriest, are you saying that I should move the location of the .java script file to data.scripts.hullmod? That's not where it shows up in the directory structure of other mods, or Starsector's vanilla directory structure.
Logged

Timid

  • Admiral
  • *****
  • Posts: 640
  • Personal Text
    • View Profile
Re: Hullmod to decrease surveying crew
« Reply #6 on: October 17, 2019, 02:58:50 PM »

Removing the overrides doesn't seem to have worked. Techpriest, are you saying that I should move the location of the .java script file to data.scripts.hullmod? That's not where it shows up in the directory structure of other mods, or Starsector's vanilla directory structure.

Replace (Float) 200f with 200f

Lightweaver

  • Ensign
  • *
  • Posts: 8
    • View Profile
Re: Hullmod to decrease surveying crew
« Reply #7 on: October 17, 2019, 07:28:02 PM »

Here's an updated copy of my code:

Code
package data.hullmods;

import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.ShipAPI.HullSize;
import com.fs.starfarer.api.impl.campaign.ids.Commodities;
import com.fs.starfarer.api.impl.campaign.ids.Stats;
import com.fs.starfarer.api.impl.hullmods.BaseLogisticsHullMod;

public class AutoSurvey extends BaseLogisticsHullMod {

    public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
        stats.getDynamic().getMod(Stats.getSurveyCostReductionId(Commodities.CREW)).modifyFlat(id, 200f);
    }

    public String getDescriptionParam(int index, HullSize hullSize) {
        return "" + (200f);
    }
}

It is regrettably still nonfunctional.

EDIT:
Ok, I've narrowed down the issue a bit more. It looks like SurveyPluginImpl.java contains code which counts up the number of ships in the fleet with hullmods (like the basic Surveying Equipment) that reduce the machinery and supply requirements of a survey, and then factors in that number when calculating the final requirement. The code I've written above associates a certain id- the survey cost reduction id- with the ship that has the hullmod; it is this id that is counted by the code in SurveyPluginImpl. The survey cost reduction id is a string constructed from the id of the provided commodity variable appended to "survey_cost_reduction_".

My problem is that SurveyPluginImpl counts occurrences of "survey_cost_reduction_supplies" and "survey_cost_reduction_heavy_machinery", but not "survey_cost_reduction_crew". So, if I want to get the hullmod working, I need to find some way to modify SurveyPluginImpl and add a clause which counts "survey_cost_reduction_crew" occurrences and adds them to the calculation. I'm stumped on how to do that, though, short of manually editing the base game's original SurveyPluginImpl.java file.

Any advice?

EDIT 2, IN THE POSSIBLY VAIN HOPE THAT SOMEONE WILL BE IMPRESSED BY MY INDEPENDENT EFFORTS AND THROW ME A BONE:
So, I created a new script by the name of SurveyPluginImplEx.java and put it in my jar directory at data.scripts.plugins. I also created a settings.json file in my ordinary mod directory at data/config, and pointed to my new script as follows:
Code
{
"plugins":{
"SurveyPluginImplEx":"data.scripts.plugins.SurveyPluginImplEx",
}
}

The code in SurveyPluginImplEx.java is identical to that of the original SurveyPluginImpl.java, save for a few lines I added into the getRequired function.

Here's the original:
Code
	public Map<String, Integer> getRequired() {
Map<String, Integer> result = new LinkedHashMap<String, Integer>();

float mult = getCostMult().getModifiedValue();

int machinery = (int)Math.round(BASE_MACHINERY * mult);
machinery -= (int) Misc.getFleetwideTotalMod(fleet, Stats.getSurveyCostReductionId(Commodities.HEAVY_MACHINERY), 0);
machinery = Math.round(machinery / 10f) * 10;
if (machinery < MIN_SUPPLIES_OR_MACHINERY) machinery = MIN_SUPPLIES_OR_MACHINERY;

result.put(Commodities.HEAVY_MACHINERY, machinery);
result.put(Commodities.CREW, (int)Math.round((int)(BASE_CREW * mult) / 10f) * 10);

return result;
}

And here's my new version:
Code
	public Map<String, Integer> getRequired() {
Map<String, Integer> result = new LinkedHashMap<String, Integer>();

float mult = getCostMult().getModifiedValue();

int machinery = (int)Math.round(BASE_MACHINERY * mult);
machinery -= (int) Misc.getFleetwideTotalMod(fleet, Stats.getSurveyCostReductionId(Commodities.HEAVY_MACHINERY), 0);
machinery = Math.round(machinery / 10f) * 10;
if (machinery < MIN_SUPPLIES_OR_MACHINERY) machinery = MIN_SUPPLIES_OR_MACHINERY;

result.put(Commodities.HEAVY_MACHINERY, machinery);

int crew = (int)Math.round(BASE_CREW * mult);
crew = Math.round(crew / 10f) * 10;
crew -= (int) Misc.getFleetwideTotalMod(fleet, Stats.getSurveyCostReductionId(Commodities.CREW), 0);
if (crew < MIN_CREW) crew = MIN_CREW;
result.put(Commodities.CREW, crew);

return result;
}

Finally, I created the MIN_CREW static variable near the top of the file and set it to 0, then compiled the whole thing.

The game is running still, so I know that I didn't mess anything up too badly at least, but as the astute reader can likely surmise, I'm still not seeing any effects in-game. Surveys require just as much
crew as they used to. It feels like the further I try to progress on my own, the more points of potential failure I'm adding, so I'd really appreciate it if someone would take a look over what I have so far and point out where I've gone wrong.

My current suspicion is that I need to do something to get the script running besides just linking to it in the settings file, probably something related to its modPlugin class. However, I have no earthly idea what exactly I'm supposed to do. Any help would be appreciated.

Thank you all so much for your help!
« Last Edit: October 18, 2019, 11:24:00 AM by Lightweaver »
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: Hullmod to decrease surveying crew
« Reply #8 on: October 18, 2019, 07:06:06 PM »

You need to assign the modded plugin to the same surveyPlugin key that the vanilla plugin uses (i.e. you'll be replacing vanilla plugin) in the plugins table.

Code: json
{
"plugins":{
"surveyPlugin":"data.scripts.plugins.SurveyPluginImplEx",
}
}
This also means your mod will be incompatible with anyone else wanting to change the survey plugin, although hopefully no-one else will.

(Also, for code cleanliness reasons: If you aren't already doing so, make SurveyPluginImplEx extend SurveyPluginImpl and only include the methods() + variables that are changed, rather than completely duplicating SurveyPluginImpl.)
Logged

Lightweaver

  • Ensign
  • *
  • Posts: 8
    • View Profile
Re: Hullmod to decrease surveying crew
« Reply #9 on: October 19, 2019, 07:49:20 AM »

Histidine, thank you so much! It's working like a charm now. I really can't thank you enough.
Logged