Get sector/zone position given highway coordinates

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Post Reply
redmessy
Posts: 5
Joined: Thu, 30. Dec 21, 04:50

Get sector/zone position given highway coordinates

Post by redmessy » Thu, 30. Dec 21, 05:09

Hi,

I've spent 3 days now trying to figure this out - any help would be greatly appreciated.

Given highway coordinates (x = y = 0, z in [0,1]) within some highway, e.g. like what you get from 'get_global_path' with the 'offset' attribute, for the life of me I can't figure out how to convert those into a sector or zone position. Looking up close at a highway path on the map, it looks a bit like they're defined piecewise, like with a spline.

I assumed there'd be some function I could pass a highway, the 1-dimensional highway coordinate and a space to get a position in that space. From 'get_closest_highway_offset', I can "go in the other direction", i.e. get highway coordinates from a sector/zone position. If the inverse of that function exists, I don't know what it's called.

What am I missing?

Thank you!

Edit: corrected highway z-coordinate interval
Last edited by redmessy on Wed, 5. Jan 22, 23:48, edited 1 time in total.

redmessy
Posts: 5
Joined: Thu, 30. Dec 21, 04:50

Re: Get sector/zone position given highway coordinates

Post by redmessy » Wed, 5. Jan 22, 23:38

Looking at library 'DistanceAcrossClusters' in 'md/lib_generic.xml', which also uses 'get_global_path' to calculate travel path distance across clusters, it seems to explicitly avoid dealing with highways. I want to implement the same as this library but with taking highways into account.

My guess is this library either avoids highways because it was deemed too computationally expensive to include them or because there's currently no mod support for converting a highway + the 1-dimensional highway coordinate to a zone/sector position. I hope it's not the latter and I feel like there's just something trivial I'm missing...

User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13293
Joined: Sun, 15. Feb 04, 20:12
x4

Re: Get sector/zone position given highway coordinates

Post by euclid » Thu, 6. Jan 22, 00:44

I'm not sure what you are trying to do. If you intend to get a series of coordinates that defines the 3D curve of a highway then I'd use a script that writes your ship position at fixed time steps while you riding the highway. But then again I cannot figure out what you planning to do with these. If you'd disclose your goal then there might be a better way ;-)

Cheers Euclid
"In any special doctrine of nature there can be only as much proper science as there is mathematics therein.”
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786

redmessy
Posts: 5
Joined: Thu, 30. Dec 21, 04:50

Re: Get sector/zone position given highway coordinates

Post by redmessy » Thu, 6. Jan 22, 01:52

Thanks for your reply, let me try to explain with an example:

My ship is located somewhere north of the highway in sector Profit Center Alpha and I want to calculate the distance to the station "ARG Pharmaceutical Goods Factory II" in sector Silent Witness I (one gate away). To get the path my ship will need to travel, I use:

Code: Select all

<get_global_path component="$path_components" offset="$path_offsets" multiple="true">
	<start object="this.ship" />
	<end object="$station" />
</get_global_path>
To show you the results, I've used the following to dump them to a file:

Code: Select all

<do_all exact="$path_components.count" counter="$i">
	<debug_to_file name="this.ship.idcode" directory="'foobar'" text="'%s. Component ref: %s; Class: %s; Name: %s; Offset: %s'.[$i, $path_components.{$i}, $path_components.{$i}.class, $path_components.{$i}.knownname, $path_offsets.{$i}]" output="false" append="true" />
</do_all>
Here's the file contents:

Code: Select all

1. Component ref: 0x48f3c; Class: ship_m; Name: Trader; Offset: position.[0.000000m, 0.000000m, 0.000000m]
2. Component ref: 0x4918b; Class: highway; Name: Highway; Offset: position.[0.000000m, 0.000000m, 0.679121m]
3. Component ref: 0x4918b; Class: highway; Name: Highway; Offset: position.[0.000000m, 0.000000m, 0.899046m]
4. Component ref: 0x4918b; Class: highway; Name: Highway; Offset: position.[0.000000m, 0.000000m, 1.000000m]
5. Component ref: 0x479bc; Class: gate; Name: Jump Gate; Offset: position.[0.000000m, 0.000000m, 0.000000m]
6. Component ref: 0x112a6; Class: gate; Name: Jump Gate; Offset: position.[0.000000m, 0.000000m, 0.000000m]
7. Component ref: 0x11950; Class: highway; Name: Highway; Offset: position.[0.000000m, 0.000000m, 0.000000m]
8. Component ref: 0x11950; Class: highway; Name: Highway; Offset: position.[0.000000m, 0.000000m, 0.228337m]
9. Component ref: 0x116f7; Class: zone; Name: Empty Space; Offset: position.[-6810.109375m, -25.066999m, -11406.456055m]
10. Component ref: 0x1166b; Class: station; Name: ARG Pharmaceutical Goods Factory II; Offset: position.[0.000000m, 0.000000m, 0.000000m]
Going through these, in order:
  1. We start at my ship, zero offset in the ship position space
  2. We enter the highway at (presumably) the closest point to the ship, which is at highway coordinate 0.679121m (0.0 being start of highway and 1.0 being end of highway)
  3. We've moved to highway coordinate 0.899046m
  4. We've moved to highway coordinate 1.000000m, i.e. we're at the end of the highway
  5. We enter the gate in Profit Center Alpha to Silent Witness I, zero offset in the gate position space
  6. We exit the gate in Silent Witness I from Profit Center Alpha, zero offset in the gate position space
  7. We enter the highway at its start (highway coordinate 0.000000m)
  8. We exit the highway at highway coordinate 0.228337m
  9. We travel to some offset in a zone position space, presumably near the station
  10. Path ends at the station, zero offset in the station position space
