Added OwnerLostAction
Allows customisation of what will happen to an actor when its owner loses.
This commit is contained in:
committed by
Paul Chote
parent
0d23070c8e
commit
367a7f617c
@@ -181,6 +181,7 @@ namespace OpenRA.Traits
|
||||
public interface INotifyActorDisposing { void Disposing(Actor self); }
|
||||
public interface INotifyOwnerChanged { void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner); }
|
||||
public interface INotifyEffectiveOwnerChanged { void OnEffectiveOwnerChanged(Actor self, Player oldEffectiveOwner, Player newEffectiveOwner); }
|
||||
public interface INotifyOwnerLost { void OnOwnerLost(Actor self); }
|
||||
|
||||
[RequireExplicitImplementation]
|
||||
public interface IVoiced
|
||||
|
||||
@@ -343,6 +343,7 @@
|
||||
<Compile Include="Traits\Crates\RevealMapCrateAction.cs" />
|
||||
<Compile Include="Traits\Crates\SupportPowerCrateAction.cs" />
|
||||
<Compile Include="Traits\Crushable.cs" />
|
||||
<Compile Include="Traits\OwnerLostAction.cs" />
|
||||
<Compile Include="Traits\CustomSellValue.cs" />
|
||||
<Compile Include="Traits\DamagedByTerrain.cs" />
|
||||
<Compile Include="Traits\DeliversCash.cs" />
|
||||
@@ -879,6 +880,7 @@
|
||||
<Compile Include="Traits\Player\PlayerResources.cs" />
|
||||
<Compile Include="UtilityCommands\DumpSequenceSheetsCommand.cs" />
|
||||
<Compile Include="UpdateRules\Rules\DefineLocomotors.cs" />
|
||||
<Compile Include="UpdateRules\Rules\DefineOwnerLostAction.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="AfterBuild">
|
||||
|
||||
51
OpenRA.Mods.Common/Traits/OwnerLostAction.cs
Normal file
51
OpenRA.Mods.Common/Traits/OwnerLostAction.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
#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;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public enum OwnerLostActionType { ChangeOwner, Dispose, Kill }
|
||||
|
||||
[Desc("Perform an action when the actor's owner is defeated.")]
|
||||
public class OwnerLostActionInfo : ConditionalTraitInfo
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
[Desc("What does this unit do when its owner loses.",
|
||||
"Allowed values are 'ChangeOwner', 'Dispose', 'Kill'")]
|
||||
public readonly OwnerLostActionType Action = OwnerLostActionType.Kill;
|
||||
|
||||
[Desc("Map player to use when 'Action' is 'ChangeOwner'.")]
|
||||
public readonly string Owner = "Neutral";
|
||||
|
||||
public override object Create(ActorInitializer init) { return new OwnerLostAction(init, this); }
|
||||
}
|
||||
|
||||
public class OwnerLostAction : ConditionalTrait<OwnerLostActionInfo>, INotifyOwnerLost
|
||||
{
|
||||
public OwnerLostAction(ActorInitializer init, OwnerLostActionInfo info)
|
||||
: base(info) { }
|
||||
|
||||
void INotifyOwnerLost.OnOwnerLost(Actor self)
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
return;
|
||||
|
||||
if (Info.Action == OwnerLostActionType.Kill)
|
||||
self.Kill(self);
|
||||
else if (Info.Action == OwnerLostActionType.Dispose)
|
||||
self.Dispose();
|
||||
else if (Info.Action == OwnerLostActionType.ChangeOwner)
|
||||
self.ChangeOwner(self.World.Players.First(p => p.InternalName == Info.Owner));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,8 +70,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void OnPlayerLost(Player player)
|
||||
{
|
||||
foreach (var a in player.World.Actors.Where(a => a.Owner == player))
|
||||
a.Kill(a);
|
||||
foreach (var a in player.World.ActorsWithTrait<INotifyOwnerLost>().Where(a => a.Actor.Owner == player))
|
||||
a.Trait.OnOwnerLost(a.Actor);
|
||||
|
||||
if (info.SuppressNotifications)
|
||||
return;
|
||||
|
||||
@@ -109,8 +109,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void OnPlayerLost(Player player)
|
||||
{
|
||||
foreach (var a in player.World.Actors.Where(a => a.Owner == player))
|
||||
a.Kill(a);
|
||||
foreach (var a in player.World.ActorsWithTrait<INotifyOwnerLost>().Where(a => a.Actor.Owner == player))
|
||||
a.Trait.OnOwnerLost(a.Actor);
|
||||
|
||||
if (info.SuppressNotifications)
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#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;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRA.Mods.Common.UpdateRules.Rules
|
||||
{
|
||||
public class DefineOwnerLostAction : UpdateRule
|
||||
{
|
||||
public override string Name { get { return "Add OwnerLostAction to player-controlled actors"; } }
|
||||
public override string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return "A new OwnerLostAction trait has been introduced to control what happens to a\n" +
|
||||
"player's actors when they are defeated. A warning is displayed notifying that\nthis trait must be added to actors.";
|
||||
}
|
||||
}
|
||||
|
||||
bool reported;
|
||||
public override IEnumerable<string> AfterUpdate(ModData modData)
|
||||
{
|
||||
if (!reported)
|
||||
yield return "All player-controlled (or player-capturable) actors should define an OwnerLostAction trait\n" +
|
||||
"specifying an action (Kill, Dispose, ChangeOwner) to apply when the actor's owner is defeated.\n" +
|
||||
"You must manually define this trait on the appropriate default actor templates.\n" +
|
||||
"Actors missing this trait will remain controllable by their owner after they have been defeated.";
|
||||
|
||||
reported = true;
|
||||
}
|
||||
|
||||
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,8 @@ namespace OpenRA.Mods.Common.UpdateRules
|
||||
new AddShakeToBridge(),
|
||||
new AddEditorPlayer(),
|
||||
new RemovePaletteFromCurrentTileset(),
|
||||
new DefineLocomotors()
|
||||
new DefineLocomotors(),
|
||||
new DefineOwnerLostAction()
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user