The Ur-Quan Masters Home Page Welcome, Guest. Please login or register.
Did you miss your activation email?
November 27, 2022, 04:12:52 pm
Home Help Search Login Register
News: Celebrating 30 years of Star Control 2 - The Ur-Quan Masters

+  The Ur-Quan Masters Discussion Forum
|-+  The Ur-Quan Masters Re-Release
| |-+  Technical Issues (Moderator: Death 999)
| | |-+  Poking the Source Part 1: Add a new starsystem
« previous next »
Pages: [1] Print
Author Topic: Poking the Source Part 1: Add a new starsystem  (Read 2437 times)
richardk
Zebranky food
*
Offline Offline

Gender: Male
Posts: 11


SC2 = great!


View Profile
Poking the Source Part 1: Add a new starsystem
« on: April 26, 2004, 10:46:00 pm »

I've been sifting through the source code, trying to figure out what would be involved in adding certain game content.  For step 1, I wanted to add a new star system.  (In step 2 next post, we’ll put a Melnorme trader in it.)  Here's how I accomplished it, for those interested.

PREAMBLE

Yes, I know this is off on a tangent from the goal for v1.0 of recreating the original game.  But it’s interesting and neat, and I’m also curious if there’s been any consideration of how to handle “content-addons”.  But before I start:

Big Question:  Does anyone have any documentation available on the mechanics of the game code? (aside from the file descriptions in Devel\Files)

I think everyone agrees we can all benefit from generating more documentation on the SC2 guts, and I don’t want to be repeating other people’s work ;-).

A word of warning here for newbies:  The sc2 source code is a tightly-knight package and poking it can be dangerous, especially if you don’t know what you’re doing.  What I’m describing in this post is a fair bit of poking, and I don’t claim to “know what I’m doing”.

HERE WE GO

Alright, time to get our hands dirty.  STAR_DESC starmap_array[] in plandata.c contains star data, including two useful fields:  postfix name and alien presence.  The latter is taken from encount.h.  The former is the index of a record in LBM\starcon.txt.  Each line starting with a "#'"and the following line(s) until the next # make up a record.  Here's a simple formula:  Line number = record index / 4 – 1.

Question for gurus: There are two starcon.txt files.  Which one is actually used (or are both?).  From my brief testing, I only noticed changes in the \LBM to have effect.  Is this correct, or is there more to it?

So, to begin I inserted a line in the starmap_array[] definition in order to create a new white star at 200:200, near Rigel:

{{2000, 2000}, MAKE_STAR (DWARF_STAR, WHITE_BODY, -1), 0, 0, 132},

Note that the list is (and must be) sorted by y-coordinate. The final number is the index of the name for the star.  Since it is a byte, it can’t be > 255, so unfortunately you can’t simply insert a new string at the end of the starcon.txt file.  Instead, one puts the new record after the last existing star name in starcon.txt (which is probably better practice anyway).  So starting at line 525, my file looks like this:

#(Lentilis)
Lentilis


#(RKVille)
RKVille


#(UNKNOWN)
UNKNOWN


Note RKVille is record index 132.  Technically, UNKNOWN counts as a star “name”, but I think it is there for safety in case a star isn’t found.  Since we inserted rather than appended a record, you have to add 1 to each of the constants DEVICE_STRING_BASE through OPTION_STRING_BASE in globdata.h.

Also incremented the NUM_SOLAR_SYSTEMS constant in encount.h.

Okay, load up the game and voila, a fine new star system complete with planets and minerals vaguely corresponding to its size and color.  Neat!

From what I can tell, the planets, life, minerals, etc. for the system are created using a sequence of random numbers generated from a seed that is the X and Y location of the star.  This takes place in LoadSolarSys() (in solarsys.c) and DoPlanetaryAnalysis() (calc.c).

I made this post to 1) document what I’ve unraveled so far, and 2) avoid re-doing work someone else may have done.  I appreciate any feedback or comments from the gurus.  My real goal is to add a "lone ranger" character who hangs out in a far-off star system, kinda like a Melnorme trader.  Any tips from the pros on adding custom dialog, graphics, etc. are appreciated!

Keep an eye out for the next post, when we’ll add a Melnorme to the system.
« Last Edit: April 26, 2004, 10:47:04 pm by richardk » Logged
meep-eep
Forum Admin
Enlightened
*****
Offline Offline

Posts: 2847



View Profile
Re: Poking the Source Part 1: Add a new starsystem
« Reply #1 on: April 27, 2004, 06:59:16 am »

A couple of short remarks before I go to bed (I may have more to say tomorrow):
- /starcon.txt is indeed unused. I've added a remark to bug #275 for now.
- "UNKNOWN" is the name for the naturally occuring Quasispace portal. I haven't checked the code, but you may need to change another constant, or maybe NUM_SOLAR_SYSTEMS was enough.
- You may want to join us in #sc2 on irc.openprojects.net.
Logged

“When Juffo-Wup is complete
when at last there is no Void, no Non
when the Creators return
then we can finally rest.”
richardk
Zebranky food
*
Offline Offline

Gender: Male
Posts: 11


SC2 = great!


View Profile
Re: Poking the Source Part 1: Add a new starsystem
« Reply #2 on: April 27, 2004, 12:03:43 pm »

Thanks for the response!  Couldn't resolve irc.openprojects.net (problem w/ my DNS server??), but I managed to get into the #sc2 channel on Freenode.  Unfortunately, I think everyone was asleep (~3am EST).

Cheers!
« Last Edit: April 27, 2004, 12:54:47 pm by richardk » Logged
meep-eep
Forum Admin
Enlightened
*****
Offline Offline

Posts: 2847



View Profile
Re: Poking the Source Part 1: Add a new starsystem
« Reply #3 on: April 28, 2004, 02:42:32 am »

irc.freenode.org is indeed the current name of the irc server.

Everything we have on code documentation is in docs/devel, and some comments in the code itself.
Some docs on the virtual file system 'uio' are in src/sc2code/libs/uio/docs.

As for content add-ons. At the moment you can have add-on packages which override files in the main source package.
For the files themselves we're still using the original resource system. That means we've got index files that describe where to find certain resources. We don't have any easy way to add new resources to those files, but there are tools in the 'tools' modules in cvs that can be used to read from them.
In the future we intend to move to a new XML based resource system.

Logged

“When Juffo-Wup is complete
when at last there is no Void, no Non
when the Creators return
then we can finally rest.”
Pages: [1] Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!