Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: Modding all Weapons/Ships via script  (Read 5169 times)

Ranakastrasz

  • Admiral
  • *****
  • Posts: 702
  • Prince Corwin of Amber
    • View Profile
Modding all Weapons/Ships via script
« on: June 06, 2017, 09:19:12 PM »

Is it possible to run a script that applies a modification to weapons/ships, instead of having to manually alter the excel files?

Kinda like how Hull mods work, I think.
Logged
I think is easy for Simba and Mufasa sing the Circle of Life when they're on the top of the food chain, I bet the zebras hate that song.

Cigarettes are a lot like hamsters. Perfectly harmless, until you put one in your mouth and light it on fire

isaacssv552

  • Commander
  • ***
  • Posts: 215
    • View Profile
Re: Modding all Weapons/Ships via script
« Reply #1 on: June 06, 2017, 10:21:36 PM »

It sounds like you want a program that will read in a csv and modify a column by either a multiplier or a flat increase. This could be done in c with fgets and strtok or in Java with Scanner and String.split.

Something like
Code
while(scanner.hasNextLine())
{
String[] buffer = scanner.getNextLine().split(",");
for (i = 0; i < buffer.length; i++)
{
// Do Stuff
}
}
Logged

Dark.Revenant

  • Admiral
  • *****
  • Posts: 2806
    • View Profile
    • Sc2Mafia
Re: Modding all Weapons/Ships via script
« Reply #2 on: June 06, 2017, 10:39:46 PM »

For rote scripting I'd actually suggest Python over C or Java, which both are like sledgehammers for something simple like that.
Logged

zaimoni

  • Commander
  • ***
  • Posts: 110
    • View Profile
Re: Modding all Weapons/Ships via script
« Reply #3 on: June 07, 2017, 02:21:48 AM »

For rote scripting I'd actually suggest Python over C or Java, which both are like sledgehammers for something simple like that.
Agreed; Python is my go-to for in-house text-processing scripting.  Between the reference manual quality (no other major programming language can be written in idiomatically, just by reading and understanding the official reference manual), and the language being as fast as C for text processing, the only contraindication for Python for text processing would be "this is too large to re-implement in a later major version".

Which isn't relevant here.
Logged

Ranakastrasz

  • Admiral
  • *****
  • Posts: 702
  • Prince Corwin of Amber
    • View Profile
Re: Modding all Weapons/Ships via script
« Reply #4 on: June 07, 2017, 04:46:27 AM »

Not quite what I meant. I was talking about something like applying "heavy armor" hull mod to all ships intrinsicly.
Something that runs in the campaign when it loads a ship's data.

Edit:
Like this
Code
package data.hullmods;

import com.fs.starfarer.api.combat.BaseHullMod;
import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.ShipAPI.HullSize;

public class TargetingSupercomputer extends BaseHullMod {

public static float RANGE_BONUS = 200f;
public static float PD_MINUS = 140f;
public static float VISION_BONUS = 2000f;
public static float AUTOFIRE_AIM = 0.5f;

public String getDescriptionParam(int index, HullSize hullSize) {
if (index == 0) return "" + (int)Math.round(RANGE_BONUS) + "%";
if (index == 1) return "" + (int)Math.round(RANGE_BONUS - PD_MINUS) + "%";
//if (index == 0) return "" + (int)RANGE_THRESHOLD;
//if (index == 1) return "" + (int)((RANGE_MULT - 1f) * 100f);
//if (index == 1) return "" + new Float(VISION_BONUS).intValue();
return null;
}


public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
stats.getBallisticWeaponRangeBonus().modifyPercent(id, RANGE_BONUS);
stats.getEnergyWeaponRangeBonus().modifyPercent(id, RANGE_BONUS);
//stats.getBeamWeaponRangeBonus().modifyPercent(id, RANGE_BONUS);

stats.getNonBeamPDWeaponRangeBonus().modifyPercent(id, -PD_MINUS);
stats.getBeamPDWeaponRangeBonus().modifyPercent(id, -PD_MINUS);


stats.getSightRadiusMod().modifyFlat(id, VISION_BONUS);
stats.getAutofireAimAccuracy().modifyFlat(id, AUTOFIRE_AIM);
}



}

The "applyEffectsBeforeShipCreation", applied to all ships in the campaign. Whether done directly, or by having a "On Campaign Load" that adds a "Locked" hull mod to every ship that exists.
« Last Edit: June 07, 2017, 08:45:45 AM by Ranakastrasz »
Logged
I think is easy for Simba and Mufasa sing the Circle of Life when they're on the top of the food chain, I bet the zebras hate that song.

Cigarettes are a lot like hamsters. Perfectly harmless, until you put one in your mouth and light it on fire

isaacssv552

  • Commander
  • ***
  • Posts: 215
    • View Profile
Re: Modding all Weapons/Ships via script
« Reply #5 on: June 07, 2017, 08:59:47 AM »

Not quite what I meant. I was talking about something like applying "heavy armor" hull mod to all ships intrinsicly.
Something that runs in the campaign when it loads a ship's data.

Edit:
Like this
Code
package data.hullmods;

import com.fs.starfarer.api.combat.BaseHullMod;
import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.ShipAPI.HullSize;

