move common traits
This commit is contained in:
@@ -1,41 +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 OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class DonateSupplies : Enter
|
||||
{
|
||||
readonly Actor target;
|
||||
readonly int payload;
|
||||
|
||||
public DonateSupplies(Actor self, Actor target, int payload)
|
||||
: base(self, target)
|
||||
{
|
||||
this.target = target;
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
protected override void OnInside(Actor self)
|
||||
{
|
||||
if (target.IsDead)
|
||||
return;
|
||||
|
||||
target.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(payload);
|
||||
self.Destroy();
|
||||
|
||||
if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
|
||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(target.CenterPosition, target.Owner.Color.RGB, FloatingText.FormatCashTick(payload), 30)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,110 +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;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Effects;
|
||||
using OpenRA.Mods.RA.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
[Desc("Displays fireports, muzzle offsets, and hit areas in developer mode.")]
|
||||
public class CombatDebugOverlayInfo : ITraitInfo
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new CombatDebugOverlay(init.Self); }
|
||||
}
|
||||
|
||||
public class CombatDebugOverlay : IPostRender, INotifyDamage
|
||||
{
|
||||
Lazy<AttackBase> attack;
|
||||
Lazy<IBodyOrientation> coords;
|
||||
Lazy<Health> health;
|
||||
DeveloperMode devMode;
|
||||
|
||||
public CombatDebugOverlay(Actor self)
|
||||
{
|
||||
attack = Exts.Lazy(() => self.TraitOrDefault<AttackBase>());
|
||||
coords = Exts.Lazy(() => self.Trait<IBodyOrientation>());
|
||||
health = Exts.Lazy(() => self.TraitOrDefault<Health>());
|
||||
|
||||
var localPlayer = self.World.LocalPlayer;
|
||||
devMode = localPlayer != null ? localPlayer.PlayerActor.Trait<DeveloperMode>() : null;
|
||||
}
|
||||
|
||||
public void RenderAfterWorld(WorldRenderer wr, Actor self)
|
||||
{
|
||||
if (devMode == null || !devMode.ShowCombatGeometry)
|
||||
return;
|
||||
|
||||
if (health.Value != null)
|
||||
wr.DrawRangeCircle(self.CenterPosition, health.Value.Info.Radius, Color.Red);
|
||||
|
||||
// No armaments to draw
|
||||
if (attack.Value == null)
|
||||
return;
|
||||
|
||||
var wlr = Game.Renderer.WorldLineRenderer;
|
||||
var c = Color.White;
|
||||
|
||||
// Fire ports on garrisonable structures
|
||||
var garrison = attack.Value as AttackGarrisoned;
|
||||
if (garrison != null)
|
||||
{
|
||||
var bodyOrientation = coords.Value.QuantizeOrientation(self, self.Orientation);
|
||||
foreach (var p in garrison.Ports)
|
||||
{
|
||||
var pos = self.CenterPosition + coords.Value.LocalToWorld(p.Offset.Rotate(bodyOrientation));
|
||||
var da = coords.Value.LocalToWorld(new WVec(224, 0, 0).Rotate(WRot.FromYaw(p.Yaw + p.Cone)).Rotate(bodyOrientation));
|
||||
var db = coords.Value.LocalToWorld(new WVec(224, 0, 0).Rotate(WRot.FromYaw(p.Yaw - p.Cone)).Rotate(bodyOrientation));
|
||||
|
||||
var o = wr.ScreenPosition(pos);
|
||||
var a = wr.ScreenPosition(pos + da * 224 / da.Length);
|
||||
var b = wr.ScreenPosition(pos + db * 224 / db.Length);
|
||||
wlr.DrawLine(o, a, c, c);
|
||||
wlr.DrawLine(o, b, c, c);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var a in attack.Value.Armaments)
|
||||
{
|
||||
foreach (var b in a.Barrels)
|
||||
{
|
||||
var muzzle = self.CenterPosition + a.MuzzleOffset(self, b);
|
||||
var dirOffset = new WVec(0, -224, 0).Rotate(a.MuzzleOrientation(self, b));
|
||||
|
||||
var sm = wr.ScreenPosition(muzzle);
|
||||
var sd = wr.ScreenPosition(muzzle + dirOffset);
|
||||
wlr.DrawLine(sm, sd, c, c);
|
||||
wr.DrawTargetMarker(c, sm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
if (devMode == null || !devMode.ShowCombatGeometry || e.Damage == 0)
|
||||
return;
|
||||
|
||||
var health = self.TraitOrDefault<Health>();
|
||||
if (health == null)
|
||||
return;
|
||||
|
||||
var damageText = "{0} ({1}%)".F(-e.Damage, e.Damage * 100 / health.MaxHP);
|
||||
|
||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, e.Attacker.Owner.Color.RGB, damageText, 30)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,54 +65,47 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Traits\AcceptsSupplies.cs" />
|
||||
<Compile Include="Activities\DonateSupplies.cs" />
|
||||
<Compile Include="Activities\Infiltrate.cs" />
|
||||
<Compile Include="Activities\LayMines.cs" />
|
||||
<Compile Include="Activities\Leap.cs" />
|
||||
<Compile Include="Activities\Teleport.cs" />
|
||||
<Compile Include="Effects\GpsDot.cs" />
|
||||
<Compile Include="Effects\GpsSatellite.cs" />
|
||||
<Compile Include="Effects\SatelliteLaunch.cs" />
|
||||
<Compile Include="Effects\TeslaZap.cs" />
|
||||
<Compile Include="Traits\Render\RenderUnitReload.cs" />
|
||||
<Compile Include="Graphics\TeslaZapRenderable.cs" />
|
||||
<Compile Include="Traits\EjectOnDeath.cs" />
|
||||
<Compile Include="Traits\Attack\AttackLeap.cs" />
|
||||
<Compile Include="Traits\PaletteEffects\ChronoshiftPaletteEffect.cs" />
|
||||
<Compile Include="Traits\Chronoshiftable.cs" />
|
||||
<Compile Include="Traits\DemoTruck.cs" />
|
||||
<Compile Include="Effects\GpsDot.cs" />
|
||||
<Compile Include="Traits\MadTank.cs" />
|
||||
<Compile Include="Traits\Mine.cs" />
|
||||
<Compile Include="Traits\Minelayer.cs" />
|
||||
<Compile Include="Traits\PortableChrono.cs" />
|
||||
<Compile Include="Traits\Render\RenderJammerCircle.cs" />
|
||||
<Compile Include="Traits\Render\RenderDisguise.cs" />
|
||||
<Compile Include="Traits\Render\RenderLandingCraft.cs" />
|
||||
<Compile Include="Traits\Disguise.cs" />
|
||||
<Compile Include="Traits\SupplyTruck.cs" />
|
||||
<Compile Include="Traits\SupportPowers\ChronoshiftPower.cs" />
|
||||
<Compile Include="Traits\SupportPowers\GpsPower.cs" />
|
||||
<Compile Include="Traits\SupportPowers\ParatroopersPower.cs" />
|
||||
<Compile Include="Traits\Buildings\Fake.cs" />
|
||||
<Compile Include="Traits\Buildings\ClonesProducedUnits.cs" />
|
||||
<Compile Include="Traits\Chronoshiftable.cs" />
|
||||
<Compile Include="Traits\Cloneable.cs" />
|
||||
<Compile Include="Traits\DemoTruck.cs" />
|
||||
<Compile Include="Traits\Disguise.cs" />
|
||||
<Compile Include="Traits\HarvesterHuskModifier.cs" />
|
||||
<Compile Include="Traits\LeavesHusk.cs" />
|
||||
<Compile Include="Traits\TargetableSubmarine.cs" />
|
||||
<Compile Include="Traits\TransformOnPassenger.cs" />
|
||||
<Compile Include="Traits\Render\RenderShroudCircle.cs" />
|
||||
<Compile Include="Traits\Infiltration\InfiltrateForCash.cs" />
|
||||
<Compile Include="Traits\Infiltration\InfiltrateForExploration.cs" />
|
||||
<Compile Include="Traits\Infiltration\InfiltrateForPowerOutage.cs" />
|
||||
<Compile Include="Traits\Infiltration\InfiltrateForSupportPower.cs" />
|
||||
<Compile Include="Traits\Infiltration\Infiltrates.cs" />
|
||||
<Compile Include="CombatDebugOverlay.cs" />
|
||||
<Compile Include="Traits\Attack\AttackGarrisoned.cs" />
|
||||
<Compile Include="Scripting\Properties\ChronosphereProperties.cs" />
|
||||
<Compile Include="Traits\Buildings\ClonesProducedUnits.cs" />
|
||||
<Compile Include="Traits\Cloneable.cs" />
|
||||
<Compile Include="Scripting\Properties\HarvesterProperties.cs" />
|
||||
<Compile Include="Scripting\Properties\TransportProperties.cs" />
|
||||
<Compile Include="Traits\InvulnerabilityUpgrade.cs" />
|
||||
<Compile Include="Traits\MadTank.cs" />
|
||||
<Compile Include="Traits\Mine.cs" />
|
||||
<Compile Include="Traits\Minelayer.cs" />
|
||||
<Compile Include="Traits\PaletteEffects\ChronoshiftPaletteEffect.cs" />
|
||||
<Compile Include="Traits\PortableChrono.cs" />
|
||||
<Compile Include="Traits\Render\RenderJammerCircle.cs" />
|
||||
<Compile Include="Traits\Render\RenderDisguise.cs" />
|
||||
<Compile Include="Traits\Render\RenderLandingCraft.cs" />
|
||||
<Compile Include="Traits\Render\RenderShroudCircle.cs" />
|
||||
<Compile Include="Traits\Render\RenderUnitReload.cs" />
|
||||
<Compile Include="Traits\SupportPowers\ChronoshiftPower.cs" />
|
||||
<Compile Include="Traits\SupportPowers\GpsPower.cs" />
|
||||
<Compile Include="Traits\SupportPowers\ParatroopersPower.cs" />
|
||||
<Compile Include="Traits\LeavesHusk.cs" />
|
||||
<Compile Include="Traits\TargetableSubmarine.cs" />
|
||||
<Compile Include="Scripting\Properties\ChronosphereProperties.cs" />
|
||||
<Compile Include="Scripting\Properties\ParadropProperties.cs" />
|
||||
<Compile Include="Scripting\Properties\ParatroopersProperties.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">
|
||||
|
||||
@@ -1,35 +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 OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ScriptPropertyGroup("Harvester")]
|
||||
public class HarvesterProperties : ScriptActorProperties, Requires<HarvesterInfo>
|
||||
{
|
||||
readonly Harvester harvester;
|
||||
|
||||
public HarvesterProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
harvester = self.Trait<Harvester>();
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Search for nearby resources and begin harvesting.")]
|
||||
public void FindResources()
|
||||
{
|
||||
harvester.ContinueHarvesting(Self);
|
||||
}
|
||||
}
|
||||
}
|
||||
41
OpenRA.Mods.RA/Scripting/Properties/ParadropProperties.cs
Normal file
41
OpenRA.Mods.RA/Scripting/Properties/ParadropProperties.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
#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.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ScriptPropertyGroup("Paradrop")]
|
||||
public class ParadropProperties : ScriptActorProperties, Requires<CargoInfo>, Requires<ParaDropInfo>
|
||||
{
|
||||
readonly ParaDrop paradrop;
|
||||
|
||||
public ParadropProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
paradrop = self.Trait<ParaDrop>();
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Command transport to paradrop passengers near the target cell.")]
|
||||
public void Paradrop(CPos cell)
|
||||
{
|
||||
paradrop.SetLZ(cell, true);
|
||||
Self.QueueActivity(new Fly(Self, Target.FromCell(Self.World, cell)));
|
||||
Self.QueueActivity(new FlyOffMap());
|
||||
Self.QueueActivity(new RemoveSelf());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#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.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ScriptPropertyGroup("Paratroopers")]
|
||||
public class ParatroopersProperties : ScriptActorProperties, Requires<ParatroopersPowerInfo>
|
||||
{
|
||||
readonly ParatroopersPower pp;
|
||||
|
||||
public ParatroopersProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
pp = self.TraitsImplementing<ParatroopersPower>().First();
|
||||
}
|
||||
|
||||
[Desc("Activate the actor's Paratroopers Power. Returns the dropped units.")]
|
||||
public Actor[] SendParatroopers(WPos target, bool randomize = true, int facing = 0)
|
||||
{
|
||||
return pp.SendParatroopers(Self, target, randomize, facing);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,87 +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.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ScriptPropertyGroup("Transports")]
|
||||
public class TransportProperties : ScriptActorProperties, Requires<CargoInfo>
|
||||
{
|
||||
readonly Cargo cargo;
|
||||
|
||||
public TransportProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
cargo = self.Trait<Cargo>();
|
||||
}
|
||||
|
||||
[Desc("Specifies whether transport has any passengers.")]
|
||||
public bool HasPassengers { get { return cargo.Passengers.Any(); } }
|
||||
|
||||
[Desc("Teleport an existing actor inside this transport.")]
|
||||
public void LoadPassenger(Actor a) { cargo.Load(Self, a); }
|
||||
|
||||
[Desc("Remove the first actor from the transport. This actor is not added to the world.")]
|
||||
public Actor UnloadPassenger() { return cargo.Unload(Self); }
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Command transport to unload passengers.")]
|
||||
public void UnloadPassengers()
|
||||
{
|
||||
Self.QueueActivity(new UnloadCargo(Self, true));
|
||||
}
|
||||
}
|
||||
|
||||
[ScriptPropertyGroup("Transports")]
|
||||
public class ParadropPowers : ScriptActorProperties, Requires<CargoInfo>, Requires<ParaDropInfo>
|
||||
{
|
||||
readonly ParaDrop paradrop;
|
||||
|
||||
public ParadropPowers(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
paradrop = self.Trait<ParaDrop>();
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Command transport to paradrop passengers near the target cell.")]
|
||||
public void Paradrop(CPos cell)
|
||||
{
|
||||
paradrop.SetLZ(cell, true);
|
||||
Self.QueueActivity(new Fly(Self, Target.FromCell(Self.World, cell)));
|
||||
Self.QueueActivity(new FlyOffMap());
|
||||
Self.QueueActivity(new RemoveSelf());
|
||||
}
|
||||
}
|
||||
|
||||
[ScriptGlobal("Air Support Powers")]
|
||||
public class ParatroopersProperties : ScriptActorProperties, Requires<ParatroopersPowerInfo>
|
||||
{
|
||||
readonly ParatroopersPower pp;
|
||||
|
||||
public ParatroopersProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
pp = self.TraitsImplementing<ParatroopersPower>().First();
|
||||
}
|
||||
|
||||
[Desc("Activate the actor's Paratroopers Power. Returns the dropped units.")]
|
||||
public Actor[] SendParatroopers(WPos target, bool randomize = true, int facing = 0)
|
||||
{
|
||||
return pp.SendParatroopers(Self, target, randomize, facing);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +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 OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
[Desc("Tag trait for SupplyTruck: actors.")]
|
||||
class AcceptsSuppliesInfo : TraitInfo<AcceptsSupplies> { }
|
||||
|
||||
class AcceptsSupplies { }
|
||||
}
|
||||
@@ -1,196 +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;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
public class FirePort
|
||||
{
|
||||
public WVec Offset;
|
||||
public WAngle Yaw;
|
||||
public WAngle Cone;
|
||||
}
|
||||
|
||||
[Desc("Cargo can fire their weapons out of fire ports.")]
|
||||
public class AttackGarrisonedInfo : AttackFollowInfo, Requires<CargoInfo>
|
||||
{
|
||||
[Desc("Fire port offsets in local coordinates.")]
|
||||
public readonly WVec[] PortOffsets = { };
|
||||
|
||||
[Desc("Fire port yaw angles.")]
|
||||
public readonly WAngle[] PortYaws = { };
|
||||
|
||||
[Desc("Fire port yaw cone angle.")]
|
||||
public readonly WAngle[] PortCones = { };
|
||||
|
||||
public readonly string MuzzlePalette = "effect";
|
||||
|
||||
public override object Create(ActorInitializer init) { return new AttackGarrisoned(init.Self, this); }
|
||||
}
|
||||
|
||||
public class AttackGarrisoned : AttackFollow, INotifyPassengerEntered, INotifyPassengerExited, IRender
|
||||
{
|
||||
public readonly FirePort[] Ports;
|
||||
|
||||
AttackGarrisonedInfo info;
|
||||
Lazy<IBodyOrientation> coords;
|
||||
List<Armament> armaments;
|
||||
List<AnimationWithOffset> muzzles;
|
||||
Dictionary<Actor, IFacing> paxFacing;
|
||||
Dictionary<Actor, IPositionable> paxPos;
|
||||
Dictionary<Actor, RenderSprites> paxRender;
|
||||
|
||||
public AttackGarrisoned(Actor self, AttackGarrisonedInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
coords = Exts.Lazy(() => self.Trait<IBodyOrientation>());
|
||||
armaments = new List<Armament>();
|
||||
muzzles = new List<AnimationWithOffset>();
|
||||
paxFacing = new Dictionary<Actor, IFacing>();
|
||||
paxPos = new Dictionary<Actor, IPositionable>();
|
||||
paxRender = new Dictionary<Actor, RenderSprites>();
|
||||
|
||||
getArmaments = () => armaments;
|
||||
|
||||
if (info.PortOffsets.Length == 0)
|
||||
throw new InvalidOperationException("PortOffsets must have at least one entry.");
|
||||
|
||||
if (info.PortYaws.Length != info.PortOffsets.Length)
|
||||
throw new InvalidOperationException("PortYaws must define an angle for each port.");
|
||||
|
||||
if (info.PortCones.Length != info.PortOffsets.Length)
|
||||
throw new InvalidOperationException("PortCones must define an angle for each port.");
|
||||
|
||||
var p = new List<FirePort>();
|
||||
for (var i = 0; i < info.PortOffsets.Length; i++)
|
||||
{
|
||||
p.Add(new FirePort
|
||||
{
|
||||
Offset = info.PortOffsets[i],
|
||||
Yaw = info.PortYaws[i],
|
||||
Cone = info.PortCones[i],
|
||||
});
|
||||
}
|
||||
|
||||
Ports = p.ToArray();
|
||||
}
|
||||
|
||||
public void PassengerEntered(Actor self, Actor passenger)
|
||||
{
|
||||
paxFacing.Add(passenger, passenger.Trait<IFacing>());
|
||||
paxPos.Add(passenger, passenger.Trait<IPositionable>());
|
||||
paxRender.Add(passenger, passenger.Trait<RenderSprites>());
|
||||
armaments.AddRange(
|
||||
passenger.TraitsImplementing<Armament>()
|
||||
.Where(a => info.Armaments.Contains(a.Info.Name)));
|
||||
}
|
||||
|
||||
public void PassengerExited(Actor self, Actor passenger)
|
||||
{
|
||||
paxFacing.Remove(passenger);
|
||||
paxPos.Remove(passenger);
|
||||
paxRender.Remove(passenger);
|
||||
armaments.RemoveAll(a => a.Actor == passenger);
|
||||
}
|
||||
|
||||
FirePort SelectFirePort(Actor self, WAngle targetYaw)
|
||||
{
|
||||
// Pick a random port that faces the target
|
||||
var bodyYaw = facing.Value != null ? WAngle.FromFacing(facing.Value.Facing) : WAngle.Zero;
|
||||
var indices = Enumerable.Range(0, Ports.Length).Shuffle(self.World.SharedRandom);
|
||||
foreach (var i in indices)
|
||||
{
|
||||
var yaw = bodyYaw + Ports[i].Yaw;
|
||||
var leftTurn = (yaw - targetYaw).Angle;
|
||||
var rightTurn = (targetYaw - yaw).Angle;
|
||||
if (Math.Min(leftTurn, rightTurn) <= Ports[i].Cone.Angle)
|
||||
return Ports[i];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
WVec PortOffset(Actor self, FirePort p)
|
||||
{
|
||||
var bodyOrientation = coords.Value.QuantizeOrientation(self, self.Orientation);
|
||||
return coords.Value.LocalToWorld(p.Offset.Rotate(bodyOrientation));
|
||||
}
|
||||
|
||||
public override void DoAttack(Actor self, Target target)
|
||||
{
|
||||
if (!CanAttack(self, target))
|
||||
return;
|
||||
|
||||
var pos = self.CenterPosition;
|
||||
var targetYaw = WAngle.FromFacing(OpenRA.Traits.Util.GetFacing(target.CenterPosition - self.CenterPosition, 0));
|
||||
|
||||
foreach (var a in Armaments)
|
||||
{
|
||||
var port = SelectFirePort(self, targetYaw);
|
||||
if (port == null)
|
||||
return;
|
||||
|
||||
var muzzleFacing = targetYaw.Angle / 4;
|
||||
paxFacing[a.Actor].Facing = muzzleFacing;
|
||||
paxPos[a.Actor].SetVisualPosition(a.Actor, pos + PortOffset(self, port));
|
||||
|
||||
var barrel = a.CheckFire(a.Actor, facing.Value, target);
|
||||
if (barrel != null && a.Info.MuzzleSequence != null)
|
||||
{
|
||||
// Muzzle facing is fixed once the firing starts
|
||||
var muzzleAnim = new Animation(self.World, paxRender[a.Actor].GetImage(a.Actor), () => muzzleFacing);
|
||||
var sequence = a.Info.MuzzleSequence;
|
||||
|
||||
if (a.Info.MuzzleSplitFacings > 0)
|
||||
sequence += OpenRA.Traits.Util.QuantizeFacing(muzzleFacing, a.Info.MuzzleSplitFacings).ToString();
|
||||
|
||||
var muzzleFlash = new AnimationWithOffset(muzzleAnim,
|
||||
() => PortOffset(self, port),
|
||||
() => false,
|
||||
() => false,
|
||||
p => WithTurret.ZOffsetFromCenter(self, p, 1024));
|
||||
|
||||
muzzles.Add(muzzleFlash);
|
||||
muzzleAnim.PlayThen(sequence, () => muzzles.Remove(muzzleFlash));
|
||||
}
|
||||
|
||||
foreach (var npa in self.TraitsImplementing<INotifyAttack>())
|
||||
npa.Attacking(self, target, a, barrel);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> Render(Actor self, WorldRenderer wr)
|
||||
{
|
||||
var pal = wr.Palette(info.MuzzlePalette);
|
||||
|
||||
// Display muzzle flashes
|
||||
foreach (var m in muzzles)
|
||||
foreach (var r in m.Render(self, wr, pal, 1f))
|
||||
yield return r;
|
||||
}
|
||||
|
||||
public override void Tick(Actor self)
|
||||
{
|
||||
base.Tick(self);
|
||||
|
||||
// Take a copy so that Tick() can remove animations
|
||||
foreach (var m in muzzles.ToArray())
|
||||
m.Animation.Tick();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,77 +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 OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Effects;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
[Desc("Eject a ground soldier or a paratrooper while in the air.")]
|
||||
public class EjectOnDeathInfo : TraitInfo<EjectOnDeath>
|
||||
{
|
||||
[ActorReference]
|
||||
public readonly string PilotActor = "E1";
|
||||
public readonly int SuccessRate = 50;
|
||||
public readonly string ChuteSound = "chute1.aud";
|
||||
public readonly bool EjectInAir = false;
|
||||
public readonly bool EjectOnGround = false;
|
||||
|
||||
[Desc("Risks stuck units when they don't have the Paratrooper trait.")]
|
||||
public readonly bool AllowUnsuitableCell = false;
|
||||
}
|
||||
|
||||
public class EjectOnDeath : INotifyKilled
|
||||
{
|
||||
public void Killed(Actor self, AttackInfo e)
|
||||
{
|
||||
if (self.Owner.WinState == WinState.Lost || !self.World.Map.Contains(self.Location))
|
||||
return;
|
||||
|
||||
var r = self.World.SharedRandom.Next(1, 100);
|
||||
var info = self.Info.Traits.Get<EjectOnDeathInfo>();
|
||||
|
||||
if (r <= 100 - info.SuccessRate)
|
||||
return;
|
||||
|
||||
var cp = self.CenterPosition;
|
||||
if ((cp.Z > 0 && !info.EjectInAir) || (cp.Z == 0 && !info.EjectOnGround))
|
||||
return;
|
||||
|
||||
var pilot = self.World.CreateActor(false, info.PilotActor.ToLowerInvariant(),
|
||||
new TypeDictionary { new OwnerInit(self.Owner), new LocationInit(self.Location) });
|
||||
|
||||
if (info.AllowUnsuitableCell || IsSuitableCell(self, pilot))
|
||||
{
|
||||
if (cp.Z > 0)
|
||||
{
|
||||
self.World.AddFrameEndTask(w => w.Add(new Parachute(pilot, cp)));
|
||||
Sound.Play(info.ChuteSound, cp);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.World.AddFrameEndTask(w => w.Add(pilot));
|
||||
var pilotMobile = pilot.TraitOrDefault<Mobile>();
|
||||
if (pilotMobile != null)
|
||||
pilotMobile.Nudge(pilot, pilot, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
pilot.Destroy();
|
||||
}
|
||||
|
||||
static bool IsSuitableCell(Actor self, Actor actorToDrop)
|
||||
{
|
||||
return actorToDrop.Trait<IPositionable>().CanEnterCell(self.Location, self, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.RA.Traits
|
||||
if (turreted != null)
|
||||
td.Add(new TurretFacingInit(turreted.TurretFacing));
|
||||
|
||||
var chronoshiftable = self.TraitOrDefault<Chronoshiftable>();
|
||||
var chronoshiftable = self.TraitOrDefault<Chronoshiftable>(); // TODO: untie this and move to Mods.Common
|
||||
if (chronoshiftable != null && chronoshiftable.ReturnTicks > 0)
|
||||
{
|
||||
td.Add(new ChronoshiftOriginInit(chronoshiftable.Origin));
|
||||
|
||||
@@ -1,92 +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 OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
[Desc("Donate money to building if it has the AcceptSupplies: trait.")]
|
||||
class SupplyTruckInfo : ITraitInfo
|
||||
{
|
||||
[Desc("The amount of cash the owner of the building recieves.")]
|
||||
public readonly int Payload = 500;
|
||||
public object Create(ActorInitializer init) { return new SupplyTruck(this); }
|
||||
}
|
||||
|
||||
class SupplyTruck : IIssueOrder, IResolveOrder, IOrderVoice
|
||||
{
|
||||
SupplyTruckInfo info;
|
||||
|
||||
public SupplyTruck(SupplyTruckInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
{
|
||||
get { yield return new SupplyTruckOrderTargeter(); }
|
||||
}
|
||||
|
||||
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
||||
{
|
||||
if (order.OrderID != "DeliverSupplies")
|
||||
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 string VoicePhraseForOrder(Actor self, Order order)
|
||||
{
|
||||
return "Move";
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString != "DeliverSupplies")
|
||||
return;
|
||||
|
||||
var target = self.ResolveFrozenActorOrder(order, Color.Yellow);
|
||||
if (target.Type != TargetType.Actor)
|
||||
return;
|
||||
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
self.SetTargetLine(target, Color.Yellow);
|
||||
self.QueueActivity(new DonateSupplies(self, target.Actor, info.Payload));
|
||||
}
|
||||
|
||||
class SupplyTruckOrderTargeter : UnitOrderTargeter
|
||||
{
|
||||
public SupplyTruckOrderTargeter()
|
||||
: base("DeliverSupplies", 5, "enter", false, true)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
return target.HasTrait<AcceptsSupplies>();
|
||||
}
|
||||
|
||||
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
return target.Info.Traits.Contains<AcceptsSuppliesInfo>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +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.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
public class TransformOnPassengerInfo : ITraitInfo
|
||||
{
|
||||
[ActorReference] public readonly string[] PassengerTypes = { };
|
||||
[ActorReference] public readonly string OnEnter = null;
|
||||
[ActorReference] public readonly string OnExit = null;
|
||||
public readonly bool SkipMakeAnims = false;
|
||||
public readonly bool BecomeNeutral = false;
|
||||
|
||||
public object Create(ActorInitializer init) { return new TransformOnPassenger(this); }
|
||||
}
|
||||
|
||||
public class TransformOnPassenger : INotifyPassengerEntered, INotifyPassengerExited
|
||||
{
|
||||
TransformOnPassengerInfo info;
|
||||
|
||||
public TransformOnPassenger(TransformOnPassengerInfo info) { this.info = info; }
|
||||
|
||||
void MaybeTransform(Actor self, Actor passenger, string transformTo)
|
||||
{
|
||||
if (info.PassengerTypes.Contains(passenger.Info.Name) && transformTo != null)
|
||||
{
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
var facing = self.TraitOrDefault<IFacing>();
|
||||
var transform = new Transform(self, transformTo) { SkipMakeAnims = info.SkipMakeAnims };
|
||||
if (facing != null) transform.Facing = facing.Facing;
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(transform);
|
||||
if (info.BecomeNeutral) self.ChangeOwner(self.World.WorldActor.Owner);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void PassengerEntered(Actor self, Actor passenger) { MaybeTransform(self, passenger, info.OnEnter); }
|
||||
public void PassengerExited(Actor self, Actor passenger) { MaybeTransform(self, passenger, info.OnExit); }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user