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

@@ -149,7 +149,7 @@ over:
}
if found != nil {
if !g.levitCheck() {
g.pickUp(found.Type)
g.pickUp(found.Kind.Glyph())
}
} else {
if !g.Options.Terse {
@@ -409,7 +409,7 @@ func (g *RogueGame) wizardCommand(ch byte) {
case CTRL('X'):
g.turnSee(p.On(SenseMonsters))
case CTRL('~'):
if item := g.getItem("charge", int(Stick)); item != nil {
if item := g.getItem("charge", KindWand); item != nil {
item.SetCharges(10000)
}
case CTRL('I'):
@@ -425,8 +425,8 @@ func (g *RogueGame) wizardCommand(ch byte) {
p.CurWeapon = obj
// And his suit of armor
obj = newObject()
obj.Type = Armor
obj.Which = ArmorPlateMail
obj.Kind = KindArmor
obj.Which = int(ArmorPlateMail)
obj.Arm = -5
obj.Flags.Set(Known)
obj.Count = 1
@@ -671,7 +671,7 @@ func (g *RogueGame) levitCheck() bool {
// call allows a user to call a potion, scroll, or ring something
// (command.c call).
func (g *RogueGame) call() {
obj := g.getItem("call", Callable)
obj := g.getItem("call", KindCallable)
// Make certain that it is something that we want to name
if obj == nil {
return
@@ -681,20 +681,20 @@ func (g *RogueGame) call() {
var know *bool
var guess *string
it := &g.Items
switch obj.Type {
case Ring:
switch obj.Kind {
case KindRing:
op = &it.Rings[obj.Which]
elsewise = it.RingStones[obj.Which]
case Potion:
case KindPotion:
op = &it.Potions[obj.Which]
elsewise = it.PotColors[obj.Which]
case Scroll:
case KindScroll:
op = &it.Scrolls[obj.Which]
elsewise = it.ScrNames[obj.Which]
case Stick:
case KindWand:
op = &it.Sticks[obj.Which]
elsewise = it.WandMade[obj.Which]
case Food:
case KindFood:
g.msg("you can't call that anything")
return
default: