Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: 1 ... 332 333 [334] 335 336 ... 710

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

Ed

  • Captain
  • ****
  • Posts: 442
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4995 on: September 10, 2019, 12:38:55 PM »

So, the way to do this would be a making custom system? I think i get how it would work. I will try later thanks.
Logged
Check out my ships

Sundog

  • Admiral
  • *****
  • Posts: 1727
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4996 on: September 10, 2019, 12:53:44 PM »

No problem. And, yeah, unfortunately I don't think there's a good way to change a ship system's behavior short of creating a copy of it.

Vayra

  • Admiral
  • *****
  • Posts: 627
  • jangala delenda est
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4997 on: September 10, 2019, 01:20:59 PM »

I can confirm that the custom shipsystem AI does work, yes. I have some in my Kadur Remnant mod that you're welcome to use as a template if you like.
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

Ed

  • Captain
  • ****
  • Posts: 442
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4998 on: September 10, 2019, 02:49:41 PM »

I can confirm that the custom shipsystem AI does work, yes. I have some in my Kadur Remnant mod that you're welcome to use as a template if you like.
Thanks man! I learn much faster when i can reverse-engineer something that already works. This really helps.
Logged
Check out my ships

Ed

  • Captain
  • ****
  • Posts: 442
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4999 on: September 10, 2019, 04:07:11 PM »

Does anyone have any idea where is the AI script for FORTRESS_SHIELD? I can find the stats script, but not the AI version.
Logged
Check out my ships

Vayra

  • Admiral
  • *****
  • Posts: 627
  • jangala delenda est
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5000 on: September 10, 2019, 04:32:35 PM »

Is there a way to override the current dialogue and force it into a ship recovery from within that dialog script?

that probably didn't make sense, so here's what I'm trying to do specifically (trimmed slightly for length):

1) Manager EveryFrameScript is added by ModPlugin, and under certain conditions adds Event EveryFrameScript instance and serves it a system (this part works fine, and I'm pretty sure isn't breaking the rest of it)

2) Event EveryFrameScript spawns a derelict, and assigns it some custom special interaction dialogue. That (the spawning and assigning) looks like this:

Code: java
    protected void spawnWreck(StarSystemAPI system) {
       
        WeightedRandomPicker<String> factions = SalvageSpecialAssigner.getNearbyFactions(null, system.getLocation(), 15f, 5f, 5f);
        String faction = factions.pick();
        String variantId = DerelictShipEntityPlugin.pickLargeVariantId(faction, new Random());
        ShipCondition condition = Math.random() > 0.5f ? ShipCondition.PRISTINE : ShipCondition.GOOD;
        DerelictShipEntityPlugin.DerelictShipData params = new DerelictShipEntityPlugin.DerelictShipData(new ShipRecoverySpecial.PerShipData(variantId, condition), false);
       
        params.durationDays = duration;
        entity = (CustomCampaignEntityAPI) BaseThemeGenerator.addSalvageEntity(system, Entities.WRECK, Factions.NEUTRAL, params);
        entity.addTag(Tags.EXPIRES);
       
        DerelictShipEntityPlugin plugin = new DerelictShipEntityPlugin();
        plugin.init(entity, params);
       
        Misc.setSalvageSpecial(entity, (Object) new VayraGhostShipSpecial.VayraGhostShipSpecialData((CustomCampaignEntityAPI) entity));
                   
        entity.setName("Derelict Ship (" + Global.getSettings().getVariant(variantId).getFullDesignationWithHullName() + ")");
    }

3) Here's where it gets complicated. The special interaction dialogue script contains this specialData subclass:

Code
    public static class VayraGhostShipSpecialData implements SalvageSpecialInteraction.SalvageSpecialData {

        public Danger danger;
        public Type type;
        public CustomCampaignEntityAPI entity;
        public ShipVariantAPI variant;

        public VayraGhostShipSpecialData(CustomCampaignEntityAPI entity) {

            this.entity = entity;
            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);
            }
            shipData.variantId = null;
            this.variant = this.variant.clone();

            this.danger = DANGERS.pick();
            log.info("picked danger level " + this.danger);

            if (this.danger.equals(Danger.NONE)) {
                this.type = null;
                log.info("not picking a danger type");
            } else {
                this.type = TYPES.pick();
                log.info("picked danger type " + this.type);
            }
        }

        @Override
        public SalvageSpecialInteraction.SalvageSpecialPlugin createSpecialPlugin() {
            return new VayraGhostShipSpecial();
        }
    }

And does all this:

