working on letting _any_ actor be a production-queue. (chrome still needs work)
This commit is contained in:
@@ -53,6 +53,7 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
public void AddLine(Color c, string from, string text)
|
public void AddLine(Color c, string from, string text)
|
||||||
{
|
{
|
||||||
|
Log.Write( "Chat: {0}: {1}", from, text );
|
||||||
recentLines.Add(Tuple.New(c, from, text));
|
recentLines.Add(Tuple.New(c, from, text));
|
||||||
Sound.Play("rabeep1.aud");
|
Sound.Play("rabeep1.aud");
|
||||||
while (recentLines.Count > logLength) recentLines.RemoveAt(0);
|
while (recentLines.Count > logLength) recentLines.RemoveAt(0);
|
||||||
|
|||||||
@@ -108,6 +108,8 @@ namespace OpenRa.Game
|
|||||||
if (currentTab == null || !Rules.TechTree.BuildableItems(Game.LocalPlayer, currentTab).Any())
|
if (currentTab == null || !Rules.TechTree.BuildableItems(Game.LocalPlayer, currentTab).Any())
|
||||||
ChooseAvailableTab();
|
ChooseAvailableTab();
|
||||||
|
|
||||||
|
var queue = Game.LocalPlayer.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
||||||
|
|
||||||
foreach (var q in tabSprites)
|
foreach (var q in tabSprites)
|
||||||
{
|
{
|
||||||
var groupName = q.Key;
|
var groupName = q.Key;
|
||||||
@@ -117,7 +119,7 @@ namespace OpenRa.Game
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var producing = Game.LocalPlayer.Producing(groupName);
|
var producing = queue.Producing(groupName);
|
||||||
var index = q.Key == currentTab ? 2 : (producing != null && producing.Done) ? 1 : 0;
|
var index = q.Key == currentTab ? 2 : (producing != null && producing.Done) ? 1 : 0;
|
||||||
chromeRenderer.DrawSprite(q.Value[index], new float2(x, y), 0);
|
chromeRenderer.DrawSprite(q.Value[index], new float2(x, y), 0);
|
||||||
|
|
||||||
@@ -134,7 +136,8 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
void CheckDeadTab( string groupName )
|
void CheckDeadTab( string groupName )
|
||||||
{
|
{
|
||||||
var item = Game.LocalPlayer.Producing(groupName);
|
var queue = Game.LocalPlayer.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
||||||
|
var item = queue.Producing( groupName );
|
||||||
if (item != null)
|
if (item != null)
|
||||||
Game.controller.AddOrder(Order.CancelProduction(Game.LocalPlayer, item.Item));
|
Game.controller.AddOrder(Order.CancelProduction(Game.LocalPlayer, item.Item));
|
||||||
}
|
}
|
||||||
@@ -186,7 +189,8 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
return () =>
|
return () =>
|
||||||
{
|
{
|
||||||
var producing = Game.LocalPlayer.Producing(group);
|
var queue = Game.LocalPlayer.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
||||||
|
var producing = queue.Producing( group );
|
||||||
if (producing == null) return 0;
|
if (producing == null) return 0;
|
||||||
return (producing.TotalTime - producing.RemainingTime) * NumClockFrames / producing.TotalTime;
|
return (producing.TotalTime - producing.RemainingTime) * NumClockFrames / producing.TotalTime;
|
||||||
};
|
};
|
||||||
@@ -195,7 +199,7 @@ namespace OpenRa.Game
|
|||||||
void DrawBuildPalette(string queueName)
|
void DrawBuildPalette(string queueName)
|
||||||
{
|
{
|
||||||
if (queueName == null) return;
|
if (queueName == null) return;
|
||||||
var buildItem = Game.LocalPlayer.Producing(queueName);
|
|
||||||
var x = 0;
|
var x = 0;
|
||||||
var y = 0;
|
var y = 0;
|
||||||
|
|
||||||
@@ -205,7 +209,8 @@ namespace OpenRa.Game
|
|||||||
.Where(a => Rules.UnitInfo[a].TechLevel != -1)
|
.Where(a => Rules.UnitInfo[a].TechLevel != -1)
|
||||||
.OrderBy(a => Rules.UnitInfo[a].TechLevel);
|
.OrderBy(a => Rules.UnitInfo[a].TechLevel);
|
||||||
|
|
||||||
var currentItem = Game.LocalPlayer.Producing(queueName);
|
var queue = Game.LocalPlayer.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
||||||
|
var currentItem = queue.Producing( queueName );
|
||||||
|
|
||||||
var overlayBits = new List<Pair<Sprite, float2>>();
|
var overlayBits = new List<Pair<Sprite, float2>>();
|
||||||
|
|
||||||
@@ -272,7 +277,8 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
var player = Game.LocalPlayer;
|
var player = Game.LocalPlayer;
|
||||||
var group = Rules.UnitCategory[item];
|
var group = Rules.UnitCategory[item];
|
||||||
var producing = player.Producing(group);
|
var queue = player.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
||||||
|
var producing = queue.Producing( group );
|
||||||
|
|
||||||
Sound.Play("ramenu1.aud");
|
Sound.Play("ramenu1.aud");
|
||||||
|
|
||||||
|
|||||||
@@ -278,24 +278,5 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
return Game.PathFinder.FindPath(search).Count != 0;
|
return Game.PathFinder.FindPath(search).Count != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void BuildUnit(Player player, string name)
|
|
||||||
{
|
|
||||||
var newUnitType = Rules.UnitInfo[ name ];
|
|
||||||
var producerTypes = Rules.TechTree.UnitBuiltAt( newUnitType );
|
|
||||||
// TODO: choose producer based on "primary building"
|
|
||||||
var producer = world.Actors
|
|
||||||
.Where( x => producerTypes.Contains( x.Info ) && x.Owner == player )
|
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
if (producer == null)
|
|
||||||
{
|
|
||||||
player.CancelProduction(Rules.UnitCategory[name]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( producer.traits.WithInterface<IProducer>().Any( p => p.Produce( producer, newUnitType ) ) )
|
|
||||||
player.FinishProduction(Rules.UnitCategory[name]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
public void Tick()
|
public void Tick()
|
||||||
{
|
{
|
||||||
var producing = Owner.Producing( Rules.UnitCategory[ Building.Name ] );
|
var producing = Owner.PlayerActor.traits.Get<Traits.ProductionQueue>().Producing( Rules.UnitCategory[ Building.Name ] );
|
||||||
if( producing == null || producing.Item != Building.Name || producing.RemainingTime != 0 )
|
if( producing == null || producing.Item != Building.Name || producing.RemainingTime != 0 )
|
||||||
Game.world.AddFrameEndTask( _ => { Game.controller.orderGenerator = null; } );
|
Game.world.AddFrameEndTask( _ => { Game.controller.orderGenerator = null; } );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,9 +35,6 @@ namespace OpenRa.Game
|
|||||||
this.Ore = 0;
|
this.Ore = 0;
|
||||||
this.DisplayCash = 0;
|
this.DisplayCash = 0;
|
||||||
this.powerProvided = this.powerDrained = 0;
|
this.powerProvided = this.powerDrained = 0;
|
||||||
|
|
||||||
foreach( var cat in Rules.Categories.Keys )
|
|
||||||
ProductionInit( cat );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdatePower()
|
void UpdatePower()
|
||||||
@@ -127,10 +124,6 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
UpdatePower();
|
UpdatePower();
|
||||||
|
|
||||||
foreach( var p in production )
|
|
||||||
if( p.Value != null )
|
|
||||||
p.Value.Tick( this );
|
|
||||||
|
|
||||||
if (this == Game.LocalPlayer)
|
if (this == Game.LocalPlayer)
|
||||||
{
|
{
|
||||||
var totalMoney = Cash + Ore;
|
var totalMoney = Cash + Ore;
|
||||||
@@ -149,37 +142,5 @@ namespace OpenRa.Game
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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>();
|
|
||||||
|
|
||||||
public 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;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,22 @@ using System.Text;
|
|||||||
|
|
||||||
namespace OpenRa.Game.Traits
|
namespace OpenRa.Game.Traits
|
||||||
{
|
{
|
||||||
class ProductionQueue : IOrder
|
class ProductionQueue : IOrder, ITick
|
||||||
{
|
{
|
||||||
|
Actor self;
|
||||||
|
|
||||||
public ProductionQueue( 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 )
|
public Order IssueOrder( Actor self, int2 xy, bool lmb, Actor underCursor )
|
||||||
@@ -38,7 +49,7 @@ namespace OpenRa.Game.Traits
|
|||||||
|
|
||||||
bool hasPlayedSound = false;
|
bool hasPlayedSound = false;
|
||||||
|
|
||||||
order.Player.BeginProduction( group,
|
BeginProduction( group,
|
||||||
new ProductionItem( order.TargetString, (int)time, ui.Cost,
|
new ProductionItem( order.TargetString, (int)time, ui.Cost,
|
||||||
() => Game.world.AddFrameEndTask(
|
() => Game.world.AddFrameEndTask(
|
||||||
_ =>
|
_ =>
|
||||||
@@ -50,25 +61,77 @@ namespace OpenRa.Game.Traits
|
|||||||
hasPlayedSound = true;
|
hasPlayedSound = true;
|
||||||
}
|
}
|
||||||
if( !isBuilding )
|
if( !isBuilding )
|
||||||
Game.BuildUnit( order.Player, order.TargetString );
|
BuildUnit( order.TargetString );
|
||||||
} ) ) );
|
} ) ) );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "PauseProduction":
|
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 )
|
if( producing != null && producing.Item == order.TargetString )
|
||||||
producing.Paused = ( order.TargetLocation.X != 0 );
|
producing.Paused = ( order.TargetLocation.X != 0 );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "CancelProduction":
|
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 )
|
if( producing != null && producing.Item == order.TargetString )
|
||||||
order.Player.CancelProduction( Rules.UnitCategory[ order.TargetString ] );
|
CancelProduction( Rules.UnitCategory[ order.TargetString ] );
|
||||||
break;
|
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 ] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,9 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
Game.world.AddFrameEndTask( _ =>
|
Game.world.AddFrameEndTask( _ =>
|
||||||
{
|
{
|
||||||
|
var queue = order.Player.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
||||||
var building = (BuildingInfo)Rules.UnitInfo[ order.TargetString ];
|
var building = (BuildingInfo)Rules.UnitInfo[ order.TargetString ];
|
||||||
var producing = order.Player.Producing(Rules.UnitCategory[order.TargetString]);
|
var producing = queue.Producing(Rules.UnitCategory[order.TargetString]);
|
||||||
if( producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0 )
|
if( producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ namespace OpenRa.Game
|
|||||||
Sound.Play("build5.aud");
|
Sound.Play("build5.aud");
|
||||||
}
|
}
|
||||||
|
|
||||||
order.Player.FinishProduction(Rules.UnitCategory[building.Name]);
|
queue.FinishProduction(Rules.UnitCategory[building.Name]);
|
||||||
} );
|
} );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user