diff options
Diffstat (limited to 'internal/validate')
| -rw-r--r-- | internal/validate/checks.go | 68 | ||||
| -rw-r--r-- | internal/validate/validate.go | 2 |
2 files changed, 70 insertions, 0 deletions
diff --git a/internal/validate/checks.go b/internal/validate/checks.go index 6aa0a81..197b8d3 100644 --- a/internal/validate/checks.go +++ b/internal/validate/checks.go @@ -521,6 +521,74 @@ func validateCourses(s Source) []Issue { return issues } +func validateRoomTriggers(s Source) []Issue { + var issues []Issue + roomIndex := s.World.RoomIndex() + itemIDs := s.Items.IDSet() + mobIDs := s.Mobs.AllDefIDs() + + for id := range roomIndex { + room, err := s.World.LoadRoom(id) + if err != nil || len(room.Triggers) == 0 { + continue + } + for ti, trigger := range room.Triggers { + prefix := fmt.Sprintf("Room %d: trigger[%d]", id, ti) + for si, step := range trigger.Steps { + stepPrefix := fmt.Sprintf("%s: step[%d]", prefix, si) + if step.SpawnMob != nil && step.SpawnMob.ID != "" { + if _, ok := mobIDs[step.SpawnMob.ID]; !ok { + issues = append(issues, Issue{ + Level: "ERROR", + Type: "reference", + Message: fmt.Sprintf("%s: spawn_mob %q does not exist", + stepPrefix, step.SpawnMob.ID), + }) + } + for _, wr := range step.SpawnMob.DespawnRooms { + if _, ok := roomIndex[wr]; !ok { + issues = append(issues, Issue{ + Level: "ERROR", + Type: "reference", + Message: fmt.Sprintf("%s: spawn_mob despawn_rooms references nonexistent room %d", + stepPrefix, wr), + }) + } + } + } + if step.GiveItem != "" && !itemIDs[step.GiveItem] { + issues = append(issues, Issue{ + Level: "ERROR", + Type: "reference", + Message: fmt.Sprintf("%s: give_item %q does not exist", + stepPrefix, step.GiveItem), + }) + } + if step.TakeItem != "" && !itemIDs[step.TakeItem] { + issues = append(issues, Issue{ + Level: "ERROR", + Type: "reference", + Message: fmt.Sprintf("%s: take_item %q does not exist", + stepPrefix, step.TakeItem), + }) + } + if step.Teleport > 0 { + if _, ok := roomIndex[step.Teleport]; !ok { + issues = append(issues, Issue{ + Level: "ERROR", + Type: "reference", + Message: fmt.Sprintf("%s: teleport to nonexistent room %d", + stepPrefix, step.Teleport), + }) + } + } + } + } + } + + return issues +} + func validateRoomWiring(s Source) []Issue { var issues []Issue roomIndex := s.World.RoomIndex() diff --git a/internal/validate/validate.go b/internal/validate/validate.go index 5557f72..3918c95 100644 --- a/internal/validate/validate.go +++ b/internal/validate/validate.go @@ -63,6 +63,7 @@ func Run(s Source) []Issue { {"items", "item"}, {"rooms", "room"}, {"mobs", "mob"}, {"objects", "object"}, {"drops", "drop table"}, {"courses", "course"}, {"modules", "module"}, {"techs", "tech"}, {"help", "help topic"}, + {"triggers", "trigger"}, } { issues = append(issues, validateIDs(s.DataDir, dir.sub, dir.label)...) } @@ -75,6 +76,7 @@ func Run(s Source) []Issue { issues = append(issues, validateCraftBlocks(s)...) issues = append(issues, validateDropTables(s)...) issues = append(issues, validateCourses(s)...) + issues = append(issues, validateRoomTriggers(s)...) issues = append(issues, validateTechs(s)...) issues = append(issues, validateRoomWiring(s)...) |
