Moves some misc traits/activities to Mods.Common, moves some RA traits into the Traits folder

This commit is contained in:
reaperrr
2015-01-11 12:08:47 +01:00
parent be9d37f30e
commit e8fbfc366a
14 changed files with 23 additions and 29 deletions

View File

@@ -1,80 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2015 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 System.Linq;
using OpenRA.Effects;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.RA.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
class Demolish : Enter
{
readonly Actor target;
readonly IEnumerable<IDemolishable> demolishables;
readonly int delay;
readonly int flashes;
readonly int flashesDelay;
readonly int flashInterval;
readonly int flashDuration;
readonly Cloak cloak;
public Demolish(Actor self, Actor target, int delay, int flashes, int flashesDelay, int flashInterval, int flashDuration)
: base(self, target)
{
this.target = target;
demolishables = target.TraitsImplementing<IDemolishable>();
this.delay = delay;
this.flashes = flashes;
this.flashesDelay = flashesDelay;
this.flashInterval = flashInterval;
this.flashDuration = flashDuration;
cloak = self.TraitOrDefault<Cloak>();
}
protected override bool CanReserve(Actor self)
{
return demolishables.Any(i => i.IsValidTarget(target, self));
}
protected override void OnInside(Actor self)
{
self.World.AddFrameEndTask(w =>
{
if (target.IsDead)
return;
if (cloak != null && cloak.Info.UncloakOnDemolish)
cloak.Uncloak();
for (var f = 0; f < flashes; f++)
w.Add(new DelayedAction(flashesDelay + f * flashInterval, () =>
w.Add(new FlashTarget(target, ticks: flashDuration))));
w.Add(new DelayedAction(delay, () =>
{
if (target.IsDead)
return;
var modifiers = target.TraitsImplementing<IDamageModifier>()
.Concat(self.Owner.PlayerActor.TraitsImplementing<IDamageModifier>())
.Select(t => t.GetDamageModifier(self, null));
if (Util.ApplyPercentageModifiers(100, modifiers) > 0)
demolishables.Do(d => d.Demolish(target, self));
}));
});
}
}
}

View File

@@ -1,111 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2015 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 System.Drawing;
using System.Linq;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Orders;
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Traits
{
class C4DemolitionInfo : ITraitInfo
{
[Desc("Delay to demolish the target once the C4 is planted." +
"Measured in game ticks. Default is 1.8 seconds.")]
public readonly int C4Delay = 45;
[Desc("Number of times to flash the target")]
public readonly int Flashes = 3;
[Desc("Delay before the flashing starts")]
public readonly int FlashesDelay = 4;
[Desc("Interval between each flash")]
public readonly int FlashInterval = 4;
[Desc("Duration of each flash")]
public readonly int FlashDuration = 3;
[Desc("Voice string when planting explosive charges.")]
public readonly string Voice = "Attack";
public object Create(ActorInitializer init) { return new C4Demolition(this); }
}
class C4Demolition : IIssueOrder, IResolveOrder, IOrderVoice
{
readonly C4DemolitionInfo info;
public C4Demolition(C4DemolitionInfo info)
{
this.info = info;
}
public IEnumerable<IOrderTargeter> Orders
{
get { yield return new C4DemolitionOrderTargeter(); }
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
{
if (order.OrderID != "C4")
return null;
if (target.Type == TargetType.FrozenActor)
return new Order(order.OrderID, self, queued) { ExtraData = target.FrozenActor.ID };
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString != "C4")
return;
var target = self.ResolveFrozenActorOrder(order, Color.Red);
if (target.Type != TargetType.Actor)
return;
var demolishable = target.Actor.TraitOrDefault<IDemolishable>();
if (demolishable == null || !demolishable.IsValidTarget(target.Actor, self))
return;
if (!order.Queued)
self.CancelActivity();
self.SetTargetLine(target, Color.Red);
self.QueueActivity(new Demolish(self,
target.Actor, info.C4Delay, info.Flashes, info.FlashesDelay, info.FlashInterval, info.FlashDuration));
}
public string VoicePhraseForOrder(Actor self, Order order)
{
return order.OrderString == "C4" ? info.Voice : null;
}
class C4DemolitionOrderTargeter : UnitOrderTargeter
{
public C4DemolitionOrderTargeter()
: base("C4", 6, "c4", true, false) { }
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
{
// Obey force moving onto bridges
if (modifiers.HasModifier(TargetModifiers.ForceMove))
return false;
return target.TraitsImplementing<IDemolishable>().Any(i => i.IsValidTarget(target, self));
}
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
return target.Info.Traits.WithInterface<IDemolishableInfo>().Any(i => i.IsValidTarget(target.Info, self));
}
}
}
}

View File

@@ -13,6 +13,7 @@ using System.Linq;
using OpenRA.Effects;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.RA.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Effects

View File

