Created
July 10, 2014 00:52
-
-
Save phrohdoh/f038c3353ee3f786c647 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#region Copyright & License Information | |
/* | |
* Copyright 2007-2014 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. For more information, | |
* see COPYING. | |
*/ | |
#endregion | |
using System; | |
using System.Linq; | |
using OpenRA.Traits; | |
namespace OpenRA.Mods.RA | |
{ | |
public class ClonesProducedUnitsInfo : ITraitInfo, Requires<ProductionInfo>, Requires<ExitInfo> | |
{ | |
[Desc("Uses Buildable.Queue to determine whether or not we should clone produced units.")] | |
public readonly string[] CloneableTypes = { }; | |
[Desc("How many clones do we produce for every original unit created?")] | |
public readonly int ClonesPerOriginal = 1; | |
public object Create(ActorInitializer init) { return new ClonesProducedUnits(init.self, this); } | |
} | |
public class ClonesProducedUnits : INotifyProduction | |
{ | |
ClonesProducedUnitsInfo info; | |
Production production; | |
public ClonesProducedUnits(Actor self, ClonesProducedUnitsInfo info) | |
{ | |
this.info = info; | |
production = self.Trait<Production>(); | |
} | |
public void UnitProduced(Actor self, Actor other, CPos exit) | |
{ | |
var queueType = other.Info.Traits.Get<BuildableInfo>().Queue; | |
if (!info.CloneableTypes.Contains(queueType) || !info.CloneableTypes.Contains(other.Info.Name)) | |
return; | |
// Do not notify production over and over (infinite loop) | |
for (var i = 0; i < info.ClonesPerOriginal; i++) | |
production.Produce(self, other.Info, self.Owner.Country.Race, false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment