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 ... 312 313 [314] 315 316 ... 706

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

SafariJohn

  • Admiral
  • *****
  • Posts: 3010
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4695 on: July 13, 2019, 09:01:10 AM »

All of the advanceInCombat methods you could override have "ShipAPI ship" and "float amount" as parameters. If your parameters don't match that exactly, the game won't call the method.

The compiler complained at you because it couldn't find where id is declared. The simplest solution is to add a declaration above the first if-statement, like this:

Code
String id = "GMDA_BOSA";

On a side note, you can compress the last two if-statements into:
Code
if (ship.getFluxTracker().isOverloaded() || ship.getFluxTracker().getFluxLevel() < 0.65) {
    ship.getMutableStats().getMaxSpeed().unmodifyMult(id);
    ship.getMutableStats().getFluxDissipation().unmodifyMult(id);
    ship.getMutableStats().getAcceleration().unmodifyMult(id);
    ship.getMutableStats().getDeceleration().unmodifyMult(id);
    ship.getMutableStats().getMaxTurnRate().unmodifyMult(id);
    ship.getMutableStats().getTurnAcceleration().unmodifyMult(id);
}
Logged

Inventor Raccoon

  • Captain
  • ****
  • Posts: 451
  • Digging through trash for a hydroflux catalyst
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4696 on: July 13, 2019, 01:59:14 PM »

Is it possible to set the name of a ShipAPI or somehow update it to match the FleetMemberAPI?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4697 on: July 13, 2019, 09:08:36 PM »

Let me add setName() to ShipAPI. Various UI elements might not update when it changes, though, i.e. if you have a target reticle, it'd most likely keep displaying the name-that-was at the time the ship was targeted.
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4698 on: July 13, 2019, 11:09:26 PM »

If I wanted a fleet created by a RouteFleetSpawner to go straight to its destination instead of chasing down random enemy fleets, how would I do it? Is there a part of RouteFleetAssignmentAI that I should change?

As an aside: Should there be a more reliable way of generating loot drops from killing enemies (e.g. AI cores from Remnants)?
The current method of using an FID config gen override on MyFleet breaks if that config gen isn't called by the fleet interaction dialog plugin for any reason... such as when the player interacts with another fleet and MyFleet is pulled in. This doesn't come up in vanilla and a mod could add its own handling (e.g. with reportEncounterLootGenerated in a listener), but an easier approach would be nice.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4700 on: July 14, 2019, 07:36:00 AM »

If I wanted a fleet created by a RouteFleetSpawner to go straight to its destination instead of chasing down random enemy fleets, how would I do it? Is there a part of RouteFleetAssignmentAI that I should change?

You'd probably want to override addLocalAssignment, addStartingAssignment, addTravelAssignment, and addEndingAssignment to ... basically do the same thing they're doing, but using one of the DELIVER_* assignments to move them around - which makes a fleet move somewhere and not chase unless the enemy fleet overlaps.

Could also set $isTradeFleet to true in the fleet's memory, but that may have some undesired side effects.

Let me make a note to add another flag that does this w/o flagging it as a trader, since this seems to come up a fair bit.

Edit: you could also call ModularFleetAIAPI.getStrategicModule().getDoNotAttack() and periodically add all nearby fleets to it - either in another script added to the fleet, or in the fleet's assignment AI if it has a custom one already.

As an aside: Should there be a more reliable way of generating loot drops from killing enemies (e.g. AI cores from Remnants)?
The current method of using an FID config gen override on MyFleet breaks if that config gen isn't called by the fleet interaction dialog plugin for any reason... such as when the player interacts with another fleet and MyFleet is pulled in. This doesn't come up in vanilla and a mod could add its own handling (e.g. with reportEncounterLootGenerated in a listener), but an easier approach would be nice.

Let me make a note to take a look at this; good point about the "fleet being pulled in" case.
« Last Edit: July 14, 2019, 08:09:59 AM by Alex »
Logged

