Primary buildings
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,12 +128,36 @@ namespace OpenRa.Game.Traits
|
||||
{
|
||||
var newUnitType = Rules.UnitInfo[ name ];
|
||||
var producerTypes = Rules.TechTree.UnitBuiltAt( newUnitType );
|
||||
Actor producer = null;
|
||||
|
||||
// TODO: choose producer based on "primary building"
|
||||
var producer = Game.world.Actors
|
||||
.Where( x => producerTypes.Contains( x.Info ) && x.Owner == self.Owner )
|
||||
.FirstOrDefault();
|
||||
// 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 ] );
|
||||
|
||||
@@ -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); }
|
||||
|
||||
Reference in New Issue
Block a user