Move Render*Circle, ThrowsParticle and ParatroopersPower to appropriate locations
This commit is contained in:
@@ -263,12 +263,15 @@
|
||||
<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\WithBuildingPlacedAnimation.cs" />
|
||||
<Compile Include="Traits\Render\WithMakeAnimation.cs" />
|
||||
<Compile Include="Traits\Render\WithCrateBody.cs" />
|
||||
<Compile Include="Traits\Render\WithDeathAnimation.cs" />
|
||||
<Compile Include="Traits\Render\WithHarvestAnimation.cs" />
|
||||
<Compile Include="Traits\Render\WithMuzzleFlash.cs" />
|
||||
<Compile Include="Traits\Render\WithRangeCircle.cs" />
|
||||
<Compile Include="Traits\Render\WithResources.cs" />
|
||||
<Compile Include="Traits\Render\WithRotor.cs" />
|
||||
<Compile Include="Traits\Render\WithShadow.cs" />
|
||||
@@ -286,6 +289,7 @@
|
||||
<Compile Include="Traits\Sound\DeathSounds.cs" />
|
||||
<Compile Include="Traits\Sound\SoundOnDamageTransition.cs" />
|
||||
<Compile Include="Traits\TargetableUnit.cs" />
|
||||
<Compile Include="Traits\ThrowsParticle.cs" />
|
||||
<Compile Include="Traits\Tooltip.cs" />
|
||||
<Compile Include="Traits\Turreted.cs" />
|
||||
<Compile Include="Traits\Upgrades\UpgradableTrait.cs" />
|
||||
|
||||
43
OpenRA.Mods.Common/Traits/Render/RenderDetectionCircle.cs
Normal file
43
OpenRA.Mods.Common/Traits/Render/RenderDetectionCircle.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
#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 System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
class RenderDetectionCircleInfo : ITraitInfo
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new RenderDetectionCircle(init.Self); }
|
||||
}
|
||||
|
||||
class RenderDetectionCircle : IPostRenderSelection
|
||||
{
|
||||
Actor self;
|
||||
|
||||
public RenderDetectionCircle(Actor self) { this.self = self; }
|
||||
|
||||
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr)
|
||||
{
|
||||
if (self.Owner != self.World.LocalPlayer)
|
||||
yield break;
|
||||
|
||||
yield return new RangeCircleRenderable(
|
||||
self.CenterPosition,
|
||||
WRange.FromCells(self.Info.Traits.Get<DetectCloakedInfo>().Range),
|
||||
0,
|
||||
Color.FromArgb(128, Color.LimeGreen),
|
||||
Color.FromArgb(96, Color.Black));
|
||||
}
|
||||
}
|
||||
}
|
||||
80
OpenRA.Mods.Common/Traits/Render/RenderRangeCircle.cs
Normal file
80
OpenRA.Mods.Common/Traits/Render/RenderRangeCircle.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
#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 System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Draw a circle indicating my weapon's range.")]
|
||||
class RenderRangeCircleInfo : ITraitInfo, IPlaceBuildingDecoration, Requires<AttackBaseInfo>
|
||||
{
|
||||
public readonly string RangeCircleType = null;
|
||||
|
||||
[Desc("Range to draw if no armaments are available")]
|
||||
public readonly WRange FallbackRange = WRange.Zero;
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
|
||||
{
|
||||
var armaments = ai.Traits.WithInterface<ArmamentInfo>();
|
||||
var range = FallbackRange;
|
||||
|
||||
if (armaments.Any())
|
||||
range = armaments.Select(a => w.Map.Rules.Weapons[a.Weapon.ToLowerInvariant()].Range).Max();
|
||||
|
||||
if (range == WRange.Zero)
|
||||
yield break;
|
||||
|
||||
yield return new RangeCircleRenderable(
|
||||
centerPosition,
|
||||
range,
|
||||
0,
|
||||
Color.FromArgb(128, Color.Yellow),
|
||||
Color.FromArgb(96, Color.Black));
|
||||
|
||||
foreach (var a in w.ActorsWithTrait<RenderRangeCircle>())
|
||||
if (a.Actor.Owner == a.Actor.World.LocalPlayer)
|
||||
if (a.Actor.Info.Traits.Get<RenderRangeCircleInfo>().RangeCircleType == RangeCircleType)
|
||||
foreach (var r in a.Trait.RenderAfterWorld(wr))
|
||||
yield return r;
|
||||
}
|
||||
|
||||
public object Create(ActorInitializer init) { return new RenderRangeCircle(init.Self); }
|
||||
}
|
||||
|
||||
class RenderRangeCircle : IPostRenderSelection
|
||||
{
|
||||
Actor self;
|
||||
AttackBase attack;
|
||||
|
||||
public RenderRangeCircle(Actor self)
|
||||
{
|
||||
this.self = self;
|
||||
attack = self.Trait<AttackBase>();
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr)
|
||||
{
|
||||
if (self.Owner != self.World.LocalPlayer)
|
||||
yield break;
|
||||
|
||||
yield return new RangeCircleRenderable(
|
||||
self.CenterPosition,
|
||||
attack.GetMaximumRange(),
|
||||
0,
|
||||
Color.FromArgb(128, Color.Yellow),
|
||||
Color.FromArgb(96, Color.Black));
|
||||
}
|
||||
}
|
||||
}
|
||||
73
OpenRA.Mods.Common/Traits/Render/WithRangeCircle.cs
Normal file
73
OpenRA.Mods.Common/Traits/Render/WithRangeCircle.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
#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 System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Renders an arbitrary circle when selected or placing a structure")]
|
||||
class WithRangeCircleInfo : ITraitInfo, IPlaceBuildingDecoration
|
||||
{
|
||||
[Desc("Type of range circle. used to decide which circles to draw on other structures during building placement.")]
|
||||
public readonly string Type = null;
|
||||
|
||||
[Desc("Color of the circle")]
|
||||
public readonly Color Color = Color.FromArgb(128, Color.White);
|
||||
|
||||
[Desc("Range of the circle")]
|
||||
public readonly WRange Range = WRange.Zero;
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
|
||||
{
|
||||
yield return new RangeCircleRenderable(
|
||||
centerPosition,
|
||||
Range,
|
||||
0,
|
||||
Color,
|
||||
Color.FromArgb(96, Color.Black));
|
||||
|
||||
foreach (var a in w.ActorsWithTrait<WithRangeCircle>())
|
||||
if (a.Actor.Owner == a.Actor.World.LocalPlayer && a.Trait.Info.Type == Type)
|
||||
foreach (var r in a.Trait.RenderAfterWorld(wr))
|
||||
yield return r;
|
||||
}
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithRangeCircle(init.Self, this); }
|
||||
}
|
||||
|
||||
class WithRangeCircle : IPostRenderSelection
|
||||
{
|
||||
public readonly WithRangeCircleInfo Info;
|
||||
readonly Actor self;
|
||||
|
||||
public WithRangeCircle(Actor self, WithRangeCircleInfo info)
|
||||
{
|
||||
this.self = self;
|
||||
Info = info;
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr)
|
||||
{
|
||||
if (self.Owner != self.World.LocalPlayer)
|
||||
yield break;
|
||||
|
||||
yield return new RangeCircleRenderable(
|
||||
self.CenterPosition,
|
||||
Info.Range,
|
||||
0,
|
||||
Info.Color,
|
||||
Color.FromArgb(96, Color.Black));
|
||||
}
|
||||
}
|
||||
}
|
||||
96
OpenRA.Mods.Common/Traits/ThrowsParticle.cs
Normal file
96
OpenRA.Mods.Common/Traits/ThrowsParticle.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
#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 OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
class ThrowsParticleInfo : ITraitInfo, Requires<RenderSimpleInfo>, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
public readonly string Anim = null;
|
||||
|
||||
[Desc("Initial position relative to body")]
|
||||
public readonly WVec Offset = WVec.Zero;
|
||||
|
||||
[Desc("Minimum distance to throw the particle")]
|
||||
public readonly WRange MinThrowRange = new WRange(256);
|
||||
|
||||
[Desc("Maximum distance to throw the particle")]
|
||||
public readonly WRange MaxThrowRange = new WRange(768);
|
||||
|
||||
[Desc("Minimum angle to throw the particle")]
|
||||
public readonly WAngle MinThrowAngle = WAngle.FromDegrees(30);
|
||||
|
||||
[Desc("Maximum angle to throw the particle")]
|
||||
public readonly WAngle MaxThrowAngle = WAngle.FromDegrees(60);
|
||||
|
||||
[Desc("Speed to throw the particle (horizontal WPos/tick)")]
|
||||
public readonly int Velocity = 75;
|
||||
|
||||
[Desc("Maximum rotation rate")]
|
||||
public readonly float ROT = 15;
|
||||
|
||||
public object Create(ActorInitializer init) { return new ThrowsParticle(init, this); }
|
||||
}
|
||||
|
||||
class ThrowsParticle : ITick
|
||||
{
|
||||
WVec pos;
|
||||
WVec initialPos;
|
||||
WVec finalPos;
|
||||
WAngle angle;
|
||||
|
||||
int tick = 0;
|
||||
int length;
|
||||
|
||||
float facing;
|
||||
float rotation;
|
||||
|
||||
public ThrowsParticle(ActorInitializer init, ThrowsParticleInfo info)
|
||||
{
|
||||
var self = init.Self;
|
||||
var rs = self.Trait<RenderSimple>();
|
||||
var body = self.Trait<IBodyOrientation>();
|
||||
|
||||
// TODO: Carry orientation over from the parent instead of just facing
|
||||
var bodyFacing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 0;
|
||||
facing = Turreted.GetInitialTurretFacing(init, 0);
|
||||
|
||||
// Calculate final position
|
||||
var throwRotation = WRot.FromFacing(Game.CosmeticRandom.Next(1024));
|
||||
var throwDistance = Game.CosmeticRandom.Next(info.MinThrowRange.Range, info.MaxThrowRange.Range);
|
||||
|
||||
initialPos = pos = info.Offset.Rotate(body.QuantizeOrientation(self, WRot.FromFacing(bodyFacing)));
|
||||
finalPos = initialPos + new WVec(throwDistance, 0, 0).Rotate(throwRotation);
|
||||
angle = new WAngle(Game.CosmeticRandom.Next(info.MinThrowAngle.Angle, info.MaxThrowAngle.Angle));
|
||||
length = (finalPos - initialPos).Length / info.Velocity;
|
||||
|
||||
// Facing rotation
|
||||
rotation = WRange.FromPDF(Game.CosmeticRandom, 2).Range * info.ROT / 1024;
|
||||
|
||||
var anim = new Animation(init.World, rs.GetImage(self), () => (int)facing);
|
||||
anim.PlayRepeating(info.Anim);
|
||||
rs.Add(info.Anim, new AnimationWithOffset(anim, () => pos, null));
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (tick == length)
|
||||
return;
|
||||
|
||||
pos = WVec.LerpQuadratic(initialPos, finalPos, angle, tick++, length);
|
||||
|
||||
// Spin the particle
|
||||
facing += rotation;
|
||||
rotation *= .9f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user