go: port foundation — types, RNG, tables, daemon scheduler

Module sneak.berlin/go/rogue, package game:
- types.go: all rogue.h constants, flag types, Coord/Stats/Room/ObjInfo
- creature.go/object.go: the THING union split into Creature (Player/
  Monster) and Object; slices replace the C linked lists
- level.go: Place map with the C column-major layout and chat/flat/moat/
  winat access methods
- tables.go: extern.c + init.c data (bestiary, item tables, name pools)
- rng.go: the exact C LCG (seed*11109+13849), golden-tested against a
  compiled C reference for seed compatibility
- init.go: per-game item appearance randomization (init.c)
- daemon.go/daemons.go: scheduler with DaemonID replacing function
  pointers (ids match the C save format's mapping)
- game.go: RogueGame holds all former globals; NewGame constructor
This commit is contained in:
2026-07-06 18:46:22 +02:00
parent 45dba95678
commit 7fa2048402
13 changed files with 1535 additions and 0 deletions

73
game/level.go Normal file
View File

@@ -0,0 +1,73 @@
package game
// Place describes a spot on the level map (rogue.h PLACE).
type Place struct {
Ch byte // the base map character
Flags PlaceFlags
Monst *Monster
}
// Level is the current dungeon level: the map and everything on it. It is
// reset in place by NewLevel, matching the C reuse of the global arrays.
type Level struct {
Places [MaxLines * MaxCols]Place
Rooms [MaxRooms]Room
Passages [MaxPass]Room // one pseudo-room per passage network
Objects []*Object // lvl_obj: objects on this level
Monsters []*Monster // mlist: monsters on the level
Stairs Coord // location of the staircase
NTraps int // number of traps on this level
}
// At returns the map cell at (y, x); the C INDEX(y,x) macro, including its
// column-major (x<<5)+y layout.
func (l *Level) At(y, x int) *Place {
return &l.Places[(x<<5)+y]
}
// Char is the chat(y,x) macro: the base map character at a spot.
func (l *Level) Char(y, x int) byte { return l.At(y, x).Ch }
// SetChar updates the base map character at a spot.
func (l *Level) SetChar(y, x int, ch byte) { l.At(y, x).Ch = ch }
// FlagsAt is the flat(y,x) macro, returned as a pointer so ported
// read-modify-write sites keep their shape.
func (l *Level) FlagsAt(y, x int) *PlaceFlags { return &l.At(y, x).Flags }
// MonsterAt is the moat(y,x) macro: the monster standing at a spot, if any.
func (l *Level) MonsterAt(y, x int) *Monster { return l.At(y, x).Monst }
// SetMonsterAt places (or clears, with nil) the monster at a spot.
func (l *Level) SetMonsterAt(y, x int, m *Monster) { l.At(y, x).Monst = m }
// VisibleChar is the winat(y,x) macro: what is apparently at a spot — a
// monster's disguise if one stands there, else the map character.
func (l *Level) VisibleChar(y, x int) byte {
if m := l.MonsterAt(y, x); m != nil {
return m.Disguise
}
return l.Char(y, x)
}
// reset clears the per-level state ahead of NewLevel drawing a fresh level.
func (l *Level) reset() {
for i := range l.Places {
l.Places[i] = Place{}
}
for i := range l.Rooms {
l.Rooms[i] = Room{}
}
for i := range l.Passages {
l.Passages[i] = Room{Flags: IsGone | IsDark}
}
l.Objects = nil
l.Monsters = nil
l.Stairs = Coord{}
l.NTraps = 0
}
// 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
}