legacy_spawn

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

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

legacy_spawn

Post by Svengali »

legacy_spawn doesn't work similiar to the old legacy-scripting method. If a ship script uses the js-method the spawned thing (cargo,...) will be positioned at the players position. And if the player is slowly travelling he will possibly collide.

The same for legacy_spawnShip. The difference is that the spawned item is sometimes positioned (0,0,0).

The old legacy scripting methods in shipdata.plist are working as expected.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

legacy_spawn doesn't work similiar to the old legacy-scripting method. If a ship script uses the js-method the spawned thing (cargo,...) will be positioned at the players position. And if the player is slowly travelling he will possibly collide.
Possibly misuse of the function?? I used it already intensively in my tests and in UPS. it is working as expected in the death actions:

Code: Select all

    player.commsMessage("I'll be back with help for revenge!!", 5);
    system.legacy_spawn("ups-container", 5);
    system.legacy_spawn("textilepod", 15);
The cargo end up in the place........ On better thinking. (memory is getting old) I also found odditys in the placement of the cargo. Because I was close to the ship itself i just didn't realise it but now recollect one occasion were the placement was certainly wrong.
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 »

Seems like a problem with setting up the legacy scripting target. Worse, fixing it could be problematic. Hmm.

Tracked as bug #013086.
User avatar
Commander McLane
---- E L I T E ----
---- 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:

Post by Commander McLane »

As far as spawnShip: is concerned: Remember that it requires the specification of the desired position in the spawn-directory the entity's shipdata. If this is missing, I guess the entity could easily end up in position (0,0,0).
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

Commander McLane wrote:
As far as spawnShip: is concerned: Remember that it requires the specification of the desired position in the spawn-directory the entity's shipdata. If this is missing, I guess the entity could easily end up in position (0,0,0).
spawnShip: is a very unused function. It uses no placements co-ordinates but instead of that it uses the internal spawn directory for placement as Cmdr McLane writes. This function has to be used for very exact placements of objects as it also contains a orientation field. It is used for example to place the racing rings around Lave.
User avatar
TGHC
---- E L I T E ----
---- E L I T E ----
Posts: 2157
Joined: Mon Jan 31, 2005 4:16 pm
Location: Berkshire, UK

Post by TGHC »

could it be used to place generation ships further away from the witchpoint, to avoid crashes?
The Grey Haired Commander has spoken!
OK so I'm a PC user - "you know whats scary? Out of billions of sperm I was the fastest"
User avatar
Commander McLane
---- E L I T E ----
---- 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:

Post by Commander McLane »

@TGHC: No, it could only be used to give each Generation Ship its own, unique spawning-location. But the same can be achieved by other ways.

