Manually Editing the Galaxy Using a Text Editor

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

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

AalaarDB
Posts: 2279
Joined: Thu, 29. Jan 04, 09:19
x3tc

Manually Editing the Galaxy Using a Text Editor

Post by AalaarDB » Sat, 13. Mar 04, 22:27

If you unpack x2_universe.xml and open it up in a text editor you get something like the below:
At first glance it looks daunting to try to create your own galaxy (after all it's 62000 lines in length)
but once you understand it's actually quite easy. This document is meant to supplement Egosoft's
modding tutorial, as I know alot of you may understand the concept, but the numbers are difficult.
Understanding:

This excerpt shows parts of the sector Kingdoms End

Code: Select all

<universe xmlns="XUNIVERS.xsd" id="2">
	<o id="0" t="1" x="0" y="0" r="2" color="2313738" fc="0" fn="0" ff="0">
		<o t="2" s="0"/>
		<o id="0" t="18" x="0" y="0" z="-10080000" s="1" r="2" gid="1" gx="0" gy="1" gtid="0" a="32768" b="0" g="0"/>
		<o id="0" t="18" x="10080000" y="0" z="0" s="3" r="2" gid="3" gx="1" gy="0" gtid="2" a="49152" b="0" g="0"/>
		<o t="3" s="5" x="178145224" y="25597057" z="122769889" color="8570965"/>
		<o t="4" x="160609000" y="263775829" z="-297674095" s="5" r="2"/>
		<o id="0" t="17" x="2483880" y="346920" z="-2745120" s="2" atype="0" aamount="2" a="20503" b="10643" g="61392"/>
		<o id="0" t="21" x="7992000" y="1554000" z="3774000" s="112" a="0" b="0" g="0"/>
		<o id="0" t="6" x="835800" y="-351120" z="3971520" s="42" r="2" a="32768" b="0" g="0">
			<o t="23" s="6">
				<o t="11" s="0"/>
				<o t="15" s="0"/>
				<o t="14" s="4"/>
			</o>
			<o t="23" s="7">
				<o t="9" s="0"/>
			</o>
			<o t="23" s="8">
				<o t="16" s="2"/>
			</o>
			<o t="23" s="5">
				<o id="0" t="7" s="35" r="2">
				</o>
			</o>
		</o>
		<o id="0" t="7" x="2280600" y="-1377600" z="4182360" s="89" r="2">
		</o>
	</o>
Lets take a look at the second line

Code: Select all

	<o id="0" t="1" x="0" y="0" r="2" color="2313738" fc="0" fn="0" ff="0">
This tells us the starting info for the Upper Leftmost (first) sector in the galaxy - Kingdom End
You may recall from scripting that when you get sector from index x=1 y=1 you get Kingdom End
That is not so here, in fact all sectors are x-1 y-1. You need to be aware of the numbering convention,
as it will change from script editor to galaxy editor to text file.
What does id="0" mean? I don't know, everything has it therefore I can't interperet it. However, after looking at some older maps I assume that this is some text flag similar to what is now n="****"
T="1" Type = sector
X and Y are coordinates explained above.
r = race, in this case Boron. The numbers do not proceed alphabetically, they follow the same order that is in the
script editor. Until you have memorized them, check the script editor, or look at a sector you already know.
c = background color, different from the sun color, in Red Green Blue format.
fc, fn, ff color of fog, near fog, far fog color is expressed in rgb format and near/far is in units - submitted by Storm_Front
kryptyk wrote:Well in the XML file I figured out the color number. This works for sun color and sector color.

All Blue = 255 (R=0 G=0 B=255)
All Green = 65280 (R=0 G=255 B=0)
All Red = 16711680 (R=255 G=0 B=0)
White = 16777215 (R=255 G=255 B=255)

I tried to find out how the game was getting the numbers so I did a little calculating and found that 255(all blue) + 65280(all green) + 16711680(all red) = 16777215(all white)

Apparently just using all green and no blue gives the blue value a 256 instead of zero which means 255(all green) * 256(no blue) = 65280
All variables always mean the same thing, ie s=subtype, even if we are talking about sectors or ship,
so usually I won't repeat them,. I will however explain the number of the subtype if necessary.
From the sector line down, everything has been indented 1 tab, that means everything below belongs to this sector.

Code: Select all

		<o t="2" s="0"/>
This is the background graphics for the sector. If you want to create your own you need to find a number that isn't used.
Otherwise, reuse a number and it'll be fine. If you want a funny sector try number 115, it stops at 114.

Code: Select all

		<o id="0" t="18" x="0" y="0" z="-10080000" s="1" r="2" gid="1" gx="0" gy="1" gtid="0" a="32768" b="0" g="0"/>
		<o id="0" t="18" x="10080000" y="0" z="0" s="3" r="2" gid="3" gx="1" gy="0" gtid="2" a="49152" b="0" g="0"/>
These are 2 gates, so t=18 = gate. The top line is the south gate, you can tell by the coordinates. But there are
other things that tell you it's south.
s=subtype, which is 1, mean it is south, it's 0,1,2,3 for North,South,West,East respectively.
X Y and Z are the coordinates, in most sectors it will be approx 10080000, as that is 45.4 km *222
All coordinates are expressed in "units" 222 units make 1 meter. Thus 1km = 222000
gid= grid ID this is the same as subtype, it will be used to let other gates know what to connect to.
gx and gy = sector to which this gate connects to. x1y0 is of course Rolt's Drift.
gtid= grid target ID this is the gate, in the target sector, to connect to. Thus gtid references gid in sector gx gy.
If you want the East gate in KE to connect to West in RD, you would have the bottom line, if you want East KE to connect to
South RD you would change the GtargetID to number 1, or south and keep the rest.
a, b,g = This is which way the gate faces. Mostly you will only need 4 numbers, 0, 16384, 32768, and 49152 for gates

Code: Select all

		<o t="3" s="5" x="178145224" y="25597057" z="122769889" color="8570965"/>
		<o t="4" x="160609000" y="263775829" z="-297674095" s="5" r="2"/>
Top line Sun, bottom line Planet
color = red green blue
I usually just find a random sector and copy that sector's planet(s) and sun(s) when creating a new sector
because it's hard to convert 8570965 into a red green blue format for me, but subytpe is easily changed.

Code: Select all

		<o id="0" t="17" x="2483880" y="346920" z="-2745120" s="2" atype="0" aamount="2" a="20503" b="10643" g="61392"/>
t17 = Asteroid Subtype is what shape it is. Atype is which type of resource it has, 0 being ore, 1 being silicon, 2 nividium.
Aamount is the yield.

Code: Select all

		<o id="0" t="21" x="7992000" y="1554000" z="3774000" s="112" a="0" b="0" g="0"/>
A nebula, subtype is what it looks like. abg are always 0 because nebulas are always facing the player.

Code: Select all

		<o id="0" t="6" x="835800" y="-351120" z="3971520" s="42" r="2" a="32768" b="0" g="0">
Our first station, t = station. subtype 42= shield facility 1mw (boron). Most stations will have lines beneath them that
are indented an extra 1 or 2 lines. Those indentations means those lines belong to the station.

Code: Select all

			<o t="23" s="6">
For instance, here is where we add resources to the station. S6 = add resource

Code: Select all

				<o t="11" s="0"/>
				<o t="15" s="0"/>
				<o t="14" s="4"/>
			</o>
Because they are indented they belong under the add resource category.
You may recall that ware main11 sub0 is energy, well, at least I recall!
and </o> closes the indentation so that the next lines are also in the station, but not interpreted as resources.
14 4 is ore and 15 0 is bofu I think

Code: Select all

			<o t="23" s="7">
				<o t="9" s="0"/>
 			</o>
This adds the product 1MW shields.

Code: Select all

			<o t="23" s="8">
				<o t="16" s="2"/>
			</o>
This adds the secondary resource: Quantum Tubes

Code: Select all

			<o t="23" s="5">
				<o id="0" t="7" s="35" r="2">
				</o>
			</o>
		</o>
All that's left is to add the factorie's ships so that it can trade.
t7=ship, subtype=Boron Octopus
Notice that there is no x y z position, that's because it's docked. So t23 s5 = docked ships.
Notice that there are 3 </o>s the first closed the ship, nothing extra was installed. The second
closed the docked ships, there are no more docked ships at this station. The last closed the station,
there is nothing more to the station.

Code: Select all

		<o id="0" t="7" x="2280600" y="-1377600" z="4182360" s="89" r="2">
		</o>
This is a ship that is in space, it is not connected to any station, and has nothing extra installed. It's a Boron Barracuda
The game will install default items on its own upon loading. Do not add items unless you need them extra.

Code: Select all

	</o>
	<o id="0" t="1" x="1" y="0" r="2" color="10183690" fc="0" fn="0" ff="0">
This closes the sector, there is nothing left to the sector. The next sector can now start, immediately under the </o>

If this is the last sector you would also close the universe with

Code: Select all

</universe>
You are done with the basic understanding section of this tutorial. There is alot more to learn, but
you can make hundreds of sectors now if you so wished.


Creating neat stuff:
OK so you have the basics for a simple sector. But you want text!
In file 440001.xml there's a ton of text you can use.
For instance, want to make ship debris? NP First create your ship like normal.
Then, make the ship race 14, so it won't go anywhere. Next, right after race, add the text n="5561"
This will reference T ID 5561 in 440001, which happens to be ship debris.
Station debris? 5571 Debris? 5551
Broken Gate is different, do not add a n="****" instead, change the subtype to 4, and make sure it leads nowhere
like make the gtarget ID gx="-1" gy="-1"

You can make custom text. Let's say you want a personalized ship to be named "Suzy's Ship"
Find a blank spot in 440001.xml that has 2 spots back to back. Here is where you need new files.
You cannot edit 440001 yourself, but you can make a second file and call it 449999 or whatever.
*edit* you might be able to edit the 440001. I had trouble with this and it may have been user error. However, it would still be a good idea to create your own file since uploading/hosting/downloading a whole 440001 would be alot more work.

Before we get to that, lets go over how we are to integrate 449999 into the game once we have put text
into it because it's the simple part. Go into your in game script editor and create a new script. You want
it to load automatically so call it "init.your_script_here" Add a new line, go to general commands,
and press page down twice. About in the middle of the page is a line called load text: id=<var/number>
Select this, and as id enter number **** where **** is your 44**** that isn't used yet. Save and exit.

Next put text into the 449999 file, but you can't put it anywhere. Notice that file 440001 is formatted
in a special way, it's got pages and IDs etc.
If we want a ship named "Suzy's ship" and a description of that ship as "This is Suzy's ship" we would
do the following:

Code: Select all

<language id="44">
	<page id="17" title="Boardcomp. objects" descr="Quad line groups for ware factory pairs or twins (spoken by Boardcomputer)"> 
		<t id="3333">Suzy's ship</t> 
		<t id="3334">This is Suzy's Ship.</t> 
	</page>
</language>
3333 is different from your 9999, select a number that isn't used in 440001 (and isn't used in any of my mods!!!)
instead of entering n="5561" on your ship, now you would enter n="3333" Do not enter 3334 as this is the description you see by default when you look at ship info.
You can do this for ships, stations, wares, anything

