Decompose remaining effects-file hot spots (refactor step 7)
drain gains drainReaches; zapSpeed gains hasteTarget/slowTarget; readHoldMonster gains holdMonstersNear; readCreateMonster gains createMonsterSpot; revealSpot splits into revealChar/revealWall/ revealSolid/revealFloor; turnSee gains showSensed. potions.go, scrolls.go, and sticks.go are complexity-clean. Behavior and RNG call order unchanged.
This commit is contained in:
@@ -229,31 +229,46 @@ func (g *RogueGame) zapMagicMissile(*Object) bool {
|
||||
}
|
||||
|
||||
func (g *RogueGame) zapSpeed(obj *Object) bool {
|
||||
if tp := g.zapRayMonster(); tp != nil {
|
||||
if obj.WandKind() == WandHasteMonster {
|
||||
if tp.On(Slowed) {
|
||||
tp.Flags.Clear(Slowed)
|
||||
} else {
|
||||
tp.Flags.Set(Hasted)
|
||||
}
|
||||
} else {
|
||||
if tp.On(Hasted) {
|
||||
tp.Flags.Clear(Hasted)
|
||||
} else {
|
||||
tp.Flags.Set(Slowed)
|
||||
}
|
||||
|
||||
tp.Turn = true
|
||||
}
|
||||
|
||||
g.Delta.Y = tp.Pos.Y
|
||||
g.Delta.X = tp.Pos.X
|
||||
g.runTo(g.Delta)
|
||||
tp := g.zapRayMonster()
|
||||
if tp == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
if obj.WandKind() == WandHasteMonster {
|
||||
hasteTarget(tp)
|
||||
} else {
|
||||
slowTarget(tp)
|
||||
}
|
||||
|
||||
g.Delta.Y = tp.Pos.Y
|
||||
g.Delta.X = tp.Pos.X
|
||||
g.runTo(g.Delta)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// hasteTarget cancels a slow or applies a haste (the WS_HASTE_M arm of
|
||||
// do_zap).
|
||||
func hasteTarget(tp *Monster) {
|
||||
if tp.On(Slowed) {
|
||||
tp.Flags.Clear(Slowed)
|
||||
} else {
|
||||
tp.Flags.Set(Hasted)
|
||||
}
|
||||
}
|
||||
|
||||
// slowTarget cancels a haste or applies a slow (the WS_SLOW_M arm of
|
||||
// do_zap).
|
||||
func slowTarget(tp *Monster) {
|
||||
if tp.On(Hasted) {
|
||||
tp.Flags.Clear(Hasted)
|
||||
} else {
|
||||
tp.Flags.Set(Slowed)
|
||||
}
|
||||
|
||||
tp.Turn = true
|
||||
}
|
||||
|
||||
func (g *RogueGame) zapBolt(obj *Object) bool {
|
||||
var name string
|
||||
|
||||
@@ -286,9 +301,7 @@ func (g *RogueGame) drain() {
|
||||
var drainee []*Monster
|
||||
|
||||
for _, mp := range g.Level.Monsters {
|
||||
if mp.Room == p.Room || mp.Room == corp ||
|
||||
(inpass && g.Level.Char(mp.Pos.Y, mp.Pos.X) == Door &&
|
||||
&g.Level.Passages[*g.Level.FlagsAt(mp.Pos.Y, mp.Pos.X)&FPassNum] == p.Room) {
|
||||
if g.drainReaches(mp, corp, inpass) {
|
||||
drainee = append(drainee, mp)
|
||||
}
|
||||
}
|
||||
@@ -312,6 +325,18 @@ func (g *RogueGame) drain() {
|
||||
}
|
||||
}
|
||||
|
||||
// drainReaches reports whether the drain-life wand reaches this monster:
|
||||
// the hero's room, the passage behind the door he stands on, or — when
|
||||
// he is in a passage — a door of that same passage (the drainee
|
||||
// condition of sticks.c drain).
|
||||
func (g *RogueGame) drainReaches(mp *Monster, corp *Room, inpass bool) bool {
|
||||
p := &g.Player
|
||||
|
||||
return mp.Room == p.Room || mp.Room == corp ||
|
||||
(inpass && g.Level.Char(mp.Pos.Y, mp.Pos.X) == Door &&
|
||||
&g.Level.Passages[*g.Level.FlagsAt(mp.Pos.Y, mp.Pos.X)&FPassNum] == p.Room)
|
||||
}
|
||||
|
||||
// fireBolt fires a bolt in a given direction from a specific starting
|
||||
// place (sticks.c fire_bolt).
|
||||
func (g *RogueGame) fireBolt(start Coord, dir *Coord, name string) {
|
||||
|
||||
Reference in New Issue
Block a user