Adopt house golangci-lint config; fix all approved-linter findings
.golangci.yml is the prompts-repo standard verbatim plus one approved
exception (paralleltest, sneak 2026-07-06). Roughly 1,500 findings
fixed:
- autofix sweep (wsl_v5/nlreturn/intrange/modernize formatting), with
the misspell autofix REVERTED where it rewrote authentic C game text
("missle vanishes" stays, with nolint and a comment)
- error handling: errcheck sites get real handling — saveFile now
closes explicitly and removes corrupt saves, scoreboard writes are
documented best-effort, err113 sentinel errors (ErrSaveOutOfDate,
ErrScreenTooSmall); panics allowed for unrecoverable states per
MEMORY.md policy
- gosec: real fixes (ParseInt for SEED, 0600 scorefile) and justified
per-line nolints for provably-bounded conversions (randomMonsterLetter
helper collapses eight rnd(26)+'A' sites)
- API tidying from linters: pointer receivers on flag types
(recvcheck), msg helpers renamed addmsgf/doaddf/Printwf/MvPrintwf
(goprintffuncname), myExit()/findFloor(monst)/mkGameInput(t) drop
always-constant params (unparam), gameEnd carries no status
- gocritic/staticcheck: if-else chains to switches, the pack.c
inventory filter untangled into matchesFilter, main.go split so
defers run before exit (exitAfterDefer, funlen)
- revive doc comments on all exported flag types/consts/methods
Remaining findings are confined to linters pending sneak's exception
decision (mnd, gochecknoglobals, cyclop, nestif, gocognit, exhaustive,
goconst, testpackage); TODO.md records the state. MEMORY.md added at
repo root as the project's agent working notes.
This commit is contained in:
@@ -21,6 +21,7 @@ const goldGrp = 1
|
||||
// do_rooms).
|
||||
func (g *RogueGame) doRooms() {
|
||||
var bsze Coord // maximum room size
|
||||
|
||||
bsze.X = NumCols / 3
|
||||
bsze.Y = NumLines / 3
|
||||
// Clear things for a new level
|
||||
@@ -32,7 +33,7 @@ func (g *RogueGame) doRooms() {
|
||||
}
|
||||
// Put the gone rooms, if any, on the level
|
||||
leftOut := g.rnd(4)
|
||||
for i := 0; i < leftOut; i++ {
|
||||
for range leftOut {
|
||||
g.Level.Rooms[g.rndRoom()].Flags.Set(Gone)
|
||||
}
|
||||
// dig and populate all the rooms on the level
|
||||
@@ -40,6 +41,7 @@ func (g *RogueGame) doRooms() {
|
||||
rp := &g.Level.Rooms[i]
|
||||
// Find upper left corner of box that this room goes in
|
||||
top := Coord{X: (i%3)*bsze.X + 1, Y: (i / 3) * bsze.Y}
|
||||
|
||||
if rp.Flags.Has(Gone) {
|
||||
// Place a gone room. Make certain that there is a blank line
|
||||
// for passage drawing.
|
||||
@@ -47,16 +49,19 @@ func (g *RogueGame) doRooms() {
|
||||
rp.Pos.X = top.X + g.rnd(bsze.X-2) + 1
|
||||
rp.Pos.Y = top.Y + g.rnd(bsze.Y-2) + 1
|
||||
rp.Max.X = -NumCols
|
||||
|
||||
rp.Max.Y = -NumLines
|
||||
if rp.Pos.Y > 0 && rp.Pos.Y < NumLines-1 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
// set room type
|
||||
if g.rnd(10) < g.Depth-1 {
|
||||
rp.Flags.Set(Dark) // dark room
|
||||
|
||||
if g.rnd(15) == 0 {
|
||||
rp.Flags = Maze // maze room
|
||||
}
|
||||
@@ -64,10 +69,12 @@ func (g *RogueGame) doRooms() {
|
||||
// Find a place and size for a random room
|
||||
if rp.Flags.Has(Maze) {
|
||||
rp.Max.X = bsze.X - 1
|
||||
|
||||
rp.Max.Y = bsze.Y - 1
|
||||
if rp.Pos.X = top.X; rp.Pos.X == 1 {
|
||||
rp.Pos.X = 0
|
||||
}
|
||||
|
||||
if rp.Pos.Y = top.Y; rp.Pos.Y == 0 {
|
||||
rp.Pos.Y++
|
||||
rp.Max.Y--
|
||||
@@ -77,12 +84,14 @@ func (g *RogueGame) doRooms() {
|
||||
rp.Max.X = g.rnd(bsze.X-4) + 4
|
||||
rp.Max.Y = g.rnd(bsze.Y-4) + 4
|
||||
rp.Pos.X = top.X + g.rnd(bsze.X-rp.Max.X)
|
||||
|
||||
rp.Pos.Y = top.Y + g.rnd(bsze.Y-rp.Max.Y)
|
||||
if rp.Pos.Y != 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.drawRoom(rp)
|
||||
// Put the gold in
|
||||
if g.rnd(2) == 0 && (!g.HasAmulet || g.Depth >= g.MaxDepth) {
|
||||
@@ -92,6 +101,7 @@ func (g *RogueGame) doRooms() {
|
||||
rp.Gold, _ = g.findFloorIn(rp, 0, false)
|
||||
gold.Pos = rp.Gold
|
||||
g.Level.SetChar(rp.Gold.Y, rp.Gold.X, Gold)
|
||||
|
||||
gold.Flags = Stackable
|
||||
gold.Group = goldGrp
|
||||
gold.Kind = KindGold
|
||||
@@ -102,6 +112,7 @@ func (g *RogueGame) doRooms() {
|
||||
if rp.GoldVal > 0 {
|
||||
prob = 80
|
||||
}
|
||||
|
||||
if g.rnd(100) < prob {
|
||||
tp := &Monster{}
|
||||
mp, _ := g.findFloorIn(rp, 0, true)
|
||||
@@ -116,8 +127,10 @@ func (g *RogueGame) doRooms() {
|
||||
func (g *RogueGame) drawRoom(rp *Room) {
|
||||
if rp.Flags.Has(Maze) {
|
||||
g.doMaze(rp)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
g.vert(rp, rp.Pos.X) // Draw left side
|
||||
g.vert(rp, rp.Pos.X+rp.Max.X-1) // Draw right side
|
||||
g.horiz(rp, rp.Pos.Y) // Draw top
|
||||
@@ -173,26 +186,34 @@ func (g *RogueGame) dig(y, x int) {
|
||||
|
||||
for {
|
||||
cnt := 0
|
||||
|
||||
var nexty, nextx int
|
||||
|
||||
for _, cp := range del {
|
||||
newy := y + cp.Y
|
||||
|
||||
newx := x + cp.X
|
||||
if newy < 0 || newy > m.maxy || newx < 0 || newx > m.maxx {
|
||||
continue
|
||||
}
|
||||
|
||||
if g.Level.FlagsAt(newy+m.starty, newx+m.startx).Has(FPassage) {
|
||||
continue
|
||||
}
|
||||
|
||||
if cnt++; g.rnd(cnt) == 0 {
|
||||
nexty = newy
|
||||
nextx = newx
|
||||
}
|
||||
}
|
||||
|
||||
if cnt == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
g.accntMaze(y, x, nexty, nextx)
|
||||
g.accntMaze(nexty, nextx, y, x)
|
||||
|
||||
var pos Coord
|
||||
if nexty == y {
|
||||
pos.Y = y + m.starty
|
||||
@@ -209,6 +230,7 @@ func (g *RogueGame) dig(y, x int) {
|
||||
pos.Y = nexty + m.starty - 1
|
||||
}
|
||||
}
|
||||
|
||||
g.putpass(pos)
|
||||
pos.Y = nexty + m.starty
|
||||
pos.X = nextx + m.startx
|
||||
@@ -220,7 +242,7 @@ func (g *RogueGame) dig(y, x int) {
|
||||
// accntMaze accounts for maze exits (rooms.c accnt_maze).
|
||||
func (g *RogueGame) accntMaze(y, x, ny, nx int) {
|
||||
sp := &g.maze.maze[y][x]
|
||||
for i := 0; i < sp.nexits; i++ {
|
||||
for i := range sp.nexits {
|
||||
if sp.exits[i].Y == ny && sp.exits[i].X == nx {
|
||||
return
|
||||
}
|
||||
@@ -236,15 +258,18 @@ func (g *RogueGame) accntMaze(y, x, ny, nx int) {
|
||||
// rndPos picks a random spot in a room (rooms.c rnd_pos).
|
||||
func (g *RogueGame) rndPos(rp *Room) Coord {
|
||||
var cp Coord
|
||||
|
||||
cp.X = rp.Pos.X + g.rnd(rp.Max.X-2) + 1
|
||||
cp.Y = rp.Pos.Y + g.rnd(rp.Max.Y-2) + 1
|
||||
|
||||
return cp
|
||||
}
|
||||
|
||||
// findFloor finds a valid floor spot, picking a new random room each time
|
||||
// around the loop (rooms.c find_floor with rp == NULL).
|
||||
func (g *RogueGame) findFloor(rp *Room, limit int, monst bool) (Coord, bool) {
|
||||
return g.findFloorImpl(rp, limit, monst, rp == nil)
|
||||
// around the loop; it retries forever (rooms.c find_floor with rp == NULL
|
||||
// — every such C call site passed FALSE for the limit).
|
||||
func (g *RogueGame) findFloor(monst bool) (Coord, bool) {
|
||||
return g.findFloorImpl(nil, 0, monst, true)
|
||||
}
|
||||
|
||||
// findFloorIn finds a valid floor spot in this room (rooms.c find_floor
|
||||
@@ -261,6 +286,7 @@ func (g *RogueGame) findFloorImpl(rp *Room, limit int, monst, pickroom bool) (Co
|
||||
compchar = Passage
|
||||
}
|
||||
}
|
||||
|
||||
cnt := limit
|
||||
for {
|
||||
if limit != 0 {
|
||||
@@ -268,14 +294,18 @@ func (g *RogueGame) findFloorImpl(rp *Room, limit int, monst, pickroom bool) (Co
|
||||
return Coord{}, false
|
||||
}
|
||||
}
|
||||
|
||||
if pickroom {
|
||||
rp = &g.Level.Rooms[g.rndRoom()]
|
||||
|
||||
compchar = Floor
|
||||
if rp.Flags.Has(Maze) {
|
||||
compchar = Passage
|
||||
}
|
||||
}
|
||||
|
||||
cp := g.rndPos(rp)
|
||||
|
||||
pp := g.Level.At(cp.Y, cp.X)
|
||||
if monst {
|
||||
if pp.Monst == nil && stepOk(pp.Ch) {
|
||||
@@ -294,11 +324,14 @@ func (g *RogueGame) enterRoom(cp Coord) {
|
||||
rp := g.roomin(cp)
|
||||
p.Room = rp
|
||||
g.doorOpen(rp)
|
||||
|
||||
if !rp.Flags.Has(Dark) && !p.On(Blind) {
|
||||
for y := rp.Pos.Y; y < rp.Max.Y+rp.Pos.Y; y++ {
|
||||
g.move(y, rp.Pos.X)
|
||||
|
||||
for x := rp.Pos.X; x < rp.Max.X+rp.Pos.X; x++ {
|
||||
tp := g.Level.MonsterAt(y, x)
|
||||
|
||||
ch := g.Level.Char(y, x)
|
||||
if tp == nil {
|
||||
if g.inch() != ch {
|
||||
@@ -335,6 +368,7 @@ func (g *RogueGame) leaveRoom(cp Coord) {
|
||||
}
|
||||
|
||||
var floor byte
|
||||
|
||||
switch {
|
||||
case rp.Flags.Has(Gone):
|
||||
floor = Passage
|
||||
@@ -348,6 +382,7 @@ func (g *RogueGame) leaveRoom(cp Coord) {
|
||||
for y := rp.Pos.Y; y < rp.Max.Y+rp.Pos.Y; y++ {
|
||||
for x := rp.Pos.X; x < rp.Max.X+rp.Pos.X; x++ {
|
||||
g.move(y, x)
|
||||
|
||||
switch ch := g.inch(); ch {
|
||||
case Floor:
|
||||
if floor == ' ' {
|
||||
@@ -361,8 +396,10 @@ func (g *RogueGame) leaveRoom(cp Coord) {
|
||||
g.standout()
|
||||
g.addch(ch)
|
||||
g.standend()
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
pp := g.Level.At(y, x)
|
||||
if pp.Ch == Door {
|
||||
g.addch(Door)
|
||||
@@ -373,5 +410,6 @@ func (g *RogueGame) leaveRoom(cp Coord) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.doorOpen(rp)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user