Files
rgoue/game/level.go
sneak e71a2ef3fd Rename constants to descriptive names (refactor step 1)
Pure rename, no behavior change; the full suite (RNG goldens,
generation invariants, scripted sessions, save round trip) is
unchanged and green.

- Creature flags: IsHuh→Confused, IsHalu→Hallucinating,
  CanHuh→CanConfuse, CanSee→CanSeeInvisible, IsRun→Awake,
  SeeMonst→SenseMonsters, IsCanc→Cancelled, IsLevit→Levitating,
  IsBlind/IsGreed/IsHaste/IsTarget/IsHeld/IsInvis/IsMean/IsRegen/
  IsFly/IsSlow → Blind/Greedy/Hasted/Targeted/Held/Invisible/Mean/
  Regenerates/Flying/Slowed, IsFound→Found
- Object flags: IsCursed→Cursed, IsKnow→Known, IsMissl→Missile,
  IsMany→Stackable, ObjIsFound→WasFound, IsProt→Protected
- Room flags: IsDark/IsGone/IsMaze → Dark/Gone/Maze; place flags:
  FPass→FPassage, FPNum→FPassNum, FTMask→FTrapMask
- Trap types: TDoor→TrapDoor ... TMyst→TrapMystery
- Item subtypes: P*→Potion* (PLSD→PotionLSD, PMFind→
  PotionDetectMonsters, ...), S*→Scroll* (SIDRorS→
  ScrollIdentifyRingOrStick, ...), R*→Ring* (RAddHit→RingDexterity,
  RNop→RingAdornment, ...), Ws*→Wand* (WsElect→WandLightning, ...),
  weapons (TwoSword→WeaponTwoHandedSword, Shiraken→WeaponShuriken,
  ...), armor (RingMail→ArmorRingMail, ...)
- Counts: Max{Potions,Scrolls,Rings,Sticks,Weapons,Armors} →
  Num{Potion,Scroll,Ring,Wand,Weapon,Armor}Types; NTraps→NumTrapTypes
- Level.NTraps field → TrapCount (also in the save snapshot)
- Original C constant names preserved as comment breadcrumbs in
  types.go so the lineage stays greppable

TODO.md: step 1 moved to Completed, step 2 (typed kinds) promoted to
Next Step.
2026-07-06 21:28:57 +02:00

57 lines
2.0 KiB
Go

package game
// Place describes a spot on the level map (rogue.h PLACE).
type Place struct {
Ch byte // the base map character
Flags PlaceFlags
Monst *Monster
}
// Level is the current dungeon level: the map and everything on it. It is
// reset in place by NewLevel, matching the C reuse of the global arrays.
type Level struct {
Places [MaxLines * MaxCols]Place
Rooms [MaxRooms]Room
Passages [MaxPass]Room // one pseudo-room per passage network
Objects []*Object // lvl_obj: objects on this level
Monsters []*Monster // mlist: monsters on the level
Stairs Coord // location of the staircase
TrapCount int // number of traps on this level
}
// At returns the map cell at (y, x); the C INDEX(y,x) macro, including its
// column-major (x<<5)+y layout.
func (l *Level) At(y, x int) *Place {
return &l.Places[(x<<5)+y]
}
// Char is the chat(y,x) macro: the base map character at a spot.
func (l *Level) Char(y, x int) byte { return l.At(y, x).Ch }
// SetChar updates the base map character at a spot.
func (l *Level) SetChar(y, x int, ch byte) { l.At(y, x).Ch = ch }
// FlagsAt is the flat(y,x) macro, returned as a pointer so ported
// read-modify-write sites keep their shape.
func (l *Level) FlagsAt(y, x int) *PlaceFlags { return &l.At(y, x).Flags }
// MonsterAt is the moat(y,x) macro: the monster standing at a spot, if any.
func (l *Level) MonsterAt(y, x int) *Monster { return l.At(y, x).Monst }
// SetMonsterAt places (or clears, with nil) the monster at a spot.
func (l *Level) SetMonsterAt(y, x int, m *Monster) { l.At(y, x).Monst = m }
// VisibleChar is the winat(y,x) macro: what is apparently at a spot — a
// monster's disguise if one stands there, else the map character.
func (l *Level) VisibleChar(y, x int) byte {
if m := l.MonsterAt(y, x); m != nil {
return m.Disguise
}
return l.Char(y, x)
}
// goldCalc is the GOLDCALC macro: how much a gold pile is worth at depth.
func (g *RogueGame) goldCalc() int {
return g.rnd(50+10*g.Depth) + 2
}