Move all package-level vars into gameData; finish lint adoption
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.
This commit is contained in:
52
game/init.go
52
game/init.go
@@ -8,7 +8,7 @@ import "strings"
|
||||
// initPlayer rolls her up (init.c init_player).
|
||||
func (g *RogueGame) initPlayer() {
|
||||
p := &g.Player
|
||||
p.MaxStats = initStats
|
||||
p.MaxStats = g.data.initStats
|
||||
p.Stats = p.MaxStats
|
||||
p.FoodLeft = HungerTime
|
||||
// Give him some food
|
||||
@@ -20,7 +20,7 @@ func (g *RogueGame) initPlayer() {
|
||||
obj = newObject()
|
||||
obj.Kind = KindArmor
|
||||
obj.Which = int(ArmorRingMail)
|
||||
obj.ArmorClass = aClass[ArmorRingMail] - 1
|
||||
obj.ArmorClass = g.data.aClass[ArmorRingMail] - 1
|
||||
obj.Flags.Set(Known)
|
||||
obj.Count = 1
|
||||
p.CurArmor = obj
|
||||
@@ -50,19 +50,19 @@ func (g *RogueGame) initPlayer() {
|
||||
// initColors initializes the potion color scheme for this game
|
||||
// (init.c init_colors).
|
||||
func (g *RogueGame) initColors() {
|
||||
used := make([]bool, len(rainbow))
|
||||
used := make([]bool, len(g.data.rainbow))
|
||||
|
||||
for i := range NumPotionTypes {
|
||||
var j int
|
||||
for {
|
||||
j = g.rnd(len(rainbow))
|
||||
j = g.rnd(len(g.data.rainbow))
|
||||
if !used[j] {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
used[j] = true
|
||||
g.Items.PotColors[i] = rainbow[j]
|
||||
g.Items.PotColors[i] = g.data.rainbow[j]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ func (g *RogueGame) initNames() {
|
||||
for ; nwords > 0; nwords-- {
|
||||
nsyl := g.rnd(3) + 1
|
||||
for ; nsyl > 0; nsyl-- {
|
||||
sp := sylls[g.rnd(len(sylls))]
|
||||
sp := g.data.sylls[g.rnd(len(g.data.sylls))]
|
||||
if cp.Len()+len(sp) > MaxNameLen {
|
||||
break
|
||||
}
|
||||
@@ -93,47 +93,47 @@ func (g *RogueGame) initNames() {
|
||||
// initStones initializes the ring stone setting scheme for this game
|
||||
// (init.c init_stones).
|
||||
func (g *RogueGame) initStones() {
|
||||
used := make([]bool, len(stoneTable))
|
||||
used := make([]bool, len(g.data.stoneTable))
|
||||
|
||||
for i := range NumRingTypes {
|
||||
var j int
|
||||
for {
|
||||
j = g.rnd(len(stoneTable))
|
||||
j = g.rnd(len(g.data.stoneTable))
|
||||
if !used[j] {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
used[j] = true
|
||||
g.Items.RingStones[i] = stoneTable[j].Name
|
||||
g.Items.Rings[i].Worth += stoneTable[j].Value
|
||||
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(woods))
|
||||
metused := make([]bool, len(metals))
|
||||
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(metals))
|
||||
j := g.rnd(len(g.data.metals))
|
||||
if !metused[j] {
|
||||
g.Items.WandType[i] = "wand"
|
||||
str = metals[j]
|
||||
g.Items.WandType[i] = wandName
|
||||
str = g.data.metals[j]
|
||||
metused[j] = true
|
||||
|
||||
break
|
||||
}
|
||||
} else {
|
||||
j := g.rnd(len(woods))
|
||||
j := g.rnd(len(g.data.woods))
|
||||
if !used[j] {
|
||||
g.Items.WandType[i] = "staff"
|
||||
str = woods[j]
|
||||
g.Items.WandType[i] = staffName
|
||||
str = g.data.woods[j]
|
||||
used[j] = true
|
||||
|
||||
break
|
||||
@@ -156,13 +156,13 @@ func sumProbs(info []ObjInfo) {
|
||||
// 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 = baseThings
|
||||
g.Items.Potions = basePotInfo
|
||||
g.Items.Scrolls = baseScrInfo
|
||||
g.Items.Rings = baseRingInfo
|
||||
g.Items.Sticks = baseWsInfo
|
||||
g.Items.Weapons = baseWeapInfo
|
||||
g.Items.Armors = baseArmInfo
|
||||
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[:])
|
||||
@@ -177,7 +177,7 @@ func (g *RogueGame) initProbs() {
|
||||
// hallucinating (init.c pick_color).
|
||||
func (g *RogueGame) pickColor(col string) string {
|
||||
if g.Player.On(Hallucinating) {
|
||||
return rainbow[g.rnd(len(rainbow))]
|
||||
return g.data.rainbow[g.rnd(len(g.data.rainbow))]
|
||||
}
|
||||
|
||||
return col
|
||||
|
||||
Reference in New Issue
Block a user