From 6d798c56edc2b40bf5715802afc700eb0b08fd1f Mon Sep 17 00:00:00 2001 From: sneak Date: Tue, 7 Jul 2026 02:31:38 +0200 Subject: [PATCH] Rename item-subsystem methods (refactor step 5, items) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getItem→promptPackItem now returns (obj, ok) instead of a nil-signaling pointer; invName→inventoryName; doPot→applyPotionFuse. C breadcrumbs kept. Behavior unchanged; suite green. --- game/armor.go | 8 ++++---- game/command.go | 8 ++++---- game/fight.go | 2 +- game/misc.go | 4 ++-- game/pack.go | 27 ++++++++++++++------------- game/potions.go | 20 ++++++++++---------- game/rings.go | 8 ++++---- game/rip.go | 2 +- game/scrolls.go | 4 ++-- game/sticks.go | 4 ++-- game/tables.go | 2 +- game/things.go | 10 +++++----- game/weapons.go | 10 +++++----- game/wizard.go | 4 ++-- 14 files changed, 57 insertions(+), 56 deletions(-) diff --git a/game/armor.go b/game/armor.go index c57aea7..d8f71bc 100644 --- a/game/armor.go +++ b/game/armor.go @@ -6,8 +6,8 @@ package game func (g *RogueGame) wear() { p := &g.Player - obj := g.getItem("wear", KindArmor) - if obj == nil { + obj, ok := g.promptPackItem("wear", KindArmor) + if !ok { return } @@ -32,7 +32,7 @@ func (g *RogueGame) wear() { g.wasteTime() obj.Flags.Set(Known) - sp := g.invName(obj, true) + sp := g.inventoryName(obj, true) p.CurArmor = obj if !g.Options.Terse { @@ -70,7 +70,7 @@ func (g *RogueGame) takeOff() { g.addmsgf("you used to be") } - g.msg(" wearing %c) %s", obj.PackCh, g.invName(obj, true)) + g.msg(" wearing %c) %s", obj.PackCh, g.inventoryName(obj, true)) } // wasteTime does nothing but let other things happen (armor.c waste_time). diff --git a/game/command.go b/game/command.go index 70e1349..9ecb7d3 100644 --- a/game/command.go +++ b/game/command.go @@ -453,7 +453,7 @@ func (g *RogueGame) wizardCommand(ch byte) { case CTRL('X'): g.turnSee(p.On(SenseMonsters)) case CTRL('~'): - if item := g.getItem("charge", KindWand); item != nil { + if item, ok := g.promptPackItem("charge", KindWand); ok { item.Charges = 10000 } case CTRL('I'): @@ -738,9 +738,9 @@ 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", KindCallable) + obj, ok := g.promptPackItem("call", KindCallable) // Make certain that it is something that we want to name - if obj == nil { + if !ok { return } @@ -820,7 +820,7 @@ func (g *RogueGame) current(cur *Object, how, where string) { } g.InvDescribe = false - g.addmsgf("%c) %s", cur.PackCh, g.invName(cur, true)) + g.addmsgf("%c) %s", cur.PackCh, g.inventoryName(cur, true)) g.InvDescribe = true if where != "" { diff --git a/game/fight.go b/game/fight.go index b607a05..6c0514c 100644 --- a/game/fight.go +++ b/game/fight.go @@ -290,7 +290,7 @@ func (g *RogueGame) attack(mp *Monster) int { removed = true g.leavePack(steal, false, false) - g.msg("she stole %s!", g.invName(steal, true)) + g.msg("she stole %s!", g.inventoryName(steal, true)) } } } diff --git a/game/misc.go b/game/misc.go index 2390efe..67c1d9e 100644 --- a/game/misc.go +++ b/game/misc.go @@ -236,8 +236,8 @@ func (g *RogueGame) findObj(y, x int) *Object { // eat lets her try to eat something (misc.c eat). func (g *RogueGame) eat() { - obj := g.getItem("eat", KindFood) - if obj == nil { + obj, ok := g.promptPackItem("eat", KindFood) + if !ok { return } diff --git a/game/pack.go b/game/pack.go index 4e2727f..6120c3e 100644 --- a/game/pack.go +++ b/game/pack.go @@ -137,7 +137,7 @@ func (g *RogueGame) addPack(obj *Object, silent bool) { g.addmsgf("you now have ") } - g.msg("%s (%c)", g.invName(obj, !g.Options.Terse), obj.PackCh) + g.msg("%s (%c)", g.inventoryName(obj, !g.Options.Terse), obj.PackCh) } } @@ -236,7 +236,7 @@ func (g *RogueGame) inventory(list []*Object, kind ObjectKind) bool { g.NObjs++ g.Msgs.MsgEsc = true - line := string(item.PackCh) + ") " + g.invName(item, false) + line := string(item.PackCh) + ") " + g.inventoryName(item, false) if g.addLine("%s", line) == Escape { g.Msgs.MsgEsc = false g.msg("") @@ -323,7 +323,7 @@ func (g *RogueGame) moveMsg(obj *Object) { g.addmsgf("you ") } - g.msg("moved onto %s", g.invName(obj, true)) + g.msg("moved onto %s", g.inventoryName(obj, true)) } // pickyInven allows the player to inventory a single item (pack.c @@ -337,7 +337,7 @@ func (g *RogueGame) pickyInven() { } if len(p.Pack) == 1 { - g.msg("a) %s", g.invName(p.Pack[0], false)) + g.msg("a) %s", g.inventoryName(p.Pack[0], false)) return } @@ -354,7 +354,7 @@ func (g *RogueGame) pickyInven() { for _, obj := range p.Pack { if mch == obj.PackCh { - g.msg("%c) %s", mch, g.invName(obj, false)) + g.msg("%c) %s", mch, g.inventoryName(obj, false)) return } @@ -363,23 +363,24 @@ func (g *RogueGame) pickyInven() { g.msg("'%s' not in pack", unctrl(mch)) } -// getItem picks something out of a pack for a purpose (pack.c get_item). -func (g *RogueGame) getItem(purpose string, kind ObjectKind) *Object { +// promptPackItem picks something out of a pack for a purpose (pack.c +// get_item); ok reports whether the player chose an item. +func (g *RogueGame) promptPackItem(purpose string, kind ObjectKind) (obj *Object, ok bool) { p := &g.Player if len(p.Pack) == 0 { g.msg("you aren't carrying anything") - return nil + return nil, false } if g.Again { if g.LastPick != nil { - return g.LastPick + return g.LastPick, true } g.msg("you ran out") - return nil + return nil, false } for { @@ -402,7 +403,7 @@ func (g *RogueGame) getItem(purpose string, kind ObjectKind) *Object { g.After = false g.msg("") - return nil + return nil, false } g.NObjs = 1 // normal case: person types one char @@ -411,7 +412,7 @@ func (g *RogueGame) getItem(purpose string, kind ObjectKind) *Object { if !g.inventory(p.Pack, kind) { g.After = false - return nil + return nil, false } continue @@ -419,7 +420,7 @@ func (g *RogueGame) getItem(purpose string, kind ObjectKind) *Object { for _, obj := range p.Pack { if obj.PackCh == ch { - return obj + return obj, true } } diff --git a/game/potions.go b/game/potions.go index 64bf973..bf6ffc3 100644 --- a/game/potions.go +++ b/game/potions.go @@ -16,9 +16,9 @@ type pact struct { // quaff drinks a potion from the pack (potions.c quaff). func (g *RogueGame) quaff() { p := &g.Player - obj := g.getItem("quaff", KindPotion) + obj, ok := g.promptPackItem("quaff", KindPotion) // Make certain that it is something that we want to drink - if obj == nil { + if !ok { return } @@ -43,7 +43,7 @@ func (g *RogueGame) quaff() { switch obj.PotionKind() { case PotionConfusion: - g.doPot(PotionConfusion, !trip) + g.applyPotionFuse(PotionConfusion, !trip) case PotionPoison: g.Items.Potions[PotionPoison].Know = true if p.IsWearing(RingSustainStrength) { @@ -118,11 +118,11 @@ func (g *RogueGame) quaff() { g.SeenStairs = g.seenStairs() } - g.doPot(PotionLSD, true) + g.applyPotionFuse(PotionLSD, true) case PotionSeeInvisible: show := p.On(CanSeeInvisible) - g.doPot(PotionSeeInvisible, false) + g.applyPotionFuse(PotionSeeInvisible, false) if !show { g.invisOn() @@ -177,9 +177,9 @@ func (g *RogueGame) quaff() { g.msg("hey, this tastes great. It make you feel warm all over") case PotionBlindness: - g.doPot(PotionBlindness, true) + g.applyPotionFuse(PotionBlindness, true) case PotionLevitation: - g.doPot(PotionLevitation, true) + g.applyPotionFuse(PotionLevitation, true) } g.status() @@ -194,9 +194,9 @@ func (g *RogueGame) raiseLevel() { g.checkLevel() } -// doPot does a potion with standard setup: it uses a fuse and turns on a -// flag (potions.c do_pot). -func (g *RogueGame) doPot(kind PotionKind, knowit bool) { +// applyPotionFuse does a potion with standard setup: it uses a fuse and +// turns on a flag (potions.c do_pot). +func (g *RogueGame) applyPotionFuse(kind PotionKind, knowit bool) { pp := &g.data.pActions[kind] if !g.Items.Potions[kind].Know { g.Items.Potions[kind].Know = knowit diff --git a/game/rings.go b/game/rings.go index de988ae..c62a00f 100644 --- a/game/rings.go +++ b/game/rings.go @@ -7,9 +7,9 @@ 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", KindRing) + obj, ok := g.promptPackItem("put on", KindRing) // Make certain that it is something that we want to wear - if obj == nil { + if !ok { return } @@ -65,7 +65,7 @@ func (g *RogueGame) ringOn() { g.addmsgf("you are now wearing ") } - g.msg("%s (%c)", g.invName(obj, true), obj.PackCh) + g.msg("%s (%c)", g.inventoryName(obj, true), obj.PackCh) } // ringOff takes off a ring (rings.c ring_off). @@ -103,7 +103,7 @@ func (g *RogueGame) ringOff() { } if g.dropCheck(obj) { - g.msg("was wearing %s(%c)", g.invName(obj, true), obj.PackCh) + g.msg("was wearing %s(%c)", g.inventoryName(obj, true), obj.PackCh) } } diff --git a/game/rip.go b/game/rip.go index 6c6f31e..5e504cb 100644 --- a/game/rip.go +++ b/game/rip.go @@ -189,7 +189,7 @@ func (g *RogueGame) totalWinner() { } g.scr.Std.MvPrintwf(line, 0, "%c) %5d %s", obj.PackCh, worth, - g.invName(obj, false)) + g.inventoryName(obj, false)) line++ p.Purse += worth } diff --git a/game/scrolls.go b/game/scrolls.go index fbcdfd1..d73eb9c 100644 --- a/game/scrolls.go +++ b/game/scrolls.go @@ -7,8 +7,8 @@ package game func (g *RogueGame) readScroll() { p := &g.Player - obj := g.getItem("read", KindScroll) - if obj == nil { + obj, ok := g.promptPackItem("read", KindScroll) + if !ok { return } diff --git a/game/sticks.go b/game/sticks.go index 20ac1d6..44a6710 100644 --- a/game/sticks.go +++ b/game/sticks.go @@ -14,8 +14,8 @@ const ( func (g *RogueGame) doZap() { p := &g.Player - obj := g.getItem("zap with", KindWand) - if obj == nil { + obj, ok := g.promptPackItem("zap with", KindWand) + if !ok { return } diff --git a/game/tables.go b/game/tables.go index 1bb644c..bb2c4fc 100644 --- a/game/tables.go +++ b/game/tables.go @@ -94,7 +94,7 @@ type gameData struct { initWeaps [NumWeaponTypes]weaponSetup // pActions is potions.c p_actions[]. The P_SEEINVIS message is dynamic - // (it names the fruit) and is computed in doPot. + // (it names the fruit) and is computed in applyPotionFuse. pActions [NumPotionTypes]pact // idType maps identify scrolls to the kind of item they identify diff --git a/game/things.go b/game/things.go index a74173f..d0186c0 100644 --- a/game/things.go +++ b/game/things.go @@ -9,7 +9,7 @@ import ( // invName returns the name of something as it would appear in an inventory // (things.c inv_name). -func (g *RogueGame) invName(obj *Object, drop bool) string { +func (g *RogueGame) inventoryName(obj *Object, drop bool) string { var pb strings.Builder which := obj.Which @@ -142,8 +142,8 @@ func (g *RogueGame) dropIt() { return } - obj := g.getItem("drop", KindNone) - if obj == nil { + obj, ok := g.promptPackItem("drop", KindNone) + if !ok { return } @@ -162,7 +162,7 @@ func (g *RogueGame) dropIt() { g.HasAmulet = false } - g.msg("dropped %s", g.invName(obj, true)) + g.msg("dropped %s", g.inventoryName(obj, true)) } // dropCheck does special checks for dropping or unwielding|unwearing| @@ -392,7 +392,7 @@ func (g *RogueGame) printDisc(typ byte) { if info[order[i]].Know || info[order[i]].Guess != "" { obj.Kind = objectKindForGlyph(typ) obj.Which = order[i] - g.addLine("%s", g.invName(&obj, false)) + g.addLine("%s", g.inventoryName(&obj, false)) numFound++ } diff --git a/game/weapons.go b/game/weapons.go index 8158a51..515a4b6 100644 --- a/game/weapons.go +++ b/game/weapons.go @@ -9,8 +9,8 @@ const noWeapon WeaponKind = -1 // missile fires a missile in a given direction (weapons.c missile). func (g *RogueGame) missile(ydelta, xdelta int) { // Get which thing we are hurling - obj := g.getItem("throw", KindWeapon) - if obj == nil { + obj, ok := g.promptPackItem("throw", KindWeapon) + if !ok { return } @@ -113,8 +113,8 @@ func (g *RogueGame) wield() { p.CurWeapon = oweapon - obj := g.getItem("wield", KindWeapon) - if obj == nil { + obj, ok := g.promptPackItem("wield", KindWeapon) + if !ok { g.After = false return @@ -133,7 +133,7 @@ func (g *RogueGame) wield() { return } - sp := g.invName(obj, true) + sp := g.inventoryName(obj, true) p.CurWeapon = obj if !g.Options.Terse { diff --git a/game/wizard.go b/game/wizard.go index dedb1f4..d954421 100644 --- a/game/wizard.go +++ b/game/wizard.go @@ -119,7 +119,7 @@ func (g *RogueGame) whatis(insist bool, kind ObjectKind) { var obj *Object for { - obj = g.getItem("identify", kind) + obj, _ = g.promptPackItem("identify", kind) if !insist { break @@ -161,7 +161,7 @@ func (g *RogueGame) whatis(insist bool, kind ObjectKind) { setKnow(obj, g.Items.Rings[:]) } - g.msg("%s", g.invName(obj, false)) + g.msg("%s", g.inventoryName(obj, false)) } // setKnow sets things up when we really know what a thing is (wizard.c