Decompose fight.go: hit-handler table, weapon/armor helpers (step 7)
The monster special-power switch in attack becomes gameData.hitHandlers (indexed by monster letter); attack splits into monsterHit/monsterMiss; fight gains revealXeroc and heroHits; rollAttacks gains weaponAttack, wieldedRingBonus, and defenderArmor; killed gains killedSpecial. fight.go is complexity-clean. Behavior and RNG call order unchanged.
This commit is contained in:
@@ -137,6 +137,11 @@ type gameData struct {
|
||||
// cases of the sticks.c do_zap switch. A false return aborts the
|
||||
// zap without using a charge (drain life on a too-weak hero).
|
||||
zapHandlers [NumWandTypes]func(g *RogueGame, obj *Object) bool
|
||||
|
||||
// hitHandlers dispatches a monster's special power when its hit
|
||||
// lands, indexed by monster letter - 'A': the cases of the fight.c
|
||||
// attack switch. A true return means the monster removed itself.
|
||||
hitHandlers [26]func(g *RogueGame, mp *Monster, mname string) bool
|
||||
}
|
||||
|
||||
// ripWall is the repeated blank wall line of the tombstone art.
|
||||
@@ -656,6 +661,17 @@ func newGameData() *gameData {
|
||||
WandTeleportTo: (*RogueGame).zapTeleport,
|
||||
WandCancellation: (*RogueGame).zapCancellation,
|
||||
},
|
||||
|
||||
hitHandlers: [26]func(*RogueGame, *Monster, string) bool{
|
||||
0: (*RogueGame).hitAquator, // 'A' - 'A'
|
||||
'F' - 'A': (*RogueGame).hitFlytrap,
|
||||
'I' - 'A': (*RogueGame).hitIceMonster,
|
||||
'L' - 'A': (*RogueGame).hitLeprechaun,
|
||||
'N' - 'A': (*RogueGame).hitNymph,
|
||||
'R' - 'A': (*RogueGame).hitRattlesnake,
|
||||
'V' - 'A': (*RogueGame).hitLifeDrainer,
|
||||
'W' - 'A': (*RogueGame).hitLifeDrainer,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user