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)

Pages: 1 ... 300 301 [302] 303 304 ... 706

Author Topic: Misc modding questions that are too minor to warrant their own thread  (Read 1700046 times)

MShadowy

  • Admiral
  • *****
  • Posts: 911
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4515 on: April 21, 2019, 05:03:18 PM »

For the moment at least, since the main reasoning behind this is controlling some of the fighter spawning behavior. It would probably be more stable if I had it set up to only effect Shadowyards related fleet spawns though; not quite sure how to do that just yet, however.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4516 on: April 21, 2019, 05:09:51 PM »

For the moment at least, since the main reasoning behind this is controlling some of the fighter spawning behavior. It would probably be more stable if I had it set up to only effect Shadowyards related fleet spawns though; not quite sure how to do that just yet, however.

Something like:

if (params instanceof DefaultFleetInflaterParams && fleet.getFactionId().equals("shadowyards")) {

Unless that's not what you mean.

That's generally the point of the various pickXXXPlugin methods - they check the parameters to see whether they should provide a custom implementation or return null and let something else handle it (such as the default implementation).
Logged

MShadowy

  • Admiral
  • *****
  • Posts: 911
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4517 on: April 21, 2019, 05:35:33 PM »

That is exactly what I mean; it's a lot simpler than I was expecting, though I kinda have a bad habit of overcomplicating things.
Logged

Vayra

  • Admiral
  • *****
  • Posts: 627
  • jangala delenda est
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4518 on: April 23, 2019, 10:43:38 AM »

Is there any way to "catch" damage and modify it before it's taken by a ship?

Specifically what I'm looking for is a way to make a hullmod that reduces High Explosive damage by a percentage that scales upward with total, i.e. the ship takes 50% of the damage from a Hammer, but 90% of the damage from a Light Assault Gun. It looks like the stuff I might want could possibly exist through some method on CombatDamageData but I'm not sure if damage is held there for a frame so it can be modified or how to do that exactly.
Logged
Kadur Remnant: http://fractalsoftworks.com/forum/index.php?topic=6649
Vayra's Sector: http://fractalsoftworks.com/forum/index.php?topic=16058
Vayra's Ship Pack: http://fractalsoftworks.com/forum/index.php?topic=16059

im gonna push jangala into the sun i swear to god im gonna do it

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4519 on: April 23, 2019, 10:58:12 AM »

It's not possible, no - there's no hook to modify the damage as it's being applied.
Logged

Vayra

  • Admiral
  • *****
  • Posts: 627
  • jangala delenda est
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4520 on: April 23, 2019, 11:09:22 AM »

It's not possible, no - there's no hook to modify the damage as it's being applied.

Alas :( but thanks for the confirmation! Any way this could go on a to-do list for some point in the distant future?

EDIT: Wait, is there a way to get damage dealt to a ship in the last frame? I might be able to implement the concept in a hacky alternative and slightly different way anyway :P
« Last Edit: April 23, 2019, 11:15:40 AM by Vayra »
Logged
Kadur Remnant: http://fractalsoftworks.com/forum/index.php?topic=6649
Vayra's Sector: http://fractalsoftworks.com/forum/index.php?topic=16058
Vayra's Ship Pack: http://fractalsoftworks.com/forum/index.php?topic=16059

im gonna push jangala into the sun i swear to god im gonna do it

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4521 on: April 23, 2019, 11:58:12 AM »

Alas :( but thanks for the confirmation! Any way this could go on a to-do list for some point in the distant future?

Yeah, though I'm not sure if I'll get to it. It's a bit tricky for various reasons.

EDIT: Wait, is there a way to get damage dealt to a ship in the last frame? I might be able to implement the concept in a hacky alternative and slightly different way anyway :P

I think other mods may have done similar-ish things, but I'm not entirely sure how/what the best way to go about it would be.
Logged

MajorTheRed

  • Captain
  • ****
  • Posts: 288
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4522 on: April 25, 2019, 07:21:03 PM »

A rather silly question I'm afraid:
I want to make a mod for a makeshift salvage gantry. It will be exactly the same as the current one except with worse bonus and the ability to get it in the skill tree (like Expanded Missile Rack for example). But the hull mod is located in a java file so I guess it's related to its action in the campaign and not just for combat like most mods located in the data folder.
So how do I get my hullmod in a .java file? Is it like opening it with a archive software like WinRAR or so? Or can I put it in the data folder of my mod like other hullmods?
Logged

Sundog

  • Admiral
  • *****
  • Posts: 1723
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4523 on: April 25, 2019, 07:54:34 PM »

I suspect the only reason the salvage gantry script isn't in the hullmods folder is that it's more complex than most hullmod scripts. I don't see any reason you wouldn't be able copy the code from com.fs.starfarer.api.impl.campaign.RepairGantry into a script located in the folder (but I may be wrong). Here's the code:
Spoiler
Code
package com.fs.starfarer.api.impl.campaign;

import java.awt.Color;
import java.util.HashMap;
import java.util.Map;

import com.fs.starfarer.api.GameState;
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.CampaignFleetAPI;
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.fleet.FleetMemberAPI;
import com.fs.starfarer.api.impl.campaign.ids.Stats;
import com.fs.starfarer.api.ui.LabelAPI;
import com.fs.starfarer.api.ui.TooltipMakerAPI;
import com.fs.starfarer.api.util.Misc;

public class RepairGantry extends BaseHullMod {

private static Map mag = new HashMap();
static {
mag.put(HullSize.FRIGATE, 10f);
mag.put(HullSize.DESTROYER, 25f);
mag.put(HullSize.CRUISER, 30f);
mag.put(HullSize.CAPITAL_SHIP, 40f);
}

public static final float BATTLE_SALVAGE_MULT = .2f;
public static final float MIN_CR = 0.1f;

public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
//stats.getDynamic().getMod(Stats.SALVAGE_VALUE_MULT_MOD).modifyFlat(id, SALVAGE_MODIFIER);
stats.getDynamic().getMod(Stats.SALVAGE_VALUE_MULT_MOD).modifyFlat(id, (Float) mag.get(hullSize) * 0.01f);
//stats.getDynamic().getMod(Stats.BATTLE_SALVAGE_VALUE_MULT_MOD).modifyFlat(id, (Float) mag.get(hullSize) * 0.01f * (Float) mag.get(hullSize) * 0.01f);
}

public String getDescriptionParam(int index, HullSize hullSize) {
//if (index == 0) return "" + (int) (SALVAGE_MODIFIER * 100f);
//if (index == 1) return "" + (int) (BATTLE_SALVAGE_MODIFIER * 100f);

if (index == 0) return "" + ((Float) mag.get(HullSize.FRIGATE)).intValue() + "%";
if (index == 1) return "" + ((Float) mag.get(HullSize.DESTROYER)).intValue() + "%";
if (index == 2) return "" + ((Float) mag.get(HullSize.CRUISER)).intValue() + "%";
if (index == 3) return "" + ((Float) mag.get(HullSize.CAPITAL_SHIP)).intValue() + "%";
if (index == 4) return "" + (int)Math.round(BATTLE_SALVAGE_MULT * 100f) + "%";

return null;
}

@Override
public void advanceInCombat(ShipAPI ship, float amount) {

}


@Override
public boolean shouldAddDescriptionToTooltip(HullSize hullSize, ShipAPI ship, boolean isForModSpec) {
return true;
}

@Override
public void addPostDescriptionSection(TooltipMakerAPI tooltip, HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec) {
float pad = 3f;
float opad = 10f;
Color h = Misc.getHighlightColor();
Color bad = Misc.getNegativeHighlightColor();

tooltip.addPara("Each additional ship with a salvage gantry provides diminishing returns.", opad);

if (isForModSpec || ship == null) return;
if (Global.getSettings().getCurrentState() == GameState.TITLE) return;

CampaignFleetAPI fleet = Global.getSector().getPlayerFleet();
float fleetMod = getAdjustedGantryModifier(fleet, null, 0f);
float currShipMod = (Float) mag.get(hullSize) * 0.01f;

float fleetModWithOneMore = getAdjustedGantryModifier(fleet, null, currShipMod);
float fleetModWithoutThisShip = getAdjustedGantryModifier(fleet, ship.getFleetMemberId(), 0f);

tooltip.addPara("The total resource recovery bonus for your fleet is %s.", opad, h,
"" + (int)Math.round(fleetMod * 100f) + "%");

float cr = ship.getCurrentCR();
for (FleetMemberAPI member : Global.getSector().getPlayerFleet().getFleetData().getMembersListCopy()) {
if (member.getId().equals(ship.getFleetMemberId())) {
cr = member.getRepairTracker().getCR();
}
}

if (cr < MIN_CR) {
LabelAPI label = tooltip.addPara("This ship's combat readiness is below %s " +
"and the gantry can not be utilized. Bringing this ship into readiness " +
"would increase the fleetwide bonus to %s.",
opad, h,
"" + (int) Math.round(MIN_CR * 100f) + "%",
"" + (int)Math.round(fleetModWithOneMore * 100f) + "%");
label.setHighlightColors(bad, h);
label.setHighlight("" + (int) Math.round(MIN_CR * 100f) + "%", "" + (int)Math.round(fleetModWithOneMore * 100f) + "%");

// tooltip.addPara("Bringing this ship into readiness " +
// "would increase the fleet's bonus to %s.", opad, h,
// "" + (int)Math.round(fleetModWithOneMore * 100f) + "%");
} else {
if (fleetMod > currShipMod) {
tooltip.addPara("Removing this ship would decrease it to %s. Adding another ship of the same type " +
"would increase it to %s.", opad, h,
"" + (int)Math.round(fleetModWithoutThisShip * 100f) + "%",
"" + (int)Math.round(fleetModWithOneMore * 100f) + "%");
} else {
tooltip.addPara("Adding another ship of the same type " +
"would increase it to %s.", opad, h,
"" + (int)Math.round(fleetModWithOneMore * 100f) + "%");
}
}

tooltip.addPara("The fleetwide post-battle salvage bonus is %s.", opad, h,
"" + (int)Math.round(getAdjustedGantryModifierForPostCombatSalvage(fleet) * 100f) + "%");
// "" + Misc.getRoundedValueMaxOneAfterDecimal(
// getAdjustedGantryModifierForPostCombatSalvage(fleet) * 100f) + "%");

}


public static float getAdjustedGantryModifierForPostCombatSalvage(CampaignFleetAPI fleet) {
return getAdjustedGantryModifier(fleet, null, 0) * BATTLE_SALVAGE_MULT;
}

public static float getAdjustedGantryModifier(CampaignFleetAPI fleet, String skipId, float add) {
//List<Pair<FleetMemberAPI, Float>> values = new ArrayList<Pair<FleetMemberAPI,Float>>();

float max = 0f;
float total = 0f;
for (FleetMemberAPI member : fleet.getFleetData().getMembersListCopy()) {
if (member.isMothballed()) continue;
if (member.getRepairTracker().getCR() < MIN_CR) continue;

if (member.getId().equals(skipId)) {
continue;
}
float v = member.getStats().getDynamic().getMod(Stats.SALVAGE_VALUE_MULT_MOD).computeEffective(0f);
if (v <= 0) continue;

// Pair<FleetMemberAPI, Float> p = new Pair<FleetMemberAPI, Float>(member, v);
// values.add(p);
if (v > max) max = v;
total += v;
}
if (add > max) max = add;
total += add;

if (max <= 0) return 0f;
float units = total / max;
if (units <= 1) return max;
float mult = Misc.logOfBase(2.5f, units) + 1f;
float result = total * mult / units;
if (result <= 0) {
result = 0;
} else {
result = Math.round(result * 100f) / 100f;
result = Math.max(result, 0.01f);
}
return result;
}
}
[close]

Instead of copying the code in it's entirety, I'd recommend extending the RepairGantry class if you're comfortable with that.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4524 on: April 25, 2019, 09:04:27 PM »

There's a good chance it wouldn't work as a loose script - I don't think enhanced for loops are supported by Janino, though I could be misremembering.
Logged

Sundog

  • Admiral
  • *****
  • Posts: 1723
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4525 on: April 25, 2019, 09:11:32 PM »

There's a good chance it wouldn't work as a loose script - I don't think enhanced for loops are supported by Janino, though I could be misremembering.
Oh, that's a good point. I didn't consider Janino limitations.

@MajorTheRed:
Feel free to hit me up on Discord or PM me if you run into any trouble.

Sundog

  • Admiral
  • *****
  • Posts: 1723
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4526 on: April 30, 2019, 03:56:35 PM »

Is there a reliable way to get the affected FleetMemberAPI from within BaseHullMod.applyEffectsBeforeShipCreation?
I'm working on a way to add randomly generated traits to ships, like this:
Spoiler
[close]
(Yes, I'm stealing Voiddweller's idea)

Currently, I'm appending the ship's ID to it's variant ID and using that as an identifier, like this:
Code
    FleetMemberAPI findShip(ShipAPI.HullSize hullSize, MutableShipStatsAPI stats) {
        List<FleetMemberAPI> members = Global.getSector().getPlayerFleet().getFleetData().getMembersListCopy();

        for (FleetMemberAPI s : members) {
            if (stats.getVariant().getHullVariantId().equals(s.getVariant().getHullVariantId())) {
                return s;
            }
        }

        return null;
    }
stats.getEntity frequently seems to return null, unfortunately.

If there's no better approach, does anyone have any advice for improving the reliability of the variant ID method I'm currently using? The only problem I've found so far is that the 'hullmod' effects aren't applied while the ship is in storage, but this is a very dirty hack, so I have some concerns (like the variant ID changing).

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4527 on: April 30, 2019, 04:19:38 PM »

Hmm - how about "if (stats == s.getStats())? I *think* that ought to do it.

(Yes, I'm stealing Voiddweller's idea)

Variations on this have come up once or twice, and I'm pretty sure I've thought about almost this exact thing several times :) Very cool to see you doing it, this looks amazing!

(And I'm also unreasonably excited by the extensive use of the TooltipMakerAPI features on display here.)
Logged

Sundog

  • Admiral
  • *****
  • Posts: 1723
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4528 on: April 30, 2019, 05:40:28 PM »

Hmm - how about "if (stats == s.getStats())? I *think* that ought to do it.
I may be misremembering, but I think the case in which that didn't work was the refit screen. I assume a copy of the ship is used there that has a new stats instance. I'll test that out again though.

Variations on this have come up once or twice, and I'm pretty sure I've thought about almost this exact thing several times :) Very cool to see you doing it, this looks amazing!
Glad you think so! If you ever do decide to implement something like this (which would be awesome), hopefully my mod would help you avoid whatever design mistakes I inevitably end up making  :)

(And I'm also unreasonably excited by the extensive use of the TooltipMakerAPI features on display here.)
I was likewise unreasonably excited when I found out how much tooltip versatility was exposed by the API  :)

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4529 on: April 30, 2019, 05:56:06 PM »

I may be misremembering, but I think the case in which that didn't work was the refit screen. I assume a copy of the ship is used there that has a new stats instance. I'll test that out again though.

Yeah, it might be worth another look. You could definitely be right, but at least looking at the code briefly, it doesn't seem like that should be the case. Unfortunately not a great time for me to delve into this right now, what with .1 being very soon.

Glad you think so! If you ever do decide to implement something like this (which would be awesome), hopefully my mod would help you avoid whatever design mistakes I inevitably end up making  :)

I was likewise unreasonably excited when I found out how much tooltip versatility was exposed by the API  :)

:D The latter, if we're being honest, is largely a product of me using it for so much of the core stuff.

(Oh, hey, minor random thing I noticed in the tooltip: it should be "its" rather than "it's" in all three places. Sorry, I'm a bit ocd about that, though naturally I also make my share of mistakes :D)
« Last Edit: April 30, 2019, 07:04:51 PM by Alex »
Logged
Pages: 1 ... 300 301 [302] 303 304 ... 706