Primary buildings

This commit is contained in:
Paul Chote
2010-01-07 23:23:05 +13:00
parent b18e7b2226
commit fc28d768f1
4 changed files with 81 additions and 9 deletions

View File

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

View File

@@ -4,8 +4,11 @@ using System.Collections.Generic;
namespace OpenRa.Game.Traits 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 Production( Actor self ) { }
public virtual int2? CreationLocation( Actor self, UnitInfo producee ) public virtual int2? CreationLocation( Actor self, UnitInfo producee )
@@ -50,7 +53,45 @@ namespace OpenRa.Game.Traits
public IEnumerable<TagType> GetTags() 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 newUnitType = Rules.UnitInfo[ name ];
var producerTypes = Rules.TechTree.UnitBuiltAt( newUnitType ); var producerTypes = Rules.TechTree.UnitBuiltAt( newUnitType );
Actor producer = null;
// TODO: choose producer based on "primary building" // Prioritise primary structure in build order
var producer = Game.world.Actors var primaryProducers = Game.world.Actors
.Where( x => producerTypes.Contains( x.Info ) && x.Owner == self.Owner ) .Where(x => x.traits.Contains<Production>()
.FirstOrDefault(); && 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 ) if( producer == null )
{ {
CancelProduction( Rules.UnitCategory[ name ] ); CancelProduction( Rules.UnitCategory[ name ] );

View File

@@ -22,7 +22,11 @@ namespace OpenRa.Game.Traits
Order IssueOrder( Actor self, int2 xy, MouseInput mi, Actor underCursor ); Order IssueOrder( Actor self, int2 xy, MouseInput mi, Actor underCursor );
void ResolveOrder( Actor self, Order order ); 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 IOccupySpace { IEnumerable<int2> OccupiedCells(); }
interface INotifyAttack { void Attacking(Actor self); } interface INotifyAttack { void Attacking(Actor self); }
interface IRenderModifier { IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r); } interface IRenderModifier { IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r); }