Building X2 Sector maps

The place to discuss scripting and game modifications for X²: The Threat.

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

Post Reply
Cursed Ghost
Posts: 637
Joined: Sat, 2. Oct 04, 22:44
x3tc

Building X2 Sector maps

Post by Cursed Ghost » Mon, 25. Apr 22, 04:29

Hi all

So I’m not really sure if this is the right place for this since this isn't about modding the game exactly but here goes.

for a while now I have been working on building an X Universe Codex currently I’m working on building the sector maps for X2 in order to do that I need to figure out how to convert the unit sizes listed in the x2_universe.xml file to pixels unfortunately math never was my strong suite and I’m kinda stuck and could use a little help.

So if my map for Kingdom End is 513px wide and 513px tall how do I find the scale factor so I know what top and left values I need to specify in order to position each of the station icons correctly?

Now I could just use the same low tech method I did for X - Beyond the Frontier and X-Tension to figure this out and just screen shot each sector and then overly the icons over the screen shot but that’s really slow and time consuming, and I was hoping there might be a faster and more accurate way to go about this by taking the X,Y,Z values from the x2_universe.xml file and then just converting said values to pixels.

User avatar
Zeron-mk7
Posts: 571
Joined: Sat, 23. Feb 08, 12:38
x3

Re: Building X2 Sector maps

Post by Zeron-mk7 » Tue, 26. Apr 22, 15:39

I know a lot about X2 modding, but unfortunately such specific things, I don't known :( .
I don't know, maybe you can try to look on these X2 galaxy editors/generators Projects: Galaxy Editor, XUniverseWizard - Random universe generator, X2 Editor, maybe some things from these will help you.
Image

Cursed Ghost
Posts: 637
Joined: Sat, 2. Oct 04, 22:44
x3tc

Re: Building X2 Sector maps

Post by Cursed Ghost » Tue, 26. Apr 22, 19:04

Perhaps a little more info as to what I’m trying to do might help ok so as I mentioned I’m working on building the sector maps for X2 and as you can see in these screen shots

https://i.postimg.cc/fyPhMgg6/untitled.png
https://i.postimg.cc/zBXmK1ss/untitled1.png

I’m overlaying the station icons on top of a screen shot of the sector in this case Argon Prime which helps me get everything in the right position.

Trouble is this is really slow and time consuming and I was hoping to be able to take the coordinate data in the x2_universe.xml and then convert that from units to pixels but this is where I’m stuck because I’m unsure how to figure out how many units go into 1 pixel.

Now if I had to hazard a guess as to how to do this is say I’d need to know how many units wide and how many units tall the sector map is then divide that by the size of my map in this case 513px and that should tell me how many units go into 1 pixel trouble is I don’t actually know how big the sector map is it looks to be about 100km wide and 100km tall or at least the visible area is any way since each of the gates are at about 45km from the centre

User avatar
Zeron-mk7
Posts: 571
Joined: Sat, 23. Feb 08, 12:38
x3

Re: Building X2 Sector maps

Post by Zeron-mk7 » Wed, 27. Apr 22, 16:43

I understand, what you want to make, but I'm not sure, how to defined/calculate object location into the game sector map to the image pixel measure value. Maybe this will somehow help you: :gruebel:
If you open galaxy map with X2 Editor, If I understand correctly, then 5 KM are square size - distance into the game and that's 1110000 value into the map xml file, Example screenshot.
<?xml version="1.0"?>
<universe xmlns="XUNIVERS.xsd" id="2">
<o id="0" t="1" x="1" y="3" r="1" color="4488127">
<o t="2" s="29"/>
<o id="0" t="18" x="-10080000" y="0" z="0" s="2" r="1" gid="2" gx="0" gy="3" gtid="3" a="16384" b="0" g="0"/>
<o id="0" t="18" x="0" y="0" z="-10080000" s="1" r="1" gid="1" gx="1" gy="4" gtid="0" a="32768" b="0" g="0"/>
<o id="0" t="18" x="0" y="0" z="10080000" s="0" r="1" gid="0" gx="1" gy="2" gtid="1" a="0" b="0" g="0"/>
<o id="0" t="18" x="10080000" y="0" z="0" s="3" r="1" gid="3" gx="2" gy="3" gtid="2" a="-16384" b="0" g="0"/>
<o s="0" t="5" r="1" x="1110000" y="0" z="0" a="0" b="0" g="0"><o t="23" s="8"/><o t="23" s="5"/></o></o>
</universe>
Image

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22201
Joined: Sun, 14. Nov 04, 23:26
x4

