ClonesProductionUnits:
string[] CloneableTypes checks Cloneable.Types Cloneable: string[] Types checked by ClonesProductionUnits.CloneableTypes Added INotifyOtherProduction for notifying self when another actor produces a unit.
This commit is contained in:
@@ -74,6 +74,7 @@ namespace OpenRA.Traits
|
|||||||
public interface INotifyBuildComplete { void BuildingComplete(Actor self); }
|
public interface INotifyBuildComplete { void BuildingComplete(Actor self); }
|
||||||
public interface INotifyBuildingPlaced { void BuildingPlaced(Actor self); }
|
public interface INotifyBuildingPlaced { void BuildingPlaced(Actor self); }
|
||||||
public interface INotifyProduction { void UnitProduced(Actor self, Actor other, CPos exit); }
|
public interface INotifyProduction { void UnitProduced(Actor self, Actor other, CPos exit); }
|
||||||
|
public interface INotifyOtherProduction { void UnitProducedByOther(Actor self, Actor producer, Actor produced); }
|
||||||
public interface INotifyDelivery { void IncomingDelivery(Actor self); void Delivered(Actor self); }
|
public interface INotifyDelivery { void IncomingDelivery(Actor self); void Delivered(Actor self); }
|
||||||
public interface INotifyOwnerChanged { void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner); }
|
public interface INotifyOwnerChanged { void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner); }
|
||||||
public interface INotifyEffectiveOwnerChanged { void OnEffectiveOwnerChanged(Actor self, Player oldEffectiveOwner, Player newEffectiveOwner); }
|
public interface INotifyEffectiveOwnerChanged { void OnEffectiveOwnerChanged(Actor self, Player oldEffectiveOwner, Player newEffectiveOwner); }
|
||||||
|
|||||||
50
OpenRA.Mods.RA/Buildings/ClonesProducedUnits.cs
Normal file
50
OpenRA.Mods.RA/Buildings/ClonesProducedUnits.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#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
|
||||||
|
{
|
||||||
|
[Desc("Creates a free duplicate of produced units.")]
|
||||||
|
public class ClonesProducedUnitsInfo : ITraitInfo, Requires<ProductionInfo>, Requires<ExitInfo>
|
||||||
|
{
|
||||||
|
[Desc("Uses the \"Cloneable\" trait to determine whether or not we should clone a produced unit.")]
|
||||||
|
public readonly string[] CloneableTypes = { };
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new ClonesProducedUnits(init.self, this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ClonesProducedUnits : INotifyOtherProduction
|
||||||
|
{
|
||||||
|
readonly ClonesProducedUnitsInfo info;
|
||||||
|
readonly Production production;
|
||||||
|
|
||||||
|
public ClonesProducedUnits(Actor self, ClonesProducedUnitsInfo info)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
production = self.Trait<Production>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnitProducedByOther(Actor self, Actor producer, Actor produced)
|
||||||
|
{
|
||||||
|
// No recursive cloning!
|
||||||
|
if (producer.HasTrait<ClonesProducedUnits>())
|
||||||
|
return;
|
||||||
|
|
||||||
|
var ci = produced.Info.Traits.GetOrDefault<CloneableInfo>();
|
||||||
|
if (ci == null || !info.CloneableTypes.Intersect(ci.Types).Any())
|
||||||
|
return;
|
||||||
|
|
||||||
|
production.Produce(self, produced.Info, self.Owner.Country.Race);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
24
OpenRA.Mods.RA/Cloneable.cs
Normal file
24
OpenRA.Mods.RA/Cloneable.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#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 OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA
|
||||||
|
{
|
||||||
|
[Desc("Actors with the \"ClonesProducedUnits\" trait will produce a free duplicate of me.")]
|
||||||
|
public class CloneableInfo : TraitInfo<Cloneable>
|
||||||
|
{
|
||||||
|
[Desc("This unit's cloneable type is:")]
|
||||||
|
public readonly string[] Types = { };
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Cloneable { }
|
||||||
|
}
|
||||||
@@ -528,6 +528,8 @@
|
|||||||
<Compile Include="Graphics\TextRenderable.cs" />
|
<Compile Include="Graphics\TextRenderable.cs" />
|
||||||
<Compile Include="Graphics\VoxelRenderable.cs" />
|
<Compile Include="Graphics\VoxelRenderable.cs" />
|
||||||
<Compile Include="Air\FlyAwayOnIdle.cs" />
|
<Compile Include="Air\FlyAwayOnIdle.cs" />
|
||||||
|
<Compile Include="Buildings\ClonesProducedUnits.cs" />
|
||||||
|
<Compile Include="Cloneable.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">
|
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.RA.Move;
|
using OpenRA.Mods.RA.Move;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
@@ -96,6 +97,12 @@ namespace OpenRA.Mods.RA
|
|||||||
if (!self.IsDead())
|
if (!self.IsDead())
|
||||||
foreach (var t in self.TraitsImplementing<INotifyProduction>())
|
foreach (var t in self.TraitsImplementing<INotifyProduction>())
|
||||||
t.UnitProduced(self, newUnit, exit);
|
t.UnitProduced(self, newUnit, exit);
|
||||||
|
|
||||||
|
var notifyOthers = self.World.ActorsWithTrait<INotifyOtherProduction>()
|
||||||
|
.Where(a => a.Actor.Owner == self.Owner);
|
||||||
|
|
||||||
|
foreach (var notify in notifyOthers)
|
||||||
|
notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -180,6 +180,8 @@
|
|||||||
KilledOnImpassableTerrain: true
|
KilledOnImpassableTerrain: true
|
||||||
ParachuteSequence: parach
|
ParachuteSequence: parach
|
||||||
ShadowSequence: parach-shadow
|
ShadowSequence: parach-shadow
|
||||||
|
Cloneable:
|
||||||
|
Types: Infantry
|
||||||
|
|
||||||
^Ship:
|
^Ship:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
|
|||||||
Reference in New Issue
Block a user