working on letting _any_ actor be a production-queue. (chrome still needs work)
This commit is contained in:
@@ -5,11 +5,22 @@ using System.Text;
|
||||
|
||||
namespace OpenRa.Game.Traits
|
||||
{
|
||||
class ProductionQueue : IOrder
|
||||
class ProductionQueue : IOrder, ITick
|
||||
{
|
||||
Actor self;
|
||||
|
||||
public ProductionQueue( Actor self )
|
||||
{
|
||||
this.self = self;
|
||||
foreach( var cat in Rules.Categories.Keys )
|
||||
ProductionInit( cat );
|
||||
}
|
||||
|
||||
public void Tick( Actor self )
|
||||
{
|
||||
foreach( var p in production )
|
||||
if( p.Value != null )
|
||||
p.Value.Tick( self.Owner );
|
||||
}
|
||||
|
||||
public Order IssueOrder( Actor self, int2 xy, bool lmb, Actor underCursor )
|
||||
@@ -38,7 +49,7 @@ namespace OpenRa.Game.Traits
|
||||
|
||||
bool hasPlayedSound = false;
|
||||
|
||||
order.Player.BeginProduction( group,
|
||||
BeginProduction( group,
|
||||
new ProductionItem( order.TargetString, (int)time, ui.Cost,
|
||||
() => Game.world.AddFrameEndTask(
|
||||
_ =>
|
||||
@@ -50,25 +61,77 @@ namespace OpenRa.Game.Traits
|
||||
hasPlayedSound = true;
|
||||
}
|
||||
if( !isBuilding )
|
||||
Game.BuildUnit( order.Player, order.TargetString );
|
||||
BuildUnit( order.TargetString );
|
||||
} ) ) );
|
||||
break;
|
||||
}
|
||||
case "PauseProduction":
|
||||
{
|
||||
var producing = order.Player.Producing( Rules.UnitCategory[ order.TargetString ] );
|
||||
var producing = Producing( Rules.UnitCategory[ order.TargetString ] );
|
||||
if( producing != null && producing.Item == order.TargetString )
|
||||
producing.Paused = ( order.TargetLocation.X != 0 );
|
||||
break;
|
||||
}
|
||||
case "CancelProduction":
|
||||
{
|
||||
var producing = order.Player.Producing( Rules.UnitCategory[ order.TargetString ] );
|
||||
var producing = Producing( Rules.UnitCategory[ order.TargetString ] );
|
||||
if( producing != null && producing.Item == order.TargetString )
|
||||
order.Player.CancelProduction( Rules.UnitCategory[ order.TargetString ] );
|
||||
CancelProduction( Rules.UnitCategory[ order.TargetString ] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Key: Production category. Categories are: Building, Infantry, Vehicle, Ship, Plane (and one per super, if they're done in here)
|
||||
readonly Dictionary<string, ProductionItem> production = new Dictionary<string, ProductionItem>();
|
||||
|
||||
void ProductionInit( string category )
|
||||
{
|
||||
production.Add( category, null );
|
||||
}
|
||||
|
||||
public ProductionItem Producing( string category )
|
||||
{
|
||||
return production[ category ];
|
||||
}
|
||||
|
||||
public void CancelProduction( string category )
|
||||
{
|
||||
var item = production[ category ];
|
||||
if( item == null ) return;
|
||||
self.Owner.GiveCash( item.TotalCost - item.RemainingCost ); // refund what's been paid so far.
|
||||
FinishProduction( category );
|
||||
}
|
||||
|
||||
public void FinishProduction( string category )
|
||||
{
|
||||
production[ category ] = null;
|
||||
}
|
||||
|
||||
public void BeginProduction( string group, ProductionItem item )
|
||||
{
|
||||
if( production[ group ] != null ) return;
|
||||
production[ group ] = item;
|
||||
}
|
||||
|
||||
public void BuildUnit( string name )
|
||||
{
|
||||
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();
|
||||
|
||||
if( producer == null )
|
||||
{
|
||||
CancelProduction( Rules.UnitCategory[ name ] );
|
||||
return;
|
||||
}
|
||||
|
||||
if( producer.traits.WithInterface<IProducer>().Any( p => p.Produce( producer, newUnitType ) ) )
|
||||
FinishProduction( Rules.UnitCategory[ name ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user