Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: more ships on the market  (Read 6964 times)

Venatos

  • Ensign
  • *
  • Posts: 42
    • View Profile
more ships on the market
« on: November 01, 2014, 04:36:10 AM »

hi there,

after circling the universe several times in search for an Odyssey or an Eagle i decided that there are not enough ships on the market and startet to look into the code.
goal is to roughly double the amount of ships that are sold, so that there is a greater chance to find what your searching for and not waste your precious hours of gametime.

my search lead me to starfarer.api.zip\com\fs\starfarer\api\impl\campaign\submarkets and for testing i took the blackmarketplugin and tryed a few things:

   private void addShips() {
      int marketSize = market.getSize();
      
      pruneShips(0.75f);
      
      WeightedRandomPicker<String> rolePicker = new WeightedRandomPicker<String>();
      rolePicker.add(ShipRoles.CIV_RANDOM, 5f);
      rolePicker.add(ShipRoles.FREIGHTER_SMALL, 3f);
      rolePicker.add(ShipRoles.TANKER_SMALL, 1f);
      rolePicker.add(ShipRoles.COMBAT_FREIGHTER_SMALL, 15f);
      rolePicker.add(ShipRoles.COMBAT_SMALL, 15f);
      rolePicker.add(ShipRoles.COMBAT_MEDIUM, 15f);
      rolePicker.add(ShipRoles.INTERCEPTOR, 5f);
      rolePicker.add(ShipRoles.FIGHTER, 5f);
      rolePicker.add(ShipRoles.BOMBER, 5f);
i added these 5 lines ->      rolePicker.add(ShipRoles.FREIGHTER_MEDIUM, 5f);
      rolePicker.add(ShipRoles.TANKER_MEDIUM, 1f);
      rolePicker.add(ShipRoles.COMBAT_FREIGHTER_MEDIUM, 10f);
      rolePicker.add(ShipRoles.COMBAT_MEDIUM, 10f);
      rolePicker.add(ShipRoles.CARRIER_SMALL, 10f);
      
      if (marketSize >= 4) {
         rolePicker.add(ShipRoles.FREIGHTER_MEDIUM, 5f);
         rolePicker.add(ShipRoles.TANKER_MEDIUM, 1f);
         rolePicker.add(ShipRoles.COMBAT_FREIGHTER_MEDIUM, 10f);
         rolePicker.add(ShipRoles.COMBAT_MEDIUM, 10f);
         rolePicker.add(ShipRoles.CARRIER_SMALL, 10f);
      }
      
      if (marketSize >= 6) {
         rolePicker.add(ShipRoles.FREIGHTER_LARGE, 3f);
         rolePicker.add(ShipRoles.TANKER_LARGE, 1f);
         rolePicker.add(ShipRoles.COMBAT_FREIGHTER_LARGE, 5f);
         rolePicker.add(ShipRoles.COMBAT_LARGE, 5f);
         rolePicker.add(ShipRoles.CARRIER_MEDIUM, 10f);
      }
      
      WeightedRandomPicker<FactionAPI> factionPicker = new WeightedRandomPicker<FactionAPI>();
      float stability = market.getStabilityValue();
      factionPicker.add(market.getFaction(), 10f - stability);
      factionPicker.add(submarket.getFaction(), 10f);
      
i changed marketsize *2 to *5      addShipsForRoles(marketSize * 5, rolePicker, factionPicker);
   }

all seamingly without effect, i am stuck at the moment, i need someone elses brain for a second.
anyone have an idea to what to change where? im also looking into making ai fleets bigger, as to mitigate the roflstomping in the endgame, but all i found there so far is a way to change the starting logistic points for myself from 20 to 5, which should help a bit.
any input is welcome!
thnks! ;)
Logged

Sundog

  • Admiral
  • *****
  • Posts: 1727
    • View Profile
Re: more ships on the market
« Reply #1 on: November 01, 2014, 05:29:45 AM »

It looks to me like you're on the right track based on a quick look at BaseSubmarketPlugin.addShipsForRoles(). You make it sound like you're editing the java files inside the API archive though, which won't change anything at all. Afaik, starfarer.api.zip is only there for convenience and the game doesn't actually use it. I'm pretty sure it does use starfarer.api.jar, and you might be able to replace that with your own jar to make your changes, put that's not the best idea, especially if you want to make a publicly available mod. There should be a proper way to replace a file like that with one of your own, but I haven't done anything like that yet, so I'd have to learn it myself in order to tell you how. Hopefully someone here who's messed with replacing API implementation will be able to give you a hand.

Venatos

  • Ensign
  • *
  • Posts: 42
    • View Profile
Re: more ships on the market
« Reply #2 on: November 01, 2014, 06:27:45 AM »

hehe, yes i was changing things in the .zip file and wondered why nothing happened... in case it wasnt clear bevore, it devinatly is now -> i have no idea what im doing. :D
thnx for pointing that out, i thought it would load the zip-file.

im actually not planing so far ahead, first ill try to make it run on my pc so i can play it. ill post my findings and see where its going from there.
i might make a few other teaks and call it a mod, but that wasnt the plan in the beginning.