public class TargetingSupercomputer extends BaseHullMod {

public static float RANGE_BONUS = 200f;
public static float PD_MINUS = 140f;
public static float VISION_BONUS = 2000f;
public static float AUTOFIRE_AIM = 0.5f;

public String getDescriptionParam(int index, HullSize hullSize) {
if (index == 0) return "" + (int)Math.round(RANGE_BONUS) + "%";
if (index == 1) return "" + (int)Math.round(RANGE_BONUS - PD_MINUS) + "%";
//if (index == 0) return "" + (int)RANGE_THRESHOLD;
//if (index == 1) return "" + (int)((RANGE_MULT - 1f) * 100f);
//if (index == 1) return "" + new Float(VISION_BONUS).intValue();
return null;
}


public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
stats.getBallisticWeaponRangeBonus().modifyPercent(id, RANGE_BONUS);
stats.getEnergyWeaponRangeBonus().modifyPercent(id, RANGE_BONUS);
//stats.getBeamWeaponRangeBonus().modifyPercent(id, RANGE_BONUS);

stats.getNonBeamPDWeaponRangeBonus().modifyPercent(id, -PD_MINUS);
stats.getBeamPDWeaponRangeBonus().modifyPercent(id, -PD_MINUS);


stats.getSightRadiusMod().modifyFlat(id, VISION_BONUS);
stats.getAutofireAimAccuracy().modifyFlat(id, AUTOFIRE_AIM);
}



}

The "applyEffectsBeforeShipCreation", applied to all ships in the campaign. Whether done directly, or by having a "On Campaign Load" that adds a "Locked" hull mod to every ship that exists.
I'd advise looking at the DME hullmod blocking system, which does something similar but in reverse.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24123
    • View Profile
Re: Modding all Weapons/Ships via script
« Reply #6 on: June 07, 2017, 10:08:27 AM »

Unless I'm forgetting about something, I don't think that's possible.

The closest you could get is adding a hidden built-in hullmod to all ships and then changing its effects to suit whatever you're trying to do, but you'd still have to add that hullmod to the .ship files first.
Logged

Ranakastrasz

  • Admiral
  • *****
  • Posts: 702
  • Prince Corwin of Amber
    • View Profile
Re: Modding all Weapons/Ships via script
« Reply #7 on: June 07, 2017, 10:48:10 AM »

Unless I'm forgetting about something, I don't think that's possible.

The closest you could get is adding a hidden built-in hullmod to all ships and then changing its effects to suit whatever you're trying to do, but you'd still have to add that hullmod to the .ship files first.

So, there is no way in the campaign to use a script to add/remove a hull mod, or make it innate?
I mean, if there was, I am pretty sure you can respond to game-start/load, and fleet creation to apply it. Not really sure tho.

Guess Ima need to figure out how to write a program to change XML files instead
Logged
I think is easy for Simba and Mufasa sing the Circle of Life when they're on the top of the food chain, I bet the zebras hate that song.

Cigarettes are a lot like hamsters. Perfectly harmless, until you put one in your mouth and light it on fire

isaacssv552

  • Commander
  • ***
  • Posts: 215
    • View Profile
Re: Modding all Weapons/Ships via script
« Reply #8 on: June 07, 2017, 07:28:31 PM »

Unless I'm forgetting about something, I don't think that's possible.

The closest you could get is adding a hidden built-in hullmod to all ships and then changing its effects to suit whatever you're trying to do, but you'd still have to add that hullmod to the .ship files first.
Could a script run at the start of combat get access to the shipAPIs of all ships in combat and add built-in hullmods?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24123
    • View Profile
Re: Modding all Weapons/Ships via script
« Reply #9 on: June 07, 2017, 09:35:16 PM »

Ahh, yeah, there we go - that could work. Or instead of adding hullmods, a script could just make changes to the ship stats instead.

I was thinking in terms of changing the ship hulls globally, but yeah, altering them via a combat script is probably the cleanest way.
Logged

Ranakastrasz

  • Admiral
  • *****
  • Posts: 702
  • Prince Corwin of Amber
    • View Profile
Re: Modding all Weapons/Ships via script
« Reply #10 on: June 08, 2017, 04:37:45 AM »

Can you point me at an example mod that I could use as a basis? Specifically for the in-campaign modification part? I can probably do the in-battle part.

Logged
I think is easy for Simba and Mufasa sing the Circle of Life when they're on the top of the food chain, I bet the zebras hate that song.

Cigarettes are a lot like hamsters. Perfectly harmless, until you put one in your mouth and light it on fire

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Modding all Weapons/Ships via script
« Reply #11 on: June 08, 2017, 12:54:24 PM »

Vacuum has an example of modifications to a FleetMemberAPI during a combat Mission in the script that handled in-game Boarding.  That said, the cleanest way to do this is probably to:

1.  Attach a Tag to the FleetMemberAPI when (whatever) is happening.
2.  Intercept the resulting ships when they hit the Mission using EveryFrameCombatScript(), using a HashMap to store which ships have already been checked / modified (because you don't know they'll be spawned on the first frame, you need to keep re-checking but use minimal CPU).
3.  Modify accordingly, including subsequent modification of the FleetMemberAPI.

The case in Vacuum doesn't cover all of this, but it at least covers the basics of how to get to the FleetMemberAPI (which is trickier than you'd think).
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Ranakastrasz

  • Admiral
  • *****
  • Posts: 702
  • Prince Corwin of Amber
    • View Profile
Re: Modding all Weapons/Ships via script
« Reply #12 on: June 08, 2017, 03:13:55 PM »

I already know how to do in-combat stuff, I want to know how to do in Campaign stuff.


Everything from Templars to Vacuum to Armor Repair hull mod already mess with in-combat stuff. I can't find any examples for Campaign stuff that effects ships.
Logged
I think is easy for Simba and Mufasa sing the Circle of Life when they're on the top of the food chain, I bet the zebras hate that song.

Cigarettes are a lot like hamsters. Perfectly harmless, until you put one in your mouth and light it on fire