Fix wall adjacency for multi-cell neighbours.
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
@@ -74,9 +75,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
int adjacent = 0;
|
int adjacent = 0;
|
||||||
bool dirty = true;
|
bool dirty = true;
|
||||||
|
|
||||||
bool IWallConnector.AdjacentWallCanConnect(Actor self, CPos wallLocation, string wallType)
|
bool IWallConnector.AdjacentWallCanConnect(Actor self, CPos wallLocation, string wallType, out CVec facing)
|
||||||
{
|
{
|
||||||
return wallInfo.Type == wallType;
|
facing = wallLocation - self.Location;
|
||||||
|
return wallInfo.Type == wallType && Math.Abs(facing.X) + Math.Abs(facing.Y) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IWallConnector.SetDirty() { dirty = true; }
|
void IWallConnector.SetDirty() { dirty = true; }
|
||||||
@@ -104,20 +106,18 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
adjacent = 0;
|
adjacent = 0;
|
||||||
foreach (var a in adjacentActors)
|
foreach (var a in adjacentActors)
|
||||||
{
|
{
|
||||||
var rb = a.TraitOrDefault<IWallConnector>();
|
CVec facing;
|
||||||
if (rb == null || !rb.AdjacentWallCanConnect(self, self.Location, wallInfo.Type))
|
var wc = a.TraitOrDefault<IWallConnector>();
|
||||||
|
if (wc == null || !wc.AdjacentWallCanConnect(a, self.Location, wallInfo.Type, out facing))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var location = self.Location;
|
if (facing.Y > 0)
|
||||||
var otherLocation = a.Location;
|
|
||||||
|
|
||||||
if (otherLocation == location + new CVec(0, -1))
|
|
||||||
adjacent |= 1;
|
adjacent |= 1;
|
||||||
else if (otherLocation == location + new CVec(+1, 0))
|
else if (facing.X < 0)
|
||||||
adjacent |= 2;
|
adjacent |= 2;
|
||||||
else if (otherLocation == location + new CVec(0, +1))
|
else if (facing.Y < 0)
|
||||||
adjacent |= 4;
|
adjacent |= 4;
|
||||||
else if (otherLocation == location + new CVec(-1, 0))
|
else if (facing.X > 0)
|
||||||
adjacent |= 8;
|
adjacent |= 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[RequireExplicitImplementation]
|
[RequireExplicitImplementation]
|
||||||
interface IWallConnector
|
interface IWallConnector
|
||||||
{
|
{
|
||||||
bool AdjacentWallCanConnect(Actor self, CPos wallLocation, string wallType);
|
bool AdjacentWallCanConnect(Actor self, CPos wallLocation, string wallType, out CVec facing);
|
||||||
void SetDirty();
|
void SetDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user