Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: Need help with simply creating a planet...  (Read 4480 times)

WadeStar

  • Ensign
  • *
  • Posts: 30
    • View Profile
Need help with simply creating a planet...
« on: September 30, 2018, 02:00:23 PM »

Hello community,

I'm having an impossible time understanding what's wrong with my simple mod script that is attempting to add a new planet to the Corvus system. This is a learning exercise.
First, I have tested uncommenting line 44 in  starsector-core\data\scripts\world\corvus\Corvus.java.
This successfully creates "Anomaly A" in the Corvus system when a new game is started.

I have taken this exact line and tried to implement it in my "Test Planet" mod.
This is the only mod I have enabled when starting a new game.

Though "Anomaly A" does get created, interacting with it or the system throws the following NPE:
ERROR com.fs.starfarer.combat.CombatMain  - java.lang.NullPointerException

Here is a full stack trace from the log file:
Spoiler
68926 [Thread-4] ERROR com.fs.starfarer.combat.CombatMain  - java.lang.NullPointerException
java.lang.NullPointerException
   at com.fs.starfarer.campaign.ui.intel.o0OO.void.return$new(Unknown Source)
   at com.fs.starfarer.campaign.ui.intel.o0OO.afterSizeFirstChanged(Unknown Source)
   at com.fs.starfarer.ui.Q.sizeChanged(Unknown Source)
   at com.fs.starfarer.ui.OO0O.set(Unknown Source)
   at com.fs.starfarer.ui.thisnew.super(Unknown Source)
   at com.fs.starfarer.ui.j.advanceImpl(Unknown Source)
   at com.fs.starfarer.ui.Q.advance(Unknown Source)
   at com.fs.starfarer.ui.OO00.advanceImpl(Unknown Source)
   at com.fs.starfarer.campaign.ui.intel.O0oO.advanceImpl(Unknown Source)
   at com.fs.starfarer.ui.Q.advance(Unknown Source)
   at com.fs.starfarer.ui.OO00.advanceImpl(Unknown Source)
   at com.fs.starfarer.campaign.ui.intel.B.advanceImpl(Unknown Source)
   at com.fs.starfarer.ui.Q.advance(Unknown Source)
   at com.fs.starfarer.campaign.ui.intel.B.Ò00000(Unknown Source)
   at com.fs.starfarer.ui.newui.if$7.actionPerformed(Unknown Source)
   at com.fs.starfarer.ui.newui.if.setCurrentTab(Unknown Source)
   at com.fs.starfarer.campaign.CampaignState.showCoreUITab(Unknown Source)
   at com.fs.starfarer.coreui.map.A.super(Unknown Source)
   at com.fs.starfarer.coreui.map.Objectsuper.processInputImpl(Unknown Source)
   at com.fs.starfarer.ui.Q.processInput(Unknown Source)
   at com.fs.starfarer.ui.V.o00000(Unknown Source)
   at com.fs.starfarer.BaseGameState.traverse(Unknown Source)
   at com.fs.state.AppDriver.begin(Unknown Source)
   at com.fs.starfarer.combat.CombatMain.main(Unknown Source)
   at com.fs.starfarer.StarfarerLauncher$1.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
[close]

This is my mod's one-and-only script:

package data.scripts;
Spoiler
import com.fs.starfarer.api.BaseModPlugin;
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.PlanetAPI;
import com.fs.starfarer.api.campaign.SectorAPI;
import com.fs.starfarer.api.campaign.SectorEntityToken;
import com.fs.starfarer.api.campaign.StarSystemAPI;
import com.fs.starfarer.api.impl.campaign.procgen.StarAge;
import com.fs.starfarer.api.impl.campaign.procgen.StarSystemGenerator;

