UIM no longer references Mobile by name (uses IOccupySpace)
This commit is contained in:
@@ -99,8 +99,6 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
unit.Facing,
|
unit.Facing,
|
||||||
0 );
|
0 );
|
||||||
|
|
||||||
Game.UnitInfluence.Update( mobile );
|
|
||||||
|
|
||||||
move.TickMove( self, mobile, this );
|
move.TickMove( self, mobile, this );
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -129,10 +127,10 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game.UnitInfluence.Remove( mobile );
|
Game.UnitInfluence.Remove( self, mobile );
|
||||||
var newPath = getPath(self, mobile).TakeWhile(a => a != self.Location).ToList();
|
var newPath = getPath(self, mobile).TakeWhile(a => a != self.Location).ToList();
|
||||||
|
|
||||||
Game.UnitInfluence.Add( mobile );
|
Game.UnitInfluence.Add( self, mobile );
|
||||||
if (newPath.Count != 0)
|
if (newPath.Count != 0)
|
||||||
path = newPath;
|
path = newPath;
|
||||||
|
|
||||||
@@ -219,7 +217,6 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
moveFraction - moveFractionTotal );
|
moveFraction - moveFractionTotal );
|
||||||
mobile.fromCell = mobile.toCell;
|
mobile.fromCell = mobile.toCell;
|
||||||
mobile.toCell = nextCell.Value;
|
mobile.toCell = nextCell.Value;
|
||||||
Game.UnitInfluence.Update( mobile );
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -232,7 +229,6 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
unit.Facing,
|
unit.Facing,
|
||||||
moveFraction - moveFractionTotal );
|
moveFraction - moveFractionTotal );
|
||||||
mobile.fromCell = mobile.toCell;
|
mobile.fromCell = mobile.toCell;
|
||||||
Game.UnitInfluence.Update( mobile );
|
|
||||||
return ret2;
|
return ret2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,25 +7,25 @@ namespace OpenRa.Game.Traits
|
|||||||
{
|
{
|
||||||
class Mobile : IOrder, IOccupySpace
|
class Mobile : IOrder, IOccupySpace
|
||||||
{
|
{
|
||||||
public Actor self;
|
readonly Actor self;
|
||||||
|
|
||||||
int2 __fromCell;
|
int2 __fromCell;
|
||||||
public int2 fromCell
|
public int2 fromCell
|
||||||
{
|
{
|
||||||
get { return __fromCell; }
|
get { return __fromCell; }
|
||||||
set { Game.UnitInfluence.Remove(this); __fromCell = value; Game.UnitInfluence.Add(this); }
|
set { Game.UnitInfluence.Remove(self, this); __fromCell = value; Game.UnitInfluence.Add(self, this); }
|
||||||
}
|
}
|
||||||
public int2 toCell
|
public int2 toCell
|
||||||
{
|
{
|
||||||
get { return self.Location; }
|
get { return self.Location; }
|
||||||
set { Game.UnitInfluence.Remove(this); self.Location = value; Game.UnitInfluence.Add(this); }
|
set { Game.UnitInfluence.Remove(self, this); self.Location = value; Game.UnitInfluence.Add(self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mobile(Actor self)
|
public Mobile(Actor self)
|
||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
fromCell = toCell;
|
__fromCell = toCell;
|
||||||
Game.UnitInfluence.Update(this);
|
Game.UnitInfluence.Add(self, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Order IssueOrder(Actor self, int2 xy, bool lmb, Actor underCursor)
|
public Order IssueOrder(Actor self, int2 xy, bool lmb, Actor underCursor)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
public UnitInfluenceMap()
|
public UnitInfluenceMap()
|
||||||
{
|
{
|
||||||
Game.world.ActorRemoved += a => Remove(a.traits.GetOrDefault<Mobile>());
|
Game.world.ActorRemoved += a => Remove(a, a.traits.WithInterface<IOccupySpace>().FirstOrDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick()
|
||||||
@@ -25,21 +25,18 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
for( int y = 0 ; y < 128 ; y++ )
|
for( int y = 0 ; y < 128 ; y++ )
|
||||||
for( int x = 0 ; x < 128 ; x++ )
|
for( int x = 0 ; x < 128 ; x++ )
|
||||||
if( influence[ x, y ] != null && !influence[ x, y ].traits.Get<Mobile>().OccupiedCells().Contains( new int2( x, y ) ) )
|
if( influence[ x, y ] != null && !influence[ x, y ].traits.WithInterface<IOccupySpace>().First().OccupiedCells().Contains( new int2( x, y ) ) )
|
||||||
throw new InvalidOperationException( "UIM: Sanity check failed A" );
|
throw new InvalidOperationException( "UIM: Sanity check failed A" );
|
||||||
|
|
||||||
foreach( var a in Game.world.Actors )
|
foreach( var a in Game.world.Actors )
|
||||||
{
|
foreach( var ios in a.traits.WithInterface<IOccupySpace>() )
|
||||||
if( !a.traits.Contains<Mobile>() )
|
foreach( var cell in ios.OccupiedCells() )
|
||||||
continue;
|
if( influence[ cell.X, cell.Y ] != a )
|
||||||
foreach( var cell in a.traits.Get<Mobile>().OccupiedCells() )
|
throw new InvalidOperationException( "UIM: Sanity check failed B" );
|
||||||
if( influence[ cell.X, cell.Y ] != a )
|
|
||||||
throw new InvalidOperationException( "UIM: Sanity check failed B" );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Conditional( "SANITY_CHECKS" )]
|
[Conditional( "SANITY_CHECKS" )]
|
||||||
void SanityCheckAdd( Mobile a )
|
void SanityCheckAdd( IOccupySpace a )
|
||||||
{
|
{
|
||||||
foreach( var c in a.OccupiedCells() )
|
foreach( var c in a.OccupiedCells() )
|
||||||
if( influence[c.X, c.Y] != null )
|
if( influence[c.X, c.Y] != null )
|
||||||
@@ -51,30 +48,28 @@ namespace OpenRa.Game
|
|||||||
return influence[ a.X, a.Y ];
|
return influence[ a.X, a.Y ];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(Mobile a)
|
public void Add( Actor self, IOccupySpace unit )
|
||||||
{
|
{
|
||||||
SanityCheckAdd(a);
|
SanityCheckAdd( unit );
|
||||||
foreach (var c in a.OccupiedCells())
|
foreach( var c in unit.OccupiedCells() )
|
||||||
influence[c.X, c.Y] = a.self;
|
influence[c.X, c.Y] = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(Mobile a)
|
public void Remove( Actor self, IOccupySpace unit )
|
||||||
{
|
{
|
||||||
if (a == null) return;
|
var min = int2.Max(new int2(0, 0), self.Location - searchDistance);
|
||||||
|
var max = int2.Min(new int2(128, 128), self.Location + searchDistance);
|
||||||
var min = int2.Max(new int2(0, 0), a.self.Location - searchDistance);
|
|
||||||
var max = int2.Min(new int2(128, 128), a.self.Location + searchDistance);
|
|
||||||
|
|
||||||
for (var j = min.Y; j <= max.Y; j++)
|
for (var j = min.Y; j <= max.Y; j++)
|
||||||
for (var i = min.X; i <= max.X; i++)
|
for (var i = min.X; i <= max.X; i++)
|
||||||
if (influence[i, j] == a.self)
|
if (influence[i, j] == self)
|
||||||
influence[i, j] = null;
|
influence[i, j] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(Mobile a)
|
public void Update(Actor self, IOccupySpace unit)
|
||||||
{
|
{
|
||||||
Remove(a);
|
Remove(self, unit);
|
||||||
if (!a.self.IsDead) Add(a);
|
if (!self.IsDead) Add(self, unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user