User talk:Morgan525

From UFOpaedia
Jump to navigation Jump to search

Modding Tank/Cannon into a Tank/Chaingun

Many people have questions about this. It's fairly easy to change the ammo type of the Tank/Cannon turrent and damage into a AP/rifle and then giving the turret autofire. The real problem is changing the amount of ammo in the tank and not cause problems with the amount of ammo in your base stores. In the executable there are various places that handle updating the amount of ammo for the various events: adding a tank onto a craft(checking if the base has the proper amount of ammo for the tank and removing that amount from base stores, if so), removing the tank from a craft (adding the ammo back to base stores), post-interception-battle (adding the remaining ammo from the tank into base stores and attempting to add the tank back onto the craft), and post base defense (adding the remaining ammo to base stores.) In addition, there is the routine that sets the amount of ammo for the tank in battlescape. If you miss any of these areas, your ammo supply quickly spirals out of control or you get no benefit for the changes you have made.

The DOS version of the game makes it much simpler to adjust the stats, but I have lost the notes on the offsets. The problem with the CE version is the way the compiler wrote the calculations. In the code, the value was calculated by using multiples of five with bit-shifts to get to 30. This means you can't choose any amount for your ammo. I rewrote these lines to make it simpler to understand and give more freedom to choose the value(Feel free to use these changes. I gave my tank 60 rounds {3Ch}. However, unless you want to deduce for yourself how to modify the proper locations, don't increase the amount of ammo over 63. [This has to do with how the game uses bit-shifts to calculate remaining ammo during the post-tatical phase]):

TANK/CANNON AMMO ALTERATION
POST-TACTICAL PHASE BASE/CRAFT INVENTORY UPDATE
0x449C53: B8 3C 00 00 00 0F AF C2 90 90 3B F0 7D 2C 66 0F B6 D2 66 01 17 B8 89 88 88 88 F7 EE 03 D6 C7 44 24 10 01 00 00 00 C1 FA 05 8B C2 C1 E8 1F 03 D0 88 55 2C 66 0F B6
          D2 66 29 17 66 0F B6 45 00 8B D0 C1 E2 0B 2B D0 C1 E2 04 03 D0 C1 E2 02 66 02 91 1A 01 00 00 90 90

.text:00449C53                 mov     eax, 3Ch
.text:00449C58                 imul    eax, edx
.text:00449C5B                 nop
.text:00449C5C                 nop
.text:00449C5D                 cmp     esi, eax
.text:00449C5F                 jge     short loc_449C8D
.text:00449C61                 movzx   dx, dl
.text:00449C65                 add     [edi], dx
.text:00449C68                 mov     eax, 88888889h
.text:00449C6D                 imul    esi
.text:00449C6F                 add     edx, esi
.text:00449C71                 mov     [esp+30h+var_20], 1
.text:00449C79                 sar     edx, 5
.text:00449C7C                 mov     eax, edx
.text:00449C7E                 shr     eax, 1Fh
.text:00449C81                 add     edx, eax
.text:00449C83                 mov     [ebp+2Ch], dl
.text:00449C86                 movzx   dx, dl
.text:00449C8A                 sub     [edi], dx
.text:00449C8D                 movzx   ax, byte ptr [ebp+0]
.text:00449C92                 mov     edx, eax
.text:00449C94                 shl     edx, 0Bh
.text:00449C97                 sub     edx, eax
.text:00449C99                 shl     edx, 4
.text:00449C9C                 add     edx, eax
.text:00449C9E                 shl     edx, 2
.text:00449CA1                 db      66h
.text:00449CA1                 add     dl, [ecx+11Ah]
.text:00449CA8                 nop
.text:00449CA9                 nop

0x449DFA: B8 3C 00 00 00 0F AF C2 3B F0 7D 2E 90 90 66 0F B6 D2 66 01 17 B8 89 88 88 88 F7 EE 03 D6 C7 44 24 10 01 00 00 00 C1 FA 05 8B C2 C1 E8 1F 03 D0 88 55 00 66 0F B6 
          D2 66 29 17 66 0F B6 45 00 8B D0 C1 E2 0B 2B D0 C1 E2 04 03 D0 C1 E2 02 66 01 91 1A 01 00 00 90 90