public class TPModPlugin extends BaseModPlugin {
    @Override
    public void onNewGame() {        
   SectorAPI sector = Global.getSector();
        StarSystemAPI system = sector.getStarSystem("Corvus");
        SectorEntityToken star = system.getStar();
        PlanetAPI corvusXa = system.addPlanet("test1", star, "Anomaly Alpha", "lava_minor", 240, 120, 2500, 120);
    }
    /*
    @Override
    public void onNewGameAfterProcGen() {
        //I tried testing it here, too.
    }
    */
}
[close]

You can see how to replicate this problem in the following two videos:
http:\\youtu.be/d7mJrEuTmWg
and
http:\\youtu.be/fTAUJwA4YNE
Would love to get some help with this. I've attached the mod in a .zip also. If you test the mod, please let me know the result. Thanks in advance for any help.

(edit: explicit links in case the actual ones don't show up -- reverse the "\\")

[attachment deleted by admin]
« Last Edit: September 30, 2018, 02:02:56 PM by WadeStar »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Need help with simply creating a planet...
« Reply #1 on: September 30, 2018, 02:18:02 PM »

Hi there - welcome to the forum!

Add the following after adding the planet:
Misc.initConditionMarket(corvusXa);

What happens is the game expects a planet to have a "market" set so that it can have various conditions like "hot" or "habitable" or "rare ore deposits" and so on. A new planet needs to have that created and set or parts of the game that depend on that will crash.

I don't see a reason why one shouldn't get created in addPlanet(), though - so, did that, so this extra bit of code will not be needed in the future. And it *is* a super confusing error message, too.
Logged

WadeStar

  • Ensign
  • *
  • Posts: 30
    • View Profile
Re: Need help with simply creating a planet...
« Reply #2 on: September 30, 2018, 04:02:25 PM »

Thank you! That did the trick. Did I understand you correctly that this is only necessary in 0.8 but should not be necessary in 0.9 on?

Just want to remember to remove it after the next release if so.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Need help with simply creating a planet...
« Reply #3 on: September 30, 2018, 04:11:38 PM »

Yep! Wouldn't do any harm to leave it in, though, so not a big deal if you don't remember to remove it.
Logged

WadeStar

  • Ensign
  • *
  • Posts: 30
    • View Profile
Re: Need help with simply creating a planet...
« Reply #4 on: September 30, 2018, 04:23:12 PM »

One more thing, when adding planets to pre-existing systems (as with the Corvus example above), is it possible to re-order how they appear in the planet display list? Right now "Anomaly Alpha" appears at the end of the list even though its orbit is near the center. I tried a wonky removeEntity() addEntity() loop based on the getPlanets() method but the compiler really didn't like that one (I had a hunch it wouldn't). I also tried updateOrbits(), but I think that's used in-game and isn't a part of initialization.

Or is it that currently once you add a planet to a system, its position in the planet list is permanently cemented?

Thanks again for any guidance. I'm hoping to make a tutorial on this, but even having the information in this thread would be great.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Need help with simply creating a planet...
« Reply #5 on: September 30, 2018, 05:30:16 PM »

Aha. That bit of code was supposed to sort based on distance, but apparently just ... wasn't. I hadn't noticed because it worked due to the add order being equivalent.

In any case, fixed that up for the next release - thanks for bringing it to my attention! I don't think there's any workaround at this point.
Logged

WadeStar

  • Ensign
  • *
  • Posts: 30
    • View Profile
Re: Need help with simply creating a planet...
« Reply #6 on: September 30, 2018, 06:51:55 PM »

Aha! Great, I've demonstrated value, the first step in the D.E.N.N.I.S system.

That's ok if there's no workaround. I want to make this mod/tutorial with the 0.9 release in mind as much as possible. If "updateOrbits()" is the correct method, I'll make a note that it works in 0.9 but not yet in 0.8.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Need help with simply creating a planet...
« Reply #7 on: September 30, 2018, 06:53:51 PM »

updateOrbits just puts stuff at the right coordinates given what their orbit is, basically a way to achieve that w/o having to advance a frame.
Logged