Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: Combat map question for modders  (Read 1999 times)

SatchelCharge

  • Lieutenant
  • **
  • Posts: 96
    • View Profile
Combat map question for modders
« on: September 15, 2013, 09:11:12 AM »

Is there an easy way to change the combat map back to empty space? Having a planet hanging out in the battle at all times distracts me from looking at the ships and their stats.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Combat map question for modders
« Reply #1 on: September 15, 2013, 03:51:43 PM »

Yeah, provide a ModPlugin with something like this in the onGameLoad method:

Spoiler
public void onGameLoad() {
      log.info("-------------onGameLoad");
      
      Global.getSector().registerPlugin(new BaseCampaignPlugin() {
         public PluginPick<BattleCreationPlugin> pickBattleCreationPlugin(
               SectorEntityToken opponent) {
            return new PluginPick<BattleCreationPlugin>(new BattleCreationPlugin() {
               public void initBattle(BattleCreationContext context,
                                 MissionDefinitionAPI loader) {
                  CampaignFleetAPI playerFleet = context.getPlayerFleet();
                  CampaignFleetAPI otherFleet = context.getOtherFleet();
                  FleetGoal playerGoal = context.getPlayerGoal();
                  FleetGoal enemyGoal = context.getOtherGoal();
                  int baseCommandPoints = (int) Global.getSettings().getFloat("startingCommandPoints");
                  
                  float width = 10000;
                  float height = 10000;
                  loader.initMap((float)-width/2f, (float)width/2f, (float)-height/2f, (float)height/2f);
                  
                  loader.initFleet(FleetSide.PLAYER, "ISS", playerGoal, false,
                        (int) playerFleet.getCommanderStats().getCommandPoints().getModifiedValue() - baseCommandPoints);
                  loader.initFleet(FleetSide.ENEMY, "", enemyGoal, true,
                        (int) otherFleet.getCommanderStats().getCommandPoints().getModifiedValue() - baseCommandPoints);

                  List<FleetMemberAPI> playerShips = playerFleet.getFleetData().getCombatReadyMembersListCopy();
                  if (playerGoal == FleetGoal.ESCAPE) {
                     playerShips = playerFleet.getFleetData().getMembersListCopy();
                  }
                  for (FleetMemberAPI member : playerShips) {
                     loader.addFleetMember(FleetSide.PLAYER, member);
                  }
                  
                  
                  List<FleetMemberAPI> enemyShips = otherFleet.getFleetData().getCombatReadyMembersListCopy();
                  if (enemyGoal == FleetGoal.ESCAPE) {
                     enemyShips = otherFleet.getFleetData().getMembersListCopy();
                  }
                  for (FleetMemberAPI member : enemyShips) {
                     loader.addFleetMember(FleetSide.ENEMY, member);
                  }
                  
               }
               
            }, PickPriority.MOD_GENERAL);
         }
         
      });
   }
[close]

Basically, you just want to override battle creation so that it doesn't show a nearby planet. Or create a test mission. Or fight away from planets.
Logged

Uomoz

  • Admiral
  • *****
  • Posts: 2663
  • 'womo'dz
    • View Profile
Re: Combat map question for modders
« Reply #2 on: September 15, 2013, 04:29:12 PM »

Being an opportunistic prick, is it possible to create something similar to edit the station behavior? (like text choices, adding new lines to their menus). I kind of narrowed down the thing but I'm stuck on some compilation error that makes me think that I may be completely off the mark.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Combat map question for modders
« Reply #3 on: September 15, 2013, 04:59:24 PM »

Yes, definitely possible.

(Not exactly "edit", though, but "replace wholesale for all stations or for specific stations, depending on what you want".)
Logged

Uomoz

  • Admiral
  • *****
  • Posts: 2663
  • 'womo'dz
    • View Profile
Re: Combat map question for modders
« Reply #4 on: September 15, 2013, 05:09:13 PM »

Nice! I went and grabbed the impl version of the plugin in the api.zip. I guess I have to edit the implementation you posted from:

Spoiler
public PluginPick<BattleCreationPlugin> pickBattleCreationPlugin(
               SectorEntityToken opponent) {
            return new PluginPick<BattleCreationPlugin>(new BattleCreationPlugin() {
[close]

changing them to the relative station-dialogue plugin and then start the class where

Spoiler
public void initBattle(BattleCreationContext context,
                                 MissionDefinitionAPI loader) {
[close]

is?

I hope I get the message through, I've never taken a programming class and I'm trying expressing this at best.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: Combat map question for modders
« Reply #5 on: September 15, 2013, 05:26:11 PM »

Yeah, I think you got the right idea.

You're also going to run into a bit of trouble where the plugin from the api.zip won't compile. The game uses Janino (a 3rd party Java compiler) to compile stuff on startup, but it doesn't support some convenient language features. The stuff in the api.zip is precompiled and shipped as .class files inside starfarer.api.jar, so isn't compiled by Janino on startup (not doing which, incidentally, speeds up the startup time  good bit.)

The main features that it doesn't support are:
1) Generics
2) The use of enums in switch statements

As far as I can see, the OrbitalStationInteractionDialogPluginImpl in api.zip does not use generics. But it does use an enum in a switch statement, so you'll have to change that to a if/else if/else if/etc to get it to compile on startup.

For example, in optionSelected(), it has:
      switch (option) {
      case INIT:
         // do stuff
         break;
      case TRADE_CARGO:
         // do stuff
         break;
And you'd want to change that to something like:
      if (option == OptionId.INIT) {
         // do stuff
      } else if (option == OptionId.TRADE_CARGO) {
         // do stuff
      }



Also, you may want to implement your plugin as a separate class, in another file, rather than an anonymous class inlined in the method. Just for the sake of convenience/sanity.

Edit: I'm assuming some of this won't quite make sense but hoping that it's enough to look stuff up off of and make it make sense. Feel free to ask followup questions, though - I'll try to get to 'em. In between all the bugfixing. Or maybe LazyWizard will come in to save the day, as he generally does :)
« Last Edit: September 15, 2013, 05:27:58 PM by Alex »
Logged