Scripters cove

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

I can assign a custom script to a ship by doing myship.setScript("myshipscript.js"). I think I'm correct in saying if another OXP has got there ahead of me, doing that command will wipe out any existing script and replace it with mine. Is is possible to append my script to the existing one? For example, the existing script might have the following custom function:

Code: Select all

this.$customFunction1 = function(data) 
{...code...}

this.shipTakingDamage = function(amount, whom, type) 
{
   this.$customFunction1(whom);
}
Now, I don't want to remove either of those functions. I just want to add:

Code: Select all

this.$myNewFunction = function(data) 
{...code...}

this.shipTargetLost = function(target) 
{
   this.$myNewFunction(target);
}
So that the end result is:

Code: Select all

this.$customFunction1 = function(data) 
{...code...}

this.$myNewFunction = function(data) 
{...code...}

this.shipTakingDamage = function(amount, whom, type) 
{
   this.$customFunction1(whom);
}

this.shipTargetLost = function(target) 
{
   this.$myNewFunction(target);
}
Is it possible to get both scripts assigned to the ship? Or do I have to work around the existing script?
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

Nevermind, I think I worked it out. A combination of myship.script.$myNewFunction = this.$myNewFunction; and monkey patching the ship events.
ocz
Deadly
Deadly
Posts: 175
Joined: Tue Nov 10, 2015 1:59 pm

Re: Scripters cove

Post by ocz »

As some of you already know I try to write an additional cargo space workaround script for Oolite 1.83.

Reason behind and current status of the script: There is currently no way to add cargo space, that survives a game state reload. That workaround script should create a common way for OXPs to preserve it.
Currently my script restores the added cargo space value (theoretically for several OXPs using it) in the startUp()-phase. Sadly, if that space was used for commodities and/or equipment, those items don't survive the loading process of the game engine, too. (They are omitted, when building the ship from the savegame, as the at that point too small standard cargo space isn't sufficient for them. The additional space is added too late.) The script saves them in missionVariables and restores them in the startUp()-phase, too. I'm current implementing the restoration of the equipment.


I have come across a problem with the Passenger Berths. In some cases (read above) the berths are not added to the ship when loading a savegame. Passenger contracts using them are omitted, too. Now I want to save and restore them by using missionVariables.

Regarding this I have 3 questions:
  • Q1: If a contract is dropped in such a way (just not being restored), are there any negative consequences for the pessanger transportation reputation of the player? (I already checked the savegames, but reputation is a complex affair. If somebody knows a sure answer, this would help.)
  • Q2: I didn't find any clues on how to read out contract data (passenger's name, destination, fee, advanced payment, arrival time, aso.) in-game with java methods. How do I get them?/Where are they hidden?
  • Q3:The addPessanger method doesn't provide an argument for the start date of the contract. The current game time is taken instead. How does the start date influence the contract? (Boni/Mali for arriving early or late?)
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara »

ocz wrote:
Q2: I didn't find any clues on how to read out contract data (passenger's name, destination, fee, advanced payment, arrival time, aso.) in-game with java methods. How do I get them?/Where are they hidden?
ship.passengers?
ocz
Deadly
Deadly
Posts: 175
Joined: Tue Nov 10, 2015 1:59 pm

Re: Scripters cove

Post by ocz »

Thx. 1 problem down, 2 left. I already searched through Oolite JavaScript Reference: Ship, but somehow didn't find it. Now I can implement it.

@Q1: I hope it doesn't hurt the reputation, but at least, in case it does, I have player.increasePassengerReputation(). Still if somebody knows something, it would save me crawling through the sourcecode.
@Q3: I'll have to test that, but I guess if it does change things, there is nothing I can do. Again. If somebody already has experience in this matter, your input can't hurt
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