Notice that in e.g. (2), (3) and (4), the component reference is the same, i.e. we have 3 references to the same (highway) component and the only thing that tells us where we are on the highway is the offset.

Now, let's say I want to start by finding the distance from my ship to highway coordinate 0.679121m in (2):

My initial idea was to use something like:

Code: Select all

<create_position object="$highway_component" value="$highway_offset" space="$highway_sector" name="$pos" />
To create a position in the same sector as my ship and then use:

Code: Select all

this.ship.distanceto.{$pos}
But that doesn't work. <create_position> assumes $highway_offset is in Euclidean space and doesn't seem to understand the normalization of highway coordinates.

Second idea was that maybe:

Code: Select all

this.ship.distanceto.[$highway_component, $highway_offset]
Might understand highway coordinates but varying $highway_offset between 0 and 1 does little to change the result, i.e. it seems to interpret $highway_offset the same as <create_position>.

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: Get sector/zone position given highway coordinates

Post by kuertee » Thu, 6. Jan 22, 04:53

there was a comment in one of egosoft's MDs which described converting the position value of an object from sector to zone, or from zone to another zone or from zone to sector - i can't remember.
but basically to convert the pos of one object to be relative to the pos of another object.
and i can't remember which MD file it was in, but i did use that conversion in several of my mods.

to get the pos of, in this example, a signal leak in a module in a station that is relative to the player's ship, i use create_position with the signal leak as the object reference but with the player's zone as the space reference.

Code: Select all

<create_position name="$signalLeakPos" object="$SignalLeak" space="player.zone" />
then i use get distance from the player's ship:

Code: Select all

player.ship.distanceto.{$isgnalLeakPos}
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

redmessy
Posts: 5
Joined: Thu, 30. Dec 21, 04:50

Re: Get sector/zone position given highway coordinates

Post by redmessy » Thu, 6. Jan 22, 05:33

kuertee wrote:
Thu, 6. Jan 22, 04:53
... i use create_position with the signal leak as the object reference but with the player's zone as the space reference.

Code: Select all

<create_position name="$signalLeakPos" object="$SignalLeak" space="player.zone" />
then i use get distance from the player's ship:

Code: Select all

player.ship.distanceto.{$isgnalLeakPos}
This is what I tried first with:
object = highway component
space = highway sector
value = highway offset (x = y = 0, z in [0,1])

But <create_position> interprets 'value' above like it's a regular offset from the object, i.e. it literally adds between 0 and 1 meters to the z coordinate of the highway start position (highway.position) and then creates this position in the sector space.

There doesn't seem to be a way I can signal to <create_position> that the offset I'm passing it in 'value' is a highway coordinate, which is special, and it needs to do a spline calculation to figure out where that offset will take you along the highway spline tube.

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: Get sector/zone position given highway coordinates

Post by kuertee » Thu, 6. Jan 22, 05:53

Ahhh

Ok, I seem to remember seeing a property or command to get nearest highway segment.

I’m not on the computer anymore, so can’t look it up immediately.

Check scriptproperties.xml or common.xsd
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

redmessy
Posts: 5
Joined: Thu, 30. Dec 21, 04:50

Re: Get sector/zone position given highway coordinates

Post by redmessy » Thu, 6. Jan 22, 06:17

kuertee wrote:
Thu, 6. Jan 22, 05:53
Ok, I seem to remember seeing a property or command to get nearest highway segment.
<get_closest_highway_offset> exists but it's the inverse of the function I need, i.e. I need to get a position from a highway offset and not a highway offset from a position.

I could create a series of sector positions along every highway in the game, use <get_closest_highway_offset> to get the highway offset for each and then do something like linear interpolation to produce a function that returns a sector position from any highway offset. This would be equivalent to looking up the highway knots in 'maps/xu_ep2_universe/zonehighways.xml' and precomputing splines for them myself that I could then include in my mod.

I haven't gone down that route yet because it seemed odd to me that e.g. <get_global_path> and script property 'highway.closestpointtoplayer' would return these special highway coordinates without any API to convert them to zone/sector positions - I thought I must be missing something.

Post Reply

Return to “X4: Foundations - Scripts and Modding”