cim has spent the last couple of days implementing some new JS features that I think a lot of OXpers and players will get quite excited about. These are:
Capt Murphy 2012
Licence: CC BY-NC-SA 3.0 - see http://creativecommons.org/licenses/by-nc-sa/3.0/
for more info.
Requires: Oolite 1.77 - Trunk builds after revision 5025 (nightly build 23/06/12).
Version 0.20 24/06/12
Ship_Storage_Helper contains helper functions for OXP writers that wish to use the new Trunk JS method
. It facilitates storing information about the current player ship in a variable or missionVariable, and reinstating a stored player ship as the players current ship, taking into account known OXP variables that also need to be stored/reinstated.
As development and testing is ongoing it is anticipated that additional OXP compatibility code will need to included. I would be grateful if testers and OXP authors could alert me to any bugs using the current release. In the long term I hope this OXP to become a community maintained OXP as it will require regular updating in light of new OXP releases.
Current OXP Compatibility.
Ship_Storage_Helper contains code to explicitly overcome compatibility issues for the following OXPs:
New Cargoes, HyperCargo, Vortex, APRIL, Iron Hide, Missiles and Bombs, Railgun, Target Autolock Plus, Target Reticle Sensitive, Armoury, Aquatics, Battle Damage, 'Breakables', TCAT, Respray for Griffs.
This function can be called from other worldScripts immediately before changing the player's ship with player.replaceShip(dataKey), and returns a string including the stored ships essential attributes.
This function takes the output of storeCurrentShip as an argument and uses it to reinstate the player ship from the stored information. Returns true if successful or one of the following error strings if it fails.
"Error-Invalid Parameter, expected String" - indicates that storedShipString is in wrong format
"Error-Invalid Parameter, array incorrect length" - indicates that storedShipString was created by a newer version of Ship_Storage_Helper.
"Error-Invalid dataKey" - indicates that the OXP that defined that dataKey has been removed since storedShipString was created.
The output of storeCurrentShip is a JSON stringified array of ship attributes, containing the following indices as of v0.16.
0: Place and time of storage - Array [galaxyNumber,system.ID,clock.seconds,player.ship.displayName,system.name,stationAttributes,player.ship.price] (stationAttributes are [player.ship.dockedStation.primaryRole, player.ship.dockedStation.dataKey, player.ship.dockedStation.position])
1: dataKey (e.g. "cobra3-player")
2: aftWeapon equipmentKey
3: forwardWeapon equipmentKey
4: portWeapon equipmentKey
5: starboardWeapon equipmentKey
6: Array of pylon equipmentKeys
7: Array of normal equipment equipmentKeys & equipmentStatus
8: Array of manifest contents.
10: passenger contracts
11: array of subEnts (only if frangible subEnts are missing on storage)
15: Cim's New Cargoes suspended cargo variable
16: Array of Thargoid's HyperCargo missionVariables
17: Array of Thargoid's Vortex/Maelstrom missionVariables
18: Array of Thargoid's APRIL missionVariables
19: Array of Thargoid's IronHide missionVariables
20: Ramirez's Missile & Bombs missionVariable
21: Array of McClane's Railgun missionVariables.
22: Thargoid's TargetAutoLock Plus missionVariable.
23: Eric's TargetReticle Sensitive missionVariable.
24: Thargoid's Armoury missionVariable.
25: Thargoid's Aquatics missionVariable.
26: Smivs Battle Damage missionVariable.
27: Respray for Griff's missionVariables.
Individual elements can be accessed from your own script. For example-
var myStoredShip = worldScripts["Ship_Storage_Helper.js"].storeCurrentShip()
var dataKey = JSON.parse(myStoredShip)
Context must be a string – valid values are “delete” & “retainName”.
Used to temporarily modify the behaviour of the playerBoughtNewShip function in Thargoid's Vortex.oxp, to either prevent it running, or to prevent it renaming a Vortex or Maelstrom that has previously been stored.
Reverses the changes made by the above functions.
Used to temporarily disable the playerBoughtNewShip function in Thargoid's TCAT.oxp. Buying a new ship is a trigger for mission failure in this OXP, but this may not always be appropriate behaviour using the new methods.
All of these functions are called from Extended_Shipyards.OXP if you need examples of how they can be used.
This is an array of valid player ship dataKeys from the users currently installed OXPs. It is built at startUp. It is not necessarily comprehensive, and is less likely to be comprehensive the more unique player-flyable ships are installed. It can generally capture up to 60 to 70 unique dataKeys.
v0.16 31/5/12 – Added additional information to header including system.name as a string, information about the station the ship is stored at, and the full price of the stored ship. Added entityPersonality as a ship attribute that is saved and can be restored (maintains paint colours on Griff's ships under full shaders). Thanks to cim for making this option available from trunk revision 4968. Fixed a bug were version 0.15 was unintentionally dependent on the Breakables OXPs.
v0.17 05/06/12 - v.017 05/6/12 – Fixed a bug in handling of subEntities when the ship doesn’t have any.
v0.18 09/06/12 – Added compatibility for v0.2 of Respray for Griff's.oxp
v0.19 16/06/12 – Updated compatibility for v0.3 of Respray for Griff's.oxp
v0.20 24/06/12 – Updated compatibility for v0.4 of Respray for Griff’s.oxp so that adjusted decals are correctly restored. Ensure that player shield strength is set to maximum on restore (thanks cim for the report).