Module sneak.berlin/go/rogue, package game: - types.go: all rogue.h constants, flag types, Coord/Stats/Room/ObjInfo - creature.go/object.go: the THING union split into Creature (Player/ Monster) and Object; slices replace the C linked lists - level.go: Place map with the C column-major layout and chat/flat/moat/ winat access methods - tables.go: extern.c + init.c data (bestiary, item tables, name pools) - rng.go: the exact C LCG (seed*11109+13849), golden-tested against a compiled C reference for seed compatibility - init.go: per-game item appearance randomization (init.c) - daemon.go/daemons.go: scheduler with DaemonID replacing function pointers (ids match the C save format's mapping) - game.go: RogueGame holds all former globals; NewGame constructor
129 lines
3.1 KiB
Go
129 lines
3.1 KiB
Go
package game
|
|
|
|
import "strings"
|
|
|
|
// init.c — per-game randomization of item appearances and probability
|
|
// tables. initPlayer arrives with the pack/items phase (it needs addPack).
|
|
|
|
// initColors initializes the potion color scheme for this game
|
|
// (init.c init_colors).
|
|
func (g *RogueGame) initColors() {
|
|
used := make([]bool, len(rainbow))
|
|
for i := 0; i < MaxPotions; i++ {
|
|
var j int
|
|
for {
|
|
j = g.rnd(len(rainbow))
|
|
if !used[j] {
|
|
break
|
|
}
|
|
}
|
|
used[j] = true
|
|
g.Items.PotColors[i] = rainbow[j]
|
|
}
|
|
}
|
|
|
|
// initNames generates the names of the various scrolls (init.c init_names).
|
|
func (g *RogueGame) initNames() {
|
|
for i := 0; i < MaxScrolls; i++ {
|
|
var cp strings.Builder
|
|
nwords := g.rnd(3) + 2
|
|
for ; nwords > 0; nwords-- {
|
|
nsyl := g.rnd(3) + 1
|
|
for ; nsyl > 0; nsyl-- {
|
|
sp := sylls[g.rnd(len(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(stoneTable))
|
|
for i := 0; i < MaxRings; i++ {
|
|
var j int
|
|
for {
|
|
j = g.rnd(len(stoneTable))
|
|
if !used[j] {
|
|
break
|
|
}
|
|
}
|
|
used[j] = true
|
|
g.Items.RingStones[i] = stoneTable[j].Name
|
|
g.Items.Rings[i].Worth += 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))
|
|
for i := 0; i < MaxSticks; i++ {
|
|
var str string
|
|
for {
|
|
if g.rnd(2) == 0 {
|
|
j := g.rnd(len(metals))
|
|
if !metused[j] {
|
|
g.Items.WandType[i] = "wand"
|
|
str = metals[j]
|
|
metused[j] = true
|
|
break
|
|
}
|
|
} else {
|
|
j := g.rnd(len(woods))
|
|
if !used[j] {
|
|
g.Items.WandType[i] = "staff"
|
|
str = 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 = 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
|
|
|
|
sumProbs(g.Items.Things[:])
|
|
sumProbs(g.Items.Potions[:])
|
|
sumProbs(g.Items.Scrolls[:])
|
|
sumProbs(g.Items.Rings[:])
|
|
sumProbs(g.Items.Sticks[:])
|
|
sumProbs(g.Items.Weapons[:MaxWeapons]) // 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(IsHalu) {
|
|
return rainbow[g.rnd(len(rainbow))]
|
|
}
|
|
return col
|
|
}
|