System.addShips

For test results, bug reports, announcements of new builds etc.

Moderators: another_commander, winston, Getafix

User avatar
DaddyHoggy
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 8501
Joined: Tue Dec 05, 2006 9:43 pm
Location: Newbury, UK
Contact:

Post by DaddyHoggy »

Kaks wrote:Correction 2! The convenience method wasn't really that convenient! Removed it altogether from the code, and will edit my previous post accordingly!

PS: hmm, I seem to have one of them bad hair days... where's male pattern baldness when you need it! ;)
I can photograph the top of my head and show you if you like... :roll:
Selezen wrote:Apparently I was having a DaddyHoggy moment.
Oolite Life is now revealed here

User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

DH, thank you for the kind offer! :)

I was kind of hoping someone else would make a similar offer, but it looks like on this occasion I won't be able to say 'typical, you wait for years for it to come, then 2 come at once'! :)

*Disappointed*! ;)
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)

User avatar
Commander McLane
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Post by Commander McLane »

Kaks wrote:

Code: Select all

system.addShips("anarchies_hacker_outpost", 1,Vector3D([0, 0.6, 0.5]).fromCoordinateSystem('psu'),1)
This should cover just about all coordinate conversion needs! :)
Cool! :D

User avatar
docwild
Dangerous
Dangerous
Posts: 64
Joined: Thu Mar 29, 2007 1:36 pm

Post by docwild »

Wouldn't using the multiply method on a vector from 0 to the sun give a scaled vector? i.e a lengthened vector behind the sun by a factor of the authors choosing? It's been a long time but the interpolate can be used to invert a vector (go the other way) or split the distance by some factor and the random vector thingies to randomise the final location.

I've just started looking at the documentation and I think its those four methods (interpolate, multiply and the randomy ones) cover everything you need, quite simply. I could be wrong about everything though.

User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

They do, but if you're used to the legacy coordinates, thinking in vectors can be a strain.

Hence we've added the fromCoordinateSystem() function... :)
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)

User avatar
docwild
Dangerous
Dangerous
Posts: 64
Joined: Thu Mar 29, 2007 1:36 pm

Post by docwild »

I don't know if the wiki is purposefully vague but I think it could do with some non technical language explaining the methods. Someone said earlier that there was no way to calculate a position perpendicular to a given line but this is the purpose of the cross method. However, in the wiki the word perpendicular isn't used, instead it links to a fairly technical wikipedia article about the nature of vector analysis and specifically cross products in euclidean space.

It is at least feasible to assume that the average game modder won't be aware that vector addition is used for course plotting, vector multiplication to lengthen or shorten a given directional line or that the dot product of a given quat is used to calculate the relative difference of rotation (useful for AIs presenting a low profile :wink: ).

I really hate this elitist language of programming and mathematics. Which is why I say 'thingy' and 'doohicky' wherever possible. Let's face it, it isn't as hard as the technical manuals make it out to be.

User avatar
DaddyHoggy
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 8501
Joined: Tue Dec 05, 2006 9:43 pm
Location: Newbury, UK
Contact:

Post by DaddyHoggy »

docwild wrote:I don't know if the wiki is purposefully vague but I think it could do with some non technical language explaining the methods. Someone said earlier that there was no way to calculate a position perpendicular to a given line but this is the purpose of the cross method. However, in the wiki the word perpendicular isn't used, instead it links to a fairly technical wikipedia article about the nature of vector analysis and specifically cross products in euclidean space.

It is at least feasible to assume that the average game modder won't be aware that vector addition is used for course plotting, vector multiplication to lengthen or shorten a given directional line or that the dot product of a given quat is used to calculate the relative difference of rotation (useful for AIs presenting a low profile :wink: ).

I really hate this elitist language of programming and mathematics. Which is why I say 'thingy' and 'doohicky' wherever possible. Let's face it, it isn't as hard as the technical manuals make it out to be.
Ahruman created me some code in this thread - does this help?

http://www.aegidian.org/bb/viewtopic.php?t=8104
Selezen wrote:Apparently I was having a DaddyHoggy moment.
Oolite Life is now revealed here

User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

Kaks wrote:

Code: Select all

system.addShips("anarchies_hacker_outpost", 1,Vector3D([0, 0.6, 0.5]).fromCoordinateSystem('psu'),1)
A minor quibble: it’s possible, and slightly more efficient, to write Vector3D(0, 0.6, 0.5) instead of Vector3D([0, 0.6, 0.5]). This is the one case where you can still use a list of numbers for a vector.
docwild wrote:I really hate this elitist language of programming and mathematics. Which is why I say 'thingy' and 'doohicky' wherever possible. Let's face it, it isn't as hard as the technical manuals make it out to be.
Some more approachable, tutorial-type documentation for Oolite scripting in general and geometry in particular (also optics) would be very welcome. However, I’m not going to do it – I’m not capable of writing approachable tutorials, and just keeping the terse reference documentation up to date is a big job that detracts from coding time – and no-one else seems inspired to do it.

