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:
@@ -67,7 +67,7 @@ func (g *RogueGame) fight(mp Coord, weap *Object, thrown bool) bool {
|
||||
didHit := false
|
||||
|
||||
g.HasHit = g.Options.Terse && !g.ToDeath
|
||||
if g.rollEm(&p.Creature, &tp.Creature, weap, thrown) {
|
||||
if g.rollAttacks(&p.Creature, &tp.Creature, weap, thrown) {
|
||||
didHit = false
|
||||
|
||||
if thrown {
|
||||
@@ -104,9 +104,10 @@ func (g *RogueGame) fight(mp Coord, weap *Object, thrown bool) bool {
|
||||
return didHit
|
||||
}
|
||||
|
||||
// attack has the monster attack the player (fight.c attack). Returns -1 if
|
||||
// the monster removed itself from the level during its own attack.
|
||||
func (g *RogueGame) attack(mp *Monster) int {
|
||||
// attack has the monster attack the player (fight.c attack). removed
|
||||
// reports that the monster took itself off the level during its own
|
||||
// attack (the C -1 return).
|
||||
func (g *RogueGame) attack(mp *Monster) (removed bool) {
|
||||
p := &g.Player
|
||||
// Since this is an attack, stop running and any healing that was
|
||||
// going on at the time.
|
||||
@@ -128,9 +129,8 @@ func (g *RogueGame) attack(mp *Monster) int {
|
||||
|
||||
mname := g.setMname(mp)
|
||||
oldhp := p.Stats.HP
|
||||
removed := false
|
||||
|
||||
if g.rollEm(&mp.Creature, &p.Creature, nil, false) {
|
||||
if g.rollAttacks(&mp.Creature, &p.Creature, nil, false) {
|
||||
if mp.Type != 'I' {
|
||||
if g.HasHit {
|
||||
g.addmsgf(". ")
|
||||
@@ -317,11 +317,7 @@ func (g *RogueGame) attack(mp *Monster) int {
|
||||
g.Count = 0
|
||||
g.status()
|
||||
|
||||
if removed {
|
||||
return -1
|
||||
}
|
||||
|
||||
return 0
|
||||
return removed
|
||||
}
|
||||
|
||||
// swing returns true if the swing hits (fight.c swing).
|
||||
@@ -332,8 +328,8 @@ func (g *RogueGame) swing(atLvl, opArm, wplus int) bool {
|
||||
return res+wplus >= need
|
||||
}
|
||||
|
||||
// rollEm rolls several attacks (fight.c roll_em).
|
||||
func (g *RogueGame) rollEm(thatt, thdef *Creature, weap *Object, hurl bool) bool {
|
||||
// rollAttacks rolls several attacks (fight.c roll_em).
|
||||
func (g *RogueGame) rollAttacks(thatt, thdef *Creature, weap *Object, hurl bool) bool {
|
||||
p := &g.Player
|
||||
att := &thatt.Stats
|
||||
def := &thdef.Stats
|
||||
|
||||
Reference in New Issue
Block a user