Convert crushclasses to bitset
This commit is contained in:
@@ -9,7 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
@@ -18,10 +17,10 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
{
|
{
|
||||||
class MineInfo : ITraitInfo
|
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 AvoidFriendly = true;
|
||||||
public readonly bool BlockFriendly = 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); }
|
public object Create(ActorInitializer init) { return new Mine(this); }
|
||||||
}
|
}
|
||||||
@@ -35,9 +34,9 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
this.info = info;
|
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))
|
if (!info.CrushClasses.Overlaps(crushClasses))
|
||||||
return;
|
return;
|
||||||
@@ -52,7 +51,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
self.Kill(crusher, mobile != null ? mobile.Info.LocomotorInfo.CrushDamageTypes : default(BitSet<DamageType>));
|
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)
|
if (info.BlockFriendly && !crusher.Info.HasTraitInfo<MineImmuneInfo>() && self.Owner.Stances[crusher.Owner] == Stance.Ally)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
this.Info = info;
|
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>()
|
var external = crusher.TraitsImplementing<ExternalCondition>()
|
||||||
.FirstOrDefault(t => t.Info.Condition == Info.OnCrushCondition && t.CanGrantCondition(crusher, self));
|
.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);
|
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>()
|
var external = crusher.TraitsImplementing<ExternalCondition>()
|
||||||
.FirstOrDefault(t => t.Info.Condition == Info.WarnCrushCondition && t.CanGrantCondition(crusher, self));
|
.FirstOrDefault(t => t.Info.Condition == Info.WarnCrushCondition && t.CanGrantCondition(crusher, self));
|
||||||
|
|||||||
@@ -91,9 +91,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
SetPosition(self, init.Get<LocationInit, CPos>());
|
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.
|
// Crate can only be crushed if it is not in the air.
|
||||||
if (!self.IsAtGroundLevel() || !crushClasses.Contains(info.CrushClass))
|
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;
|
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.
|
// Crate can only be crushed if it is not in the air.
|
||||||
return self.IsAtGroundLevel() && crushClasses.Contains(info.CrushClass);
|
return self.IsAtGroundLevel() && crushClasses.Contains(info.CrushClass);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Sound to play when being crushed.")]
|
[Desc("Sound to play when being crushed.")]
|
||||||
public readonly string CrushSound = null;
|
public readonly string CrushSound = null;
|
||||||
[Desc("Which crush classes does this actor belong to.")]
|
[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.")]
|
[Desc("Probability of mobile actors noticing and evading a crush attempt.")]
|
||||||
public readonly int WarnProbability = 75;
|
public readonly int WarnProbability = 75;
|
||||||
[Desc("Will friendly units just crush me instead of pathing around.")]
|
[Desc("Will friendly units just crush me instead of pathing around.")]
|
||||||
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
this.self = self;
|
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))
|
if (!CrushableInner(crushClasses, crusher.Owner))
|
||||||
return;
|
return;
|
||||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
mobile.Nudge(self, crusher, true);
|
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))
|
if (!CrushableInner(crushClasses, crusher.Owner))
|
||||||
return;
|
return;
|
||||||
@@ -61,12 +61,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
self.Kill(crusher, crusherMobile != null ? crusherMobile.Info.LocomotorInfo.CrushDamageTypes : default(BitSet<DamageType>));
|
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);
|
return CrushableInner(crushClasses, crusher.Owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CrushableInner(HashSet<string> crushClasses, Player crushOwner)
|
bool CrushableInner(BitSet<CrushClass> crushClasses, Player crushOwner)
|
||||||
{
|
{
|
||||||
if (IsTraitDisabled)
|
if (IsTraitDisabled)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.Common.Effects;
|
using OpenRA.Mods.Common.Effects;
|
||||||
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits.Render
|
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)));
|
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;
|
crushed = true;
|
||||||
|
|
||||||
@@ -112,6 +113,6 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
SpawnDeathAnimation(self, self.CenterPosition, rs.GetImage(self), Info.CrushedSequence, crushPalette);
|
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) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using OpenRA.Mods.Common.Activities;
|
using OpenRA.Mods.Common.Activities;
|
||||||
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public readonly bool SkipMakeAnims = true;
|
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); }
|
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;
|
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))
|
if (!info.CrushClasses.Overlaps(crushClasses))
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public readonly bool MoveIntoShroud = true;
|
public readonly bool MoveIntoShroud = true;
|
||||||
|
|
||||||
[Desc("e.g. crate, wall, infantry")]
|
[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.")]
|
[Desc("Types of damage that are caused while crushing. Leave empty for no damage types.")]
|
||||||
public readonly BitSet<DamageType> CrushDamageTypes = default(BitSet<DamageType>);
|
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 we cannot crush the other actor in our way, we are blocked.
|
||||||
if (Crushes == null || Crushes.Count == 0)
|
if (Crushes.IsEmpty)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// If the other actor in our way cannot be crushed, we are blocked.
|
// If the other actor in our way cannot be crushed, we are blocked.
|
||||||
|
|||||||
@@ -75,17 +75,20 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
bool IsValidTarget(Actor self, Actor saboteur);
|
bool IsValidTarget(Actor self, Actor saboteur);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Type tag for crush class bits
|
||||||
|
public class CrushClass { }
|
||||||
|
|
||||||
[RequireExplicitImplementation]
|
[RequireExplicitImplementation]
|
||||||
public interface ICrushable
|
public interface ICrushable
|
||||||
{
|
{
|
||||||
bool CrushableBy(Actor self, Actor crusher, HashSet<string> crushClasses);
|
bool CrushableBy(Actor self, Actor crusher, BitSet<CrushClass> crushClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
[RequireExplicitImplementation]
|
[RequireExplicitImplementation]
|
||||||
public interface INotifyCrushed
|
public interface INotifyCrushed
|
||||||
{
|
{
|
||||||
void OnCrush(Actor self, Actor crusher, HashSet<string> crushClasses);
|
void OnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses);
|
||||||
void WarnCrush(Actor self, Actor crusher, HashSet<string> crushClasses);
|
void WarnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
[RequireExplicitImplementation]
|
[RequireExplicitImplementation]
|
||||||
|
|||||||
Reference in New Issue
Block a user