Added IWallConnector trait interface
This commit is contained in:
@@ -68,12 +68,19 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class WithWallSpriteBody : WithSpriteBody, INotifyRemovedFromWorld, ITick
|
class WithWallSpriteBody : WithSpriteBody, INotifyRemovedFromWorld, IWallConnector, ITick
|
||||||
{
|
{
|
||||||
readonly WithWallSpriteBodyInfo wallInfo;
|
readonly WithWallSpriteBodyInfo wallInfo;
|
||||||
int adjacent = 0;
|
int adjacent = 0;
|
||||||
bool dirty = true;
|
bool dirty = true;
|
||||||
|
|
||||||
|
bool IWallConnector.AdjacentWallCanConnect(Actor self, CPos wallLocation, string wallType)
|
||||||
|
{
|
||||||
|
return wallInfo.Type == wallType;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IWallConnector.SetDirty() { dirty = true; }
|
||||||
|
|
||||||
public WithWallSpriteBody(ActorInitializer init, WithWallSpriteBodyInfo info)
|
public WithWallSpriteBody(ActorInitializer init, WithWallSpriteBodyInfo info)
|
||||||
: base(init, info, () => 0)
|
: base(init, info, () => 0)
|
||||||
{
|
{
|
||||||
@@ -97,8 +104,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
adjacent = 0;
|
adjacent = 0;
|
||||||
foreach (var a in adjacentActors)
|
foreach (var a in adjacentActors)
|
||||||
{
|
{
|
||||||
var rb = a.TraitOrDefault<WithWallSpriteBody>();
|
var rb = a.TraitOrDefault<IWallConnector>();
|
||||||
if (rb == null || rb.wallInfo.Type != wallInfo.Type)
|
if (rb == null || !rb.AdjacentWallCanConnect(self, self.Location, wallInfo.Type))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var location = self.Location;
|
var location = self.Location;
|
||||||
@@ -127,11 +134,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
var adjacentActors = CVec.Directions.SelectMany(dir =>
|
var adjacentActors = CVec.Directions.SelectMany(dir =>
|
||||||
self.World.ActorMap.GetActorsAt(self.Location + dir))
|
self.World.ActorMap.GetActorsAt(self.Location + dir))
|
||||||
.Select(a => a.TraitOrDefault<WithWallSpriteBody>())
|
.Select(a => a.TraitOrDefault<IWallConnector>())
|
||||||
.Where(a => a != null);
|
.Where(a => a != null);
|
||||||
|
|
||||||
foreach (var rb in adjacentActors)
|
foreach (var rb in adjacentActors)
|
||||||
rb.dirty = true;
|
rb.SetDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemovedFromWorld(Actor self)
|
public void RemovedFromWorld(Actor self)
|
||||||
|
|||||||
@@ -116,4 +116,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
bool PreventsAutoTarget(Actor self, Actor attacker);
|
bool PreventsAutoTarget(Actor self, Actor attacker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RequireExplicitImplementation]
|
||||||
|
interface IWallConnector
|
||||||
|
{
|
||||||
|
bool AdjacentWallCanConnect(Actor self, CPos wallLocation, string wallType);
|
||||||
|
void SetDirty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user