tetracorp / k240

Exploring K240, a project to disassemble the 1994 Commodore Amiga game, K240
https://tetracorp.github.io/k240/
5 stars 1 forks source link

Bug (or perhaps not?) - Ax'Zilanths can teleport without Mass Displacement Podule #14

Open drDragonSmoke opened 4 months ago

drDragonSmoke commented 4 months ago

After extensive play testing, I have determined that the Ax'Zilanths are able to teleport without having the Mass Displacement Podule building (indeed, without having barely any buildings). I do not yet understand the mechanism behind this bug, but it seems to be connected to their 1% chance of teleporting a random asteroid.

_16416:
    MOVEQ   #100,D0         ;16416: 7064
    JSR _RandInt        ;16418: 4eb900000c0c
    BNE.S   _1644E          ;1641e: 662e
; 1% chance:
    MOVEQ   #0,D0           ;16420: 7000
    MOVE.W  intAlienAstCount,D0 ;16422: 30390002e056
    JSR _RandInt        ;16428: 4eb900000c0c
    LEA arrAlienAsts,A1     ;1642e: 43f90001f8ba
    ADD.W   D0,D0           ;16434: d040
    ADD.W   D0,D0           ;16436: d040
    MOVEA.L (0,A1,D0.W),A0      ;16438: 20710000
_1643C:
; No missile silos
; Axz Mass Displacement Podule
    MOVEA.L ptrThisAstBldgCount,A4  ;1643c: 28790002ded4
    TST.W   (76,A4)         ;16442: 4a6c004c
    BEQ.S   _1644E          ;16446: 6706
    BSR.W   _AzxMassDisplPod    ;16448: 61002f98
    RTS             ;1644c: 4e75
_1644E:

The connection to this part of the code was established by changing the fourth line here from BNE.S _1644E to BRA.S _1644E, in order to skip it always, whereupon the bug is no longer observed.

drDragonSmoke commented 4 months ago

Update: It seems that this is related to the randomization of which alien asteroid is teleported. It can be "fixed" by making this change:

; 1% chance:
    MOVEQ   #0,D0           ;16420: 7000
;   MOVE.W  intAlienAstCount,D0 ;16422: 30390002e056
;   JSR _RandInt        ;16428: 4eb900000c0c
;   LEA arrAlienAsts,A1     ;1642e: 43f90001f8ba
;   ADD.W   D0,D0           ;16434: d040
;   ADD.W   D0,D0           ;16436: d040
;   MOVEA.L (0,A1,D0.W),A0      ;16438: 20710000
    MOVEA.L ptrThisAstStats,A0
    _1643C:

In other words, I believe the original code allows for an alien asteroid with a Mass Dicplacement Module to have a 1% chance to teleport any random alien asteroid, even one without an MDM. So this might actually be a feature, not a bug. While it does seem strange that the MDM should be able to teleport other asteroids than the one it is built on, I suppose it is not outside the realm of possibility.

tetracorp commented 4 months ago

Thanks for pointing this out. While investigating it, I found several duplicate label names in the current version of the playk240.cnf file, which I'm now fixing.

It's hard to be certain whether any given alien mechanic is a bug or intended, since of course it's undocumented. However, the other two instances (teleport to avoid collision, teleport to avoid leaving the edge of the map) require an asteroid to have its own Mass Displacement Podule. This leads me to think of it as a bug.

The 1% chance is part of _DailyAli3Atk, which triggers once per day per alien asteroid. It picks a random asteroid, then checks for the presence of a Mass Displacement Podule. However, it only loads the chosen asteroid into A0 and doesn't update ptrThisAstBldgCount to point to it, meaning that it checks the current asteroid for a Podule.

In the other 99% of cases, it does a proximity check for asteroid collisions, responding with a Mega missile if possible (if it has any Mega, has any missile silos, and it's a Terran asteroid), triggering teleport otherwise. In this case it uses the same code _1643C, but correctly checks the teleporting asteroid's Podule. Likewise, it will teleport to avoid moving off the edge of the screen, but needs its own Podule.

drDragonSmoke commented 4 months ago

Yes, I agree it is probably a bug. It seems unlikely that the Podule should be able to teleport a different asteroid than the one it is built on. I don't believe any other building functions like that, ie. can exert that kind of power on another asteroid, at unlimited distance. It makes me wonder though, about the motive behind having the 1% random chance pick a random asteroid for teleportation. Since it is a random 1% chance that every asteroid gets every day, why not just have the asteroid that rolls 100 be the one that teleports (if it has a Podule)? Why did they decide to double-up on the randomness? It is a logic that escapes me.

tetracorp commented 4 months ago

It could be that the programmer just forgot that this section ran once per asteroid.

If intentional, one possible reason is as a quick fix to raise the alien difficulty by making teleportation more common. The first Ax'zilanth colony starts with a Mass Displacement Pod, but new colonies don't prioritize building it. If my numbers are correct, it would take something like 640 days and 40 buildings before a colony has a 70% chance to have built one. It would be easy to allow other asteroids to teleport, and not too unbalanced, because the alien still only gets one teleport chance per total Podule, and most players will never notice since the Podule's effect is of course undocumented. However, the programmer could also have easily resolved this by simply adding the Podule to the build priority.

drDragonSmoke commented 4 months ago

Very true. Well, I wouldn't want to change anything in order to reduce the alien difficulty, so I think I will leave this alone. Thanks for your insight!

tetracorp commented 4 months ago

My theory is that, perhaps late in development, playtesters noticed that the main asteroid teleported but not the others. The programmer couldn't work out why, so he put in a quick fix (randomly selecting the asteroid). This "fixes" the issue at least well enough to keep the playtesters happy.

More thorough testing would have revealed that the cause was a lack of Mass Displacement Podules due to how rarely and slowly they build, and the only reason the fix "works" is that it fails to check for Podules, and therefore allows Podule-less asteroids to teleport. It's a reasonable hypothesis for the developers to make such a quick and ugly fix when the game is on a deadline.