User avatar
docwild
Dangerous
Dangerous
Posts: 64
Joined: Thu Mar 29, 2007 1:36 pm

Post by docwild »

Hey, Arhuman. I understand. I have begun some scripting and I might be able to provide a small writeup about how the the methods are used and so forth if interested.

Code: Select all

//add unknown asteroids randomly
	for(let i = 1; i <= systemAsteroids; i++)
	{ 
		let basePosition = randomVector.add(station.position); //random direction from station
		if(i%2 == 0) //even number
			forwardDirection = station.orientation.vectorUp();
		else if(i != 0)//odd number
			forwardDirection = station.orientation.vectorForward();
		randomVector = randomVector.cross(forwardDirection).multiply(distance);
		let position = forwardDirection.add(randomVector); 
	
		tempShip = system.addShips("mine", 1, position); //add station randomly
		log(this.name, "Mine added at " + position.toString());
...
...
...
      missionVariables["miningSystemPerpetuity" + i] = arrayOfMines[i-1].position.toString();
		missionVariables["miningAllAsteroidNames" + i] = arrayOfMines[i-1].displayName;
will legacy addShipsAtPrecisely be more precise than the new addShips? It's never far off and I quite like the impression that they 'drift' anyway, but it may annoy someone, I spose.

The missionVariables... Are they stings or numbers only? How about arrays or vectors? Is it possible to store an object like a ship, with position and so forth? There doesn't seem to be much mentioned about them.

User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

Doing

Code: Select all

system.addShips("mine", 1, position)
is not very precise at all, because it will place the ship with role 'mine' randomly within scanner range (25600 metres) radius of the specified position.

In practice

Code: Select all

system.addShips("mine", 1, position,1)
is as precise as it needs to be. Well, in theory you can always try a radius of 0.001 metres, which should be placing the ship randomly within one millimetre of the specified position! Most people won't really be bothered to try and tell the difference between the two positions ( I'd personally be really happy if a ship is within 10 metres of where I expect it! ). Using legacy_addShipPrecisely won't really give you more precision than that: one thing to bear in mind with both system.addShips & the legacy methods: the engine will reposition ships automatically, if it detects a possible collision when creating them in the specified place, so the specified position is never guaranteed.

In the code above, a more useful log entry could have been

Code: Select all

log(this.name, "Mine requested at: " + position.toString() +"   - added at: " + tempShip[0].position.toString()); 
instead of

Code: Select all

log(this.name, "Mine added at " + position.toString()); 
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)

User avatar
docwild
Dangerous
Dangerous
Posts: 64
Joined: Thu Mar 29, 2007 1:36 pm

Post by docwild »

Thanks kaks. You also answered the question about repositioning even though I forgot to ask it. Now that's service.

I do have the other log entry, or its equivalent, which is how I know it wasn't precise. :wink:

User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

docwild wrote:The missionVariables... Are they stings or numbers only?
Mission variables are always strings internally. A mission variable with a numerical value is always converted to a number when retrieving it through JavaScript. If a non-string value (including a number) is assigned to a mission variable, it is converted to a string by the standard language mechanism, which generally corresponds to calling toString(). This behaviour is required for compatibility with the legacy scripting mechanism, where all variables are strings (but basic arithmetic is supported).

There is no useful way to store a reference to a ship in a mission variable. Non-player ships are not persisted across sessions (except, in a limited way, ships in scanned wormholes), and mission variables are only useful for persistence.

For other types, you’d need to serialize manually. There’s currently no JSON implementation in Oolite, but E4X is supported. (To store an XML object, use missionVariables.foo = myXML.toXMLString(); to restore it, use myXML = new XML(missionVariables.foo).)

A more general mechanism will probably be added after the next stable release.

User avatar
docwild
Dangerous
Dangerous
Posts: 64
Joined: Thu Mar 29, 2007 1:36 pm

Post by docwild »

Very nice, thank you.

Generating a ship/object explicitly given its attributes is much more elitey anyway.

Now there's a new adjective....

User avatar
Thargoid
Thargoid
Thargoid
Posts: 5510
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

And as a small comment, the role "mine" would probably not be your best choice to use in practice, as it's somewhat *ahem* generic ;)

User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

Ahruman wrote:
docwild wrote:I really hate this elitist language of programming and mathematics. Which is why I say 'thingy' and 'doohicky' wherever possible. Let's face it, it isn't as hard as the technical manuals make it out to be.
Some more approachable, tutorial-type documentation for Oolite scripting in general and geometry in particular (also optics) would be very welcome. However, I’m not going to do it – I’m not capable of writing approachable tutorials, and just keeping the terse reference documentation up to date is a big job that detracts from coding time – and no-one else seems inspired to do it.
I believe I mentioned the Wolfire blog’s tutorials on vectors a while ago, but part 3 came out today after a bit over a year.

Post Reply