OK, now you want to name your sector and add a description to it

Code: Select all

<language id="44">
	<page id="7" title="Boardcomp. Sectornames" descr="Names of all sectors (spoken by Boardcomputer)">
		<t id="1021505">My sector name</t>
	</page>
<page id="19" title="Sectordescription" descr="Long descriptions of all sectors">
		<t id="1031505">My sector description</t>
	</page>
</language>
The 102**** and 103**** are important. This number does not correspond to any text file or whatever.
Instead, it is your sector coordinates. But wait, I don't have a sector there! For example, Rolk's Drift
x1y0 in the x2_universe.xml would become 1020102. The x and y are switched, to YX and 1 is added to each number.
If you get your sector number from the in game galaxy map you do not need to add 1 to each,
since RD in game is x2 y1 already

OK, that's it for the text. Now you want more features for your Carrier

Code: Select all

		<o id="0" t="7" x="2212560" y="739200" z="-5658240" s="31" r="2">
			<o t="23" s="4">
				<o t="16" s="19" n="1"/>
			</o>
			<o t="23" s="5">
				<o id="0" t="7" s="35" r="2">
				</o>
			</o>
			<o t="23" s="9">
				<o id="0" t="7" x="1680" y="-1034040" z="0" s="35" r="2">
				</o>
			</o>
		</o>
