Rename combat methods; -1 status codes become named bool results
Refactor step 5, combat: rollEm→rollAttacks; attack, moveMonster, and chaseStep return (removed bool) instead of the C -1/0 int codes. Behavior unchanged; suite green.
This commit is contained in:
@@ -13,12 +13,12 @@ func (g *RogueGame) runners(int) {
|
||||
origPos := tp.Pos
|
||||
|
||||
wastarget := tp.On(Targeted)
|
||||
if g.moveMonster(tp) == -1 {
|
||||
if removed := g.moveMonster(tp); removed {
|
||||
continue
|
||||
}
|
||||
|
||||
if tp.On(Flying) && distCp(g.Player.Pos, tp.Pos) >= 3 {
|
||||
if g.moveMonster(tp) == -1 {
|
||||
if removed := g.moveMonster(tp); removed {
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -38,23 +38,24 @@ func (g *RogueGame) runners(int) {
|
||||
}
|
||||
|
||||
// moveMonster executes a single turn of running for a monster (chase.c
|
||||
// move_monst). Returns -1 if the monster died or left the level.
|
||||
func (g *RogueGame) moveMonster(tp *Monster) int {
|
||||
// move_monst). removed reports that the monster died or left the level
|
||||
// (the C -1 return).
|
||||
func (g *RogueGame) moveMonster(tp *Monster) (removed bool) {
|
||||
if !tp.On(Slowed) || tp.Turn {
|
||||
if g.chaseStep(tp) == -1 {
|
||||
return -1
|
||||
if g.chaseStep(tp) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if tp.On(Hasted) {
|
||||
if g.chaseStep(tp) == -1 {
|
||||
return -1
|
||||
if g.chaseStep(tp) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
tp.Turn = !tp.Turn
|
||||
|
||||
return 0
|
||||
return false
|
||||
}
|
||||
|
||||
// relocate makes the monster's new location be the specified one, updating
|
||||
@@ -86,9 +87,10 @@ func (g *RogueGame) relocate(th *Monster, newLoc Coord) {
|
||||
}
|
||||
}
|
||||
|
||||
// chaseStep makes one thing chase another (chase.c do_chase). Returns -1
|
||||
// if the chaser died in the attempt.
|
||||
func (g *RogueGame) chaseStep(th *Monster) int {
|
||||
// chaseStep makes one thing chase another (chase.c do_chase). removed
|
||||
// reports that the chaser died or left the level in the attempt (the C
|
||||
// -1 return).
|
||||
func (g *RogueGame) chaseStep(th *Monster) (removed bool) {
|
||||
p := &g.Player
|
||||
stoprun := false // true means we are there
|
||||
mindist := 32767
|
||||
@@ -153,7 +155,7 @@ func (g *RogueGame) chaseStep(th *Monster) int {
|
||||
g.Kamikaze = false
|
||||
}
|
||||
|
||||
return 0
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +190,7 @@ func (g *RogueGame) chaseStep(th *Monster) int {
|
||||
}
|
||||
} else {
|
||||
if th.Type == 'F' {
|
||||
return 0
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +200,7 @@ func (g *RogueGame) chaseStep(th *Monster) int {
|
||||
th.Flags.Clear(Awake)
|
||||
}
|
||||
|
||||
return 0
|
||||
return false
|
||||
}
|
||||
|
||||
// chase finds the spot for the chaser to move closer to the chasee
|
||||
|
||||
Reference in New Issue
Block a user