Per-player unit production. Also, fixed an interesting bug in Sequence.
This commit is contained in:
@@ -101,31 +101,6 @@ namespace OpenRa.Game
|
|||||||
.FirstOrDefault(a => a != null) : null;
|
.FirstOrDefault(a => a != null) : null;
|
||||||
|
|
||||||
return c ?? (Game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any() ? Cursor.Select : Cursor.Default);
|
return c ?? (Game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any() ? Cursor.Select : Cursor.Default);
|
||||||
|
|
||||||
//foreach( var o in
|
|
||||||
//var uog = orderGenerator as UnitOrderGenerator;
|
|
||||||
|
|
||||||
//if (uog != null)
|
|
||||||
// uog.selection.RemoveAll(a => a.IsDead);
|
|
||||||
|
|
||||||
//if (uog != null && uog.selection.Count > 0
|
|
||||||
// && uog.selection.Any(a => a.traits.Contains<Traits.Mobile>())
|
|
||||||
// && uog.selection.All(a => a.Owner == Game.LocalPlayer))
|
|
||||||
//{
|
|
||||||
// var umts = uog.selection.Select(a => a.traits.GetOrDefault<Mobile>())
|
|
||||||
// .Where(m => m != null)
|
|
||||||
// .Select(m => m.GetMovementType())
|
|
||||||
// .Distinct();
|
|
||||||
|
|
||||||
// if (!umts.Any(umt => Game.IsCellBuildable(dragEnd.ToInt2(), umt)))
|
|
||||||
// return Cursor.MoveBlocked;
|
|
||||||
// return Cursor.Move;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//if (Game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any())
|
|
||||||
// return Cursor.Select;
|
|
||||||
|
|
||||||
//return Cursor.Default;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,6 +129,8 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
world.Update();
|
world.Update();
|
||||||
UnitInfluence.Tick();
|
UnitInfluence.Tick();
|
||||||
|
foreach( var player in players.Values )
|
||||||
|
player.Tick();
|
||||||
|
|
||||||
viewport.DrawRegions();
|
viewport.DrawRegions();
|
||||||
|
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ namespace OpenRa.Game.Graphics
|
|||||||
start = src.Start + int.Parse(e.GetAttribute("start"));
|
start = src.Start + int.Parse(e.GetAttribute("start"));
|
||||||
|
|
||||||
if (e.GetAttribute("length") == "*" || e.GetAttribute("end") == "*")
|
if (e.GetAttribute("length") == "*" || e.GetAttribute("end") == "*")
|
||||||
length = src.End - start;
|
length = src.End - start + 1;
|
||||||
else if (e.HasAttribute("length"))
|
else if (e.HasAttribute("length"))
|
||||||
length = int.Parse(e.GetAttribute("length"));
|
length = int.Parse(e.GetAttribute("length"));
|
||||||
else if (e.HasAttribute("end"))
|
else if (e.HasAttribute("end"))
|
||||||
length = int.Parse(e.GetAttribute("end")) - start;
|
length = int.Parse(e.GetAttribute("end")) - int.Parse(e.GetAttribute("start"));
|
||||||
else
|
else
|
||||||
length = 1;
|
length = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace OpenRa.Game
|
|||||||
var ret = new MemoryStream();
|
var ret = new MemoryStream();
|
||||||
var w = new BinaryWriter(ret);
|
var w = new BinaryWriter(ret);
|
||||||
w.Write((uint)Player.Palette | 0x80000000u);
|
w.Write((uint)Player.Palette | 0x80000000u);
|
||||||
w.Write((byte)0xFF); //
|
w.Write((byte)0xFF);
|
||||||
w.Write(OrderString);
|
w.Write(OrderString);
|
||||||
w.Write(Subject == null ? 0xFFFFFFFF : Subject.ActorID);
|
w.Write(Subject == null ? 0xFFFFFFFF : Subject.ActorID);
|
||||||
w.Write(TargetActor == null ? 0xFFFFFFFF : TargetActor.ActorID);
|
w.Write(TargetActor == null ? 0xFFFFFFFF : TargetActor.ActorID);
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
@@ -19,5 +21,87 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
return 0.5f; /* todo: work this out the same way as RA */
|
return 0.5f; /* todo: work this out the same way as RA */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void GiveCash( int num )
|
||||||
|
{
|
||||||
|
// TODO: increase cash
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TakeCash( int num )
|
||||||
|
{
|
||||||
|
// TODO: decrease cash.
|
||||||
|
// returns: if enough cash was available, true
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Tick()
|
||||||
|
{
|
||||||
|
foreach( var p in production )
|
||||||
|
{
|
||||||
|
if( p.Value != null )
|
||||||
|
p.Value.Tick( this );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Key: Production category. Categories are: building, infantry, vehicle, boat, 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.
|
||||||
|
production[ category ] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void BeginProduction( string group, ProductionItem item )
|
||||||
|
{
|
||||||
|
if( production[ group ] != null ) return;
|
||||||
|
production[ group ] = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ProductionItem
|
||||||
|
{
|
||||||
|
public readonly string Item;
|
||||||
|
|
||||||
|
public readonly int TotalTime;
|
||||||
|
public readonly int TotalCost;
|
||||||
|
public int RemainingTime { get; private set; }
|
||||||
|
public int RemainingCost { get; private set; }
|
||||||
|
|
||||||
|
public bool Paused = false, Done = false;
|
||||||
|
|
||||||
|
public ProductionItem( string item, int time, int cost )
|
||||||
|
{
|
||||||
|
Item = item;
|
||||||
|
RemainingTime = TotalTime = time;
|
||||||
|
RemainingCost = TotalCost = cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Tick( Player player )
|
||||||
|
{
|
||||||
|
if( Paused || Done ) return;
|
||||||
|
|
||||||
|
var costThisFrame = RemainingCost / RemainingTime;
|
||||||
|
if( costThisFrame == 0 && !player.TakeCash( costThisFrame ) ) return;
|
||||||
|
|
||||||
|
RemainingCost -= costThisFrame;
|
||||||
|
RemainingTime -= 1;
|
||||||
|
if( RemainingTime > 0 ) return;
|
||||||
|
|
||||||
|
// item finished; do whatever needs done.
|
||||||
|
Done = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
Dictionary<string, string> itemGroups = new Dictionary<string,string>(); //item->group
|
Dictionary<string, string> itemGroups = new Dictionary<string,string>(); //item->group
|
||||||
Dictionary<string, Animation> clockAnimations = new Dictionary<string,Animation>(); //group->clockAnimation
|
Dictionary<string, Animation> clockAnimations = new Dictionary<string,Animation>(); //group->clockAnimation
|
||||||
Dictionary<string, SidebarItem> selectedItems = new Dictionary<string,SidebarItem>(); //group->selectedItem
|
|
||||||
|
|
||||||
List<SidebarItem> items = new List<SidebarItem>();
|
List<SidebarItem> items = new List<SidebarItem>();
|
||||||
|
|
||||||
@@ -48,16 +47,27 @@ namespace OpenRa.Game
|
|||||||
LoadSprites( "ShipTypes", "boat" );
|
LoadSprites( "ShipTypes", "boat" );
|
||||||
LoadSprites( "PlaneTypes", "plane" );
|
LoadSprites( "PlaneTypes", "plane" );
|
||||||
|
|
||||||
foreach (string s in groups)
|
foreach (string group in groups)
|
||||||
{
|
{
|
||||||
clockAnimations.Add(s, new Animation("clock"));
|
Game.LocalPlayer.ProductionInit( group );
|
||||||
clockAnimations[s].PlayRepeating("idle");
|
clockAnimations.Add( group, new Animation( "clock" ) );
|
||||||
selectedItems.Add(s, null);
|
clockAnimations[ group ].PlayFetchIndex( "idle", ClockAnimFrame( group ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
blank = SheetBuilder.Add(new Size((int)spriteWidth, (int)spriteHeight), 16);
|
blank = SheetBuilder.Add(new Size((int)spriteWidth, (int)spriteHeight), 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int NumClockFrames = 54;
|
||||||
|
Func<int> ClockAnimFrame( string group )
|
||||||
|
{
|
||||||
|
return () =>
|
||||||
|
{
|
||||||
|
var producing = Game.LocalPlayer.Producing( group );
|
||||||
|
if( producing == null ) return 0;
|
||||||
|
return ( producing.TotalTime - producing.RemainingTime ) * NumClockFrames / producing.TotalTime;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public void Build(SidebarItem item)
|
public void Build(SidebarItem item)
|
||||||
{
|
{
|
||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
@@ -115,28 +125,27 @@ namespace OpenRa.Game
|
|||||||
unitPos += spriteHeight;
|
unitPos += spriteHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (string g in groups) selectedItems[g] = null;
|
foreach( string g in groups ) Game.LocalPlayer.CancelProduction( g );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Paint()
|
void Paint()
|
||||||
{
|
{
|
||||||
foreach (SidebarItem i in items)
|
foreach( SidebarItem i in items )
|
||||||
i.Paint(spriteRenderer, region.Location);
|
{
|
||||||
|
var group = itemGroups[ i.techTreeItem.tag ];
|
||||||
|
var producing = Game.LocalPlayer.Producing( group );
|
||||||
|
if( producing != null && producing.Item == i.techTreeItem.tag )
|
||||||
|
{
|
||||||
|
clockAnimations[ group ].Tick();
|
||||||
|
clockRenderer.DrawSprite( clockAnimations[ group ].Image, region.Location.ToFloat2() + i.location, 0 );
|
||||||
|
}
|
||||||
|
i.Paint( spriteRenderer, region.Location );
|
||||||
|
}
|
||||||
|
|
||||||
Fill(region.Size.Y + region.Location.Y, new float2(region.Location.X, buildPos + region.Location.Y));
|
Fill(region.Size.Y + region.Location.Y, new float2(region.Location.X, buildPos + region.Location.Y));
|
||||||
Fill(region.Size.Y + region.Location.Y, new float2(region.Location.X + spriteWidth, unitPos + region.Location.Y));
|
Fill(region.Size.Y + region.Location.Y, new float2(region.Location.X + spriteWidth, unitPos + region.Location.Y));
|
||||||
|
|
||||||
spriteRenderer.Flush();
|
spriteRenderer.Flush();
|
||||||
|
|
||||||
foreach (var kvp in selectedItems)
|
|
||||||
{
|
|
||||||
if (kvp.Value != null)
|
|
||||||
{
|
|
||||||
clockRenderer.DrawSprite(clockAnimations[kvp.Key].Image, region.Location.ToFloat2() + kvp.Value.location, 0);
|
|
||||||
clockAnimations[kvp.Key].Tick(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
clockRenderer.Flush();
|
clockRenderer.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,9 +167,9 @@ namespace OpenRa.Game
|
|||||||
if (item != null)
|
if (item != null)
|
||||||
{
|
{
|
||||||
string group = itemGroups[item.techTreeItem.tag];
|
string group = itemGroups[item.techTreeItem.tag];
|
||||||
if (selectedItems[group] == null)
|
if (Game.LocalPlayer.Producing(group) == null)
|
||||||
{
|
{
|
||||||
selectedItems[group] = item;
|
Game.LocalPlayer.BeginProduction( group, new ProductionItem( item.techTreeItem.tag, 25, 0 ) );
|
||||||
Build(item);
|
Build(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,7 +181,7 @@ namespace OpenRa.Game
|
|||||||
if( item != null )
|
if( item != null )
|
||||||
{
|
{
|
||||||
string group = itemGroups[ item.techTreeItem.tag ];
|
string group = itemGroups[ item.techTreeItem.tag ];
|
||||||
selectedItems[ group ] = null;
|
Game.LocalPlayer.CancelProduction( group );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user