Basic market fix for old oxps

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

Moderators: another_commander, winston

Post Reply
Layne
---- E L I T E ----
---- E L I T E ----
Posts: 355
Joined: Sat Mar 28, 2015 11:14 pm

Basic market fix for old oxps

Post by Layne »

Right, so with some help from another_commander, I've finally been able to upgrade my Oolite to 1.82 and still get it to work moderately well on my crummy laptop. (Side note, is anyone else using Deep Horizons Planetary Systems as a moon/planet re-texture? It's had some strange behavior in 1.82 and I had to switch to Additional Planets to get a similar effect.) Obviously, with the new markets, a lot (a lot a lot) of older oxp's have ancillary stations that no longer provide trading. These include Anarchies, Commies, Dictators, etc, the system oxps, for the most part. Looking at Norby's patch for Planetfall, I'm still not sure I see how to quickly add markets back into these stations.

Is there a quick template I can look at for returning functioning markets to older oxps? Not just duplicates of the main station market, but with some more specialized prices?
Reports of my death have been greatly underestimated.
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2676
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Basic market fix for old oxps

Post by spara »

Wildships has a fairly straight forward conversion script. That might get you going.
Layne
---- E L I T E ----
---- E L I T E ----
Posts: 355
Joined: Sat Mar 28, 2015 11:14 pm

Re: Basic market fix for old oxps

Post by Layne »

spara wrote:
Wildships has a fairly straight forward conversion script. That might get you going.
Thanks, that'll probably be just what I need!
Reports of my death have been greatly underestimated.
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2676
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Basic market fix for old oxps

Post by spara »

Finally back to my rig. Here's a short howto for anyone looking for a way to bring back markets to the old OXPs containing commodities.plist definition file. This method practically makes a carbon copy of the original market by duplicating the old market creation method in js.

The initial setting should be an old station OXP with shipdata.plist and commodities.plist files in the Config folder.

1. Create a folder named "Scripts" to the root of the OXP.
2. Create a uniquely named js-file to the Scripts folder. For example "my-station-market.js".
3. Copy-paste the following into the just created market file.

Code: Select all

"use strict";

this.name = "my-station-market";

//put the original defs here. no def is handled later.
this.$originalDefs = {
      "food" : [0, 0, 25, -1, -1, 250, 5, 5, 0],
      "textiles" : [0, 0, 18, -1, 0, 250, 5, 10, 0],
      "radioactives" : [0, 0, 53, -2, -3, 0, 7, 15, 0],
      "slaves" : [0, 0, 20, -2, -1, 5, 0, 3, 0],
      "liquor_wines" : [0, 0, 130, -1, -1, 250, 15, 5, 0],
      "luxuries" : [0, 0, 190, 8, -1, 250, 9, 21, 0],
      "narcotics" : [0, 0, 36, -5, -9, 250, 5, 5, 0],
      "computers" : [0, 0, 150, 14, -1, 250, 3, 21, 0],
      "machinery" : [0, 0, 120, 6, 1, 250, 31, 10, 0],
      "alloys" : [0, 0, 88, 3, 1, 250, 21, 10, 0],
      "firearms" : [0, 0, 100, 13, 0, 0, 63, 0, 0],
      "furs" : [0, 0, 170, -9, -1, 250, 63, 21, 0],
      "minerals" : [0, 0, 16, -1, -2, 15, 3, 31, 0],
      "gold" : [0, 0, 100, 0, 0, 0, 4, 0, 1],
      "platinum" : [0, 0, 181, 0, 0, 0, 21, 0, 1],
      "gem_stones" : [0, 0, 50, 0, 0, 0, 10, 0, 2],
      "alien_items" : [0, 0, 125, 1, 0, 0, 31, 0, 0]
};

