Rename movement/world methods to idiomatic Go; remove all gotos

Refactor step 4. Renames (C breadcrumbs kept in doc comments):
doMove→moveHero, beTrapped→springTrap, rndmove→randomStep,
doRooms→digRooms, doPassages→digPassages, doMaze→digMaze,
chgStr→changeStrength, doRun→startRun, moveStuff→finishMove,
turnref→turnRefresh, moveMonst→moveMonster, doChase→chaseStep,
setOldch→setOldChar, cansee→canSee, roomin→roomIn, runto→runTo,
conn→connectRooms, putpass→putPassage, passnum→numberPassages,
numpass→numberPassage, rndPos→randomPos, rndRoom→randomRoom,
treasRoom→treasureRoom, accntMaze→accountMaze.

All goto/label flows are gone: moveHero uses a retry loop with the
PASSGO corner logic extracted into passageTurn; dispatch re-dispatches
via a loop; chaseStep re-checks via a loop; saveGame uses a labeled
prompt loop. Control flow and RNG call order are unchanged; suite
green.
This commit is contained in:
2026-07-07 02:29:06 +02:00
parent 65a1cd68b8
commit 6850c87ae7
21 changed files with 653 additions and 624 deletions

47
TODO.md
View File

@@ -29,14 +29,26 @@ Refactor ground rules:
# Next Step # Next Step
Refactor step 4: method renames, movement/world subsystem Refactor step 5: method renames, items/combat/UI subsystems
(doMove→moveHero, beTrapped→springTrap, rndmove→randomStep, (invName→inventoryName, rollEm→rollAttacks, doPot→applyPotionFuse,
doRooms/doPassages/doMaze→digRooms/digPassages/digMaze, getItem→promptPackItem returning (obj, ok), getDir→promptDirection);
chgStr→changeStrength, ...); remove the goto/label flows in doMove, int status codes (attack returning -1) become named results. Two or
dispatch, and saveGame in favor of loops and helpers. three commits, one subsystem each.
# Completed Steps # Completed Steps
- 2026-07-07 Refactor step 4 (refactor/movement-renames): movement/world
renames (doMove→moveHero, beTrapped→springTrap, rndmove→randomStep,
doRooms/doPassages/doMaze→digRooms/digPassages/digMaze,
chgStr→changeStrength, doRun→startRun, moveStuff→finishMove,
turnref→turnRefresh, moveMonst→moveMonster, doChase→chaseStep,
setOldch→setOldChar, cansee→canSee, roomin→roomIn, runto→runTo,
conn→connectRooms, putpass→putPassage, passnum→numberPassages,
numpass→numberPassage, rndPos→randomPos, rndRoom→randomRoom,
treasRoom→treasureRoom, accntMaze→accountMaze); all goto/label flows
replaced with loops (moveHero retry loop + extracted passageTurn,
dispatch re-dispatch loop, chaseStep passage loop, saveGame labeled
prompt loop); C breadcrumbs kept in doc comments.
- 2026-07-07 Lint adoption finished (refactor/no-package-globals): all - 2026-07-07 Lint adoption finished (refactor/no-package-globals): all
37 package-level vars moved into `gameData` (built by `newGameData`, 37 package-level vars moved into `gameData` (built by `newGameData`,
hung on RogueGame as `g.data`, set in NewGame and Restore); ObjectKind hung on RogueGame as `g.data`, set in NewGame and Restore); ObjectKind
@@ -98,41 +110,36 @@ dispatch, and saveGame in favor of loops and helpers.
# Future Steps # Future Steps
1. Refactor step 5: method renames, items/combat/UI subsystems 1. Refactor step 6: extract types from the god object — MessageLine
(invName→inventoryName, rollEm→rollAttacks, doPot→applyPotionFuse,
getItem→promptPackItem returning (obj, ok), getDir→promptDirection);
int status codes (attack returning -1) become named results. Two or
three commits, one subsystem each.
2. Refactor step 6: extract types from the god object — MessageLine
owns the msg/addmsg/endmsg machinery; pack/inventory operations move owns the msg/addmsg/endmsg machinery; pack/inventory operations move
onto *Player; monster/object list management and map queries onto *Player; monster/object list management and map queries
consolidate onto *Level; RogueGame keeps turn orchestration and consolidate onto *Level; RogueGame keeps turn orchestration and
cross-system effects only. cross-system effects only.
3. Refactor step 7: effects dispatch — the giant quaff/readScroll/doZap 2. Refactor step 7: effects dispatch — the giant quaff/readScroll/doZap
switches become per-kind handler tables of small named methods, switches become per-kind handler tables of small named methods,
keeping effect order and RNG call sequence identical. This step also keeping effect order and RNG call sequence identical. This step also
clears the outstanding cyclop/gocognit/nestif lint findings. clears the outstanding cyclop/gocognit/nestif lint findings.
4. Refactor step 8: constructor and style pass per the house 3. Refactor step 8: constructor and style pass per the house
styleguide — game.New(game.Params{...}) replacing NewGame(Config); styleguide — game.New(game.Params{...}) replacing NewGame(Config);
replace the gameEnd panic unwind with error-based turn results where replace the gameEnd panic unwind with error-based turn results where
feasible; 77-column wrap sweep. feasible; 77-column wrap sweep.
5. Docs refresh: update ARCHITECTURE.md Part 2 and README.md for the 4. Docs refresh: update ARCHITECTURE.md Part 2 and README.md for the
post-refactor names; add the C name → Go name rename table. post-refactor names; add the C name → Go name rename table.
6. Playtest hardening pass: play several full games with the tcell 5. Playtest hardening pass: play several full games with the tcell
binary and extend run_test.go to script a deeper multi-level binary and extend run_test.go to script a deeper multi-level
playthrough (descend past level 5, use potions, scrolls, zapping, playthrough (descend past level 5, use potions, scrolls, zapping,
save/restore). Fix any panics, message mismatches, or divergences save/restore). Fix any panics, message mismatches, or divergences
from the C behavior that this uncovers, with regression tests. from the C behavior that this uncovers, with regression tests.
7. Verify the seed-compatibility claim against the C reference on 6. Verify the seed-compatibility claim against the C reference on
c-master: same seed, same dungeon, same item tables, for several c-master: same seed, same dungeon, same item tables, for several
seeds. seeds.
8. Broaden unit test coverage where playtesting finds thin spots 7. Broaden unit test coverage where playtesting finds thin spots
(rings, sticks, wizard commands). (rings, sticks, wizard commands).
9. Tag a release once a full game (Amulet retrieval and score entry) 8. Tag a release once a full game (Amulet retrieval and score entry)
completes without defects. completes without defects.
10. Full-terminal-size support (deferred by explicit decision 9. Full-terminal-size support (deferred by explicit decision
2026-07-06): per-game dungeon dimensions instead of the 80x24 2026-07-06): per-game dungeon dimensions instead of the 80x24
constants; open design questions are resize policy, gameplay constants; open design questions are resize policy, gameplay
tuning at larger sizes, and a --classic 80x24 mode. tuning at larger sizes, and a --classic 80x24 mode.
11. Note: this repo is exempt from the standard policy scaffold. Do not 10. Note: this repo is exempt from the standard policy scaffold. Do not
add Makefile, Dockerfile, or REPO_POLICIES.md. add Makefile, Dockerfile, or REPO_POLICIES.md.

View File