Code
    @Override
    public void optionSelected(String optionText, Object optionData) {

        if (CONFIRM.equals(optionData)) {
            (a whole bunch of stuff/other options go here)

        } else if (NEVER_AGAIN.equals(optionData)) {
            setDone(true);
            setShowAgain(false);
            setEndWithContinue(false);
        }

        if (recoverable) {
            SalvageSpecialAssigner.ShipRecoverySpecialCreator creator = new SalvageSpecialAssigner.ShipRecoverySpecialCreator(null, 0, 0, false, null, null);
            ShipRecoverySpecialData specialData = (ShipRecoverySpecialData) creator.createSpecial(entity, null);
            Misc.setSalvageSpecial(entity, specialData);
            ShipRecoverySpecial special = new ShipRecoverySpecial();
            special.init(dialog, specialData);
            setDone(true);
            setShowAgain(false);
        }
        }

Problem is, even if recoverable == true, the ship isn't recoverable - like I can't attach a new salvageSpecial to it from inside another salvageSpecial, or while another one is attached or something. :P

Presumably I'm doing something real dumb here, but I can't quite figure out what the "right" way to do this is. Any help would be much appreciated.
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

Vayra

  • Admiral
  • *****
  • Posts: 627
  • jangala delenda est
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5001 on: September 10, 2019, 04:33:21 PM »

Does anyone have any idea where is the AI script for FORTRESS_SHIELD? I can find the stats script, but not the AI version.

Pretty sure only one ShipSystemAI example is provided and it's a dummy script with nothing or almost nothing in it - that's why I volunteered my own scripts as templates.
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: 24126
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5002 on: September 10, 2019, 04:48:11 PM »

Does anyone have any idea where is the AI script for FORTRESS_SHIELD? I can find the stats script, but not the AI version.

Pretty sure only one ShipSystemAI example is provided and it's a dummy script with nothing or almost nothing in it - that's why I volunteered my own scripts as templates.

Correct - the ship system AIs are generally in core code, like the rest of the ship AI. Extricating them from the internal dependencies would be ... troublesome.


@Vayra: this probably isn't the best thread for it because it's too involved, so might be better to have a separate thread for any follow-up. That said, the way you're creating the ship recovery special is missing some stuff. Here's an example creating one for a derelict:

ShipRecoverySpecialData data = new ShipRecoverySpecialData(null);
DerelictShipEntityPlugin plugin = (DerelictShipEntityPlugin) entity.getCustomPlugin();
data.addShip(plugin.getData().ship.clone());
Misc.setSalvageSpecial(entity, data);

The part you're missing is calling .addShip() for the ShipRecoverySpecialData.

The other issue is the flow of it - you're already in a "special" interaction, and when it ends, it'll unset the "special" data in the entity memory, since you've called setShowAgain(false). You want to call setShowAgain(true), so that it keeps the special data around (the code is assuming it's the old data, but it'll be the data you switched in using Misc.setSalvageSpecial.

However, even with that, I don't believe it'll chain to showing that special - it'll move on straight to salvage, per the sal_specialFinished rule. What you'll want to do is create another rule for the SalvageSpecialFinished trigger (and set a variable in entity memory from your "if (recoverable) {" block so you can tell when to use this rule), and have that rule "FireBest CheckSalvageSpecial" so that on finishing salvage, it loops back around to check for the special again, this time it being the newly-set ship recovery special.

Hope that makes sense!


Logged

Vayra

  • Admiral
  • *****
  • Posts: 627
  • jangala delenda est
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5003 on: September 10, 2019, 04:51:55 PM »

Does anyone have any idea where is the AI script for FORTRESS_SHIELD? I can find the stats script, but not the AI version.

Pretty sure only one ShipSystemAI example is provided and it's a dummy script with nothing or almost nothing in it - that's why I volunteered my own scripts as templates.

Correct - the ship system AIs are generally in core code, like the rest of the ship AI. Extricating them from the internal dependencies would be ... troublesome.


@Vayra: this probably isn't the best thread for it because it's too involved, so might be better to have a separate thread for any follow-up. That said, the way you're creating the ship recovery special is missing some stuff. Here's an example creating one for a derelict:

ShipRecoverySpecialData data = new ShipRecoverySpecialData(null);
DerelictShipEntityPlugin plugin = (DerelictShipEntityPlugin) entity.getCustomPlugin();
data.addShip(plugin.getData().ship.clone());
Misc.setSalvageSpecial(entity, data);

The part you're missing is calling .addShip() for the ShipRecoverySpecialData.

