From d7a0eff16d97b8450853074f3a7e877852c228d1 Mon Sep 17 00:00:00 2001 From: Mag-nus Date: Sun, 28 Apr 2024 11:13:48 -0500 Subject: [PATCH] Allow for irregular shaped lb groups --- Source/ACE.Server/Entity/LandblockGroup.cs | 19 ++++++++++++++++++- .../Entity/LandblockGroupSplitHelper.cs | 17 +++++++++++++++++ .../ACE.Server/Managers/LandblockManager.cs | 2 +- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Source/ACE.Server/Entity/LandblockGroup.cs b/Source/ACE.Server/Entity/LandblockGroup.cs index 138ee76c6e..2d1a340e09 100644 --- a/Source/ACE.Server/Entity/LandblockGroup.cs +++ b/Source/ACE.Server/Entity/LandblockGroup.cs @@ -187,7 +187,7 @@ private LandblockGroup DoTrySplit() for (int i = remainingLandblocks.Count - 1; i >= 0; i--) { - if (landblockGroupSplitHelper.BoundaryDistance(remainingLandblocks[i]) < LandblockGroupMinSpacing) + if (landblockGroupSplitHelper.ClosestLandblock(remainingLandblocks[i]) < LandblockGroupMinSpacing) { landblockGroupSplitHelper.Add(remainingLandblocks[i]); remainingLandblocks.RemoveAt(i); @@ -269,6 +269,23 @@ public List TryThrottledSplit() } + public int ClosestLandblock(Landblock landblock) + { + int closest = int.MaxValue; + + foreach (var value in landblocks) + { + var distance = Math.Max( + Math.Abs(value.Id.LandblockX - landblock.Id.LandblockX), + Math.Abs(value.Id.LandblockY - landblock.Id.LandblockY)); + + if (distance < closest) + closest = distance; + } + + return closest; + } + /// /// This will calculate the distance from the landblock group boarder. /// -X = Inside the bounds, where -1 is the outer perimeter diff --git a/Source/ACE.Server/Entity/LandblockGroupSplitHelper.cs b/Source/ACE.Server/Entity/LandblockGroupSplitHelper.cs index 31b17425c8..baba1dd6e5 100644 --- a/Source/ACE.Server/Entity/LandblockGroupSplitHelper.cs +++ b/Source/ACE.Server/Entity/LandblockGroupSplitHelper.cs @@ -49,6 +49,23 @@ IEnumerator IEnumerable.GetEnumerator() } + public int ClosestLandblock(Landblock landblock) + { + int closest = int.MaxValue; + + foreach (var value in landblocks) + { + var distance = Math.Max( + Math.Abs(value.Id.LandblockX - landblock.Id.LandblockX), + Math.Abs(value.Id.LandblockY - landblock.Id.LandblockY)); + + if (distance < closest) + closest = distance; + } + + return closest; + } + /// /// This will calculate the distance from the landblock group boarder. /// -X = Inside the bounds, where -1 is the outer perimeter diff --git a/Source/ACE.Server/Managers/LandblockManager.cs b/Source/ACE.Server/Managers/LandblockManager.cs index d594d93c58..11d1f93127 100644 --- a/Source/ACE.Server/Managers/LandblockManager.cs +++ b/Source/ACE.Server/Managers/LandblockManager.cs @@ -193,7 +193,7 @@ private static void ProcessPendingLandblockGroupAdditions() if (landblockGroups[j].IsDungeon) continue; - var distance = landblockGroups[j].BoundaryDistance(landblockGroupPendingAdditions[i]); + var distance = landblockGroups[j].ClosestLandblock(landblockGroupPendingAdditions[i]); if (distance < LandblockGroup.LandblockGroupMinSpacing) landblockGroupsIndexMatchesByDistance.Add(j);