Structure Upgrades (Trek.exe info)

Structure Upgrades (Trek.exe info); support/discussion/questions

Moderator: thunderchero

Post Reply
User avatar
QuasarDonkey
Code Analyst
Code Analyst
Posts: 433
Joined: Tue Jul 26, 2011 8:29 pm
Location: Ireland

Structure Upgrades (Trek.exe info)

Post by QuasarDonkey » Fri Nov 18, 2011 12:26 am

I've done some initial research into the upgrade mechanism in Trek.exe. It's actually pretty simple.

The subroutines controlling upgrades start at asm offset 488B2C (prefixed Game_Upgrade in the Standard IDA DB). These subroutines use tables of data starting at asm offset 590FE8.

Here's what the upgrade table for farms looks like when nicely formatted (asm offset 590FE8):

Code: Select all

           c    f    h    k    r
       /==========================
tech1 |    98  144  190  236  282
tech2 |    99  145  191  237  283
tech3 |   100  146  192  238  284
tech4 |   101  147  193  239  285
tech5 |   102  148  194  240  286
tech6 |   103  149  195  241  287
tech7 |   104  150  196  242  288
tech8 |   105  151  197  243  289
tech9 |   106  152  198  244  290
It's a 5x9 table of 16-bit integers (or words). Each number is a building ID. The 5 columns are for the major races, and the rows are for tech levels. If you cross-reference this with UE, you'll see the building 98 is a Cardassian Type 1 farm, 99 is a Card Type 2 farm, etc. 144 is Ferengi Type 1 farm... you get the idea.

Following that, there are similar tables for industry, energy, research, and intel (in that order).

There is also an upgrade table for scanners at asm 005911AA:

Code: Select all

12, 13, 24, 14
Again checking UE, building 12 is a Subspace Scanner, 13 is Listening Post, 24 is Covert Sensor Array, and 14 is Isolinear Scanner.

The subroutines use this data to determine which structures can be upgraded from others. The subroutines are hardcoded to only work with those tables, so adding additional upgradeable building types cannot yet be supported.

:idea: My idea is to scrap this system, and totally rewrite those functions to read in the upgrade tables from a new file in STBOF.RES. That way, we can have upgradeable energy structures (like Type 2 Shields, etc.), more scanner types, and maybe even Future Tech farms... the sky is the limit!

I've fully figured out the signatures all the upgrade functions:

Code: Select all

00489984 ; int Game_Upgrade_GetBuildingID(int techLevel, int buildingType)
         ; Returns the building ID for a given tech level and building type.

004893DC ; int Game_Upgrade_GetUpgradedBuildingID(int buildingId, int buildingType)
         ; Returns the building ID for the upgraded version of the building with given ID and type.

00488B2C ; int Game_Upgrade_CompareBuildingTechLevels(int buildingId1, int buildingId2, int buildingType)
         ; returns 1 if buildingId1 has higher tech level than buildingId2
         ; returns 0 if they have same tech level
         ; return -1 if buildingId1 has lower tech level than buildingId2
There are also some other functions that are only used by these three. With this info, I can begin recoding them.

If successful, this should allow for some serious mods :D

User avatar
Peter1981
Rear-Admiral
Rear-Admiral
Posts: 1118
Joined: Tue May 06, 2008 2:00 am
Location: England

Re: Structure Upgrades (Trek.exe info)

Post by Peter1981 » Fri Nov 18, 2011 4:53 am

@QD just to mention take a look again at the edifice.bst tread, there are some limits within the edifice.bst file but shouldn't be to hard to reformat it to use higher technologies. Specifically the table of avaliable building at each tech level and the race bit mask.

User avatar
Flocke
BORG Trouble Maker
BORG Trouble Maker
Posts: 2546
Joined: Sun Apr 27, 2008 2:00 am
Location: Hamburg, Germany
Contact:

Re: Structure Upgrades (Trek.exe info)

Post by Flocke » Fri Nov 18, 2011 6:27 am

that's cool stuff! :o
great work QuasarDonkey :D

User avatar
anjel
Past Administrator
Past Administrator
Posts: 666
Joined: Thu May 08, 2008 2:00 am
Location: Bs As - Argentina

Re: Structure Upgrades (Trek.exe info)

Post by anjel » Fri Nov 18, 2011 7:25 am

nice intel you are doing QD "the sky is the limit" should be your signature :D .
Keep up the good hard work !!!
Live long and propser

User avatar
QuasarDonkey
Code Analyst
Code Analyst
Posts: 433
Joined: Tue Jul 26, 2011 8:29 pm
Location: Ireland

Re: Structure Upgrades (Trek.exe info)

Post by QuasarDonkey » Sun Nov 20, 2011 4:35 pm

I've rewritten the above subroutines to load in the data from STBOF.RES. Upgrades still only work on manned structures and scanners. :x

But that's not the end of the story. It turns out that this upgrade code is only the last link in the chain. I'll need to analyze and rewrite some code for Solar System screen and for AI System Development. The code is not too complex though. It just loops over all the structures in the current star system and does lots of checks to decide what can be built / upgraded.

Edit: actually it's quite complex, lol.

I'll post all the technical details on how upgrades work when I finish analyzing these other routines.

User avatar
Flocke
BORG Trouble Maker
BORG Trouble Maker
Posts: 2546
Joined: Sun Apr 27, 2008 2:00 am
Location: Hamburg, Germany
Contact:

Re: Structure Upgrades (Trek.exe info)

Post by Flocke » Sun Nov 20, 2011 9:25 pm

did you try to just skip all current upgrade code?
If that works, it should be possible to place complete new code in there. Then you could also try to fix the complete build subroutine and even allow to build multiple things per turn.
The upgrades could also be read in from an own textfile, so there's less restriction.
There's lots known on how the buildings of the systems are stored, you can refer to the savegame documentation. Not sure about current build tasks and production but am sure this can be figured as well, if not already.

Lots possibilities. Always wanted to give that a try, but you know, too much to do. :)

Post Reply

Return to “Structure Upgrades (Trek.exe info)”

Who is online

Users browsing this forum: No registered users