Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: How to add Derelict hulls to an existing starsystem.  (Read 2381 times)

Gwyvern

  • Captain
  • ****
  • Posts: 318
  • I build ships.
    • View Profile
How to add Derelict hulls to an existing starsystem.
« on: November 22, 2018, 07:55:28 PM »

Hello, I am trying to figure something out for later, but I have completely hit a brick wall and am at the end of my rope here.

https://pastebin.com/PEnw0D4j

How do you add a wreck to a system that already exists? All of the existing methods I have found do so ONLY after generating a token and adding them within the token's purview, this method does not seem capable of functioning when you are trying to append things to an existing system using a separate script.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24123
    • View Profile
Re: How to add Derelict hulls to an existing starsystem.
« Reply #1 on: November 22, 2018, 08:20:34 PM »

Didn't look too too closely, but: does the tutorial ship graveyard around Tetra fit the bill? The code's in data.scripts.world.systems.Galatia.java
Logged

Gwyvern

  • Captain
  • ****
  • Posts: 318
  • I build ships.
    • View Profile
Re: How to add Derelict hulls to an existing starsystem.
« Reply #2 on: November 22, 2018, 08:25:16 PM »

Didn't look too too closely, but: does the tutorial ship graveyard around Tetra fit the bill? The code's in data.scripts.world.systems.Galatia.java

No, that was the first place I looked, using this method without first creating a new planet via sector entity token doesn't seem to work.
« Last Edit: November 22, 2018, 08:31:58 PM by Gwyvern »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24123
    • View Profile
Re: How to add Derelict hulls to an existing starsystem.
« Reply #3 on: November 22, 2018, 08:39:29 PM »

I guess I'm not understanding the issue. The code snippet you linked can't work, btw, because there's no addDerelict() method in that class (unless I'm missing something obvious, which I might be because lack of sleep, in which case apologies).

And the addDerelict() method in Galatia.java doesn't depend on just having added the planet.

I guess what I'm saying is, it's not clear from what you're saying what the actual issue is :)
Logged

Machine

  • Commander
  • ***
  • Posts: 114
    • View Profile
Re: How to add Derelict hulls to an existing starsystem.
« Reply #4 on: November 22, 2018, 08:41:03 PM »

Currently using this script, I made based on Alex's tutorial, to spawn my derelicts
Code
package data.scripts.world;

import com.fs.starfarer.api.campaign.SectorEntityToken;
import com.fs.starfarer.api.campaign.StarSystemAPI;
import com.fs.starfarer.api.impl.campaign.DerelictShipEntityPlugin.DerelictShipData;
import com.fs.starfarer.api.impl.campaign.ids.Entities;
import com.fs.starfarer.api.impl.campaign.ids.Factions;
import com.fs.starfarer.api.impl.campaign.procgen.themes.BaseThemeGenerator;
import com.fs.starfarer.api.impl.campaign.procgen.themes.SalvageSpecialAssigner.ShipRecoverySpecialCreator;
import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special.ShipRecoverySpecial.PerShipData;
import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special.ShipRecoverySpecial.ShipCondition;

import com.fs.starfarer.api.util.Misc;

public class TSC_AddDerelict {
   
    public static SectorEntityToken addDerelict(StarSystemAPI system, SectorEntityToken focus, String variantId,
            ShipCondition condition, float orbitRadius, boolean recoverable) {       
       
        DerelictShipData params = new DerelictShipData(new PerShipData(variantId, condition), false);
        SectorEntityToken ship = BaseThemeGenerator.addSalvageEntity(system, Entities.WRECK, Factions.NEUTRAL, params);
        ship.setDiscoverable(true);

        float orbitDays = orbitRadius / (10f + (float) Math.random() * 5f);
        ship.setCircularOrbit(focus, (float) Math.random() * 360f, orbitRadius, orbitDays);

        if (recoverable) {
            ShipRecoverySpecialCreator creator = new ShipRecoverySpecialCreator(null, 0, 0, false, null, null);
            Misc.setSalvageSpecial(ship, creator.createSpecial(ship, null));
        }
        return ship;
    }
}

Tried it on penelope's star, and it worked. Granted I had to get all planets in the system and then select the one I wanted from the list.
Code
        //Ship Recovery Test
        SectorEntityToken Arcon_Adarga_D = TSC_AddDerelict.addDerelict(
                system, //Star system
                system.getPlanets().get(1), //Orbital focus
                "TSC_Adarga_D_Attack", //Variant Id
                ShipRecoverySpecial.ShipCondition.BATTERED, //Ship condition
                550f, //Orbital radius
                true //Recoverable?
        );
Logged

Gwyvern

  • Captain
  • ****
  • Posts: 318
  • I build ships.
    • View Profile
Re: How to add Derelict hulls to an existing starsystem.
« Reply #5 on: November 22, 2018, 09:42:04 PM »

Spoiler
Currently using this script, I made based on Alex's tutorial, to spawn my derelicts
Code
package data.scripts.world;

import com.fs.starfarer.api.campaign.SectorEntityToken;
import com.fs.starfarer.api.campaign.StarSystemAPI;
import com.fs.starfarer.api.impl.campaign.DerelictShipEntityPlugin.DerelictShipData;
import com.fs.starfarer.api.impl.campaign.ids.Entities;
import com.fs.starfarer.api.impl.campaign.ids.Factions;
import com.fs.starfarer.api.impl.campaign.procgen.themes.BaseThemeGenerator;
import com.fs.starfarer.api.impl.campaign.procgen.themes.SalvageSpecialAssigner.ShipRecoverySpecialCreator;
import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special.ShipRecoverySpecial.PerShipData;
import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special.ShipRecoverySpecial.ShipCondition;

import com.fs.starfarer.api.util.Misc;

public class TSC_AddDerelict {
   
    public static SectorEntityToken addDerelict(StarSystemAPI system, SectorEntityToken focus, String variantId,
            ShipCondition condition, float orbitRadius, boolean recoverable) {       
       
        DerelictShipData params = new DerelictShipData(new PerShipData(variantId, condition), false);
        SectorEntityToken ship = BaseThemeGenerator.addSalvageEntity(system, Entities.WRECK, Factions.NEUTRAL, params);
        ship.setDiscoverable(true);

        float orbitDays = orbitRadius / (10f + (float) Math.random() * 5f);
        ship.setCircularOrbit(focus, (float) Math.random() * 360f, orbitRadius, orbitDays);

        if (recoverable) {
            ShipRecoverySpecialCreator creator = new ShipRecoverySpecialCreator(null, 0, 0, false, null, null);
            Misc.setSalvageSpecial(ship, creator.createSpecial(ship, null));
        }
        return ship;
    }
}

Tried it on penelope's star, and it worked. Granted I had to get all planets in the system and then select the one I wanted from the list.
Code
        //Ship Recovery Test
        SectorEntityToken Arcon_Adarga_D = TSC_AddDerelict.addDerelict(
                system, //Star system
                system.getPlanets().get(1), //Orbital focus
                "TSC_Adarga_D_Attack", //Variant Id
                ShipRecoverySpecial.ShipCondition.BATTERED, //Ship condition
                550f, //Orbital radius
                true //Recoverable?
        );
[close]

Thank you! This is exactly what I needed!
Logged