aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_dig.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-09-18 20:03:13 -0400
committerhistoria <[not public]>2026-09-18 20:03:13 -0400
commit79764732406d6484f67d3dec045483dcb5d08c28 (patch)
tree7a64e8581a540b97ed554f5723e2d587424ab1c6 /internal/game/cmd_dig.go
parentf1e461ab6aec6b9bf056bbe2daa88a251e0f21da (diff)
downloadthehouseoficarus-79764732406d6484f67d3dec045483dcb5d08c28.tar.gz
feat: better card ascii art
Diffstat (limited to 'internal/game/cmd_dig.go')
-rw-r--r--internal/game/cmd_dig.go26
1 files changed, 17 insertions, 9 deletions
diff --git a/internal/game/cmd_dig.go b/internal/game/cmd_dig.go
index c58ba63..ff33490 100644
--- a/internal/game/cmd_dig.go
+++ b/internal/game/cmd_dig.go
@@ -127,7 +127,7 @@ func (g *Game) executeDig(sess *net.Session, args []string, rawInput string) {
return
}
- newID, err := findNextRoomID(curPath)
+ newID, err := findNextRoomID(filepath.Dir(curPath), g.World.RoomIndex())
if err != nil {
sess.WriteLine("Error scanning room directory.")
return
@@ -222,14 +222,22 @@ func (g *Game) executeDig(sess *net.Session, args []string, rawInput string) {
g.checkAggro(sess)
}
-func findNextRoomID(currentRoomPath string) (int, error) {
- dir := filepath.Dir(currentRoomPath)
- entries, err := os.ReadDir(dir)
+// findNextRoomID returns the first free room ID at or above localDir's
+// minimum, checked against every room ID in the world (globallyUsed). The
+// admin allocator (admin/id_alloc.go) does the same. A directory-scoped scan
+// could hand out an ID that already exists in another area, and
+// World.AddRoomPath would then silently shadow that room for the rest of the
+// process while leaving a duplicate file on disk.
+func findNextRoomID(localDir string, globallyUsed map[int]bool) (int, error) {
+ entries, err := os.ReadDir(localDir)
if err != nil {
return 0, err
}
- used := make(map[int]bool)
+ used := make(map[int]bool, len(globallyUsed)+len(entries))
+ for id := range globallyUsed {
+ used[id] = true
+ }
minID := 0
first := true
for _, entry := range entries {
@@ -248,11 +256,11 @@ func findNextRoomID(currentRoomPath string) (int, error) {
}
}
- if first {
- return 1, nil
+ start := 1
+ if !first {
+ start = minID
}
-
- for id := minID; ; id++ {
+ for id := start; ; id++ {
if !used[id] {
return id, nil
}