Give item categories and subtypes real types (refactor step 2)
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.
This commit is contained in:
22
game/rip.go
22
game/rip.go
@@ -115,37 +115,37 @@ func (g *RogueGame) totalWinner() {
|
||||
for _, obj := range p.Pack {
|
||||
worth := 0
|
||||
it := &g.Items
|
||||
switch obj.Type {
|
||||
case Food:
|
||||
switch obj.Kind {
|
||||
case KindFood:
|
||||
worth = 2 * obj.Count
|
||||
case Weapon:
|
||||
case KindWeapon:
|
||||
worth = it.Weapons[obj.Which].Worth
|
||||
worth *= 3*(obj.HPlus+obj.DPlus) + obj.Count
|
||||
obj.Flags.Set(Known)
|
||||
case Armor:
|
||||
case KindArmor:
|
||||
worth = it.Armors[obj.Which].Worth
|
||||
worth += (9 - obj.Arm) * 100
|
||||
worth += 10 * (aClass[obj.Which] - obj.Arm)
|
||||
obj.Flags.Set(Known)
|
||||
case Scroll:
|
||||
case KindScroll:
|
||||
op := &it.Scrolls[obj.Which]
|
||||
worth = op.Worth * obj.Count
|
||||
if !op.Know {
|
||||
worth /= 2
|
||||
}
|
||||
op.Know = true
|
||||
case Potion:
|
||||
case KindPotion:
|
||||
op := &it.Potions[obj.Which]
|
||||
worth = op.Worth * obj.Count
|
||||
if !op.Know {
|
||||
worth /= 2
|
||||
}
|
||||
op.Know = true
|
||||
case Ring:
|
||||
case KindRing:
|
||||
op := &it.Rings[obj.Which]
|
||||
worth = op.Worth
|
||||
if obj.Which == RingAddStrength || obj.Which == RingIncreaseDamage ||
|
||||
obj.Which == RingProtection || obj.Which == RingDexterity {
|
||||
if obj.RingKind() == RingAddStrength || obj.RingKind() == RingIncreaseDamage ||
|
||||
obj.RingKind() == RingProtection || obj.RingKind() == RingDexterity {
|
||||
if obj.Arm > 0 {
|
||||
worth += obj.Arm * 100
|
||||
} else {
|
||||
@@ -157,7 +157,7 @@ func (g *RogueGame) totalWinner() {
|
||||
}
|
||||
obj.Flags.Set(Known)
|
||||
op.Know = true
|
||||
case Stick:
|
||||
case KindWand:
|
||||
op := &it.Sticks[obj.Which]
|
||||
worth = op.Worth
|
||||
worth += 20 * obj.Charges()
|
||||
@@ -166,7 +166,7 @@ func (g *RogueGame) totalWinner() {
|
||||
}
|
||||
obj.Flags.Set(Known)
|
||||
op.Know = true
|
||||
case Amulet:
|
||||
case KindAmulet:
|
||||
worth = 1000
|
||||
}
|
||||
if worth < 0 {
|
||||
|
||||
Reference in New Issue
Block a user