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:
2026-07-06 22:00:43 +02:00
parent 626f8c5a7d
commit b940cfc41f
27 changed files with 426 additions and 259 deletions

View File

@@ -7,12 +7,12 @@ import "fmt"
// ringOn puts a ring on a hand (rings.c ring_on).
func (g *RogueGame) ringOn() {
p := &g.Player
obj := g.getItem("put on", int(Ring))
obj := g.getItem("put on", KindRing)
// Make certain that it is something that we want to wear
if obj == nil {
return
}
if obj.Type != Ring {
if obj.Kind != KindRing {
if !g.Options.Terse {
g.msg("it would be difficult to wrap that around a finger")
} else {
@@ -47,7 +47,7 @@ func (g *RogueGame) ringOn() {
p.CurRing[ring] = obj
// Calculate the effect it has on the poor guy.
switch obj.Which {
switch obj.RingKind() {
case RingAddStrength:
g.chgStr(obj.Arm)
case RingSeeInvisible:
@@ -147,7 +147,7 @@ func (g *RogueGame) ringEat(hand int) int {
if ring == nil {
return 0
}
eat := ringUses[ring.Which]
eat := ringUses[ring.RingKind()]
if eat < 0 {
if g.rnd(-eat) == 0 {
eat = 1
@@ -155,7 +155,7 @@ func (g *RogueGame) ringEat(hand int) int {
eat = 0
}
}
if ring.Which == RingSlowDigestion {
if ring.RingKind() == RingSlowDigestion {
eat = -eat
}
return eat
@@ -166,7 +166,7 @@ func ringNum(g *RogueGame, obj *Object) string {
if !obj.Flags.Has(Known) {
return ""
}
switch obj.Which {
switch obj.RingKind() {
case RingProtection, RingAddStrength, RingIncreaseDamage, RingDexterity:
return fmt.Sprintf(" [%s]", num(obj.Arm, 0, Ring))
}