Convert readScroll to a per-scroll handler table (refactor step 7)
The read_scroll switch becomes gameData.readHandlers, indexed by ScrollKind; the five identify scrolls share one handler. The magic mapping cell logic is extracted into revealSpot. Effect order and RNG call sequence unchanged.
This commit is contained in:
@@ -127,6 +127,11 @@ type gameData struct {
|
||||
// the cases of the potions.c quaff switch. The bool is trip — was
|
||||
// the hero hallucinating when the potion went down.
|
||||
quaffHandlers [NumPotionTypes]func(g *RogueGame, trip bool)
|
||||
|
||||
// readHandlers dispatches each scroll kind to its effect method:
|
||||
// the cases of the scrolls.c read_scroll switch. The handler gets
|
||||
// the scroll being read (the identify family needs its subtype).
|
||||
readHandlers [NumScrollTypes]func(g *RogueGame, obj *Object)
|
||||
}
|
||||
|
||||
// ripWall is the repeated blank wall line of the tombstone art.
|
||||
@@ -609,6 +614,27 @@ func newGameData() *gameData {
|
||||
PotionBlindness: (*RogueGame).quaffBlindness,
|
||||
PotionLevitation: (*RogueGame).quaffLevitation,
|
||||
},
|
||||
|
||||
readHandlers: [NumScrollTypes]func(*RogueGame, *Object){
|
||||
ScrollMonsterConfusion: (*RogueGame).readMonsterConfusion,
|
||||
ScrollMagicMapping: (*RogueGame).readMagicMapping,
|
||||
ScrollHoldMonster: (*RogueGame).readHoldMonster,
|
||||
ScrollSleep: (*RogueGame).readSleep,
|
||||
ScrollEnchantArmor: (*RogueGame).readEnchantArmor,
|
||||
ScrollIdentifyPotion: (*RogueGame).readIdentify,
|
||||
ScrollIdentifyScroll: (*RogueGame).readIdentify,
|
||||
ScrollIdentifyWeapon: (*RogueGame).readIdentify,
|
||||
ScrollIdentifyArmor: (*RogueGame).readIdentify,
|
||||
ScrollIdentifyRingOrStick: (*RogueGame).readIdentify,
|
||||
ScrollScareMonster: (*RogueGame).readScareMonster,
|
||||
ScrollFoodDetection: (*RogueGame).readFoodDetection,
|
||||
ScrollTeleportation: (*RogueGame).readTeleportation,
|
||||
ScrollEnchantWeapon: (*RogueGame).readEnchantWeapon,
|
||||
ScrollCreateMonster: (*RogueGame).readCreateMonster,
|
||||
ScrollRemoveCurse: (*RogueGame).readRemoveCurse,
|
||||
ScrollAggravateMonsters: (*RogueGame).readAggravateMonsters,
|
||||
ScrollProtectArmor: (*RogueGame).readProtectArmor,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user