@@ -1,67 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2015 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.Linq;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Traits
{
[Desc("Spawn new actors when sold.")]
class EmitInfantryOnSellInfo : TraitInfo<EmitInfantryOnSell>
{
public readonly float ValuePercent = 40;
public readonly float MinHpPercent = 30;
[ActorReference]
[Desc("Be sure to use lowercase. Default value is \"e1\".")]
public readonly string[] ActorTypes = { "e1" };
}
class EmitInfantryOnSell : INotifySold
{
public void Selling(Actor self) { }
static void Emit(Actor self)
{
var info = self.Info.Traits.Get<EmitInfantryOnSellInfo>();
var csv = self.Info.Traits.GetOrDefault<CustomSellValueInfo>();
var valued = self.Info.Traits.GetOrDefault<ValuedInfo>();
var cost = csv != null ? csv.Value : (valued != null ? valued.Cost : 0);
var health = self.TraitOrDefault<Health>();
var dudesValue = info.ValuePercent * cost;
if (health != null)
dudesValue = dudesValue * health.HP / health.MaxHP;
dudesValue /= 100;
var eligibleLocations = FootprintUtils.Tiles(self).ToList();
var actorTypes = info.ActorTypes.Select(a => new { Name = a, Cost = self.World.Map.Rules.Actors[a].Traits.Get<ValuedInfo>().Cost }).ToArray();
while (eligibleLocations.Count > 0 && actorTypes.Any(a => a.Cost <= dudesValue))
{
var at = actorTypes.Where(a => a.Cost <= dudesValue).Random(self.World.SharedRandom);
var loc = eligibleLocations.Random(self.World.SharedRandom);
eligibleLocations.Remove(loc);
dudesValue -= at.Cost;
self.World.AddFrameEndTask(w => w.CreateActor(at.Name, new TypeDictionary
{
new LocationInit(loc),
new OwnerInit(self.Owner),
}));
}
}
public void Sold(Actor self) { Emit(self); }
}
}

View File

@@ -83,7 +83,6 @@
<Compile Include="AI\HackyAI.cs" />
<Compile Include="Traits\AcceptsSupplies.cs" />
<Compile Include="Activities\DeliverResources.cs" />
<Compile Include="Activities\Demolish.cs" />
<Compile Include="Activities\DonateSupplies.cs" />
<Compile Include="Activities\FindResources.cs" />
<Compile Include="Activities\Infiltrate.cs" />
@@ -97,12 +96,11 @@
<Compile Include="Effects\TeslaZap.cs" />
<Compile Include="Traits\Render\RenderUnitReload.cs" />
<Compile Include="Graphics\TeslaZapRenderable.cs" />
<Compile Include="EjectOnDeath.cs" />
<Compile Include="Traits\EjectOnDeath.cs" />
<Compile Include="AI\RushFuzzy.cs" />
<Compile Include="AI\StateMachine.cs" />
<Compile Include="Traits\Attack\AttackLeap.cs" />
<Compile Include="Scripting\Properties\RepairableBuildingProperties.cs" />
<Compile Include="C4Demolition.cs" />
<Compile Include="Traits\PaletteEffects\ChronoshiftPaletteEffect.cs" />
<Compile Include="Traits\Chronoshiftable.cs" />
<Compile Include="CrateSpawner.cs" />
@@ -122,7 +120,6 @@
<Compile Include="Traits\DemoTruck.cs" />
<Compile Include="Effects\GpsDot.cs" />
<Compile Include="Effects\Parachute.cs" />
<Compile Include="EmitInfantryOnSell.cs" />
<Compile Include="Lint\CheckActorReferences.cs" />
<Compile Include="Lint\CheckSyncAnnotations.cs" />
<Compile Include="Lint\CheckTraitPrerequisites.cs" />
@@ -130,7 +127,7 @@
<Compile Include="Traits\MadTank.cs" />
<Compile Include="Traits\Mine.cs" />
<Compile Include="Traits\Minelayer.cs" />
<Compile Include="ParaDrop.cs" />
<Compile Include="Traits\ParaDrop.cs" />
<Compile Include="Traits\PortableChrono.cs" />
<Compile Include="Scripting\Properties\GuardProperties.cs" />
<Compile Include="Widgets\Logic\TabCompletionLogic.cs" />
@@ -138,7 +135,7 @@
<Compile Include="Traits\Render\RenderHarvester.cs" />
<Compile Include="Traits\Render\RenderDisguise.cs" />
<Compile Include="Traits\Render\RenderLandingCraft.cs" />
<Compile Include="Disguise.cs" />
<Compile Include="Traits\Disguise.cs" />
<Compile Include="Traits\SupplyTruck.cs" />
<Compile Include="Traits\SupportPowers\ChronoshiftPower.cs" />
<Compile Include="Traits\SupportPowers\GpsPower.cs" />
@@ -150,8 +147,7 @@
<Compile Include="Traits\HarvesterHuskModifier.cs" />
<Compile Include="Traits\LeavesHusk.cs" />
<Compile Include="Traits\TargetableSubmarine.cs" />
<Compile Include="TransformOnPassenger.cs" />
<Compile Include="Transforms.cs" />
<Compile Include="Traits\TransformOnPassenger.cs" />
<Compile Include="Widgets\Logic\KickSpectatorsLogic.cs" />
<Compile Include="Widgets\Logic\MissionBrowserLogic.cs" />
<Compile Include="Widgets\Logic\IngameMenuLogic.cs" />
@@ -219,11 +215,11 @@
<Compile Include="Lint\CheckPlayers.cs" />
<Compile Include="Lint\CheckActors.cs" />
<Compile Include="Lint\CheckMapCordon.cs" />
<Compile Include="Parachutable.cs" />
<Compile Include="Traits\Parachutable.cs" />
<Compile Include="Widgets\Logic\InstallFromCDLogic.cs" />
<Compile Include="Widgets\Logic\InstallMusicLogic.cs" />
<Compile Include="Traits\Buildings\ClonesProducedUnits.cs" />
<Compile Include="Cloneable.cs" />
<Compile Include="Traits\Cloneable.cs" />
<Compile Include="Widgets\Logic\Ingame\IngameCashCounterLogic.cs" />
<Compile Include="Widgets\Logic\Ingame\IngamePowerCounterLogic.cs" />
<Compile Include="Widgets\Logic\Ingame\IngamePowerBarLogic.cs" />

