Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 321 322 [323] 324 325 ... 459

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

NoFoodAfterMidnight

  • Ensign
  • *
  • Posts: 39
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4830 on: August 21, 2019, 12:11:27 AM »

Is any of the base AI accessible or is the only way to modify AI to write new code and use ShipAIPlugin.Advance() ?  There's some simple tweaks I'd like to make.

If it's all done through Advance() , how would I go about finding the core methods of ship controls and such to write a new AI, and how would I overwrite parts of the base AI?
Logged

SafariJohn

  • Admiral
  • *****
  • Posts: 1771
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4831 on: August 21, 2019, 02:34:38 PM »

Well, I tried to implement ore production, but something has gone wrong. I have the code below in my apply() method. The top log call reports that the market does in fact have ore_moderate and the bottom log call reports oreSupply has a value of 1, as expected, but the industry produces no ore.

Spoiler
Code: java
        int oreSupply = 0;
        int rareSupply = 0;
        int volatilesSupply = 0;
        int organicsSupply = 0;

        org.apache.log4j.Logger logger = Global.getLogger(Roider_Dives.class);

        for (MarketConditionAPI c : market.getConditions()) {
            logger.info("asddssd" + c.getId());

            switch (c.getId()) {
                case (Conditions.ORE_ULTRARICH): oreSupply++;
                case (Conditions.ORE_RICH): oreSupply++;
                case (Conditions.ORE_ABUNDANT): oreSupply++;
                case (Conditions.ORE_MODERATE): oreSupply++;
                case (Conditions.ORE_SPARSE): break;

                case (Conditions.ORGANICS_PLENTIFUL): organicsSupply++;
                case (Conditions.ORGANICS_ABUNDANT): organicsSupply++;
                case (Conditions.ORGANICS_COMMON): organicsSupply++;
                case (Conditions.ORGANICS_TRACE): break;


                // Reduced supply for rare ores and volatiles
                case (Conditions.RARE_ORE_ULTRARICH): rareSupply++;
                case (Conditions.RARE_ORE_RICH): rareSupply++;
                case (Conditions.RARE_ORE_ABUNDANT): break;
                case (Conditions.RARE_ORE_MODERATE): break;
                case (Conditions.RARE_ORE_SPARSE): break;

                case (Conditions.VOLATILES_PLENTIFUL): volatilesSupply++;
                case (Conditions.VOLATILES_ABUNDANT): break;
                case (Conditions.VOLATILES_DIFFUSE): break;
                case (Conditions.VOLATILES_TRACE): break;
            }
        }

        logger.info("asddssd ore " + oreSupply);
        logger.info("asddssd " + rareSupply);
        logger.info("asddssd " + volatilesSupply);
        logger.info("asddssd " + organicsSupply);

        supply(Commodities.ORE, oreSupply);
        supply(Commodities.RARE_ORE, rareSupply);
        supply(Commodities.VOLATILES, volatilesSupply);
        supply(Commodities.ORGANICS, organicsSupply);
[close]
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 17089
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4832 on: August 21, 2019, 02:44:54 PM »

Is any of the base AI accessible or is the only way to modify AI to write new code and use ShipAIPlugin.Advance() ?  There's some simple tweaks I'd like to make.

If it's all done through Advance() , how would I go about finding the core methods of ship controls and such to write a new AI, and how would I overwrite parts of the base AI?

It's not accessible, no. It's a tangled ball of core code that would be way too much of a project to try to extract into mod-land, unfortunately.

So it's an all-or-nothing deal, with the exception of ship systems, which have modular AIs.

For controlling ships: see ShipAPI.giveCommand().

Well, I tried to implement ore production, but something has gone wrong. I have the code below in my apply() method. The top log call reports that the market does in fact have ore_moderate and the bottom log call reports oreSupply has a value of 1, as expected, but the industry produces no ore.

I'd suggest calling the supply() method that has a String id as the first parameter. Probably something else is supplying 0 units with the default ID that the supply() method you're calling uses, and that overrides whatever you're doing. Not 100% sure, though.
Logged

SafariJohn

  • Admiral
  • *****
  • Posts: 1771
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4833 on: August 21, 2019, 02:59:47 PM »

That works, thanks! Though, now I have to code descriptions *shakes fist*
Logged

Vayra

  • Admiral
  • *****
  • Posts: 581
  • jangala delenda est
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4834 on: August 21, 2019, 09:38:15 PM »

