Merge commit 'alzeih/master'; commit 'pchote/master'

This commit is contained in:
Chris Forbes
2010-01-08 10:13:23 +13:00
18 changed files with 372 additions and 111 deletions

View File

@@ -326,6 +326,21 @@ namespace OpenRa.Game
AddButton(chronoshiftRect, isLmb => HandleChronosphereButton());
}
buildPaletteRenderer.DrawSprite(repairButton.Image, chronoshiftDrawPos, PaletteType.Chrome);
// Iron Curtain
Rectangle curtainRect = new Rectangle(6, 14+50, repairButton.Image.bounds.Width, repairButton.Image.bounds.Height);
var curtainDrawPos = Game.viewport.Location + new float2(curtainRect.Location);
var hasCurtain = Game.world.Actors.Any(a => a.Owner == Game.LocalPlayer && a.traits.Contains<IronCurtain>());
if (!hasCurtain)
repairButton.ReplaceAnim("disabled");
else
{
//repairButton.ReplaceAnim(Game.controller.orderGenerator is RepairOrderGenerator ? "pressed" : "normal");
AddButton(curtainRect, isLmb => HandleIronCurtainButton());
}
buildPaletteRenderer.DrawSprite(repairButton.Image, curtainDrawPos, PaletteType.Chrome);
// Repair
@@ -423,6 +438,12 @@ namespace OpenRa.Game
Sound.Play("slcttgt1.aud");
}
void HandleIronCurtainButton()
{
if (Game.controller.ToggleInputMode<IronCurtainOrderGenerator>())
Sound.Play("slcttgt1.aud");
}
void DrawChat()
{
var chatpos = new int2(400, Game.viewport.Height - 20);

View File

@@ -25,6 +25,7 @@ namespace OpenRa.Game
public static Cursor DeployBlocked { get { return new Cursor("deploy-blocked"); } }
public static Cursor Chronoshift { get { return new Cursor("chrono-target"); } }
public static Cursor ChronoshiftSelect { get { return new Cursor("chrono-select"); } }
public static Cursor Ability { get { return new Cursor("ability"); } }
public static Cursor C4 { get { return new Cursor("c4"); } }
public static Cursor Capture { get { return new Cursor("capture"); } }
public static Cursor Heal { get { return new Cursor("heal"); } }

View File

@@ -0,0 +1,30 @@
using System.Collections.Generic;
using OpenRa.Game.Graphics;
using OpenRa.Game.Traits;
namespace OpenRa.Game.Effects
{
class InvulnEffect : IEffect
{
Actor a;
IronCurtainable b;
public InvulnEffect(Actor a)
{
this.a = a;
this.b = a.traits.Get<IronCurtainable>();
}
public void Tick()
{
if (a.IsDead || b.GetDamageModifier() > 0)
Game.world.AddFrameEndTask(w => w.Remove(this));
}
public IEnumerable<Renderable> Render()
{
foreach (var r in a.Render())
yield return r.WithPalette(PaletteType.Invuln);
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Collections.Generic;
using OpenRa.Game.Graphics;
using OpenRa.Game.Traits;
namespace OpenRa.Game.Effects
{
class PowerDownIndicator : IEffect
{
Actor a;
Building b;
Animation anim = new Animation("powerdown");
public PowerDownIndicator(Actor a)
{
this.a = a;
this.b = a.traits.Get<Building>();
anim.PlayRepeating("disabled");
}
public void Tick()
{
if (!b.Disabled || a.IsDead)
Game.world.AddFrameEndTask(w => w.Remove(this));
}
public IEnumerable<Renderable> Render()
{
foreach (var r in a.Render())
yield return r.WithPalette(PaletteType.Disabled);
if (b.ManuallyDisabled)
yield return new Renderable(anim.Image,
a.CenterLocation - .5f * anim.Image.size, PaletteType.Chrome);
}
}
}

View File

@@ -5,8 +5,8 @@ namespace OpenRa.Game.Graphics
{
public enum PaletteType
{
Gold, Blue, Red, Orange, Teal, Salmon, Green, Gray,
Shadow, Invuln, Chrome, Shroud, Highlight,
Gold, Blue, Red, Orange, Teal, Salmon, Green, Gray,
Shadow, Invuln, Disabled, Highlight, Shroud, Chrome,
};
class HardwarePalette : Sheet
@@ -23,11 +23,12 @@ namespace OpenRa.Game.Graphics
foreach (string remap in new string[] { "blue", "red", "orange", "teal", "salmon", "green", "gray" })
AddPalette(new Palette(pal, new PlayerColorRemap(FileSystem.Open(remap + ".rem"))));
AddPalette(new Palette(pal, new SingleColorRemap(Color.FromArgb(140, 0, 0, 0))));
AddPalette(pal); // iron curtain. todo: remap!
AddPalette(pal); // chrome (it's like gold, but we're not going to hax it in palettemods)
AddPalette(new Palette(pal, new ShroudPaletteRemap()));
AddPalette(new Palette(pal, new SingleColorRemap(Color.FromArgb(128, 255, 255, 255))));
AddPalette(new Palette(pal, new SingleColorRemap(Color.FromArgb(140, 0, 0, 0)))); // Shadow
AddPalette(new Palette(pal, new SingleColorRemap(Color.FromArgb(128, 128, 0, 0)))); // Invulnerable (Iron Curtain)
AddPalette(new Palette(pal, new SingleColorRemap(Color.FromArgb(180, 0, 0, 0)))); // Disabled / Low power
AddPalette(new Palette(pal, new SingleColorRemap(Color.FromArgb(128, 255, 255, 255)))); // Highlight
AddPalette(new Palette(pal, new ShroudPaletteRemap())); // Shroud
AddPalette(pal); // Chrome (it's like gold, but we're not going to hax it in palettemods)
}
int AddPalette(Palette p)

View File

@@ -242,6 +242,9 @@ namespace OpenRa.Game.Graphics
{
foreach (var tag in tags.GetTags())
{
if (tag == TagType.None)
continue;
var tagImages = new Animation("pips");
tagImages.PlayRepeating(tagStrings[(int)tag]);
spriteRenderer.DrawSprite(tagImages.Image, tagxyBase + tagxyOffset, PaletteType.Chrome);

View File

@@ -83,7 +83,9 @@
<Compile Include="Effects\Corpse.cs" />
<Compile Include="Effects\DelayedAction.cs" />
<Compile Include="Effects\FlashTarget.cs" />
<Compile Include="Effects\InvulnEffect.cs" />
<Compile Include="Effects\MoveFlash.cs" />
<Compile Include="Effects\PowerDownIndicator.cs" />
<Compile Include="Effects\RepairIndicator.cs" />
<Compile Include="Effects\Smoke.cs" />
<Compile Include="Effects\TeslaZap.cs" />
@@ -100,6 +102,7 @@
<Compile Include="Orders\ChronoshiftSelfDestinationOrderGenerator.cs" />
<Compile Include="Orders\ChronosphereSelectOrderGenerator.cs" />
<Compile Include="Orders\IOrderSource.cs" />
<Compile Include="Orders\IronCurtainOrderGenerator.cs" />
<Compile Include="Orders\LocalOrderSource.cs" />
<Compile Include="Effects\Missile.cs" />
<Compile Include="Orders\NetworkOrderSource.cs" />
@@ -217,6 +220,8 @@
<Compile Include="Traits\Helicopter.cs" />
<Compile Include="Traits\InvisibleToOthers.cs" />
<Compile Include="Traits\ConstructionYard.cs" />
<Compile Include="Traits\IronCurtain.cs" />
<Compile Include="Traits\IronCurtainable.cs" />
<Compile Include="Traits\MineImmune.cs" />
<Compile Include="Traits\Minelayer.cs" />
<Compile Include="Traits\LimitedAmmo.cs" />

View File

@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Game.GameRules;
using OpenRa.Game.Traits;
namespace OpenRa.Game.Orders
{
class IronCurtainOrderGenerator : IOrderGenerator
{
public IEnumerable<Order> Order(int2 xy, MouseInput mi)
{
if (mi.Button == MouseButton.Right)
Game.controller.CancelInputMode();
return OrderInner(xy, mi);
}
IEnumerable<Order> OrderInner(int2 xy, MouseInput mi)
{
if (mi.Button == MouseButton.Left)
{
var loc = mi.Location + Game.viewport.Location;
var underCursor = Game.FindUnits(loc, loc)
.Where(a => a.Owner == Game.LocalPlayer
&& a.traits.Contains<IronCurtainable>()
&& a.Info.Selectable).FirstOrDefault();
var unit = underCursor != null ? underCursor.Info as UnitInfo : null;
if (unit != null)
{
yield return new Order("IronCurtain", underCursor, null, int2.Zero, null);
}
}
}
public void Tick()
{
var hasStructure = Game.world.Actors
.Any(a => a.Owner == Game.LocalPlayer && a.traits.Contains<IronCurtain>());
if (!hasStructure)
Game.controller.CancelInputMode();
}
public void Render() { }
public Cursor GetCursor(int2 xy, MouseInput mi)
{
mi.Button = MouseButton.Left;
return OrderInner(xy, mi).Any()
? Cursor.Ability : Cursor.MoveBlocked;
}
}
}

View File

@@ -26,7 +26,7 @@ namespace OpenRa.Game.Traits
protected override void QueueAttack( Actor self, Order order )
{
if (self.traits.Contains<Building>() && self.traits.Get<Building>().InsuffientPower())
if (self.traits.Contains<Building>() && self.traits.Get<Building>().Disabled)
return;
const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */

View File

@@ -9,13 +9,16 @@ using OpenRa.Game.Graphics;
namespace OpenRa.Game.Traits
{
class Building : INotifyDamage, IOrder, ITick, IRenderModifier
class Building : INotifyDamage, IOrder, ITick
{
readonly Actor self;
public readonly BuildingInfo unitInfo;
bool isRepairing = false;
bool isPoweredDown = false;
bool manuallyDisabled = false;
public bool ManuallyDisabled { get { return manuallyDisabled; } }
public bool Disabled { get { return (manuallyDisabled || (unitInfo.Powered && self.Owner.GetPowerState() != PowerState.Normal)); } }
bool wasDisabled = false;
public Building(Actor self)
{
this.self = self;
@@ -24,14 +27,9 @@ namespace OpenRa.Game.Traits
* ((float2)self.Location + .5f * (float2)unitInfo.Dimensions);
}
public bool InsuffientPower()
{
return (isPoweredDown || (unitInfo.Powered && self.Owner.GetPowerState() != PowerState.Normal));
}
public int GetPowerUsage()
{
if (isPoweredDown)
if (manuallyDisabled)
return 0;
if (unitInfo.Power > 0) /* todo: is this how real-ra scales it? */
@@ -40,32 +38,6 @@ namespace OpenRa.Game.Traits
return unitInfo.Power;
}
public Animation iconAnim;
public IEnumerable<Renderable>
ModifyRender(Actor self, IEnumerable<Renderable> rs)
{
if (!InsuffientPower())
return rs;
List<Renderable> nrs = new List<Renderable>(rs);
foreach(var r in rs)
{
// Need 2 shadows to make it dark enough
nrs.Add(r.WithPalette(PaletteType.Shadow));
nrs.Add(r.WithPalette(PaletteType.Shadow));
}
if (isPoweredDown)
{
iconAnim = new Animation("powerdown");
iconAnim.PlayRepeating("disabled");
nrs.Add(new Renderable(iconAnim.Image, self.CenterLocation - 0.5f*iconAnim.Image.size, PaletteType.Chrome));
}
return nrs;
}
public void Damaged(Actor self, AttackInfo e)
{
if (e.DamageState == DamageState.Dead)
@@ -92,8 +64,8 @@ namespace OpenRa.Game.Traits
if (order.OrderString == "PowerDown")
{
isPoweredDown = !isPoweredDown;
Sound.Play((isPoweredDown) ? "bleep12.aud" : "bleep11.aud");
manuallyDisabled = !manuallyDisabled;
Sound.Play((manuallyDisabled) ? "bleep12.aud" : "bleep11.aud");
}
}
@@ -101,6 +73,11 @@ namespace OpenRa.Game.Traits
public void Tick(Actor self)
{
// If the disabled state has changed since the last frame
if (Disabled ^ wasDisabled
&& (wasDisabled = Disabled)) // Yes, I mean assignment
Game.world.AddFrameEndTask(w => w.Add(new PowerDownIndicator(self)));
if (!isRepairing) return;
if (remainingTicks == 0)

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Game.Traits
{
class IronCurtain
{
public IronCurtain(Actor self) {}
}
}

View File

@@ -0,0 +1,47 @@
using OpenRa.Game.Traits;
using OpenRa.Game.Orders;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using OpenRa.Game.Effects;
using OpenRa.Game.Graphics;
namespace OpenRa.Game.Traits
{
class IronCurtainable: IOrder, IDamageModifier, ITick
{
int RemainingTicks = 0;
public IronCurtainable(Actor self) { }
public void Tick(Actor self)
{
if (RemainingTicks > 0)
RemainingTicks--;
}
public float GetDamageModifier()
{
return (RemainingTicks > 0) ? 0.0f : 1.0f;
}
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
{
return null; // Chronoshift order is issued through Chrome.
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "IronCurtain")
{
Game.controller.CancelInputMode();
Game.world.AddFrameEndTask(w => w.Add(new InvulnEffect(self)));
RemainingTicks = (int)(Rules.General.IronCurtain * 60 * 25);
Sound.Play("ironcur9.aud");
// Play active anim
var ironCurtain = Game.world.Actors.Where(a => a.Owner == order.Subject.Owner && a.traits.Contains<IronCurtain>()).FirstOrDefault();
if (ironCurtain != null)
ironCurtain.traits.Get<RenderBuilding>().PlayCustomAnim(ironCurtain, "active");
}
}
}
}

View File

@@ -4,8 +4,11 @@ using System.Collections.Generic;
namespace OpenRa.Game.Traits
{
class Production : IProducer, ITags
class Production : IOrder, IProducer, ITags
{
bool isPrimary = false;
public bool IsPrimary { get { return isPrimary; } }
public Production( Actor self ) { }
public virtual int2? CreationLocation( Actor self, UnitInfo producee )
@@ -50,7 +53,45 @@ namespace OpenRa.Game.Traits
public IEnumerable<TagType> GetTags()
{
yield return (true) ? TagType.Primary : TagType.None;
yield return (isPrimary) ? TagType.Primary : TagType.None;
}
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
{
if (mi.Button == MouseButton.Right && underCursor == self)
return new Order("Deploy", self, null, int2.Zero, null);
return null;
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "Deploy")
{
SetPrimaryProducer(self, !isPrimary);
}
}
public void SetPrimaryProducer(Actor self, bool state)
{
if (state == false)
{
isPrimary = false;
return;
}
// Cancel existing primaries
foreach (var p in (self.Info as BuildingInfo).Produces)
{
foreach (var b in Game.world.Actors.Where(x => x.traits.Contains<Production>()
&& x.Owner == self.Owner
&& x.traits.Get<Production>().IsPrimary == true
&& (x.Info as BuildingInfo).Produces.Contains(p)))
{
b.traits.Get<Production>().SetPrimaryProducer(b, false);
}
}
isPrimary = true;
Sound.Play("pribldg1.aud");
}
}
}

View File

@@ -128,12 +128,36 @@ namespace OpenRa.Game.Traits
{
var newUnitType = Rules.UnitInfo[ name ];
var producerTypes = Rules.TechTree.UnitBuiltAt( newUnitType );
// TODO: choose producer based on "primary building"
var producer = Game.world.Actors
.Where( x => producerTypes.Contains( x.Info ) && x.Owner == self.Owner )
.FirstOrDefault();
Actor producer = null;
// Prioritise primary structure in build order
var primaryProducers = Game.world.Actors
.Where(x => x.traits.Contains<Production>()
&& producerTypes.Contains(x.Info)
&& x.Owner == self.Owner
&& x.traits.Get<Production>().IsPrimary == true);
foreach (var p in primaryProducers)
{
// Ignore buildings that are disabled
if (p.traits.Contains<Building>() && p.traits.Get<Building>().Disabled)
continue;
producer = p;
break;
}
// TODO: Be smart about disabled buildings. Units in progress should be paused(?)
// Ignore this for now
// Pick the first available producer
if (producer == null)
{
producer = Game.world.Actors
.Where( x => producerTypes.Contains( x.Info ) && x.Owner == self.Owner )
.FirstOrDefault();
}
// Something went wrong somewhere...
if( producer == null )
{
CancelProduction( Rules.UnitCategory[ name ] );

View File

@@ -19,7 +19,7 @@ namespace OpenRa.Game.Traits
// Check if powered
var b = self.traits.Get<Building>();
if (b != null && b.InsuffientPower())
if (b != null && b.Disabled)
return false;
return true;

View File

@@ -22,7 +22,11 @@ namespace OpenRa.Game.Traits
Order IssueOrder( Actor self, int2 xy, MouseInput mi, Actor underCursor );
void ResolveOrder( Actor self, Order order );
}
interface IProducer { bool Produce( Actor self, UnitInfo producee ); }
interface IProducer
{
bool Produce( Actor self, UnitInfo producee );
void SetPrimaryProducer(Actor self, bool isPrimary);
}
interface IOccupySpace { IEnumerable<int2> OccupiedCells(); }
interface INotifyAttack { void Attacking(Actor self); }
interface IRenderModifier { IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r); }