MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / MigrateCoordinates

Function MigrateCoordinates

internal/mapper/mapper.go:1348–1402  ·  view source on GitHub ↗
(force bool)

Source from the content-addressed store, hash-verified

1346}
1347
1348func MigrateCoordinates(force bool) (migrated int, conflicts []string, unreachable []int) {
1349 for _, zoneName := range rooms.GetAllZoneNames() {
1350 rootRoomId, err := rooms.GetZoneRoot(zoneName)
1351 if err != nil {
1352 continue
1353 }
1354
1355 m := NewMapper(rootRoomId)
1356 m.Start()
1357
1358 zoneRoomIds := rooms.GetAllZoneRoomsIds(zoneName)
1359 crawledSet := make(map[int]struct{}, len(m.crawledRooms))
1360 for rid := range m.crawledRooms {
1361 crawledSet[rid] = struct{}{}
1362 }
1363
1364 for _, rid := range zoneRoomIds {
1365 if _, found := crawledSet[rid]; !found {
1366 unreachable = append(unreachable, rid)
1367 }
1368 }
1369
1370 for roomId, node := range m.crawledRooms {
1371 room := rooms.LoadRoom(roomId)
1372 if room == nil {
1373 continue
1374 }
1375
1376 if room.Zone != zoneName {
1377 continue
1378 }
1379
1380 if room.HasCoordinates && !force {
1381 continue
1382 }
1383
1384 x, y, z := node.Pos.x, node.Pos.y, node.Pos.z
1385
1386 if !rooms.IsCoordinateAvailable(zoneName, x, y, z, roomId) {
1387 occupyingId, _ := rooms.GetRoomAtCoordinate(zoneName, x, y, z)
1388 conflicts = append(conflicts, fmt.Sprintf("room %d and room %d both at (%d, %d, %d) in zone %s", roomId, occupyingId, x, y, z, zoneName))
1389 continue
1390 }
1391
1392 if room.HasCoordinates {
1393 rooms.UnregisterCoordinate(zoneName, roomId)
1394 }
1395 room.SetCoordinates(x, y, z)
1396 rooms.RegisterCoordinate(zoneName, roomId, x, y, z)
1397 rooms.SaveRoomTemplate(*room)
1398 migrated++
1399 }
1400 }
1401 return
1402}

Callers 1

RoomFunction · 0.92

Calls 12

GetAllZoneNamesFunction · 0.92
GetZoneRootFunction · 0.92
GetAllZoneRoomsIdsFunction · 0.92
LoadRoomFunction · 0.92
IsCoordinateAvailableFunction · 0.92
GetRoomAtCoordinateFunction · 0.92
UnregisterCoordinateFunction · 0.92
RegisterCoordinateFunction · 0.92
SaveRoomTemplateFunction · 0.92
NewMapperFunction · 0.85
StartMethod · 0.80
SetCoordinatesMethod · 0.80

Tested by

no test coverage detected