go: port command loop, save/restore, tcell terminal, and the binary

- command.c in full: the command dispatcher with repeat counts, run
  prefixes, ctrl-run door-stop mode, fight-to-death targeting, and all
  wizard debug commands; search, help, identify, d_level/u_level, call,
  current
- main.c completed: Run()/playit() with the C double ROGUEOPTS parse;
  exit()-anywhere becomes a gameEnd panic recovered in Run
- save.c + state.c: gob SaveState snapshot with explicit pointer-to-
  index fixups for equipment, monster rooms, and chase targets (the
  rs_fix_thing role); save file deleted on restore as in C; SIGHUP/
  SIGTERM autosave hook
- wizard.c completed (create_obj, show_map), passages.c add_pass
- term/: tcell/v2 Terminal — the one third-party dependency — replacing
  curses and mdport's 900-line key decoder; shell escape via suspend
- cmd/rogue: flags -s/-d, SEED (wizard), ROGUEOPTS, ROGUE_WIZARD

Tests: full scripted sessions through Run (quit, descend stairs,
3200-move crash sweep, save-command round trip). Notable fixes found
by tests: gob silently drops embedded fields of unexported types, and
--More-- prompts swallow space-free input scripts.
This commit is contained in:
2026-07-06 20:15:47 +02:00
parent cdf9bf73a9
commit 41fc1042fc
14 changed files with 2067 additions and 20 deletions

View File

@@ -1,8 +1,96 @@
package game
// wizard.c — special wizard commands, some of which are also non-wizard
// commands under strange circumstances. The MASTER-only debug commands
// (create_obj, show_map) arrive with the UI phase.
// commands under strange circumstances. The DES password check is not
// ported: wizard mode is enabled by configuration instead.
// createObj is the wizard command for getting anything he wants (wizard.c
// create_obj).
func (g *RogueGame) createObj() {
obj := newObject()
g.msg("type of item: ")
obj.Type = g.readchar()
g.Msgs.Mpos = 0
g.msg("which %c do you want? (0-f)", obj.Type)
ch := g.readchar()
if isDigit(ch) {
obj.Which = int(ch - '0')
} else {
obj.Which = int(ch-'a') + 10
}
obj.Group = 0
obj.Count = 1
g.Msgs.Mpos = 0
switch {
case obj.Type == Weapon || obj.Type == Armor:
g.msg("blessing? (+,-,n)")
bless := g.readchar()
g.Msgs.Mpos = 0
if bless == '-' {
obj.Flags.Set(IsCursed)
}
if obj.Type == Weapon {
g.initWeapon(obj, obj.Which)
if bless == '-' {
obj.HPlus -= g.rnd(3) + 1
}
if bless == '+' {
obj.HPlus += g.rnd(3) + 1
}
} else {
obj.Arm = aClass[obj.Which]
if bless == '-' {
obj.Arm += g.rnd(3) + 1
}
if bless == '+' {
obj.Arm -= g.rnd(3) + 1
}
}
case obj.Type == Ring:
switch obj.Which {
case RProtect, RAddStr, RAddHit, RAddDam:
g.msg("blessing? (+,-,n)")
bless := g.readchar()
g.Msgs.Mpos = 0
if bless == '-' {
obj.Flags.Set(IsCursed)
obj.Arm = -1
} else {
obj.Arm = g.rnd(2) + 1
}
case RAggr, RTeleport:
obj.Flags.Set(IsCursed)
}
case obj.Type == Stick:
g.fixStick(obj)
case obj.Type == Gold:
g.msg("how much?")
buf := ""
if g.getStr(&buf, g.scr.Std) == Norm {
obj.SetGoldVal(cAtoi(buf))
}
}
g.addPack(obj, false)
}
// showMap prints out the whole map for the wizard (wizard.c show_map).
func (g *RogueGame) showMap() {
hw := g.scr.Hw
hw.Clear()
for y := 1; y < NumLines-1; y++ {
for x := 0; x < NumCols; x++ {
real := g.Level.FlagsAt(y, x).Has(FReal)
if !real {
hw.Standout(true)
}
hw.MvAddCh(y, x, g.Level.Char(y, x))
if !real {
hw.Standout(false)
}
}
}
g.showWin("---More (level map)---")
}
// whatis identifies what a certain object is (wizard.c whatis).
func (g *RogueGame) whatis(insist bool, typ int) {