So, maybe a dumb question, but... I don't understand EventPlugins.

I've created a copy of part of the NearbyEventPlugin thingy. How do I go about adding it to the EventManager? I only see options to start or prime an event, but I just want to add it on a new game so it stays there and spawns distress calls.  ???

EDIT: Actually, what are the advantages of using an EventPlugin over an EveryFrameScript? It looks like the NearbyEventPlugin distress call bit in particular tracks its own timeout, etc, in an IntervalUtil and the advance() method, just like it would as an EveryFrameScript, so...

EDIT EDIT: While I'm here and asking questions: How would I go about getting the actual ShipAPI/FleetMemberAPI created as a CustomCampaignEntityAPI derelict? I need to add a custom hullmod to it, no matter what hull it is - so i can't just use a custom variant/hull that always has it - is my goal here. I have a sinking feeling it's not actually created until the player interacts with it, but I'm sure there's a way around that.
« Last Edit: August 21, 2019, 10:49:05 PM 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

MrHoon

  • Ensign
  • *
  • Posts: 11
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4835 on: August 22, 2019, 10:42:35 AM »

How does one use applyEffectsToFighterSpawnedByShip with xxxx.getMutableStats? I spent the entire day yesterday trying to make a simple hullmod that adds 25% more armor to fighters but no matter what I try it seems like I just can't seem to understand how anything works with applyEffectsToFighterSpawnedByShip
Logged

Sundog

  • Admiral
  • *****
  • Posts: 1133
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4836 on: August 22, 2019, 01:18:46 PM »

@Varya: I'm afraid I don't have much experience with all that. I might get the chance to look into it later though.

@MrHoon:
That should be as simple as this:
Code
    @Override
    public void applyEffectsToFighterSpawnedByShip(ShipAPI fighter, ShipAPI ship, String id) {
        fighter.getMutableStats().getArmorBonus().modifyPercent(id, 25);
    }

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 17089
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4837 on: August 22, 2019, 01:36:42 PM »

So, maybe a dumb question, but... I don't understand EventPlugins.

I've created a copy of part of the NearbyEventPlugin thingy. How do I go about adding it to the EventManager? I only see options to start or prime an event, but I just want to add it on a new game so it stays there and spawns distress calls.  ???

EDIT: Actually, what are the advantages of using an EventPlugin over an EveryFrameScript? It looks like the NearbyEventPlugin distress call bit in particular tracks its own timeout, etc, in an IntervalUtil and the advance() method, just like it would as an EveryFrameScript, so...

Yeah, just use an EFS - the NearbyEventsEvent is an event only for historical reasons. It used to be required/handy to send out reports, but since the intel system is completely different, "Events" have lost their purpose, code-wise.

EDIT EDIT: While I'm here and asking questions: How would I go about getting the actual ShipAPI/FleetMemberAPI created as a CustomCampaignEntityAPI derelict? I need to add a custom hullmod to it, no matter what hull it is - so i can't just use a custom variant/hull that always has it - is my goal here. I have a sinking feeling it's not actually created until the player interacts with it, but I'm sure there's a way around that.

DerelictShipEntityPlugin plugin = (DerelictShipEntityPlugin) entity.getCustomPlugin();
plugin.getData().ship <- this is a com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special.ShipRecoverySpecial. PerShipData

It could be based on a variantId (i.e. ship.variantId != null), or it may be based on a variant (i.e. ship.variant != null). If there's a variant, you can change it however you like.

If it's based on a variantId, you'll need to set the variant first (to... whatever variant you want, really), but that should also work.


@Varya: I'm afraid I don't have much experience with all that. I might get the chance to look into it later though.

(Thank you for helping out here, btw! Much appreciated.)


@MrHoon:
That should be as simple as this:
Code
    @Override
    public void applyEffectsToFighterSpawnedByShip(ShipAPI fighter, ShipAPI ship, String id) {
        fighter.getMutableStats().getArmorBonus().modifyPercent(id, 25);
    }

Possibly worth noting: the hullmod needs to be on the carrier, *not* on the fighter.
Logged

MrHoon

  • Ensign
  • *
  • Posts: 11
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4838 on: August 22, 2019, 02:04:21 PM »

Thank you guys so much! I didnt realize it had to be fighter.getMutableStats() and I kept doing ship.getMutableStats()

