go: port combat, chase driver, traps, zapping, death and scores
- fight.c in full: fight/attack with all eight special monster attacks (aquator rust, ice freeze, rattlesnake poison, wraith/vampire drains, flytrap hold, leprechaun/nymph theft), swing, roll_em dice parsing (with a C-semantics atoi — Go's strconv rejects '1x4/...'), hit/miss message variants, killed, remove_mon - chase.c completed: runners, move_monst, relocate, do_chase with dragon breath, chase target selection (C's dead oroom comparison in relocate is preserved as-is) - move.c in full: do_move with passgo turning, all eight traps, rndmove, rust_armor - sticks.c completed: do_zap (all 14 sticks), drain, fire_bolt with wall bounces; weapons.c completed: missile/do_motion/fall/wield - rip.c: death tombstone, total_winner, killname; C exit() becomes a gameEnd panic that Run will recover - score.go: top-ten scoreboard as a gob file with lock-file protocol replacing the XOR-encrypted C format - wizard.c: whatis/set_know/teleport; daemons.c stomach - monster bestiary moved to per-game state (C mutates the flytrap damage string during play) Tests: combat math, kill/removal bookkeeping, monster chase pursuit, death unwinding, scripted-input headless terminal.
This commit is contained in:
111
game/wizard.go
Normal file
111
game/wizard.go
Normal file
@@ -0,0 +1,111 @@
|
||||
package game
|
||||
|
||||
// wizard.c — special wizard commands, some of which are also non-wizard
|
||||
// commands under strange circumstances. The MASTER-only debug commands
|
||||
// (create_obj, show_map) arrive with the UI phase.
|
||||
|
||||
// whatis identifies what a certain object is (wizard.c whatis).
|
||||
func (g *RogueGame) whatis(insist bool, typ int) {
|
||||
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", typ)
|
||||
if !insist {
|
||||
break
|
||||
}
|
||||
if g.NObjs == 0 {
|
||||
return
|
||||
}
|
||||
if obj == nil {
|
||||
g.msg("you must identify something")
|
||||
} else if typ != 0 && int(obj.Type) != typ &&
|
||||
!(typ == RorS && (obj.Type == Ring || obj.Type == Stick)) {
|
||||
g.msg("you must identify a %s", typeName(typ))
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if obj == nil {
|
||||
return
|
||||
}
|
||||
|
||||
switch obj.Type {
|
||||
case Scroll:
|
||||
setKnow(obj, g.Items.Scrolls[:])
|
||||
case Potion:
|
||||
setKnow(obj, g.Items.Potions[:])
|
||||
case Stick:
|
||||
setKnow(obj, g.Items.Sticks[:])
|
||||
case Weapon, Armor:
|
||||
obj.Flags.Set(IsKnow)
|
||||
case Ring:
|
||||
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(IsKnow)
|
||||
info[obj.Which].Guess = ""
|
||||
}
|
||||
|
||||
// typeNameTable is the wizard.c type_name static tlist.
|
||||
var typeNameTable = []struct {
|
||||
ch int
|
||||
desc string
|
||||
}{
|
||||
{int(Potion), "potion"},
|
||||
{int(Scroll), "scroll"},
|
||||
{int(Food), "food"},
|
||||
{RorS, "ring, wand or staff"},
|
||||
{int(Ring), "ring"},
|
||||
{int(Stick), "wand or staff"},
|
||||
{int(Weapon), "weapon"},
|
||||
{int(Armor), "suit of armor"},
|
||||
}
|
||||
|
||||
// typeName returns the name of an object type (wizard.c type_name).
|
||||
func typeName(typ int) string {
|
||||
for _, hp := range typeNameTable {
|
||||
if typ == hp.ch {
|
||||
return hp.desc
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// 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(IsHeld) {
|
||||
p.Flags.Clear(IsHeld)
|
||||
p.VfHit = 0
|
||||
g.Monsters['F'-'A'].Stats.Dmg = "000x0"
|
||||
}
|
||||
g.NoMove = 0
|
||||
g.Count = 0
|
||||
g.Running = false
|
||||
g.flushType()
|
||||
}
|
||||
Reference in New Issue
Block a user