The other issue is the flow of it - you're already in a "special" interaction, and when it ends, it'll unset the "special" data in the entity memory, since you've called setShowAgain(false). You want to call setShowAgain(true), so that it keeps the special data around (the code is assuming it's the old data, but it'll be the data you switched in using Misc.setSalvageSpecial.

However, even with that, I don't believe it'll chain to showing that special - it'll move on straight to salvage, per the sal_specialFinished rule. What you'll want to do is create another rule for the SalvageSpecialFinished trigger (and set a variable in entity memory from your "if (recoverable) {" block so you can tell when to use this rule), and have that rule "FireBest CheckSalvageSpecial" so that on finishing salvage, it loops back around to check for the special again, this time it being the newly-set ship recovery special.

Hope that makes sense!

Thanks! I'll try to work it out when I get home, and make a thread if (when, tbh) I run into any trouble.  ;D
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: 24126
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5004 on: September 10, 2019, 04:57:26 PM »

Thanks! I'll try to work it out when I get home, and make a thread if (when, tbh) I run into any trouble.  ;D

A realist, I see :)

(Edit: if for some reason I don't respond in that thread in some kind of reasonable time, ping me - probably means I got sidetracked and forgot to check for it.)
Logged

Ed

  • Captain
  • ****
  • Posts: 442
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5005 on: September 10, 2019, 05:19:51 PM »

Does anyone have any idea where is the AI script for FORTRESS_SHIELD? I can find the stats script, but not the AI version.

Pretty sure only one ShipSystemAI example is provided and it's a dummy script with nothing or almost nothing in it - that's why I volunteered my own scripts as templates.

I am studying your code, but i would like to know what exactly is in the fortress shield AI since I am implementing a slightly different version of it.

Also guys how do i get the parent module of a module in a ship?

ship.getParentStation() is returning null, my ship does have SHIP_WITH_MODULES tag and all.

Edit to make things clear

This is the ship
Code
Rottweiler,edshipyard_rottweiler,Heavy Cruiser,ED Shipyard,fortressshield,17,8000,1500,10000,9000,450,175,,30,20,10,12,12,2250,FRONT,,150,0.6,0.6,,,200,300,150,150,5,30,8,175000,4,12,540,0.25,28,28,SHIP_WITH_MODULES,rare_bp,,0.4,2,3,404

This is the module
Code
,edshipyard_leonberger_midplate,Shield Module,,module_fortressshield,1,2000,1200,7400,5000,250,24,,0,0,0,10,10,600,FRONT,,90,0.1,1,,,0,0,0,0,1,0,,75000,,1,840,0.25,0,0,"UNBOARDABLE, HIDE_IN_CODEX",,,0.5,2,3,2100

I am editing the module_fortressshield, so that the module don't use it while the parent shield is on.
« Last Edit: September 10, 2019, 05:22:22 PM by Ed »
Logged
Check out my ships

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24126
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5006 on: September 10, 2019, 05:22:03 PM »

Also guys how do i get the parent module of a module in a ship?

ship.getParentStation() is returning null, my ship does have SHIP_WITH_MODULES tag and all.

getParentStation() should really do the job, afaik stations and SHIP_WITH_MODULES aren't treated differently there. If it's not, hmm - maybe you're calling it on the wrong ship or some such?
Logged

Ed

  • Captain
  • ****
  • Posts: 442
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5007 on: September 10, 2019, 05:25:04 PM »


getParentStation() should really do the job, afaik stations and SHIP_WITH_MODULES aren't treated differently there. If it's not, hmm - maybe you're calling it on the wrong ship or some such?

this is my init, this is called on the module AI (module_fortressshield)

Code
public void init(ShipAPI ship, ShipSystemAPI system, ShipwideAIFlags flags, CombatEngineAPI engine) {
        this.ship = ship;
        this.flags = flags;
        this.system = system;
        this.engine = engine;

        parent = ship.getParentStation();
        if(parent != null) { // <- if i remove this i get a crash on this line (nullpointer)
        parentFlags = parent.getAIFlags();// <-- code never gets here when i test
        }       
}
Logged
Check out my ships

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24126
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5008 on: September 10, 2019, 05:28:08 PM »

Ah - it's probably null at this point since the module is just being created and hadn't been added to the parent ship yet.
Logged

Ed

  • Captain
  • ****
  • Posts: 442
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5009 on: September 10, 2019, 05:30:52 PM »

Ah - it's probably null at this point since the module is just being created and hadn't been added to the parent ship yet.
Oh, i see, so i should make it look for a parent during the activate loop then?
Logged
Check out my ships
Pages: 1 ... 332 333 [334] 335 336 ... 710