@Eric: I would love you to dig deeper into the orientation-key in the spawn-directory. I have no idea why it seems to work with the racing rings (probably it doesn't, but their correct orientation is due to something else?), because I never got it to work with any entity I tried with. No matter what orientation I give it, it is always spawned with its z-axis along the internal (absolute) z-axis. See the Hacker Outposts in Anarchies1.0.oxp as an example (which I am to upload soon).

EDIT: It seems I have run into a problem, that will further delay the release of Anarchies1.0.oxp. Ironically it is related to the very method discussed here. :? :(
User avatar
Commander McLane
---- E L I T E ----
---- 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:

Re: legacy_spawn

Post by Commander McLane »

Svengali wrote:
The same for legacy_spawnShip. The difference is that the spawned item is sometimes positioned (0,0,0).

The old legacy scripting methods in shipdata.plist are working as expected.
No, I have just encountered a case where an object spawned in the old plist style with spawnShip: was created at (0,0,0).

So both the old spawnShip: and the new legacy_spawnShip seem to be broken in the same way in 1.70.
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Post by Svengali »

Ok, after some more testing:

The position of the spawned thing is only sometimes (0,0,0) and sometimes the players position. Or maybe the ones position who has killed the ship. So it is necessary to correct the position after spawning.

Currently I'm using:

Code: Select all

this.shipDied = function()
{
	System.legacy_spawn('harkov_honeypod', 8);
	let posto = this.ship.position.add(3,1,5.6);
	let allpods = System.shipsWithRole('harkov_honeypod');
	allpods.reverse();
	for (let a = 8; a > 0; a--)
	{
		allpods[0].setPosition(posto.add(Math.random(),Math.random(),Math.random()));
		allpods.shift();
	}
}
But it is not always working. The problem is that if the player==killer and if he moves very slow the script will position the cargo to close to the player, so he will collide. And the other problem is that the sorting order is only based on the distance.

Any solutions?
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 »

The solution to spawn is already on svn, as reported here. Hopefully, it won't be too long before the release of Oolite 1.71...;)

Edit: As far as js is concerned, you could check the distance to the player with

Code: Select all

player.position.distanceTo(posto)
& then move posto accordingly if it's less than the distance desired....

Edit 2: in case player is already dereferenced, you could store a reference to player inside the ship script :

Code: Select all

this.beingAttacked = function(whom)
{
//find the player
if (whom.isPlayer) this.Player=whom;
//other stuff

}
then inside the this.shipDied function:

Code: Select all

if(this.Player && this.Player.position.distanceTo(posto)<20){
//stuff
}
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Post by Svengali »

Sorry Kaks,

maybe the problem was not clear. Just as explanation. My problem was that the moved pods were possibly not the spawned pods, because it is possible that there were already some of them out there. But after a little bit more thinking about it I found the solution. It is not totally safe, but a good workaround for the legacy_spawn problem in V1.70.

Code: Select all

/*
this.name           = "harkov_transporter";
this.author         = "Svengali";
this.copyright      = "Feb2008";
this.description    = "Localhero Part I - V1.03.5";
this.version        = "1.00";
*/
this.shipDied = function() { this.localhero_transport(); }

this.localhero_transport = function()
{
	system.legacy_spawn('harkov_honeypod', 8);
	let posto = this.ship.position.add(3,1,5.6);
	let allpods = system.shipsWithRole('harkov_honeypod');
	allpods.sort().reverse();
	for (let a = Math.min(8, allpods.length); a > 0; a--)
	{
		allpods[0].setPosition(posto.add(Math.random(),Math.random(),Math.random()));
		allpods.shift();
	}
}
sort() does the trick. Ahruman has told us that scooper is a concatenated string. And the other thing is to limit the number of loops, because it is possible that some pods were destroyed. I know that it is a timeintensive solution and maybe there is a better way. But it is a working solution. I have tested it with 3 Transports at the same time and the result was no reference error and they are doing their job.

Cheerio
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 »

Ahruman has told us that scooper is a concatenated string.
Not quite sure what you mean, scooper is an object, and I don't remember Ahruman saying 'scooper is a concatenated string.'

Still, we weren't talking about scooper, and I'm glad you found a solution for the actual problem you had. :)

Cheers,

Kaks
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Post by Svengali »

Kaks wrote:
Not quite sure what you mean, scooper is an object, and I don't remember Ahruman saying 'scooper is a concatenated string.'
Ok Kaks. You are right :lol: . He said
Ahruman wrote:
The square brackets don’t indicate an array. The standard behaviour of toString() for general objects is to return “[Object something]”, where “something” is the class of the object. Oolite’s toString() implementations use a variant of that syntax.
That gave me the hint to search for string-handling-methods. And allpods is similiar to scooper. A array with more infos in it (Name, ID, Position,...).
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 »

Svengali wrote:

Code: Select all

allpods[0].setPosition(posto.add(Math.random(),Math.random(),Math.random()));
This may not really be what you want, since the range of Math.random() is [0, 1). If you want a random offset, you’d be better off with something like:

Code: Select all

this.randomDirection = function()
{
    // Returns vectors distributed reasonably evenly over the unit sphere.
    function myRandom() { return Math.random() * 2 - 1; }
    let v;
    do
    {
        v = new Vector(myRandom(), myRandom(), myRandom());
    } while (v.magnitude() == 0); // Catch the unlikely event of v = (0, 0, 0)
    return v.direction();
}

this.randomVector = function(scale)
{
    // Returns vectors distributed reasonably evenly in a sphere of radius "scale".
    if (scale === undefined)  scale = 1;
    return this.randomDirection(). multiply(scale * Math.random());
}
randomDirection() has a slight bias towards the corners of the co-ordinate cube, but it’s unlikely to be noticeable. Vector should probably have these methods built in.
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Post by Svengali »

Muchas gracias, Ahruman.
Ahruman wrote:
This may not really be what you want, since the range of Math.random() is [0, 1).
That's all I wanted. There are 8 pods nearby to that position where the ship died. The explosion could possibly give the spawned cargo pods a momentum. That's what I wanted. The momentum isn't that high ( added(3,1,5.6) before) , so they will be more scattered. And the used AI will stop them. But maybe it would be better to define a variable for that case instead of calling Math.random() 3 times on every loop.

Another case will come to use your snippet. Thanks a lot.
Post Reply