this.updateLocalCommodityDefinition = function(goodDefinition) {
	var commodity = goodDefinition.key;
	var oldDefs = this.$originalDefs[commodity];
	
	//define the market size for the station
	goodDefinition.capacity = 127;
	
	//old style definition found for the good. calculate it the old way
	if (oldDefs) {
		var market_base_price = oldDefs[2];
		var market_eco_adjust_price = oldDefs[3];
		var market_eco_adjust_quantity = oldDefs[4];
		var market_base_quantity = oldDefs[5];
		var market_mask_price = oldDefs[6];
		var market_mask_quantity = oldDefs[7];
		var market_rnd = Math.floor(Math.random() * 256);

		var economy = system.economy;
		
		var price = (market_base_price + (market_rnd & market_mask_price) + (economy * market_eco_adjust_price)) & 255;
		price *= 0.4;
		
		var quantity = (market_base_quantity + (market_rnd & market_mask_quantity) - (economy * market_eco_adjust_quantity)) & 255;
		if (quantity > 127) quantity = 0;
		
		quantity &= 63;
		
		goodDefinition.quantity = quantity;
		goodDefinition.price = price * 10;
	}

	//no definition found. just add some variance to the system market (+/-5%)
	else {
		goodDefinition.price = goodDefinition.price * (1.05 - Math.random() * 0.1);
		goodDefinition.quantity = Math.floor(goodDefinition.quantity * (1.05 - Math.random() * 0.1));
	}

	//no definition found. no market on that commodity
	//else {
	//	goodDefinition.price = 0;
	//	goodDefinition.quantity = 0;
	//	goodDefinition.capacity = 0;
	//}

	//scale down if quantity too high
	if (goodDefinition.quantity > goodDefinition.capacity)
		goodDefinition.quantity = Math.floor(goodDefinition.quantity / 127 * goodDefinition.capacity);

	return goodDefinition;
};
4. Replace the definitions in the script above with the definitions from the old commodities.plist. Only replace the numbers! In case the old commodities.plist is in xml, you'll probably want to convert it to open step with xml2ns.py script found from the wiki: [wiki]Oolite Converters[/wiki].
5. Tweak the capacity of the station to your liking by editing goodDefinition.capacity.
6. Decide what to do with custom commodities. By default the script just adds some variance.
7. Remember to save your new market file!
8. Open shipdata.plist file and find the definition for the station.
9. Add

Code: Select all

market_script = "my-station-market.js";
below the line saying market=.... The place really does not matter, but it's tidier that way.
10. Save shipdata.plist, start the game while holding shift and visit the station. If all went well, it should have a functional market. If not, latest.log will probably tell you what went wrong.

That should be it. Have fun tweaking :mrgreen: .
User avatar
Cholmondely
Archivist
Archivist
Posts: 4977
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Basic market fix for old oxps

Post by Cholmondely »

spara wrote: Sat Jul 25, 2015 2:04 pm
That should be it. Have fun tweaking :mrgreen: .
Reinstating a deprecated market definition without changing the original shipdata.plist

I'm trying to override the old defunct market in the SecCom stations in the original Galactic_Navy.oxp

The original shipdata.plist reads

Code: Select all

	<key>navystat</key>
	<dict>
		…
		<key>market</key>
		<string>navystat</string>
		<key>max_cargo</key>
		<string>0</string>
		…
	</dict>
which ties in with the navystat definitions in the deprecated commodities.plist inside the original .oxp



I tried overriding it by following the advice immediately above:

Adding market_script = "galactic_navy_market_fix.js"; to the shipdata-overrides.plist in Spara's Galactic_Navy_Facelift.oxp

Code: Select all

"navystat" = {
		"model" = "adck_x-station.dat";
		market_script = "galactic_navy_market_fix.js"; // <---- here!
		script_info = {
			bgs_tunnel_texture = "spara_bgs_navy_tunnel.png";
		};
		...
		};
And then bunging this galactic_navy_market_fix.js in a brand new Scripts folder inside Spara's Galactic_Navy_Facelift.oxp

Code: Select all

