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
156 lines
5.3 KiB
Go
156 lines
5.3 KiB
Go
package game
|
|
|
|
// ItemLore is the per-game item identity state: the randomized appearance
|
|
// names and the seven mutable ObjInfo tables (extern.c/init.c).
|
|
type ItemLore struct {
|
|
PotColors [MaxPotions]string // p_colors: colors of the potions
|
|
ScrNames [MaxScrolls]string // s_names: names of the scrolls
|
|
RingStones [MaxRings]string // r_stones: stone settings of the rings
|
|
WandMade [MaxSticks]string // ws_made: what sticks are made of
|
|
WandType [MaxSticks]string // ws_type: "wand" or "staff"
|
|
|
|
Things [NumThings]ObjInfo
|
|
Potions [MaxPotions]ObjInfo
|
|
Scrolls [MaxScrolls]ObjInfo
|
|
Rings [MaxRings]ObjInfo
|
|
Sticks [MaxSticks]ObjInfo
|
|
Weapons [MaxWeapons + 1]ObjInfo
|
|
Armors [MaxArmors]ObjInfo
|
|
|
|
Group int // group number for the next stack of missiles (weapons.c `group`)
|
|
}
|
|
|
|
// Options are the user-settable game options (options.c optlist).
|
|
type Options struct {
|
|
Terse bool // terse: shorter messages
|
|
FightFlush bool // flush: flush typeahead during battle
|
|
Jump bool // jump: show position only at end of run
|
|
SeeFloor bool // seefloor: show the lamp-illuminated floor
|
|
PassGo bool // passgo: follow turnings in passageways
|
|
Tombstone bool // tombstone: print tombstone when killed
|
|
InvType int // inven: inventory style (InvOver/InvSlow/InvClear)
|
|
}
|
|
|
|
// Config carries everything needed to construct a game.
|
|
type Config struct {
|
|
Seed int32 // dungeon number; the caller derives it (time+pid or SEED env)
|
|
Name string // player name (overridden by ROGUEOPTS name=)
|
|
RogueOpts string // the ROGUEOPTS environment string
|
|
Home string // home directory (save file default location)
|
|
ScorePath string // scoreboard file; empty disables scoring
|
|
Wizard bool // enable debug commands (implies NoScore)
|
|
}
|
|
|
|
// RogueGame is one complete game of Rogue: every piece of state that was a
|
|
// global (or file-scope static) in the C sources, plus the terminal it is
|
|
// played on. Construct with NewGame, then call Run.
|
|
//
|
|
// The struct grows with the port; fields appear in the phase that ports the
|
|
// code owning them.
|
|
type RogueGame struct {
|
|
// identity / RNG
|
|
Rng *Rng
|
|
Dnum int // dungeon number
|
|
Whoami string // name of player
|
|
Fruit string // favorite fruit
|
|
Home string // user's home directory
|
|
FileName string // save file name
|
|
Wizard bool // true if allows wizard commands
|
|
NoScore bool // was a wizard sometime
|
|
|
|
// the world
|
|
Player Player
|
|
Level Level
|
|
Depth int // C `level`: what level she is on
|
|
MaxDepth int // C `max_level`: deepest player has gone
|
|
HasAmulet bool // C `amulet`: he found the amulet
|
|
SeenStairs bool // have seen the stairs (for lsd)
|
|
|
|
// turn/command engine
|
|
Playing bool // true until he quits
|
|
After bool // true if we want after daemons
|
|
Again bool // repeating the last command
|
|
Count int // number of times to repeat command
|
|
NoCommand int // number of turns asleep
|
|
NoMove int // number of turns held in place
|
|
Quiet int // number of quiet turns
|
|
Running bool // true if player is running
|
|
RunCh byte // direction player is running
|
|
DoorStop bool // stop running when we pass a door
|
|
Firstmove bool // first move after setting door_stop
|
|
MoveOn bool // next move shouldn't pick up items
|
|
ToDeath bool // fighting is to the death!
|
|
Kamikaze bool // to_death really to DEATH
|
|
HasHit bool // has a "hit" message pending in msg
|
|
MaxHit int // max damage done to her in to_death
|
|
Take byte // thing she is taking
|
|
Delta Coord
|
|
DirCh byte
|
|
LastComm byte
|
|
LastDir byte
|
|
LLastComm byte
|
|
LLastDir byte
|
|
LastPick *Object
|
|
LLastPick *Object
|
|
|
|
// daemons/fuses
|
|
Daemons DaemonList
|
|
|
|
// UI state (the Screen itself arrives with the UI phase)
|
|
StatMsg bool // should status() print as a msg()
|
|
InvDescribe bool // say which way items are being used
|
|
QComm bool // are we executing a 'Q' command?
|
|
InShell bool // true if executing a shell
|
|
Oldpos Coord // position before last look() call
|
|
Oldrp *Room
|
|
NObjs int // # items listed in inventory() call
|
|
|
|
// options and item identity
|
|
Options Options
|
|
Items ItemLore
|
|
|
|
// scores
|
|
LastScore int
|
|
AllScore bool
|
|
ScorePath string
|
|
}
|
|
|
|
// NewGame builds a game from cfg, seeds the RNG, and randomizes the item
|
|
// appearance tables (the front half of main.c main(); the player roll-up
|
|
// and first level arrive with later porting phases).
|
|
func NewGame(cfg Config) *RogueGame {
|
|
g := &RogueGame{
|
|
Rng: &Rng{Seed: cfg.Seed},
|
|
Dnum: int(cfg.Seed),
|
|
Whoami: cfg.Name,
|
|
Fruit: "slime-mold",
|
|
Home: cfg.Home,
|
|
Wizard: cfg.Wizard,
|
|
NoScore: cfg.Wizard,
|
|
Playing: true,
|
|
Depth: 1,
|
|
ScorePath: cfg.ScorePath,
|
|
LastScore: -1,
|
|
}
|
|
g.Options = Options{
|
|
SeeFloor: true,
|
|
Tombstone: true,
|
|
InvType: InvOver,
|
|
}
|
|
g.InvDescribe = true
|
|
g.FileName = cfg.Home + "/rogue.save"
|
|
if cfg.Wizard {
|
|
g.Player.Flags.Set(SeeMonst)
|
|
}
|
|
// TODO(port): parse cfg.RogueOpts once options.go lands.
|
|
|
|
g.initProbs() // set up prob tables for objects
|
|
// TODO(port): initPlayer() goes exactly here (RNG order!) once pack.go lands.
|
|
g.initNames() // set up names of scrolls
|
|
g.initColors() // set up colors of potions
|
|
g.initStones() // set up stone settings of rings
|
|
g.initMaterials() // set up materials of wands
|
|
// TODO(port): new level + daemon start-up once their phases land.
|
|
return g
|
|
}
|