Un-overload Object fields and pre-parse damage dice (refactor step 3)

Object.Arm carried four meanings in C (o_arm/o_charges/o_goldval plus
ring bonuses); it is now four fields: ArmorClass, Charges, GoldValue,
and Bonus. Stats.Arm becomes Stats.ArmorClass. The Charges()/GoldVal()
accessor pair is gone.

Damage dice strings ("1x4/1x2") are parsed once into DiceSpec — at
table definition for the bestiary and weapon tables, at creation for
items — instead of re-parsed with atoi on every swing as fight.c
roll_em did. ParseDice preserves the C parse semantics exactly,
including the junk-tolerant "%%%x0" bestiary placeholder and the
"000x0" flytrap reset (regression-tested in dice_test.go); the
flytrap's growing grip becomes DiceSpec{{VfHit, 1}}.

Save format bumps to 5.4.4-go3 (field renames and retypes would
silently zero under gob's match-by-name decoding).

No behavior change; full suite green.
This commit is contained in:
2026-07-06 23:07:57 +02:00
parent c75af2ec22
commit 2eff377a73
28 changed files with 268 additions and 186 deletions

View File

@@ -16,7 +16,7 @@ func (g *RogueGame) doZap() {
g.msg("you can't zap with that!")
return
}
if obj.Charges() == 0 {
if obj.Charges == 0 {
g.msg("nothing happens")
return
}
@@ -111,7 +111,7 @@ func (g *RogueGame) doZap() {
g.Items.Sticks[WandMagicMissile].Know = true
bolt := newObject()
bolt.Kind = KindGold // C set o_type='*': draws a '*' and is not a weapon
bolt.HurlDmg = "1x4"
bolt.HurlDmg = dice("1x4")
bolt.HPlus = 100
bolt.DPlus = 1
bolt.Flags = Missile
@@ -167,7 +167,7 @@ func (g *RogueGame) doZap() {
g.Items.Sticks[obj.Which].Know = true
case WandNothing:
}
obj.SetCharges(obj.Charges() - 1)
obj.Charges--
}
// drain does the drain-hit-points-from-player schtick (sticks.c drain).
@@ -213,7 +213,7 @@ func (g *RogueGame) fireBolt(start Coord, dir *Coord, name string) {
bolt := newObject()
bolt.Kind = KindWeapon
bolt.Which = int(WeaponFlame)
bolt.HurlDmg = "6x6"
bolt.HurlDmg = dice("6x6")
bolt.HPlus = 100
bolt.DPlus = 0
g.Items.Weapons[WeaponFlame].Name = name
@@ -322,17 +322,17 @@ func (g *RogueGame) fireBolt(start Coord, dir *Coord, name string) {
// 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 = "2x3"
cur.Damage = dice("2x3")
} else {
cur.Damage = "1x1"
cur.Damage = dice("1x1")
}
cur.HurlDmg = "1x1"
cur.HurlDmg = dice("1x1")
switch cur.WandKind() {
case WandLight:
cur.SetCharges(g.rnd(10) + 10)
cur.Charges = g.rnd(10) + 10
default:
cur.SetCharges(g.rnd(5) + 3)
cur.Charges = g.rnd(5) + 3
}
}
@@ -343,7 +343,7 @@ func chargeStr(g *RogueGame, obj *Object) string {
return ""
}
if g.Options.Terse {
return fmt.Sprintf(" [%d]", obj.Charges())
return fmt.Sprintf(" [%d]", obj.Charges)
}
return fmt.Sprintf(" [%d charges]", obj.Charges())
return fmt.Sprintf(" [%d charges]", obj.Charges)
}