Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Custom Interaction Dialog Example  (Read 15743 times)

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 17042
    • View Profile
Custom Interaction Dialog Example
« on: September 25, 2013, 10:15:54 AM »

Download it here.

Overview

This mod provides a simple example of a custom campaign interaction dialog. The code is written so that it avoids using anything that Janino (the compiler used by Starsector) can't handle. So, the source files can be compiled by the game on startup, but the code isn't as clean as it could be.

Key features:
  • Does not require external compilation or use jar files, everything compiled with Janino
  • Adds a custom interaction for asteroids - they can be searched for hidden supply caches
  • Keeps track of asteroids searched and supplies remaining in any found cache using SectorAPI.getPersistentData()
  • Can be added to an existing savegame, can not be removed from one


Files

mod_info.json
Standard mod descriptor. Points to MyModPlugin.java.

data/scripts/AsteriodInteractionDialogPlugin.java
Contains all the code that drives the asteroid interaction dialog.

data/scripts/MyCampaignPlugin.java
Tells the game to use the AsteriodInteractionDialogPlugin for interactions with asteroids.

data/scripts/MyModPlugin.java
Registers MyCampaignPlugin when a savegame is run with this mod for the first time.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 17042
    • View Profile
Re: Custom Interaction Dialog Example
« Reply #1 on: September 25, 2013, 11:15:38 AM »

(Unlocking this because it seems to make less sense to lock something that's an example rather than actual documentation.)
Logged

frag971

  • Commander
  • ***
  • Posts: 242
    • View Profile
    • Email
Re: Custom Interaction Dialog Example
« Reply #2 on: September 25, 2013, 11:46:05 AM »

Sweet. Will this allow, say, to approach an asteroid or planet but instead of an empty dialog panel we would get some sort of mini text quest within that panel that, upon proper choices in that dialog tree would reward me with loot?

Something like this?:

Some signal comes from that asteroid
>approach asteroid carefully
_ignore the asteroid

Scanning the asteroid reveals something on its surface, no life signs
_scan the asteroid (might trigger a trap)
>send a team of marines to examine (might trigger trap, rewards loot)
_shoot it (safe but no loot)

The marines sucessfully retrieve the artifact, upon close inspection a virus took over your ship and kill the crew by asphixiation!
>attempt to retake the ship! (battle)
_attempt to hack the virus and retake control (might infect the fleet)
_run away and save the fleet (safely leave, the ship becomes a hostile-to-all enemy "fleet")
Logged
Let's say I'm captaining the ISS Slightly Lopsided Isosceles Triangle here.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 17042
    • View Profile
Re: Custom Interaction Dialog Example
« Reply #3 on: September 25, 2013, 11:51:17 AM »

Yeah, you could do something like that. It'd be a little more involved than the example, but not by all that much.

Sweet. Will this allow, say, to approach an asteroid or planet but instead of an empty dialog panel

Do you mean that you've tried the mod and are getting an empty dialog panel when interacting with an asteroid? What you should be getting is 1 line of text ("Your fleet approaches the asteroid."), an image of some wreckage on the right, and two options - "Send down a survey team" and "Leave".
Logged

Gothars

  • Global Moderator
  • Admiral
  • *****
  • Posts: 4213
  • Eschewing obfuscatory verbosity.
    • View Profile
Re: Custom Interaction Dialog Example
« Reply #4 on: September 28, 2013, 03:40:24 PM »

Do you mean that you've tried the mod and are getting an empty dialog panel when interacting with an asteroid? What you should be getting is 1 line of text ("Your fleet approaches the asteroid."), an image of some wreckage on the right, and two options - "Send down a survey team" and "Leave".

Works fine for me.
Logged

Uomoz

  • Admiral
  • *****
  • Posts: 2663
  • 'womo'dz
    • View Profile
    • Email
Re: Custom Interaction Dialog Example
« Reply #5 on: September 28, 2013, 06:42:35 PM »

Thanks Alex! You know we love you (I speak for Psyion aswell).
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 4863
  • naively breaking things!
    • View Profile
Re: Custom Interaction Dialog Example
« Reply #6 on: November 06, 2013, 01:57:22 PM »

I've finally gotten around to messing with this, and have written a new Asteroid "mining" system that destroys the Asteroid when you're done.

Anyhow, I took a look at the FleetInteractionDialogPluginImpl, because I'm contemplating doing a custom, Janino-friendly version that changes things, but I'm really confused thus far :)

I have figured out the basics:

1.  playerFleet and otherFleet are determined at the start of the script via who's talking to whom.
2.  dialog.startBattle(BattleCreationContext) takes us to a Battle.
3.  After a Battle, I presume that backFromEngagement() is called immediately.  I'm not sure how the cases are working there, though.

Stuff I'm confused about:
1.  I'm not sure how we get to the Loot screen, or how the Loot screen is populated with Stuff.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Zaphide

  • Admiral
  • *****
  • Posts: 799
    • View Profile
Re: Custom Interaction Dialog Example
« Reply #7 on: November 06, 2013, 02:15:28 PM »

You'll want to look at FleetEncounterContext.java, as it seems to control the loot-related stuff. See the method scrapDisabledShipsAndGenerateLoot.

The first call in backFromEngagement is FleetEncounterContext.processEngagementResults(), which passes off to the FleetEncounterContext.

Sorry I haven't really played round with it that much.
Logged

Okim

  • Admiral
  • *****
  • Posts: 2146
    • View Profile
    • Okim`s Modelling stuff
Re: Custom Interaction Dialog Example
« Reply #8 on: November 07, 2013, 02:28:11 AM »

Exactly as Zaphide says - FleetEncounterContext is what you need to look at.

Note that changing it is tricky as it will require you to change a lot of other scripts in terms of sources/names.

I for one use the copy of that script placed in a data/scripts folder from where it is accessed by IroncladsFleetInteractionDialogue plugin (which is also a modified version of core script).

I recommend using some specialised editor like Intelij IDEA. Its free and provides a lot of help and support. It also fixes errors and misspells :)

Ragni

  • Ensign
  • *
  • Posts: 32
    • View Profile
Re: Custom Interaction Dialog Example
« Reply #9 on: May 30, 2017, 03:46:48 PM »

Mod is slightly out of date;

To fix the incompatability:

Add

Code
@Override
    public Map<String, MemoryAPI> getMemoryMap() {
        return null;
    }

to the AsteriodInteractionDialogPlugin Class

Method is not used by the mod, so it is safe to just return null.
« Last Edit: May 30, 2017, 08:10:16 PM by Ragni »
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 4863
  • naively breaking things!
    • View Profile
Re: Custom Interaction Dialog Example
« Reply #10 on: August 14, 2017, 09:20:46 AM »

Thank you for updating that; I was thinking of putting Asteroid-mining back in as a mini-mod.
Logged
Please check out my SS projects :)
Xeno's Mod Pack