I can photograph the top of my head and show you if you like...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!
System.addShips
Moderators: winston, another_commander, Getafix
- DaddyHoggy
- Intergalactic Spam Assassin
- Posts: 8515
- Joined: Tue Dec 05, 2006 9:43 pm
- Location: Newbury, UK
- Contact:
Oolite Life is now revealed hereSelezen wrote:Apparently I was having a DaddyHoggy moment.
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*!
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)
- Commander McLane
- ---- E L I T E ----
- Posts: 9520
- Joined: Thu Dec 14, 2006 9:08 am
- Location: a Hacker Outpost in a moderately remote area
- Contact:
Cool!Kaks wrote:This should cover just about all coordinate conversion needs!Code: Select all
system.addShips("anarchies_hacker_outpost", 1,Vector3D([0, 0.6, 0.5]).fromCoordinateSystem('psu'),1)
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.
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.
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...
Hence we've added the fromCoordinateSystem() function...
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
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 ).
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.
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 ).
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.
- DaddyHoggy
- Intergalactic Spam Assassin
- Posts: 8515
- Joined: Tue Dec 05, 2006 9:43 pm
- Location: Newbury, UK
- Contact:
Ahruman created me some code in this thread - does this help?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 ).
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.
https://bb.oolite.space/viewtopic.php?t=8104
Oolite Life is now revealed hereSelezen wrote:Apparently I was having a DaddyHoggy moment.
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
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.Kaks wrote:Code: Select all
system.addShips("anarchies_hacker_outpost", 1,Vector3D([0, 0.6, 0.5]).fromCoordinateSystem('psu'),1)
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.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.
E-mail: [email protected]
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.
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.
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;
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.
Doing
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
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
instead of
Code: Select all
system.addShips("mine", 1, position)
In practice
Code: Select all
system.addShips("mine", 1, position,1)
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());
Code: Select all
log(this.name, "Mine added at " + position.toString());
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
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).docwild wrote:The missionVariables... Are they stings or numbers only?
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.
E-mail: [email protected]
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
My OXPs via Boxspace or from my Wiki pages .
Thargoid TV
Dropbox Referral Link
Thargoid TV
Dropbox Referral Link
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
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.Ahruman wrote: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.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.
E-mail: [email protected]