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
16 changed files
with
169 additions
and
76 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
77 changes: 77 additions & 0 deletions
77
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,77 @@ | ||
#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.Collections.Generic; | ||
|
||
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) | ||
{ | ||
if (!allProductionPaused) | ||
{ | ||
for (var i = 0; i < Queue.Count;) | ||
{ | ||
var first = Queue[0]; | ||
|
||
var before = first.RemainingTime; | ||
|
||
if (!first.Paused) | ||
first.Tick(playerResources); | ||
|
||
foreach (var item in Queue.FindAll(a => a.Item == first.Item)) | ||
{ | ||
i++; | ||
Queue.Remove(item); | ||
Queue.Add(item); | ||
} | ||
|
||
if (first.RemainingTime != before) | ||
return; | ||
} | ||
} | ||
} | ||
|
||
public override bool IsProducing(ProductionItem item) | ||
{ | ||
return Queue.Contains(item); | ||
} | ||
|
||
public override int RemainingTimeActual(ProductionItem item) | ||
{ | ||
var parallelBuilds = 0; | ||
var added = new List<string>(); | ||
|
||
foreach (var i in Queue) | ||
{ | ||
if (added.Contains(i.Item)) | ||
continue; | ||
|
||
added.Add(i.Item); | ||
|
||
if (!i.Paused && !i.Done) | ||
++parallelBuilds; | ||
} | ||
|
||
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.