Colonies: population, farms, factories

Colonies : population, farms, factories; support/discussion/questions

Moderator: thunderchero

User avatar
Gowron
Code Master
Code Master
Posts: 304
Joined: Sat Apr 26, 2008 2:00 am
Location: 50° N, 11° E

Colonies: population, farms, factories

Post by Gowron »

The production rate of a colony ship determines the starting population and the starting buildings of the colony that it founds.

The default values are:

Code: Select all

colony ship production   0   1   2   3   4   5   6   7   8

starting population...  10  10  20  20  30  30  40  40  50
number of farms.......   1   2   2   3   3   4   4   5   5
number of factories...   0   0   1   1   2   2   3   3   4

NOTE: Newly colonized systems will already grow during the turn that they're colonized, so you'll never actually see the listed starting populations. Also note that this should always be a multiple of 10(dec), otherwise auto-assigning workers to buildings (when the system grows) will be bugged.

The values in this table (except for the colony ship production values) are stored in trek.exe as integers (4 bytes per value), starting at 0x18e2b8, sorted by columns first and then by rows.
Modding them works fine, but adding other buildings than just farms and factories doesn't seem to be possible.

The colony ship production values are not stored there, instead they seem to function as index values. This pretty much foils the option to increase colony ship production values in order to remove the insta-terraforming "easter egg".

Increasing the colony ship production to 10 (0x0a) or more results in a crash whenever one tries to found a colony with such a ship (terraforming works, though).

Setting the colony ship production to zero did not cause any crashes so far, but the AI gets somewhat stuck, of course.

==> Link to A Detailed Implementation Example :idea:
Last edited by Gowron on Sat Nov 22, 2008 5:17 pm, edited 1 time in total.
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.
User avatar
Gowron
Code Master
Code Master
Posts: 304
Joined: Sat Apr 26, 2008 2:00 am
Location: 50° N, 11° E

Post by Gowron »

Note that these values can collide with the raiding percentage base values:

http://armadafleetcommand.com/onscreen/ ... opic&t=491
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.
User avatar
Gowron
Code Master
Code Master
Posts: 304
Joined: Sat Apr 26, 2008 2:00 am
Location: 50° N, 11° E

Re: Colonies: population, farms, factories

Post by Gowron »

Gowron wrote:But increasing the colony ship production to 10 (0x0a) or more results in a crash whenever one tries to found a colony with such a ship
The corresponding check is located at position 0x68EF4:

Code: Select all

position   hex            asm

0x68EF4    83FF0A         cmp edi, 00A
0x68EF7    0F8DC7020000   jge 00469DC4
And directly after that, we have the data offset definition:

Code: Select all

position   hex            asm

0x68EFD   8D04BD00000000  lea eax, dword[4*edi+00000000]
0x68F04   29F8            sub eax, edi
0x68F06   8B9424E4010000  mov edx, dword[esp+000001E4]
0x68F0D   8B0485B8045900  mov eax, dword[4*eax+005904B8]
The first two statements set [eax] to 3*[edi] (because there are three data values per data block: number of farms, number of factories and starting population), and the last line multiplies [eax] by 4 (because each data value has a size of 4 bytes) and adds the base offset, which is 0x5904B8 (asm) resp. 0x18E2B8 (hex).


Removing the check allows colony ship production rates to exceed 10, and the data offset calcaulation has to be adapted so that the correct values are read (since the production rate is used to determine the offset).
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.
User avatar
Gowron
Code Master
Code Master
Posts: 304
Joined: Sat Apr 26, 2008 2:00 am
Location: 50° N, 11° E

Post by Gowron »

You gotta try out the HxD Editor
http://mh-nexus.de/en/ (English)
resp.
http://mh-nexus.de/de/ (German)

It's small, free, ad-free and reliable.

Available as a portable and an installable version :)
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.
User avatar
Gowron
Code Master
Code Master
Posts: 304
Joined: Sat Apr 26, 2008 2:00 am
Location: 50° N, 11° E

Post by Gowron »

Peter1981 wrote:thanks for the info Gowron :-)
You're welcome :)



Update:

There data offsets for farms and factories are stored separately at these locations:

Code: Select all

position     asm

0x68F98  8BB3BC045900    mov esi, dword[ebx+005904BC]  // farms

0x68FBA  3B8BBC045900    cmp ecx, dword[ebx+005904BC]  // farms

0x69008  8B93C0045900    mov edx, dword[ebx+005904C0]  // factories

0x69027  3B8BC0045900    cmp ecx, dword[ebx+005904C0]  // factories
If you intend to change the base offset for the colony data, then you should change all five values by the same amount.
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7851
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: Colonies: population, farms, factories

Post by thunderchero »

Gowron wrote:Modding them works fine, but adding other buildings than just farms and factories doesn't seem to be possible.
Is it possible now?

I was thinking it would be nice to have instead of 10 different sets to have 5 sets population, food, production, energy, intel, research. but one for each race.

this way cards colonies could be focused on intel, ferengi focused on production, feds could be balanced, klingons focused on production, and romulans focused on intel/research. Or any way the modder likes.

thoughts

thunderchero
User avatar
Tethys
Past Administrator
Past Administrator
Posts: 2392
Joined: Fri Jul 18, 2008 2:00 am
Location: Your mom's bed ;)
Contact:

Re: Colonies: population, farms, factories

Post by Tethys »

This would indeed be an interesting route to take. So your saying that 0-4 production values could be for food and industry, 5-9 values can be for intel and research, if so, I see where you are coming from. But if this is indeed possible, I think it would be a good idea to have Feds using the 4 and 5 values for a balance like you suggested. I am curious about this myself ;)
Not for the weak of heart...
Galaxies MOD v0.4.0 <--- GALM/Galaxies Mod latest version
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7851
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: Colonies: population, farms, factories

Post by thunderchero »

Tethys wrote:This would indeed be an interesting route to take. So your saying that 0-4 production values could be for food and industry, 5-9 values can be for intel and research, if so, I see where you are coming from. But if this is indeed possible, I think it would be a good idea to have Feds using the 4 and 5 values for a balance like you suggested. I am curious about this myself ;)
no I was thinking only 1 production value (maybe to free up code) old table 0 - 1 cards, 2 - 3 ferengi, 4 - 5 feds, 6 - 7 klingons, 8 - 9 romulans. But only 5 values possible 0-4 that would use full area as before just 1 setting per race Or if modder wanted to share values for advanced production that should be possible too. Or use part of the unused section for larger table then code changes permitted who knows.

thunderchero
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

Colonies Starting Pop and Buildings - experimental code

Post by Spocks-cuddly-tribble »

Corrected the colony ship production table by Gowron at 0x18E2B8 (9*12 bytes i.e. for production values 0-8 only). Consequently the vanilla code should be: (or just avoid using/editing production values 9+)

Code: Select all

00469AF4       cmp     edi, 9

00469DC4       mov     edi, 8
00469DC9       jmp 00469AFD
By default production value 0 is unused due to the missing terraforming ability, but could be used with e.g. this bio tech modification:
viewtopic.php?p=24497&sid=f325f6163b2d0 ... fe5#p24497

Or change my above code example at 00469DC4 to 'mov edi, 0' i.e. production values 9+ will use table entry 0.


:arrow: Colonies Starting Pop and Buildings - experimental code (test code for main building fixes)

New 12 byte entry structure of the colony ship production table at 0x18E2B8: (for production values 0-8)

Bytes:
  • 1-4 starting population (unchanged)
    => Number of main buildings:
    5 - Food
    6 - Industry
    7 - Energy
    8 - Research
    9 - Intel
    10 - Race specific bonus buildings (see below)
    => AI bonuses:
    11 - AI starting pop bonus (i.e. +value from byte 1-4)
    12 - 1= AI extra starting shipyard
At asm-469DEB i.e. 0x691EB (5 zero bytes) = race specific bonus area (1 byte each, card-rom)

Area IDs for race specific extra buildings:

0 - Food
1 - Industry
2 - Energy
3 - Research
4 - Intel

e.g. 00 00 00 01 00 -> klingons extra Industry, all other extra Food (cf. byte 10 above for number of extra buildings)


The starting buildings are always the latest upgrades (unless the number is 0). IIRC a request/idea by Dr_Breen.

Code: Select all

trek.exe at 0x68F54 - 0x6902E new code 0xDB bytes:

0F B6 42 4C 89 44 24 0C 6B FF 0C 81 C7 BC 04 59 00 33 F6 89 74 24 10 80 3F 00 74 4C 8B 44 24 0C 8D 54 24 20 6B CE 03 C1 E1 06 BB 20 51 44 00 2B D9 90 FF D3 90 90 0F B6 94 24 85 00 00 00 8B 44 24 0C E8 E5 9A FE FF 48 90 90 3C 08 7E 02 B0 08 33 C9 0F B7 5C 24 70 03 D8 8B 45 0C 8B D3 E8 39 C2 FD FF 41 3A 0F 7C F1 47 FE 44 24 10 8B 74 24 10 83 FE 05 7C A1 74 44 90 90 90 90 8B 8C 24 E4 01 00 00 83 79 04 01 75 53 0F B6 07 01 41 40 80 7F 01 01 75 47 8B 41 44 E8 93 0A FD FF 8B D0 8B 45 0C E8 F5 C1 FD FF EB 33 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 8B 44 24 0C 0F B6 B0 EB 9D 46 00 E9 4B FF FF FF 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90

-ASM Code-

00469B54     0FB642 4C            MOVZX EAX, BYTE [EDX+4C]  // race ID
00469B58     894424 0C            MOV [ESP+C], EAX  // store race ID
00469B5C     6BFF 0C              IMUL EDI, EDI ,0C  // colony ship production
00469B5F     81C7 BC045900        ADD EDI, 005904BC  // production table+4
00469B65     33F6                 XOR ESI, ESI  // area ID
00469B67     897424 10            MOV DWORD PTR SS:[ESP+10], ESI // loop count
00469B6B     803F 00              CMP BYTE [EDI], 0   // if number/marker 0...
00469B6E     74 4C                JE SHORT 469BBC   // ...check next
00469B70   8B4424 0C           MOV EAX, [ESP+C]  // race ID
00469B74   8D5424 20           LEA EDX, [ESP+20] // address for edifice.bst entry
00469B78   6BCE 03              IMUL ECX,ESI, 3
00469B7B   C1E1 06              SHL ECX, 6
00469B7E   BB 20514400          MOV EBX, 00445120
00469B83   2BD9                 SUB EBX, ECX
00469B85   90                   NOP
00469B86   FFD3                CALL EBX   // load T1 building edifice.bst entry
00469B88   90                  NOP
00469B89   90                  NOP
00469B8A     0FB69424 85000000    MOVZX EDX, BYTE [ESP+85]  // Tech req. type
00469B92     8B4424 0C            MOV EAX, [ESP+C]  // race ID
00469B96     E8 E59AFEFF          CALL 453680  // get tech level
00469B9B     48                   DEC EAX  // current tech level -1
00469B9C     90                   NOP
00469B9D     90                   NOP
00469B9E     3C 08                CMP AL, 8    // max upgrades for main buildings
00469BA0     7E 02                JLE SHORT 469BA4
00469BA2     B0 08                MOV AL, 8   // max upgrades for main buildings
00469BA4     33C9                 XOR ECX, ECX
00469BA6     0FB75C24 70          MOVZX EBX, WORD [ESP+70]  // tech 1 building ID
00469BAB     03D8                 ADD EBX, EAX   // add tech factor
00469BAD     8B45 0C              MOV EAX, [EBP+C]  // system ID
00469BB0     8BD3                 MOV EDX, EBX  // building ID
00469BB2     E8 39C2FDFF          CALL 445DF0  // add building
00469BB7     41                   INC ECX
00469BB8     3A0F                 CMP CL, BYTE [EDI]
00469BBA    ^7C F1                JL SHORT 469BAD // add buildings loop
00469BBC     47                   INC EDI
00469BBD     FE4424 10            INC BYTE [ESP+10]
00469BC1     8B7424 10            MOV ESI, [ESP+10]
00469BC5     83FE 05              CMP ESI, 5
00469BC8    ^7C A1                JL SHORT 469B6B // loop next area
00469BCA     74 44                JE SHORT 469C10 // goto load race bonus area
00469BCC     90                   NOP
00469BCD     90                   NOP
00469BCE     90                   NOP
00469BCF     90                   NOP
00469BD0     8B8C24 E4010000      MOV ECX, [ESP+1E4]  // systInfo
00469BD7     8379 04 01           CMP DWORD [ECX+4], 1  // AI system?
00469BDB     75 53                JNZ SHORT 469C30    // exit if player
00469BDD     0FB607               MOVZX EAX,BYTE [EDI]   // AI pop bonus
00469BE0     0141 40              ADD [ECX+40], EAX  // add extra pop
00469BE3     807F 01 01           CMP BYTE [EDI+1], 1 // AI shipyard marker
00469BE7     75 47                JNZ SHORT 469C30
00469BE9     8B41 44              MOV EAX, [ECX+44] // race ID
00469BEC     E8 930AFDFF          CALL 43A684  // get yard ID
00469BF1     8BD0                 MOV EDX, EAX
00469BF3     8B45 0C              MOV EAX, [EBP+C]  // system ID
00469BF6     E8 F5C1FDFF          CALL 445DF0  // add building
00469BFB     EB 33                JMP SHORT 469C30  // exit
00469BFD     90                   NOP
00469BFE     90                   NOP
00469BFF     90                   NOP
00469C00     90                   NOP
00469C01     90                   NOP
00469C02     90                   NOP
00469C03     90                   NOP
00469C04     90                   NOP
00469C05     90                   NOP
00469C06     90                   NOP
00469C07     90                   NOP
00469C08     90                   NOP
00469C09     90                   NOP
00469C0A     90                   NOP
00469C0B     90                   NOP
00469C0C     90                   NOP
00469C0D     90                   NOP
00469C0E     90                   NOP
00469C0F     90                   NOP
00469C10     8B4424 0C            MOV EAX, [ESP+C] // race ID
00469C14     0FB6B0 EB9D4600      MOVZX ESI, BYTE [EAX+469DEB] // race bonus area
00469C1B    ^E9 4BFFFFFF          JMP 469B6B
00469C20     90                   NOP
00469C21     90                   NOP
00469C22     90                   NOP
00469C23     90                   NOP
00469C24     90                   NOP
00469C25     90                   NOP
00469C26     90                   NOP
00469C27     90                   NOP
00469C28     90                   NOP
00469C29     90                   NOP
00469C2A     90                   NOP
00469C2B     90                   NOP
00469C2C     90                   NOP
00469C2D     90                   NOP
00469C2E     90                   NOP
To disable newest upgrade feature:

