simplify Strategic*
This commit is contained in:
@@ -18,15 +18,11 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
public class StrategicPointInfo : ITraitInfo
|
public class StrategicPointInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
public readonly bool Critical = false;
|
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new StrategicPoint(init.self, this); }
|
public object Create(ActorInitializer init) { return new StrategicPoint(init.self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class StrategicPoint : INotifyCapture, ITick, ISync
|
public class StrategicPoint : INotifyCapture, ITick, ISync
|
||||||
{
|
{
|
||||||
[Sync] public Actor Self;
|
|
||||||
[Sync] public bool Critical;
|
|
||||||
[Sync] public Player OriginalOwner;
|
[Sync] public Player OriginalOwner;
|
||||||
[Sync] public int TicksOwned = 0;
|
[Sync] public int TicksOwned = 0;
|
||||||
|
|
||||||
@@ -34,11 +30,8 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
public StrategicPoint(Actor self, StrategicPointInfo info)
|
public StrategicPoint(Actor self, StrategicPointInfo info)
|
||||||
{
|
{
|
||||||
Self = self;
|
|
||||||
Info = info;
|
Info = info;
|
||||||
OriginalOwner = self.Owner;
|
OriginalOwner = self.Owner;
|
||||||
|
|
||||||
Critical = info.Critical;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||||
@@ -49,7 +42,6 @@ namespace OpenRA.Mods.RA
|
|||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (OriginalOwner == self.Owner || self.Owner.WinState != WinState.Undefined) return;
|
if (OriginalOwner == self.Owner || self.Owner.WinState != WinState.Undefined) return;
|
||||||
|
|
||||||
TicksOwned++;
|
TicksOwned++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,16 +15,11 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Attach to players only kthx :)
|
|
||||||
/// </summary>
|
|
||||||
public class StrategicVictoryConditionsInfo : ITraitInfo, Requires<ConquestVictoryConditionsInfo>
|
public class StrategicVictoryConditionsInfo : ITraitInfo, Requires<ConquestVictoryConditionsInfo>
|
||||||
{
|
{
|
||||||
public readonly int TicksToHold = 25 * 60 * 5; // ~5 minutes
|
public readonly int TicksToHold = 25 * 60 * 5; // ~5 minutes
|
||||||
public readonly bool ResetOnHoldLost = true;
|
public readonly bool ResetOnHoldLost = true;
|
||||||
public readonly float RatioRequired = 0.5f; // 50% required of all koth locations
|
public readonly float RatioRequired = 0.5f; // 50% required of all koth locations
|
||||||
public readonly float CriticalRatioRequired = 1f; // if someone owns 100% of all critical locations
|
|
||||||
public readonly bool SplitHolds = true; // disallow or allow the 'holdsrequired' to include critical locations
|
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new StrategicVictoryConditions(init.self, this); }
|
public object Create(ActorInitializer init) { return new StrategicVictoryConditions(init.self, this); }
|
||||||
}
|
}
|
||||||
@@ -34,102 +29,28 @@ namespace OpenRA.Mods.RA
|
|||||||
Actor self;
|
Actor self;
|
||||||
StrategicVictoryConditionsInfo info;
|
StrategicVictoryConditionsInfo info;
|
||||||
|
|
||||||
[Sync] bool SplitHolds;
|
|
||||||
[Sync] public int TicksLeft = 0;
|
[Sync] public int TicksLeft = 0;
|
||||||
[Sync] public int CriticalTicksLeft = 0;
|
|
||||||
|
|
||||||
public StrategicVictoryConditions(Actor self, StrategicVictoryConditionsInfo info)
|
public StrategicVictoryConditions(Actor self, StrategicVictoryConditionsInfo info)
|
||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
this.info = info;
|
this.info = info;
|
||||||
SplitHolds = info.SplitHolds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public IEnumerable<TraitPair<StrategicPoint>> AllPoints
|
||||||
/// Includes your allies as well
|
|
||||||
/// </summary>
|
|
||||||
int Owned
|
|
||||||
{
|
|
||||||
get { return CountOwnedPoints(false) + (SplitHolds ? 0 : OwnedCritical); }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Includes your allies as well
|
|
||||||
/// </summary>
|
|
||||||
int OwnedCritical
|
|
||||||
{
|
|
||||||
get { return CountOwnedPoints(true); }
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerable<TraitPair<StrategicPoint>> AllPoints
|
|
||||||
{
|
{
|
||||||
get { return self.World.ActorsWithTrait<StrategicPoint>(); }
|
get { return self.World.ActorsWithTrait<StrategicPoint>(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Total
|
public int Total { get { return AllPoints.Count(); } }
|
||||||
{
|
int Owned { get { return AllPoints.Count( a => WorldUtils.AreMutualAllies( self.Owner, a.Actor.Owner )); } }
|
||||||
get
|
|
||||||
{
|
|
||||||
return SplitHolds
|
|
||||||
? AllPoints.Count( a => a.Trait.Critical )
|
|
||||||
: AllPoints.Count();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int TotalCritical
|
public bool Holding { get { return Owned >= info.RatioRequired * Total; } }
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return AllPoints.Count( a => a.Trait.Critical );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int CountOwnedPoints(bool critical)
|
|
||||||
{
|
|
||||||
return AllPoints.Count( a => a.Trait.Critical == critical &&
|
|
||||||
WorldUtils.AreMutualAllies( self.Owner, a.Actor.Owner ));
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool HoldingCritical
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var criticalOwned = 1f / TotalCritical * OwnedCritical;
|
|
||||||
|
|
||||||
return criticalOwned >= info.CriticalRatioRequired;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Holding
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var owned = 1f / Total * Owned;
|
|
||||||
|
|
||||||
return owned >= info.RatioRequired;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (self.Owner.WinState != WinState.Undefined || self.Owner.NonCombatant) return;
|
if (self.Owner.WinState != WinState.Undefined || self.Owner.NonCombatant) return;
|
||||||
|
|
||||||
// See if any of the conditions are met to increase the count
|
|
||||||
if (TotalCritical > 0)
|
|
||||||
{
|
|
||||||
if (HoldingCritical)
|
|
||||||
{
|
|
||||||
// Hah! We met ths critical owned condition
|
|
||||||
if (CriticalTicksLeft == 0)
|
|
||||||
CriticalTicksLeft = info.TicksToHold; // crap
|
|
||||||
else if (--CriticalTicksLeft == 0)
|
|
||||||
Won();
|
|
||||||
}
|
|
||||||
else if (CriticalTicksLeft != 0)
|
|
||||||
if (info.ResetOnHoldLost)
|
|
||||||
CriticalTicksLeft = info.TicksToHold; // Reset the time hold
|
|
||||||
}
|
|
||||||
|
|
||||||
// See if any of the conditions are met to increase the count
|
// See if any of the conditions are met to increase the count
|
||||||
if (Total > 0)
|
if (Total > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,35 +35,27 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
Init();
|
Init();
|
||||||
|
|
||||||
if (!IsVisible()) return;
|
if (!IsVisible()) return;
|
||||||
int2 offset = int2.Zero;
|
|
||||||
|
var rb = RenderBounds;
|
||||||
|
var offset = int2.Zero;
|
||||||
|
|
||||||
var svc = world.Players.Select(p => p.PlayerActor.TraitOrDefault<StrategicVictoryConditions>()).FirstOrDefault();
|
var svc = world.Players.Select(p => p.PlayerActor.TraitOrDefault<StrategicVictoryConditions>()).FirstOrDefault();
|
||||||
|
|
||||||
var totalWidth = (svc.Total + svc.TotalCritical) * 32;
|
var totalWidth = svc.Total * 32;
|
||||||
int curX = -(totalWidth / 2);
|
var curX = -totalWidth / 2;
|
||||||
|
|
||||||
foreach (var a in world.ActorsWithTrait<StrategicPoint>().Where(a => a.Trait.Critical))
|
foreach (var a in svc.AllPoints)
|
||||||
{
|
{
|
||||||
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("strategic", "unowned"), offset + new float2(RenderBounds.Left + curX, RenderBounds.Top));
|
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("strategic", "critical_unowned"), offset + new float2(rb.Left + curX, rb.Top));
|
||||||
|
|
||||||
if (WorldUtils.AreMutualAllies(a.Actor.Owner, world.LocalPlayer))
|
if (WorldUtils.AreMutualAllies(a.Actor.Owner, world.LocalPlayer))
|
||||||
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("strategic", "player_owned"), offset + new float2(RenderBounds.Left + curX, RenderBounds.Top));
|
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("strategic", "player_owned"), offset + new float2(rb.Left + curX, rb.Top));
|
||||||
else if (!a.Actor.Owner.NonCombatant)
|
else if (!a.Actor.Owner.NonCombatant)
|
||||||
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("strategic", "enemy_owned"), offset + new float2(RenderBounds.Left + curX, RenderBounds.Top));
|
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("strategic", "enemy_owned"), offset + new float2(rb.Left + curX, rb.Top));
|
||||||
curX += 32;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var a in world.ActorsWithTrait<StrategicPoint>().Where(a => !a.Trait.Critical))
|
|
||||||
{
|
|
||||||
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("strategic", "critical_unowned"), offset + new float2(RenderBounds.Left + curX, RenderBounds.Top));
|
|
||||||
|
|
||||||
if (WorldUtils.AreMutualAllies(a.Actor.Owner, world.LocalPlayer))
|
|
||||||
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("strategic", "player_owned"), offset + new float2(RenderBounds.Left + curX, RenderBounds.Top));
|
|
||||||
else if (!a.Actor.Owner.NonCombatant)
|
|
||||||
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("strategic", "enemy_owned"), offset + new float2(RenderBounds.Left + curX, RenderBounds.Top));
|
|
||||||
|
|
||||||
curX += 32;
|
curX += 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += new int2(0, 32);
|
offset += new int2(0, 32);
|
||||||
|
|
||||||
if (world.LocalPlayer == null) return;
|
if (world.LocalPlayer == null) return;
|
||||||
@@ -74,12 +66,12 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
var isVictory = pendingWinner == world.LocalPlayer || !WorldUtils.AreMutualAllies(pendingWinner, world.LocalPlayer);
|
var isVictory = pendingWinner == world.LocalPlayer || !WorldUtils.AreMutualAllies(pendingWinner, world.LocalPlayer);
|
||||||
var tc = "Strategic {0} in {1}".F(
|
var tc = "Strategic {0} in {1}".F(
|
||||||
isVictory ? "victory" : "defeat",
|
isVictory ? "victory" : "defeat",
|
||||||
WidgetUtils.FormatTime(Math.Max(winnerSvc.CriticalTicksLeft, winnerSvc.TicksLeft)));
|
WidgetUtils.FormatTime(winnerSvc.TicksLeft));
|
||||||
|
|
||||||
var size = Game.Renderer.Fonts["Bold"].Measure(tc);
|
var font = Game.Renderer.Fonts["Bold"];
|
||||||
|
|
||||||
Game.Renderer.Fonts["Bold"].DrawText(tc, offset + new float2(RenderBounds.Left - size.X / 2 + 1, RenderBounds.Top + 1), Color.Black);
|
var size = font.Measure(tc);
|
||||||
Game.Renderer.Fonts["Bold"].DrawText(tc, offset + new float2(RenderBounds.Left - size.X / 2, RenderBounds.Top), Color.WhiteSmoke);
|
font.DrawTextWithContrast(tc, offset + new float2(rb.Left - size.X / 2 + 1, rb.Top + 1), Color.White, Color.Black, 1);
|
||||||
offset += new int2(0, size.Y + 1);
|
offset += new int2(0, size.Y + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,12 +85,6 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
{
|
{
|
||||||
var svc = p.PlayerActor.Trait<StrategicVictoryConditions>();
|
var svc = p.PlayerActor.Trait<StrategicVictoryConditions>();
|
||||||
|
|
||||||
if (svc.HoldingCritical && svc.CriticalTicksLeft > 0 && svc.CriticalTicksLeft < shortest)
|
|
||||||
{
|
|
||||||
shortest = svc.CriticalTicksLeft;
|
|
||||||
shortestPlayer = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (svc.Holding && svc.TicksLeft > 0 && svc.TicksLeft < shortest)
|
if (svc.Holding && svc.TicksLeft > 0 && svc.TicksLeft < shortest)
|
||||||
{
|
{
|
||||||
shortest = svc.TicksLeft;
|
shortest = svc.TicksLeft;
|
||||||
|
|||||||
Reference in New Issue
Block a user