Merge pull request #7570 from Mailaender/mods-common

Moved more traits to Mods.Common
This commit is contained in:
reaperrr
2015-03-15 19:53:13 +01:00
22 changed files with 172 additions and 150 deletions

View File

@@ -0,0 +1,40 @@
#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.Traits;
namespace OpenRA.Mods.Common.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)));
}
}
}

View File

@@ -95,6 +95,7 @@
<Compile Include="Activities\CaptureActor.cs" />
<Compile Include="Activities\DeliverResources.cs" />
<Compile Include="Activities\Demolish.cs" />
<Compile Include="Activities\DonateSupplies.cs" />
<Compile Include="Activities\Enter.cs" />
<Compile Include="Activities\EnterTransport.cs" />
<Compile Include="Activities\ExternalCaptureActor.cs" />
@@ -200,24 +201,27 @@
<Compile Include="Scripting\Global\ReinforcementsGlobal.cs" />
<Compile Include="Scripting\Global\TriggerGlobal.cs" />
<Compile Include="Scripting\Global\UtilsGlobal.cs" />
<Compile Include="Scripting\Properties\DiplomacyProperties.cs" />
<Compile Include="Scripting\Properties\HealthProperties.cs" />
<Compile Include="Scripting\Properties\PowerProperties.cs" />
<Compile Include="Scripting\Properties\ResourceProperties.cs" />
<Compile Include="Scripting\Properties\UpgradeProperties.cs" />
<Compile Include="Scripting\Properties\AirstrikeProperties.cs" />
<Compile Include="Scripting\Properties\ProductionProperties.cs" />
<Compile Include="Scripting\Properties\CombatProperties.cs" />
<Compile Include="Scripting\Properties\DiplomacyProperties.cs" />
<Compile Include="Scripting\Properties\HarvesterProperties.cs" />
<Compile Include="Scripting\Properties\HealthProperties.cs" />
<Compile Include="Scripting\Properties\HelicopterProperties.cs" />
<Compile Include="Scripting\Properties\GeneralProperties.cs" />
<Compile Include="Scripting\Properties\GuardProperties.cs" />
<Compile Include="Scripting\Properties\MissionObjectiveProperties.cs" />
<Compile Include="Scripting\Properties\MobileProperties.cs" />
<Compile Include="Scripting\Properties\GeneralProperties.cs" />
<Compile Include="Scripting\Properties\CombatProperties.cs" />
<Compile Include="Scripting\Properties\PlayerProperties.cs" />
<Compile Include="Scripting\Properties\HelicopterProperties.cs" />
<Compile Include="Scripting\Properties\PlaneProperties.cs" />
<Compile Include="Scripting\Properties\TransformProperties.cs" />
<Compile Include="Scripting\Properties\PlayerProperties.cs" />
<Compile Include="Scripting\Properties\PowerProperties.cs" />
<Compile Include="Scripting\Properties\ProductionProperties.cs" />
<Compile Include="Scripting\Properties\RepairableBuildingProperties.cs" />
<Compile Include="Scripting\Properties\GuardProperties.cs" />
<Compile Include="Scripting\Properties\ResourceProperties.cs" />
<Compile Include="Scripting\Properties\TransformProperties.cs" />
<Compile Include="Scripting\Properties\TransportProperties.cs" />
<Compile Include="Scripting\Properties\UpgradeProperties.cs" />
<Compile Include="TraitsInterfaces.cs" />
<Compile Include="Traits\AcceptsSupplies.cs" />
<Compile Include="Traits\Air\Aircraft.cs" />
<Compile Include="Traits\Air\AttackBomber.cs" />
<Compile Include="Traits\Air\AttackHeli.cs" />
@@ -235,6 +239,7 @@
<Compile Include="Traits\Attack\AttackCharge.cs" />
<Compile Include="Traits\Attack\AttackFollow.cs" />
<Compile Include="Traits\Attack\AttackFrontal.cs" />
<Compile Include="Traits\Attack\AttackGarrisoned.cs" />
<Compile Include="Traits\Attack\AttackMedic.cs" />
<Compile Include="Traits\Attack\AttackOmni.cs" />
<Compile Include="Traits\Attack\AttackTurreted.cs" />
@@ -271,6 +276,7 @@
<Compile Include="Traits\Cargo.cs" />
<Compile Include="Traits\CashTrickler.cs" />
<Compile Include="Traits\Cloak.cs" />
<Compile Include="Traits\CombatDebugOverlay.cs" />
<Compile Include="Traits\Crates\Crate.cs" />
<Compile Include="Traits\Crates\CrateAction.cs" />
<Compile Include="Traits\Crates\DuplicateUnitCrateAction.cs" />
@@ -285,32 +291,33 @@
<Compile Include="Traits\Crates\RevealMapCrateAction.cs" />
<Compile Include="Traits\Crates\SupportPowerCrateAction.cs" />
<Compile Include="Traits\Crushable.cs" />
<Compile Include="Traits\EmitInfantryOnSell.cs" />
<Compile Include="Traits\ExternalCapturable.cs" />
<Compile Include="Traits\ExternalCapturableBar.cs" />
<Compile Include="Traits\ExternalCaptures.cs" />
<Compile Include="Traits\Harvester.cs" />
<Compile Include="Traits\IgnoresCloak.cs" />
<Compile Include="Traits\IgnoresDisguise.cs" />
<Compile Include="Traits\DetectCloaked.cs" />
<Compile Include="Traits\EngineerRepair.cs" />
<Compile Include="Traits\Explodes.cs" />
<Compile Include="Traits\Guard.cs" />
<Compile Include="Traits\Guardable.cs" />
<Compile Include="Traits\GainsExperience.cs" />
<Compile Include="Traits\GivesBounty.cs" />
<Compile Include="Traits\GivesExperience.cs" />
<Compile Include="Traits\Huntable.cs" />
<Compile Include="Traits\CustomBuildTimeValue.cs" />
<Compile Include="Traits\CustomSellValue.cs" />
<Compile Include="Traits\Demolishable.cs" />
<Compile Include="Traits\DetectCloaked.cs" />
<Compile Include="Traits\EjectOnDeath.cs" />
<Compile Include="Traits\EmitInfantryOnSell.cs" />
<Compile Include="Traits\EngineerRepair.cs" />
<Compile Include="Traits\Explodes.cs" />
<Compile Include="Traits\ExternalCapturable.cs" />
<Compile Include="Traits\ExternalCapturableBar.cs" />
<Compile Include="Traits\ExternalCaptures.cs" />
<Compile Include="Traits\GainsExperience.cs" />
<Compile Include="Traits\GivesBounty.cs" />
<Compile Include="Traits\GivesExperience.cs" />
<Compile Include="Traits\GlobalUpgradable.cs" />
<Compile Include="Traits\Guard.cs" />
<Compile Include="Traits\Guardable.cs" />
<Compile Include="Traits\Harvester.cs" />
<Compile Include="Traits\Husk.cs" />
<Compile Include="Traits\Huntable.cs" />
<Compile Include="Traits\IgnoresCloak.cs" />
<Compile Include="Traits\IgnoresDisguise.cs" />
<Compile Include="Traits\Immobile.cs" />
<Compile Include="Traits\Infantry\ScaredyCat.cs" />
<Compile Include="Traits\Infantry\TakeCover.cs" />
<Compile Include="Traits\Invulnerable.cs" />
<Compile Include="Traits\Infantry\TerrainModifiesDamage.cs" />
<Compile Include="Traits\Invulnerable.cs" />
<Compile Include="Traits\JamsMissiles.cs" />
<Compile Include="Traits\KillsSelf.cs" />
<Compile Include="Traits\LimitedAmmo.cs" />
@@ -368,18 +375,18 @@
<Compile Include="Traits\Render\RenderHarvester.cs" />
<Compile Include="Traits\Render\RenderInfantry.cs" />
<Compile Include="Traits\Render\RenderNameTag.cs" />
<Compile Include="Traits\Render\ProductionBar.cs" />
<Compile Include="Traits\Render\RenderSimple.cs" />
<Compile Include="Traits\Render\RenderSprites.cs" />
<Compile Include="Traits\Render\RenderUnit.cs" />
<Compile Include="Traits\Render\SupportPowerChargeBar.cs" />
<Compile Include="Traits\Render\TimedUpgradeBar.cs" />
<Compile Include="Traits\Render\WithBarrel.cs" />
<Compile Include="Traits\Render\WithBuildingExplosion.cs" />
<Compile Include="Traits\Render\RenderBuildingSilo.cs" />
<Compile Include="Traits\Render\RenderBuildingWall.cs" />
<Compile Include="Traits\Render\RenderDetectionCircle.cs" />
<Compile Include="Traits\Render\RenderRangeCircle.cs" />
<Compile Include="Traits\Render\ProductionBar.cs" />
<Compile Include="Traits\Render\SupportPowerChargeBar.cs" />
<Compile Include="Traits\Render\TimedUpgradeBar.cs" />
<Compile Include="Traits\Render\WithBarrel.cs" />
<Compile Include="Traits\Render\WithBuildingExplosion.cs" />
<Compile Include="Traits\Render\WithActiveAnimation.cs" />
<Compile Include="Traits\Render\WithBuildingPlacedAnimation.cs" />
<Compile Include="Traits\Render\WithMakeAnimation.cs" />
@@ -396,6 +403,9 @@
<Compile Include="Traits\Render\WithShadow.cs" />
<Compile Include="Traits\Render\WithSmoke.cs" />
<Compile Include="Traits\Render\WithTurret.cs" />
<Compile Include="Traits\Render\WithFire.cs" />
<Compile Include="Traits\Render\WithBuildingPlacedOverlay.cs" />
<Compile Include="Traits\Render\WithProductionOverlay.cs" />
<Compile Include="Traits\Repairable.cs" />
<Compile Include="Traits\RepairableNear.cs" />
<Compile Include="Traits\RepairsBridges.cs" />
@@ -411,6 +421,7 @@
<Compile Include="Traits\Sound\AnnounceOnSeen.cs" />
<Compile Include="Traits\Sound\DeathSounds.cs" />
<Compile Include="Traits\Sound\SoundOnDamageTransition.cs" />
<Compile Include="Traits\SupplyTruck.cs" />
<Compile Include="Traits\SupportPowers\AirstrikePower.cs" />
<Compile Include="Traits\SupportPowers\GrantUpgradePower.cs" />
<Compile Include="Traits\SupportPowers\NukePower.cs" />
@@ -421,6 +432,7 @@
<Compile Include="Traits\ThrowsParticle.cs" />
<Compile Include="Traits\Tooltip.cs" />
<Compile Include="Traits\TransformOnCapture.cs" />
<Compile Include="Traits\TransformOnPassenger.cs" />
<Compile Include="Traits\Transforms.cs" />
<Compile Include="Traits\Turreted.cs" />
<Compile Include="Traits\Upgrades\DisableUpgrade.cs" />
@@ -462,6 +474,8 @@
<Compile Include="Traits\World\StartGameNotification.cs" />
<Compile Include="Traits\World\TerrainGeometryOverlay.cs" />
<Compile Include="UtilityCommands\ActorStatsExport.cs" />
<Compile Include="UtilityCommands\CheckYaml.cs" />
<Compile Include="UtilityCommands\CheckCodeStyle.cs" />
<Compile Include="UtilityCommands\ConvertPngToShpCommand.cs" />
<Compile Include="UtilityCommands\ConvertSpriteToPngCommand.cs" />
<Compile Include="UtilityCommands\ExportCharacterSeparatedRules.cs" />
@@ -476,6 +490,7 @@
<Compile Include="UtilityCommands\ImportLegacyMapCommand.cs" />
<Compile Include="UtilityCommands\LegacyMapImporter.cs" />
<Compile Include="UtilityCommands\RemapShpCommand.cs" />
<Compile Include="UtilityCommands\ReplayMetadataCommand.cs" />
<Compile Include="UtilityCommands\UpgradeMapCommand.cs" />
<Compile Include="UtilityCommands\UpgradeModCommand.cs" />
<Compile Include="UtilityCommands\UpgradeRules.cs" />
@@ -572,9 +587,6 @@
<Compile Include="SpriteLoaders\ShpD2Loader.cs" />
<Compile Include="LoadScreens\LogoStripeLoadScreen.cs" />
<Compile Include="LoadScreens\BlankLoadScreen.cs" />
<Compile Include="UtilityCommands\CheckYaml.cs" />
<Compile Include="UtilityCommands\CheckCodeStyle.cs" />
<Compile Include="UtilityCommands\ReplayMetadataCommand.cs" />
<Compile Include="Widgets\Logic\ReplayUtils.cs" />
<Compile Include="InstallUtils.cs" />
<Compile Include="Graphics\DefaultSpriteSequence.cs" />