{
"use strict";

this.name = "galactic_navy_market_fix";

//put the original defs here. no def is handled later.
this.$originalDefs = {
      "food" : [0, 0, 12, 0, 0, 0, 1, 0, 0],
      "textiles" : [0, 0, 18, 0, 0, 0, 3, 0, 0],
      "radioactives" : [0, 0, 93, 0, 0, 0, 7, 0, 0],
      "slaves" : [0, 0, 0, 0, 0, 0, 0, 0, 0],
      "liquor_wines" : [0, 0, 83, 0, 0, 0, 23, 0, 0],
      "luxuries" : [0, 0, 176, 0, 0, 0, 15, 0, 0],
      "narcotics" : [0, 0, 0, 0, 0, 0, 0, 0, 0],
      "computers" : [0, 0, 149, 0, 0, 0, 3, 0, 0],
      "machinery" : [0, 0, 117, 0, 0, 0, 7, 0, 0],
      "alloys" : [0, 0, 78, 0, 0, 0, 31, 0, 0],
      "firearms" : [0, 0, 0, 0, 0, 0, 0, 0, 0],
      "furs" : [0, 0, 0, 0, 0, 0, 0, 0, 0],
      "minerals" : [0, 0, 0, 0, 0, 0, 0, 0, 0],
      "gold" : [0, 0, 87, 0, 0, 0, 7, 0, 1],
      "platinum" : [0, 0, 154, 0, 0, 0, 31, 0, 1],
      "gem_stones" : [0, 0, 40, 0, 0, 0, 15, 0, 2],
      "alien_items" : [0, 0, 195, 0, 0, 0, 31, 0, 0]
};

this.updateLocalCommodityDefinition = function(goodDefinition) {
	var commodity = goodDefinition.key;
	var oldDefs = this.$originalDefs[commodity];
	
	//define the market size for the station
	goodDefinition.capacity = 127;
	
	//old style definition found for the good. calculate it the old way
	if (oldDefs) {
		var market_base_price = oldDefs[2];
		var market_eco_adjust_price = oldDefs[3];
		var market_eco_adjust_quantity = oldDefs[4];
		var market_base_quantity = oldDefs[5];
		var market_mask_price = oldDefs[6];
		var market_mask_quantity = oldDefs[7];
		var market_rnd = Math.floor(Math.random() * 256);

		var economy = system.economy;
		
		var price = (market_base_price + (market_rnd & market_mask_price) + (economy * market_eco_adjust_price)) & 255;
		price *= 0.4;
		
		var quantity = (market_base_quantity + (market_rnd & market_mask_quantity) - (economy * market_eco_adjust_quantity)) & 255;
		if (quantity > 127) quantity = 0;
		
		quantity &= 63;
		
		goodDefinition.quantity = quantity;
		goodDefinition.price = price * 10;
	}

	//no definition found. just add some variance to the system market (+/-5%)
	else {
		goodDefinition.price = goodDefinition.price * (1.05 - Math.random() * 0.1);
		goodDefinition.quantity = Math.floor(goodDefinition.quantity * (1.05 - Math.random() * 0.1));
	}

	//no definition found. no market on that commodity
	//else {
	//	goodDefinition.price = 0;
	//	goodDefinition.quantity = 0;
	//	goodDefinition.capacity = 0;
	//}

	//scale down if quantity too high
	if (goodDefinition.quantity > goodDefinition.capacity)
		goodDefinition.quantity = Math.floor(goodDefinition.quantity / 127 * goodDefinition.capacity);

	return goodDefinition;
};
}
Needless to say, the entire exercise has proved to be an utter bust!

What should I do?

I notice that
1) the original shipdata.plist is in XML, while the shipdataoverride.plist is in openstep.
But that did not stop anything else in the override from working so it seems irrelevant

2) the original shipdata.plist mentions a "navystat market", presumably directing Oolite to look for that in the deprecated "commodities.plist"
Might that be where things are going pear-shaped? (Since I have no override for the "market=navystat" entry in the override.plist) And if so, how do I correct for it?

3) alas, "latest.log" tells me nothing.

4) and, as a red herring, the famed "spara_bgs_navy_tunnel.png" seems to be missing from the textures folder!

Re-edited to make #2 less obscure
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
User avatar
Cholmondely
Archivist
Archivist
Posts: 4977
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Basic market fix for old oxps

Post by Cholmondely »

