Change to use pattern matching
This commit is contained in:
@@ -209,12 +209,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
Func<object, bool> saveInit = init =>
|
||||
{
|
||||
var factionInit = init as FactionInit;
|
||||
if (factionInit != null && factionInit.Value == Owner.Faction)
|
||||
if (init is FactionInit factionInit && factionInit.Value == Owner.Faction)
|
||||
return false;
|
||||
|
||||
var healthInit = init as HealthInit;
|
||||
if (healthInit != null && healthInit.Value == 100)
|
||||
if (init is HealthInit healthInit && healthInit.Value == 100)
|
||||
return false;
|
||||
|
||||
// TODO: Other default values will need to be filtered
|
||||
|
||||
@@ -303,8 +303,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (check <= BlockedByActor.Immovable && cellFlag.HasCellFlag(CellFlag.HasMovableActor) &&
|
||||
actor.Owner.RelationshipWith(otherActor.Owner) == PlayerRelationship.Ally)
|
||||
{
|
||||
var mobile = otherActor.OccupiesSpace as Mobile;
|
||||
if (mobile != null && !mobile.IsTraitDisabled && !mobile.IsTraitPaused && !mobile.IsImmovable)
|
||||
if (otherActor.OccupiesSpace is Mobile mobile && !mobile.IsTraitDisabled && !mobile.IsTraitPaused && !mobile.IsImmovable)
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -324,8 +323,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (cellFlag.HasCellFlag(CellFlag.HasTransitOnlyActor))
|
||||
{
|
||||
// Transit only tiles should not block movement
|
||||
var building = otherActor.OccupiesSpace as Building;
|
||||
if (building != null && building.TransitOnlyCells().Contains(cell))
|
||||
if (otherActor.OccupiesSpace is Building building && building.TransitOnlyCells().Contains(cell))
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -346,16 +344,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
static bool IsMoving(Actor self, Actor other)
|
||||
{
|
||||
// PERF: Because we can be sure that OccupiesSpace is Mobile here we can save some performance by avoiding querying for the trait.
|
||||
var otherMobile = other.OccupiesSpace as Mobile;
|
||||
if (otherMobile == null || !otherMobile.CurrentMovementTypes.HasMovementType(MovementType.Horizontal))
|
||||
if (!(other.OccupiesSpace is Mobile otherMobile) || !otherMobile.CurrentMovementTypes.HasMovementType(MovementType.Horizontal))
|
||||
return false;
|
||||
|
||||
// PERF: Same here.
|
||||
var selfMobile = self.OccupiesSpace as Mobile;
|
||||
if (selfMobile == null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return self.OccupiesSpace is Mobile;
|
||||
}
|
||||
|
||||
public void WorldLoaded(World w, WorldRenderer wr)
|
||||
@@ -466,8 +459,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var isMovable = mobile != null && !mobile.IsTraitDisabled && !mobile.IsTraitPaused && !mobile.IsImmovable;
|
||||
var isMoving = isMovable && mobile.CurrentMovementTypes.HasMovementType(MovementType.Horizontal);
|
||||
|
||||
var building = actor.OccupiesSpace as Building;
|
||||
var isTransitOnly = building != null && building.TransitOnlyCells().Contains(cell);
|
||||
var isTransitOnly = actor.OccupiesSpace is Building building && building.TransitOnlyCells().Contains(cell);
|
||||
|
||||
if (isTransitOnly)
|
||||
{
|
||||
|
||||
@@ -158,8 +158,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
IEnumerable<IRenderable> ITiledTerrainRenderer.RenderUIPreview(WorldRenderer wr, TerrainTemplateInfo t, int2 origin, float scale)
|
||||
{
|
||||
var template = t as DefaultTerrainTemplateInfo;
|
||||
if (template == null)
|
||||
if (!(t is DefaultTerrainTemplateInfo template))
|
||||
yield break;
|
||||
|
||||
var ts = map.Grid.TileSize;
|
||||
|
||||
Reference in New Issue
Block a user