(WIP) Elite Trader

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

Moderators: another_commander, winston

another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6552
Joined: Wed Feb 28, 2007 7:54 am

Re: (WIP) Elite Trader

Post by another_commander »

I think spara refers to player.credits.

Almost everything you can imagine in Oolite has a handler, a property or a method associated with it. Look at this page: http://wiki.alioth.net/index.php/Catego ... _Reference

There is a lot to study in there.
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: (WIP) Elite Trader

Post by spara »

What a_c says :D. Check the change in credits between entering and leaving the market screen. That's a start at least.
User avatar
Reval
---- E L I T E ----
---- E L I T E ----
Posts: 402
Joined: Thu Oct 29, 2020 3:14 am
Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.

Re: (WIP) Elite Trader

Post by Reval »

OMG yes - that is indeed simple :)
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6552
Joined: Wed Feb 28, 2007 7:54 am

Re: (WIP) Elite Trader

Post by another_commander »

Yes. You can easily check this if you enter system.mainStation.name in the debug console and see if it responds with a value or not.

Since ship inherits from Entity, you can also use any property that belongs in Entity.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6552
Joined: Wed Feb 28, 2007 7:54 am

Re: (WIP) Elite Trader

Post by another_commander »

You can also see the full properties set of an item if you execute e.g. :d system.mainStation in the console. This will return with the full JSON dictionary of all properties of the item you request.
User avatar
Reval
---- E L I T E ----
---- E L I T E ----
Posts: 402
Joined: Thu Oct 29, 2020 3:14 am
Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.

Re: (WIP) Elite Trader

Post by Reval »

Thanks. Off-topic, but there's something amiss with my debug console. I see in the log:

Code: Select all

06:01:56.578 [debugTCP.disconnect]: No connection to debug console: "Connection to debug console failed: 'No se ha podido establecer conexión ya que el equipo de destino ha denegado activamente dicha conexión. (outStream status: 7, inStream status: 7)."
06:01:56.578 [debugTCP.send.warning]: Error sending packet header, retrying.
06:01:56.625 [debugTCP.send.error]: The following packet could not be sent: {"Oolite version" = 1.90; "packet type" = "Request Connection"; "protocol version" = 65792; }
06:01:56.828 [debugTCP.disconnect]: No connection to debug console: "Connection to debug console failed: 'bad stream.' (outStream status: 0, inStream status: 0)."
06:01:56.828 [debugTCP.connect.failed]: Failed to connect to debug console at address 127.0.0.1:8563.
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6552
Joined: Wed Feb 28, 2007 7:54 am

Re: (WIP) Elite Trader

Post by another_commander »

This means the debug console is not running when Oolite is launched. If it is running, maybe there is a firewall getting in the way?
User avatar
Reval
---- E L I T E ----
---- E L I T E ----
Posts: 402
Joined: Thu Oct 29, 2020 3:14 am
Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.

Re: (WIP) Elite Trader

Post by Reval »

How do I check? - I've never attempted to use it before.

Also, I have a WAMP installation and I can access localhost (127.0.0.1:80) no problem.
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6552
Joined: Wed Feb 28, 2007 7:54 am

Re: (WIP) Elite Trader

Post by another_commander »

1. Launch the Oolite debug console application, make sure it is running and you can see the message "Waiting for connection...".
2. Launch Oolite test release version. The game launches and you should see the message "Opened connection with Oolite version 1.90" on the console window.
3. At this point you can start typing commands in the console.

If this does not happen, then you have one of those issues:
1. You are not running the test release of Oolite.
2. There is a firewall blocking the connection. Windows firewall normally wakes up and pops a confirmation window the very first time you run the console asking if yοu allow it access, but I am not sure if this happens also on WinXP.
User avatar
Reval
---- E L I T E ----
---- E L I T E ----
Posts: 402
Joined: Thu Oct 29, 2020 3:14 am
Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.

Re: (WIP) Elite Trader

Post by Reval »

another_commander wrote: Tue Nov 10, 2020 12:06 pm
1. Launch the Oolite debug console application, make sure it is running and you can see the message "Waiting for connection...".
Ah, is that a separate download? I don't think I have it (at least no other .exe's under oolite.app).
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6552
Joined: Wed Feb 28, 2007 7:54 am

Re: (WIP) Elite Trader

Post by another_commander »

OMG please don't tell me you are trying to write OXPs without the debug console. This is like trying to write a program in hexadecimal machine code when there are compilers out there!

Save yourself from the pain; go straight to http://oolite.org/download/ and get the OoDebugConsole1.5.zip. Decompress the executable to your root Oolite folder. Then enjoy OXPing the way it was meant to be.
User avatar
Reval
---- E L I T E ----
---- E L I T E ----
Posts: 402
Joined: Thu Oct 29, 2020 3:14 am
Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.

Re: (WIP) Elite Trader

Post by Reval »

:) Ok! (yes, that's exactly what I was doing, hehe). Thanks for the link - found it at github too.
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
User avatar
Reval
---- E L I T E ----
---- E L I T E ----
Posts: 402
Joined: Thu Oct 29, 2020 3:14 am
Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.

Re: (WIP) Elite Trader

Post by Reval »

Status update: Still not quite totally glitch-free, but all the 'player changes mind and sells a few units/buys others' now gives sensible values for the hold-contents. I've been bashing it pretty hard to test this. And I'm still striving to avoid those game-saves (but I may have to throw in the towel ;) )

Code: Select all

"use strict";

this.name = "Elite Trader";
this.author = "Reval";
this.description = "A profitable Market trade scores toward Elite";

/*  Version 0.1 Beta
	
	This OXP takes no account of cargo contracts,
	special deals, scoops of drifting cargo in space, 
	or of gems or precious metals.
	
	NB. If the game loads with full holds, the first score is missed.
*/

	
this.playerSoldCargo = function(commodity, units, price) {

	// selling preliminaries - update quantity and price
	if (this.$etLastPrice[commodity]>0) {
		this.$etSoldUnits += units;
		this.$etSoldPrice += price * units;
	}
	
	// see if we made a profit
	this.$etMadeProfit = ((this.$etSoldPrice > this.$etBoughtPrice) && (this.$etLastPrice[commodity] > 0));
	
	// conditions for scoring
	this.$etOKtoScore = ((units > 2) && (!this.$etDone) && (this.$etBoughtUnits>0) && (this.$etMadeProfit));
	
	// decrement the manifest by # of units and price
	if (this.$etLastPrice[commodity]>0) {
		this.$etBoughtUnits -= units;
		this.$etBoughtPrice -= this.$etLastPrice[commodity] * units;
	}
	
	// display ship's cargo and its purchase value
	if (price==this.$etLastPrice[commodity])
		player.consoleMessage("In hold: "+this.$etBoughtUnits+" pods ( "+formatCredits(((this.$etBoughtPrice)/10),true,true)+" )");

	// credit a "market killing" on first profitable sell
	if (this.$etOKtoScore) {
		player.score ++;
		player.consoleMessage("You made a killing!");
		// for simplicity, only one score per station
		this.$etDone = true;
	// otherwise acknowledge a skillful trade if we're not just unloading
	} else if (this.$etMadeProfit && (price!=this.$etLastPrice[commodity])) 
		player.consoleMessage("Nice trade!");
}
	

this.playerBoughtCargo = function (commodity, units, price) {
	// buying preliminaries - record quantity and price
	this.$etBoughtUnits += units;
	this.$etBoughtPrice += price * units;
	this.$etLastPrice[commodity] = price;
	// display ship's cargo and its purchase value
	player.consoleMessage("In hold: "+this.$etBoughtUnits+" pods ( "+formatCredits(((this.$etBoughtPrice)/10),true,true)+" )");
}


this.shipDockedWithStation = function(station) {
	// clear flags and sold-quantities on docking
	this.$etDone = false;
	this.$etMadeProfit = false;
	this.$etSoldUnits = 0;
	this.$etSoldPrice = 0;
}


this.startUp = function() {
    log(this.name, "Initialising OXP " + this.name);
	// declare & initialize globals
	this.$etDone = false;
	this.$etMadeProfit = false;
	this.$etOKtoScore = false;
	this.$etSoldUnits = 0;
	this.$etSoldPrice = 0;
	this.$etBoughtPrice = 0;
	this.$etBoughtUnits = 0;
	this.$etLastPrice = new Array();
	for (var c=0; c<20; c++) this.$etLastPrice[c]=0;
}
Still adequately simple per the mission, though.
Last edited by Reval on Thu Nov 12, 2020 2:55 pm, edited 5 times in total.
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
User avatar
Reval
---- E L I T E ----
---- E L I T E ----
Posts: 402
Joined: Thu Oct 29, 2020 3:14 am
Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.

Re: (WIP) Elite Trader

Post by Reval »

Would the following be an acceptable global array declaration in Oolite JS?

Code: Select all

this.$etManifest1 = new Array();
(So says my Javascript: The Definitive Guide, for standard JS, at least).

Edit: And a comon-or-garden function/method definition... like so?

Code: Select all

this.getManifest = function() {
}
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Re: (WIP) Elite Trader

Post by dybal »

Reval wrote: Wed Nov 11, 2020 4:23 am
Would the following be an acceptable global array declaration in Oolite JS?

Code: Select all

this.$etManifest1 = new Array();
Yep, or you could do:

Code: Select all

this.$etManifest1 = [];
Reval wrote: Wed Nov 11, 2020 4:23 am
Edit: And a comon-or-garden function/method definition... like so?

Code: Select all

this.getManifest = function() {
}
I would suggest putting a '$' or '_' in front of the variable name that holds the function reference just to guard against the possibility of an event handler named getManifest being defined in future Oolite versions.

And it might be worthwhile to define a name for the function (with a prefix unique to your OXP), it can make some error and exceptions messages from the scripting engine in Latest.log more informative:

Code: Select all

this.$getManifest = function eliteTrader_getManifest() {
}
Post Reply