Give item categories and subtypes real types (refactor step 2)
ObjectKind separates what an item is from how it draws: Object.Type (a byte that doubled as the map character) becomes Kind ObjectKind, with Glyph() producing the display character and objectKindForGlyph converting back at the map boundary. KindWand covers the C 'stick' category. The magic-missile bolt uses KindGold, matching C's literal o_type='*' trick, with a comment. PotionKind, ScrollKind, RingKind, WandKind, WeaponKind, ArmorKind and TrapKind are now iota enums with Stringer (names come from the base info tables); Object gains typed accessors (obj.RingKind(), ...) and Launch is typed WeaponKind. beTrapped returns TrapKind. The getItem/inventory/whatis prompt filters take ObjectKind, with KindCallable/KindRingOrStick replacing the C CALLABLE/R_OR_S sentinels; wizard.c's type_name table is subsumed by ObjectKind.String(). IsRing/IsWearing/initWeapon/doPot signatures are typed accordingly. The save format version becomes 5.4.4-go2: the gob field rename would otherwise silently zero Kind when reading old saves. No behavior change; full suite green.
This commit is contained in:
@@ -2,25 +2,25 @@ package game
|
||||
|
||||
// scrolls.c — read a scroll and let it happen.
|
||||
|
||||
// idType maps identify scrolls to the type they identify (scrolls.c
|
||||
// static id_type).
|
||||
var idType = [ScrollIdentifyRingOrStick + 1]int{
|
||||
ScrollIdentifyPotion: int(Potion),
|
||||
ScrollIdentifyScroll: int(Scroll),
|
||||
ScrollIdentifyWeapon: int(Weapon),
|
||||
ScrollIdentifyArmor: int(Armor),
|
||||
ScrollIdentifyRingOrStick: RorS,
|
||||
// idType maps identify scrolls to the kind of item they identify
|
||||
// (scrolls.c static id_type).
|
||||
var idType = [ScrollIdentifyRingOrStick + 1]ObjectKind{
|
||||
ScrollIdentifyPotion: KindPotion,
|
||||
ScrollIdentifyScroll: KindScroll,
|
||||
ScrollIdentifyWeapon: KindWeapon,
|
||||
ScrollIdentifyArmor: KindArmor,
|
||||
ScrollIdentifyRingOrStick: KindRingOrStick,
|
||||
}
|
||||
|
||||
// readScroll reads a scroll from the pack and does the appropriate thing
|
||||
// (scrolls.c read_scroll).
|
||||
func (g *RogueGame) readScroll() {
|
||||
p := &g.Player
|
||||
obj := g.getItem("read", int(Scroll))
|
||||
obj := g.getItem("read", KindScroll)
|
||||
if obj == nil {
|
||||
return
|
||||
}
|
||||
if obj.Type != Scroll {
|
||||
if obj.Kind != KindScroll {
|
||||
if !g.Options.Terse {
|
||||
g.msg("there is nothing on it to read")
|
||||
} else {
|
||||
@@ -35,7 +35,7 @@ func (g *RogueGame) readScroll() {
|
||||
// Get rid of the thing
|
||||
g.leavePack(obj, false, false)
|
||||
|
||||
switch obj.Which {
|
||||
switch obj.ScrollKind() {
|
||||
case ScrollMonsterConfusion:
|
||||
// Scroll of monster confusion. Give him that power.
|
||||
p.Flags.Set(CanConfuse)
|
||||
@@ -99,7 +99,7 @@ func (g *RogueGame) readScroll() {
|
||||
// Or anything else nasty
|
||||
if ch := g.Level.VisibleChar(y, x); stepOk(ch) {
|
||||
if ch == Scroll {
|
||||
if fo := g.findObj(y, x); fo != nil && fo.Which == ScrollScareMonster {
|
||||
if fo := g.findObj(y, x); fo != nil && fo.ScrollKind() == ScrollScareMonster {
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func (g *RogueGame) readScroll() {
|
||||
// Identify, let him figure something out
|
||||
g.Items.Scrolls[obj.Which].Know = true
|
||||
g.msg("this scroll is an %s scroll", g.Items.Scrolls[obj.Which].Name)
|
||||
g.whatis(true, idType[obj.Which])
|
||||
g.whatis(true, idType[obj.ScrollKind()])
|
||||
case ScrollMagicMapping:
|
||||
// Scroll of magic mapping.
|
||||
g.Items.Scrolls[ScrollMagicMapping].Know = true
|
||||
@@ -192,7 +192,7 @@ func (g *RogueGame) readScroll() {
|
||||
found := false
|
||||
g.scr.Hw.Clear()
|
||||
for _, fo := range g.Level.Objects {
|
||||
if fo.Type == Food {
|
||||
if fo.Kind == KindFood {
|
||||
found = true
|
||||
g.scr.Hw.MvAddCh(fo.Pos.Y, fo.Pos.X, Food)
|
||||
}
|
||||
@@ -211,7 +211,7 @@ func (g *RogueGame) readScroll() {
|
||||
g.Items.Scrolls[ScrollTeleportation].Know = true
|
||||
}
|
||||
case ScrollEnchantWeapon:
|
||||
if p.CurWeapon == nil || p.CurWeapon.Type != Weapon {
|
||||
if p.CurWeapon == nil || p.CurWeapon.Kind != KindWeapon {
|
||||
g.msg("you feel a strange sense of loss")
|
||||
} else {
|
||||
p.CurWeapon.Flags.Clear(Cursed)
|
||||
|
||||
Reference in New Issue
Block a user