Intermediate crushable-behavior checkin; Muliple units per cell in UIM; Crushable TraitInterface; Crushable units are taken into account in pathfinding; Crashes when trying to crush a unit
This commit is contained in:
@@ -1,17 +1,22 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using OpenRa.Game.Traits;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
class UnitInfluenceMap
|
||||
{
|
||||
Actor[,] influence = new Actor[128, 128];
|
||||
List<Actor>[,] influence = new List<Actor>[128, 128];
|
||||
readonly int2 searchDistance = new int2(2,2);
|
||||
|
||||
public UnitInfluenceMap()
|
||||
{
|
||||
for (int i = 0; i < 128; i++)
|
||||
for (int j = 0; j < 128; j++)
|
||||
influence[ i, j ] = new List<Actor>();
|
||||
|
||||
Game.world.ActorRemoved += a => Remove(a, a.traits.WithInterface<IOccupySpace>().FirstOrDefault());
|
||||
}
|
||||
|
||||
@@ -25,25 +30,28 @@ namespace OpenRa.Game
|
||||
{
|
||||
for( int y = 0 ; y < 128 ; y++ )
|
||||
for( int x = 0 ; x < 128 ; x++ )
|
||||
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" );
|
||||
if( influence[ x, y ] != null )
|
||||
foreach (var a in influence[ x, y ])
|
||||
if (!a.traits.WithInterface<IOccupySpace>().First().OccupiedCells().Contains( new int2( x, y ) ) )
|
||||
throw new InvalidOperationException( "UIM: Sanity check failed A" );
|
||||
|
||||
foreach( var a in Game.world.Actors )
|
||||
foreach( Actor a in Game.world.Actors )
|
||||
foreach( var ios in a.traits.WithInterface<IOccupySpace>() )
|
||||
foreach( var cell in ios.OccupiedCells() )
|
||||
if( influence[ cell.X, cell.Y ] != a )
|
||||
throw new InvalidOperationException( "UIM: Sanity check failed B" );
|
||||
if (!influence[cell.X, cell.Y].Contains(a))
|
||||
//if( influence[ cell.X, cell.Y ] != a )
|
||||
throw new InvalidOperationException( "UIM: Sanity check failed B" );
|
||||
}
|
||||
|
||||
[Conditional( "SANITY_CHECKS" )]
|
||||
void SanityCheckAdd( IOccupySpace a )
|
||||
{
|
||||
foreach( var c in a.OccupiedCells() )
|
||||
if( influence[c.X, c.Y] != null )
|
||||
if( influence[c.X, c.Y].Any())
|
||||
throw new InvalidOperationException( "UIM: Sanity check failed (Add)" );
|
||||
}
|
||||
|
||||
public Actor GetUnitAt( int2 a )
|
||||
public IEnumerable<Actor> GetUnitsAt( int2 a )
|
||||
{
|
||||
return influence[ a.X, a.Y ];
|
||||
}
|
||||
@@ -52,14 +60,14 @@ namespace OpenRa.Game
|
||||
{
|
||||
SanityCheckAdd( unit );
|
||||
foreach( var c in unit.OccupiedCells() )
|
||||
influence[c.X, c.Y] = self;
|
||||
influence[c.X, c.Y].Add(self);
|
||||
}
|
||||
|
||||
public void Remove( Actor self, IOccupySpace unit )
|
||||
{
|
||||
if (unit != null)
|
||||
foreach (var c in unit.OccupiedCells())
|
||||
influence[c.X, c.Y] = null;
|
||||
influence[c.X, c.Y].Remove(self);
|
||||
}
|
||||
|
||||
public void Update(Actor self, IOccupySpace unit)
|
||||
|
||||
Reference in New Issue
Block a user