.text:00449DFA                 mov     eax, 3Ch
.text:00449DFF                 imul    eax, edx
.text:00449E02                 cmp     esi, eax
.text:00449E04                 jge     short loc_449E34
.text:00449E06                 nop
.text:00449E07                 nop
.text:00449E08                 movzx   dx, dl
.text:00449E0C                 add     [edi], dx
.text:00449E0F                 mov     eax, 88888889h
.text:00449E14                 imul    esi
.text:00449E16                 add     edx, esi
.text:00449E18                 mov     [esp+30h+var_20], 1
.text:00449E20                 sar     edx, 5
.text:00449E23                 mov     eax, edx
.text:00449E25                 shr     eax, 1Fh
.text:00449E28                 add     edx, eax
.text:00449E2A                 mov     [ebp+0], dl
.text:00449E2D                 movzx   dx, dl
.text:00449E31                 sub     [edi], dx
.text:00449E34                 movzx   ax, byte ptr [ebp+0]
.text:00449E39                 mov     edx, eax
.text:00449E3B                 shl     edx, 0Bh
.text:00449E3E                 sub     edx, eax
.text:00449E40                 shl     edx, 4
.text:00449E43                 add     edx, eax
.text:00449E45                 shl     edx, 2
.text:00449E48                 add     [ecx+11Ah], dx
.text:00449E4F                 nop
.text:00449E50                 nop

[TANK/CHAINGUN AMMO AMOUNT SET FOR TACTICAL REFERENCE]
0x44ED27: C6 45 76 3C

.text:0044ED27                 mov     byte ptr [ebp+76h], 3Ch

[TANK/CHAINGUN AMMO CHECK IN BASE INVENTORY AND ALTERATION OF AMOUNT]
0x456410: 66 83 84 90 1A 01 00 00  3C

.text:00456410                 add     word ptr [eax+edx*4+11Ah], 3Ch
0x4564F1: 66 83 F9 3C
.text:004564F1                 cmp     cx, 3Ch
0x456512: 83 C1 C4
.text:00456512                 add     ecx, 0FFFFFFC4h   (add    ecx, -3Ch)

[Alternate option]
0x456512: 83 E9 3C
.text:00456512                 sub     ecx, 3Ch              


TANK STATS start at offset 47573B

TANK UFOpaedia info 4752B0~4752CF 

Functions used in UFOloader's new interception routines

For those that might want to know how accuracy is calculated with the new options for interception turned on:

X-Craft Accuracy

[(1+((3-(.5*(difficulty level-1)))/UFOsize)/2 ] * Weapon Accuracy ....... [beginner=1..superhuman=5]

Diff	Ship Size				
	VS	S	M	L	VL
begin	0.8	0.875	1	1.25	2
exp	0.75	0.8125	0.91667	1.125	1.75
vet	0.7	0.75	0.83333	1	1.5
Genius	0.65	0.6875	0.75	0.875	1.25
Super	0.6	0.625	0.66667	0.75	1
         

UFO Accuracy

60 + (difficulty level *3) - [Cautious Mode bonus (10)]

Comparison of Damage routines

Xcraft-dam-routine.GIF


To explain, first the memory address of the Xcraft weapon is loaded to eax. Then the damage value is read from (eax+6) and loaded into bx. This value is sent to the random function where the value generated is returned through eax. Thereafter, the base value (ebx) is added to the random value (eax) for a range of 100-200%. The value of eax has edx subtracted from it (after extensive testing of several encounters and having edx displayed for each attack, edx always seems to be 0). eax is bit-shifted 1 space to the right {divided by two} and the final amount added to the amount of damage the craft has sustained (edi+0Ah). The result is that Xcraft weapons do 50-100% damage.

UFO-dam-routine.GIF

In the UFO case: the memory location for the UFO stats are set in ecx. Then the UFO weapon power is read (ecx+16h) and put into dx. Then this value is sent to the random funtion and again returned through eax (or ax as is the case here). ecx is set to zero and the random value is checked to see if zero was generated [cmp(compare) ax, cx]. If this is true, the program jumps past the section to assign damage to the Xcraft.



  • The main routine for interdiction in DOS1.4 version is from 330B0~336A8.

Feedback

Any questions or feedback one may have....