This creates a carrier with docked ships (subtype5) and patroling ships too! (subtype 9)
The main16 sub19 installs N docking computers

*NEW EDITED*
I want to create an asteroid field, but making 50 asteroids is alot of work. Solution?

Code: Select all

		<o id="0" t="20" x="0" y="0" z="0" s="20" a="0" b="0" g="0"/>
Creates a mini asteroid field. They aren't targetable and have no resource/yield.

*NEW EDITED*
I'm making a racetrack, making gates are a bit big so I'd like to use Kessler rings. Solution?

Code: Select all

		<o id="0" t="20" x="0" y="0" z="0" s="0" a="0" b="0" g="0"/>
The above 2 are edited because I made a mistake. Sorry

If this doesn't work, try scripting in a special object-type number 0, in conjuction with Reven's X² Math library - fixed point decimal & trig functions

Debugging and tips:

My game crashes when I try to start my custom map.
Uh oh

My game hangs but doesn't crash when I try to start my custom map
It sounds like a script error instead of a map error, are you sure the map was the only thing you changed?

Come on help me, I wrote 10000 lines of text and it crashes when I try to start my custom map.
OK if it crashes there's an error someplace in your text. One time I made the following mistake:

Code: Select all

		<o id="0" t="7" x="-2436450" y="923964" z="-280386" s="28" r="4" n="5561>
