Skip to content

Commit

Permalink
Allow for irregular shaped lb groups (#4166)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mag-nus authored May 12, 2024
1 parent ef427aa commit 95e60bf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
19 changes: 18 additions & 1 deletion Source/ACE.Server/Entity/LandblockGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,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);
Expand Down Expand Up @@ -283,6 +283,23 @@ public List<LandblockGroup> 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;
}

/// <summary>
/// This will calculate the distance from the landblock group boarder.<para />
/// -X = Inside the bounds, where -1 is the outer perimeter<para />
Expand Down
17 changes: 17 additions & 0 deletions Source/ACE.Server/Entity/LandblockGroupSplitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <summary>
/// This will calculate the distance from the landblock group boarder.<para />
/// -X = Inside the bounds, where -1 is the outer perimeter<para />
Expand Down
2 changes: 1 addition & 1 deletion Source/ACE.Server/Managers/LandblockManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,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);
Expand Down

0 comments on commit 95e60bf

Please sign in to comment.