Code: Select all

00469BAB     03D8       ADD EBX, EAX
->  Nop  9090
To adapt upgrade feature to reduced upgrades mods: (code is shared for all main buildings!)

Code: Select all

00469B9B     48                   DEC EAX  // current tech level -1
00469B9C     9090                 NOP
-> e.g. 'dec eax' & 'shr eax,1' = [tech level-1]/2 for BoP (4 upgrades instead of vanilla 8) 

00469B9E     3C 08                CMP AL, 8    // max upgrades for main buildings

00469BA2     B0 08                MOV AL, 8   // max upgrades for main buildings
-> e.g. set 4 for BoP, 0 if no upgrades
To change location of the colony ship production table at 0x18E2B8: (only two values)

Code: Select all

00469B0D     8B0485 B8045900    MOV EAX, [EAX*4+5904B8] // old pop pointer

00469B5F     81C7 BC045900        ADD EDI, 005904BC // new building pointer to 5904B8+4
Edit by Tethys (11/09/2014)

To turn AI bonuses into human player bonuses, at 0x68FDB: (remove jump by overwriting 2 bytes with 90 90)

Code: Select all

00469BDB     75 53                JNZ SHORT 469C30    // exit if player

becomes

00469BDB     90 90                NOP    // 
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

Colony Starting Pop/Buildings Index Bug Fix

Post by Spocks-cuddly-tribble »

Well, I almost missed this obvious bug:
Spocks-cuddly-tribble wrote:...colony ship production table...at 0x18E2B8 (9*12 bytes i.e. for production values 0-8 only). Consequently the vanilla code should be: (or just avoid using/editing production values 9+)