anyway, thnx again for pointing me in the right direction, where the changes i make actually do something. lol
Logged

Venatos

  • Ensign
  • *
  • Posts: 42
    • View Profile
Re: more ships on the market
« Reply #3 on: November 01, 2014, 08:32:27 AM »

ok, i realy have trouble compiling my modified BlackMarketPlugin.java into a .class file... javac and eclipse just give me loads of errors.
i´ve tryed the file alone and the whole flipin starfarer.api.zip, without luck so far.
can someone who knows java tell me how to do it? im not lazy, im trying to compile that fing file for 6 hours now, i just never used java bevor.
im hungry, i need a break...
Logged

Darloth

  • Admiral
  • *****
  • Posts: 592
    • View Profile
Re: more ships on the market
« Reply #4 on: November 01, 2014, 08:52:22 AM »

Even after you compile it, you still need to get the game to use it.

All mods are required to implement a ModPlugin, which usually has a CampaignPlugin which then tells the campaign engine which bits the mod overrides.

You want to make a new BlackMarketPlugin, and then tell the campaign to use yours instead of the original one, which amusingly enough is the bit I've just forgotten how to do...

More once I find an example and do it myself.
In terms of compiling, there's various guides for getting Starsector mods to compile in the modding tools and resources thread:
http://fractalsoftworks.com/forum/index.php?topic=633.0

At a guess, are you having trouble getting your .jar to reference the starsector library jar and all of the other required library jars?  I can't tell you how to do this with Eclipse, but I do have a guide for IntelliJ here: http://fractalsoftworks.com/forum/index.php?topic=6809.0
« Last Edit: November 01, 2014, 09:42:17 AM by Darloth »
Logged

Venatos

  • Ensign
  • *
  • Posts: 42
    • View Profile
Re: more ships on the market
« Reply #5 on: November 01, 2014, 12:17:34 PM »

thnx for the help, i followed the guide for eclipse modding tutorial and configured it.
sadly that didnt realy help, the .java file is still not getting compiled without errors...
i realy didnt think that changing one function in a class can be such a pain. and the worst thing is i dont even know that if i succeeded it would do what i want.
the idea was to try out some simple code changes to see if im in the right spot, not to f around a whole day without any result.
i couldnt do it today, but i used to write C and C++ code in notepad, put all the files into a compiler and presto, a new programm was born. java code is easy to read, although i still dont like that its so unspecific and automated, but the compiling and presto part seems alot more complicated than i was used to.
i might take another stab at it tomorow, but i dont plan to go through the whole weekend without gaming. ;)

EDIT: btw. for now the plan is just to compile the BlackMarketPlugin.java into .class and overwrite the original inside starfarer.api.jar with it for quick testing.(ofcourse i have a backup of starfarer.api.jar)
« Last Edit: November 01, 2014, 12:20:42 PM by Venatos »
Logged

Darloth

  • Admiral
  • *****
  • Posts: 592
    • View Profile
Re: more ships on the market
« Reply #6 on: November 01, 2014, 01:36:11 PM »

If you post the exact error message we'd have a lot more chance to be able to fix it for you, or at least give you some pointers.
Logged

Zaphide

  • Admiral
  • *****
  • Posts: 799
    • View Profile
Re: more ships on the market
« Reply #7 on: November 01, 2014, 03:29:20 PM »

EDIT: btw. for now the plan is just to compile the BlackMarketPlugin.java into .class and overwrite the original inside starfarer.api.jar with it for quick testing.(ofcourse i have a backup of starfarer.api.jar)

Is this even possible? Won't you have to re-compile the whole of starfarer.api.jar? But you don't have the source for a lot of the classes in it... (admittedly I know next to nothing about Java packaging)

Anyway, I think you are much better off just creating a small mod that replaces the core BlackMarketPlugin with your own. It's still not a small job but I suspect trying to re-compile starfarer.api.jar would be far more difficult.

The submarkets (and associated scripts) are defined in data/campaign/submarkets.csv. Your mod would have a submarket.csv where you define the new black market e.g:
Code
id,name,faction,desc,script,icon,order
black_market,"Black Market",pirates,"The (MODIFIED) black market",package.part.of.ModifiedBlackMarketPlugin,graphics/factions/black_market.png,999

Your mod would then need ModifiedBlackMarketPlugin (either pre-compiled in a jar, or available so Janino can compile it). You may need to remove the black_market entry from StarSector-core's submarket.csv file as I'm not sure if your new definition would override it by default.
Logged

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: more ships on the market
« Reply #8 on: November 01, 2014, 03:43:48 PM »

The source for all the impl files are inside starfarer.api.zip, as are all the API interface files, you can recompile the whole starfarer.api.jar
Logged

Darloth

  • Admiral
  • *****
  • Posts: 592
    • View Profile
Re: more ships on the market
« Reply #9 on: November 01, 2014, 07:21:15 PM »

<gumball>or CAN you?</gumball>

Explanation: Actually it doesn't work quite right now if you do that. Also that episode of Gumball. It's 2am here.
Logged

Venatos

  • Ensign
  • *
  • Posts: 42
    • View Profile
