diff options
Diffstat (limited to 'internal/world/room_migrate.go')
| -rw-r--r-- | internal/world/room_migrate.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/world/room_migrate.go b/internal/world/room_migrate.go index b7840bc..42cd1ae 100644 --- a/internal/world/room_migrate.go +++ b/internal/world/room_migrate.go @@ -101,6 +101,48 @@ func (r *Room) RewriteRoomIDs(idMap map[int]int) bool { return changed } +// RemoveRoomRefs drops references to a deleted room from this room's +// per-instance mob and object wander lists. Exit targets are removed by the +// deletion caller. Teleport steps and conditions that name the deleted room +// are left in place and neutralized at runtime (teleportPlayer refuses a +// missing destination, and a Condition.Room that no longer exists simply +// never matches), so this only removes the references the validator would +// otherwise report as dangling. Returns whether anything changed. +func (r *Room) RemoveRoomRefs(removedID int) bool { + if r == nil || removedID <= 0 { + return false + } + changed := false + for i := range r.Mobs { + if removeRoomRef(&r.Mobs[i].WanderRooms, removedID) { + changed = true + } + } + for i := range r.Objects { + if removeRoomRef(&r.Objects[i].WanderRooms, removedID) { + changed = true + } + } + return changed +} + +// removeRoomRef removes target from list in place and reports whether it was +// present. +func removeRoomRef(list *[]int, target int) bool { + src := *list + out := src[:0] + removed := false + for _, v := range src { + if v == target { + removed = true + continue + } + out = append(out, v) + } + *list = out + return removed +} + // remapTriggers remaps step fields across a []behavior.Trigger (each trigger's // Steps + per-step Condition + trigger-level Condition). func remapTriggers(idMap map[int]int, list []behavior.Trigger) bool { |
