aboutsummaryrefslogtreecommitdiff
path: root/internal/world
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-25 15:40:48 -0400
committerhistoria <[not public]>2026-06-25 15:40:48 -0400
commitabd612c15799f604e671e83dc7c410ed2b44185f (patch)
tree0597ca92350de73aac2a7cf26b2f2d6595dac0cc /internal/world
parent2725e2927a1595c7b100d942d1f14146252adeb7 (diff)
downloadthehouseoficarus-abd612c15799f604e671e83dc7c410ed2b44185f.tar.gz
slop refactor
Diffstat (limited to 'internal/world')
-rw-r--r--internal/world/hazard.go8
-rw-r--r--internal/world/mob.go161
-rw-r--r--internal/world/objects.go10
-rw-r--r--internal/world/room.go52
-rw-r--r--internal/world/world.go18
5 files changed, 121 insertions, 128 deletions
diff --git a/internal/world/hazard.go b/internal/world/hazard.go
index 1361cff..ac2a6a6 100644
--- a/internal/world/hazard.go
+++ b/internal/world/hazard.go
@@ -5,8 +5,8 @@ import (
"os"
"path/filepath"
- "thehouseoficarus/internal/action"
"gopkg.in/yaml.v3"
+ "thehouseoficarus/internal/behavior"
)
// HazardDef describes an environmental threat attached to a room (a sandstorm,
@@ -29,7 +29,7 @@ type HazardDef struct {
MaxHit int `yaml:"max_hit"`
Speed float64 `yaml:"speed"` // ticks between hazard rolls
WarnMessage string `yaml:"warn_message"`
- HitMessage string `yaml:"hit_message"` // accepts a single %d for damage
+ HitMessage string `yaml:"hit_message"` // accepts a single %d for damage
MissMessage string `yaml:"miss_message"`
RequiredItem string `yaml:"required_item"` // equipped item that negates the hazard
}
@@ -38,7 +38,7 @@ type HazardDef struct {
func (w *World) LoadHazard(id string) (*HazardDef, error) {
w.hazardMu.Lock()
if w.hazardPathIndex == nil {
- w.hazardPathIndex = action.BuildPathIndex(filepath.Join(w.dataDir, "hazards"))
+ w.hazardPathIndex = behavior.BuildPathIndex(filepath.Join(w.dataDir, "hazards"))
}
if def, ok := w.hazardDefs[id]; ok {
w.hazardMu.Unlock()
@@ -70,7 +70,7 @@ func (w *World) HazardIndex() map[string]bool {
w.hazardMu.Lock()
defer w.hazardMu.Unlock()
if w.hazardPathIndex == nil {
- w.hazardPathIndex = action.BuildPathIndex(filepath.Join(w.dataDir, "hazards"))
+ w.hazardPathIndex = behavior.BuildPathIndex(filepath.Join(w.dataDir, "hazards"))
}
ids := make(map[string]bool, len(w.hazardPathIndex))
for id := range w.hazardPathIndex {
diff --git a/internal/world/mob.go b/internal/world/mob.go
index 4864e5c..4c6becb 100644
--- a/internal/world/mob.go
+++ b/internal/world/mob.go
@@ -8,38 +8,37 @@ import (
"strings"
"sync"
- "thehouseoficarus/internal/action"
- "thehouseoficarus/internal/object"
"gopkg.in/yaml.v3"
+ "thehouseoficarus/internal/behavior"
)
type MobDropTable struct {
- Remains string `yaml:"remains"`
- Loot []action.DropEntry `yaml:"loot"`
+ Remains string `yaml:"remains"`
+ Loot []behavior.DropEntry `yaml:"loot"`
}
type MobDef struct {
- ID string `yaml:"id"`
- Name string `yaml:"name"`
- Description string `yaml:"description"`
- IdleDescriptions []string `yaml:"idle_descriptions"`
- CombatDescriptions []string `yaml:"combat_descriptions"`
- Attack int `yaml:"attack"`
- Strength int `yaml:"strength"`
- Defense int `yaml:"defense"`
- HP int `yaml:"hp"`
- Ranged int `yaml:"ranged"`
- Science int `yaml:"science"`
- Speed float64 `yaml:"speed"`
- Aggressive bool `yaml:"aggressive"`
- Protected bool `yaml:"protected"`
- Unique bool `yaml:"unique"`
- RespawnTicks float64 `yaml:"respawn_ticks"`
+ ID string `yaml:"id"`
+ Name string `yaml:"name"`
+ Description string `yaml:"description"`
+ IdleDescriptions []string `yaml:"idle_descriptions"`
+ CombatDescriptions []string `yaml:"combat_descriptions"`
+ Attack int `yaml:"attack"`
+ Strength int `yaml:"strength"`
+ Defense int `yaml:"defense"`
+ HP int `yaml:"hp"`
+ Ranged int `yaml:"ranged"`
+ Science int `yaml:"science"`
+ Speed float64 `yaml:"speed"`
+ Aggressive bool `yaml:"aggressive"`
+ Protected bool `yaml:"protected"`
+ Unique bool `yaml:"unique"`
+ RespawnTicks float64 `yaml:"respawn_ticks"`
Drops MobDropTable `yaml:"drops"`
- AttackBonus int `yaml:"attack_bonus"`
- StrengthBonus int `yaml:"strength_bonus"`
- AttackType string `yaml:"attack_type"`
+ AttackBonus int `yaml:"attack_bonus"`
+ StrengthBonus int `yaml:"strength_bonus"`
+ AttackType string `yaml:"attack_type"`
StabDefense int `yaml:"stab_defense"`
SlashDefense int `yaml:"slash_defense"`
@@ -47,11 +46,11 @@ type MobDef struct {
ScienceDefense int `yaml:"science_defense"`
RangedDefense int `yaml:"ranged_defense"`
- Weakness string `yaml:"weakness"`
- StealTable string `yaml:"steal_table"`
- StealLevel int `yaml:"steal_level"`
- StealXP int `yaml:"steal_xp"`
- StealSpeed float64 `yaml:"steal_speed"`
+ Weakness string `yaml:"weakness"`
+ StealTable string `yaml:"steal_table"`
+ StealLevel int `yaml:"steal_level"`
+ StealXP int `yaml:"steal_xp"`
+ StealSpeed float64 `yaml:"steal_speed"`
AssassinLevel int `yaml:"assassin_level"`
FinishingBlow string `yaml:"finishing_blow"`
@@ -68,7 +67,7 @@ type MobDef struct {
ProgressNoun string `yaml:"progress_noun"` // flavor noun, e.g. "construction"
CompleteMessage string `yaml:"complete_message"` // shown on completion
- Talk *action.TalkConfig `yaml:"talk,omitempty"`
+ Talk *behavior.TalkConfig `yaml:"talk,omitempty"`
}
func (d *MobDef) IsTalkable() bool { return d.Talk != nil }
@@ -100,9 +99,9 @@ type MobInstance struct {
WanderTickCounter int
regenerateTick int
- AttackBonus int
- StrengthBonus int
- AttackType string
+ AttackBonus int
+ StrengthBonus int
+ AttackType string
StabDefense int
SlashDefense int
@@ -110,11 +109,11 @@ type MobInstance struct {
ScienceDefense int
RangedDefense int
- Weakness string
- StealTable string
- StealLevel int
- StealXP int
- StealSpeed float64
+ Weakness string
+ StealTable string
+ StealLevel int
+ StealXP int
+ StealSpeed float64
AssassinLevel int
FinishingBlow string
@@ -126,7 +125,7 @@ type MobInstance struct {
ProgressNoun string
CompleteMessage string
- TalkConfig *action.TalkConfig
+ TalkConfig *behavior.TalkConfig
}
func (m *MobInstance) IsTalkable() bool { return m.TalkConfig != nil }
@@ -135,48 +134,48 @@ func (m *MobInstance) IsTask() bool { return m.Kind == "task" }
func NewMobInstance(def *MobDef, instanceID string, roomID int, wanderRooms []int, wanderInterval float64) *MobInstance {
return &MobInstance{
- InstanceID: instanceID,
- DefID: def.ID,
- Name: def.Name,
- HP: def.HP,
- MaxHP: def.HP,
- Attack: def.Attack,
- Strength: def.Strength,
- Defense: def.Defense,
- Ranged: def.Ranged,
- Science: def.Science,
- Speed: def.Speed,
- Aggressive: def.Aggressive,
- Protected: def.Protected,
- Unique: def.Unique,
- RespawnTicks: def.RespawnTicks,
- RoomID: roomID,
- HomeRoomID: roomID,
- WanderRooms: wanderRooms,
- WanderInterval: wanderInterval,
- Drops: def.Drops,
- AttackBonus: def.AttackBonus,
- StrengthBonus: def.StrengthBonus,
- AttackType: def.AttackType,
- StabDefense: def.StabDefense,
- SlashDefense: def.SlashDefense,
- CrushDefense: def.CrushDefense,
- ScienceDefense: def.ScienceDefense,
- RangedDefense: def.RangedDefense,
- Weakness: def.Weakness,
- StealTable: def.StealTable,
- StealLevel: def.StealLevel,
- StealXP: def.StealXP,
- StealSpeed: def.StealSpeed,
- AssassinLevel: def.AssassinLevel,
- FinishingBlow: def.FinishingBlow,
- DamageWithout: def.DamageWithout,
- Size: def.Size,
- Kind: def.Kind,
- Verb: def.Verb,
- ProgressNoun: def.ProgressNoun,
+ InstanceID: instanceID,
+ DefID: def.ID,
+ Name: def.Name,
+ HP: def.HP,
+ MaxHP: def.HP,
+ Attack: def.Attack,
+ Strength: def.Strength,
+ Defense: def.Defense,
+ Ranged: def.Ranged,
+ Science: def.Science,
+ Speed: def.Speed,
+ Aggressive: def.Aggressive,
+ Protected: def.Protected,
+ Unique: def.Unique,
+ RespawnTicks: def.RespawnTicks,
+ RoomID: roomID,
+ HomeRoomID: roomID,
+ WanderRooms: wanderRooms,
+ WanderInterval: wanderInterval,
+ Drops: def.Drops,
+ AttackBonus: def.AttackBonus,
+ StrengthBonus: def.StrengthBonus,
+ AttackType: def.AttackType,
+ StabDefense: def.StabDefense,
+ SlashDefense: def.SlashDefense,
+ CrushDefense: def.CrushDefense,
+ ScienceDefense: def.ScienceDefense,
+ RangedDefense: def.RangedDefense,
+ Weakness: def.Weakness,
+ StealTable: def.StealTable,
+ StealLevel: def.StealLevel,
+ StealXP: def.StealXP,
+ StealSpeed: def.StealSpeed,
+ AssassinLevel: def.AssassinLevel,
+ FinishingBlow: def.FinishingBlow,
+ DamageWithout: def.DamageWithout,
+ Size: def.Size,
+ Kind: def.Kind,
+ Verb: def.Verb,
+ ProgressNoun: def.ProgressNoun,
CompleteMessage: def.CompleteMessage,
- TalkConfig: def.Talk,
+ TalkConfig: def.Talk,
}
}
@@ -191,7 +190,7 @@ func (m *MobInstance) MatchQuality(input string) int {
if strings.ToLower(m.Name) == lower {
return MatchExact
}
- if object.WordPrefixMatch(input, m.Name) {
+ if behavior.WordPrefixMatch(input, m.Name) {
return MatchPrefix
}
return MatchNone
@@ -221,7 +220,7 @@ type MobStore struct {
func NewMobStore(dataDir string) *MobStore {
return &MobStore{
dataDir: dataDir,
- pathIndex: action.BuildPathIndex(filepath.Join(dataDir, "mobs")),
+ pathIndex: behavior.BuildPathIndex(filepath.Join(dataDir, "mobs")),
defs: make(map[string]*MobDef),
instances: make(map[string]*MobInstance),
}
diff --git a/internal/world/objects.go b/internal/world/objects.go
index a7e0605..849c47a 100644
--- a/internal/world/objects.go
+++ b/internal/world/objects.go
@@ -6,7 +6,7 @@ import (
"sort"
"strings"
- "thehouseoficarus/internal/object"
+ "thehouseoficarus/internal/behavior"
)
type ObjState struct {
@@ -25,9 +25,9 @@ type ObjState struct {
SharedTimer int
Quality float64
- SafespotLevel int
+ SafespotLevel int
SafespotTicksAtLevel int
- SafespotOccupants []string
+ SafespotOccupants []string
}
type ObjMove struct {
@@ -187,11 +187,11 @@ func (w *World) FindObjInstances(roomID int, name string) []ObjState {
}
func wordMatchesObj(lower, defID, objName string, aliases []string) bool {
- if object.WordPrefixMatch(lower, objName) {
+ if behavior.WordPrefixMatch(lower, objName) {
return true
}
for _, alias := range aliases {
- if object.WordPrefixMatch(lower, alias) {
+ if behavior.WordPrefixMatch(lower, alias) {
return true
}
}
diff --git a/internal/world/room.go b/internal/world/room.go
index 2441c30..71a36ed 100644
--- a/internal/world/room.go
+++ b/internal/world/room.go
@@ -2,7 +2,7 @@ package world
import (
"gopkg.in/yaml.v3"
- "thehouseoficarus/internal/action"
+ "thehouseoficarus/internal/behavior"
)
type ExitDir string
@@ -17,12 +17,12 @@ const (
)
var ExitAliases = map[string]ExitDir{
- "n": North,
- "s": South,
- "e": East,
- "w": West,
- "u": Up,
- "d": Down,
+ "n": North,
+ "s": South,
+ "e": East,
+ "w": West,
+ "u": Up,
+ "d": Down,
}
var OppositeExit = map[ExitDir]ExitDir{
@@ -45,11 +45,11 @@ type SpawnDef struct {
}
type ExitDef struct {
- Room int `yaml:"room"`
- Condition *action.Condition `yaml:"condition"`
- BlockedMessage string `yaml:"blocked_message"`
- SetFlags map[string]any `yaml:"set_flags"`
- SetPlayerFlags map[string]any `yaml:"set_player_flags"`
+ Room int `yaml:"room"`
+ Condition *behavior.Condition `yaml:"condition"`
+ BlockedMessage string `yaml:"blocked_message"`
+ SetFlags map[string]any `yaml:"set_flags"`
+ SetPlayerFlags map[string]any `yaml:"set_player_flags"`
}
func (e *ExitDef) UnmarshalYAML(value *yaml.Node) error {
@@ -68,24 +68,18 @@ func (e *ExitDef) UnmarshalYAML(value *yaml.Node) error {
type Room struct {
ID int `yaml:"id"`
Name string `yaml:"name"`
- Description string `yaml:"description"`
- Descriptions []RoomDesc `yaml:"descriptions,omitempty"`
+ Description behavior.DescList `yaml:"description"`
Exits map[ExitDir]ExitDef `yaml:"exits"`
Objects []RoomObject `yaml:"objects"`
- ItemSpawns []SpawnDef `yaml:"item_spawns"`
+ ItemSpawns []SpawnDef `yaml:"item_spawns"`
Mobs []RoomMob `yaml:"mobs"`
OnEnter []EnterStep `yaml:"on_enter"`
Hazard string `yaml:"hazard"`
}
-type RoomDesc struct {
- Text string `yaml:"text"`
- Condition *action.Condition `yaml:"condition"`
-}
-
type RoomMob struct {
- ID string `yaml:"id"`
- WanderRooms []int `yaml:"wander_rooms"`
+ ID string `yaml:"id"`
+ WanderRooms []int `yaml:"wander_rooms"`
WanderInterval float64 `yaml:"wander_interval"`
}
@@ -103,11 +97,11 @@ func (rm *RoomMob) UnmarshalYAML(value *yaml.Node) error {
}
type EnterStep struct {
- Message string `yaml:"message"`
- Condition *action.Condition `yaml:"condition"`
- Delay int `yaml:"delay"`
- SetFlags map[string]any `yaml:"set_flags"`
- SetPlayerFlags map[string]any `yaml:"set_player_flags"`
+ Message string `yaml:"message"`
+ Condition *behavior.Condition `yaml:"condition"`
+ Delay int `yaml:"delay"`
+ SetFlags map[string]any `yaml:"set_flags"`
+ SetPlayerFlags map[string]any `yaml:"set_player_flags"`
}
// IsTimed reports whether the step carries cutscene semantics: a tick delay or
@@ -119,7 +113,7 @@ func (e EnterStep) IsTimed() bool {
}
type RoomObject struct {
- ID string `yaml:"id"`
- WanderRooms []int `yaml:"wander_rooms"`
+ ID string `yaml:"id"`
+ WanderRooms []int `yaml:"wander_rooms"`
WanderInterval float64 `yaml:"wander_interval"`
}
diff --git a/internal/world/world.go b/internal/world/world.go
index 8ed9a7c..ee06142 100644
--- a/internal/world/world.go
+++ b/internal/world/world.go
@@ -7,18 +7,18 @@ import (
"strings"
"sync"
- "thehouseoficarus/internal/action"
"gopkg.in/yaml.v3"
+ "thehouseoficarus/internal/behavior"
)
type World struct {
- dataDir string
- mu sync.Mutex
- roomPathIndex map[int]string
- groundItems map[int][]*groundEntry
- seeded map[int]bool
- objStates map[string]*ObjState
- objMoves []ObjMove
+ dataDir string
+ mu sync.Mutex
+ roomPathIndex map[int]string
+ groundItems map[int][]*groundEntry
+ seeded map[int]bool
+ objStates map[string]*ObjState
+ objMoves []ObjMove
hazardMu sync.Mutex
hazardPathIndex map[string]string
@@ -28,7 +28,7 @@ type World struct {
func New(dataDir string) *World {
return &World{
dataDir: dataDir,
- roomPathIndex: action.BuildRoomIndex(filepath.Join(dataDir, "rooms")),
+ roomPathIndex: behavior.BuildRoomIndex(filepath.Join(dataDir, "rooms")),
groundItems: make(map[int][]*groundEntry),
seeded: make(map[int]bool),
objStates: make(map[string]*ObjState),