tzuridis

  • Ensign
  • *
  • Posts: 34
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4701 on: July 16, 2019, 07:39:27 AM »

Random question, mostly on what you guys think would be the best way to go about this. I want to create a mod that changes combat somewhat, basically doing this:

Small ships are faster either by 50%, more or less (using the designations?). As are missiles and torpedoes. Missiles and torpedoes also do 3x - 5x more damage but all weapons can fire 100 - 200% further similar to the hullmod for the battle station. The whole point of this is to make it so that small ships are still capable of taking down big fellas if they can get around as shield strength will be the same. Would test it out a bit, mess around, maybe push the mod so people can try a new experience.

So my idea to implement this was in hope of finding a base hullmod that all ships had, perhaps hidden or something. Not really applicable to apply to all .ship files especially with other mods. I did find the basehullmod in the API, is there one in hullmods that applies to all ships? I was hoping I could find something in there so I could import the supercomputer targetting mod. I'm pretty sure my way is wrong, so any advice as to what should I take a look at? I am guessing it is all in the API?

I don't know java but I know js so I think I could figure it out eventually.
« Last Edit: July 16, 2019, 07:45:10 AM by tzuridis »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4702 on: July 16, 2019, 07:57:00 AM »

I think you're thinking about this in a good way as far as structuring it, but, yeah - there's no such hullmod.

That being absent, the best way to go is probably an EveryFrameCombatPlugin that keeps track of which ships it's seen so far, and then applies your desired changes to ships right after they get deployed.

See: data.scripts.plugins.TestCombatPlugin for a really messy and extremely random implementation of a combat plugin; it's one I've used to test an assortment of things. If you put it in data.scripts.plugins, you don't need to register it. If you put it elsewhere (say because you've set things up to compile your mod's code into a jar) you'd need to add it to the "plugins" section in settings.json for it to be picked up.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4703 on: July 16, 2019, 08:25:46 AM »

Here's a basic, bare-bones structure for what Alex said.  I was going to recommend going down the Built-In Hull Mod route, but this will work for testing basic concepts or global effects like this. 

You'll really, really want to install a Java IDE first and learn to make "my first JAR", etc.  See Modding Tools; there are great, newbie-friendly instructions for installing NetBeans, Intellij, etc. here.

Code: java
public class my_awesome_plugin_example implements EveryFrameCombatPlugin {

private CombatEngineAPI engine;

    @Override
    public void init(CombatEngineAPI cEngine) {
engine = cEngine;
    }

    @Override
    public void advance(float amount, List events) {
         //If we're paused or not in combat or whatever, stop here.
         if(engine == null
             || engine.isPaused()
             || (!engine.isInCampaign() && !engine.isInCampaignSim() && !engine.isMission() && !engine.isSimulation())){
                return;
         }   

         //Get all of the ships currently on the battlefield, iterate through them.
         for(ShipAPI ship : engine.getShips()){
                  //Do stuff to ships here, depending on what they are, etc.
         }

    }

    @Override
    public void renderInWorldCoords(ViewportAPI viewport) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void renderInUICoords(ViewportAPI viewport) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

@Override
public void processInputPreCoreControls(float f, List<InputEventAPI> list) {
}

}
Logged
Please check out my SS projects :)
Xeno's Mod Pack

tzuridis

  • Ensign
  • *
  • Posts: 34
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4704 on: July 16, 2019, 08:31:16 AM »

Awesome thanks for the quick replies.
Logged

tzuridis

  • Ensign
  • *
  • Posts: 34
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4705 on: July 17, 2019, 06:57:04 AM »

2 quick if you guys have time. I am editing the testcombat plugin. I tried to use this method:

