More caching
This commit is contained in:
@@ -59,11 +59,23 @@ namespace OpenRA.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
Shroud shroud;
|
Shroud shroud;
|
||||||
|
UnitInfluence uim;
|
||||||
|
UnitInfo unitInfo;
|
||||||
|
BuildingInfluence bim;
|
||||||
|
bool canShareCell;
|
||||||
|
|
||||||
public Mobile(ActorInitializer init, MobileInfo info)
|
public Mobile(ActorInitializer init, MobileInfo info)
|
||||||
{
|
{
|
||||||
this.self = init.self;
|
this.self = init.self;
|
||||||
this.Info = info;
|
this.Info = info;
|
||||||
this.__fromCell = this.__toCell = init.location;
|
this.__fromCell = this.__toCell = init.location;
|
||||||
|
|
||||||
|
shroud = self.World.WorldActor.traits.Get<Shroud>();
|
||||||
|
uim = self.World.WorldActor.traits.Get<UnitInfluence>();
|
||||||
|
bim = self.World.WorldActor.traits.Get<BuildingInfluence>();
|
||||||
|
unitInfo = self.Info.Traits.GetOrDefault<UnitInfo>();
|
||||||
|
canShareCell = self.traits.Contains<SharesCell>();
|
||||||
|
|
||||||
AddInfluence();
|
AddInfluence();
|
||||||
|
|
||||||
TerrainCost = new Dictionary<string, float>();
|
TerrainCost = new Dictionary<string, float>();
|
||||||
@@ -77,7 +89,6 @@ namespace OpenRA.Traits
|
|||||||
TerrainCost.Add(info.TerrainTypes[i], 1f/info.TerrainSpeeds[i]);
|
TerrainCost.Add(info.TerrainTypes[i], 1f/info.TerrainSpeeds[i]);
|
||||||
TerrainSpeed.Add(info.TerrainTypes[i], info.TerrainSpeeds[i]);
|
TerrainSpeed.Add(info.TerrainTypes[i], info.TerrainSpeeds[i]);
|
||||||
}
|
}
|
||||||
shroud = self.World.WorldActor.traits.Get<Shroud>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPosition(Actor self, int2 cell)
|
public void SetPosition(Actor self, int2 cell)
|
||||||
@@ -160,7 +171,7 @@ namespace OpenRA.Traits
|
|||||||
public virtual bool CanEnterCell(int2 cell, Actor ignoreActor, bool checkTransientActors)
|
public virtual bool CanEnterCell(int2 cell, Actor ignoreActor, bool checkTransientActors)
|
||||||
{
|
{
|
||||||
// Check for buildings
|
// Check for buildings
|
||||||
var building = self.World.WorldActor.traits.Get<BuildingInfluence>().GetBuildingBlocking(cell);
|
var building = bim.GetBuildingBlocking(cell);
|
||||||
if (building != null && building != ignoreActor)
|
if (building != null && building != ignoreActor)
|
||||||
{
|
{
|
||||||
if (Info.Crushes == null)
|
if (Info.Crushes == null)
|
||||||
@@ -177,10 +188,9 @@ namespace OpenRA.Traits
|
|||||||
// Check mobile actors
|
// Check mobile actors
|
||||||
if (checkTransientActors)
|
if (checkTransientActors)
|
||||||
{
|
{
|
||||||
var canShare = self.traits.Contains<SharesCell>();
|
var actors = uim.GetUnitsAt(cell).Where(a => a != self && a != ignoreActor);
|
||||||
var actors = self.World.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(cell).Where(a => a != self && a != ignoreActor);
|
var nonshareable = actors.Where(a => !(canShareCell && a.traits.Contains<SharesCell>()));
|
||||||
var nonshareable = actors.Where(a => !(canShare && a.traits.Contains<SharesCell>()));
|
var shareable = actors.Where(a => canShareCell && a.traits.Contains<SharesCell>());
|
||||||
var shareable = actors.Where(a => canShare && a.traits.Contains<SharesCell>());
|
|
||||||
|
|
||||||
// only allow 5 in a cell
|
// only allow 5 in a cell
|
||||||
if (shareable.Count() >= 5)
|
if (shareable.Count() >= 5)
|
||||||
@@ -200,7 +210,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public virtual void FinishedMoving(Actor self)
|
public virtual void FinishedMoving(Actor self)
|
||||||
{
|
{
|
||||||
var crushable = self.World.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(self.Location).Where(a => a != self && a.traits.Contains<ICrushable>());
|
var crushable = uim.GetUnitsAt(self.Location).Where(a => a != self && a.traits.Contains<ICrushable>());
|
||||||
foreach (var a in crushable)
|
foreach (var a in crushable)
|
||||||
{
|
{
|
||||||
var crushActions = a.traits.WithInterface<ICrushable>().Where(b => b.CrushClasses.Intersect(Info.Crushes).Any());
|
var crushActions = a.traits.WithInterface<ICrushable>().Where(b => b.CrushClasses.Intersect(Info.Crushes).Any());
|
||||||
@@ -220,7 +230,6 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public virtual float MovementSpeedForCell(Actor self, int2 cell)
|
public virtual float MovementSpeedForCell(Actor self, int2 cell)
|
||||||
{
|
{
|
||||||
var unitInfo = self.Info.Traits.GetOrDefault<UnitInfo>();
|
|
||||||
if( unitInfo == null )
|
if( unitInfo == null )
|
||||||
return 0f;
|
return 0f;
|
||||||
|
|
||||||
@@ -243,12 +252,12 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public virtual void AddInfluence()
|
public virtual void AddInfluence()
|
||||||
{
|
{
|
||||||
self.World.WorldActor.traits.Get<UnitInfluence>().Add( self, this );
|
uim.Add( self, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void RemoveInfluence()
|
public virtual void RemoveInfluence()
|
||||||
{
|
{
|
||||||
self.World.WorldActor.traits.Get<UnitInfluence>().Remove( self, this );
|
uim.Remove( self, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnNudge(Actor self, Actor nudger)
|
public void OnNudge(Actor self, Actor nudger)
|
||||||
|
|||||||
Reference in New Issue
Block a user