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,6 +51,29 @@ func (l *Level) VisibleChar(y, x int) byte {
|
||||
return l.Char(y, x)
|
||||
}
|
||||
|
||||
// ObjectAt finds the unclaimed object at (y, x) (misc.c find_obj).
|
||||
func (l *Level) ObjectAt(y, x int) *Object {
|
||||
for _, obj := range l.Objects {
|
||||
if obj.Pos.Y == y && obj.Pos.X == x {
|
||||
return obj
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddObject puts an object on the level (list.c attach on lvl_obj).
|
||||
func (l *Level) AddObject(obj *Object) { attachObj(&l.Objects, obj) }
|
||||
|
||||
// RemoveObject takes an object off the level (list.c detach on lvl_obj).
|
||||
func (l *Level) RemoveObject(obj *Object) { detachObj(&l.Objects, obj) }
|
||||
|
||||
// AddMonster puts a monster on the level (list.c attach on mlist).
|
||||
func (l *Level) AddMonster(m *Monster) { attachMon(&l.Monsters, m) }
|
||||
|
||||
// RemoveMonster takes a monster off the level (list.c detach on mlist).
|
||||
func (l *Level) RemoveMonster(m *Monster) { detachMon(&l.Monsters, m) }
|
||||
|
||||
// goldCalc is the GOLDCALC macro: how much a gold pile is worth at depth.
|
||||
func (g *RogueGame) goldCalc() int {
|
||||
return g.rnd(50+10*g.Depth) + 2
|
||||
|
||||
Reference in New Issue
Block a user