ObjectKind separates what an item is from how it draws: Object.Type (a byte that doubled as the map character) becomes Kind ObjectKind, with Glyph() producing the display character and objectKindForGlyph converting back at the map boundary. KindWand covers the C 'stick' category. The magic-missile bolt uses KindGold, matching C's literal o_type='*' trick, with a comment. PotionKind, ScrollKind, RingKind, WandKind, WeaponKind, ArmorKind and TrapKind are now iota enums with Stringer (names come from the base info tables); Object gains typed accessors (obj.RingKind(), ...) and Launch is typed WeaponKind. beTrapped returns TrapKind. The getItem/inventory/whatis prompt filters take ObjectKind, with KindCallable/KindRingOrStick replacing the C CALLABLE/R_OR_S sentinels; wizard.c's type_name table is subsumed by ObjectKind.String(). IsRing/IsWearing/initWeapon/doPot signatures are typed accordingly. The save format version becomes 5.4.4-go2: the gob field rename would otherwise silently zero Kind when reading old saves. No behavior change; full suite green.
179 lines
4.0 KiB
Go
179 lines
4.0 KiB
Go
package game
|
|
|
|
// wizard.c — special wizard commands, some of which are also non-wizard
|
|
// commands under strange circumstances. The DES password check is not
|
|
// ported: wizard mode is enabled by configuration instead.
|
|
|
|
// createObj is the wizard command for getting anything he wants (wizard.c
|
|
// create_obj).
|
|
func (g *RogueGame) createObj() {
|
|
obj := newObject()
|
|
g.msg("type of item: ")
|
|
obj.Kind = objectKindForGlyph(g.readchar())
|
|
g.Msgs.Mpos = 0
|
|
g.msg("which %c do you want? (0-f)", obj.Kind.Glyph())
|
|
ch := g.readchar()
|
|
if isDigit(ch) {
|
|
obj.Which = int(ch - '0')
|
|
} else {
|
|
obj.Which = int(ch-'a') + 10
|
|
}
|
|
obj.Group = 0
|
|
obj.Count = 1
|
|
g.Msgs.Mpos = 0
|
|
switch {
|
|
case obj.Kind == KindWeapon || obj.Kind == KindArmor:
|
|
g.msg("blessing? (+,-,n)")
|
|
bless := g.readchar()
|
|
g.Msgs.Mpos = 0
|
|
if bless == '-' {
|
|
obj.Flags.Set(Cursed)
|
|
}
|
|
if obj.Kind == KindWeapon {
|
|
g.initWeapon(obj, WeaponKind(obj.Which))
|
|
if bless == '-' {
|
|
obj.HPlus -= g.rnd(3) + 1
|
|
}
|
|
if bless == '+' {
|
|
obj.HPlus += g.rnd(3) + 1
|
|
}
|
|
} else {
|
|
obj.Arm = aClass[obj.Which]
|
|
if bless == '-' {
|
|
obj.Arm += g.rnd(3) + 1
|
|
}
|
|
if bless == '+' {
|
|
obj.Arm -= g.rnd(3) + 1
|
|
}
|
|
}
|
|
case obj.Kind == KindRing:
|
|
switch obj.RingKind() {
|
|
case RingProtection, RingAddStrength, RingDexterity, RingIncreaseDamage:
|
|
g.msg("blessing? (+,-,n)")
|
|
bless := g.readchar()
|
|
g.Msgs.Mpos = 0
|
|
if bless == '-' {
|
|
obj.Flags.Set(Cursed)
|
|
obj.Arm = -1
|
|
} else {
|
|
obj.Arm = g.rnd(2) + 1
|
|
}
|
|
case RingAggravateMonsters, RingTeleportation:
|
|
obj.Flags.Set(Cursed)
|
|
}
|
|
case obj.Kind == KindWand:
|
|
g.fixStick(obj)
|
|
case obj.Kind == KindGold:
|
|
g.msg("how much?")
|
|
buf := ""
|
|
if g.getStr(&buf, g.scr.Std) == Norm {
|
|
obj.SetGoldVal(cAtoi(buf))
|
|
}
|
|
}
|
|
g.addPack(obj, false)
|
|
}
|
|
|
|
// showMap prints out the whole map for the wizard (wizard.c show_map).
|
|
func (g *RogueGame) showMap() {
|
|
hw := g.scr.Hw
|
|
hw.Clear()
|
|
for y := 1; y < NumLines-1; y++ {
|
|
for x := 0; x < NumCols; x++ {
|
|
real := g.Level.FlagsAt(y, x).Has(FReal)
|
|
if !real {
|
|
hw.Standout(true)
|
|
}
|
|
hw.MvAddCh(y, x, g.Level.Char(y, x))
|
|
if !real {
|
|
hw.Standout(false)
|
|
}
|
|
}
|
|
}
|
|
g.showWin("---More (level map)---")
|
|
}
|
|
|
|
// whatis identifies what a certain object is (wizard.c whatis).
|
|
func (g *RogueGame) whatis(insist bool, kind ObjectKind) {
|
|
p := &g.Player
|
|
if len(p.Pack) == 0 {
|
|
g.msg("you don't have anything in your pack to identify")
|
|
return
|
|
}
|
|
|
|
var obj *Object
|
|
for {
|
|
obj = g.getItem("identify", kind)
|
|
if !insist {
|
|
break
|
|
}
|
|
if g.NObjs == 0 {
|
|
return
|
|
}
|
|
if obj == nil {
|
|
g.msg("you must identify something")
|
|
} else if kind != KindNone && obj.Kind != kind &&
|
|
!(kind == KindRingOrStick &&
|
|
(obj.Kind == KindRing || obj.Kind == KindWand)) {
|
|
g.msg("you must identify a %s", kind)
|
|
} else {
|
|
break
|
|
}
|
|
}
|
|
|
|
if obj == nil {
|
|
return
|
|
}
|
|
|
|
switch obj.Kind {
|
|
case KindScroll:
|
|
setKnow(obj, g.Items.Scrolls[:])
|
|
case KindPotion:
|
|
setKnow(obj, g.Items.Potions[:])
|
|
case KindWand:
|
|
setKnow(obj, g.Items.Sticks[:])
|
|
case KindWeapon, KindArmor:
|
|
obj.Flags.Set(Known)
|
|
case KindRing:
|
|
setKnow(obj, g.Items.Rings[:])
|
|
}
|
|
g.msg("%s", g.invName(obj, false))
|
|
}
|
|
|
|
// setKnow sets things up when we really know what a thing is (wizard.c
|
|
// set_know).
|
|
func setKnow(obj *Object, info []ObjInfo) {
|
|
info[obj.Which].Know = true
|
|
obj.Flags.Set(Known)
|
|
info[obj.Which].Guess = ""
|
|
}
|
|
|
|
// The C type_name()/tlist table is gone: ObjectKind.String() carries the
|
|
// same vocabulary.
|
|
|
|
// teleport bamfs the hero someplace else (wizard.c teleport).
|
|
func (g *RogueGame) teleport() {
|
|
p := &g.Player
|
|
g.mvaddch(p.Pos.Y, p.Pos.X, g.floorAt())
|
|
c, _ := g.findFloor(nil, 0, true)
|
|
if g.roomin(c) != p.Room {
|
|
g.leaveRoom(p.Pos)
|
|
p.Pos = c
|
|
g.enterRoom(p.Pos)
|
|
} else {
|
|
p.Pos = c
|
|
g.look(true)
|
|
}
|
|
g.mvaddch(p.Pos.Y, p.Pos.X, PlayerCh)
|
|
// turn off ISHELD in case teleportation was done while fighting a
|
|
// Flytrap
|
|
if p.On(Held) {
|
|
p.Flags.Clear(Held)
|
|
p.VfHit = 0
|
|
g.Monsters['F'-'A'].Stats.Dmg = "000x0"
|
|
}
|
|
g.NoMove = 0
|
|
g.Count = 0
|
|
g.Running = false
|
|
g.flushType()
|
|
}
|