Can you spot the error? My computer sure did. If you can't spot it here how can you spot it in 10000 lines of text?
So the moral is save often, make a backup before changing really big stuff, and alt tab to your game and try out your
map with the in game galaxy editor. You can alt tab back out and edit your text, even save your text while still playing the game,
but to load the new text after a save you must exit to the start menu and restart galaxy editor.
PS the error was n="5561> it should have been n="5561">
I can't think of any other reasons why it would crash on start up except for typing errors. If you have a syntax error
such as:

Code: Select all

		<o id="0" t="6" x="835800" y="-351120" z="3971520" s="42" r="2" a="32768" b="0" g="0">
			<o t="23" s="7">
 			</o>
				<o t="9" s="0"/>
		</o>
or:

Code: Select all

				<o id="0" t="7" s="90" r="2">
				</o>
				</o>
				<o id="0" t="7" s="30" r="2">
it simply won't load that section, eveything else will be fine.

My custom map will start, but as soon as I open up the galaxy map it crashes.
Sounds like you forgot

Code: Select all

		<o t="2" s="0"/>
if that's there, also look for sectors that aren't closed, make sure there's a </universe> tag
at the end of the script, so that the universe is closed too.

My custom map starts, galaxy map opens up, but my sector isn't there
If you go to your sector using arrow keys and it seems to "freeze" at one part of the map, that's your sector
I can't help you there, there is no graphic for your sector in your universe, you need to edit it with 3dmax

If you go to your sector, and it skips over it like it wasn't there at all then that's a problem, most likely
you didn't close the tag.

Everything works except the gates, they don't work or they make you backwards
Make sure your IDs are ok, then make sure your alpha is ok. Make sure the other sector has the
exit gate too.

I created sectors and ships with custom text, but when I start the game it says ReadText **** or doesn't show at all.
OK first, if it does not show at all, then there is a syntax error in your galaxy map, or you forgot the n="****" for ships and stations. For sectors, then you may have used the wrong id# for your text, remember that x and y are switched and add 1.
If it shows ReadText **** then you may have a syntax error in your text file, or you may have forgotten to include your init script that loads the text file.

*NEW*
I have a map with a whole bunch of sectors, but some don't show.
The limit to your map size is 20x, 15y. Remember since numbers start at 0 you have the numbers 0-19 for x and 0-14 for y. A grand total of 300 sectors :/
Last edited by AalaarDB on Thu, 18. Mar 04, 09:31, edited 14 times in total.

The_Rock
Posts: 2549
Joined: Wed, 6. Nov 02, 21:31
x2

Post by The_Rock » Sat, 13. Mar 04, 23:14

Good work dude.

I just hope someone can make a GUI for this like Stoned'd's exe editor for X-T.
"How very touching his meaningless death was. But this fight was never for mortals".

User avatar
Storm_Front
Posts: 751
Joined: Mon, 15. Dec 03, 06:27
x2

Post by Storm_Front » Sat, 13. Mar 04, 23:19

I just posted what the color, fc, fn and ff represent in the thread
http://www.egosoft.com/x2/forum/viewtopic.php?t=34156

*Edit* Ok, now I see it up there.

kryptyk
Posts: 392
Joined: Fri, 5. Dec 03, 21:19
x4

Post by kryptyk » Sun, 14. Mar 04, 00:46

That's useful info aalaadb :)

I was able to decode the color number in the XML file here http://www.egosoft.com/x2/forum/viewtopic.php?t=34156

Are you compiling a HowTo on manually editing the universe file by any chance?

AalaarDB
Posts: 2279
Joined: Thu, 29. Jan 04, 09:19
x3tc

Post by AalaarDB » Sun, 14. Mar 04, 01:36

The title is misleading, it is about manually editing the universe. I don't like the in game galaxy editor, sure it's great for looking, but you have to remember a whole bunch of keys, press the wrong one and you delete your object or have to cycle through. On the other hand I use the in game editor for scripting, that's great.

User avatar
esd
Posts: 11610
Joined: Tue, 2. Sep 03, 05:57
x3tc

Post by esd » Sun, 14. Mar 04, 01:59

