Files
rgoue/game/scrolls.go
sneak cdf9bf73a9 go: port item effects — potions, scrolls, options, call_it
- potions.c completed: quaff with all 14 potion effects, the PACT
  standard-fuse table (do_pot), raise_level; the see-invisible fruit-
  juice message is computed at quaff time as in C
- scrolls.c in full: read_scroll with all 18 scroll effects including
  the magic-mapping map rewrite and identify dispatch, uncurse
- options.c in full: the interactive options screen, get_bool/get_str/
  get_inv_t/get_sf editors, ROGUEOPTS parsing (prefix matching, no-
  prefixed booleans, ~ expansion), strucpy
- misc.c call_it via the get_str line editor
- turn_see gets a DaemonID (C casts it to a fuse callback for the
  monster-detection potion)

Tests: healing/confusion potions with fuse burn-down, enchant armor,
hold monster, slow-monster zap, ROGUEOPTS parsing, and a regression
test documenting the C wake_monster ISGREED/ISHELD quirk the port
keeps faithfully.
2026-07-06 19:34:36 +02:00

263 lines
6.3 KiB
Go

package game
// scrolls.c — read a scroll and let it happen.
// idType maps identify scrolls to the type they identify (scrolls.c
// static id_type).
var idType = [SIDRorS + 1]int{
SIDPotion: int(Potion),
SIDScroll: int(Scroll),
SIDWeapon: int(Weapon),
SIDArmor: int(Armor),
SIDRorS: RorS,
}
// readScroll reads a scroll from the pack and does the appropriate thing
// (scrolls.c read_scroll).
func (g *RogueGame) readScroll() {
p := &g.Player
obj := g.getItem("read", int(Scroll))
if obj == nil {
return
}
if obj.Type != Scroll {
if !g.Options.Terse {
g.msg("there is nothing on it to read")
} else {
g.msg("nothing to read")
}
return
}
// Calculate the effect it has on the poor guy.
if obj == p.CurWeapon {
p.CurWeapon = nil
}
// Get rid of the thing
g.leavePack(obj, false, false)
switch obj.Which {
case SConfuse:
// Scroll of monster confusion. Give him that power.
p.Flags.Set(CanHuh)
g.msg("your hands begin to glow %s", g.pickColor("red"))
case SArmor:
if p.CurArmor != nil {
p.CurArmor.Arm--
p.CurArmor.Flags.Clear(IsCursed)
g.msg("your armor glows %s for a moment", g.pickColor("silver"))
}
case SHold:
// Hold monster scroll. Stop all monsters within two spaces from
// chasing after the hero.
held := 0
for x := p.Pos.X - 2; x <= p.Pos.X+2; x++ {
if x < 0 || x >= NumCols {
continue
}
for y := p.Pos.Y - 2; y <= p.Pos.Y+2; y++ {
if y < 0 || y > NumLines-1 {
continue
}
if mp := g.Level.MonsterAt(y, x); mp != nil && mp.On(IsRun) {
mp.Flags.Clear(IsRun)
mp.Flags.Set(IsHeld)
held++
}
}
}
if held > 0 {
g.addmsg("the monster")
if held > 1 {
g.addmsg("s around you")
}
g.addmsg(" freeze")
if held == 1 {
g.addmsg("s")
}
g.endmsg()
g.Items.Scrolls[SHold].Know = true
} else {
g.msg("you feel a strange sense of loss")
}
case SSleep:
// Scroll which makes you fall asleep
g.Items.Scrolls[SSleep].Know = true
g.NoCommand += g.rnd(g.spread(5)) + 4 // SLEEPTIME
p.Flags.Clear(IsRun)
g.msg("you fall asleep")
case SCreate:
// Create a monster: first look in a circle around him, next try
// his room, otherwise give up
i := 0
var mp Coord
for y := p.Pos.Y - 1; y <= p.Pos.Y+1; y++ {
for x := p.Pos.X - 1; x <= p.Pos.X+1; x++ {
// Don't put a monster on top of the player.
if y == p.Pos.Y && x == p.Pos.X {
continue
}
// Or anything else nasty
if ch := g.Level.VisibleChar(y, x); stepOk(ch) {
if ch == Scroll {
if fo := g.findObj(y, x); fo != nil && fo.Which == SScare {
continue
}
}
if i++; g.rnd(i) == 0 {
mp = Coord{Y: y, X: x}
}
}
}
}
if i == 0 {
g.msg("you hear a faint cry of anguish in the distance")
} else {
tp := &Monster{}
g.newMonster(tp, g.randMonster(false), mp)
}
case SIDPotion, SIDScroll, SIDWeapon, SIDArmor, SIDRorS:
// Identify, let him figure something out
g.Items.Scrolls[obj.Which].Know = true
g.msg("this scroll is an %s scroll", g.Items.Scrolls[obj.Which].Name)
g.whatis(true, idType[obj.Which])
case SMap:
// Scroll of magic mapping.
g.Items.Scrolls[SMap].Know = true
g.msg("oh, now this scroll has a map on it")
// take all the things we want to keep hidden out of the window
for y := 1; y < NumLines-1; y++ {
for x := 0; x < NumCols; x++ {
pp := g.Level.At(y, x)
ch := pp.Ch
pass := false
switch ch {
case Door, Stairs:
case '-', '|':
if !pp.Flags.Has(FReal) {
ch = Door
pp.Ch = Door
pp.Flags.Set(FReal)
}
case ' ':
if pp.Flags.Has(FReal) {
// def: hidden things in walls stay hidden
if pp.Flags.Has(FPass) {
pass = true
} else {
ch = ' '
}
} else {
pp.Flags.Set(FReal)
pp.Ch = Passage
pass = true
}
case Passage:
pass = true
case Floor:
if pp.Flags.Has(FReal) {
ch = ' '
} else {
ch = Trap
pp.Ch = Trap
pp.Flags.Set(FSeen | FReal)
}
default:
if pp.Flags.Has(FPass) {
pass = true
} else {
ch = ' '
}
}
if pass {
if !pp.Flags.Has(FReal) {
pp.Ch = Passage
}
pp.Flags.Set(FSeen | FReal)
ch = Passage
}
if ch != ' ' {
if tp := pp.Monst; tp != nil {
tp.OldCh = ch
if !p.On(SeeMonst) {
g.mvaddch(y, x, ch)
}
} else {
g.mvaddch(y, x, ch)
}
}
}
}
case SFDet:
// Food detection
found := false
g.scr.Hw.Clear()
for _, fo := range g.Level.Objects {
if fo.Type == Food {
found = true
g.scr.Hw.MvAddCh(fo.Pos.Y, fo.Pos.X, Food)
}
}
if found {
g.Items.Scrolls[SFDet].Know = true
g.showWin("Your nose tingles and you smell food.--More--")
} else {
g.msg("your nose tingles")
}
case STelep:
// Scroll of teleportation: make him disappear and reappear
curRoom := p.Room
g.teleport()
if curRoom != p.Room {
g.Items.Scrolls[STelep].Know = true
}
case SEnch:
if p.CurWeapon == nil || p.CurWeapon.Type != Weapon {
g.msg("you feel a strange sense of loss")
} else {
p.CurWeapon.Flags.Clear(IsCursed)
if g.rnd(2) == 0 {
p.CurWeapon.HPlus++
} else {
p.CurWeapon.DPlus++
}
g.msg("your %s glows %s for a moment",
g.Items.Weapons[p.CurWeapon.Which].Name, g.pickColor("blue"))
}
case SScare:
// Reading it is a mistake and produces laughter at her poor boo
// boo.
g.msg("you hear maniacal laughter in the distance")
case SRemove:
uncurse(p.CurArmor)
uncurse(p.CurWeapon)
uncurse(p.CurRing[Left])
uncurse(p.CurRing[Right])
g.msg("%s", g.chooseStr("you feel in touch with the Universal Onenes",
"you feel as if somebody is watching over you"))
case SAggr:
// This scroll aggravates all the monsters on the current level
// and sets them running towards the hero
g.aggravate()
g.msg("you hear a high pitched humming noise")
case SProtect:
if p.CurArmor != nil {
p.CurArmor.Flags.Set(IsProt)
g.msg("your armor is covered by a shimmering %s shield",
g.pickColor("gold"))
} else {
g.msg("you feel a strange sense of loss")
}
}
g.look(true) // put the result of the scroll on the screen
g.status()
g.callIt(&g.Items.Scrolls[obj.Which])
}
// uncurse uncurses an item (scrolls.c uncurse).
func uncurse(obj *Object) {
if obj != nil {
obj.Flags.Clear(IsCursed)
}
}