Finish score/wakeMonster tidy (scoreSlot; drop unused return)
This commit is contained in:
@@ -116,7 +116,7 @@ func (g *RogueGame) wanderer() {
|
|||||||
|
|
||||||
// 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
|
||||||
// (monsters.c wake_monster).
|
// (monsters.c wake_monster).
|
||||||
func (g *RogueGame) wakeMonster(y, x int) *Monster {
|
func (g *RogueGame) wakeMonster(y, x int) {
|
||||||
p := &g.Player
|
p := &g.Player
|
||||||
|
|
||||||
tp := g.Level.MonsterAt(y, x)
|
tp := g.Level.MonsterAt(y, x)
|
||||||
@@ -143,8 +143,6 @@ func (g *RogueGame) wakeMonster(y, x int) *Monster {
|
|||||||
tp.Dest = &p.Pos
|
tp.Dest = &p.Pos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// meanWakes decides whether a sleeping mean monster starts the chase
|
// meanWakes decides whether a sleeping mean monster starts the chase
|
||||||
|
|||||||
@@ -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 {
|
func (g *RogueGame) scoreInsert(topTen []ScoreEnt, amount, flags int, monst byte) int {
|
||||||
uid := os.Getuid()
|
uid := os.Getuid()
|
||||||
|
|
||||||
scp := len(topTen)
|
scp := g.scoreSlot(topTen, amount, flags, uid)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if scp >= len(topTen) {
|
if scp >= len(topTen) {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
@@ -179,6 +165,25 @@ func (g *RogueGame) scoreInsert(topTen []ScoreEnt, amount, flags int, monst byte
|
|||||||
return scp
|
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
|
// scoreLines formats the scoreboard, noting which display line holds
|
||||||
// the freshly inserted score (the display half of rip.c score).
|
// the freshly inserted score (the display half of rip.c score).
|
||||||
func (g *RogueGame) scoreLines(topTen []ScoreEnt, ins int) ([]string, int) {
|
func (g *RogueGame) scoreLines(topTen []ScoreEnt, ins int) ([]string, int) {
|
||||||
|
|||||||
Reference in New Issue
Block a user