Scripters cove

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

Moderators: winston, another_commander

User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16081
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Scripters cove (the new station.market object (in v1.81+

Post by Cody »

phasted_too wrote:
I've just started to sit down and think about how all of this new stuff can be used to make Real-life Economics better...
Phasted, I presume? Did you forget your password?
I would advise stilts for the quagmires, and camels for the snowy hills
And any survivors, their debts I will certainly pay. There's always a way!
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove (the new station.market object (in v1.81+

Post by cim »

phasted_too wrote:
The central concept in RLE is the econBalance. econBalance is calculated by the _determineMarket() method which is called by the shipWillExitWitchspace() event handler... unless I'm misunderstanding something, I think I need econBalance to be in place before trade-goods.plist works its magic, but I'm not sure it will be.

So, my question: does Oolite v1.81+ calculate prices and quantities after the player has "arrived" in the new system (after the tunnel effect)? Is shipWillExitWitchspace() called before Oolite calculates prices and quantities?
shipWillExitWitchspace would be too late. The easiest thing to do would be to generate it in the market script itself:

Code: Select all

this.name = "RLE Market Script";

this.$econBalance = 0;
this.$lastSystem = -1;

this.updateLocalCommodityDefinition = function(marketdef, station, system) {
  if (system.ID != this.$lastSystem) {
    this.$econBalance = ...; // recalculate it here
    this.$lastSystem = system.ID;
  }

  // ... and now use the economy balance as needed
}
phasted_too wrote:
Another thing that has me absolutely stumped: what's the difference between the market script specified in planetinfo.plist and the one called for by trade-goods.plist. Do I need both? Do I need either one? An actual working example (even a silly trivial one) would be a gift from heaven...
They both do similar things - it depends what you're trying to do. The market script in planetinfo.plist is for people trying to amend the system prices, for multiple - perhaps all - trade goods. The market script in trade-goods.plist is to give special market behaviour to that specific trade good.

In your case, planetinfo.plist is the way to go, since you want to update all (or at least most) goods on a system-by-system basis. Here's a quick (untested, so there might be a typo) example. We'll assume this is being applied to a single system only:

Code: Select all

this.name = "Test market script";

this.updateLocalCommodityDefinition = function(marketdef, station, systemID) {
    // big sales on food right now
    if (marketdef.classes.indexOf("oolite-edible") > -1) {
        // if the good is in the "edible" class - Food, Liquor/Wines, or an edible OXP-defined trade good
        // edit its market definition to lower the price and boost the quantity
        marketdef.price = Math.floor(marketdef.price*0.75); // 25% off
        marketdef.quantity = marketdef.quantity * 2;
    }
    // else it's not edible and we don't adjust the market from its previous definition
    return marketdef;
}
A trade-goods.plist market script would be to add particular behaviour to a single trade good (or group of trade goods defined by one OXP). Here's one for a hypothetical "sunscreen" trade good - it has normal pricing by economy set up in the trade-goods.plist, but then we want to tweak that to raise the prices if the local star is particularly bright.

Code: Select all

this.updateGeneralCommodityDefinition = function(marketdef, station, systemID) {
    if (system.info.sun_radius > 200000 && !station) {
        // really big star
        marketdef.quantity = 0; // no stock for export - everyone is using it
        marketdef.price = Math.floor(marketdef.price*1.2); // 20% price bonus
        marketdef.legality_export = 3; // strongly discouraging taking it out of the system
    }
    // otherwise just use the normal pricing
    return marketdef;
}
The !station is because the method gets called twice - once to set system prices and once to set station prices. We only want to make the price modification once, on the system pricing.
phasted_too
Poor
Poor
Posts: 4
Joined: Sun Apr 26, 2015 10:15 am

Re: Scripters cove (the new station.market object (in v1.81+

Post by phasted_too »

Cody wrote:
phasted_too wrote:
I've just started to sit down and think about how all of this new stuff can be used to make Real-life Economics better...
Phasted, I presume? Did you forget your password?
Yep... tried to request a new one... the BB software swears up and down that it sent me one but there's nothing in my inbox. So, I'm locked out of the old account.
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16081
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Scripters cove (the new station.market object (in v1.81+

Post by Cody »

phasted_too wrote:
So, I'm locked out of the old account.
Different email address, possibly? <pages Disembodied>
I would advise stilts for the quagmires, and camels for the snowy hills
And any survivors, their debts I will certainly pay. There's always a way!
User avatar
Disembodied
Jedi Spam Assassin
Jedi Spam Assassin
Posts: 6885
Joined: Thu Jul 12, 2007 10:54 pm
Location: Carter's Snort

Re: Scripters cove

Post by Disembodied »

phasted_too wrote:
Yep... tried to request a new one... the BB software swears up and down that it sent me one but there's nothing in my inbox. So, I'm locked out of the old account.
Your old account uses a different email address to your new account - maybe the password was sent there? If not, and you want to reactivate it, I can PM you a new password for your old account.

Edit: ninja'd - what Cody said!
phasted_too
Poor
Poor
Posts: 4
Joined: Sun Apr 26, 2015 10:15 am

Re: Scripters cove

Post by phasted_too »

Your old account uses a different email address to your new account - maybe the password was sent there? If not, and you want to reactivate it, I can PM you a new password for your old account.
[/quote]

The board wouldn't let me sign up for new account using the old e-mail... two accounts using the same address is apparently a no-no...

Please PM me a new password... I'd prefer to use the old account...

Thanks.
phasted_too
Poor
Poor
Posts: 4
Joined: Sun Apr 26, 2015 10:15 am

Re: Scripters cove (the new station.market object (in v1.81+

Post by phasted_too »

cim wrote:
shipWillExitWitchspace would be too late. The easiest thing to do would be to generate it in the market script itself:

Code: Select all

this.name = "RLE Market Script";

this.$econBalance = 0;
this.$lastSystem = -1;

this.updateLocalCommodityDefinition = function(marketdef, station, system) {
  if (system.ID != this.$lastSystem) {
    this.$econBalance = ...; // recalculate it here
    this.$lastSystem = system.ID;
  }

  // ... and now use the economy balance as needed
}
phasted_too wrote:
Another thing that has me absolutely stumped: what's the difference between the market script specified in planetinfo.plist and the one called for by trade-goods.plist. Do I need both? Do I need either one? An actual working example (even a silly trivial one) would be a gift from heaven...
They both do similar things - it depends what you're trying to do. The market script in planetinfo.plist is for people trying to amend the system prices, for multiple - perhaps all - trade goods. The market script in trade-goods.plist is to give special market behaviour to that specific trade good.

In your case, planetinfo.plist is the way to go, since you want to update all (or at least most) goods on a system-by-system basis. Here's a quick (untested, so there might be a typo) example. We'll assume this is being applied to a single system only:

Code: Select all

this.name = "Test market script";

this.updateLocalCommodityDefinition = function(marketdef, station, systemID) {
    // big sales on food right now
    if (marketdef.classes.indexOf("oolite-edible") > -1) {
        // if the good is in the "edible" class - Food, Liquor/Wines, or an edible OXP-defined trade good
        // edit its market definition to lower the price and boost the quantity
        marketdef.price = Math.floor(marketdef.price*0.75); // 25% off
        marketdef.quantity = marketdef.quantity * 2;
    }
    // else it's not edible and we don't adjust the market from its previous definition
    return marketdef;
}
marketDef.classes!! That's a smokin' brilliant idea... I wouldn't have thought of it on my own (from reading the documentation I got the impression that classes were only useful in secondary markets). I'll define two classes of my own ("RLE-ag" and "RLE-ind") and deal with all of the commodities in two easy-to-handle groups... that should simplify a lot of things... I hope.

So, I guess I've got my work cut out for me. I'll have to re-write _activateMarket() completely from the ground up (it makes extensive use of the pre-1.81 station.market object) and I'll have to pull _determineMarket() out of the world script and put it in the market script and re-write it almost completely from the ground up.

* sigh * :(

But at least now I have a rough idea of what I'm doing...

Thanks, cim...
User avatar
Disembodied
Jedi Spam Assassin
Jedi Spam Assassin
Posts: 6885
Joined: Thu Jul 12, 2007 10:54 pm
Location: Carter's Snort

Re: Scripters cove

Post by Disembodied »

phasted_too wrote:
Please PM me a new password... I'd prefer to use the old account...
PM sent!
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove (the new station.market object (in v1.81+

Post by cim »

phasted_too wrote:
marketDef.classes!! That's a smokin' brilliant idea... I wouldn't have thought of it on my own (from reading the documentation I got the impression that classes were only useful in secondary markets). I'll define two classes of my own ("RLE-ag" and "RLE-ind") and deal with all of the commodities in two easy-to-handle groups... that should simplify a lot of things... I hope.
Defining your own classes probably isn't the best approach here - you'd need to override the core trade-goods.plist to do it, and they then wouldn't be available on new goods.

Easier is probably to use marketDef.peak_import and marketDef.peak_export to determine whether a good is agricultural or industrial. (You could also get an OXP good which was for example peak_import = 0 and peak_export = 2 - goes from Poor Industrial to Rich Industrial systems, and Agricultural systems don't really care about it.)
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

Can someone point me in the right direction here?

I'm trying to manually create a group of ships. But while all the code I write seems to work, in that ships are added and groups are created and ships are attached, the escort ships don't seem to follow the leader. Here's what I have:

Code: Select all

	// create a cobra 3 trader, give it some cargo, and set the outbound destination
	var ships = system.addShips("[cobra3-trader]", 1, p.position.add(p.vectorForward.multiply(10000)), 1000);
	ships[0].fuel = 7;
	ships[0].shipUniqueName = "My Cobbie";
	ships[0].setCargoType("PLENTIFUL_GOODS");
	ships[0].homeSystem = system.ID;
	ships[0].destinationSystem = 252;

	// create a new ship group and make the cobbie the leader
	var shipG = new ShipGroup("mygroup1", ships[0]);
	ships[0].group = shipG;

	// create a sidewinder escort and offer to escort the cobbie
	var grp1 = system.addShips("[sidewinder-escort]", 1, p.position.add(p.vectorForward.multiply(10000)), 1000);
	grp1[0].shipUniqueName = "My Sidewinder";
	grp1[0].offerToEscort(ships[0]);

	// add the sidewinder to the group
	shipG.addShip(grp1[0]);
	grp1[0].group = shipG;

	// create a mamba escort and offer to escort the cobbie
	var grp2 = system.addShips("[mamba-escort]", 1, p.position.add(p.vectorForward.multiply(10000)), 1000);
	grp2[0].shipUniqueName = "My Mamba";
	grp2[0].offerToEscort(ships[0]);

	// add the mamba to the group
	shipG.addShip(grp2[0]);
	grp2[0].group = shipG;
But the cobbie just jumps out, leaving the 2 escorts behind. They don't follow him through the wormhole. What have I missed?
User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2577
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Scripters cove

Post by Norby »

Maybe grp1[0].switchAI("escortAI.plist");
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

Two, maybe three things, I think.

Firstly, as Norby points out, you need to give them an escort AI or they won't know how to react to escort commands like "follow through wormhole". oolite-escortAI.js is probably better to use nowadays if you want a standard one, or you can write your own.

Secondly, only certain ships can be escorts: specifically, they need to have a primary role in the oolite-escort role category from role-categories.plist. Setting the primary role to "escort" is probably the easiest.

Thirdly, a cobra3-trader might not actually have any escort slots available. I think in this case it'll be okay, though, and it will default to the 16 maximum.

Check the return value of offerToEscort - if it's false, something went wrong.

(You don't need to add the escorts to the group, by the way - they'll automatically be added to the escortGroup if the escort request is accepted)
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

Quick one: what controls the sort order of equipment items for sale on the F3 screen? I thought it was install time, but I've seen things out of that order. It doesn't appear to be name either, or cost.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

It used to be load order. So on Windows, alphabetical order of the containing OXPs -ish. But since 1.80 there's a sort order key in equipment.plist...?

Edit: I was thinking of the order on the status screen.
Last edited by Wildeblood on Fri May 22, 2015 5:52 am, edited 1 time in total.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

Sort order if set, but it usually isn't. Otherwise techlevel and cost.
Post Reply