Added to favourites! Good work dude! :D
esd's Guides: X² Loops - X³ MORTs

kryptyk
Posts: 392
Joined: Fri, 5. Dec 03, 21:19
x4

Post by kryptyk » Sun, 14. Mar 04, 08:22

aalaardb wrote:The title is misleading, it is about manually editing the universe. I don't like the in game galaxy editor, sure it's great for looking, but you have to remember a whole bunch of keys, press the wrong one and you delete your object or have to cycle through. On the other hand I use the in game editor for scripting, that's great.
Yeah but the scripting engine is more limited compared to the galaxy editor. The two editors perform 2 completely different functions but both of them used together are very powerful modification tools.
I started that thread to better understand the entries in the x2_universe file because some of the fields can't be edited by the galaxy editor (like sector light color) and some changes are easier. Hopefully soon somebody will create a tutorial on galaxy editing that will explain things and teach people how to use this powerful tool. If you understand the scripting engine better then by all means stick with it.....the community always needs good scripts to enhance X2. :wink:

AalaarDB
Posts: 2279
Joined: Thu, 29. Jan 04, 09:19
x3tc

Post by AalaarDB » Mon, 15. Mar 04, 21:12

maybe this should be stickied?

User avatar
Storm_Front
Posts: 751
Joined: Mon, 15. Dec 03, 06:27
x2

Post by Storm_Front » Mon, 15. Mar 04, 21:29

aalaardb wrote:maybe this should be stickied?
Adding it to my favorites will have to do for now. :)

kryptyk
Posts: 392
Joined: Fri, 5. Dec 03, 21:19
x4

Post by kryptyk » Tue, 16. Mar 04, 01:31

Yeah this explains a lot...and should be stickied IMO. :D

AalaarDB
Posts: 2279
Joined: Thu, 29. Jan 04, 09:19
x3tc

Post by AalaarDB » Wed, 17. Mar 04, 03:12

bump

User avatar
DeadlyDa
Posts: 1882
Joined: Mon, 5. Jan 04, 05:46
x4

Post by DeadlyDa » Sat, 20. Mar 04, 19:45

Many thanx for the info...it really helps. I'm having fun playing around with a couple of custom maps, but not being able to see my new sectors is a pain.

I saw a previous post somewhere that mentioned a 3dMax file that had to be modified. While I use 3dMax version 6, I still have my old V5 CD's around, and wouldn't mind having a play with the ingame map.

Do you (or anyone else), know what file I should look at? (I really don't want to wast my time unpacking every file in the game just to find he ingame map.)

Thanx again for all your work.

User avatar
Thalass
Posts: 841
Joined: Wed, 6. Nov 02, 21:31
x2

Post by Thalass » Sun, 21. Mar 04, 10:05

Hey aalaardb, this is good. :)


But I'm having some trouble with finding the files. I assume you have to unpack them using the mod pack file x2tool.exe, but that doesn't actually do anything, that I can detect.

So, uh, what do I do? Stupid question, perhaps. I reckon I've missed something somewhere, but I can't find anything to tell me how.
Legitimate Businessman. Honest.

AalaarDB
Posts: 2279
Joined: Thu, 29. Jan 04, 09:19
x3tc

Post by AalaarDB » Sun, 21. Mar 04, 10:20

I'm better aquainted with OlisJ's x2 modder thingy. It uses a gui and makes life simple, but if you can't find that then you're stuck with x2tool.exe. Open up a command prompt (ie go to dos, or Start Menu - Run - type cmd and hit enter) Navigate to where you installed x2tool.exe. type x2tool.exe -extract-dat 01

You now have a folder called 01. navigate to that folder and go to maps. type x2tool.exe -unpack x2_universe.pck x2_universe.xml.

I'm assuming you know how to / what I mean by navigate in a command prompt. If not, here's how:

At windows, click start menu
click run
type *cmd* without the * and press enter
type cd c:\ and press enter
type cd egosoft (or whatever, mine is different)
type cd x2 - the threat
and you're there!

In summary, I recommend using x2 modder by olisj, don't have a link atm, check commander jamiesons site, he has links.

PS thanks for the bump :wink:

User avatar
Thalass
Posts: 841
Joined: Wed, 6. Nov 02, 21:31
x2

Post by Thalass » Sun, 21. Mar 04, 10:30

ah! Through the command prompt! *facepalms* never thought of that. No matter how many times I double clicked on x2tool.exe it just flashed up and then closed. :lol:


Thanks mate. :) You're a lifesaver.
Legitimate Businessman. Honest.

Post Reply

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