Re: Building X2 Sector maps

Post by Cycrow » Wed, 27. Apr 22, 18:38

You could normalise the coordinates to between 0 and 1 by picking a fixed sector size to use

with the normalised coordinates, then you just multiply them by the width and height of the image you wish to create.

the coordinates defined in the map file are the internal values, which represent 1/500th of a metre

Code: Select all

x = (((x / 500) / sectorWidth) + 1) / 2
y = (((y / 500) / sectorHeight) + 1) / 2

pixelx = x * imageWidth
pixely = y * imageHeight

Cursed Ghost
Posts: 637
Joined: Sat, 2. Oct 04, 22:44
x3tc

Re: Building X2 Sector maps

Post by Cursed Ghost » Thu, 5. May 22, 23:51

Cycrow wrote:
Wed, 27. Apr 22, 18:38
You could normalise the coordinates to between 0 and 1 by picking a fixed sector size to use

with the normalised coordinates, then you just multiply them by the width and height of the image you wish to create.

the coordinates defined in the map file are the internal values, which represent 1/500th of a metre

Code: Select all

x = (((x / 500) / sectorWidth) + 1) / 2
y = (((y / 500) / sectorHeight) + 1) / 2

pixelx = x * imageWidth
pixely = y * imageHeight
that's a nice idea but something seems to be off, based on what you posted I wiped up a quick and dirty script for testing

Code: Select all

var x = -1603560;
var z = -1195320;

x = (((x / 500) / 100000) + 1) / 2;
z = (((z / 500) / 100000) + 1) / 2;

var pixelx = x * 513;
var pixelz = z * 513;

var img = document.getElementById('trading_station');

img.style.left = pixelx+'px';
img.style.top = pixelz+'px';
only when I tried running it the trading station icon wasn't placed where it should be as you can see in this screen shot

https://i.postimg.cc/CKZCqbTc/untitled.png

the sector width/height of around 100km or 100,000 meters seems to be about right as each of the gates seem to be placed at around 45km from the centre and the width and height of my sector map is 513px so I'm not sure what part of this is wrong but something isn't working right.

could the discrepancy be caused by the fact that I enlarged the screen shot from 411px to 513px ? or could it be that the above doesn't account for the width and the height of the station icon which is 20px wide and 22px tall or perhaps both

Cursed Ghost
Posts: 637
Joined: Sat, 2. Oct 04, 22:44
x3tc

Re: Building X2 Sector maps

Post by Cursed Ghost » Thu, 12. May 22, 21:58

Ok so now that I've had a little time to work on it here is a more complete version of the script.

Code: Select all

var icons = 
{
  shipyard:                       {x: -609840,   y: 1879080,  z: -1617000},
  wharf:                          {x: 3552000,   y: 333000,   z: 4151400},
  equipment_dock:                 {x: 722400,    y: -1187760, z: 1300320},
  trading_station:                {x: -1603560,  y: 506520,   z: -1195320},
  solar_power_plant_alpha:        {x: -7022400,  y: 435960,   z: -1504440},
  solar_power_plant_beta:         {x: 2009280,   y: -1346520, z: 2655240},
  rimes_fact_alpha:               {x: -5394600,  y: -1110000, z: -3529800},
  cattle_ranch_alpha:             {x: -2348640,  y: 1706040,  z: 1743000},
  cahoona_bakery_alpha:           {x: -3662400,  y: 2055480,  z: 1601040},
  shield_production_facility_1mw: {x: -655200,   y: -926520,  z: -3623760},
  mass_driver_forge:              {x: 5328000,   y: -88800,   z: 1931400},
  ammo_factory:                   {x: 3108000,   y: 88800,    z: -1776000},
  north_gate:                     {x: 0,         y: 0,        z: 10080000},
  east_gate:                      {x: 10080000,  y: 0,        z: 0},
  south_gate:                     {x: 0,         y: 0,        z: -10080000},
  west_gate:                      {x: -10080000, y: 0,        z: 0},
};

for (var key in icons)
{
  //get coordinates and convert to pixels
  x = (((icons[key]['x'] / 500) / 100000) + 1) / 2 * 513;
  z = (((icons[key]['z'] / 500) / 100000) + 1) / 2 * 513;

  //get icon
  var icon = document.getElementById(key);

  //position icons
  icon.style.left = x + 'px';
  icon.style.top = z + 'px';
}
While this works and positions all the icons as expected something is way off in the way that the games internal coordinates are being converted to pixels, as you can see in this screen shot

