.golangci.yml is the prompts-repo standard verbatim plus one approved
exception (paralleltest, sneak 2026-07-06). Roughly 1,500 findings
fixed:
- autofix sweep (wsl_v5/nlreturn/intrange/modernize formatting), with
the misspell autofix REVERTED where it rewrote authentic C game text
("missle vanishes" stays, with nolint and a comment)
- error handling: errcheck sites get real handling — saveFile now
closes explicitly and removes corrupt saves, scoreboard writes are
documented best-effort, err113 sentinel errors (ErrSaveOutOfDate,
ErrScreenTooSmall); panics allowed for unrecoverable states per
MEMORY.md policy
- gosec: real fixes (ParseInt for SEED, 0600 scorefile) and justified
per-line nolints for provably-bounded conversions (randomMonsterLetter
helper collapses eight rnd(26)+'A' sites)
- API tidying from linters: pointer receivers on flag types
(recvcheck), msg helpers renamed addmsgf/doaddf/Printwf/MvPrintwf
(goprintffuncname), myExit()/findFloor(monst)/mkGameInput(t) drop
always-constant params (unparam), gameEnd carries no status
- gocritic/staticcheck: if-else chains to switches, the pack.c
inventory filter untangled into matchesFilter, main.go split so
defers run before exit (exitAfterDefer, funlen)
- revive doc comments on all exported flag types/consts/methods
Remaining findings are confined to linters pending sneak's exception
decision (mnd, gochecknoglobals, cyclop, nestif, gocognit, exhaustive,
goconst, testpackage); TODO.md records the state. MEMORY.md added at
repo root as the project's agent working notes.
410 lines
8.2 KiB
Go
410 lines
8.2 KiB
Go
package game
|
|
|
|
import "fmt"
|
|
|
|
// sticks.c — zap wands and staffs.
|
|
|
|
// doZap performs a zap with a wand (sticks.c do_zap).
|
|
func (g *RogueGame) doZap() {
|
|
p := &g.Player
|
|
|
|
obj := g.getItem("zap with", KindWand)
|
|
if obj == nil {
|
|
return
|
|
}
|
|
|
|
if obj.Kind != KindWand {
|
|
g.After = false
|
|
g.msg("you can't zap with that!")
|
|
|
|
return
|
|
}
|
|
|
|
if obj.Charges == 0 {
|
|
g.msg("nothing happens")
|
|
|
|
return
|
|
}
|
|
|
|
switch obj.WandKind() {
|
|
case WandLight:
|
|
// Reddy Kilowatt wand. Light up the room
|
|
g.Items.Sticks[WandLight].Know = true
|
|
if p.Room.Flags.Has(Gone) {
|
|
g.msg("the corridor glows and then fades")
|
|
} else {
|
|
p.Room.Flags.Clear(Dark)
|
|
// Light the room and put the player back up
|
|
g.enterRoom(p.Pos)
|
|
g.addmsgf("the room is lit")
|
|
|
|
if !g.Options.Terse {
|
|
g.addmsgf(" by a shimmering %s light", g.pickColor("blue"))
|
|
}
|
|
|
|
g.endmsg()
|
|
}
|
|
case WandDrainLife:
|
|
// take away 1/2 of hero's hit points, then take it away evenly
|
|
// from the monsters in the room (or next to hero if he is in a
|
|
// passage)
|
|
if p.Stats.HP < 2 {
|
|
g.msg("you are too weak to use it")
|
|
|
|
return
|
|
}
|
|
|
|
g.drain()
|
|
case WandInvisibility, WandPolymorph, WandTeleportAway, WandTeleportTo, WandCancellation:
|
|
y := p.Pos.Y
|
|
|
|
x := p.Pos.X
|
|
for stepOk(g.Level.VisibleChar(y, x)) {
|
|
y += g.Delta.Y
|
|
x += g.Delta.X
|
|
}
|
|
|
|
if tp := g.Level.MonsterAt(y, x); tp != nil {
|
|
monster := tp.Type
|
|
if monster == 'F' {
|
|
p.Flags.Clear(Held)
|
|
}
|
|
|
|
switch obj.WandKind() {
|
|
case WandInvisibility:
|
|
tp.Flags.Set(Invisible)
|
|
|
|
if g.cansee(y, x) {
|
|
g.mvaddch(y, x, tp.OldCh)
|
|
}
|
|
case WandPolymorph:
|
|
pp := tp.Pack
|
|
detachMon(&g.Level.Monsters, tp)
|
|
|
|
if g.seeMonst(tp) {
|
|
g.mvaddch(y, x, g.Level.Char(y, x))
|
|
}
|
|
|
|
oldch := tp.OldCh
|
|
g.Delta.Y = y
|
|
g.Delta.X = x
|
|
monster = g.randomMonsterLetter()
|
|
g.newMonster(tp, monster, g.Delta)
|
|
|
|
if g.seeMonst(tp) {
|
|
g.mvaddch(y, x, monster)
|
|
}
|
|
|
|
tp.OldCh = oldch
|
|
|
|
tp.Pack = pp
|
|
if g.seeMonst(tp) {
|
|
g.Items.Sticks[WandPolymorph].Know = true
|
|
}
|
|
case WandCancellation:
|
|
tp.Flags.Set(Cancelled)
|
|
tp.Flags.Clear(Invisible | CanConfuse)
|
|
|
|
tp.Disguise = tp.Type
|
|
if g.seeMonst(tp) {
|
|
g.mvaddch(y, x, tp.Disguise)
|
|
}
|
|
case WandTeleportAway, WandTeleportTo:
|
|
var newPos Coord
|
|
|
|
if obj.WandKind() == WandTeleportAway {
|
|
for {
|
|
newPos, _ = g.findFloor(true)
|
|
if newPos != p.Pos {
|
|
break
|
|
}
|
|
}
|
|
} else {
|
|
newPos.Y = p.Pos.Y + g.Delta.Y
|
|
newPos.X = p.Pos.X + g.Delta.X
|
|
}
|
|
|
|
tp.Dest = &p.Pos
|
|
tp.Flags.Set(Awake)
|
|
g.relocate(tp, newPos)
|
|
}
|
|
}
|
|
case WandMagicMissile:
|
|
g.Items.Sticks[WandMagicMissile].Know = true
|
|
bolt := newObject()
|
|
bolt.Kind = KindGold // C set o_type='*': draws a '*' and is not a weapon
|
|
bolt.HurlDmg = dice("1x4")
|
|
bolt.HPlus = 100
|
|
bolt.DPlus = 1
|
|
|
|
bolt.Flags = Missile
|
|
if p.CurWeapon != nil {
|
|
bolt.Launch = WeaponKind(p.CurWeapon.Which)
|
|
}
|
|
|
|
g.doMotion(bolt, g.Delta.Y, g.Delta.X)
|
|
|
|
if tp := g.Level.MonsterAt(bolt.Pos.Y, bolt.Pos.X); tp != nil &&
|
|
!g.saveThrow(VsMagic, &tp.Stats) {
|
|
g.hitMonster(bolt.Pos, bolt)
|
|
} else if g.Options.Terse {
|
|
g.msg("missle vanishes") //nolint:misspell // C's spelling, kept faithfully
|
|
} else {
|
|
g.msg("the missle vanishes with a puff of smoke") //nolint:misspell // C's spelling
|
|
}
|
|
case WandHasteMonster, WandSlowMonster:
|
|
y := p.Pos.Y
|
|
|
|
x := p.Pos.X
|
|
for stepOk(g.Level.VisibleChar(y, x)) {
|
|
y += g.Delta.Y
|
|
x += g.Delta.X
|
|
}
|
|
|
|
if tp := g.Level.MonsterAt(y, x); 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 = y
|
|
g.Delta.X = x
|
|
g.runto(g.Delta)
|
|
}
|
|
case WandLightning, WandFire, WandCold:
|
|
var name string
|
|
|
|
switch obj.WandKind() {
|
|
case WandLightning:
|
|
name = "bolt"
|
|
case WandFire:
|
|
name = "flame"
|
|
default:
|
|
name = "ice"
|
|
}
|
|
|
|
g.fireBolt(p.Pos, &g.Delta, name)
|
|
g.Items.Sticks[obj.Which].Know = true
|
|
case WandNothing:
|
|
}
|
|
|
|
obj.Charges--
|
|
}
|
|
|
|
// drain does the drain-hit-points-from-player schtick (sticks.c drain).
|
|
func (g *RogueGame) drain() {
|
|
p := &g.Player
|
|
// First count how many things we need to spread the hit points among
|
|
var corp *Room
|
|
if g.Level.Char(p.Pos.Y, p.Pos.X) == Door {
|
|
corp = &g.Level.Passages[*g.Level.FlagsAt(p.Pos.Y, p.Pos.X)&FPassNum]
|
|
}
|
|
|
|
inpass := p.Room.Flags.Has(Gone)
|
|
|
|
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) {
|
|
drainee = append(drainee, mp)
|
|
}
|
|
}
|
|
|
|
cnt := len(drainee)
|
|
if cnt == 0 {
|
|
g.msg("you have a tingling feeling")
|
|
|
|
return
|
|
}
|
|
|
|
p.Stats.HP /= 2
|
|
cnt = p.Stats.HP / cnt
|
|
// Now zot all of the monsters
|
|
for _, mp := range drainee {
|
|
if mp.Stats.HP -= cnt; mp.Stats.HP <= 0 {
|
|
g.killed(mp, g.seeMonst(mp))
|
|
} else {
|
|
g.runto(mp.Pos)
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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) {
|
|
p := &g.Player
|
|
fromHero := start == p.Pos
|
|
|
|
bolt := newObject()
|
|
bolt.Kind = KindWeapon
|
|
bolt.Which = int(WeaponFlame)
|
|
bolt.HurlDmg = dice("6x6")
|
|
bolt.HPlus = 100
|
|
bolt.DPlus = 0
|
|
g.Items.Weapons[WeaponFlame].Name = name
|
|
|
|
var dirch byte
|
|
|
|
switch dir.Y + dir.X {
|
|
case 0:
|
|
dirch = '/'
|
|
case 1, -1:
|
|
if dir.Y == 0 {
|
|
dirch = '-'
|
|
} else {
|
|
dirch = '|'
|
|
}
|
|
case 2, -2:
|
|
dirch = '\\'
|
|
}
|
|
|
|
pos := start
|
|
hitHero := !fromHero
|
|
used := false
|
|
changed := false
|
|
|
|
var spotpos []Coord
|
|
for len(spotpos) < BoltLength && !used {
|
|
pos.Y += dir.Y
|
|
pos.X += dir.X
|
|
spotpos = append(spotpos, pos)
|
|
ch := g.Level.VisibleChar(pos.Y, pos.X)
|
|
bounce := false
|
|
|
|
switch ch {
|
|
case Door:
|
|
// this code is necessary if the hero is on a door and he
|
|
// fires at the wall the door is in, it would otherwise loop
|
|
// infinitely
|
|
if p.Pos != pos {
|
|
bounce = true
|
|
}
|
|
case '|', '-', ' ':
|
|
bounce = true
|
|
}
|
|
|
|
if bounce {
|
|
if !changed {
|
|
hitHero = !hitHero
|
|
}
|
|
|
|
changed = false
|
|
dir.Y = -dir.Y
|
|
dir.X = -dir.X
|
|
spotpos = spotpos[:len(spotpos)-1]
|
|
|
|
g.msg("the %s bounces", name)
|
|
|
|
continue
|
|
}
|
|
|
|
if tp := g.Level.MonsterAt(pos.Y, pos.X); !hitHero && tp != nil {
|
|
hitHero = true
|
|
changed = !changed
|
|
|
|
tp.OldCh = g.Level.Char(pos.Y, pos.X)
|
|
if !g.saveThrow(VsMagic, &tp.Stats) {
|
|
bolt.Pos = pos
|
|
used = true
|
|
|
|
if tp.Type == 'D' && name == "flame" {
|
|
g.addmsgf("the flame bounces")
|
|
|
|
if !g.Options.Terse {
|
|
g.addmsgf(" off the dragon")
|
|
}
|
|
|
|
g.endmsg()
|
|
} else {
|
|
g.hitMonster(pos, bolt)
|
|
}
|
|
} else if ch != 'M' || tp.Disguise == 'M' {
|
|
if fromHero {
|
|
g.runto(pos)
|
|
}
|
|
|
|
if g.Options.Terse {
|
|
g.msg("%s misses", name)
|
|
} else {
|
|
g.msg("the %s whizzes past %s", name, g.setMname(tp))
|
|
}
|
|
}
|
|
} else if hitHero && pos == p.Pos {
|
|
hitHero = false
|
|
changed = !changed
|
|
|
|
if !g.save(VsMagic) {
|
|
if p.Stats.HP -= g.roll(6, 6); p.Stats.HP <= 0 {
|
|
if fromHero {
|
|
g.death('b')
|
|
} else {
|
|
g.death(g.Level.MonsterAt(start.Y, start.X).Type)
|
|
}
|
|
}
|
|
|
|
used = true
|
|
|
|
if g.Options.Terse {
|
|
g.msg("the %s hits", name)
|
|
} else {
|
|
g.msg("you are hit by the %s", name)
|
|
}
|
|
} else {
|
|
g.msg("the %s whizzes by you", name)
|
|
}
|
|
}
|
|
|
|
g.mvaddch(pos.Y, pos.X, dirch)
|
|
g.refresh()
|
|
}
|
|
// erase the bolt trail
|
|
for _, c2 := range spotpos {
|
|
g.mvaddch(c2.Y, c2.X, g.Level.Char(c2.Y, c2.X))
|
|
}
|
|
}
|
|
|
|
// fixStick sets up a new wand or staff (sticks.c fix_stick).
|
|
func (g *RogueGame) fixStick(cur *Object) {
|
|
if g.Items.WandType[cur.Which] == "staff" {
|
|
cur.Damage = dice("2x3")
|
|
} else {
|
|
cur.Damage = dice("1x1")
|
|
}
|
|
|
|
cur.HurlDmg = dice("1x1")
|
|
|
|
switch cur.WandKind() {
|
|
case WandLight:
|
|
cur.Charges = g.rnd(10) + 10
|
|
default:
|
|
cur.Charges = g.rnd(5) + 3
|
|
}
|
|
}
|
|
|
|
// chargeStr returns the charge-count suffix for an identified stick
|
|
// (sticks.c charge_str).
|
|
func chargeStr(g *RogueGame, obj *Object) string {
|
|
if !obj.Flags.Has(Known) {
|
|
return ""
|
|
}
|
|
|
|
if g.Options.Terse {
|
|
return fmt.Sprintf(" [%d]", obj.Charges)
|
|
}
|
|
|
|
return fmt.Sprintf(" [%d charges]", obj.Charges)
|
|
}
|