Code: Select all

00469AF4       cmp     edi, 9

00469DC4       mov     edi, 8
00469DC9       jmp 00469AFD
By default production value 0 is unused due to the missing terraforming ability...
:arrow: Colony Starting Pop/Buildings Index Bug Fix

Code: Select all

trek.exe at 0x68EE1 new code 9 bytes:

4F 83 FF FF 7F 02 33 FF 90

asm code:
00469AE1     4F          DEC EDI
00469AE2     83FF FF     CMP EDI, -1
00469AE5     7F 02       JG SHORT 469AE9
00469AE7     33FF        XOR EDI, EDI
00469AE9     90          NOP
Note: The vanilla table by Gowron at 0x18E2B8 now represents the production values 1-9.

Using this fix the check values at asm 469AF4 & 469DC4 in my example should be decreased by a point each (but unneeded, see my comment above).
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
deva5tator
Cadet 2nd Year
Cadet 2nd Year
Posts: 7
Joined: Sun Jul 28, 2013 4:01 pm

Re: Colonies: population, farms, factories

Post by deva5tator »

Wow this is complicated for me..

I am trying to make it so that every Fed colony starts with in the Ultimate Dominion Mod III:

25x LVL 9 Automated Farms
25x LVL 9 Mass Replicators
25x LVL 9 Plasma Reactors
25x LVL 9 Databanks
25x LVL 9 Universities

But I am not sure which file to edit or what to use? I think it is possible with the UE..?

Thanks
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7851
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: Colonies: population, farms, factories

Post by thunderchero »

deva5tator wrote: I think it is possible with the UE..?
No, you must hex edit the trek.exe

this is main post to make the changes you want.

viewtopic.php?f=9&t=64&p=33179&sid=e966 ... 55b#p33179

you might also want to watch this post

viewtopic.php?f=4&t=2780

he is wanting to do same thing.

thunderchero
User avatar
brianmcfa
Lieutenant-Commander
Lieutenant-Commander
Posts: 134
Joined: Tue Aug 03, 2010 2:00 am
Location: Concrete, WA

Re:

Post by brianmcfa »

Gowron wrote:You gotta try out the HxD Editor
http://mh-nexus.de/en/ (English)
resp.
http://mh-nexus.de/de/ (German)

It's small, free, ad-free and reliable.

Available as a portable and an installable version :)
I downloaded and tried using this hex editor but I can't seem to find the values you list. I'm a novice at this but all the offsets I show start with 00 and none that have 0x. What are the settings I should be using to get the values you have?
User avatar
Flocke
BORG Trouble Maker
BORG Trouble Maker
Posts: 3197
Joined: Sun Apr 27, 2008 2:00 am
Location: Hamburg, Germany
Contact:

Re: Colonies: population, farms, factories

Post by Flocke »

hi brianmcfa,
first you need to seperate on whether it's asm or hex offsets
asm is the memory location to where the game gets loaded, hex is the file offset
asm you can convert to hex with ue or look it up with a disassembler
for HxD you need hex offsets
second, 0x just means the value is hexadicimal based so with values 0 to F so just a convention for writing the values down

I think we also have a guide on this and using UE and so somewhere or at least some topic with info :roll:

cheers & HTH
User avatar
brianmcfa
Lieutenant-Commander
Lieutenant-Commander
Posts: 134
Joined: Tue Aug 03, 2010 2:00 am
Location: Concrete, WA

Re: Colonies: population, farms, factories

Post by brianmcfa »

Flocke wrote:hi brianmcfa,
first you need to seperate on whether it's asm or hex offsets
asm is the memory location to where the game gets loaded, hex is the file offset
asm you can convert to hex with ue or look it up with a disassembler
for HxD you need hex offsets
second, 0x just means the value is hexadicimal based so with values 0 to F so just a convention for writing the values down

I think we also have a guide on this and using UE and so somewhere or at least some topic with info :roll:

cheers & HTH
The UE I've got down pretty well. It's just the stuff that UE can't do that I have to hex edit where I'm trying to relearn the universe. I miss my BASIC. :lol:
Post Reply

Return to “Colonies : population, farms, factories”