edit

So i tried this and I'm not sure its working?

This is the part of the code I'm working with
Code
public class hhe_FighterPlating extends BaseHullMod {
///
public static final float FIGHTER_ARMOR = 25f;
///
    @Override
public void applyEffectsToFighterSpawnedByShip(ShipAPI fighter, ShipAPI ship, String id) {
fighter.getMutableStats().getArmorBonus().modifyPercent(id, FIGHTER_ARMOR);
}
}


For testing purpose, I changed the FIGHTER_ARMOR = 25f to 5000f , but my fighters are still dying at the same speed as if they didn't have this hull.

Ive been testing this in both run simulation inside a fresh save and the benchmark tester, same results. Is there something else I need to add into the code? (aside from the string)
« Last Edit: August 22, 2019, 03:05:22 PM by MrHoon »
Logged

Vayra

  • Admiral
  • *****
  • Posts: 581
  • jangala delenda est
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4839 on: August 22, 2019, 02:55:44 PM »

It could be based on a variantId (i.e. ship.variantId != null), or it may be based on a variant (i.e. ship.variant != null). If there's a variant, you can change it however you like.

If it's based on a variantId, you'll need to set the variant first (to... whatever variant you want, really), but that should also work.

Thanks so much! I think I can puzzle it out from here.
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

Sundog

  • Admiral
  • *****
  • Posts: 1133
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4840 on: August 22, 2019, 03:50:48 PM »

Ive been testing this in both run simulation inside a fresh save and the benchmark tester, same results. Is there something else I need to add into the code? (aside from the string)
Is that all of the code? If so, it looks like you're missing your package and import lines. It's not strictly necessary, but you'll want to override getDescriptionParam as well. If that's not the problem... Is the hullmod showing up on the carrier? What's your hull_mods.csv look like? Are you sure it points to hhe_FighterPlating correctly?

(Thank you for helping out here, btw! Much appreciated.)
No problem! I figure trying to help with the easier problems in this thread is a way to help compensate for the time you've spent answering all my questions  :)

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 17089
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4841 on: August 22, 2019, 04:26:59 PM »

No problem! I figure trying to help with the easier problems in this thread is a way to help compensate for the time you've spent answering all my questions  :)

;D <3
Logged

Vayra

  • Admiral
  • *****
  • Posts: 581
  • jangala delenda est
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4842 on: August 22, 2019, 04:32:51 PM »

Quick followup question!

Code: java
            DerelictShipEntityPlugin plugin = (DerelictShipEntityPlugin) entity.getCustomPlugin();
            PerShipData shipData = plugin.getData().ship;
            this.variant = shipData.variant;
            if (this.variant == null) {
                this.variant = Global.getSettings().getVariant(shipData.variantId);
            }
            this.variant = this.variant.clone(); // THIS LINE RIGHT HERE
           
            this.variant.addPermaMod("vayra_ghost_ship");

Is this .clone() line necessary to avoid messing up all hound_Assaults across the sector, or does Global.getSettings().getVariant(shipData.variantId) return a unique instance that I can mess with as much as I want?
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: 17089
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4843 on: August 22, 2019, 04:35:49 PM »

Is this .clone() line necessary to avoid messing up all hound_Assaults across the sector,

Correct!
Logged

MrHoon

  • Ensign
  • *
  • Posts: 11
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4844 on: August 22, 2019, 06:25:40 PM »

Ive been testing this in both run simulation inside a fresh save and the benchmark tester, same results. Is there something else I need to add into the code? (aside from the string)
Is that all of the code? If so, it looks like you're missing your package and import lines. It's not strictly necessary, but you'll want to override getDescriptionParam as well. If that's not the problem... Is the hullmod showing up on the carrier? What's your hull_mods.csv look like? Are you sure it points to hhe_FighterPlating correctly?

(Thank you for helping out here, btw! Much appreciated.)
No problem! I figure trying to help with the easier problems in this thread is a way to help compensate for the time you've spent answering all my questions  :)

forgot about the import codes whoops

Code
package data.hullmods.scripts;

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;

I didn't bother doing the description part yet because I wanted to see the mod actually working.

Normally if i messup in the import, I get an error message when i start the mod. Is it possible Im importing the wrong things?
Logged
Pages: 1 ... 321 322 [323] 324 325 ... 459