-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented ParallelProductionQueue.
- Loading branch information
Showing
15 changed files
with
161 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
OpenRA.Mods.Common/Traits/Player/ParallelProductionQueue.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#region Copyright & License Information | ||
/* | ||
* Copyright 2007-2018 The OpenRA Developers (see AUTHORS) | ||
* This file is part of OpenRA, which is free software. It is made | ||
* available to you under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. For more | ||
* information, see COPYING. | ||
*/ | ||
#endregion | ||
|
||
using System.Linq; | ||
|
||
namespace OpenRA.Mods.Common.Traits | ||
{ | ||
public class ParallelProductionQueueInfo : ProductionQueueInfo | ||
{ | ||
public override object Create(ActorInitializer init) { return new ParallelProductionQueue(init, init.Self.Owner.PlayerActor, this); } | ||
} | ||
|
||
public class ParallelProductionQueue : ProductionQueue | ||
{ | ||
public ParallelProductionQueue(ActorInitializer init, Actor playerActor, ParallelProductionQueueInfo info) | ||
: base(init, playerActor, info) { } | ||
|
||
protected override void TickInner(Actor self, bool allProductionPaused) | ||
{ | ||
CancelUnbuildableItems(); | ||
|
||
var item = Queue.FirstOrDefault(i => !i.Paused); | ||
if (item == null) | ||
return; | ||
|
||
var before = item.RemainingTime; | ||
|
||
if (!item.Paused) | ||
item.Tick(playerResources); | ||
|
||
if (item.RemainingTime == before) | ||
return; | ||
|
||
foreach (var other in Queue.FindAll(a => a.Item == item.Item)) | ||
{ | ||
Queue.Remove(other); | ||
Queue.Add(other); | ||
} | ||
} | ||
|
||
public override bool IsProducing(ProductionItem item) | ||
{ | ||
return Queue.Contains(item); | ||
} | ||
|
||
public override int RemainingTimeActual(ProductionItem item) | ||
{ | ||
var parallelBuilds = Queue.FindAll(i => !i.Paused && !i.Done) | ||
.GroupBy(i => i.Item) | ||
.ToList() | ||
.Count; | ||
return item.RemainingTimeActual * parallelBuilds; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.