Merge branch 'master' of git://github.com/chrisforbes/OpenRA

This commit is contained in:
Alli
2010-01-08 01:00:21 +13:00
12 changed files with 284 additions and 65 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 => Game.controller.ToggleInputMode<IronCurtainOrderGenerator>());
}
buildPaletteRenderer.DrawSprite(repairButton.Image, curtainDrawPos, PaletteType.Chrome);
// Repair

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

@@ -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

@@ -100,6 +100,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 +218,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

@@ -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,57 @@
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, IRenderModifier
{
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")
{
RemainingTicks = (int)(Rules.General.IronCurtain * 60 * 25);
// Play active anim
var ironCurtain = Game.world.Actors.Where(a => a.Owner == order.Subject.Owner && a.traits.Contains<IronCurtain>()).FirstOrDefault();
Sound.Play("ironcur9.aud");
if (ironCurtain != null)
ironCurtain.traits.Get<RenderBuilding>().PlayCustomAnim(ironCurtain, "active");
}
}
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> rs)
{
if (RemainingTicks <= 0)
return rs;
List<Renderable> nrs = new List<Renderable>(rs);
foreach(var r in rs)
{
nrs.Add(r.WithPalette(PaletteType.Shadow));
}
return nrs;
}
}
}

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>().InsuffientPower())
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

@@ -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); }