Finish score/wakeMonster tidy (scoreSlot; drop unused return)

This commit is contained in:
2026-07-22 22:02:02 +07:00
parent 8895db530d
commit ff7ee95395
2 changed files with 21 additions and 18 deletions

View File

@@ -116,7 +116,7 @@ func (g *RogueGame) wanderer() {
// wakeMonster is what to do when the hero steps next to a monster
// (monsters.c wake_monster).
func (g *RogueGame) wakeMonster(y, x int) *Monster {
func (g *RogueGame) wakeMonster(y, x int) {
p := &g.Player
tp := g.Level.MonsterAt(y, x)
@@ -143,8 +143,6 @@ func (g *RogueGame) wakeMonster(y, x int) *Monster {
tp.Dest = &p.Pos
}
}
return tp
}
// meanWakes decides whether a sleeping mean monster starts the chase

View File

@@ -126,21 +126,7 @@ func (g *RogueGame) score(amount, flags int, monst byte) {
func (g *RogueGame) scoreInsert(topTen []ScoreEnt, amount, flags int, monst byte) int {
uid := os.Getuid()
scp := len(topTen)
for i := range topTen {
if amount > topTen[i].Score {
scp = i
break
} else if !g.AllScore && flags != 2 &&
topTen[i].UID == uid && topTen[i].Flags != 2 {
// only one score per nowin uid
scp = len(topTen)
break
}
}
scp := g.scoreSlot(topTen, amount, flags, uid)
if scp >= len(topTen) {
return -1
}
@@ -179,6 +165,25 @@ func (g *RogueGame) scoreInsert(topTen []ScoreEnt, amount, flags int, monst byte
return scp
}
// scoreSlot finds where the new score lands: len(topTen) when it does
// not place, or when this uid already holds a losing score (the scan of
// rip.c score).
func (g *RogueGame) scoreSlot(topTen []ScoreEnt, amount, flags, uid int) int {
for i := range topTen {
if amount > topTen[i].Score {
return i
}
if !g.AllScore && flags != 2 &&
topTen[i].UID == uid && topTen[i].Flags != 2 {
// only one score per nowin uid
return len(topTen)
}
}
return len(topTen)
}
// scoreLines formats the scoreboard, noting which display line holds
// the freshly inserted score (the display half of rip.c score).
func (g *RogueGame) scoreLines(topTen []ScoreEnt, ins int) ([]string, int) {