Convert crushclasses to bitset

This commit is contained in:
Chris Forbes
2018-07-28 12:50:51 -07:00
committed by Paul Chote
parent 82f6c2b862
commit 51e000599a
8 changed files with 31 additions and 28 deletions

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
@@ -18,10 +17,10 @@ namespace OpenRA.Mods.Cnc.Traits
{
class MineInfo : ITraitInfo
{
public readonly HashSet<string> CrushClasses = new HashSet<string>();
public readonly BitSet<CrushClass> CrushClasses = default(BitSet<CrushClass>);
public readonly bool AvoidFriendly = true;
public readonly bool BlockFriendly = true;
public readonly HashSet<string> DetonateClasses = new HashSet<string>();
public readonly BitSet<CrushClass> DetonateClasses = default(BitSet<CrushClass>);
public object Create(ActorInitializer init) { return new Mine(this); }
}
@@ -35,9 +34,9 @@ namespace OpenRA.Mods.Cnc.Traits
this.info = info;
}
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, HashSet<string> crushClasses) { }
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses) { }
void INotifyCrushed.OnCrush(Actor self, Actor crusher, HashSet<string> crushClasses)
void INotifyCrushed.OnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses)
{
if (!info.CrushClasses.Overlaps(crushClasses))
return;
@@ -52,7 +51,7 @@ namespace OpenRA.Mods.Cnc.Traits
self.Kill(crusher, mobile != null ? mobile.Info.LocomotorInfo.CrushDamageTypes : default(BitSet<DamageType>));
}
bool ICrushable.CrushableBy(Actor self, Actor crusher, HashSet<string> crushClasses)
bool ICrushable.CrushableBy(Actor self, Actor crusher, BitSet<CrushClass> crushClasses)
{
if (info.BlockFriendly && !crusher.Info.HasTraitInfo<MineImmuneInfo>() && self.Owner.Stances[crusher.Owner] == Stance.Ally)
return false;

View File

@@ -9,8 +9,8 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits
this.Info = info;
}
void INotifyCrushed.OnCrush(Actor self, Actor crusher, HashSet<string> crushClasses)
void INotifyCrushed.OnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses)
{
var external = crusher.TraitsImplementing<ExternalCondition>()
.FirstOrDefault(t => t.Info.Condition == Info.OnCrushCondition && t.CanGrantCondition(crusher, self));
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
external.GrantCondition(crusher, self, Info.OnCrushDuration);
}
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, HashSet<string> crushClasses)
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses)
{
var external = crusher.TraitsImplementing<ExternalCondition>()
.FirstOrDefault(t => t.Info.Condition == Info.WarnCrushCondition && t.CanGrantCondition(crusher, self));

View File

@@ -91,9 +91,9 @@ namespace OpenRA.Mods.Common.Traits
SetPosition(self, init.Get<LocationInit, CPos>());
}
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, HashSet<string> crushClasses) { }
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses) { }
void INotifyCrushed.OnCrush(Actor self, Actor crusher, HashSet<string> crushClasses)
void INotifyCrushed.OnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses)
{
// Crate can only be crushed if it is not in the air.
if (!self.IsAtGroundLevel() || !crushClasses.Contains(info.CrushClass))
@@ -216,7 +216,7 @@ namespace OpenRA.Mods.Common.Traits
return GetAvailableSubCell(a, SubCell.Any, ignoreActor, checkTransientActors) != SubCell.Invalid;
}
bool ICrushable.CrushableBy(Actor self, Actor crusher, HashSet<string> crushClasses)
bool ICrushable.CrushableBy(Actor self, Actor crusher, BitSet<CrushClass> crushClasses)
{
// Crate can only be crushed if it is not in the air.
return self.IsAtGroundLevel() && crushClasses.Contains(info.CrushClass);

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Sound to play when being crushed.")]
public readonly string CrushSound = null;
[Desc("Which crush classes does this actor belong to.")]
public readonly HashSet<string> CrushClasses = new HashSet<string> { "infantry" };
public readonly BitSet<CrushClass> CrushClasses = new BitSet<CrushClass>("infantry");
[Desc("Probability of mobile actors noticing and evading a crush attempt.")]
public readonly int WarnProbability = 75;
[Desc("Will friendly units just crush me instead of pathing around.")]
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
this.self = self;
}
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, HashSet<string> crushClasses)
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses)
{
if (!CrushableInner(crushClasses, crusher.Owner))
return;
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
mobile.Nudge(self, crusher, true);
}
void INotifyCrushed.OnCrush(Actor self, Actor crusher, HashSet<string> crushClasses)
void INotifyCrushed.OnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses)
{
if (!CrushableInner(crushClasses, crusher.Owner))
return;
@@ -61,12 +61,12 @@ namespace OpenRA.Mods.Common.Traits
self.Kill(crusher, crusherMobile != null ? crusherMobile.Info.LocomotorInfo.CrushDamageTypes : default(BitSet<DamageType>));
}
bool ICrushable.CrushableBy(Actor self, Actor crusher, HashSet<string> crushClasses)
bool ICrushable.CrushableBy(Actor self, Actor crusher, BitSet<CrushClass> crushClasses)
{
return CrushableInner(crushClasses, crusher.Owner);
}
bool CrushableInner(HashSet<string> crushClasses, Player crushOwner)
bool CrushableInner(BitSet<CrushClass> crushClasses, Player crushOwner)
{
if (IsTraitDisabled)
return false;

View File

@@ -12,6 +12,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Effects;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
@@ -98,7 +99,7 @@ namespace OpenRA.Mods.Common.Traits.Render
self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(pos, w, image, sequence, palette)));
}
void INotifyCrushed.OnCrush(Actor self, Actor crusher, HashSet<string> crushClasses)
void INotifyCrushed.OnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses)
{
crushed = true;
@@ -112,6 +113,6 @@ namespace OpenRA.Mods.Common.Traits.Render
SpawnDeathAnimation(self, self.CenterPosition, rs.GetImage(self), Info.CrushedSequence, crushPalette);
}
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, HashSet<string> crushClasses) { }
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses) { }
}
}

View File

@@ -9,8 +9,8 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.Mods.Common.Activities;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly bool SkipMakeAnims = true;
public readonly HashSet<string> CrushClasses = new HashSet<string>();
public readonly BitSet<CrushClass> CrushClasses = default(BitSet<CrushClass>);
public virtual object Create(ActorInitializer init) { return new TransformCrusherOnCrush(init, this); }
}
@@ -38,9 +38,9 @@ namespace OpenRA.Mods.Common.Traits
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
}
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, HashSet<string> crushClasses) { }
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses) { }
void INotifyCrushed.OnCrush(Actor self, Actor crusher, HashSet<string> crushClasses)
void INotifyCrushed.OnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses)
{
if (!info.CrushClasses.Overlaps(crushClasses))
return;

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly bool MoveIntoShroud = true;
[Desc("e.g. crate, wall, infantry")]
public readonly HashSet<string> Crushes = new HashSet<string>();
public readonly BitSet<CrushClass> Crushes = default(BitSet<CrushClass>);
[Desc("Types of damage that are caused while crushing. Leave empty for no damage types.")]
public readonly BitSet<DamageType> CrushDamageTypes = default(BitSet<DamageType>);
@@ -277,7 +277,7 @@ namespace OpenRA.Mods.Common.Traits
}
// If we cannot crush the other actor in our way, we are blocked.
if (Crushes == null || Crushes.Count == 0)
if (Crushes.IsEmpty)
return true;
// If the other actor in our way cannot be crushed, we are blocked.

View File

@@ -75,17 +75,20 @@ namespace OpenRA.Mods.Common.Traits
bool IsValidTarget(Actor self, Actor saboteur);
}
// Type tag for crush class bits
public class CrushClass { }
[RequireExplicitImplementation]
public interface ICrushable
{
bool CrushableBy(Actor self, Actor crusher, HashSet<string> crushClasses);
bool CrushableBy(Actor self, Actor crusher, BitSet<CrushClass> crushClasses);
}
[RequireExplicitImplementation]
public interface INotifyCrushed
{
void OnCrush(Actor self, Actor crusher, HashSet<string> crushClasses);
void WarnCrush(Actor self, Actor crusher, HashSet<string> crushClasses);
void OnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses);
void WarnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses);
}
[RequireExplicitImplementation]