Re: more ships on the market
« Reply #10 on: November 02, 2014, 01:29:45 AM »

again thnx for all the help. :)
i decided to give the "small mod that replaces stuff" a go. i borrowd the mod_info.json from the ironclads mod, moddified it to my needs:
/*
"totalConversion":"false",
"jars":   [""],
"modPlugin": "data.scripts.myBlackMarketPlugin",
"replace":
   [
"data/campaign/submarkets.csv",
   ],
}
*/

changed the submarkets.csv entry for the blackmarket to: data.scripts.myBlackMarketPlugin
and it ended up like that:

33646 [Thread-5] ERROR com.fs.starfarer.combat.D  - java.lang.RuntimeException: Error compiling [data.scripts.myBlackMarketPlugin]
java.lang.RuntimeException: Error compiling [data.scripts.myBlackMarketPlugin]
   at com.fs.starfarer.loading.scripts.ScriptStore$3.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: Parsing compilation unit "com.fs.starfarer.loading.A$1@a637be"
   at org.codehaus.janino.JavaSourceIClassLoader.findIClass(JavaSourceIClassLoader.java:180)
   at org.codehaus.janino.IClassLoader.loadIClass(IClassLoader.java:158)
   at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(JavaSourceClassLoader.java:199)
   at org.codehaus.janino.JavaSourceClassLoader.findClass(JavaSourceClassLoader.java:164)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   ... 2 more
 Caused by: org.codehaus.commons.compiler.CompileException: File data/scripts/myBlackMarketPlugin.java, Line 35, Column 34: ';' expected instead of ':'

i checked and what this is refering to seems to be:
   public void updateCargoPrePlayerInteraction() {
      
      if (!okToUpdateCargo()) return;
      sinceLastCargoUpdate = 0f;
      
      CargoAPI cargo = getCargo();
      float stability = market.getStabilityValue();
      float blackMarketLegalFraction = 0.1f - 0.01f * stability;
      float blackMarketIllegalFraction = 0.2f - 0.01f * stability;
      
      for (CommodityOnMarketAPI com : market.getAllCommodities()) { <- this is the only ":" in the whole file(checked with ctrl-F)
         String id = com.getId();
         boolean illegal = market.isIllegal(id);

so i assume that janino cant handle this operator? if so i dont know how to circumvent that as i learnd yesterday precompiling the file is rather elaborate.
if some of what i say makes no sense, feel free to correct it, im only guessing and trying here.
« Last Edit: November 02, 2014, 01:35:51 AM by Venatos »
Logged

Zaphide

  • Admiral
  • *****
  • Posts: 799
    • View Profile
Re: more ships on the market
« Reply #11 on: November 02, 2014, 03:20:46 AM »

Yeah Janino can't use the shorthand 'foreach' statements, it's other main downside is that it can't really handle generics :(

You could refactor it into a for statement, but it may just be easiest to setup an IDE to pre-compile a jar for you. I think there are a couple of guides for Eclipse/NetBeans/ItelliJIDEA on this forum :)

Also, (unless I'm mistaken, always possible :) ) you won't need to specify a modPlugin entry in your mod_info.json. You will just need your modified data/campaign/submarkets.csv which will direct StarSector to use data.scripts.myBlackMarketPlugin. You only need a ModPlugin if you need to load classes/scripts that aren't specified via csv/json files (dialog plugins, AI plugins etc) or use some of the hooks (onNewGame, onLoadGame etc) available to ModPlugins.

I believe for your purposes you will need:
 - mod_info.json
 - data.scripts.myBlackMarketPlugin (either pre-compiled in a jar, or janino-compatible)
 - data/campaign/submarkets.csv that redifnes the black market to use your new script
Logged

Venatos

  • Ensign
  • *
  • Posts: 42
    • View Profile
Re: more ships on the market
« Reply #12 on: November 02, 2014, 05:17:39 AM »

thnx for the confirmation, janino uses the slang of javaskript, correct?

yeah i spent most of yesterday to try and compile it, i think ill try to reformulate it into a normal "for" statement.
i dont know how to do it yet, but as i understand it, the foreach works with some sort of array which sounds like a pain.
but i would much rather learn the language a little better than fiddling around with javac, eclipse and others again.

ill do some research today, maybe give it a try later.
Logged

Okim

  • Admiral
  • *****
  • Posts: 2161
    • View Profile
    • Okim`s Modelling stuff
Re: more ships on the market
« Reply #13 on: November 02, 2014, 06:42:11 AM »

I strongly reccomend you to set up InteljIdea or other software for java codding. Saves a lot of time due to inbuilt real time debuggers that hunt down any errors and provide suggestions how to fix those.

For example the copy pasted java file from starsector.jar.zip to data.scripts (doesn`t matter which) turned out to need some extra 'include' lines to work properly.

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: more ships on the market
« Reply #14 on: November 02, 2014, 08:55:28 AM »

No, no, no, no...Java and JavaScript are not in any way related. It was called JavaScript as a branding exercise to increase popularity. Sounds better than ECMAScript right?

A lot of us here use NetBeans, there are tutorials and a couple of videos about it specifically for Starsector on the forum if you take a quick look around.
Logged