Difference between revisions of "Oolite JavaScript Reference: Market Scripts"
m (→updateGeneralCommodityDefinition: not null) |
(Updating BB links) |
||
(6 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
'''Note: this page describes functionality currently only in the 1.81 development code. It may change further before being part of a stable release.''' | '''Note: this page describes functionality currently only in the 1.81 development code. It may change further before being part of a stable release.''' | ||
+ | |||
+ | == Preamble == | ||
+ | To tweak the pricing/availability of commodities in (''eg''.) a station, you need to define the market inside the station's Shipdata.plist - or include a "hook" inside that shipdata.plist to a javascript Oolite Market Script (which allows more complex definitions). | ||
From Oolite 1.81 it is possible for Javascript to be used to modify station, system and trade good prices. It is possible that a single trade good price/quantity calculation may be affected by more than one script. The order of events in the calculation is as follows: | From Oolite 1.81 it is possible for Javascript to be used to modify station, system and trade good prices. It is possible that a single trade good price/quantity calculation may be affected by more than one script. The order of events in the calculation is as follows: | ||
Line 22: | Line 25: | ||
In general this method should only modify the "price", "quantity", "capacity", "legality_export" and "legality_import" keys of the goodDefinition object. Modifying other keys is possible but significant caution should be used when doing so. | In general this method should only modify the "price", "quantity", "capacity", "legality_export" and "legality_import" keys of the goodDefinition object. Modifying other keys is possible but significant caution should be used when doing so. | ||
− | This method is called for scripts defined for the trade good, and is applied once for each market that good appears at. It may be called twice for the same good - once with station = false to set the primary market, and once with station = (Station) for each secondary market. In general distinguishing between these two cases and performing different modifications will be necessary. | + | This method is called for scripts defined for the trade good, and is applied once for each market that good appears at. It may be called twice for the same good - once with station = <code>false</code> to set the primary market, and once with station = (Station) for each secondary market. In general distinguishing between these two cases and performing different modifications will be necessary. |
=== updateLocalCommodityDefinition === | === updateLocalCommodityDefinition === | ||
Line 33: | Line 36: | ||
This method is called for scripts defined for the system or station, and is called once for each good in that market. To allow the same script to be applied to multiple systems or stations, the station and system parameters will give the current context. | This method is called for scripts defined for the system or station, and is called once for each good in that market. To allow the same script to be applied to multiple systems or stations, the station and system parameters will give the current context. | ||
+ | [https://bb.oolite.space/viewtopic.php?f=4&t=17621#p239979 Here is an example] of how to use this method. | ||
+ | |||
+ | == Links == | ||
+ | *[[Trade-goods.plist]] which combined the following two .plists: | ||
+ | :*Legacy script: [[Commodities.plist]] | ||
+ | :*Legacy script: [[Misc_plists#illegal_goods.plist|illegal goods.plist]] | ||
+ | |||
+ | === Examples === | ||
+ | ''These will be found at the bottom of the wiki page on the'' [[Trade-goods.plist]]. | ||
+ | *Setting an orbital main station's slaves on sale to zero | ||
+ | *Creating an invariant market independent of the local system economy (agricultural/industrial) | ||
[[Category:Oolite JavaScript Reference]] | [[Category:Oolite JavaScript Reference]] |
Latest revision as of 02:18, 29 February 2024
Note: this page describes functionality currently only in the 1.81 development code. It may change further before being part of a stable release.
Contents
Preamble
To tweak the pricing/availability of commodities in (eg.) a station, you need to define the market inside the station's Shipdata.plist - or include a "hook" inside that shipdata.plist to a javascript Oolite Market Script (which allows more complex definitions).
From Oolite 1.81 it is possible for Javascript to be used to modify station, system and trade good prices. It is possible that a single trade good price/quantity calculation may be affected by more than one script. The order of events in the calculation is as follows:
- Firstly, the primary system market is calculated
- The trade good price and quantity are generated from the values in trade-goods.plist
- The
updateGeneralCommodityDefinition
handler of the commodity's market_script will be called to set primary market data for the trade good - The
updateLocalCommodityDefinition
handler of the system's market_script will be called to modify primary market data for the trade good.
- Secondary markets are then calculated for each non-main station
- The primary system market is copied into the secondary market, and then quantities are scaled to the station's market capacity
- If the station does not have a market script, the rules in its market_definition are applied.
- The
updateGeneralCommodityDefinition
handler of the commodity's market_script will be called again to set secondary market data for the trade good. - The
updateLocalCommodityDefinition
handler of the station's market_script will be called to modify secondary market data for the trade good.
Handlers
updateGeneralCommodityDefinition
This method was added in Oolite test release 1.81.
function updateGeneralCommodityDefinition (goodDefinition : Object, station : Station, system : Int) : Object
This method takes an object containing the current good definition (keys as in trade-goods.plist, with an additional "price" key for the current price, "quantity" for the current quantity, and "key" for the identifier of the trade good in the plist), carries out modifications to it based on the station and system, and returns the object in the same format.
In general this method should only modify the "price", "quantity", "capacity", "legality_export" and "legality_import" keys of the goodDefinition object. Modifying other keys is possible but significant caution should be used when doing so.
This method is called for scripts defined for the trade good, and is applied once for each market that good appears at. It may be called twice for the same good - once with station = false
to set the primary market, and once with station = (Station) for each secondary market. In general distinguishing between these two cases and performing different modifications will be necessary.
updateLocalCommodityDefinition
This method was added in Oolite test release 1.81.
function updateLocalCommodityDefinition (goodDefinition : Object, station : Station, system : Int) : Object
This method takes an object containing the current good definition (keys as in trade-goods.plist, with an additional "price" key for the current price, "quantity" for the current quantity, and "key" for the identifier of the trade good in the plist), carries out modifications to it based on the station and system, and returns the object in the same format.
In general this method should only modify the "price", "quantity", "capacity", "legality_export" and "legality_import" keys of the goodDefinition object. Modifying other keys is possible but significant caution should be used when doing so.
This method is called for scripts defined for the system or station, and is called once for each good in that market. To allow the same script to be applied to multiple systems or stations, the station and system parameters will give the current context.
Here is an example of how to use this method.
Links
- Trade-goods.plist which combined the following two .plists:
- Legacy script: Commodities.plist
- Legacy script: illegal goods.plist
Examples
These will be found at the bottom of the wiki page on the Trade-goods.plist.
- Setting an orbital main station's slaves on sale to zero
- Creating an invariant market independent of the local system economy (agricultural/industrial)