https://i.postimg.cc/1RrkWfxS/untitled.png

So some how I don’t think

Code: Select all

x = (((x / 500) / sectorWidth) + 1) / 2 * imageHeight
y = (((y / 500) / sectorHeight) + 1) / 2 * imageWidth
is the correct way to convert the games internal coordinates to pixels, unless I've misunderstood and done something wrong that is, something else I noticed is that the north and south gates are flipped around the north is at the bottom instead of the top and the south is at the top instead of the bottom, and its not just the north and south gate that are flipped all the north south coordinates are flipped.

also are you sure the coordinates defined in the map file represent 1/500th of a metre because I was reading here viewtopic.php?t=34432

and apparently to convert the games internal values to meters you divide by 222 not 500 to take the example from the linked post.

you convert units to meters like so
10080000 / 222 = 45405.405405405405405405405405405

then to convert to meters to km you do
45405.405405405405405405405405405 / 1000 = 45.405405405405405405405405405405 rounded up that's 45.4 km which is what I see when I check the coordinates in game.
Last edited by Cursed Ghost on Fri, 13. May 22, 00:39, edited 2 times in total.

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22201
Joined: Sun, 14. Nov 04, 23:26
x4

Re: Building X2 Sector maps

Post by Cycrow » Thu, 12. May 22, 23:08

I'm not actually sure for x2, but is for x3.
It's possible x2 used a different value

Cursed Ghost
Posts: 637
Joined: Sat, 2. Oct 04, 22:44
x3tc

Re: Building X2 Sector maps

Post by Cursed Ghost » Fri, 13. May 22, 00:43

Code: Select all

var x = (((icons[key]['x'] / 222) / 50000) + 1) / 2 * 513 - 10;
var z = (((icons[key]['z'] / 222) / 50000) + 1) / 2 * 513 - 11;
gets pretty close as you can see in this screen shot

https://i.postimg.cc/vmczn895/untitled.png

though I'm not sure how to flip the north south values around because as you can see the north south values are the wrong way round.

https://i.postimg.cc/pdfdqzDv/untitled.png

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22201
Joined: Sun, 14. Nov 04, 23:26
x4

Re: Building X2 Sector maps

Post by Cycrow » Fri, 13. May 22, 11:32

To flip the Z axis you can just negate it

Code: Select all

var z = (((-icons[key]['z'] / 222) / 50000) + 1) / 2 * 513 - 11;

Cursed Ghost
Posts: 637
Joined: Sat, 2. Oct 04, 22:44
x3tc

Re: Building X2 Sector maps

Post by Cursed Ghost » Sat, 20. Aug 22, 17:09

Thanks inverting the z axis seems to of done the trick though for some reason things are still little off.

for example

Code: Select all

//get coordinates and convert to pixels
var x = (((icons[key]['x'] / 222) / 51000) + 1) / 2 * 513;
var z = (((-icons[key]['z'] / 222) / 51000) + 1) / 2 * 513;

//positions icons
var top_position = Math.trunc(z) + 'px';
var left_position = Math.trunc(x) + 'px';
results in

https://i.postimg.cc/BZPqSPfm/untitled.png

now I was able to improve that by doing

Code: Select all

//get coordinates and convert to pixels
var x = (((icons[key]['x'] / 222) / 51000) + 1) / 2 * 513;
var z = (((-icons[key]['z'] / 222) / 51000) + 1) / 2 * 513;

//positions icons
var top_position = Math.trunc(z) + 16 + 'px';
var left_position = Math.trunc(x) - 7 + 'px';
which results in

https://i.postimg.cc/QMn3sh4L/untitled1.png

though despite my best attempts to eliminate the error I've been unable to do so because tweaking the above fixes the error for some but throws others out so I'm wondering if you might know of a way to eliminate this irritating error completely.

obviously there will be some small amount of variance due to pixellation but what I'm seeing is not down to pixellation it's down to the above formula getting the final answer wrong for some of the icons.

for example

the X axis of the shipyard icon is off by +2px
the Y axis of the equipment dock icon is off by +2px
both the X and Y axis of the 1MW Shield Production Facility icon are off by +1px
both the X and Y axis of the Mass Driver Forge icon are off by -1px and +2px respectively.

so as you can see eliminating the error is proving to be tricky.

Post Reply

Return to “X²: The Threat - Scripts and Modding”