Add ignoreActor and checkTransientActors to IPositionable.CanEnterCell

Improved 'return' checks
Removed unnecessary 'using'
Fixed defaults.yaml spelling error
This commit is contained in:
Taryn Hill
2013-10-11 02:46:32 -04:00
parent e9652db486
commit e3e7d0b38c
6 changed files with 30 additions and 14 deletions

View File

@@ -137,6 +137,7 @@ namespace OpenRA.Traits
public interface IPositionable : IOccupySpace public interface IPositionable : IOccupySpace
{ {
bool CanEnterCell(CPos location); bool CanEnterCell(CPos location);
bool CanEnterCell(CPos location, Actor ignoreActor, bool checkTransientActors);
void SetPosition(Actor self, CPos cell); void SetPosition(Actor self, CPos cell);
void SetPosition(Actor self, WPos pos); void SetPosition(Actor self, WPos pos);
void SetVisualPosition(Actor self, WPos pos); void SetVisualPosition(Actor self, WPos pos);

View File

@@ -140,6 +140,7 @@ namespace OpenRA.Mods.RA.Air
} }
public bool CanEnterCell(CPos location) { return true; } public bool CanEnterCell(CPos location) { return true; }
public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors) { return CanEnterCell(cell, null, true); }
public int MovementSpeed public int MovementSpeed
{ {

View File

@@ -88,19 +88,26 @@ namespace OpenRA.Mods.RA
public void SetPosition(Actor self, WPos pos) { SetPosition(self, pos.ToCPos()); } public void SetPosition(Actor self, WPos pos) { SetPosition(self, pos.ToCPos()); }
public void SetVisualPosition(Actor self, WPos pos) { SetPosition(self, pos.ToCPos()); } public void SetVisualPosition(Actor self, WPos pos) { SetPosition(self, pos.ToCPos()); }
public bool CanEnterCell(CPos cell) public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors)
{ {
if (!self.World.Map.IsInMap(cell.X, cell.Y)) return false; if (!self.World.Map.IsInMap(cell.X, cell.Y)) return false;
var type = self.World.GetTerrainType(cell); var type = self.World.GetTerrainType(cell);
if (!info.TerrainTypes.Contains(type)) if (!info.TerrainTypes.Contains(type))
return false; return false;
if (self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(cell) != null) return false; if (self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(cell) != null) return false;
if (self.World.ActorMap.GetUnitsAt(cell).Any()) return false;
if (!checkTransientActors)
return true; return true;
return !self.World.ActorMap.GetUnitsAt(cell)
.Where(x => x != ignoreActor)
.Any();
} }
public bool CanEnterCell(CPos cell) { return CanEnterCell(cell, null, true); }
public void SetPosition(Actor self, CPos cell) public void SetPosition(Actor self, CPos cell)
{ {
self.World.ActorMap.RemoveInfluence(self, this); self.World.ActorMap.RemoveInfluence(self, this);

View File

@@ -8,7 +8,6 @@
*/ */
#endregion #endregion
using System.Linq;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Mods.RA.Effects; using OpenRA.Mods.RA.Effects;
using OpenRA.Traits; using OpenRA.Traits;
@@ -29,15 +28,16 @@ namespace OpenRA.Mods.RA
{ {
public void Killed(Actor self, AttackInfo e) public void Killed(Actor self, AttackInfo e)
{ {
var cp = self.CenterPosition; if (self.Owner.WinState == WinState.Lost)
var info = self.Info.Traits.Get<EjectOnDeathInfo>(); return;
var r = self.World.SharedRandom.Next(1, 100); var r = self.World.SharedRandom.Next(1, 100);
var info = self.Info.Traits.Get<EjectOnDeathInfo>();
if (r <= 100 - info.SuccessRate || self.Owner.WinState == WinState.Lost) if (r <= 100 - info.SuccessRate)
return; return;
if ((!info.EjectInAir && cp.Z > 0) || (!info.EjectOnGround && cp.Z == 0)) var cp = self.CenterPosition;
return;
var pilot = self.World.CreateActor(false, info.PilotActor.ToLowerInvariant(), var pilot = self.World.CreateActor(false, info.PilotActor.ToLowerInvariant(),
new TypeDictionary { new OwnerInit(self.Owner), new LocationInit(self.Location) }); new TypeDictionary { new OwnerInit(self.Owner), new LocationInit(self.Location) });
@@ -45,12 +45,12 @@ namespace OpenRA.Mods.RA
if (IsSuitableCell(self, pilot, self.Location)) if (IsSuitableCell(self, pilot, self.Location))
{ {
if (cp.Z > 0 && info.EjectInAir) if (cp.Z > 0)
{ {
self.World.AddFrameEndTask(w => w.Add(new Parachute(pilot, cp))); self.World.AddFrameEndTask(w => w.Add(new Parachute(pilot, cp)));
Sound.Play(info.ChuteSound, cp); Sound.Play(info.ChuteSound, cp);
} }
else if (cp.Z == 0 && info.EjectOnGround) else
self.World.AddFrameEndTask(w => w.Add(pilot)); self.World.AddFrameEndTask(w => w.Add(pilot));
} }
else else

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Mods.RA
} }
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); } public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); }
public bool CanEnterCell(CPos cell) public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors)
{ {
if (!self.World.Map.IsInMap(cell.X, cell.Y)) if (!self.World.Map.IsInMap(cell.X, cell.Y))
return false; return false;
@@ -60,9 +60,16 @@ namespace OpenRA.Mods.RA
if (!info.AllowedTerrain.Contains(self.World.GetTerrainType(cell))) if (!info.AllowedTerrain.Contains(self.World.GetTerrainType(cell)))
return false; return false;
return !self.World.ActorMap.AnyUnitsAt(cell); if (!checkTransientActors)
return true;
return !self.World.ActorMap.GetUnitsAt(cell)
.Where(x => x != ignoreActor)
.Any();
} }
public bool CanEnterCell(CPos cell) { return CanEnterCell(cell, null, true); }
public void SetPosition(Actor self, CPos cell) { SetPosition(self, cell.CenterPosition); } public void SetPosition(Actor self, CPos cell) { SetPosition(self, cell.CenterPosition); }
public void SetVisualPosition(Actor self, WPos pos) public void SetVisualPosition(Actor self, WPos pos)
{ {

View File

@@ -195,7 +195,7 @@
EjectOnDeath: EjectOnDeath:
PilotActor: E1 PilotActor: E1
SuccessRate: 50 SuccessRate: 50
EjectOnDeath: no EjectOnGround: no
EjectInAir: yes EjectInAir: yes
GivesBounty: GivesBounty:
GpsDot: GpsDot: