Phantom-Dilithium Bug (fix)

Phantom Dilithium Bug (fix) -> OPTION; support/discussion/questions

Moderator: thunderchero

Post Reply
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 723
Joined: Sun Apr 27, 2008 2:00 am

Phantom-Dilithium Bug (fix)

Post by Spocks-cuddly-tribble » Mon Sep 15, 2008 3:48 pm

As we all know a bug of BotF enabels keeping more ships under construction than the total of running dilithium sources (unless it's zero). Real source only limits the maximum of finished ships per turn.

Oftentimes this method/bug called "Phantom Dilithium" induces wastages of system production at turns consuming the total amount of real dilithium for ship completions. (Thanks to The_Nighthawk for pointing to the issue).

That depends on beginning of ships production. BotF sorts all ships under construction by beginning of production. I.e. by the earliest setting into FIRST position of Production Queue.
NOTE: BotF is watching in which order things will be done during a turn !

In case of maximal ship finishing, all ships with a later beginning of production than the current completed have an interrupt. I.e. the industrial production of the system is wasted.


Example:

sh1 = ship with the earliest beginning of production
sh2 = ship with the second earliest beginning of production
and so on

shX# = ship X finished

S1 = system producing sh1
S2 = system producing sh2
and so on

DS = amount of running dilithium sources


DS = 1
sh1 - sh2# - sh3 -> S1/OK - S3/interrupt



The good news is if multiple ships completed on the same turn then decides the ship with the latest beginning of production upon interrupt:


DS = 2
sh1 - sh2# -sh3 - sh4# - sh5 -> S1 & S3/OK ; S5/interrupt -> sh4# decides



If there were additional ships in Production Queue behind sh2# & sh4# then will the RELATIVE order for the next turn still remain.



Btw leaving systems displaying "Dilithium Shortage" instead of "Turns Remainig X" won't affect BotF. Just ignore it.

The same applies to "On Hold" instead of "X turn(s)" behind ships in systems list ->Build column.

In case of a REAL dilithium shortage only the ships with the earlier beginning of production will be finished. The others will interrupt explained above.
On the verge of a nervous breakdown? Try the relaxing tribble sounds.

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

Post by Spocks-cuddly-tribble » Sat Sep 05, 2009 10:03 am

Now from the in-game effects to the modding part. :)



We've three displays and (aside of the one click delay of No.3) they work all correctly and as intended:


1.) F1 Empire Info -> Count of unused dilithium (Red warning if negative)

2.) Summary / Systems -> (On Hold) warning for ALL ships

3.) F2 Build Queue -> Dilithium Shortage warning for ALL ships


This strongly indicates that Dilithium Shortage was meant to affect all ships under construction and not only the surplus i.e. similar effect as "Credit Deficit".


Hence the new code restores the functionality of BotF as initially intended by the developers :



Phantom-Dilithium Bug (fix)

Code: Select all

In trek.exe at 0x5F313 replace:

8D 04 ED 00 00 00 00 01 E8 C1 E0 02 01 E8 C1 E0 02 89 C5 C1 E0 02 29 E8 05 98 1A 5B 00

with:

69 C5 BC 01 00 00 05 98 1A 5B 00 8B 68 64 3B 68 60 76 0A 31 D2 E9 C8 02 00 00 90 90 90


replacement at asm 45FF13:

imul    eax, ebp, 1BCh
add     eax, offset save_EmpsInfo
mov     ebp, [eax+64h]
cmp     ebp, [eax+60h]
jbe     short loc_45FF30
xor     edx, edx
jmp     loc_4601F5 (dilithium_shortage)
nop    (3x)
Alternative method: (not recommended, since more work & not matching displays)

Remove at 460159 dec dword ptr [eax+0Ch] & insert at 45FF94 (3 freed bytes needed)



Note there is still the Ship Yard Unpowered bug which allows shipbuilding despite of unpowered yard, but I doubt it's worth the effort to fix it.
On the verge of a nervous breakdown? Try the relaxing tribble sounds.

User avatar
dx_chaos
Ensign
Ensign
Posts: 37
Joined: Fri Jan 02, 2009 3:00 am

Post by dx_chaos » Mon Sep 07, 2009 3:05 pm

Spock

This is very interesting stuff and as you say seems to take the game in the direction it was intended to be.

It would be great to see this implemented in one of the mods - has anyone any plans to do this?

Chaos

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

Post by thunderchero » Mon Oct 12, 2009 11:05 pm

Spocks-cuddly-tribble,

I am just wondering, Is it possible to remove the 3 warning for those mods who want to keep to this option for building ships? like UDM (major ship building mod)

F1 Empire Info -> Count of systems with dilithium only
Summary / Systems -> no (On Hold) warning Regardless how many systems are building ships
F2 Build Queue -> no Dilithium Shortage warning Regardless how many systems are building ships

I know warning can be ignored but this would be nice to have this option for those who want it.

thunderchero

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

Post by Spocks-cuddly-tribble » Tue Oct 13, 2009 11:33 am

thunderchero wrote:F1 Empire Info -> Count of systems with dilithium only
Summary / Systems -> no (On Hold) warning Regardless how many systems are building ships
F2 Build Queue -> no Dilithium Shortage warning Regardless how many systems are building ships
EDIT(2nd): dilithium count (1)

Replace -> 4EA37A mov eax, [eax+10h]
with -> xor eax, eax (&nop)
=> trek.exe at 0xE977A change 8B 40 10 to 31 C0 90

For (2) & (3) remove:

441BBD mov edi, 0FFFFFFFCh -> (on hold)
4F2ECE ja loc_4F2F9B -> DIL_shortage

Also, I'd suggest remove:

45FF8E jz loc_4601F5

(disables any need for dilithium when shipbuilding)

and:

4F2EDF jz loc_4F3001 -> ship_yard_unpowered warning
On the verge of a nervous breakdown? Try the relaxing tribble sounds.

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

Post by Spocks-cuddly-tribble » Fri Dec 25, 2009 6:11 pm

This code will turn phantom dilithium into an (almost) proper feature i.e. without any silly order-of-ships production wastages (both parts of damaged code moved to ship completion).

One can keep unlimited ships under construction (even without any dilithium) but still need dilithium at the turn of completion. Finalising more ships than available dilithium results only in a not completed surplus (in the order explained above) whilst the industry will be added (until max cost).

Code: Select all

trek.exe at 0x5F382

change:
8B 84 24 34 01 00 00 8B 50 0C 85 D2 0F 84 61 02 00 00
to:
90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90

=> remove asm 45FF82-45FF8E

AND

trek.exe at 0x5F53C

change:
31 C0 66 8B 55 04 66 8B 84 24 40 01 00 00 39 C2 0F 8C 18 01 00 00 8B 84 24 34 01 00 00 FF 48 0C 8B 57 12 8B 47 02 C1 FA 10 C1 F8 10
to:
0F B7 84 24 40 01 00 00 39 45 04 7C 0E 89 45 04 8B 84 24 34 01 00 00 83 78 0C 01 0F 8C 0D 01 00 00 FF 48 0C 0F B7 57 14 0F B7 47 04


=> at asm 46013C:
movzx     eax,  word ptr [esp+140h]
cmp       [ebp+4], eax
jl        short_14 bytes   //   not finished
mov       [ebp+4], eax
mov       eax, [esp+134h]
cmp       dword ptr [eax+0Ch], 1
jl        loc_46026A      //   not finished
dec       dword ptr [eax+0Ch]
movzx     edx, word ptr [edi+14h]
movzx     eax, word ptr [edi+4]
On the verge of a nervous breakdown? Try the relaxing tribble sounds.

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 » Sun Dec 27, 2009 9:23 am

Wow, that's amazing, thank you very much :)
I did not expect this to be achievable.

Just wanting to make sure I understand you correctly:
At the global loop, every system which is currently producing a ship will still decrement the dilithium count. But no dilithium shortage will be induced.

In the second part, you modify an area that will only affect systems which are actually finishing a ship at the current turn. You read the dilithium count and stall the ship completion if there's no dilithium left.

Which leads to one question: How on earth did you free up enough space to squeeze in that many code lines? ^^

Spocks-cuddly-tribble wrote:
Gowron wrote:At the global loop, every system which is currently producing a ship will still decrement the dilithium count. But no dilithium shortage will be induced.
No, due to the bug, unmodded BotF never did decrement dil. count at this area. The "global" check (and jump statement) for dilithium shortage has been removed there.
Gowron wrote:In the second part, you modify an area that will only affect systems which are actually finishing a ship at the current turn. You read the dilithium count and stall the ship completion if there's no dilithium left.
Yes, whilst preventing project overflows.
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.

Post Reply

Return to “Phantom Dilithium Bug (fix) -> OPTION”

Who is online

Users browsing this forum: No registered users