View File

@@ -0,0 +1,35 @@
#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.Common.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);
}
}
}

View File

@@ -0,0 +1,46 @@
#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.Scripting;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.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));
}
}
}

View File

@@ -0,0 +1,19 @@
#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.Common.Traits
{
[Desc("Tag trait for `SupplyTruck` actors.")]
class AcceptsSuppliesInfo : TraitInfo<AcceptsSupplies> { }
class AcceptsSupplies { }
}

View File

@@ -0,0 +1,195 @@
#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.Traits;
namespace OpenRA.Mods.Common.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();
}
}
}

View File

@@ -0,0 +1,108 @@
#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.Traits;
namespace OpenRA.Mods.Common.Traits
{
[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
{
readonly DeveloperMode devMode;
Lazy<AttackBase> attack;
Lazy<IBodyOrientation> coords;
Lazy<Health> health;
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)));
}
}
}

View File

@@ -0,0 +1,75 @@
#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.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.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);
}
}
}

View File

@@ -0,0 +1,84 @@
#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.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Rendered when the actor constructed a building.")]
public class WithBuildingPlacedOverlayInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
{
[Desc("Sequence name to use")]
public readonly string Sequence = "crane-overlay";
[Desc("Position relative to body")]
public readonly WVec Offset = WVec.Zero;
[Desc("Custom palette name")]
public readonly string Palette = null;
[Desc("Custom palette is a player palette BaseName")]
public readonly bool IsPlayerPalette = false;
public object Create(ActorInitializer init) { return new WithBuildingPlacedOverlay(init.Self, this); }
}
public class WithBuildingPlacedOverlay : INotifyBuildComplete, INotifySold, INotifyDamageStateChanged, INotifyBuildingPlaced, INotifyTransform
{
Animation overlay;
bool buildComplete;
public WithBuildingPlacedOverlay(Actor self, WithBuildingPlacedOverlayInfo info)
{
var rs = self.Trait<RenderSprites>();
var body = self.Trait<IBodyOrientation>();
buildComplete = !self.HasTrait<Building>(); // always render instantly for units
overlay = new Animation(self.World, rs.GetImage(self));
overlay.Play(info.Sequence);
rs.Add("crane_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !buildComplete),
info.Palette, info.IsPlayerPalette);
}
public void BuildingComplete(Actor self)
{
buildComplete = true;
}
public void Sold(Actor self) { }
public void Selling(Actor self)
{
buildComplete = false;
}
public void BeforeTransform(Actor self)
{
buildComplete = false;
}
public void OnTransform(Actor self) { }
public void AfterTransform(Actor self) { }
public void DamageStateChanged(Actor self, AttackInfo e)
{
overlay.ReplaceAnim(RenderSprites.NormalizeSequence(overlay, e.DamageState, overlay.CurrentSequence.Name));
}
public void BuildingPlaced(Actor self)
{
overlay.Play(overlay.CurrentSequence.Name);
}
}
}

