Difference between revisions of "OXP tutorial"

From Elite Wiki
(Links: Added originating BB thread)
(Updating BB links)
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
 +
{{OXPNote|This page was last edited by a knowledgeable programmer back in 2013! (''May 2022 comment'')}}
 +
 
==Getting Ready==
 
==Getting Ready==
 
Of course you can just jump into OXP development. Skip this section and move on.
 
Of course you can just jump into OXP development. Skip this section and move on.
Line 6: Line 8:
 
* be sure to run the OXP Developer's version of Oolite: http://oolite.org/download/
 
* be sure to run the OXP Developer's version of Oolite: http://oolite.org/download/
 
* Oolite can verify your OXP. Ensure you configure enforce-oxp-standards=3
 
* Oolite can verify your OXP. Ensure you configure enforce-oxp-standards=3
* Currently we do not know what our OXP will contain or how often you need to change it. But be aware Oolite caches data to not be frustrated not seeing your in action - or simply turn off caching with always-flush-cache=YES (which sounds comfortable but has not always worked out reliably. In this case it may be easier to delete the cache before starting Oolite. See http://aegidian.org/bb/viewtopic.php?f=2&t=21120
+
* Currently we do not know what our OXP will contain or how often you need to change it. But be aware Oolite caches data to not be frustrated not seeing your in action - or simply turn off caching with always-flush-cache=YES (which sounds comfortable but has not always worked out reliably. In this case it may be easier to delete the cache before starting Oolite. See https://bb.oolite.space/viewtopic.php?f=2&t=21120
 
* In case errors and warnings happen and you want to easily find where in your scripting they occurred, configure both dump-stack-for-errors=YES and dump-stack-for-warnings=YES
 
* In case errors and warnings happen and you want to easily find where in your scripting they occurred, configure both dump-stack-for-errors=YES and dump-stack-for-warnings=YES
  
 
==My First OXP==
 
==My First OXP==
  
An [[OXP]] is an expansion pack to [[Oolite]]. You can customise the whole [[Oolite]] experience. In the same directory as the oolite.app directory is an AddOns directory. An OXP is a directory under AddOns called oxpname.oxp where oxpname is the name of your expansion pack. I have rashly committed to an ambitious OXP on the [http://aegidian.org/bb/index.php oolite BB] - this tutorial / blog is the story of how I got there.
+
An [[OXP]] is an expansion pack to [[Oolite]]. You can customise the whole [[Oolite]] experience. In the same directory as the oolite.app directory is an AddOns directory. An OXP is a directory under AddOns called oxpname.oxp where oxpname is the name of your expansion pack. I have rashly committed to an ambitious OXP on the [https://bb.oolite.space/index.php oolite BB] - this tutorial / blog is the story of how I got there.
  
 
'''So create a new directory in the Addons folder. Make sure the extension is .oxp as otherwise Oolite will ignore it.'''
 
'''So create a new directory in the Addons folder. Make sure the extension is .oxp as otherwise Oolite will ignore it.'''
Line 19: Line 21:
 
My first [[OXP]] will be to create a ship. There are 2 approaches to this. The first involves [[OXP_howto_model|3D modelling]]. That is time consuming and too involved for my level of impatience. So we'll use the second method - borrowing someone else's model.  
 
My first [[OXP]] will be to create a ship. There are 2 approaches to this. The first involves [[OXP_howto_model|3D modelling]]. That is time consuming and too involved for my level of impatience. So we'll use the second method - borrowing someone else's model.  
  
Configuration files and scripts are either [[Property lists|property lists]] (.plist extension) or [[Scripting_Oolite_with_JavaScript|javascript]] (.js extension). Both are text format. Notepad++[http://notepad-plus.sourceforge.net/] is a good editting tool - even if I prefer vi[www.vim.org/download.php]. Though you can use whatever editor you are comfortable with (apart from Windows notepad).  
+
Configuration files and scripts are either [[Property lists|property lists]] (.plist extension) or [[Scripting_Oolite_with_JavaScript|javascript]] (.js extension). Both are text format. [http://notepad-plus.sourceforge.net/ Notepad++] is a good editing tool - even if I prefer [www.vim.org/download.php vim]. Though you can use whatever editor you are comfortable with (apart from Windows notepad).  
  
First we need a name for our expansion pack. If you plan on deploying it try to make it unique. Thargons.oxp is a stunningly bad name as it is likely to crash. Thus I will call this expansion pack cobraball_1_0.oxp. Throughout this tutorial I am using a major and minor version number - so you can download and identify all the examples.
+
First we need a name for our expansion pack. If you plan on publishing it then try to make it unique. Thargons.oxp is a stunningly bad name as it is likely to crash. Thus I will call this expansion pack cobraball_1_0.oxp. Throughout this tutorial I am using a major and minor version number - so we can download and identify all the examples.
  
 
Having come up with a catchy (well unique) name, we need a directory. Create a directory called cobraball_1_0.oxp in the AddOns directory. Create a Config sub directory. Within the Config directory create a text file called shipdata.plist.
 
Having come up with a catchy (well unique) name, we need a directory. Create a directory called cobraball_1_0.oxp in the AddOns directory. Create a Config sub directory. Within the Config directory create a text file called shipdata.plist.
  
This will be our first [[Property list]]. There are 2 different [[Property_list#Formats|formats]], but this a tutorial not a reference manual so we will ignore one of them and use the XML format.
+
This will be our first [[Property list]]. There are several different [[Property_list#Formats|formats]], but this a tutorial not a reference manual so we will just use the XML format.
  
Below is a blank template for a [[Property_list|Property list]]. For our purposes we need to use the header and footer below and don't need to understand them.
+
Below is a blank template for a [[Property_list|Property list]]. For our purposes we need to use the header and footer below, but don't need to understand them.
  
 
<code><pre>
 
<code><pre>
Line 39: Line 41:
 
</pre></code>
 
</pre></code>
  
Enough preamble - on with our first [[OXP]]. We are going to build a ship. It will be like the [[Cobra_Mk.3_(Oolite)|Cobra Mk III]] (the playable version not the pirate / trader)- except we'll change it around a bit - otherwise what is the point? The key (internal name) for the ship will be cobraball_cobra_1_0 - this is never seen by the player. Note the use of the like_ship key. Take the code below and save it in shipdata.plist.
+
Enough preamble - on with our first [[OXP]]. We are going to build a ship. It will be like the [[Cobra_Mk.3_(Oolite)|Cobra Mk III]] (the playable version not the pirate / trader)- except we'll change it around a bit - otherwise what is the point? The '''key''' (internal name) for the ship will be cobraball_cobra_1_0 - this is never seen by the player. Note the use of the like_ship key. Take the code below and save it in shipdata.plist.
  
 
<code><pre>
 
<code><pre>
Line 64: Line 66:
 
As the header and footer can get boring very quickly and add clutter I won't include them from here on. Unless I do.  
 
As the header and footer can get boring very quickly and add clutter I won't include them from here on. Unless I do.  
  
As might be obvious shipdata.plist is the ships configuration file. The shipdata.plist information in all the installed OXPs is added to the standard definition in the central shipdata.plist to get the master list used in the gameplay. For the impatient the full list of available fields is available [[Shipdata.plist|here]].
+
As might be obvious shipdata.plist is the ship's configuration file. The shipdata.plist information in all the installed OXPs is added to the standard definition in the central shipdata.plist to get the master list used in the gameplay. For the impatient the full list of available fields is available [[Shipdata.plist|here]].
  
 
The ship now exists, but it would not be particularly easy to find at the moment. Thus we need more code wizardry. Create a new text file demoships.plist in the same Config directory as shipdata.plist. Add the following code to it:
 
The ship now exists, but it would not be particularly easy to find at the moment. Thus we need more code wizardry. Create a new text file demoships.plist in the same Config directory as shipdata.plist. Add the following code to it:
Line 78: Line 80:
 
</pre></code>
 
</pre></code>
  
Now fire up Oolite. And when it asks if you want to load the previous commander - press "N". Then use the left arrow to toggle through the ships - and delight in your new caption.  
+
Now fire up an old version of Oolite (v.1.77 or earlier). And when it asks if you want to load the previous commander - press "N". Then use the left arrow to toggle through the ships on display - and delight in your new caption.
  
 
===Creating My First Useful Ship (cobraball_1_1)===
 
===Creating My First Useful Ship (cobraball_1_1)===
Line 298: Line 300:
 
*Never forget that manifest & CargoList are arrays.
 
*Never forget that manifest & CargoList are arrays.
  
*Some oxp's have helpful annotation explaining what the author is up to: [[User:Phkb|Phkb]], [[User:Thargoid|Thargoid]], [[User:Norby|Norby]] are again all recommended by Montana05.
+
*Some oxp's have helpful annotation explaining what the author is up to: those by [[User:Phkb|Phkb]], [[User:Thargoid|Thargoid]] & [[User:Norby|Norby]] are again all recommended by Montana05.
  
 
*For those with an adversion to Javascript, try [[Legacy Scripting]]
 
*For those with an adversion to Javascript, try [[Legacy Scripting]]
*[http://www.aegidian.org/bb/viewtopic.php?f=4&t=3902 Fons et origo] of this page (2007).
+
*[https://bb.oolite.space/viewtopic.php?f=4&t=3902 Fons et origo] of this page (2007).
 +
 
 +
*[https://bb.oolite.space/viewtopic.php?f=7&t=8022 My first ship...] (2010) Daddyhoggy's attempt to create a ship, with pitfalls and problems explained
  
 
[[Category:Oolite Development]]
 
[[Category:Oolite Development]]

Latest revision as of 02:17, 29 February 2024

Getting Ready

Of course you can just jump into OXP development. Skip this section and move on. But be warned you may go into pitfalls that are easily avoided if you take a few precautions:

The precautions will actually activate suitable features from Hidden_Settings_in_Oolite.

  • be sure to run the OXP Developer's version of Oolite: http://oolite.org/download/
  • Oolite can verify your OXP. Ensure you configure enforce-oxp-standards=3
  • Currently we do not know what our OXP will contain or how often you need to change it. But be aware Oolite caches data to not be frustrated not seeing your in action - or simply turn off caching with always-flush-cache=YES (which sounds comfortable but has not always worked out reliably. In this case it may be easier to delete the cache before starting Oolite. See https://bb.oolite.space/viewtopic.php?f=2&t=21120
  • In case errors and warnings happen and you want to easily find where in your scripting they occurred, configure both dump-stack-for-errors=YES and dump-stack-for-warnings=YES

My First OXP

An OXP is an expansion pack to Oolite. You can customise the whole Oolite experience. In the same directory as the oolite.app directory is an AddOns directory. An OXP is a directory under AddOns called oxpname.oxp where oxpname is the name of your expansion pack. I have rashly committed to an ambitious OXP on the oolite BB - this tutorial / blog is the story of how I got there.

So create a new directory in the Addons folder. Make sure the extension is .oxp as otherwise Oolite will ignore it.

Creating My First Ship (cobraball_1_0)

My first OXP will be to create a ship. There are 2 approaches to this. The first involves 3D modelling. That is time consuming and too involved for my level of impatience. So we'll use the second method - borrowing someone else's model.

Configuration files and scripts are either property lists (.plist extension) or javascript (.js extension). Both are text format. Notepad++ is a good editing tool - even if I prefer [www.vim.org/download.php vim]. Though you can use whatever editor you are comfortable with (apart from Windows notepad).

First we need a name for our expansion pack. If you plan on publishing it then try to make it unique. Thargons.oxp is a stunningly bad name as it is likely to crash. Thus I will call this expansion pack cobraball_1_0.oxp. Throughout this tutorial I am using a major and minor version number - so we can download and identify all the examples.

Having come up with a catchy (well unique) name, we need a directory. Create a directory called cobraball_1_0.oxp in the AddOns directory. Create a Config sub directory. Within the Config directory create a text file called shipdata.plist.

This will be our first Property list. There are several different formats, but this a tutorial not a reference manual so we will just use the XML format.

Below is a blank template for a Property list. For our purposes we need to use the header and footer below, but don't need to understand them.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <!-- this is a comment and is ignored by Oolite -->
  <!-- this is where in the file all of our stuff goes -->
  <!-- you can ignore the header and footer parts -->
</plist>

Enough preamble - on with our first OXP. We are going to build a ship. It will be like the Cobra Mk III (the playable version not the pirate / trader)- except we'll change it around a bit - otherwise what is the point? The key (internal name) for the ship will be cobraball_cobra_1_0 - this is never seen by the player. Note the use of the like_ship key. Take the code below and save it in shipdata.plist.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs PropertyList-1.0.dtd">
<plist version="1.0">

<!-- the end of the header and the start of the custom code -->

 <dict>
  <key>cobraball_cobra_1_0</key>
  <dict>
   <key>like_ship</key>
   <string>cobra3-player</string>
   <key>name</key>
   <string>My Custom Cobra Mk III</string>
  </dict>
 </dict>

<!-- the end of the custom code and the start of the footer -->
</plist>

As the header and footer can get boring very quickly and add clutter I won't include them from here on. Unless I do.

As might be obvious shipdata.plist is the ship's configuration file. The shipdata.plist information in all the installed OXPs is added to the standard definition in the central shipdata.plist to get the master list used in the gameplay. For the impatient the full list of available fields is available here.

The ship now exists, but it would not be particularly easy to find at the moment. Thus we need more code wizardry. Create a new text file demoships.plist in the same Config directory as shipdata.plist. Add the following code to it:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
	<string>cobraball_cobra_1_0</string>
</array>
</plist>

Now fire up an old version of Oolite (v.1.77 or earlier). And when it asks if you want to load the previous commander - press "N". Then use the left arrow to toggle through the ships on display - and delight in your new caption.

Creating My First Useful Ship (cobraball_1_1)

Ok, all so far, so impressive, but that was an awful lot of work to look at the standard Cobra. Now what we want to do is fly this baby.

Before we can fly it, we need to buy it. So we need a new configuration file in the OXP. Create a new text file shipyard.plist. For the impatient the full list of available fields is available here.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>cobraball_cobra_1_0</key>
	<dict>

<!-- The chance of getting this ship in a ship yard. 1 is certainty. 0 is never. We always want to see out ship, so we can test it-->
		<key>chance</key>
		<real>1</real>

<!-- This section determines what is available from the f3 screen -->
		<key>optional_equipment</key>
		<array>
			<string>EQ_ECM</string>
			<string>EQ_FUEL_SCOOPS</string>
			<string>EQ_ENERGY_BOMB</string>
			<string>EQ_ENERGY_UNIT</string>
			<string>EQ_NAVAL_ENERGY_UNIT</string>
			<string>EQ_DOCK_COMP</string>
			<string>EQ_WEAPON_PULSE_LASER</string>
			<string>EQ_WEAPON_BEAM_LASER</string>
			<string>EQ_WEAPON_MINING_LASER</string>
			<string>EQ_WEAPON_MILITARY_LASER</string>
			<string>EQ_FUEL_INJECTION</string>
			<string>EQ_SCANNER_SHOW_MISSILE_TARGET</string>
			<string>EQ_MULTI_TARGET</string>
			<string>EQ_GAL_DRIVE</string>
			<string>EQ_ADVANCED_COMPASS</string>
			<string>EQ_SHIELD_BOOSTER</string>
			<string>EQ_NAVAL_SHIELD_BOOSTER</string>
			<string>EQ_HEAT_SHIELD</string>
		</array>

<!-- Bargain for testing purposes -->
		<key>price</key>
		<integer>10</integer>

<!-- This section determines what is standard equipment -->
		<key>standard_equipment</key>
		<dict>

			<key>extras</key>
			<array>
				<string>EQ_ESCAPE_POD</string>
			</array>

<!-- Defines the default forward facing weapon -->
			<key>forward_weapon_type</key>
			<string>EQ_WEAPON_BEAM_LASER</string>

			<key>missiles</key>
			<integer>1</integer>
		</dict>
		<key>techlevel</key>
		<integer>1</integer>
		<key>weapon_facings</key>
		<integer>15</integer>
	</dict>
</dict>
</plist>

This should all be straight forward but a useful reference for plist files can be found here. But enough of that dry academia, let's fly. Start up Oolite. Start a new game. Press F3 twice. Buy your very own ship and take it for a spin.

Creating My First Game Killer Ship (cobraball_1_2)

Now this is all well and good, but where is the fun? I know you are going to build a stupidly overspecified mean machine, so we may as well show you how so you can get it out of your system.

shipdata.plist:

 <dict>
  <key>cobraball_cobra_1_2</key>
  <dict>
<!-- Stupidly high recharge rate - same as for a station -->  
   <key>energy_recharge_rate</key>
   <real>100</real>
<!-- I like yellow lasers -->     
   <key>laser_color</key>
   <string>yellowColor</string>   
   <key>like_ship</key>
   <string>cobra3-player</string>
<!-- Energy bars are energy divided by 64 -->
   <key>max_energy</key>
   <real>920</real>
   <key>max_cargo</key>
   <integer>250</integer>
   <key>max_flight_pitch</key>
   <real>3.0</real>
   <key>max_flight_roll</key>
   <real>4.2</real>
   <key>max_flight_speed</key>
   <real>1000</real>
   <key>max_missiles</key>
   <real>20</real>   
   
   <key>name</key>
   <string>Super Cobra Mk III (1.2)</string>
   <key>thrust</key>
   <real>100</real>
  </dict>
 </dict>


shipyard.plist:

<dict>
	<key>cobraball_cobra_1_2</key>
	<dict>
		<key>chance</key>
		<real>1</real>
		<key>optional_equipment</key>
		<array>
			<string>EQ_WEAPON_MILITARY_LASER</string>
		</array>
		<key>price</key>
		<integer>10</integer>
		<key>standard_equipment</key>
		<dict>
		<key>extras</key>
		<array>
			<string>EQ_ESCAPE_POD</string>
			<string>EQ_ECM</string>
			<string>EQ_FUEL_SCOOPS</string>
			<string>EQ_ENERGY_BOMB</string>
			<string>EQ_NAVAL_ENERGY_UNIT</string>
			<string>EQ_DOCK_COMP</string>
			<string>EQ_FUEL_INJECTION</string>
			<string>EQ_SCANNER_SHOW_MISSILE_TARGET</string>
			<string>EQ_MULTI_TARGET</string>
			<string>EQ_GAL_DRIVE</string>
			<string>EQ_ADVANCED_COMPASS</string>
			<string>EQ_NAVAL_SHIELD_BOOSTER</string>
			<string>EQ_HEAT_SHIELD</string>
			<string>EQ_CLOAKING_DEVICE</string>
			<string>EQ_MILITARY_JAMMER</string>
			<string>EQ_MILITARY_SCANNER_FILTER</string>
		</array>
		<key>missiles</key>
		<integer>20</integer>
		</dict>
		<key>techlevel</key>
		<integer>1</integer>
		<key>weapon_facings</key>
		<integer>15</integer>
	</dict>
</dict>

Make all the good stuff standard. Including some stuff only available as a mission reward. This is a game play killer so don't. The EQ_ codes are defined in Equipment.plist.

The trouble with super ships like the above is that they wreck the balance of the game - they take away the challenge and make life too easy. Just because we can does not mean we should. Superman would be mighty dull without Kryptonite to add some drama.


BEYOND THIS POINT IS A WORK IN PROGRESS


Asteroids and positioning (cobraball_1_3)

Create a custom asteroid

Create an asteroid based on the standard version.

Add a flasher

Add flashers so we can identify our asteroid clearly.

Station View

Park by the station beacon.

Witchspace Beacon (cobraball_1_3_1)

Park by the beacon.

Surface of the Sun (cobraball_1_3_2)

Park near the sun closest to the planet.

Route 1(cobraball_1_3_3)

Randomly along route 1.

Route 2(cobraball_1_3_4)

Randomly along route 2.

Space Lanes (cobraball_1_3_5)

Create a space lane with 2 asteroids as buoys marking the space lane to witchspace.

Rings (cobraball_1_3_6)

Install the rings oxp - provide a rings models only version. And place along the space lane. We'll go for every 10% of the station beacon route.

Shipdata.plist Verifier

Oolite has what amounts to a spell checker for shipdata.plist, called the OXP verifier. It can currently only be invoked from the command line.

On Windows or Linux: oolite.app/oolite --verify-oxp <path to OXP>

On Mac OS X: Oolite.app/Contents/MacOS/Oolite --verify-oxp <path to OXP>

Customising Models

A New Paint Job

Give the Cobra Mark III a bright pink paint job.


This is a work in progress to be continued


Links

Reference

  • Some oxp's have helpful annotation explaining what the author is up to: those by Phkb, Thargoid & Norby are again all recommended by Montana05.
  • My first ship... (2010) Daddyhoggy's attempt to create a ship, with pitfalls and problems explained