implement Ordos nerve gas missiles as warheads

closes #2838
This commit is contained in:
Matthias Mailänder
2014-10-05 17:04:04 +02:00
parent 611e3038b2
commit 9e650adef8
8 changed files with 142 additions and 49 deletions

View 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.Collections.Generic;
using OpenRA.GameRules;
using OpenRA.Traits;
namespace OpenRA.Mods.D2k
{
[Desc("Interacts with the DynamicOwnerChange trait.")]
public class ChangeOwnerWarhead : Warhead
{
[Desc("Duration of the owner change (in ticks). Set to 0 to make it permanent.")]
public readonly int Duration = 0;
public readonly WRange Range = WRange.FromCells(1);
public override void DoImpact(Target target, Actor firedBy, IEnumerable<int> damageModifiers)
{
var actors = target.Type == TargetType.Actor ? new[] { target.Actor } :
firedBy.World.FindActorsInCircle(target.CenterPosition, Range);
foreach (var a in actors)
{
if (a.Owner == firedBy.Owner) // don't do anything on friendly fire
continue;
if (Duration == 0)
a.ChangeOwner(firedBy.Owner); // permanent
else
{
var tempOwnerManager = a.TraitOrDefault<TemporaryOwnerManager>();
if (tempOwnerManager == null)
continue;
tempOwnerManager.ChangeOwner(a, firedBy.Owner, Duration);
}
a.CancelActivity(); // stop shooting, you have got new enemies
}
}
}
}

View File

@@ -92,6 +92,8 @@
<Compile Include="AutoCarryall\Carryable.cs" />
<Compile Include="AutoCarryall\CarryUnit.cs" />
<Compile Include="WormManager.cs" />
<Compile Include="ChangeOwnerWarhead.cs" />
<Compile Include="TemporaryOwnerManager.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>

View File

@@ -0,0 +1,82 @@
#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.Drawing;
using OpenRA.Traits;
namespace OpenRA.Mods.D2k
{
[Desc("Interacts with the ChangeOwner warhead.",
"Displays a bar how long this actor is affected and reverts back to the old owner on temporary changes.")]
public class TemporaryOwnerManagerInfo : ITraitInfo
{
public readonly Color BarColor = Color.Orange;
public object Create(ActorInitializer init) { return new TemporaryOwnerManager(init.self, this); }
}
public class TemporaryOwnerManager : ISelectionBar, ITick, ISync, INotifyOwnerChanged
{
readonly TemporaryOwnerManagerInfo info;
Player originalOwner;
Player changingOwner;
[Sync] int remaining = -1;
int duration;
public TemporaryOwnerManager(Actor self, TemporaryOwnerManagerInfo info)
{
this.info = info;
originalOwner = self.Owner;
}
public void ChangeOwner(Actor self, Player newOwner, int duration)
{
remaining = this.duration = duration;
changingOwner = newOwner;
self.ChangeOwner(newOwner);
}
public void Tick(Actor self)
{
if (!self.IsInWorld)
return;
if (--remaining == 0)
{
changingOwner = originalOwner;
self.ChangeOwner(originalOwner);
self.CancelActivity(); // Stop shooting, you have got new enemies
}
}
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
{
if (changingOwner == null || changingOwner != newOwner)
originalOwner = newOwner; // It wasn't a temporary change, so we need to update here
else
changingOwner = null; // It was triggered by this trait: reset
}
public float GetValue()
{
if (remaining <= 0)
return 0;
return (float)remaining / duration;
}
public Color GetColor()
{
return info.BarColor;
}
}
}