View File

@@ -8,6 +8,7 @@
*/
#endregion
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.RA.Traits;
using OpenRA.Scripting;
using OpenRA.Traits;

View File

@@ -11,7 +11,7 @@
using System;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
namespace OpenRA.Mods.RA.Traits
{
[Desc("Actors with the \"ClonesProducedUnits\" trait will produce a free duplicate of me.")]
public class CloneableInfo : TraitInfo<Cloneable>

View File

@@ -13,10 +13,9 @@ using System.Collections.Generic;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Effects;
using OpenRA.Mods.RA.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
namespace OpenRA.Mods.RA.Traits
{
[Desc("This unit can spawn and eject other actors while flying.")]
public class ParaDropInfo : ITraitInfo, Requires<CargoInfo>

View File

@@ -10,10 +10,9 @@
using OpenRA.Mods.Common.Effects;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.RA.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
namespace OpenRA.Mods.RA.Traits
{
[Desc("Can be paradropped by a ParaDrop actor.")]
class ParachutableInfo : ITraitInfo

View File

@@ -13,7 +13,7 @@ using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
namespace OpenRA.Mods.RA.Traits
{
public class TransformOnPassengerInfo : ITraitInfo
{

View File

@@ -1,109 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2015 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.Mods.Common.Activities;
using OpenRA.Mods.Common.Orders;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Traits
{
[Desc("Actor becomes a specified actor type when this trait is triggered.")]
class TransformsInfo : ITraitInfo
{
[ActorReference] public readonly string IntoActor = null;
public readonly CVec Offset = CVec.Zero;
public readonly int Facing = 96;
public readonly string[] TransformSounds = { };
public readonly string[] NoTransformSounds = { };
public virtual object Create(ActorInitializer init) { return new Transforms(init, this); }
}
class Transforms : IIssueOrder, IResolveOrder, IOrderVoice
{
readonly Actor self;
readonly TransformsInfo info;
readonly BuildingInfo bi;
readonly string race;
public Transforms(ActorInitializer init, TransformsInfo info)
{
self = init.Self;
this.info = info;
bi = self.World.Map.Rules.Actors[info.IntoActor].Traits.GetOrDefault<BuildingInfo>();
race = init.Contains<RaceInit>() ? init.Get<RaceInit, string>() : self.Owner.Country.Race;
}
public string VoicePhraseForOrder(Actor self, Order order)
{
return (order.OrderString == "DeployTransform") ? "Move" : null;
}
bool CanDeploy()
{
var b = self.TraitOrDefault<Building>();
if (b != null && b.Locked)
return false;
return bi == null || self.World.CanPlaceBuilding(info.IntoActor, bi, self.Location + info.Offset, self);
}
public IEnumerable<IOrderTargeter> Orders
{
get { yield return new DeployOrderTargeter("DeployTransform", 5, () => CanDeploy()); }
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
{
if (order.OrderID == "DeployTransform")
return new Order(order.OrderID, self, queued);
return null;
}
public void DeployTransform(bool queued)
{
var b = self.TraitOrDefault<Building>();
if (!CanDeploy() || (b != null && !b.Lock()))
{
foreach (var s in info.NoTransformSounds)
Sound.PlayToPlayer(self.Owner, s);
return;
}
if (!queued)
self.CancelActivity();
if (self.HasTrait<IFacing>())
self.QueueActivity(new Turn(self, info.Facing));
foreach (var nt in self.TraitsImplementing<INotifyTransform>())
nt.BeforeTransform(self);
var transform = new Transform(self, info.IntoActor) { Offset = info.Offset, Facing = info.Facing, Sounds = info.TransformSounds, Race = race };
var makeAnimation = self.TraitOrDefault<WithMakeAnimation>();
if (makeAnimation != null)
makeAnimation.Reverse(self, transform);
else
self.QueueActivity(transform);
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "DeployTransform")
DeployTransform(order.Queued);
}
}
}