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

@@ -13,13 +13,13 @@ func (g *RogueGame) initPlayer() {
p.FoodLeft = HungerTime
// Give him some food
obj := newObject()
obj.Type = Food
obj.Kind = KindFood
obj.Count = 1
g.addPack(obj, true)
// And his suit of armor
obj = newObject()
obj.Type = Armor
obj.Which = ArmorRingMail
obj.Kind = KindArmor
obj.Which = int(ArmorRingMail)
obj.Arm = aClass[ArmorRingMail] - 1
obj.Flags.Set(Known)
obj.Count = 1
@@ -51,7 +51,7 @@ func (g *RogueGame) initPlayer() {
// (init.c init_colors).
func (g *RogueGame) initColors() {
used := make([]bool, len(rainbow))
for i := 0; i < NumPotionTypes; i++ {
for i := PotionKind(0); i < NumPotionTypes; i++ {
var j int
for {
j = g.rnd(len(rainbow))
@@ -66,7 +66,7 @@ func (g *RogueGame) initColors() {
// initNames generates the names of the various scrolls (init.c init_names).
func (g *RogueGame) initNames() {
for i := 0; i < NumScrollTypes; i++ {
for i := ScrollKind(0); i < NumScrollTypes; i++ {
var cp strings.Builder
nwords := g.rnd(3) + 2
for ; nwords > 0; nwords-- {
@@ -88,7 +88,7 @@ func (g *RogueGame) initNames() {
// (init.c init_stones).
func (g *RogueGame) initStones() {
used := make([]bool, len(stoneTable))
for i := 0; i < NumRingTypes; i++ {
for i := RingKind(0); i < NumRingTypes; i++ {
var j int
for {
j = g.rnd(len(stoneTable))
@@ -107,7 +107,7 @@ func (g *RogueGame) initStones() {
func (g *RogueGame) initMaterials() {
used := make([]bool, len(woods))
metused := make([]bool, len(metals))
for i := 0; i < NumWandTypes; i++ {
for i := WandKind(0); i < NumWandTypes; i++ {
var str string
for {
if g.rnd(2) == 0 {