Extract MessageLine, Player pack ops, and Level list management
Refactor step 6. MessageLine (was MsgLine) owns the msg/addmsg/endmsg machinery, wired to its screen, pre---More-- redraw, and input via attach(); RogueGame keeps one-line msg/addmsgf/endmsg shorthands so the ~400 call sites are unchanged. Player gains nextPackChar and removeFromPack (the state half of pack.c leave_pack); leavePack keeps only the LastPick repeat-command tracking. Level gains ObjectAt (misc.c find_obj) and AddObject/RemoveObject/AddMonster/RemoveMonster, replacing direct attach/detach calls on the level lists. Inventory and pickup UI flows stay on RogueGame: display and orchestration, not state surgery. Behavior and RNG order unchanged; suite green.
This commit is contained in:
51
game/pack.go
51
game/pack.go
@@ -9,7 +9,7 @@ func (g *RogueGame) addPack(obj *Object, silent bool) {
|
||||
fromFloor := false
|
||||
|
||||
if obj == nil {
|
||||
if obj = g.findObj(p.Pos.Y, p.Pos.X); obj == nil {
|
||||
if obj = g.Level.ObjectAt(p.Pos.Y, p.Pos.X); obj == nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func (g *RogueGame) addPack(obj *Object, silent bool) {
|
||||
|
||||
// Check for and deal with scare monster scrolls
|
||||
if obj.Kind == KindScroll && obj.ScrollKind() == ScrollScareMonster && obj.Flags.Has(WasFound) {
|
||||
detachObj(&g.Level.Objects, obj)
|
||||
g.Level.RemoveObject(obj)
|
||||
g.mvaddch(p.Pos.Y, p.Pos.X, g.floorCh())
|
||||
|
||||
if p.Room.Flags.Has(Gone) {
|
||||
@@ -34,7 +34,7 @@ func (g *RogueGame) addPack(obj *Object, silent bool) {
|
||||
|
||||
if len(p.Pack) == 0 {
|
||||
p.Pack = append(p.Pack, obj)
|
||||
obj.PackCh = g.packChar()
|
||||
obj.PackCh = p.nextPackChar()
|
||||
p.Inpack++
|
||||
} else {
|
||||
// Walk the pack looking for the insertion point, keeping items of
|
||||
@@ -112,7 +112,7 @@ func (g *RogueGame) addPack(obj *Object, silent bool) {
|
||||
return
|
||||
}
|
||||
|
||||
obj.PackCh = g.packChar()
|
||||
obj.PackCh = p.nextPackChar()
|
||||
p.Pack = append(p.Pack[:lp+1],
|
||||
append([]*Object{obj}, p.Pack[lp+1:]...)...)
|
||||
}
|
||||
@@ -168,7 +168,7 @@ func (g *RogueGame) packRoom(fromFloor bool, obj *Object) bool {
|
||||
}
|
||||
|
||||
if fromFloor {
|
||||
detachObj(&g.Level.Objects, obj)
|
||||
g.Level.RemoveObject(obj)
|
||||
g.mvaddch(p.Pos.Y, p.Pos.X, g.floorCh())
|
||||
|
||||
if p.Room.Flags.Has(Gone) {
|
||||
@@ -181,46 +181,17 @@ func (g *RogueGame) packRoom(fromFloor bool, obj *Object) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// leavePack takes an item out of the pack (pack.c leave_pack).
|
||||
// leavePack takes an item out of the pack (pack.c leave_pack), keeping
|
||||
// the repeat-command bookkeeping; the pack surgery is
|
||||
// Player.removeFromPack.
|
||||
func (g *RogueGame) leavePack(obj *Object, newobj, all bool) *Object {
|
||||
p := &g.Player
|
||||
p.Inpack--
|
||||
|
||||
nobj := obj
|
||||
if obj.Count > 1 && !all {
|
||||
g.LastPick = obj
|
||||
|
||||
obj.Count--
|
||||
if obj.Group != 0 {
|
||||
p.Inpack++
|
||||
}
|
||||
|
||||
if newobj {
|
||||
copied := *obj
|
||||
nobj = &copied
|
||||
nobj.Count = 1
|
||||
}
|
||||
} else {
|
||||
g.LastPick = nil
|
||||
p.PackUsed[obj.PackCh-'a'] = false
|
||||
detachObj(&p.Pack, obj)
|
||||
}
|
||||
|
||||
return nobj
|
||||
}
|
||||
|
||||
// packChar returns the next unused pack character (pack.c pack_char).
|
||||
func (g *RogueGame) packChar() byte {
|
||||
p := &g.Player
|
||||
for i := range p.PackUsed {
|
||||
if !p.PackUsed[i] {
|
||||
p.PackUsed[i] = true
|
||||
|
||||
return byte(i) + 'a'
|
||||
}
|
||||
}
|
||||
|
||||
return byte(len(p.PackUsed)) + 'a' // C would walk off the array here
|
||||
return g.Player.removeFromPack(obj, newobj, all)
|
||||
}
|
||||
|
||||
// inventory lists what is in the pack; returns true if there is something
|
||||
@@ -277,7 +248,7 @@ func (g *RogueGame) pickUp(ch byte) {
|
||||
return
|
||||
}
|
||||
|
||||
obj := g.findObj(p.Pos.Y, p.Pos.X)
|
||||
obj := g.Level.ObjectAt(p.Pos.Y, p.Pos.X)
|
||||
if g.MoveOn {
|
||||
g.moveMsg(obj)
|
||||
|
||||
@@ -291,7 +262,7 @@ func (g *RogueGame) pickUp(ch byte) {
|
||||
}
|
||||
|
||||
g.money(obj.GoldValue)
|
||||
detachObj(&g.Level.Objects, obj)
|
||||
g.Level.RemoveObject(obj)
|
||||
|
||||
p.Room.GoldVal = 0
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user