Convert quaff to a per-potion handler table (refactor step 7)
The quaff switch becomes gameData.quaffHandlers, a method-expression table indexed by PotionKind; each case body moved verbatim into a quaff* method. Effect order and RNG call sequence unchanged.
This commit is contained in:
@@ -122,6 +122,11 @@ type gameData struct {
|
||||
|
||||
// scoreReasons is the rip.c reason[] scoreboard strings.
|
||||
scoreReasons [4]string
|
||||
|
||||
// quaffHandlers dispatches each potion kind to its effect method:
|
||||
// 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)
|
||||
}
|
||||
|
||||
// ripWall is the repeated blank wall line of the tombstone art.
|
||||
@@ -587,6 +592,23 @@ func newGameData() *gameData {
|
||||
"A total winner",
|
||||
"killed with Amulet",
|
||||
},
|
||||
|
||||
quaffHandlers: [NumPotionTypes]func(*RogueGame, bool){
|
||||
PotionConfusion: (*RogueGame).quaffConfusion,
|
||||
PotionLSD: (*RogueGame).quaffLSD,
|
||||
PotionPoison: (*RogueGame).quaffPoison,
|
||||
PotionGainStrength: (*RogueGame).quaffGainStrength,
|
||||
PotionSeeInvisible: (*RogueGame).quaffSeeInvisible,
|
||||
PotionHealing: (*RogueGame).quaffHealing,
|
||||
PotionDetectMonsters: (*RogueGame).quaffDetectMonsters,
|
||||
PotionDetectMagic: (*RogueGame).quaffDetectMagic,
|
||||
PotionRaiseLevel: (*RogueGame).quaffRaiseLevel,
|
||||
PotionExtraHealing: (*RogueGame).quaffExtraHealing,
|
||||
PotionHaste: (*RogueGame).quaffHaste,
|
||||
PotionRestoreStrength: (*RogueGame).quaffRestoreStrength,
|
||||
PotionBlindness: (*RogueGame).quaffBlindness,
|
||||
PotionLevitation: (*RogueGame).quaffLevitation,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user