lufia2ac: new features, bug fixes, and more (#1549)

### New features

- ***Architect mode***
  Usually the cave is randomized by the game, meaning that each attempt will produce a different dungeon. However, with this new feature the player can, between runs, opt into keeping the same cave. If activated, they will then encounter the same floor layouts, same enemy spawns, and same red chest contents as on their previous attempt.   

- ***Custom item pool***
  Previously, the multiworld item pool consisted entirely of random blue chest items because, well, the permanent checks are blue chests and that's what one would normally get from these. While blue chest items often greatly increase your odds against regular enemies, being able to defeat the Master can be contingent on having an appropriate equipment setup of red chest items (such as Dekar blade) or even enemy drops (such as Hidora rock), most of which cannot normally be obtained from blue chests.
  With the custom item pool option, players now have the freedom to place any cave item into the multiworld itempool for their world.

- ***Enemy floor number, enemy sprite, and enemy movement pattern randomization***
  Experienced players can deduce a lot of information about the opposition they will be facing, for example: Given the current floor number, one can know in advance which of the enemy types will have a chance to spawn on that floor. And when seeing a particular enemy sprite, one can already know which enemy types one might have to face in battle if one were to come in contact with it, and also how that enemy group will move through the dungeon.
  Three new randomization options are added for players who want to spice up their game: one can shuffle which enemy types appear on which floor, one can shuffle which sprite is used by which enemy type, and one can shuffle which movement pattern is used by which sprite.

- ***EXP modifier***
  Just a simple multiplier option to allow people to level up faster. (For technical reasons, the maximum amount of EXP that can be awarded for a single enemy is limited to 65535, but even with the maximum allowed modifier of 500% there are only 6 enemy types in the cave that can reach this cap.)


### Balance change

- ***proportionally adjust chest type distribution to accommodate increased blue chest chance***
  One of the main problems that became apparent in the current version has to do with the distribution of chest contents. The game considers 6 categories, namely: consumable (mostly non-restorative), consumable (restorative), blue chest item, spell, gear, and weapon. Since only blue chests count as multiworld locations, we want to have a mechanism to customize the blue chest chance.
  Given how the chest types are detetermined in game, a naive implementation of an increased blue chest chance causes only the consumable chance to be decreased in return. In practice, this has resulted in some players of worlds with a high blue chest chance struggling (more than usual) to keep their party alive because they were always low on comsumables that restore HP and MP.
  The new algorithm tries to avoid this one-sided effect by having an increase in blue chest chance resulting in a decrease of all other types, calculated in such a way that the relative distribution of the other 5 categories stays (approximately) the same.


### Bug fixes

- ***prevent using party member items if character is already in party***
  This should have been changed at the same time that 6eb00621e39c930f5746f5f3c69a6bc19cd0e84a was made, but oh well... 

- ***fix glitched sprite when opening a chest immediately after receiving an item***
  When opening a chest right after receiving a multiworld item (such that there were two item get animations in the exact same iteration of the game main loop), the item from the chest would display an incorrect sprite in the wrong place. Fixed by cleaning up some relevant memory addresses after getting the multiworld item.

- ***fix death link***
  There was a condition in `deathlink_kill_player` that looked kinda smart (it checked the time against `last_death_link`), but actually wasn't smart at all because `deathlink_kill_player` is executed as an async task and the main thread will update `last_death_link` after creating the task, meaning that whether or not the incoming death link would actually be passed to the game seems to have been up to a race condition. Fixed by simply removing that check.


### Other

- ***add Lufia II Ancient Cave (and SMW) to the network diagram***
  These two games were missing from the SNES sector.

- ***implement get_filler_item_name***
  Place a restorative consumable instead of a completely random item. (Now the only known problem with item links in lufia2ac is... that noone has ever tested item links. But this should be an improvement at least. Anyway, now #1172 can come ;)
  And btw., if you think that the implementation of random selection in this method looks weird, that's because it is indeed weird. (It tries to recreate the algorithm that the game itself uses when it generates a replacement item for a chest that would contain a spell that the party already knows.)

- ***store all options in a dataclass***
  This is basically like using #993 (but without actual support from core). It makes the lufia2ac world code much nicer to maintain because one doesn't have to change 5 different places anymore when adding or renaming an option.

- ***remove master_hp.scale***
  I have to admit: `scale` was a mistake. Never have I seen a single option value cause so many user misconceptions. Some people assume it affects enemies other than the Master; some people assume it affects stats other than HP; and many people will just assume it is a magic option that will somehow counterbalance whatever settings combination they are currently trying to shoot themselves in the foot with.
  On top of that, the `scale` mechanism probably doesn't provide a good user experience even when used for its intended purpose (since having reached floor XY in general doesn't mean you will have the power to deplete XY% of the Masters usual HP; especially given that, due to the randomness of loot, you are never guaranteed to be able to defeat the vanilla Master even when you have cleared 100% of the floors).
  The intended target audience of the `master_hp` option are people who want to fight the Master (and know how to fight it), but also want to lessen (to a degree of their choosing) the harsh dependence on the specific equipment setups that are usually required to win this fight even when having done all 99 floors. They can achieve this by setting the `master_hp` option to a numeric value appropriate for the level of challenge they are seeking. Therefore, nothing of value should be lost by removing the special `scale` value from the `master_hp` option, while at the same time a major source of user confusion will be eliminated.

- ***typing***
  This (combined with the switch to the option dataclass) greatly reduces the typing problems in the lufia2ac world. The remaining typing errors mostly fall into 4 categories:
  1. Lambdas with defaults (which seem to be incorrectly reported as an error due to a mypy bug)
  1. Classmethods that return instances (which could probably be improved using PEP 673 "Self" types, but that would require Python 3.11 as the minimum supported version)
  1. Everything that inherits from TextChoice (which is a typing mess in core)
  1. Everything related to asar.py (which does not have proper typing and lies outside of this project)

## How was this tested?

https://discord.com/channels/731205301247803413/1080852357442707476 and others
This commit is contained in:
el-u
2023-03-20 17:04:57 +01:00
committed by GitHub
parent ff9f563d4a
commit 6d13dc4944
15 changed files with 1032 additions and 442 deletions

View File

@@ -3,13 +3,13 @@ lorom
org $DFFFFD ; expand ROM to 3MB
DB "EOF"
org $80FFD8 ; expand SRAM to 16KB
DB $04 ; overwrites DB $03
org $80FFD8 ; expand SRAM to 32KB
DB $05 ; overwrites DB $03
org $80809A ; patch copy protection
CMP $704000 ; overwrites CMP $702000
CMP $710000 ; overwrites CMP $702000
org $8080A6 ; patch copy protection
CMP $704000 ; overwrites CMP $702000
CMP $710000 ; overwrites CMP $702000
@@ -34,8 +34,8 @@ org $8AF681 ; skip gruberik lexis dialogue
org $8EA349 ; skip ancient cave entrance dialogue
DB $1C,$B0,$01 ; L2SASM JMP $8EA1AD+$01B0
org $8EA384 ; skip ancient cave exit dialogue
DB $1C,$2B,$02 ; L2SASM JMP $8EA1AD+$022B
org $8EA384 ; reset architect mode, skip ancient cave exit dialogue
DB $1B,$E1,$1C,$2B,$02 ; clear flag $E1, L2SASM JMP $8EA1AD+$022B
org $8EA565 ; skip ancient cave leaving dialogue
DB $1C,$E9,$03 ; L2SASM JMP $8EA1AD+$03E9
@@ -108,11 +108,13 @@ Init:
STX $4302 ; A-bus destination address $F02000 (SRAM)
LDA.b #$F0
STA $4304
STX $4305 ; transfer 8kB
LDX.w #$6000
STX $4305 ; transfer 24kB
LDA.b #$01
STA $420B ; start DMA channel 1
; sign expanded SRAM
PHB
TDC
LDA.b #$3F
LDX.w #$8000
LDY.w #$2000
@@ -213,6 +215,8 @@ RX:
JSR SpecialItemGet
SEP #$20
JSL $8EC1EF ; call chest opening routine (but without chest opening animation)
STZ $A7 ; cleanup
JSL $83AB4F ; cleanup
+: SEP #$20
RTS
@@ -268,11 +272,15 @@ SpecialItemUse:
SBC.w #$01B1 ; party member items range from $01B2 to $01B7
BMI +
ASL
TAX
ASL
ASL
ADC.w #$FD2E
STA $09B7 ; set pointer to L2SASM join script
SEP #$20
LDA $8ED8C7,X ; load predefined bitmask with a single bit set
BIT $077E ; check against EV flags $02 to $07 (party member flags)
BNE + ; abort if character already present
LDA $07A9 ; load EV register $11 (party counter)
CMP.b #$03
BPL + ; abort if party full
@@ -593,18 +601,16 @@ FinalFloor:
pushpc
org $8488BB
; DB=$84, x=0, m=0
SEC ; {carry clear = disable this feature, carry set = enable this feature}
JSL Providence ; overwrites LDX.w #$1402 : STX $0A8D
NOP ;
NOP #2
pullpc
Providence:
LDX.w #$1402 ; (overwritten instruction)
STX $0A8D ; (overwritten instruction) add Potion x10
BCC +
LDX.w #$022D ;
LDX.w #$022D
STX $0A8F ; add Providence
+: RTL
RTL
@@ -646,6 +652,142 @@ StartInventory:
; architect mode
pushpc
org $8EA1E7
base = $8EA1AD ; ancient cave entrance script base
DB $15,$E1 : DW .locked-base ; L2SASM JMP .locked if flag $E1 set
DB $08,"Did you like the layout",$03, \
"of the last cave? I can",$03, \
"lock it down and prevent",$03, \
"the cave from changing.",$01
DB $08,"Do you want to lock",$03, \
"the cave layout?",$01
DB $10,$02 : DW .cancel-base,.lock-base ; setup 2 choices: .cancel and .lock
DB $08,"Cancel",$0F,"LOCK IT DOWN!",$0B
.cancel:
DB $4C,$54,$00 ; play sound $54, END
.lock:
DB $5A,$05,$03,$7F,$37,$28,$56,$4C,$6B,$1A,$E1 ; shake, delay $28 f, stop shake, play sound $6B, set flag $E1
.locked:
DB $08,"It's locked down.",$00
warnpc $8EA344
org $839018
; DB=$83, x=0, m=1
JSL ArchitectMode ; overwrites LDA.b #$7E : PHA : PLB
pullpc
ArchitectMode:
; check current mode
LDA $079A
BIT.b #$02
BEQ + ; go to write mode if flag $E1 (i.e., bit $02 in $079A) not set
; read mode (replaying the locked down layout)
JSR ArchitectBlockAddress
LDA $F00000,X ; check if current block is marked as filled
BEQ + ; go to write mode if block unused
TDC
LDA.b #$36
LDY.w #$0521
INX
MVN $7E,$F0 ; restore 55 RNG values from $F00000,X to $7E0521
INX
LDA $F00000,X
STA $0559 ; restore current RNG index from $F00000,X to $7E0559
BRA ++
; write mode (recording the layout)
+: JSR ArchitectClearBlocks
JSR ArchitectBlockAddress
LDA $7FE696
STA $F00000,X ; mark block as used
TDC
LDA.b #$36
LDX.w #$0521
INY
MVN $F0,$7E ; backup 55 RNG values from $7E0521 to $F00000,Y
INY
LDA $7E0559
STA $0000,Y ; backup current RNG index from $7E0559 to $F00000,Y
LDA.b #$7E ; (overwritten instruction) set DB=$7E
PHA ; (overwritten instruction)
PLB ; (overwritten instruction)
++: RTL
ArchitectClearBlocks:
LDA $7FE696 ; read next floor number
CMP $D08015 ; compare initial floor number
BEQ +
BRL ++ ; skip if not initial floor
+: LDA.b #$F0
PHA
PLB
!floor = 1
while !floor < 99 ; mark all blocks as unused
STZ !floor*$40+$6000
!floor #= !floor+1
endwhile
++: RTS
ArchitectBlockAddress:
; calculate target SRAM address
TDC
LDA $7FE696 ; read next floor number
REP #$20
ASL #6
ADC.w #$6000 ; target SRAM address = next_floor * $40 + $6000
TAX
TAY
SEP #$20
RTS
; for architect mode: make red chest behavior for iris treasure replacements independent of current inventory
; by ensuring the same number of RNG calls, no matter if you have the iris item already or not
; (done by prefilling *all* chests first and potentially overwriting one of them with an iris item afterwards,
; instead of checking the iris item first and then potentially filling *one fewer* regular chest)
pushpc
org $8390C9
; DB=$96, x=0, m=1
NOP ; overwrites LDY.w #$0000
BRA + ; go to regular red chest generation
-: ; iris treasure handling happens below
org $839114
; DB=$7F, x=0, m=1
NOP #36 ; overwrites all of providence handling
LDA.b #$83 ; (overwritten instruction from org $8391E9) set DB=$83 for floor layout generation
PHA ; (overwritten instruction from org $8391E9)
PLB ; (overwritten instruction from org $8391E9)
BRL ++ ; go to end
+: LDY.w #$0000 ; (overwritten instruction from org $8390C9) initialize chest index
; red chests are filled below
org $8391E9
; DB=$7F, x=0, m=1
NOP ; overwrites LDA.b #$83 : PHA : PLB
BRL - ; go to iris treasure handling
++: ; floor layout generation happens below
pullpc
; for architect mode: make red chest behavior for spell replacements independent of currently learned spells
; by ensuring the same number of RNG calls, no matter if you have the spell already or not
pushpc
org $8391A6
; DB=$7F, x=0, m=1
JSL SpellRNG ; overwrites LDA.b #$80 : STA $E747,Y
NOP
pullpc
SpellRNG:
LDA.b #$80 ; (overwritten instruction) mark chest item as spell
STA $E747,Y ; (overwritten instruction)
JSL $8082C7 ;
JSL $8082C7 ; advance RNG twice
RTL
; increase variety of red chest gear after B9
pushpc
org $839176
@@ -891,3 +1033,4 @@ pullpc
; $F02800 2 received counter
; $F02802 2 processed counter
; $F02804 inf list of received items
; $F06000 inf architect mode RNG state backups