gochecknoglobals: all 37 package-level tables consolidated into the gameData struct (game/tables.go), built by newGameData() and carried on RogueGame as g.data (set in NewGame and Restore). ObjectKind Glyph()/objectKindForGlyph are now switches; the table-reading subtype Stringer methods are gone; isMagic is a RogueGame method. goconst: repeated words named (potionName/scrollName/ringName/goldName in object.go, wandName/staffName in sticks.go, ripWall in tables.go). exhaustive, testpackage: disabled in .golangci.yml with sneak's approval (2026-07-07). Also reverts misspell's silent corruption of the "ther" scroll-name syllable (it had become "there", changing generated scroll names vs C). Remaining red: cyclop/gocognit/nestif until refactor step 7; mnd awaits a ruling. TODO.md rotated; MEMORY.md lint notes updated.
188 lines
5.0 KiB
Go
188 lines
5.0 KiB
Go
package game
|
|
|
|
// ObjectKind is the category of an item. In C this was the o_type byte,
|
|
// which doubled as the character drawn on the map; the port separates the
|
|
// category (ObjectKind) from its display character (Glyph).
|
|
type ObjectKind int
|
|
|
|
// Item categories.
|
|
const (
|
|
KindNone ObjectKind = iota
|
|
KindPotion
|
|
KindScroll
|
|
KindFood
|
|
KindWeapon
|
|
KindArmor
|
|
KindRing
|
|
KindWand // a "stick": wand or staff
|
|
KindAmulet
|
|
KindGold
|
|
)
|
|
|
|
// Prompt-filter pseudo-kinds for item selection (rogue.h CALLABLE and
|
|
// R_OR_S): they never appear on an Object, only as getItem filters.
|
|
const (
|
|
KindCallable ObjectKind = -1
|
|
KindRingOrStick ObjectKind = -2
|
|
)
|
|
|
|
// Category words shared by ObjectKind.String, the discovery list, and the
|
|
// ident table. (The bare identifiers Potion, Scroll, Ring, Gold are the
|
|
// glyph byte constants.)
|
|
const (
|
|
potionName = "potion"
|
|
scrollName = "scroll"
|
|
ringName = "ring"
|
|
goldName = "gold"
|
|
)
|
|
|
|
// Glyph returns the map/display character for this kind of object.
|
|
func (k ObjectKind) Glyph() byte {
|
|
switch k {
|
|
case KindPotion:
|
|
return Potion
|
|
case KindScroll:
|
|
return Scroll
|
|
case KindFood:
|
|
return Food
|
|
case KindWeapon:
|
|
return Weapon
|
|
case KindArmor:
|
|
return Armor
|
|
case KindRing:
|
|
return Ring
|
|
case KindWand:
|
|
return Stick
|
|
case KindAmulet:
|
|
return Amulet
|
|
case KindGold:
|
|
return Gold
|
|
}
|
|
|
|
return ' '
|
|
}
|
|
|
|
// String names the category the way the C type_name() did.
|
|
func (k ObjectKind) String() string {
|
|
switch k {
|
|
case KindPotion:
|
|
return potionName
|
|
case KindScroll:
|
|
return scrollName
|
|
case KindFood:
|
|
return "food"
|
|
case KindWeapon:
|
|
return "weapon"
|
|
case KindArmor:
|
|
return "suit of armor"
|
|
case KindRing:
|
|
return ringName
|
|
case KindWand:
|
|
return "wand or staff"
|
|
case KindAmulet:
|
|
return "amulet"
|
|
case KindGold:
|
|
return goldName
|
|
case KindRingOrStick:
|
|
return "ring, wand or staff"
|
|
}
|
|
|
|
return "bizarre thing"
|
|
}
|
|
|
|
// objectKindForGlyph is the reverse of Glyph: what category of item does a
|
|
// map character denote. Returns KindNone for non-item characters.
|
|
func objectKindForGlyph(ch byte) ObjectKind {
|
|
switch ch {
|
|
case Potion:
|
|
return KindPotion
|
|
case Scroll:
|
|
return KindScroll
|
|
case Food:
|
|
return KindFood
|
|
case Weapon:
|
|
return KindWeapon
|
|
case Armor:
|
|
return KindArmor
|
|
case Ring:
|
|
return KindRing
|
|
case Stick:
|
|
return KindWand
|
|
case Amulet:
|
|
return KindAmulet
|
|
case Gold:
|
|
return KindGold
|
|
}
|
|
|
|
return KindNone
|
|
}
|
|
|
|
// MergesInPack reports whether picking up another of this kind merges into
|
|
// an existing pack entry's count (rogue.h ISMULT).
|
|
func (k ObjectKind) MergesInPack() bool {
|
|
return k == KindPotion || k == KindScroll || k == KindFood
|
|
}
|
|
|
|
// Object is the _o arm of the C THING union: anything that can lie on the
|
|
// floor or ride in a pack.
|
|
type Object struct {
|
|
Kind ObjectKind // what kind of object it is (o_type)
|
|
Pos Coord // where it lives on the screen
|
|
Text string // what it says if you read it
|
|
Launch WeaponKind // what you need to launch it (noWeapon if none)
|
|
PackCh byte // what character it is in the pack
|
|
Damage DiceSpec // damage if used like sword
|
|
HurlDmg DiceSpec // damage if thrown
|
|
Count int // count for plural objects
|
|
Which int // which object of a type it is (index for the Kind's table)
|
|
HPlus int // plusses to hit
|
|
DPlus int // plusses to damage
|
|
ArmorClass int // armor protection (armor only)
|
|
Charges int // charges remaining (wands and staffs only)
|
|
GoldValue int // worth (gold piles only)
|
|
Bonus int // magic bonus (rings only: protection, add strength, ...)
|
|
Flags ObjFlags
|
|
Group int // group number for this object
|
|
Label string // label for object
|
|
}
|
|
|
|
// newObject is list.c new_item() for objects: a zeroed Object with the
|
|
// same non-zero defaults the C code relies on.
|
|
func newObject() *Object {
|
|
return &Object{Launch: noWeapon}
|
|
}
|
|
|
|
// PotionKind returns Which as a potion kind; valid only for KindPotion.
|
|
func (o *Object) PotionKind() PotionKind { return PotionKind(o.Which) }
|
|
|
|
// ScrollKind returns Which as a scroll kind; valid only for KindScroll.
|
|
func (o *Object) ScrollKind() ScrollKind { return ScrollKind(o.Which) }
|
|
|
|
// RingKind returns Which as a ring kind; valid only for KindRing.
|
|
func (o *Object) RingKind() RingKind { return RingKind(o.Which) }
|
|
|
|
// WandKind returns Which as a wand kind; valid only for KindWand.
|
|
func (o *Object) WandKind() WandKind { return WandKind(o.Which) }
|
|
|
|
// WeaponKind returns Which as a weapon kind; valid only for KindWeapon.
|
|
func (o *Object) WeaponKind() WeaponKind { return WeaponKind(o.Which) }
|
|
|
|
// ArmorKind returns Which as an armor kind; valid only for KindArmor.
|
|
func (o *Object) ArmorKind() ArmorKind { return ArmorKind(o.Which) }
|
|
|
|
// attachObj is list.c attach(): push item onto the front of a list.
|
|
func attachObj(list *[]*Object, item *Object) {
|
|
*list = append([]*Object{item}, *list...)
|
|
}
|
|
|
|
// detachObj is list.c detach(): remove item (by identity) from a list.
|
|
func detachObj(list *[]*Object, item *Object) {
|
|
for i, o := range *list {
|
|
if o == item {
|
|
*list = append((*list)[:i], (*list)[i+1:]...)
|
|
|
|
return
|
|
}
|
|
}
|
|
}
|