simplify Strategic*
This commit is contained in:
@@ -18,15 +18,11 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
public class StrategicPointInfo : ITraitInfo
|
||||
{
|
||||
public readonly bool Critical = false;
|
||||
|
||||
public object Create(ActorInitializer init) { return new StrategicPoint(init.self, this); }
|
||||
}
|
||||
|
||||
public class StrategicPoint : INotifyCapture, ITick, ISync
|
||||
{
|
||||
[Sync] public Actor Self;
|
||||
[Sync] public bool Critical;
|
||||
[Sync] public Player OriginalOwner;
|
||||
[Sync] public int TicksOwned = 0;
|
||||
|
||||
@@ -34,11 +30,8 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public StrategicPoint(Actor self, StrategicPointInfo info)
|
||||
{
|
||||
Self = self;
|
||||
Info = info;
|
||||
OriginalOwner = self.Owner;
|
||||
|
||||
Critical = info.Critical;
|
||||
}
|
||||
|
||||
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||
@@ -49,7 +42,6 @@ namespace OpenRA.Mods.RA
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (OriginalOwner == self.Owner || self.Owner.WinState != WinState.Undefined) return;
|
||||
|
||||
TicksOwned++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,16 +15,11 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
/// <summary>
|
||||
/// Attach to players only kthx :)
|
||||
/// </summary>
|
||||
public class StrategicVictoryConditionsInfo : ITraitInfo, Requires<ConquestVictoryConditionsInfo>
|
||||
{
|
||||
public readonly int TicksToHold = 25 * 60 * 5; // ~5 minutes
|
||||
public readonly bool ResetOnHoldLost = true;
|
||||
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); }
|
||||
}
|
||||
@@ -34,102 +29,28 @@ namespace OpenRA.Mods.RA
|
||||
Actor self;
|
||||
StrategicVictoryConditionsInfo info;
|
||||
|
||||
[Sync] bool SplitHolds;
|
||||
[Sync] public int TicksLeft = 0;
|
||||
[Sync] public int CriticalTicksLeft = 0;
|
||||
|
||||
public StrategicVictoryConditions(Actor self, StrategicVictoryConditionsInfo info)
|
||||
{
|
||||
this.self = self;
|
||||
this.info = info;
|
||||
SplitHolds = info.SplitHolds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
public IEnumerable<TraitPair<StrategicPoint>> AllPoints
|
||||
{
|
||||
get { return self.World.ActorsWithTrait<StrategicPoint>(); }
|
||||
}
|
||||
|
||||
public int Total
|
||||
{
|
||||
get
|
||||
{
|
||||
return SplitHolds
|
||||
? AllPoints.Count( a => a.Trait.Critical )
|
||||
: AllPoints.Count();
|
||||
}
|
||||
}
|
||||
public int Total { get { return AllPoints.Count(); } }
|
||||
int Owned { get { return AllPoints.Count( a => WorldUtils.AreMutualAllies( self.Owner, a.Actor.Owner )); } }
|
||||
|
||||
public int TotalCritical
|
||||
{
|
||||
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 bool Holding { get { return Owned >= info.RatioRequired * Total; } }
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
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
|
||||
if (Total > 0)
|
||||
{
|
||||
|
||||
@@ -35,35 +35,27 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
Init();
|
||||
|
||||
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 totalWidth = (svc.Total + svc.TotalCritical) * 32;
|
||||
int curX = -(totalWidth / 2);
|
||||
var totalWidth = svc.Total * 32;
|
||||
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))
|
||||
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)
|
||||
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;
|
||||
}
|
||||
offset += new int2(0, 32);
|
||||
|
||||
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 tc = "Strategic {0} in {1}".F(
|
||||
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);
|
||||
Game.Renderer.Fonts["Bold"].DrawText(tc, offset + new float2(RenderBounds.Left - size.X / 2, RenderBounds.Top), Color.WhiteSmoke);
|
||||
var size = font.Measure(tc);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -93,12 +85,6 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
{
|
||||
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)
|
||||
{
|
||||
shortest = svc.TicksLeft;
|
||||
|
||||
Reference in New Issue
Block a user