View File

@@ -0,0 +1,35 @@
#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.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Renders a flame sprite on top of the actor.")]
class WithFireInfo : ITraitInfo, Requires<RenderSpritesInfo>
{
public readonly string StartSequence = "fire-start";
public readonly string LoopSequence = "fire-loop";
public object Create(ActorInitializer init) { return new WithFire(init.Self, this); }
}
class WithFire
{
public WithFire(Actor self, WithFireInfo info)
{
var rs = self.Trait<RenderSprites>();
var fire = new Animation(self.World, rs.GetImage(self));
fire.PlayThen(info.StartSequence, () => fire.PlayRepeating(info.LoopSequence));
rs.Add("fire", new AnimationWithOffset(fire, null, null, 1024));
}
}
}

View File

@@ -0,0 +1,101 @@
#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.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Renders an animation when the Production trait of the actor is activated.",
"Works both with per player ClassicProductionQueue and per building ProductionQueue, but needs any of these.")]
public class WithProductionOverlayInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
{
[Desc("Sequence name to use")]
public readonly string Sequence = "production-overlay";
[Desc("Position relative to body")]
public readonly WVec Offset = WVec.Zero;
[Desc("Custom palette name")]
public readonly string Palette = null;
[Desc("Custom palette is a player palette BaseName")]
public readonly bool IsPlayerPalette = false;
public object Create(ActorInitializer init) { return new WithProductionOverlay(init.Self, this); }
}
public class WithProductionOverlay : INotifyDamageStateChanged, ITick, INotifyBuildComplete, INotifySold
{
Animation overlay;
ProductionQueue queue;
bool buildComplete;
bool IsProducing
{
get { return queue != null && queue.CurrentItem() != null && !queue.CurrentPaused; }
}
public WithProductionOverlay(Actor self, WithProductionOverlayInfo info)
{
var rs = self.Trait<RenderSprites>();
var body = self.Trait<IBodyOrientation>();
buildComplete = !self.HasTrait<Building>(); // always render instantly for units
overlay = new Animation(self.World, rs.GetImage(self));
overlay.PlayRepeating(info.Sequence);
rs.Add("production_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !IsProducing || !buildComplete),
info.Palette, info.IsPlayerPalette);
}
public void Tick(Actor self)
{
// search for the queue here once so we don't rely on order of trait initialization
if (queue == null)
{
var production = self.TraitOrDefault<Production>();
var perBuildingQueues = self.TraitsImplementing<ProductionQueue>();
queue = perBuildingQueues.FirstOrDefault(q => q.Enabled && production.Info.Produces.Contains(q.Info.Type));
if (queue == null)
{
var perPlayerQueues = self.Owner.PlayerActor.TraitsImplementing<ProductionQueue>();
queue = perPlayerQueues.FirstOrDefault(q => q.Enabled && production.Info.Produces.Contains(q.Info.Type));
}
if (queue == null)
throw new InvalidOperationException("Can't find production queues.");
}
}
public void BuildingComplete(Actor self)
{
buildComplete = true;
}
public void Sold(Actor self) { }
public void Selling(Actor self)
{
buildComplete = false;
}
public void DamageStateChanged(Actor self, AttackInfo e)
{
overlay.ReplaceAnim(RenderSprites.NormalizeSequence(overlay, e.DamageState, overlay.CurrentSequence.Name));
}
}
}

View File

@@ -0,0 +1,91 @@
#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.Activities;
using OpenRA.Mods.Common.Orders;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Donate money to actors with the `AcceptSupplies` trait.")]
class SupplyTruckInfo : ITraitInfo
{
[Desc("The amount of cash the owner recieves.")]
public readonly int Payload = 500;
public object Create(ActorInitializer init) { return new SupplyTruck(this); }
}
class SupplyTruck : IIssueOrder, IResolveOrder, IOrderVoice
{
readonly 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>();
}
}
}
}

View File

@@ -0,0 +1,54 @@
#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.Traits;
namespace OpenRA.Mods.Common.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
{
readonly 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); }
}
}