JS and wormholes

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

Moderators: winston, another_commander

Post Reply
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:

JS and wormholes

Post by Commander McLane »

What about wormholes is currently exposed to JS? I haven't found anything in the documentation, except that world script event handler shipWillEnterWitchspace can have "wormhole" as the value of its cause-parameter.

Specifically I'd like to know whether
  • there exists an undocumented wormhole JS-object? (S.entitiesWithScanClass("CLASS_WORMHOLE") for instance returns an empty array; also when targeting a wormhole PS.target is null; so I guess the answer is no);
  • at least some properties (like duration and destination) can be accessed by JS? Specifically, I'd like to have my script know the destination of the wormhole the player is currently entering; player.ship.targetSystem returns the system selected on the map, not the system the entered wormhole leads to.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: JS and wormholes

Post by Eric Walch »

From the code:

Code: Select all

			// Should probably pass the wormhole, but they have no JS representation
			[ship doScriptEvent:OOJSID("shipExitedWormhole") andReactToAIMessage:@"EXITED WITCHSPACE"];
The comment says enough: currently none of the code it prepared to pass wormholes as parameter. Wormholes are no ship class.
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: JS and wormholes

Post by Commander McLane »

:sigh: I was afraid so.

I was alerted to a glitch in wormhole_restoration.oxp which can only be solved with JS-knowledge about wormholes:

If the player follows an NPC-wormhole and misjumps, he is of course headed to the NPC's target system, not to his own. Therefore the re-created wormhole out of interstellar space should lead to the NPC's target system, not his own. But the script is only storing the player's target system.

And without being able to read out a wormhole's destination I can't change that.
User avatar
Staer9
---- E L I T E ----
---- E L I T E ----
Posts: 570
Joined: Fri Feb 18, 2011 4:53 pm
Location: Hatfield, Hertfordshire (poor industrial)

Re: JS and wormholes

Post by Staer9 »

So therefore, it could just be a bad understanding, if I misjump and your wormhole_restoration.oxp is active, then if I change my target system and reactivate the wormhole I will go there instead... even if it is on the other side of the galaxy?
Image
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: JS and wormholes

Post by Capt. Murphy »

You can derive duration when you can access the mass of the NPC ship the created the wormhole via JS. Can't help with destination.

duration in seconds = 50 + (mass/4000).
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
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: JS and wormholes

Post by Commander McLane »

Staer9 wrote:
So therefore, it could just be a bad understanding, if I misjump and your wormhole_restoration.oxp is active, then if I change my target system and reactivate the wormhole I will go there instead... even if it is on the other side of the galaxy?
No, the OXP stores your target system the moment you do the misjump. If you target another system while you're still in interstellar space, that won't change anything. The saving wormhole always goes to the system you had targeted when you first misjumped.

So the problem only happens if you had targeted one system, but jumped to another system by following an NPC's wormhole, and this NPC (and therefore you in its footsteps) has a misjump. The chances for that are fairly low.

Nevertheless, I still have an idea how to possibly fix this. I am at it right now.
User avatar
Staer9
---- E L I T E ----
---- E L I T E ----
Posts: 570
Joined: Fri Feb 18, 2011 4:53 pm
Location: Hatfield, Hertfordshire (poor industrial)

Re: JS and wormholes

Post by Staer9 »

Thats a pity, it would be a great way of traveling long distances really fast :wink:
Image
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: JS and wormholes

Post by Commander McLane »

Capt. Murphy wrote:
You can derive duration when you can access the mass of the NPC ship the created the wormhole via JS. Can't help with destination.

duration in seconds = 50 + (mass/4000).
Thanks, but I only need the destination anyway.

Also, it's effectively impossible to access the NPC. The player may only decide to enter a wormhole when the NPC has already jumped out. The script can't foresee which wormhole the player is going to choose, or if he chooses any in the first place.
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: JS and wormholes

Post by Commander McLane »

Staer9 wrote:
Thats a pity, it would be a great way of traveling long distances really fast :wink:
The 7LY rule is set in stone in Oolite. There's no way around it.

It's one of the very few absolutely fixed things, because changing it would have a massive impact on gameplay and game balance, to the point of altering the game beyond recognition.

To put it very simply: the 7LY rule is one of the defining features of Elite. Altering it would result in a type of game that is not Elite. But Oolite is a type of game that is Elite.
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: JS and wormholes

Post by Commander McLane »

Another question to the code/JS-wizards: does a function exist that returns a system number or possibly a systemInfo object if fed a set of galactic coordinates?

Never mind, I got it (this.originSystem was stored before the jump):

Code: Select all

this.shipWillExitWitchspace = function()
{
    <snip>
    // the target system of the jump is established
    this.originCoordinates = System.infoForSystem(galaxyNumber, this.originSystem).coordinates;
    this.currentCoordinates = system.info.coordinates;
    this.coordinatesDifference = this.currentCoordinates.subtract(this.originCoordinates);
    this.jumpLength = this.coordinatesDifference.multiply(2);
    this.targetCoordinates = this.originCoordinates.add(this.jumpLength);
    this.targetSystemInfo = SystemInfo.filteredSystems(this, function(other){return (other.coordinates.squaredDistanceTo(this.targetCoordinates) < 0.0000001)});
    this.targetSystem = this.targetSystemInfo[0].systemID;
So in the next version of wormhole_restoration.oxp the wormhole out of interstellar space will always to the correct system, the one you were actually heading for. :D
Post Reply