Code
public class TestCombatPlugin extends BaseEveryFrameCombatPlugin { 

public static float DAMAGE_MISSILES_PERCENT = 200f;
public static float SPEED_MISSILES_PERCENT = 500f;

public static float SPEED_BONUS = 525f;
public static float TURN_BONUS = 20f;

/**
* Set this to true to have the plugin actually do stuff.
*/
private static boolean TEST_MODE = true;

private CombatEngineAPI engine;
public void init(CombatEngineAPI engine) {
this.engine = engine;
}

   public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
stats.getDamageToMissiles().modifyPercent(id, DAMAGE_MISSILES_PERCENT);
stats.getMaxSpeed().modifyPercent(id, SPEED_BONUS);
stats.getBallisticWeaponRangeBonus().modifyFlat(id, 600f);
stats.getBeamWeaponRangeBonus().modifyFlat(id, 300f);
}
I am not sure how to do this exactly. I see this stems from basehull which I believe is not passed down to baseeveryframecombat plugin? Not really any methods that I can pull from there right?

Could you give me a little more syntax as to how I could write the for loop you gave me below? .getShips doesn't take the parameters right? Could I even use stats.getMaxSpeed() or methods like that. I have stats imported through MutableShipStatsAPI.



 
Code
@Override
    public void advance(float amount, List events) {
         //If we're paused or not in combat or whatever, stop here.
         if(engine == null
             || engine.isPaused()
             || (!engine.isInCampaign() && !engine.isInCampaignSim() && !engine.isMission() && !engine.isSimulation())){
                return;
         }   

         //Get all of the ships currently on the battlefield, iterate through them.
         for(ShipAPI ship : engine.getShips()){
                 
         }

    }

This part is not in the file by the way, only the top part I couldn't figure out the syntax for this part. If I am totally wrong I am to take a fee java course.

Thanks for any help
« Last Edit: July 17, 2019, 06:59:22 AM by tzuridis »
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4706 on: July 17, 2019, 10:02:55 AM »

You're going to want to write something that changes the MutableShipStatsAPI, accessible through ShipAPI (hence why I gave it that way).  Essentially, just tweak their max stats directly through a buff.

The only tricky bit, in terms of performance, is designing it so that it doesn't repeat; this is best-achieved through a HashSet, so that you can check .contains() for the presence of the ShipAPI in question and only alter its stats once.

Sorry if that went whoosh over your head, but basically, in Java, there are traditional data structures like arrays and a bunch of more exotic ones that offer great lookup performance, but are a little more difficult to understand initially.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4707 on: July 19, 2019, 09:44:16 PM »

Is there a way to add a pre-existing LabelAPI to a TooltipMakerAPI?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4708 on: July 20, 2019, 07:30:53 AM »

TooltipMakerAPI.addCustom() should let you do it, if you cast the LabelAPI to a UIComponentAPI.

Be careful if that same LabelAPI already shows up somewhere in the UI, though - the behavior when the same UI element is added to the UI multiple times is undefined.

(Also, probably goes without saying, but hanging on to a LabelAPI in any sort of data that ends up in a savefile would not be a good idea.)

Edit: I guess what I'm trying to say is "it's possible, but the question sets off potential alarm bells" :)
Logged

AxleMC131

  • Admiral
  • *****
  • Posts: 1722
  • Amateur World-Builder
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4709 on: July 21, 2019, 12:50:19 AM »

I've got a ship with a module, which I'm trying to dynamically change (as in, the whole module) with a hullmod setup. I got this from ShipVariantAPI:

Code
void setModuleVariant(String slotId, ShipVariantAPI variant);

Frustratingly, it doesn't seem to work for me. I'm very sure I've got the weapon slot ID right, and I've got an actual ShipVariantAPI instance that I'm plugging into it (I've tried several), but no matter how I swing it that line of code acts as if it's just not executing - the ship remains sans-modules, or in the previous tests the module just doesn't change when it should.

Am I missing something obvious? Does this method only work in certain circumstances? I have only been testing in single missions, so if this is another thing that only works in the campaign please let me know.
Logged
Pages: 1 ... 312 313 [314] 315 316 ... 706