Fix ra queue visibility

This commit is contained in:
Paul Chote
2010-08-28 01:29:23 +12:00
parent b2f535d2e0
commit 9de22add08
2 changed files with 52 additions and 41 deletions

View File

@@ -50,7 +50,6 @@ namespace OpenRA.Traits
foreach (var a in Rules.TechTree.AllBuildables(Info.Type)) foreach (var a in Rules.TechTree.AllBuildables(Info.Type))
{ {
var bi = a.Traits.Get<BuildableInfo>(); var bi = a.Traits.Get<BuildableInfo>();
Console.WriteLine(a.Name);
// Can our race build this by satisfying normal prereqs? // Can our race build this by satisfying normal prereqs?
var buildable = bi.Owner.Contains(self.Owner.Country.Race); var buildable = bi.Owner.Contains(self.Owner.Country.Race);
Produceable.Add( a, new ProductionState(){ Visible = buildable && !bi.Hidden } ); Produceable.Add( a, new ProductionState(){ Visible = buildable && !bi.Hidden } );
@@ -89,8 +88,12 @@ namespace OpenRA.Traits
return Queue; return Queue;
} }
ActorInfo[] None = new ActorInfo[]{};
public IEnumerable<ActorInfo> AllItems() public IEnumerable<ActorInfo> AllItems()
{ {
if (!QueueActive)
return None;
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().AllTech) if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().AllTech)
return Produceable.Select(a => a.Key); return Produceable.Select(a => a.Key);
@@ -99,6 +102,9 @@ namespace OpenRA.Traits
public IEnumerable<ActorInfo> BuildableItems() public IEnumerable<ActorInfo> BuildableItems()
{ {
if (!QueueActive)
return None;
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().AllTech) if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().AllTech)
return Produceable.Select(a => a.Key); return Produceable.Select(a => a.Key);
@@ -111,11 +117,17 @@ namespace OpenRA.Traits
return Rules.TechTree.CanBuild(actor, self.Owner, buildings); return Rules.TechTree.CanBuild(actor, self.Owner, buildings);
} }
[Sync] bool QueueActive = true;
public void Tick( Actor self ) public void Tick( Actor self )
{ {
if (!initialized) if (!initialized)
Initialize(); Initialize();
if (self == self.Owner.PlayerActor)
QueueActive = self.World.Queries.OwnedBy[self.Owner].WithTrait<Production>()
.Where(x => x.Trait.Info.Produces.Contains(Info.Type))
.Any();
while( Queue.Count > 0 && !BuildableItems().Any(b => b.Name == Queue[ 0 ].Item) ) while( Queue.Count > 0 && !BuildableItems().Any(b => b.Name == Queue[ 0 ].Item) )
{ {
self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(Queue[0].TotalCost - Queue[0].RemainingCost); // refund what's been paid so far. self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(Queue[0].TotalCost - Queue[0].RemainingCost); // refund what's been paid so far.
@@ -227,36 +239,38 @@ namespace OpenRA.Traits
void BuildUnit( string name ) void BuildUnit( string name )
{ {
// If the actor has a production trait, use it. if (self == self.Owner.PlayerActor)
var sp = self.TraitsImplementing<Production>().Where(p => p.Info.Produces.Contains(Info.Type)).FirstOrDefault();
if (sp != null)
{ {
if (!IsDisabledBuilding(self) && sp.Produce(self, Rules.Info[ name ])) // original ra behavior; queue lives on PlayerActor, need to find a production structure
FinishProduction(); var producers = self.World.Queries.OwnedBy[self.Owner]
return;
}
var producers = self.World.Queries.OwnedBy[self.Owner]
.WithTrait<Production>() .WithTrait<Production>()
.Where(x => x.Trait.Info.Produces.Contains(Info.Type)) .Where(x => x.Trait.Info.Produces.Contains(Info.Type))
.OrderByDescending(x => x.Actor.IsPrimaryBuilding() ? 1 : 0 ) // prioritize the primary. .OrderByDescending(x => x.Actor.IsPrimaryBuilding() ? 1 : 0 ) // prioritize the primary.
.ToArray(); .ToArray();
if (producers.Length == 0) if (producers.Length == 0)
{
CancelProduction(name);
return;
}
foreach (var p in producers)
{
if (IsDisabledBuilding(p.Actor)) continue;
if (p.Trait.Produce(p.Actor, Rules.Info[ name ]))
{ {
FinishProduction(); CancelProduction(name);
break; return;
} }
foreach (var p in producers)
{
if (IsDisabledBuilding(p.Actor)) continue;
if (p.Trait.Produce(p.Actor, Rules.Info[ name ]))
{
FinishProduction();
break;
}
}
}
else
{
// queue lives on actor; is produced at same actor
var sp = self.TraitsImplementing<Production>().Where(p => p.Info.Produces.Contains(Info.Type)).FirstOrDefault();
if (sp != null && !IsDisabledBuilding(self) && sp.Produce(self, Rules.Info[ name ]))
FinishProduction();
} }
} }
} }

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Widgets
public int Rows = 5; public int Rows = 5;
ProductionQueue CurrentQueue = null; ProductionQueue CurrentQueue = null;
List<ProductionQueue> visibleTabs = new List<ProductionQueue>(); List<ProductionQueue> VisibleQueues = new List<ProductionQueue>();
bool paletteOpen = false; bool paletteOpen = false;
Dictionary<string, Sprite> iconSprites; Dictionary<string, Sprite> iconSprites;
@@ -75,20 +75,21 @@ namespace OpenRA.Mods.RA.Widgets
public override void Tick(World world) public override void Tick(World world)
{ {
visibleTabs.Clear(); VisibleQueues.Clear();
var queues = world.Queries.WithTraitMultiple<ProductionQueue>() var queues = world.Queries.WithTraitMultiple<ProductionQueue>()
.Where(p => p.Actor.Owner == world.LocalPlayer) .Where(p => p.Actor.Owner == world.LocalPlayer)
.Select(p => p.Trait); .Select(p => p.Trait);
foreach (var queue in queues) foreach (var queue in queues)
if (queue.BuildableItems().Count() > 0) {
visibleTabs.Add(queue); if (queue.AllItems().Count() > 0)
VisibleQueues.Add(queue);
else if (CurrentQueue == queue) else if (CurrentQueue == queue)
CurrentQueue = null; CurrentQueue = null;
}
if (CurrentQueue == null) if (CurrentQueue == null)
CurrentQueue = queues.FirstOrDefault(); CurrentQueue = VisibleQueues.FirstOrDefault();
TickPaletteAnimation(world); TickPaletteAnimation(world);
@@ -386,11 +387,7 @@ namespace OpenRA.Mods.RA.Widgets
tabs.Clear(); tabs.Clear();
var queues = world.Queries.WithTraitMultiple<ProductionQueue>() foreach (var queue in VisibleQueues)
.Where(p => p.Actor.Owner == world.LocalPlayer)
.Select(p => p.Trait);
foreach (var queue in queues)
{ {
string[] tabKeys = { "normal", "ready", "selected" }; string[] tabKeys = { "normal", "ready", "selected" };
var producing = queue.CurrentItem(); var producing = queue.CurrentItem();
@@ -500,23 +497,23 @@ namespace OpenRA.Mods.RA.Widgets
void TabChange(bool shift) void TabChange(bool shift)
{ {
int size = visibleTabs.Count(); int size = VisibleQueues.Count();
if (size > 0) if (size > 0)
{ {
int current = visibleTabs.IndexOf(CurrentQueue); int current = VisibleQueues.IndexOf(CurrentQueue);
if (!shift) if (!shift)
{ {
if (current + 1 >= size) if (current + 1 >= size)
SetCurrentTab(visibleTabs.FirstOrDefault()); SetCurrentTab(VisibleQueues.FirstOrDefault());
else else
SetCurrentTab(visibleTabs[current + 1]); SetCurrentTab(VisibleQueues[current + 1]);
} }
else else
{ {
if (current - 1 < 0) if (current - 1 < 0)
SetCurrentTab(visibleTabs.LastOrDefault()); SetCurrentTab(VisibleQueues.LastOrDefault());
else else
SetCurrentTab(visibleTabs[current - 1]); SetCurrentTab(VisibleQueues[current - 1]);
} }
} }
} }