What would I need to do to recreate the planet descriptions for all the planets? For instance, if I wanted to (in my personal Ooniverse) eliminate "edible poets" from planetary descriptions, could I edit the "descriptions.plist" file and then run some code to output a new description to the log file or something?
Fritz
---- E L I T E ----
---- E L I T E ----
Posts: 591
Joined: Sun Jul 12, 2015 2:30 pm
Location: Bavaria, Germany
Contact:

Re: Scripters cove

Post by Fritz »

Does anybody know the formula to calculate the mass-lock distance for planets and suns? I should do this for the NPC ship during torus synchronisation, as well in Escorts Contracts as in my new OXP.
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"
User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2577
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Scripters cove

Post by Norby »

Fritz wrote:
Does anybody know the formula to calculate the mass-lock distance for planets and suns?
Planets from planet.position:
planet.radius + Math.max( planet.radius, 25600 )
Is not always 2*radius due to there are small moons (planet.hasAtmosphere==false) where the masslock radius is at least the normal scanner range over the surface.

Sun from system.sun.position:
system.sun.radius * Math.sqrt(2)
Fritz
---- E L I T E ----
---- E L I T E ----
Posts: 591
Joined: Sun Jul 12, 2015 2:30 pm
Location: Bavaria, Germany
Contact:

Re: Scripters cove

Post by Fritz »

Thank you! I expected a complicated calculation involving planet mass and an oolite-specific gravitational constant...
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"
User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2577
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Scripters cove

Post by Norby »

Fritz wrote:
planet mass and an oolite-specific gravitational constant...
Both planet.mass and sun.mass return 0 - seems calculated from the volume for ships only.
There is no gravity in Ooniverse so the "constant" is 0 also.
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16081
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Scripters cove

Post by Cody »

Stood Far Back When The Gravitas Was Handed Out
I would advise stilts for the quagmires, and camels for the snowy hills
And any survivors, their debts I will certainly pay. There's always a way!
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

phkb wrote:
What would I need to do to recreate the planet descriptions for all the planets? For instance, if I wanted to (in my personal Ooniverse) eliminate "edible poets" from planetary descriptions, could I edit the "descriptions.plist" file and then run some code to output a new description to the log file or something?
If you just wanted to substitute a component in the current algorithm, then either a find-and-replace on planetinfo.plist, or a little bit of Javascript that makes the change by updating System.infoForSystem(g,s).description for the affected systems, would probably be the easiest approach.

You could also download/compile Oolite 1.77.1, update its descriptions.plist, and output the system descriptions as they get procedurally generated to the log (you'll need to do this once per galaxy since reading from other galaxies was a consequence of not procedurally generating everything)

Really big changes are probably easiest to make by writing a separate generator script, running it, and saving the result as a planetinfo.plist.
Fritz
---- E L I T E ----
---- E L I T E ----
Posts: 591
Joined: Sun Jul 12, 2015 2:30 pm
Location: Bavaria, Germany
Contact:

Re: Scripters cove

Post by Fritz »

system.addShips() can add ships with a certain role. I don't know where I have read it (it isn't documented in the wiki), but the method can also add ships of a certain type if the type name is enclosed in square brackets. But in the latter case, the ships don't seem to have a role, which can be bad for testing. I wonder if there is a possibility to add ships of a certain type in a specific role, like, for example, a Boa trader?
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"
User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2577
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Scripters cove

Post by Norby »

Fritz wrote:
add ships of a certain type in a specific role
Brute force: add and remove ships in a cycle giving role until the dataKey of the received ship is not the wanted.
Fritz
---- E L I T E ----
---- E L I T E ----
Posts: 591
Joined: Sun Jul 12, 2015 2:30 pm
Location: Bavaria, Germany
Contact:

Re: Scripters cove

Post by Fritz »

Hm... I'll try it. This seems really brutal, and I probably wouldn't include it in an OXP, but it's only for testing.
"You wouldn't kill me just for a few credits, would you?" – "No, I'll do it just for the fun!"
Post Reply