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:
@@ -192,7 +192,7 @@ func (g *RogueGame) doorOpen(rp *Room) {
|
||||
}
|
||||
|
||||
// beTrapped makes him pay for stepping on a trap (move.c be_trapped).
|
||||
func (g *RogueGame) beTrapped(tc Coord) int {
|
||||
func (g *RogueGame) beTrapped(tc Coord) TrapKind {
|
||||
p := &g.Player
|
||||
if p.On(Levitating) {
|
||||
return TrapRust // anything that's not a door or teleport
|
||||
@@ -201,7 +201,7 @@ func (g *RogueGame) beTrapped(tc Coord) int {
|
||||
g.Count = 0
|
||||
pp := g.Level.At(tc.Y, tc.X)
|
||||
pp.Ch = Trap
|
||||
tr := int(pp.Flags & FTrapMask)
|
||||
tr := TrapKind(pp.Flags & FTrapMask)
|
||||
pp.Flags.Set(FSeen)
|
||||
switch tr {
|
||||
case TrapDoor:
|
||||
@@ -311,7 +311,7 @@ func (g *RogueGame) rndmove(who *Creature) Coord {
|
||||
break
|
||||
}
|
||||
}
|
||||
if found != nil && found.Which == ScrollScareMonster {
|
||||
if found != nil && found.ScrollKind() == ScrollScareMonster {
|
||||
return who.Pos
|
||||
}
|
||||
}
|
||||
@@ -321,7 +321,7 @@ func (g *RogueGame) rndmove(who *Creature) Coord {
|
||||
// rustArmor rusts the given armor, if it is a legal kind to rust, and we
|
||||
// aren't wearing a magic ring (move.c rust_armor).
|
||||
func (g *RogueGame) rustArmor(arm *Object) {
|
||||
if arm == nil || arm.Type != Armor || arm.Which == ArmorLeather ||
|
||||
if arm == nil || arm.Kind != KindArmor || arm.ArmorKind() == ArmorLeather ||
|
||||
arm.Arm >= 9 {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user