@@ -13,12 +13,12 @@ func (g *RogueGame) runners(int) {
origPos := tp.Pos origPos := tp.Pos
wastarget := tp.On(Targeted) wastarget := tp.On(Targeted)
if g.moveMonst(tp) == -1 { if g.moveMonster(tp) == -1 {
continue continue
} }
if tp.On(Flying) && distCp(g.Player.Pos, tp.Pos) >= 3 { if tp.On(Flying) && distCp(g.Player.Pos, tp.Pos) >= 3 {
if g.moveMonst(tp) == -1 { if g.moveMonster(tp) == -1 {
continue continue
} }
} }
@@ -37,17 +37,17 @@ func (g *RogueGame) runners(int) {
} }
} }
// moveMonst executes a single turn of running for a monster (chase.c // moveMonster executes a single turn of running for a monster (chase.c
// move_monst). Returns -1 if the monster died or left the level. // move_monst). Returns -1 if the monster died or left the level.
func (g *RogueGame) moveMonst(tp *Monster) int { func (g *RogueGame) moveMonster(tp *Monster) int {
if !tp.On(Slowed) || tp.Turn { if !tp.On(Slowed) || tp.Turn {
if g.doChase(tp) == -1 { if g.chaseStep(tp) == -1 {
return -1 return -1
} }
} }
if tp.On(Hasted) { if tp.On(Hasted) {
if g.doChase(tp) == -1 { if g.chaseStep(tp) == -1 {
return -1 return -1
} }
} }
@@ -62,8 +62,8 @@ func (g *RogueGame) moveMonst(tp *Monster) int {
func (g *RogueGame) relocate(th *Monster, newLoc Coord) { func (g *RogueGame) relocate(th *Monster, newLoc Coord) {
if newLoc != th.Pos { if newLoc != th.Pos {
g.mvaddch(th.Pos.Y, th.Pos.X, th.OldCh) g.mvaddch(th.Pos.Y, th.Pos.X, th.OldCh)
th.Room = g.roomin(newLoc) th.Room = g.roomIn(newLoc)
g.setOldch(th, newLoc) g.setOldChar(th, newLoc)
oroom := th.Room oroom := th.Room
g.Level.SetMonsterAt(th.Pos.Y, th.Pos.X, nil) g.Level.SetMonsterAt(th.Pos.Y, th.Pos.X, nil)
@@ -86,9 +86,9 @@ func (g *RogueGame) relocate(th *Monster, newLoc Coord) {
} }
} }
// doChase makes one thing chase another (chase.c do_chase). Returns -1 if // chaseStep makes one thing chase another (chase.c do_chase). Returns -1
// the chaser died in the attempt. // if the chaser died in the attempt.
func (g *RogueGame) doChase(th *Monster) int { func (g *RogueGame) chaseStep(th *Monster) int {
p := &g.Player p := &g.Player
stoprun := false // true means we are there stoprun := false // true means we are there
mindist := 32767 mindist := 32767
@@ -102,16 +102,16 @@ func (g *RogueGame) doChase(th *Monster) int {
if th.Dest == &p.Pos { if th.Dest == &p.Pos {
ree = p.Room ree = p.Room
} else { } else {
ree = g.roomin(*th.Dest) ree = g.roomIn(*th.Dest)
} }
// We don't count doors as inside rooms for this routine // We don't count doors as inside rooms for this routine
door := g.Level.Char(th.Pos.Y, th.Pos.X) == Door door := g.Level.Char(th.Pos.Y, th.Pos.X) == Door
var this Coord var this Coord
over: for {
// If the object of our desire is in a different room, and we are not // If the object of our desire is in a different room, and we are
// in a corridor, run to the door nearest to our goal. // not in a corridor, run to the door nearest to our goal.
if rer != ree { if rer != ree {
for i := range rer.Exits { for i := range rer.Exits {
curdist := distCp(*th.Dest, rer.Exits[i]) curdist := distCp(*th.Dest, rer.Exits[i])
@@ -125,13 +125,13 @@ over:
rer = &g.Level.Passages[*g.Level.FlagsAt(th.Pos.Y, th.Pos.X)&FPassNum] rer = &g.Level.Passages[*g.Level.FlagsAt(th.Pos.Y, th.Pos.X)&FPassNum]
door = false door = false
goto over continue // the C goto over: redo with the passage as room
} }
} else { } else {
this = *th.Dest this = *th.Dest
// For dragons check and see if (a) the hero is on a straight line // For dragons check and see if (a) the hero is on a straight
// from it, and (b) that it is within shooting distance, but // line from it, and (b) that it is within shooting distance,
// outside of striking range. // but outside of striking range.
if th.Type == 'D' && (th.Pos.Y == p.Pos.Y || th.Pos.X == p.Pos.X || if th.Type == 'D' && (th.Pos.Y == p.Pos.Y || th.Pos.X == p.Pos.X ||
abs(th.Pos.Y-p.Pos.Y) == abs(th.Pos.X-p.Pos.X)) && abs(th.Pos.Y-p.Pos.Y) == abs(th.Pos.X-p.Pos.X)) &&
distCp(th.Pos, p.Pos) <= BoltLength*BoltLength && distCp(th.Pos, p.Pos) <= BoltLength*BoltLength &&
@@ -156,6 +156,9 @@ over:
return 0 return 0
} }
} }
break
}
// This now contains what we want to run to this time so we run to it. // This now contains what we want to run to this time so we run to it.
// If we hit it we either want to fight it or stop running // If we hit it we either want to fight it or stop running
if !g.chase(th, this) { if !g.chase(th, this) {
@@ -214,7 +217,7 @@ func (g *RogueGame) chase(tp *Monster, ee Coord) bool {
if (tp.On(Confused) && g.rnd(5) != 0) || (tp.Type == 'P' && g.rnd(5) == 0) || if (tp.On(Confused) && g.rnd(5) != 0) || (tp.Type == 'P' && g.rnd(5) == 0) ||
(tp.Type == 'B' && g.rnd(2) == 0) { (tp.Type == 'B' && g.rnd(2) == 0) {
// get a valid random move // get a valid random move
g.chRet = g.rndmove(&tp.Creature) g.chRet = g.randomStep(&tp.Creature)
curdist = distCp(g.chRet, ee) curdist = distCp(g.chRet, ee)
// Small chance that it will become un-confused // Small chance that it will become un-confused
if g.rnd(20) == 0 { if g.rnd(20) == 0 {
@@ -294,8 +297,8 @@ func (g *RogueGame) chase(tp *Monster, ee Coord) bool {
return curdist != 0 && g.chRet != p.Pos return curdist != 0 && g.chRet != p.Pos
} }
// setOldch sets the oldch character for the monster (chase.c set_oldch). // setOldChar sets the oldch character for the monster (chase.c set_oldch).
func (g *RogueGame) setOldch(tp *Monster, cp Coord) { func (g *RogueGame) setOldChar(tp *Monster, cp Coord) {
if tp.Pos == cp { if tp.Pos == cp {
return return
} }
@@ -341,8 +344,8 @@ func (g *RogueGame) seeMonst(mp *Monster) bool {
return !mp.Room.Flags.Has(Dark) return !mp.Room.Flags.Has(Dark)
} }
// runto sets a monster running after the hero (chase.c runto). // runTo sets a monster running after the hero (chase.c runto).
func (g *RogueGame) runto(runner Coord) { func (g *RogueGame) runTo(runner Coord) {
tp := g.Level.MonsterAt(runner.Y, runner.X) tp := g.Level.MonsterAt(runner.Y, runner.X)
if tp == nil { if tp == nil {
return return
@@ -353,9 +356,9 @@ func (g *RogueGame) runto(runner Coord) {
tp.Dest = g.findDest(tp) tp.Dest = g.findDest(tp)
} }
// roomin finds what room some coordinates are in; nil means they aren't in // roomIn finds what room some coordinates are in; nil means they aren't in
// any room (chase.c roomin). // any room (chase.c roomin).
func (g *RogueGame) roomin(cp Coord) *Room { func (g *RogueGame) roomIn(cp Coord) *Room {
fp := *g.Level.FlagsAt(cp.Y, cp.X) fp := *g.Level.FlagsAt(cp.Y, cp.X)
if fp.Has(FPassage) { if fp.Has(FPassage) {
return &g.Level.Passages[fp&FPassNum] return &g.Level.Passages[fp&FPassNum]
@@ -387,9 +390,9 @@ func (g *RogueGame) diagOk(sp, ep Coord) bool {
return stepOk(g.Level.Char(ep.Y, sp.X)) && stepOk(g.Level.Char(sp.Y, ep.X)) return stepOk(g.Level.Char(ep.Y, sp.X)) && stepOk(g.Level.Char(sp.Y, ep.X))
} }
// cansee returns true if the hero can see a certain coordinate (chase.c // canSee returns true if the hero can see a certain coordinate (chase.c
// cansee). // cansee).
func (g *RogueGame) cansee(y, x int) bool { func (g *RogueGame) canSee(y, x int) bool {
p := &g.Player p := &g.Player
if p.On(Blind) { if p.On(Blind) {
return false return false
@@ -408,7 +411,7 @@ func (g *RogueGame) cansee(y, x int) bool {
} }
// We can only see if the hero is in the same room as the coordinate // We can only see if the hero is in the same room as the coordinate
// and the room is lit, or if it is close. // and the room is lit, or if it is close.
rer := g.roomin(Coord{X: x, Y: y}) rer := g.roomIn(Coord{X: x, Y: y})
return rer == p.Room && !rer.Flags.Has(Dark) return rer == p.Room && !rer.Flags.Has(Dark)
} }
@@ -426,7 +429,7 @@ func (g *RogueGame) findDest(tp *Monster) *Coord {
continue continue
} }
if g.roomin(obj.Pos) == tp.Room && g.rnd(100) < prob { if g.roomIn(obj.Pos) == tp.Room && g.rnd(100) < prob {
claimed := false claimed := false
for _, other := range g.Level.Monsters { for _, other := range g.Level.Monsters {

View File

@@ -151,12 +151,12 @@ func (g *RogueGame) command() {
} }
} }
// dispatch runs one command character (the big switch in command.c, // dispatch runs one command character (the big switch in command.c; the
// including its `goto over` re-dispatch). // loop stands in for its `goto over` re-dispatch).
func (g *RogueGame) dispatch(ch byte) { func (g *RogueGame) dispatch(ch byte) {
p := &g.Player p := &g.Player
over: for {
switch ch { switch ch {
case ',': case ',':
var found *Object var found *Object
@@ -189,37 +189,37 @@ over:
case '!': case '!':
g.shell() g.shell()
case 'h': case 'h':
g.doMove(0, -1) g.moveHero(0, -1)
case 'j': case 'j':
g.doMove(1, 0) g.moveHero(1, 0)
case 'k': case 'k':
g.doMove(-1, 0) g.moveHero(-1, 0)
case 'l': case 'l':
g.doMove(0, 1) g.moveHero(0, 1)
case 'y': case 'y':
g.doMove(-1, -1) g.moveHero(-1, -1)
case 'u': case 'u':
g.doMove(-1, 1) g.moveHero(-1, 1)
case 'b': case 'b':
g.doMove(1, -1) g.moveHero(1, -1)
case 'n': case 'n':
g.doMove(1, 1) g.moveHero(1, 1)
case 'H': case 'H':
g.doRun('h') g.startRun('h')
case 'J': case 'J':
g.doRun('j') g.startRun('j')
case 'K': case 'K':
g.doRun('k') g.startRun('k')
case 'L': case 'L':
g.doRun('l') g.startRun('l')
case 'Y': case 'Y':
g.doRun('y') g.startRun('y')
case 'U': case 'U':
g.doRun('u') g.startRun('u')
case 'B': case 'B':
g.doRun('b') g.startRun('b')
case 'N': case 'N':
g.doRun('n') g.startRun('n')
case CTRL('H'), CTRL('J'), CTRL('K'), CTRL('L'), case CTRL('H'), CTRL('J'), CTRL('K'), CTRL('L'),
CTRL('Y'), CTRL('U'), CTRL('B'), CTRL('N'): CTRL('Y'), CTRL('U'), CTRL('B'), CTRL('N'):
if !p.On(Blind) { if !p.On(Blind) {
@@ -234,7 +234,7 @@ over:
g.direction = ch g.direction = ch
} }
goto over continue // the C goto over: re-dispatch as the run command
case 'F', 'f': case 'F', 'f':
if ch == 'F' { if ch == 'F' {
g.Kamikaze = true g.Kamikaze = true
@@ -266,7 +266,7 @@ over:
g.RunCh = g.DirCh g.RunCh = g.DirCh
ch = g.DirCh ch = g.DirCh
goto over continue // the C goto over: fight by running at it
} }
case 't': case 't':
if !g.getDir() { if !g.getDir() {
@@ -282,7 +282,7 @@ over:
ch = g.LastComm ch = g.LastComm
g.Again = true g.Again = true
goto over continue // the C goto over: replay the last command
} }
case 'q': case 'q':
g.quaff() g.quaff()
@@ -392,7 +392,7 @@ over:
ch = g.DirCh ch = g.DirCh
g.countCh = g.DirCh g.countCh = g.DirCh
goto over continue // the C goto over: move onto it without pickup
} }
case ')': case ')':
g.current(p.CurWeapon, "wielding", "") g.current(p.CurWeapon, "wielding", "")
@@ -416,6 +416,9 @@ over:
g.illcom(ch) g.illcom(ch)
} }
} }
return
}
} }
// wizardCommand handles the MASTER debug commands (command.c). // wizardCommand handles the MASTER debug commands (command.c).

View File

@@ -212,7 +212,7 @@ func (g *RogueGame) comeDown(int) {
// undo the things // undo the things
for _, tp := range g.Level.Objects { for _, tp := range g.Level.Objects {
if g.cansee(tp.Pos.Y, tp.Pos.X) { if g.canSee(tp.Pos.Y, tp.Pos.X) {
g.mvaddch(tp.Pos.Y, tp.Pos.X, tp.Kind.Glyph()) g.mvaddch(tp.Pos.Y, tp.Pos.X, tp.Kind.Glyph())
} }
} }
@@ -223,7 +223,7 @@ func (g *RogueGame) comeDown(int) {
for _, tp := range g.Level.Monsters { for _, tp := range g.Level.Monsters {
g.move(tp.Pos.Y, tp.Pos.X) g.move(tp.Pos.Y, tp.Pos.X)
if g.cansee(tp.Pos.Y, tp.Pos.X) { if g.canSee(tp.Pos.Y, tp.Pos.X) {
if !tp.On(Invisible) || p.On(CanSeeInvisible) { if !tp.On(Invisible) || p.On(CanSeeInvisible) {
g.addch(tp.Disguise) g.addch(tp.Disguise)
} else { } else {
@@ -248,13 +248,13 @@ func (g *RogueGame) visuals(int) {
} }
// change the things // change the things
for _, tp := range g.Level.Objects { for _, tp := range g.Level.Objects {
if g.cansee(tp.Pos.Y, tp.Pos.X) { if g.canSee(tp.Pos.Y, tp.Pos.X) {
g.mvaddch(tp.Pos.Y, tp.Pos.X, g.rndThing()) g.mvaddch(tp.Pos.Y, tp.Pos.X, g.rndThing())
} }
} }
// change the stairs // change the stairs
if !g.SeenStairs && g.cansee(g.Level.Stairs.Y, g.Level.Stairs.X) { if !g.SeenStairs && g.canSee(g.Level.Stairs.Y, g.Level.Stairs.X) {
g.mvaddch(g.Level.Stairs.Y, g.Level.Stairs.X, g.rndThing()) g.mvaddch(g.Level.Stairs.Y, g.Level.Stairs.X, g.rndThing())
} }

View File

@@ -10,7 +10,7 @@ func mkGameInput(t *testing.T) *RogueGame {
g := NewGame(Config{Seed: 5, Term: &testTerm{}}) g := NewGame(Config{Seed: 5, Term: &testTerm{}})
g.NewLevel() g.NewLevel()
g.Oldpos = g.Player.Pos g.Oldpos = g.Player.Pos
g.Oldrp = g.roomin(g.Player.Pos) g.Oldrp = g.roomIn(g.Player.Pos)
return g return g
} }

View File

@@ -47,7 +47,7 @@ func (g *RogueGame) fight(mp Coord, weap *Object, thrown bool) bool {
// place. // place.
g.Count = 0 g.Count = 0
g.Quiet = 0 g.Quiet = 0
g.runto(mp) g.runTo(mp)
// Let him know it was really a xeroc (if it was one). // Let him know it was really a xeroc (if it was one).
if tp.Type == 'X' && tp.Disguise != 'X' && !p.On(Blind) { if tp.Type == 'X' && tp.Disguise != 'X' && !p.On(Blind) {
tp.Disguise = 'X' tp.Disguise = 'X'
@@ -182,7 +182,7 @@ func (g *RogueGame) attack(mp *Monster) int {
// Rattlesnakes have poisonous bites // Rattlesnakes have poisonous bites
if !g.save(VsPoison) { if !g.save(VsPoison) {
if !p.IsWearing(RingSustainStrength) { if !p.IsWearing(RingSustainStrength) {
g.chgStr(-1) g.changeStrength(-1)
if !g.Options.Terse { if !g.Options.Terse {
g.msg("you feel a bite in your leg and now feel weaker") g.msg("you feel a bite in your leg and now feel weaker")

View File

@@ -10,7 +10,7 @@ func mkGame(t *testing.T, seed int32) *RogueGame {
g := NewGame(Config{Seed: seed, Term: &testTerm{}}) g := NewGame(Config{Seed: seed, Term: &testTerm{}})
g.NewLevel() g.NewLevel()
g.Oldpos = g.Player.Pos g.Oldpos = g.Player.Pos
g.Oldrp = g.roomin(g.Player.Pos) g.Oldrp = g.roomIn(g.Player.Pos)
return g return g
} }

View File

@@ -242,7 +242,7 @@ func (g *RogueGame) playit() {
g.Oldpos = g.Player.Pos g.Oldpos = g.Player.Pos
g.Oldrp = g.roomin(g.Player.Pos) g.Oldrp = g.roomIn(g.Player.Pos)
for g.Playing { for g.Playing {
g.command() // command execution g.command() // command execution
} }

View File

@@ -305,9 +305,9 @@ func (g *RogueGame) checkLevel() {
} }
} }
// chgStr modifies the player's strength, keeping track of the highest it // changeStrength modifies the player's strength, keeping track of the
// has been (misc.c chg_str). // highest it has been (misc.c chg_str).
func (g *RogueGame) chgStr(amt int) { func (g *RogueGame) changeStrength(amt int) {
if amt == 0 { if amt == 0 {
return return
} }
@@ -362,10 +362,10 @@ func (g *RogueGame) addHaste(potion bool) bool {
// aggravate aggravates all the monsters on this level (misc.c aggravate). // aggravate aggravates all the monsters on this level (misc.c aggravate).
func (g *RogueGame) aggravate() { func (g *RogueGame) aggravate() {
// runto() can splice the monster list while we walk it, so iterate a copy. // runTo() can splice the monster list while we walk it, so iterate a copy.
monsters := append([]*Monster(nil), g.Level.Monsters...) monsters := append([]*Monster(nil), g.Level.Monsters...)
for _, mp := range monsters { for _, mp := range monsters {
g.runto(mp.Pos) g.runTo(mp.Pos)
} }
} }

View File

@@ -37,7 +37,7 @@ func (g *RogueGame) newMonster(tp *Monster, typ byte, cp Coord) {
tp.Pos = cp tp.Pos = cp
g.move(cp.Y, cp.X) g.move(cp.Y, cp.X)
tp.OldCh = g.inch() tp.OldCh = g.inch()
tp.Room = g.roomin(cp) tp.Room = g.roomIn(cp)
g.Level.SetMonsterAt(cp.Y, cp.X, tp) g.Level.SetMonsterAt(cp.Y, cp.X, tp)
mp := &g.Monsters[tp.Type-'A'] mp := &g.Monsters[tp.Type-'A']
tp.Stats.Lvl = mp.Stats.Lvl + levAdd tp.Stats.Lvl = mp.Stats.Lvl + levAdd
@@ -57,7 +57,7 @@ func (g *RogueGame) newMonster(tp *Monster, typ byte, cp Coord) {
tp.Pack = nil tp.Pack = nil
if g.Player.IsWearing(RingAggravateMonsters) { if g.Player.IsWearing(RingAggravateMonsters) {
g.runto(cp) g.runTo(cp)
} }
if typ == 'X' { if typ == 'X' {
@@ -92,7 +92,7 @@ func (g *RogueGame) wanderer() {
var cp Coord var cp Coord
for { for {
cp, _ = g.findFloor(true) cp, _ = g.findFloor(true)
if g.roomin(cp) != g.Player.Room { if g.roomIn(cp) != g.Player.Room {
break break
} }
} }
@@ -111,7 +111,7 @@ func (g *RogueGame) wanderer() {
g.standend() g.standend()
} }
g.runto(tp.Pos) g.runTo(tp.Pos)
} }
// wakeMonster is what to do when the hero steps next to a monster // wakeMonster is what to do when the hero steps next to a monster

View File

@@ -2,16 +2,17 @@ package game
// move.c — hero movement commands. // move.c — hero movement commands.
// doRun starts the hero running (move.c do_run). // startRun starts the hero running (move.c do_run).
func (g *RogueGame) doRun(ch byte) { func (g *RogueGame) startRun(ch byte) {
g.Running = true g.Running = true
g.After = false g.After = false
g.RunCh = ch g.RunCh = ch
} }
// doMove checks that a move is legal and handles the consequences — // moveHero checks that a move is legal and handles the consequences —
// fighting, picking up, etc. (move.c do_move). // fighting, picking up, etc. (move.c do_move). The C `goto over`
func (g *RogueGame) doMove(dy, dx int) { // re-check after a passage turn is the retry loop.
func (g *RogueGame) moveHero(dy, dx int) {
p := &g.Player p := &g.Player
g.Firstmove = false g.Firstmove = false
@@ -24,7 +25,7 @@ func (g *RogueGame) doMove(dy, dx int) {
// Do a confused move (maybe) // Do a confused move (maybe)
var nh Coord var nh Coord
if p.On(Confused) && g.rnd(5) != 0 { if p.On(Confused) && g.rnd(5) != 0 {
nh = g.rndmove(&p.Creature) nh = g.randomStep(&p.Creature)
if nh == p.Pos { if nh == p.Pos {
g.After = false g.After = false
g.Running = false g.Running = false
@@ -36,9 +37,9 @@ func (g *RogueGame) doMove(dy, dx int) {
nh = Coord{Y: p.Pos.Y + dy, X: p.Pos.X + dx} nh = Coord{Y: p.Pos.Y + dy, X: p.Pos.X + dx}
} }
over: for {
// Check if he tried to move off the screen or make an illegal diagonal // Check if he tried to move off the screen or make an illegal
// move, and stop him if he did. // diagonal move, and stop him if he did.
hitBound := nh.X < 0 || nh.X >= NumCols || nh.Y <= 0 || nh.Y >= NumLines-1 hitBound := nh.X < 0 || nh.X >= NumCols || nh.Y <= 0 || nh.Y >= NumLines-1
var ( var (
@@ -81,8 +82,76 @@ over:
switch ch { switch ch {
case ' ', '|', '-': case ' ', '|', '-':
if g.Options.PassGo && g.Running && p.Room.Flags.Has(Gone) && if turn, ndy, ndx := g.passageTurn(dy, dx); turn {
!p.On(Blind) { dy, dx = ndy, ndx
g.turnRefresh()
nh = Coord{Y: p.Pos.Y + dy, X: p.Pos.X + dx}
continue // the C goto over: re-check the turned move
}
g.Running = false
g.After = false
case Door:
g.Running = false
if g.Level.FlagsAt(p.Pos.Y, p.Pos.X).Has(FPassage) {
g.enterRoom(nh)
}
g.finishMove(nh, fl)
case Trap:
tr := g.springTrap(nh)
if tr == TrapDoor || tr == TrapTeleport {
return
}
g.finishMove(nh, fl)
case Passage:
// when you're in a corridor, you don't know if you're in a maze
// room or not, and there ain't no way to find out if you're
// leaving a maze room, so it is necessary to always recalculate
// proom.
p.Room = g.roomIn(p.Pos)
g.finishMove(nh, fl)
case Floor:
if !fl.Has(FReal) {
g.springTrap(p.Pos)
}
g.finishMove(nh, fl)
default:
if ch == Stairs {
g.SeenStairs = true
}
g.Running = false
if isUpper(ch) || g.Level.MonsterAt(nh.Y, nh.X) != nil {
g.fight(nh, p.CurWeapon, false)
} else {
if ch != Stairs {
g.Take = ch
}
g.finishMove(nh, fl)
}
}
return
}
}
// passageTurn checks whether a runner in a gone-room passage should turn
// the corner instead of stopping at a wall (the PASSGO block of move.c
// do_move). It reports whether to turn and the new deltas, updating RunCh.
func (g *RogueGame) passageTurn(dy, dx int) (bool, int, int) {
p := &g.Player
if !g.Options.PassGo || !g.Running || !p.Room.Flags.Has(Gone) ||
p.On(Blind) {
return false, dy, dx
}
var b1, b2 bool var b1, b2 bool
switch g.RunCh { switch g.RunCh {
@@ -99,13 +168,7 @@ over:
dy = 1 dy = 1
} }
dx = 0 return true, dy, 0
g.turnref()
nh = Coord{Y: p.Pos.Y + dy, X: p.Pos.X + dx}
goto over
} }
case 'j', 'k': case 'j', 'k':
b1 = p.Pos.X != 0 && g.turnOk(p.Pos.Y, p.Pos.X-1) b1 = p.Pos.X != 0 && g.turnOk(p.Pos.Y, p.Pos.X-1)
@@ -120,66 +183,15 @@ over:
dx = 1 dx = 1
} }
dy = 0 return true, 0, dx
g.turnref()
nh = Coord{Y: p.Pos.Y + dy, X: p.Pos.X + dx}
goto over
}
} }
} }
g.Running = false return false, dy, dx
g.After = false
case Door:
g.Running = false
if g.Level.FlagsAt(p.Pos.Y, p.Pos.X).Has(FPassage) {
g.enterRoom(nh)
} }
g.moveStuff(nh, fl) // finishMove is the move_stuff label in do_move: complete the step.
case Trap: func (g *RogueGame) finishMove(nh Coord, fl PlaceFlags) {
tr := g.beTrapped(nh)
if tr == TrapDoor || tr == TrapTeleport {
return
}
g.moveStuff(nh, fl)
case Passage:
// when you're in a corridor, you don't know if you're in a maze
// room or not, and there ain't no way to find out if you're
// leaving a maze room, so it is necessary to always recalculate
// proom.
p.Room = g.roomin(p.Pos)
g.moveStuff(nh, fl)
case Floor:
if !fl.Has(FReal) {
g.beTrapped(p.Pos)
}
g.moveStuff(nh, fl)
default:
if ch == Stairs {
g.SeenStairs = true
}
g.Running = false
if isUpper(ch) || g.Level.MonsterAt(nh.Y, nh.X) != nil {
g.fight(nh, p.CurWeapon, false)
} else {
if ch != Stairs {
g.Take = ch
}
g.moveStuff(nh, fl)
}
}
}
// moveStuff is the move_stuff label in do_move: complete the step.
func (g *RogueGame) moveStuff(nh Coord, fl PlaceFlags) {
p := &g.Player p := &g.Player
g.mvaddch(p.Pos.Y, p.Pos.X, g.floorAt()) g.mvaddch(p.Pos.Y, p.Pos.X, g.floorAt())
@@ -198,8 +210,9 @@ func (g *RogueGame) turnOk(y, x int) bool {
return pp.Ch == Door || pp.Flags&(FReal|FPassage) == (FReal|FPassage) return pp.Ch == Door || pp.Flags&(FReal|FPassage) == (FReal|FPassage)
} }
// turnref decides whether to refresh at a passage turning (move.c turnref). // turnRefresh decides whether to refresh at a passage turning (move.c
func (g *RogueGame) turnref() { // turnref).
func (g *RogueGame) turnRefresh() {
p := &g.Player p := &g.Player
pp := g.Level.At(p.Pos.Y, p.Pos.X) pp := g.Level.At(p.Pos.Y, p.Pos.X)
@@ -228,8 +241,8 @@ func (g *RogueGame) doorOpen(rp *Room) {
} }
} }
// beTrapped makes him pay for stepping on a trap (move.c be_trapped). // springTrap makes him pay for stepping on a trap (move.c be_trapped).
func (g *RogueGame) beTrapped(tc Coord) TrapKind { func (g *RogueGame) springTrap(tc Coord) TrapKind {
p := &g.Player p := &g.Player
if p.On(Levitating) { if p.On(Levitating) {
return TrapRust // anything that's not a door or teleport return TrapRust // anything that's not a door or teleport
@@ -313,7 +326,7 @@ func (g *RogueGame) beTrapped(tc Coord) TrapKind {
} }
if !p.IsWearing(RingSustainStrength) && !g.save(VsPoison) { if !p.IsWearing(RingSustainStrength) && !g.save(VsPoison) {
g.chgStr(-1) g.changeStrength(-1)
} }
g.msg("a small dart just hit you in the shoulder") g.msg("a small dart just hit you in the shoulder")
@@ -328,9 +341,9 @@ func (g *RogueGame) beTrapped(tc Coord) TrapKind {
return tr return tr
} }
// rndmove moves in a random direction if the monster/person is confused // randomStep moves in a random direction if the monster/person is
// (move.c rndmove). // confused (move.c rndmove).
func (g *RogueGame) rndmove(who *Creature) Coord { func (g *RogueGame) randomStep(who *Creature) Coord {
ret := Coord{ ret := Coord{
Y: who.Pos.Y + g.rnd(3) - 1, Y: who.Pos.Y + g.rnd(3) - 1,
X: who.Pos.X + g.rnd(3) - 1, X: who.Pos.X + g.rnd(3) - 1,

View File

@@ -27,8 +27,8 @@ func (g *RogueGame) NewLevel() {
// go with them (the garbage collector is our free_list). // go with them (the garbage collector is our free_list).
g.Level.Monsters = nil g.Level.Monsters = nil
g.Level.Objects = nil g.Level.Objects = nil
g.doRooms() // Draw rooms g.digRooms() // Draw rooms
g.doPassages() // Draw passages g.digPassages() // Draw passages
p.NoFood++ p.NoFood++
@@ -61,7 +61,7 @@ func (g *RogueGame) NewLevel() {
g.SeenStairs = false g.SeenStairs = false
for _, tp := range g.Level.Monsters { for _, tp := range g.Level.Monsters {
tp.Room = g.roomin(tp.Pos) tp.Room = g.roomIn(tp.Pos)
} }
hero, _ := g.findFloor(true) hero, _ := g.findFloor(true)
@@ -78,8 +78,8 @@ func (g *RogueGame) NewLevel() {
} }
} }
// rndRoom picks a room that is really there (new_level.c rnd_room). // randomRoom picks a room that is really there (new_level.c rnd_room).
func (g *RogueGame) rndRoom() int { func (g *RogueGame) randomRoom() int {
for { for {
rm := g.rnd(MaxRooms) rm := g.rnd(MaxRooms)
if !g.Level.Rooms[rm].Flags.Has(Gone) { if !g.Level.Rooms[rm].Flags.Has(Gone) {
@@ -98,7 +98,7 @@ func (g *RogueGame) putThings() {
} }
// check for treasure rooms, and if so, put it in. // check for treasure rooms, and if so, put it in.
if g.rnd(treasRoomChance) == 0 { if g.rnd(treasRoomChance) == 0 {
g.treasRoom() g.treasureRoom()
} }
// Do MAXOBJ attempts to put things on a level // Do MAXOBJ attempts to put things on a level
for range MaxObj { for range MaxObj {
@@ -126,9 +126,9 @@ func (g *RogueGame) putThings() {
} }
} }
// treasRoom adds a treasure room (new_level.c treas_room). // treasureRoom adds a treasure room (new_level.c treas_room).
func (g *RogueGame) treasRoom() { func (g *RogueGame) treasureRoom() {
rp := &g.Level.Rooms[g.rndRoom()] rp := &g.Level.Rooms[g.randomRoom()]
spots := min((rp.Max.Y-2)*(rp.Max.X-2)-minTreas, maxTreas-minTreas) spots := min((rp.Max.Y-2)*(rp.Max.X-2)-minTreas, maxTreas-minTreas)

View File

@@ -2,8 +2,8 @@ package game
// passages.c — draw the connecting passages. // passages.c — draw the connecting passages.
// doPassages draws all the passages on a level (passages.c do_passages). // digPassages draws all the passages on a level (passages.c do_passages).
func (g *RogueGame) doPassages() { func (g *RogueGame) digPassages() {
var ( var (
isconn [MaxRooms][MaxRooms]bool isconn [MaxRooms][MaxRooms]bool
ingraph [MaxRooms]bool ingraph [MaxRooms]bool
@@ -41,7 +41,7 @@ func (g *RogueGame) doPassages() {
// otherwise, connect new room to the graph, and draw a tunnel // otherwise, connect new room to the graph, and draw a tunnel
// to it // to it
ingraph[r2] = true //nolint:gosec // G602: rnd(MaxRooms) bounded ingraph[r2] = true //nolint:gosec // G602: rnd(MaxRooms) bounded
g.conn(r1, r2) g.connectRooms(r1, r2)
isconn[r1][r2] = true isconn[r1][r2] = true
isconn[r2][r1] = true //nolint:gosec // G602: rnd(MaxRooms) bounded isconn[r2][r1] = true //nolint:gosec // G602: rnd(MaxRooms) bounded
roomcount++ roomcount++
@@ -69,18 +69,18 @@ func (g *RogueGame) doPassages() {
} }
// if there is one, connect it and look for the next added passage // if there is one, connect it and look for the next added passage
if j != 0 { if j != 0 {
g.conn(r1, r2) g.connectRooms(r1, r2)
isconn[r1][r2] = true isconn[r1][r2] = true
isconn[r2][r1] = true //nolint:gosec // G602: rnd(MaxRooms) bounded isconn[r2][r1] = true //nolint:gosec // G602: rnd(MaxRooms) bounded
} }
} }
g.passnum() g.numberPassages()
} }
// conn draws a corridor from a room in a certain direction (passages.c // connectRooms draws a corridor from a room in a certain direction
// conn). // (passages.c conn).
func (g *RogueGame) conn(r1, r2 int) { func (g *RogueGame) connectRooms(r1, r2 int) {
var ( var (
rm int rm int
direc byte direc byte
@@ -193,13 +193,13 @@ func (g *RogueGame) conn(r1, r2 int) {
if !rpf.Flags.Has(Gone) { if !rpf.Flags.Has(Gone) {
g.door(rpf, spos) g.door(rpf, spos)
} else { } else {
g.putpass(spos) g.putPassage(spos)
} }
if !rpt.Flags.Has(Gone) { if !rpt.Flags.Has(Gone) {
g.door(rpt, epos) g.door(rpt, epos)
} else { } else {
g.putpass(epos) g.putPassage(epos)
} }
// Get ready to move... // Get ready to move...
curr := spos curr := spos
@@ -210,13 +210,13 @@ func (g *RogueGame) conn(r1, r2 int) {
// Check if we are at the turn place, if so do the turn // Check if we are at the turn place, if so do the turn
if distance == turnSpot { if distance == turnSpot {
for ; turnDistance > 0; turnDistance-- { for ; turnDistance > 0; turnDistance-- {
g.putpass(curr) g.putPassage(curr)
curr.X += turnDelta.X curr.X += turnDelta.X
curr.Y += turnDelta.Y curr.Y += turnDelta.Y
} }
} }
// Continue digging along // Continue digging along
g.putpass(curr) g.putPassage(curr)
distance-- distance--
} }
@@ -229,9 +229,9 @@ func (g *RogueGame) conn(r1, r2 int) {
} }
} }
// putpass adds a passage character or secret passage here (passages.c // putPassage adds a passage character or secret passage here (passages.c
// putpass). // putpass).
func (g *RogueGame) putpass(cp Coord) { func (g *RogueGame) putPassage(cp Coord) {
pp := g.Level.At(cp.Y, cp.X) pp := g.Level.At(cp.Y, cp.X)
pp.Flags.Set(FPassage) pp.Flags.Set(FPassage)
@@ -302,8 +302,8 @@ func (g *RogueGame) addPass() {
} }
} }
// passnum assigns a number to each passageway (passages.c passnum). // numberPassages assigns a number to each passageway (passages.c passnum).
func (g *RogueGame) passnum() { func (g *RogueGame) numberPassages() {
g.pnum = 0 g.pnum = 0
g.newpnum = false g.newpnum = false
@@ -315,14 +315,14 @@ func (g *RogueGame) passnum() {
rp := &g.Level.Rooms[i] rp := &g.Level.Rooms[i]
for j := range rp.Exits { for j := range rp.Exits {
g.newpnum = true g.newpnum = true
g.numpass(rp.Exits[j].Y, rp.Exits[j].X) g.numberPassage(rp.Exits[j].Y, rp.Exits[j].X)
} }
} }
} }
// numpass numbers a passageway square and its brethren (passages.c // numberPassage numbers a passageway square and its brethren (passages.c
// numpass). // numpass).
func (g *RogueGame) numpass(y, x int) { func (g *RogueGame) numberPassage(y, x int) {
if x >= NumCols || x < 0 || y >= NumLines || y <= 0 { if x >= NumCols || x < 0 || y >= NumLines || y <= 0 {
return return
} }
@@ -348,10 +348,10 @@ func (g *RogueGame) numpass(y, x int) {
*fp |= PlaceFlags(g.pnum) //nolint:gosec // G115: pnum < MaxPass=13 *fp |= PlaceFlags(g.pnum) //nolint:gosec // G115: pnum < MaxPass=13
// recurse on the surrounding places // recurse on the surrounding places
g.numpass(y+1, x) g.numberPassage(y+1, x)
g.numpass(y-1, x) g.numberPassage(y-1, x)
g.numpass(y, x+1) g.numberPassage(y, x+1)
g.numpass(y, x-1) g.numberPassage(y, x-1)
} }
// abs is C abs() for ints. // abs is C abs() for ints.

View File

@@ -49,7 +49,7 @@ func (g *RogueGame) quaff() {
if p.IsWearing(RingSustainStrength) { if p.IsWearing(RingSustainStrength) {
g.msg("you feel momentarily sick") g.msg("you feel momentarily sick")
} else { } else {
g.chgStr(-(g.rnd(3) + 1)) g.changeStrength(-(g.rnd(3) + 1))
g.msg("you feel very sick now") g.msg("you feel very sick now")
g.comeDown(0) g.comeDown(0)
} }
@@ -64,7 +64,7 @@ func (g *RogueGame) quaff() {
g.msg("you begin to feel better") g.msg("you begin to feel better")
case PotionGainStrength: case PotionGainStrength:
g.Items.Potions[PotionGainStrength].Know = true g.Items.Potions[PotionGainStrength].Know = true
g.chgStr(1) g.changeStrength(1)
g.msg("you feel stronger, now. What bulging muscles!") g.msg("you feel stronger, now. What bulging muscles!")
case PotionDetectMonsters: case PotionDetectMonsters:
p.Flags.Set(SenseMonsters) p.Flags.Set(SenseMonsters)

View File

@@ -54,7 +54,7 @@ func (g *RogueGame) ringOn() {
// Calculate the effect it has on the poor guy. // Calculate the effect it has on the poor guy.
switch obj.RingKind() { switch obj.RingKind() {
case RingAddStrength: case RingAddStrength:
g.chgStr(obj.Bonus) g.changeStrength(obj.Bonus)
case RingSeeInvisible: case RingSeeInvisible:
g.invisOn() g.invisOn()
case RingAggravateMonsters: case RingAggravateMonsters:

View File

@@ -17,9 +17,9 @@ type mazeState struct {
const goldGrp = 1 const goldGrp = 1
// doRooms creates rooms and corridors with a connectivity graph (rooms.c // digRooms creates rooms and corridors with a connectivity graph (rooms.c
// do_rooms). // do_rooms).
func (g *RogueGame) doRooms() { func (g *RogueGame) digRooms() {
var bsze Coord // maximum room size var bsze Coord // maximum room size
bsze.X = NumCols / 3 bsze.X = NumCols / 3
@@ -34,7 +34,7 @@ func (g *RogueGame) doRooms() {
// Put the gone rooms, if any, on the level // Put the gone rooms, if any, on the level
leftOut := g.rnd(4) leftOut := g.rnd(4)
for range leftOut { for range leftOut {
g.Level.Rooms[g.rndRoom()].Flags.Set(Gone) g.Level.Rooms[g.randomRoom()].Flags.Set(Gone)
} }
// dig and populate all the rooms on the level // dig and populate all the rooms on the level
for i := range g.Level.Rooms { for i := range g.Level.Rooms {
@@ -126,7 +126,7 @@ func (g *RogueGame) doRooms() {
// rooms; for maze rooms, draws the maze (rooms.c draw_room). // rooms; for maze rooms, draws the maze (rooms.c draw_room).
func (g *RogueGame) drawRoom(rp *Room) { func (g *RogueGame) drawRoom(rp *Room) {
if rp.Flags.Has(Maze) { if rp.Flags.Has(Maze) {
g.doMaze(rp) g.digMaze(rp)
return return
} }
@@ -158,8 +158,8 @@ func (g *RogueGame) horiz(rp *Room, starty int) {
} }
} }
// doMaze digs a maze (rooms.c do_maze). // digMaze digs a maze (rooms.c do_maze).
func (g *RogueGame) doMaze(rp *Room) { func (g *RogueGame) digMaze(rp *Room) {
m := &g.maze m := &g.maze
for y := range m.maze { for y := range m.maze {
for x := range m.maze[y] { for x := range m.maze[y] {
@@ -175,7 +175,7 @@ func (g *RogueGame) doMaze(rp *Room) {
starty := (g.rnd(rp.Max.Y) / 2) * 2 starty := (g.rnd(rp.Max.Y) / 2) * 2
startx := (g.rnd(rp.Max.X) / 2) * 2 startx := (g.rnd(rp.Max.X) / 2) * 2
pos := Coord{Y: starty + m.starty, X: startx + m.startx} pos := Coord{Y: starty + m.starty, X: startx + m.startx}
g.putpass(pos) g.putPassage(pos)
g.dig(starty, startx) g.dig(starty, startx)
} }
@@ -211,8 +211,8 @@ func (g *RogueGame) dig(y, x int) {
return return
} }
g.accntMaze(y, x, nexty, nextx) g.accountMaze(y, x, nexty, nextx)
g.accntMaze(nexty, nextx, y, x) g.accountMaze(nexty, nextx, y, x)
var pos Coord var pos Coord
if nexty == y { if nexty == y {
@@ -231,16 +231,16 @@ func (g *RogueGame) dig(y, x int) {
} }
} }
g.putpass(pos) g.putPassage(pos)
pos.Y = nexty + m.starty pos.Y = nexty + m.starty
pos.X = nextx + m.startx pos.X = nextx + m.startx
g.putpass(pos) g.putPassage(pos)
g.dig(nexty, nextx) g.dig(nexty, nextx)
} }
} }
// accntMaze accounts for maze exits (rooms.c accnt_maze). // accountMaze accounts for maze exits (rooms.c accnt_maze).
func (g *RogueGame) accntMaze(y, x, ny, nx int) { func (g *RogueGame) accountMaze(y, x, ny, nx int) {
sp := &g.maze.maze[y][x] sp := &g.maze.maze[y][x]
for i := range sp.nexits { for i := range sp.nexits {
if sp.exits[i].Y == ny && sp.exits[i].X == nx { if sp.exits[i].Y == ny && sp.exits[i].X == nx {
@@ -255,8 +255,8 @@ func (g *RogueGame) accntMaze(y, x, ny, nx int) {
} }
} }
// rndPos picks a random spot in a room (rooms.c rnd_pos). // randomPos picks a random spot in a room (rooms.c rnd_pos).
func (g *RogueGame) rndPos(rp *Room) Coord { func (g *RogueGame) randomPos(rp *Room) Coord {
var cp Coord var cp Coord
cp.X = rp.Pos.X + g.rnd(rp.Max.X-2) + 1 cp.X = rp.Pos.X + g.rnd(rp.Max.X-2) + 1
@@ -296,7 +296,7 @@ func (g *RogueGame) findFloorImpl(rp *Room, limit int, monst, pickroom bool) (Co
} }
if pickroom { if pickroom {
rp = &g.Level.Rooms[g.rndRoom()] rp = &g.Level.Rooms[g.randomRoom()]
compchar = Floor compchar = Floor
if rp.Flags.Has(Maze) { if rp.Flags.Has(Maze) {
@@ -304,7 +304,7 @@ func (g *RogueGame) findFloorImpl(rp *Room, limit int, monst, pickroom bool) (Co
} }
} }
cp := g.rndPos(rp) cp := g.randomPos(rp)
pp := g.Level.At(cp.Y, cp.X) pp := g.Level.At(cp.Y, cp.X)
if monst { if monst {
@@ -321,7 +321,7 @@ func (g *RogueGame) findFloorImpl(rp *Room, limit int, monst, pickroom bool) (Co
// enter_room). // enter_room).
func (g *RogueGame) enterRoom(cp Coord) { func (g *RogueGame) enterRoom(cp Coord) {
p := &g.Player p := &g.Player
rp := g.roomin(cp) rp := g.roomIn(cp)
p.Room = rp p.Room = rp
g.doorOpen(rp) g.doorOpen(rp)

View File

@@ -449,12 +449,14 @@ func (g *RogueGame) applySnapshot(st *SaveState) {
g.scr.Std.SetContents(st.Screen) g.scr.Std.SetContents(st.Screen)
} }
// saveGame implements the "save game" command (save.c save_game). The C // saveGame implements the "save game" command (save.c save_game). The
// goto over/gotfile flow becomes the useDefault flag. // labeled prompt loop and the useDefault flag stand in for the C
// goto over/gotfile flow.
func (g *RogueGame) saveGame() { func (g *RogueGame) saveGame() {
g.Msgs.Mpos = 0 g.Msgs.Mpos = 0
over: prompt:
for {
useDefault := false useDefault := false
if g.FileName != "" { if g.FileName != "" {
@@ -522,7 +524,7 @@ over:
} }
if c == 'n' || c == 'N' { if c == 'n' || c == 'N' {
goto over continue prompt // the C goto over: start again
} }
g.msg("Please answer Y or N") g.msg("Please answer Y or N")
@@ -541,7 +543,8 @@ over:
continue continue
} }
break break prompt
}
} }
g.myExit() g.myExit()

View File

@@ -80,7 +80,7 @@ func (g *RogueGame) doZap() {
case WandInvisibility: case WandInvisibility:
tp.Flags.Set(Invisible) tp.Flags.Set(Invisible)
if g.cansee(y, x) { if g.canSee(y, x) {
g.mvaddch(y, x, tp.OldCh) g.mvaddch(y, x, tp.OldCh)
} }
case WandPolymorph: case WandPolymorph:
@@ -186,7 +186,7 @@ func (g *RogueGame) doZap() {
g.Delta.Y = y g.Delta.Y = y
g.Delta.X = x g.Delta.X = x
g.runto(g.Delta) g.runTo(g.Delta)
} }
case WandLightning, WandFire, WandCold: case WandLightning, WandFire, WandCold:
var name string var name string
@@ -243,7 +243,7 @@ func (g *RogueGame) drain() {
if mp.Stats.HP -= cnt; mp.Stats.HP <= 0 { if mp.Stats.HP -= cnt; mp.Stats.HP <= 0 {
g.killed(mp, g.seeMonst(mp)) g.killed(mp, g.seeMonst(mp))
} else { } else {
g.runto(mp.Pos) g.runTo(mp.Pos)
} }
} }
} }
@@ -339,7 +339,7 @@ func (g *RogueGame) fireBolt(start Coord, dir *Coord, name string) {
} }
} else if ch != 'M' || tp.Disguise == 'M' { } else if ch != 'M' || tp.Disguise == 'M' {
if fromHero { if fromHero {
g.runto(pos) g.runTo(pos)
} }
if g.Options.Terse { if g.Options.Terse {

View File

@@ -201,7 +201,7 @@ func (g *RogueGame) dropCheck(obj *Object) bool {
switch obj.RingKind() { switch obj.RingKind() {
case RingAddStrength: case RingAddStrength:
g.chgStr(-obj.Bonus) g.changeStrength(-obj.Bonus)
case RingSeeInvisible: case RingSeeInvisible:
g.unsee(0) g.unsee(0)
g.Extinguish(DUnsee) g.Extinguish(DUnsee)

View File

@@ -36,7 +36,7 @@ func (g *RogueGame) doMotion(obj *Object, ydelta, xdelta int) {
obj.Pos = p.Pos obj.Pos = p.Pos
for { for {
// Erase the old one // Erase the old one
if obj.Pos != p.Pos && g.cansee(obj.Pos.Y, obj.Pos.X) && !g.Options.Terse { if obj.Pos != p.Pos && g.canSee(obj.Pos.Y, obj.Pos.X) && !g.Options.Terse {
ch := g.Level.Char(obj.Pos.Y, obj.Pos.X) ch := g.Level.Char(obj.Pos.Y, obj.Pos.X)
if ch == Floor && !g.showFloor() { if ch == Floor && !g.showFloor() {
ch = ' ' ch = ' '
@@ -51,7 +51,7 @@ func (g *RogueGame) doMotion(obj *Object, ydelta, xdelta int) {
ch := g.Level.VisibleChar(obj.Pos.Y, obj.Pos.X) ch := g.Level.VisibleChar(obj.Pos.Y, obj.Pos.X)
if stepOk(ch) && ch != Door { if stepOk(ch) && ch != Door {
// It hasn't hit anything yet, so display it if it's alright. // It hasn't hit anything yet, so display it if it's alright.
if g.cansee(obj.Pos.Y, obj.Pos.X) && !g.Options.Terse { if g.canSee(obj.Pos.Y, obj.Pos.X) && !g.Options.Terse {
g.mvaddch(obj.Pos.Y, obj.Pos.X, obj.Kind.Glyph()) g.mvaddch(obj.Pos.Y, obj.Pos.X, obj.Kind.Glyph())
g.refresh() g.refresh()
} }
@@ -70,7 +70,7 @@ func (g *RogueGame) fall(obj *Object, pr bool) {
pp.Ch = obj.Kind.Glyph() pp.Ch = obj.Kind.Glyph()
obj.Pos = fpos obj.Pos = fpos
if g.cansee(fpos.Y, fpos.X) { if g.canSee(fpos.Y, fpos.X) {
if pp.Monst != nil { if pp.Monst != nil {
pp.Monst.OldCh = obj.Kind.Glyph() pp.Monst.OldCh = obj.Kind.Glyph()
} else { } else {

View File

@@ -181,7 +181,7 @@ func (g *RogueGame) teleport() {
g.mvaddch(p.Pos.Y, p.Pos.X, g.floorAt()) g.mvaddch(p.Pos.Y, p.Pos.X, g.floorAt())
c, _ := g.findFloor(true) c, _ := g.findFloor(true)
if g.roomin(c) != p.Room { if g.roomIn(c) != p.Room {
g.leaveRoom(p.Pos) g.leaveRoom(p.Pos)
p.Pos = c p.Pos = c
g.enterRoom(p.Pos) g.enterRoom(p.Pos)