aboutsummaryrefslogtreecommitdiff
path: root/internal/game/core_startup.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/core_startup.go')
-rw-r--r--internal/game/core_startup.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/internal/game/core_startup.go b/internal/game/core_startup.go
index 4bdb50d..323e519 100644
--- a/internal/game/core_startup.go
+++ b/internal/game/core_startup.go
@@ -31,6 +31,7 @@ func (g *Game) ValidateStartup() []StartupIssue {
issues = append(issues, validateRooms(g)...)
issues = append(issues, validateMobs(g)...)
+ issues = append(issues, validateHazards(g)...)
issues = append(issues, validateObjects(g)...)
issues = append(issues, validateItems(g)...)
issues = append(issues, validateCraftBlocks(g)...)
@@ -66,6 +67,7 @@ func validateRooms(g *Game) []StartupIssue {
itemIDs := g.ItemStore.IDSet()
mobIDs := g.MobStore.AllDefIDs()
objIDs := g.ObjectStore.IDSet()
+ hazardIDs := g.World.HazardIndex()
for id := range roomIndex {
room, err := g.World.LoadRoom(id)
@@ -164,6 +166,15 @@ func validateRooms(g *Game) []StartupIssue {
}
}
}
+
+ if room.Hazard != "" && !hazardIDs[room.Hazard] {
+ issues = append(issues, StartupIssue{
+ Level: "ERROR",
+ Type: "reference",
+ Message: fmt.Sprintf("Room %d: references nonexistent hazard %q",
+ id, room.Hazard),
+ })
+ }
}
return issues
@@ -193,6 +204,14 @@ func validateMobs(g *Game) []StartupIssue {
})
}
+ if def.Kind != "" && def.Kind != "combat" && def.Kind != "task" {
+ issues = append(issues, StartupIssue{
+ Level: "ERROR",
+ Type: "reference",
+ Message: fmt.Sprintf("Mob %q: invalid kind %q (must be \"combat\" or \"task\")", id, def.Kind),
+ })
+ }
+
if def.Drops.Remains != "" && !itemIDs[def.Drops.Remains] {
issues = append(issues, StartupIssue{
Level: "ERROR",
@@ -243,6 +262,40 @@ func validateMobs(g *Game) []StartupIssue {
return issues
}
+func validateHazards(g *Game) []StartupIssue {
+ var issues []StartupIssue
+ itemIDs := g.ItemStore.IDSet()
+ validTypes := map[string]bool{"stab": true, "slash": true, "crush": true, "ranged": true, "science": true}
+
+ for id := range g.World.HazardIndex() {
+ def, err := g.World.LoadHazard(id)
+ if err != nil {
+ issues = append(issues, StartupIssue{
+ Level: "ERROR",
+ Type: "reference",
+ Message: fmt.Sprintf("Hazard %q: failed to load: %v", id, err),
+ })
+ continue
+ }
+ if def.AttackType != "" && !validTypes[def.AttackType] {
+ issues = append(issues, StartupIssue{
+ Level: "ERROR",
+ Type: "reference",
+ Message: fmt.Sprintf("Hazard %q: invalid attack_type %q (must be stab/slash/crush/ranged/science)", id, def.AttackType),
+ })
+ }
+ if def.RequiredItem != "" && !itemIDs[def.RequiredItem] {
+ issues = append(issues, StartupIssue{
+ Level: "ERROR",
+ Type: "reference",
+ Message: fmt.Sprintf("Hazard %q: required_item %q does not exist", id, def.RequiredItem),
+ })
+ }
+ }
+
+ return issues
+}
+
func validateObjects(g *Game) []StartupIssue {
var issues []StartupIssue
objIDs := g.ObjectStore.IDSet()