Just to add to this:

I presume that the override does not prevent the original shipdata.plist from linking to the deprecated commodities.plist (which therefore scuppers the market settings), making any reference to .js scripts irrelevant and ditto for inserting a market definition in the override.plist in Spara's .oxp

I did try this in the override instead

Code: Select all

	// Market Tester for SeCCom stations
{
	"navystat" = {
		"model" = "adck_x-station.dat";
		//market_script = "galactic_navy_market_fix.js";
		//added in for testing:
		market_capacity = 100;
		market_definition = (
		{
		"type" = "class";
		"name" = "oolite-thargoid";  <-- Alien Items
		"price_multiplier" = 1.5;
		"price_randomiser" = 0.3;
		"quantity_multiplier" = 0;
		"quantity_randomiser" = 0;
		}, 			
		{
		"type" = "class";
		"name" = "oolite-edible";  <-- Food, Liquor/wines + Fresh water & Oxygen
		"price_multiplier" = 1.3;
		"price_randomiser" = 0.3;
		"quantity_multiplier" = 0;
		"quantity_randomiser" = 0;
		},
		{
		"type" = "class";
		"name" = "oolite-shipyard";  <-- Alloys & Computers
		"price_multiplier" = 1.2;
		"price_randomiser" = 0.2;
		"quantity_multiplier" = 0;
		"quantity_randomiser" = 0;
		},
		{
		"type" = "default";
		"price_multiplier" = 0;
		"capacity" = 0;
		}
		);
		market_monitored = yes;  //  <--- registers the market for the "Commodities Markets" Screen on the F4 ship-station interfaces screen
		"allows_fast_docking" = "yes"; //added in for testing
		"allows_auto_docking" = "yes"; //added in for testing
		"requires_docking_clearance" = "yes"; //added in for testing
		script_info = {
			bgs_tunnel_texture = "spara_bgs_navy_tunnel.png";
		
		+ other stuff	
			
The AppleMac Terminal "plutil" capability passed the syntax as good.

But! The SecCom market did not appear on the F4 (MarketInquirer) Commodities Market screen at the GalCop main orbital station.

And when I docked at the SecCom, everything was priced at 0 (except for Quirium Crystals!) and with 0 TC for sale.

But on the SecCom F8 markets screen, the Market Observer price differentials were given for Food, Wines, Alloys, Computers, Fresh water*, Oxygen* and Alien Items (and Quirium Crystals, obviously). So the market definitions must have had some effect!

(* Fresh water and Oxygen are added in by SWEconomy.oxp - both tagged as "oolite-edible" in the tradesgoods.plist there)

I suspect that the deprecation of the commodities.plist is setting all the prices to 0 and shutting down the market. The dead horse is then flogged by the "market definition" in the overrides.plist which therefore creates Market Observer statistics just for the defined commodities, but does not give them a price.

Does this make sense?

And why is the Quirium Crystal registering a price (46.7₢) when nothing else does? Why is it not neutered by the deprecation of the commodities.plist? The quantity present is set to zero!

Edited to add: Changed nothing and tried a second time. Still no entry on the F4 (MarketInquirer) Commodities Market screen at the GalCop main orbital station.

But this time, when I docked, nothing!

No market observer statistics (no diff in price, % diff in price for the market value of 0₢). And no price for Quirium Crystal.

According to the Latest Log, the GalNavy OXPs were listed in the same order as they were for my first try (Matt's first, Spara's Overrides second). If that means anything.

ReEdited to add:
This also happens if I leave the system with the tweaked market and then re-enter it.
Last edited by Cholmondely on Wed Jun 14, 2023 2:00 pm, edited 1 time in total.
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2412
Joined: Mon May 31, 2010 11:11 pm

Re: Basic market fix for old oxps

Post by Switeck »

It is very hard to override markets of existing OXPs/OXZs without replacing their market-related files.
I gave up and edited a lot of them "by hand" to do that...and I'm still pretty unhappy with the results, as they mostly resemble the main station and I cannot seem to get the desired amount ranges or price ranges.
Post Reply