Page 87 of 117

Re: Scripters cove

Posted: Mon Nov 30, 2015 1:19 am
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?

Re: Scripters cove

Posted: Mon Nov 30, 2015 2:30 am
by phkb
Nevermind, I think I worked it out. A combination of myship.script.$myNewFunction = this.$myNewFunction; and monkey patching the ship events.

Re: Scripters cove

Posted: Mon Dec 07, 2015 3:10 pm
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?)

Re: Scripters cove

Posted: Mon Dec 07, 2015 4:49 pm
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?

Re: Scripters cove

Posted: Mon Dec 07, 2015 5:17 pm
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

Re: Scripters cove

Posted: Fri Dec 11, 2015 4:43 am
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?

Re: Scripters cove

Posted: Fri Dec 11, 2015 11:06 pm
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.

Re: Scripters cove

Posted: Fri Dec 11, 2015 11:47 pm
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)

Re: Scripters cove

Posted: Sat Dec 12, 2015 12:15 am
by Fritz
Thank you! I expected a complicated calculation involving planet mass and an oolite-specific gravitational constant...

Re: Scripters cove

Posted: Sat Dec 12, 2015 12:49 am
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.

Re: Scripters cove

Posted: Sat Dec 12, 2015 1:04 am
by Cody
Stood Far Back When The Gravitas Was Handed Out

Re: Scripters cove

Posted: Tue Dec 15, 2015 10:16 pm
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.

Re: Scripters cove

Posted: Mon Jan 04, 2016 1:29 am
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?

Re: Scripters cove

Posted: Mon Jan 04, 2016 1:51 am
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.

Re: Scripters cove

Posted: Mon Jan 04, 2016 2:01 am
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.