gochecknoglobals: all 37 package-level tables consolidated into the gameData struct (game/tables.go), built by newGameData() and carried on RogueGame as g.data (set in NewGame and Restore). ObjectKind Glyph()/objectKindForGlyph are now switches; the table-reading subtype Stringer methods are gone; isMagic is a RogueGame method. goconst: repeated words named (potionName/scrollName/ringName/goldName in object.go, wandName/staffName in sticks.go, ripWall in tables.go). exhaustive, testpackage: disabled in .golangci.yml with sneak's approval (2026-07-07). Also reverts misspell's silent corruption of the "ther" scroll-name syllable (it had become "there", changing generated scroll names vs C). Remaining red: cyclop/gocognit/nestif until refactor step 7; mnd awaits a ruling. TODO.md rotated; MEMORY.md lint notes updated.
185 lines
4.2 KiB
Go
185 lines
4.2 KiB
Go
package game
|
|
|
|
import "strings"
|
|
|
|
// init.c — per-game randomization of item appearances and probability
|
|
// tables, and the player roll-up.
|
|
|
|
// initPlayer rolls her up (init.c init_player).
|
|
func (g *RogueGame) initPlayer() {
|
|
p := &g.Player
|
|
p.MaxStats = g.data.initStats
|
|
p.Stats = p.MaxStats
|
|
p.FoodLeft = HungerTime
|
|
// Give him some food
|
|
obj := newObject()
|
|
obj.Kind = KindFood
|
|
obj.Count = 1
|
|
g.addPack(obj, true)
|
|
// And his suit of armor
|
|
obj = newObject()
|
|
obj.Kind = KindArmor
|
|
obj.Which = int(ArmorRingMail)
|
|
obj.ArmorClass = g.data.aClass[ArmorRingMail] - 1
|
|
obj.Flags.Set(Known)
|
|
obj.Count = 1
|
|
p.CurArmor = obj
|
|
g.addPack(obj, true)
|
|
// Give him his weaponry. First a mace.
|
|
obj = newObject()
|
|
g.initWeapon(obj, WeaponMace)
|
|
obj.HPlus = 1
|
|
obj.DPlus = 1
|
|
obj.Flags.Set(Known)
|
|
g.addPack(obj, true)
|
|
p.CurWeapon = obj
|
|
// Now a +1 bow
|
|
obj = newObject()
|
|
g.initWeapon(obj, WeaponBow)
|
|
obj.HPlus = 1
|
|
obj.Flags.Set(Known)
|
|
g.addPack(obj, true)
|
|
// Now some arrows
|
|
obj = newObject()
|
|
g.initWeapon(obj, WeaponArrow)
|
|
obj.Count = g.rnd(15) + 25
|
|
obj.Flags.Set(Known)
|
|
g.addPack(obj, true)
|
|
}
|
|
|
|
// initColors initializes the potion color scheme for this game
|
|
// (init.c init_colors).
|
|
func (g *RogueGame) initColors() {
|
|
used := make([]bool, len(g.data.rainbow))
|
|
|
|
for i := range NumPotionTypes {
|
|
var j int
|
|
for {
|
|
j = g.rnd(len(g.data.rainbow))
|
|
if !used[j] {
|
|
break
|
|
}
|
|
}
|
|
|
|
used[j] = true
|
|
g.Items.PotColors[i] = g.data.rainbow[j]
|
|
}
|
|
}
|
|
|
|
// initNames generates the names of the various scrolls (init.c init_names).
|
|
func (g *RogueGame) initNames() {
|
|
for i := range NumScrollTypes {
|
|
var cp strings.Builder
|
|
|
|
nwords := g.rnd(3) + 2
|
|
for ; nwords > 0; nwords-- {
|
|
nsyl := g.rnd(3) + 1
|
|
for ; nsyl > 0; nsyl-- {
|
|
sp := g.data.sylls[g.rnd(len(g.data.sylls))]
|
|
if cp.Len()+len(sp) > MaxNameLen {
|
|
break
|
|
}
|
|
|
|
cp.WriteString(sp)
|
|
}
|
|
|
|
cp.WriteByte(' ')
|
|
}
|
|
|
|
g.Items.ScrNames[i] = strings.TrimSuffix(cp.String(), " ")
|
|
}
|
|
}
|
|
|
|
// initStones initializes the ring stone setting scheme for this game
|
|
// (init.c init_stones).
|
|
func (g *RogueGame) initStones() {
|
|
used := make([]bool, len(g.data.stoneTable))
|
|
|
|
for i := range NumRingTypes {
|
|
var j int
|
|
for {
|
|
j = g.rnd(len(g.data.stoneTable))
|
|
if !used[j] {
|
|
break
|
|
}
|
|
}
|
|
|
|
used[j] = true
|
|
g.Items.RingStones[i] = g.data.stoneTable[j].Name
|
|
g.Items.Rings[i].Worth += g.data.stoneTable[j].Value
|
|
}
|
|
}
|
|
|
|
// initMaterials initializes the construction materials for wands and staffs
|
|
// (init.c init_materials).
|
|
func (g *RogueGame) initMaterials() {
|
|
used := make([]bool, len(g.data.woods))
|
|
metused := make([]bool, len(g.data.metals))
|
|
|
|
for i := range NumWandTypes {
|
|
var str string
|
|
|
|
for {
|
|
if g.rnd(2) == 0 {
|
|
j := g.rnd(len(g.data.metals))
|
|
if !metused[j] {
|
|
g.Items.WandType[i] = wandName
|
|
str = g.data.metals[j]
|
|
metused[j] = true
|
|
|
|
break
|
|
}
|
|
} else {
|
|
j := g.rnd(len(g.data.woods))
|
|
if !used[j] {
|
|
g.Items.WandType[i] = staffName
|
|
str = g.data.woods[j]
|
|
used[j] = true
|
|
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
g.Items.WandMade[i] = str
|
|
}
|
|
}
|
|
|
|
// sumProbs sums up the probabilities for items appearing, converting the
|
|
// per-item weights into a cumulative distribution (init.c sumprobs).
|
|
func sumProbs(info []ObjInfo) {
|
|
for i := 1; i < len(info); i++ {
|
|
info[i].Prob += info[i-1].Prob
|
|
}
|
|
}
|
|
|
|
// initProbs copies the base tables into the game and initializes the
|
|
// probabilities for the various items (init.c init_probs).
|
|
func (g *RogueGame) initProbs() {
|
|
g.Items.Things = g.data.baseThings
|
|
g.Items.Potions = g.data.basePotInfo
|
|
g.Items.Scrolls = g.data.baseScrInfo
|
|
g.Items.Rings = g.data.baseRingInfo
|
|
g.Items.Sticks = g.data.baseWsInfo
|
|
g.Items.Weapons = g.data.baseWeapInfo
|
|
g.Items.Armors = g.data.baseArmInfo
|
|
|
|
sumProbs(g.Items.Things[:])
|
|
sumProbs(g.Items.Potions[:])
|
|
sumProbs(g.Items.Scrolls[:])
|
|
sumProbs(g.Items.Rings[:])
|
|
sumProbs(g.Items.Sticks[:])
|
|
sumProbs(g.Items.Weapons[:NumWeaponTypes]) // C sums MAXWEAPONS, excluding the flame entry
|
|
sumProbs(g.Items.Armors[:])
|
|
}
|
|
|
|
// pickColor returns the given color, or a random one if the hero is
|
|
// hallucinating (init.c pick_color).
|
|
func (g *RogueGame) pickColor(col string) string {
|
|
if g.Player.On(Hallucinating) {
|
|
return g.data.rainbow[g.rnd(len(g.data.rainbow))]
|
|
}
|
|
|
|
return col
|
|
}
|