diff --git a/game/object.go b/game/object.go index 5991503..b62f689 100644 --- a/game/object.go +++ b/game/object.go @@ -77,17 +77,9 @@ func (k ObjectKind) String() string { 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" + default: + return k.stringRest() } - - return "bizarre thing" } // objectKindForGlyph is the reverse of Glyph: what category of item does a @@ -123,6 +115,23 @@ func (k ObjectKind) MergesInPack() bool { return k == KindPotion || k == KindScroll || k == KindFood } +// stringRest names the remaining kinds, including the ring-or-stick +// prompt pseudo-kind (the tail of the C type_name switch). +func (k ObjectKind) stringRest() string { + switch k { + case KindWand: + return "wand or staff" + case KindAmulet: + return "amulet" + case KindGold: + return goldName + case KindRingOrStick: + return "ring, wand or staff" + } + + return "bizarre thing" +} + // 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 { diff --git a/game/weapons.go b/game/weapons.go index de56d1d..c555240 100644 --- a/game/weapons.go +++ b/game/weapons.go @@ -35,34 +35,38 @@ func (g *RogueGame) doMotion(obj *Object, ydelta, xdelta int) { // Come fly with us ... obj.Pos = p.Pos for { - // Erase the old one - if obj.Pos != p.Pos && g.canSee(obj.Pos.Y, obj.Pos.X) && !g.Options.Terse { - ch := g.Level.Char(obj.Pos.Y, obj.Pos.X) - if ch == Floor && !g.showFloor() { - ch = ' ' - } - - g.mvaddch(obj.Pos.Y, obj.Pos.X, ch) - } + g.eraseFlight(obj, p.Pos) // Get the new position obj.Pos.Y += ydelta obj.Pos.X += xdelta ch := g.Level.VisibleChar(obj.Pos.Y, obj.Pos.X) - if stepOk(ch) && ch != Door { - // It hasn't hit anything yet, so display it if it's alright. - if g.canSee(obj.Pos.Y, obj.Pos.X) && !g.Options.Terse { - g.mvaddch(obj.Pos.Y, obj.Pos.X, obj.Kind.Glyph()) - g.refresh() - } - - continue + if !stepOk(ch) || ch == Door { + break + } + // It hasn't hit anything yet, so display it if it's alright. + if g.canSee(obj.Pos.Y, obj.Pos.X) && !g.Options.Terse { + g.mvaddch(obj.Pos.Y, obj.Pos.X, obj.Kind.Glyph()) + g.refresh() } - - break } } +// eraseFlight erases a flying object from its current square, unless it +// still sits on the hero (the erase step of weapons.c do_motion). +func (g *RogueGame) eraseFlight(obj *Object, heroPos Coord) { + if obj.Pos == heroPos || !g.canSee(obj.Pos.Y, obj.Pos.X) || g.Options.Terse { + return + } + + ch := g.Level.Char(obj.Pos.Y, obj.Pos.X) + if ch == Floor && !g.showFloor() { + ch = ' ' + } + + g.mvaddch(obj.Pos.Y, obj.Pos.X, ch) +} + // fall drops an item someplace around here (weapons.c fall). func (g *RogueGame) fall(obj *Object, pr bool) { if fpos, ok := g.fallpos(obj.Pos); ok {