Initial commit: OpenRA game engine
Fork from OpenRA/OpenRA with one-click launch script (start-ra.cmd) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
227
OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs
Normal file
227
OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs
Normal file
@@ -0,0 +1,227 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Support power that spawns a group of aircraft and orders them to deliver an airstrike.")]
|
||||
public class AirstrikePowerInfo : DirectionalSupportPowerInfo
|
||||
{
|
||||
[ActorReference(typeof(AircraftInfo))]
|
||||
[Desc("Aircraft used to deliver the airstrike.")]
|
||||
public readonly string UnitType = "badr.bomber";
|
||||
|
||||
[Desc("Number of aircraft to use in an airstrike formation.")]
|
||||
public readonly int SquadSize = 1;
|
||||
|
||||
[Desc("Offset vector between the aircraft in a formation.")]
|
||||
public readonly WVec SquadOffset = new(-1536, 1536, 0);
|
||||
|
||||
[Desc("Number of different possible facings of the aircraft (used only for choosing a random direction to spawn from.)")]
|
||||
public readonly int QuantizedFacings = 32;
|
||||
|
||||
[Desc("Additional distance from the map edge to spawn the aircraft.")]
|
||||
public readonly WDist Cordon = new(5120);
|
||||
|
||||
[ActorReference]
|
||||
[Desc("Actor to spawn when the aircraft start attacking.")]
|
||||
public readonly string CameraActor = null;
|
||||
|
||||
[Desc("Amount of time to keep the camera alive after the aircraft have finished attacking.")]
|
||||
public readonly int CameraRemoveDelay = 25;
|
||||
|
||||
[Desc("Weapon range offset to apply during the beacon clock calculation.")]
|
||||
public readonly WDist BeaconDistanceOffset = WDist.FromCells(6);
|
||||
|
||||
public override object Create(ActorInitializer init) { return new AirstrikePower(init.Self, this); }
|
||||
}
|
||||
|
||||
public class AirstrikePower : DirectionalSupportPower
|
||||
{
|
||||
readonly AirstrikePowerInfo info;
|
||||
|
||||
public AirstrikePower(Actor self, AirstrikePowerInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public override void Activate(Actor self, Order order, SupportPowerManager manager)
|
||||
{
|
||||
base.Activate(self, order, manager);
|
||||
|
||||
var facing = info.UseDirectionalTarget && order.ExtraData != uint.MaxValue ? (WAngle?)WAngle.FromFacing((int)order.ExtraData) : null;
|
||||
SendAirstrike(self, order.Target.CenterPosition, facing);
|
||||
}
|
||||
|
||||
public Actor[] SendAirstrike(Actor self, WPos target, WAngle? facing = null)
|
||||
{
|
||||
var aircraft = new List<Actor>();
|
||||
if (!facing.HasValue)
|
||||
facing = new WAngle(1024 * self.World.SharedRandom.Next(info.QuantizedFacings) / info.QuantizedFacings);
|
||||
|
||||
var altitude = self.World.Map.Rules.Actors[info.UnitType].TraitInfo<AircraftInfo>().CruiseAltitude.Length;
|
||||
var attackRotation = WRot.FromYaw(facing.Value);
|
||||
var delta = new WVec(0, -1024, 0).Rotate(attackRotation);
|
||||
target += new WVec(0, 0, altitude);
|
||||
var startEdge = target - (self.World.Map.DistanceToEdge(target, -delta) + info.Cordon).Length * delta / 1024;
|
||||
var finishEdge = target + (self.World.Map.DistanceToEdge(target, delta) + info.Cordon).Length * delta / 1024;
|
||||
|
||||
Actor camera = null;
|
||||
Beacon beacon = null;
|
||||
var aircraftInRange = new Dictionary<Actor, bool>();
|
||||
|
||||
void OnEnterRange(Actor a)
|
||||
{
|
||||
// Spawn a camera and remove the beacon when the first plane enters the target area
|
||||
if (info.CameraActor != null && camera == null && !aircraftInRange.Any(kv => kv.Value))
|
||||
{
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
camera = w.CreateActor(info.CameraActor,
|
||||
[
|
||||
new LocationInit(self.World.Map.CellContaining(target)),
|
||||
new OwnerInit(self.Owner),
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
RemoveBeacon(beacon);
|
||||
|
||||
aircraftInRange[a] = true;
|
||||
}
|
||||
|
||||
void OnExitRange(Actor a)
|
||||
{
|
||||
aircraftInRange[a] = false;
|
||||
|
||||
// Remove the camera when the final plane leaves the target area
|
||||
if (!aircraftInRange.Any(kv => kv.Value))
|
||||
RemoveCamera(camera);
|
||||
}
|
||||
|
||||
void OnRemovedFromWorld(Actor a)
|
||||
{
|
||||
aircraftInRange[a] = false;
|
||||
|
||||
// Checking for attack range is not relevant here because
|
||||
// aircraft may be shot down before entering the range.
|
||||
// If at the map's edge, they may be removed from world before leaving.
|
||||
if (aircraftInRange.All(kv => !kv.Key.IsInWorld))
|
||||
{
|
||||
RemoveCamera(camera);
|
||||
RemoveBeacon(beacon);
|
||||
}
|
||||
}
|
||||
|
||||
// Create the actors immediately so they can be returned
|
||||
for (var i = -info.SquadSize / 2; i <= info.SquadSize / 2; i++)
|
||||
{
|
||||
// Even-sized squads skip the lead plane
|
||||
if (i == 0 && (info.SquadSize & 1) == 0)
|
||||
continue;
|
||||
|
||||
// Includes the 90 degree rotation between body and world coordinates
|
||||
var so = info.SquadOffset;
|
||||
var spawnOffset = new WVec(i * so.Y, -Math.Abs(i) * so.X, 0).Rotate(attackRotation);
|
||||
var targetOffset = new WVec(i * so.Y, 0, 0).Rotate(attackRotation);
|
||||
var a = self.World.CreateActor(false, info.UnitType,
|
||||
[
|
||||
new CenterPositionInit(startEdge + spawnOffset),
|
||||
new OwnerInit(self.Owner),
|
||||
new FacingInit(facing.Value),
|
||||
]);
|
||||
|
||||
aircraft.Add(a);
|
||||
aircraftInRange.Add(a, false);
|
||||
|
||||
var attack = a.Trait<AttackBomber>();
|
||||
attack.SetTarget(target + targetOffset);
|
||||
attack.OnEnteredAttackRange += OnEnterRange;
|
||||
attack.OnExitedAttackRange += OnExitRange;
|
||||
attack.OnRemovedFromWorld += OnRemovedFromWorld;
|
||||
}
|
||||
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
PlayLaunchSounds();
|
||||
|
||||
var j = 0;
|
||||
Actor distanceTestActor = null;
|
||||
for (var i = -info.SquadSize / 2; i <= info.SquadSize / 2; i++)
|
||||
{
|
||||
// Even-sized squads skip the lead plane
|
||||
if (i == 0 && (info.SquadSize & 1) == 0)
|
||||
continue;
|
||||
|
||||
// Includes the 90 degree rotation between body and world coordinates
|
||||
var so = info.SquadOffset;
|
||||
var spawnOffset = new WVec(i * so.Y, -Math.Abs(i) * so.X, 0).Rotate(attackRotation);
|
||||
|
||||
var a = aircraft[j++];
|
||||
w.Add(a);
|
||||
|
||||
a.QueueActivity(new Fly(a, Target.FromPos(target + spawnOffset)));
|
||||
a.QueueActivity(new Fly(a, Target.FromPos(finishEdge + spawnOffset)));
|
||||
a.QueueActivity(new RemoveSelf());
|
||||
distanceTestActor = a;
|
||||
}
|
||||
|
||||
if (Info.DisplayBeacon)
|
||||
{
|
||||
var distance = (target - startEdge).HorizontalLength;
|
||||
|
||||
beacon = new Beacon(
|
||||
self.Owner,
|
||||
target - new WVec(0, 0, altitude),
|
||||
Info.BeaconPaletteIsPlayerPalette,
|
||||
Info.BeaconPalette,
|
||||
Info.BeaconImage,
|
||||
Info.BeaconPoster,
|
||||
Info.BeaconPosterPalette,
|
||||
Info.BeaconSequence,
|
||||
Info.ArrowSequence,
|
||||
Info.CircleSequence,
|
||||
Info.ClockSequence,
|
||||
() => 1 - ((distanceTestActor.CenterPosition - target).HorizontalLength - info.BeaconDistanceOffset.Length) * 1f / distance,
|
||||
Info.BeaconDelay);
|
||||
|
||||
w.Add(beacon);
|
||||
}
|
||||
});
|
||||
|
||||
return aircraft.ToArray();
|
||||
}
|
||||
|
||||
void RemoveCamera(Actor camera)
|
||||
{
|
||||
if (camera == null)
|
||||
return;
|
||||
|
||||
camera.QueueActivity(new Wait(info.CameraRemoveDelay));
|
||||
camera.QueueActivity(new RemoveSelf());
|
||||
}
|
||||
|
||||
void RemoveBeacon(Beacon beacon)
|
||||
{
|
||||
if (beacon == null)
|
||||
return;
|
||||
|
||||
Self.World.AddFrameEndTask(w => w.Remove(beacon));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Immutable;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public abstract class DirectionalSupportPowerInfo : SupportPowerInfo
|
||||
{
|
||||
[Desc("Enables the player directional targeting")]
|
||||
public readonly bool UseDirectionalTarget = false;
|
||||
|
||||
[SequenceReference(nameof(DirectionArrowAnimation), allowNullImage: true)]
|
||||
public readonly ImmutableArray<string> Arrows = ["arrow-t", "arrow-tl", "arrow-l", "arrow-bl", "arrow-b", "arrow-br", "arrow-r", "arrow-tr"];
|
||||
|
||||
[Desc("Animation used to render the direction arrows.")]
|
||||
public readonly string DirectionArrowAnimation = null;
|
||||
|
||||
[PaletteReference]
|
||||
[Desc("Palette for direction cursor animation.")]
|
||||
public readonly string DirectionArrowPalette = "chrome";
|
||||
}
|
||||
|
||||
public class DirectionalSupportPower : SupportPower
|
||||
{
|
||||
readonly DirectionalSupportPowerInfo info;
|
||||
|
||||
public DirectionalSupportPower(Actor self, DirectionalSupportPowerInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public override void SelectTarget(Actor self, string order, SupportPowerManager manager)
|
||||
{
|
||||
if (info.UseDirectionalTarget)
|
||||
self.World.OrderGenerator = new SelectDirectionalTarget(self.World, order, manager, info);
|
||||
else
|
||||
base.SelectTarget(self, order, manager);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Mods.Common.Traits.Render;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class GrantExternalConditionPowerInfo : SupportPowerInfo
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
[Desc("The condition to apply. Must be included in the target actor's ExternalConditions list.")]
|
||||
public readonly string Condition = null;
|
||||
|
||||
[Desc("Duration of the condition (in ticks). Set to 0 for a permanent condition.")]
|
||||
public readonly int Duration = 0;
|
||||
|
||||
[FieldLoader.Require]
|
||||
[Desc("Size of the footprint of the affected area.")]
|
||||
public readonly CVec Dimensions = CVec.Zero;
|
||||
|
||||
[FieldLoader.Require]
|
||||
[Desc("Actual footprint. Cells marked as x will be affected.")]
|
||||
public readonly string Footprint = string.Empty;
|
||||
|
||||
[Desc("Sound to instantly play at the targeted area.")]
|
||||
public readonly string OnFireSound = null;
|
||||
|
||||
[Desc("Player relationships which condition can be applied to.")]
|
||||
public readonly PlayerRelationship ValidRelationships = PlayerRelationship.Ally;
|
||||
|
||||
[SequenceReference]
|
||||
[Desc("Sequence to play for granting actor when activated.",
|
||||
"This requires the actor to have the WithSpriteBody trait or one of its derivatives.")]
|
||||
public readonly string Sequence = "active";
|
||||
|
||||
public readonly string FootprintImage = "overlay";
|
||||
|
||||
[SequenceReference(nameof(FootprintImage))]
|
||||
public readonly string FootprintSequence = "target-select";
|
||||
|
||||
public override object Create(ActorInitializer init) { return new GrantExternalConditionPower(init.Self, this); }
|
||||
}
|
||||
|
||||
public class GrantExternalConditionPower : SupportPower
|
||||
{
|
||||
readonly GrantExternalConditionPowerInfo info;
|
||||
readonly char[] footprint;
|
||||
|
||||
public GrantExternalConditionPower(Actor self, GrantExternalConditionPowerInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
footprint = info.Footprint.Where(c => !char.IsWhiteSpace(c)).ToArray();
|
||||
}
|
||||
|
||||
public override void SelectTarget(Actor self, string order, SupportPowerManager manager)
|
||||
{
|
||||
self.World.OrderGenerator = new SelectConditionTarget(Self.World, order, manager, this);
|
||||
}
|
||||
|
||||
public override void Activate(Actor self, Order order, SupportPowerManager manager)
|
||||
{
|
||||
base.Activate(self, order, manager);
|
||||
PlayLaunchSounds();
|
||||
|
||||
var wsb = self.TraitOrDefault<WithSpriteBody>();
|
||||
if (wsb != null && wsb.DefaultAnimation.HasSequence(info.Sequence))
|
||||
wsb.PlayCustomAnimation(self, info.Sequence);
|
||||
|
||||
Game.Sound.Play(SoundType.World, info.OnFireSound, order.Target.CenterPosition);
|
||||
|
||||
foreach (var a in UnitsInRange(self.World.Map.CellContaining(order.Target.CenterPosition)))
|
||||
a.TraitsImplementing<ExternalCondition>()
|
||||
.FirstOrDefault(t => t.Info.Condition == info.Condition && t.CanGrantCondition(self))
|
||||
?.GrantCondition(a, self, info.Duration);
|
||||
}
|
||||
|
||||
public IEnumerable<Actor> UnitsInRange(CPos xy)
|
||||
{
|
||||
var tiles = CellsMatching(xy, footprint, info.Dimensions);
|
||||
var units = new HashSet<Actor>();
|
||||
foreach (var t in tiles)
|
||||
foreach (var a in Self.World.ActorMap.GetActorsAt(t))
|
||||
units.Add(a);
|
||||
|
||||
return units.Where(a =>
|
||||
{
|
||||
if (!info.ValidRelationships.HasRelationship(Self.Owner.RelationshipWith(a.Owner)))
|
||||
return false;
|
||||
|
||||
return a.TraitsImplementing<ExternalCondition>()
|
||||
.Any(t => t.Info.Condition == info.Condition && t.CanGrantCondition(Self));
|
||||
});
|
||||
}
|
||||
|
||||
sealed class SelectConditionTarget : OrderGenerator
|
||||
{
|
||||
protected override MouseActionType ActionType => MouseActionType.SupportPower;
|
||||
readonly GrantExternalConditionPower power;
|
||||
readonly char[] footprint;
|
||||
readonly CVec dimensions;
|
||||
readonly Sprite tile;
|
||||
readonly float alpha;
|
||||
readonly SupportPowerManager manager;
|
||||
readonly string order;
|
||||
|
||||
public SelectConditionTarget(World world, string order, SupportPowerManager manager, GrantExternalConditionPower power)
|
||||
: base(world)
|
||||
{
|
||||
this.manager = manager;
|
||||
this.order = order;
|
||||
this.power = power;
|
||||
footprint = power.info.Footprint.Where(c => !char.IsWhiteSpace(c)).ToArray();
|
||||
dimensions = power.info.Dimensions;
|
||||
|
||||
var sequence = world.Map.Sequences.GetSequence(power.info.FootprintImage, power.info.FootprintSequence);
|
||||
tile = sequence.GetSprite(0);
|
||||
alpha = sequence.GetAlpha(0);
|
||||
}
|
||||
|
||||
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
world.CancelInputMode();
|
||||
if (power.UnitsInRange(cell).Any())
|
||||
yield return new Order(order, manager.Self, Target.FromCell(world, cell), false) { SuppressVisualFeedback = true };
|
||||
}
|
||||
|
||||
protected override void Tick(World world)
|
||||
{
|
||||
// Cancel the OG if we can't use the power
|
||||
if (!manager.Powers.TryGetValue(order, out var p) || !p.Active || !p.Ready)
|
||||
world.CancelInputMode();
|
||||
}
|
||||
|
||||
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
||||
|
||||
protected override IEnumerable<IRenderable> RenderAnnotations(WorldRenderer wr, World world)
|
||||
{
|
||||
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
||||
foreach (var unit in power.UnitsInRange(xy))
|
||||
{
|
||||
var decorations = unit.TraitsImplementing<ISelectionDecorations>().FirstEnabledTraitOrDefault();
|
||||
if (decorations != null)
|
||||
foreach (var d in decorations.RenderSelectionAnnotations(unit, wr, Color.Red))
|
||||
yield return d;
|
||||
}
|
||||
}
|
||||
|
||||
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world)
|
||||
{
|
||||
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
||||
var pal = wr.Palette(TileSet.TerrainPaletteInternalName);
|
||||
|
||||
foreach (var t in power.CellsMatching(xy, footprint, dimensions))
|
||||
yield return new SpriteRenderable(tile, wr.World.Map.CenterOfCell(t), WVec.Zero, -511, pal, 1f, alpha, float3.Ones, TintModifiers.IgnoreWorldTint, true);
|
||||
}
|
||||
|
||||
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
return power.UnitsInRange(cell).Any() ? power.info.Cursor : power.info.BlockedCursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
244
OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs
Normal file
244
OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs
Normal file
@@ -0,0 +1,244 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class NukePowerInfo : SupportPowerInfo
|
||||
{
|
||||
[WeaponReference]
|
||||
[FieldLoader.Require]
|
||||
[Desc("Weapon to use for the impact.")]
|
||||
public readonly string MissileWeapon = "";
|
||||
|
||||
[Desc("Delay (in ticks) after launch until the missile is spawned.")]
|
||||
public readonly int MissileDelay = 0;
|
||||
|
||||
[Desc("Image to use for the missile.")]
|
||||
public readonly string MissileImage = null;
|
||||
|
||||
[SequenceReference(nameof(MissileImage))]
|
||||
[Desc("Sprite sequence for the ascending missile.")]
|
||||
public readonly string MissileUp = "up";
|
||||
|
||||
[SequenceReference(nameof(MissileImage))]
|
||||
[Desc("Sprite sequence for the descending missile.")]
|
||||
public readonly string MissileDown = "down";
|
||||
|
||||
[Desc("Offset from the actor the missile spawns on.")]
|
||||
public readonly WVec SpawnOffset = WVec.Zero;
|
||||
|
||||
[Desc("Altitude offset from the target position at which the warhead should detonate.")]
|
||||
public readonly WDist DetonationAltitude = WDist.Zero;
|
||||
|
||||
[Desc("Should nuke missile projectile be removed on detonation above ground.",
|
||||
"'False' will make the missile continue until it hits the ground and disappears (without triggering another explosion).")]
|
||||
public readonly bool RemoveMissileOnDetonation = true;
|
||||
|
||||
[PaletteReference(nameof(IsPlayerPalette))]
|
||||
[Desc("Palette to use for the missile weapon image.")]
|
||||
public readonly string MissilePalette = "effect";
|
||||
|
||||
[Desc("Custom palette is a player palette BaseName.")]
|
||||
public readonly bool IsPlayerPalette = false;
|
||||
|
||||
[Desc("Trail animation.")]
|
||||
public readonly string TrailImage = null;
|
||||
|
||||
[SequenceReference(nameof(TrailImage), allowNullImage: true)]
|
||||
[Desc("Loop a randomly chosen sequence of TrailImage from this list while this projectile is moving.")]
|
||||
public readonly ImmutableArray<string> TrailSequences = [];
|
||||
|
||||
[Desc("Interval in ticks between each spawned Trail animation.")]
|
||||
public readonly int TrailInterval = 1;
|
||||
|
||||
[Desc("Delay in ticks until trail animation is spawned.")]
|
||||
public readonly int TrailDelay = 1;
|
||||
|
||||
[PaletteReference(nameof(TrailUsePlayerPalette))]
|
||||
[Desc("Palette used to render the trail sequence.")]
|
||||
public readonly string TrailPalette = "effect";
|
||||
|
||||
[Desc("Use the Player Palette to render the trail sequence.")]
|
||||
public readonly bool TrailUsePlayerPalette = false;
|
||||
|
||||
[Desc("Travel time - split equally between ascent and descent.")]
|
||||
public readonly int FlightDelay = 400;
|
||||
|
||||
[Desc("Visual ascent velocity in WDist / tick.")]
|
||||
public readonly WDist FlightVelocity = new(512);
|
||||
|
||||
[Desc("Descend immediately on the target.")]
|
||||
public readonly bool SkipAscent = false;
|
||||
|
||||
[Desc("Amount of time before detonation to remove the beacon.")]
|
||||
public readonly int BeaconRemoveAdvance = 25;
|
||||
|
||||
[Desc("Range of cells the camera should reveal around target cell.")]
|
||||
public readonly WDist CameraRange = WDist.Zero;
|
||||
|
||||
[Desc("Can the camera reveal shroud generated by the `" + nameof(CreatesShroud) + "` trait?")]
|
||||
public readonly bool RevealGeneratedShroud = true;
|
||||
|
||||
[Desc("Reveal cells to players with these relationships only.")]
|
||||
public readonly PlayerRelationship CameraRelationships = PlayerRelationship.Ally;
|
||||
|
||||
[Desc("Amount of time before detonation to spawn the camera.")]
|
||||
public readonly int CameraSpawnAdvance = 25;
|
||||
|
||||
[Desc("Amount of time after detonation to remove the camera.")]
|
||||
public readonly int CameraRemoveDelay = 25;
|
||||
|
||||
[Desc("Range circle color.")]
|
||||
public readonly Color CircleColor = Color.FromArgb(128, Color.Red);
|
||||
|
||||
[Desc("Range circle width in pixel.")]
|
||||
public readonly float CircleWidth = 1;
|
||||
|
||||
[Desc("Range circle border color.")]
|
||||
public readonly Color CircleBorderColor = Color.FromArgb(64, Color.Red);
|
||||
|
||||
[Desc("Range circle border width in pixel.")]
|
||||
public readonly float CircleBorderWidth = 3;
|
||||
|
||||
[Desc("Render circles based on these distance ranges while targeting.")]
|
||||
public readonly ImmutableArray<WDist> CircleRanges = default;
|
||||
|
||||
public WeaponInfo WeaponInfo { get; private set; }
|
||||
|
||||
public override object Create(ActorInitializer init) { return new NukePower(init.Self, this); }
|
||||
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(TrailImage) && TrailSequences.Length == 0)
|
||||
throw new YamlException("At least one entry in TrailSequences must be defined when TrailImage is defined.");
|
||||
|
||||
var weaponToLower = (MissileWeapon ?? string.Empty).ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||
throw new YamlException($"Weapons Ruleset does not contain an entry '{weaponToLower}'");
|
||||
|
||||
WeaponInfo = weapon;
|
||||
|
||||
base.RulesetLoaded(rules, ai);
|
||||
}
|
||||
}
|
||||
|
||||
sealed class NukePower : SupportPower
|
||||
{
|
||||
readonly NukePowerInfo info;
|
||||
BodyOrientation body;
|
||||
|
||||
public NukePower(Actor self, NukePowerInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
protected override void Created(Actor self)
|
||||
{
|
||||
body = self.TraitOrDefault<BodyOrientation>();
|
||||
base.Created(self);
|
||||
}
|
||||
|
||||
public override void Activate(Actor self, Order order, SupportPowerManager manager)
|
||||
{
|
||||
base.Activate(self, order, manager);
|
||||
PlayLaunchSounds();
|
||||
|
||||
Activate(self, order.Target.CenterPosition);
|
||||
}
|
||||
|
||||
public void Activate(Actor self, WPos targetPosition)
|
||||
{
|
||||
var palette = info.IsPlayerPalette ? info.MissilePalette + self.Owner.InternalName : info.MissilePalette;
|
||||
var skipAscent = info.SkipAscent || body == null;
|
||||
var launchPos = skipAscent ? WPos.Zero : self.CenterPosition + body.LocalToWorld(info.SpawnOffset);
|
||||
|
||||
var missile = new NukeLaunch(self.Owner, info.MissileImage, info.WeaponInfo, palette, info.MissileUp, info.MissileDown,
|
||||
launchPos,
|
||||
targetPosition, info.DetonationAltitude, info.RemoveMissileOnDetonation,
|
||||
info.FlightVelocity, info.MissileDelay, info.FlightDelay, skipAscent,
|
||||
info.TrailImage, info.TrailSequences, info.TrailPalette, info.TrailUsePlayerPalette, info.TrailDelay, info.TrailInterval);
|
||||
|
||||
self.World.AddFrameEndTask(w => w.Add(missile));
|
||||
|
||||
if (info.CameraRange != WDist.Zero)
|
||||
{
|
||||
var type = info.RevealGeneratedShroud ? Shroud.SourceType.Visibility
|
||||
: Shroud.SourceType.PassiveVisibility;
|
||||
|
||||
self.World.AddFrameEndTask(w => w.Add(new RevealShroudEffect(targetPosition, info.CameraRange, type, self.Owner, info.CameraRelationships,
|
||||
info.FlightDelay - info.CameraSpawnAdvance, info.CameraSpawnAdvance + info.CameraRemoveDelay)));
|
||||
}
|
||||
|
||||
if (Info.DisplayBeacon)
|
||||
{
|
||||
var beacon = new Beacon(
|
||||
self.Owner,
|
||||
targetPosition,
|
||||
Info.BeaconPaletteIsPlayerPalette,
|
||||
Info.BeaconPalette,
|
||||
Info.BeaconImage,
|
||||
Info.BeaconPoster,
|
||||
Info.BeaconPosterPalette,
|
||||
Info.BeaconSequence,
|
||||
Info.ArrowSequence,
|
||||
Info.CircleSequence,
|
||||
Info.ClockSequence,
|
||||
() => missile.FractionComplete,
|
||||
Info.BeaconDelay,
|
||||
info.FlightDelay - info.BeaconRemoveAdvance);
|
||||
|
||||
self.World.AddFrameEndTask(w => w.Add(beacon));
|
||||
}
|
||||
}
|
||||
|
||||
public override void SelectTarget(Actor self, string order, SupportPowerManager manager)
|
||||
{
|
||||
self.World.OrderGenerator = new SelectNukePowerTarget(order, manager, info);
|
||||
}
|
||||
}
|
||||
|
||||
public class SelectNukePowerTarget : SelectGenericPowerTarget
|
||||
{
|
||||
readonly NukePowerInfo info;
|
||||
|
||||
public SelectNukePowerTarget(string order, SupportPowerManager manager, NukePowerInfo info)
|
||||
: base(order, manager, info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
protected override IEnumerable<IRenderable> RenderAnnotations(WorldRenderer wr, World world)
|
||||
{
|
||||
if (info.CircleRanges == null)
|
||||
yield break;
|
||||
|
||||
var centerPosition = wr.World.Map.CenterOfCell(wr.Viewport.ViewToWorld(Viewport.LastMousePos));
|
||||
foreach (var range in info.CircleRanges)
|
||||
yield return new RangeCircleAnnotationRenderable(
|
||||
centerPosition,
|
||||
range,
|
||||
0,
|
||||
info.CircleColor,
|
||||
info.CircleWidth,
|
||||
info.CircleBorderColor,
|
||||
info.CircleBorderWidth);
|
||||
}
|
||||
}
|
||||
}
|
||||
277
OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs
Normal file
277
OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs
Normal file
@@ -0,0 +1,277 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Support power that spawns and delivers units to the desired location via aircraft.")]
|
||||
public class ParatroopersPowerInfo : DirectionalSupportPowerInfo
|
||||
{
|
||||
[ActorReference(typeof(AircraftInfo))]
|
||||
[Desc("Aircraft used to deliver the drop.")]
|
||||
public readonly string UnitType = "badr";
|
||||
|
||||
[Desc("Number of aircraft to use in the formation.")]
|
||||
public readonly int SquadSize = 1;
|
||||
|
||||
[Desc("Distance between the aircraft in a formation.")]
|
||||
public readonly WVec SquadOffset = new(-1536, 1536, 0);
|
||||
|
||||
[NotificationReference("Speech")]
|
||||
[Desc("Speech notification to play when entering the drop zone.")]
|
||||
public readonly string ReinforcementsArrivedSpeechNotification = null;
|
||||
|
||||
[FluentReference(optional: true)]
|
||||
[Desc("Text notification to display when entering the drop zone.")]
|
||||
public readonly string ReinforcementsArrivedTextNotification = null;
|
||||
|
||||
[Desc("Number of facings that the delivery aircraft may approach from.")]
|
||||
public readonly int QuantizedFacings = 32;
|
||||
|
||||
[Desc("Spawn and remove the plane this far outside the map.")]
|
||||
public readonly WDist Cordon = new(5120);
|
||||
|
||||
[ActorReference(typeof(PassengerInfo))]
|
||||
[Desc("Troops to be delivered. They will be distributed between the planes if SquadSize > 1.")]
|
||||
public readonly ImmutableArray<string> DropItems = [];
|
||||
|
||||
[Desc("Risks stuck units when they don't have the Paratrooper trait.")]
|
||||
public readonly bool AllowImpassableCells = false;
|
||||
|
||||
[ActorReference]
|
||||
[Desc("Actor to spawn when the paradrop starts.")]
|
||||
public readonly string CameraActor = null;
|
||||
|
||||
[Desc("Amount of time (in ticks) to keep the camera alive while the passengers drop.")]
|
||||
public readonly int CameraRemoveDelay = 85;
|
||||
|
||||
[Desc("Weapon range offset to apply during the beacon clock calculation.")]
|
||||
public readonly WDist BeaconDistanceOffset = WDist.FromCells(4);
|
||||
|
||||
public override object Create(ActorInitializer init) { return new ParatroopersPower(init.Self, this); }
|
||||
}
|
||||
|
||||
public class ParatroopersPower : DirectionalSupportPower
|
||||
{
|
||||
readonly ParatroopersPowerInfo info;
|
||||
|
||||
public ParatroopersPower(Actor self, ParatroopersPowerInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public override void Activate(Actor self, Order order, SupportPowerManager manager)
|
||||
{
|
||||
base.Activate(self, order, manager);
|
||||
|
||||
var facing = info.UseDirectionalTarget && order.ExtraData != uint.MaxValue ? (WAngle?)WAngle.FromFacing((int)order.ExtraData) : null;
|
||||
SendParatroopers(self, order.Target.CenterPosition, facing);
|
||||
}
|
||||
|
||||
public (Actor[] Aircraft, Actor[] Units) SendParatroopers(Actor self, WPos target, WAngle? facing = null)
|
||||
{
|
||||
var aircraft = new List<Actor>();
|
||||
var units = new List<Actor>();
|
||||
|
||||
if (!facing.HasValue)
|
||||
facing = new WAngle(1024 * self.World.SharedRandom.Next(info.QuantizedFacings) / info.QuantizedFacings);
|
||||
|
||||
var utLower = info.UnitType.ToLowerInvariant();
|
||||
if (!self.World.Map.Rules.Actors.TryGetValue(utLower, out var unitType))
|
||||
throw new YamlException($"Actors ruleset does not include the entry '{utLower}'");
|
||||
|
||||
var altitude = unitType.TraitInfo<AircraftInfo>().CruiseAltitude.Length;
|
||||
var dropRotation = WRot.FromYaw(facing.Value);
|
||||
var delta = new WVec(0, -1024, 0).Rotate(dropRotation);
|
||||
target += new WVec(0, 0, altitude);
|
||||
var startEdge = target - (self.World.Map.DistanceToEdge(target, -delta) + info.Cordon).Length * delta / 1024;
|
||||
var finishEdge = target + (self.World.Map.DistanceToEdge(target, delta) + info.Cordon).Length * delta / 1024;
|
||||
|
||||
Actor camera = null;
|
||||
Beacon beacon = null;
|
||||
var aircraftInRange = new Dictionary<Actor, bool>();
|
||||
|
||||
void OnEnterRange(Actor a)
|
||||
{
|
||||
// Spawn a camera and remove the beacon when the first plane enters the target area
|
||||
if (info.CameraActor != null && camera == null && !aircraftInRange.Any(kv => kv.Value))
|
||||
{
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
camera = w.CreateActor(info.CameraActor,
|
||||
[
|
||||
new LocationInit(self.World.Map.CellContaining(target)),
|
||||
new OwnerInit(self.Owner),
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
RemoveBeacon(beacon);
|
||||
|
||||
if (!aircraftInRange.Any(kv => kv.Value))
|
||||
{
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech",
|
||||
info.ReinforcementsArrivedSpeechNotification, self.Owner.Faction.InternalName);
|
||||
|
||||
TextNotificationsManager.AddTransientLine(self.Owner, info.ReinforcementsArrivedTextNotification);
|
||||
}
|
||||
|
||||
aircraftInRange[a] = true;
|
||||
}
|
||||
|
||||
void OnExitRange(Actor a)
|
||||
{
|
||||
aircraftInRange[a] = false;
|
||||
|
||||
// Remove the camera when the final plane leaves the target area
|
||||
if (!aircraftInRange.Any(kv => kv.Value))
|
||||
RemoveCamera(camera);
|
||||
}
|
||||
|
||||
void OnRemovedFromWorld(Actor a)
|
||||
{
|
||||
aircraftInRange[a] = false;
|
||||
|
||||
// Checking for attack range is not relevant here because
|
||||
// aircraft may be shot down before entering the range.
|
||||
// If at the map's edge, they may be removed from world before leaving.
|
||||
if (aircraftInRange.All(kv => !kv.Key.IsInWorld))
|
||||
{
|
||||
RemoveCamera(camera);
|
||||
RemoveBeacon(beacon);
|
||||
}
|
||||
}
|
||||
|
||||
// Create the actors immediately so they can be returned
|
||||
for (var i = -info.SquadSize / 2; i <= info.SquadSize / 2; i++)
|
||||
{
|
||||
// Even-sized squads skip the lead plane
|
||||
if (i == 0 && (info.SquadSize & 1) == 0)
|
||||
continue;
|
||||
|
||||
// Includes the 90 degree rotation between body and world coordinates
|
||||
var so = info.SquadOffset;
|
||||
var spawnOffset = new WVec(i * so.Y, -Math.Abs(i) * so.X, 0).Rotate(dropRotation);
|
||||
|
||||
aircraft.Add(self.World.CreateActor(false, info.UnitType,
|
||||
[
|
||||
new CenterPositionInit(startEdge + spawnOffset),
|
||||
new OwnerInit(self.Owner),
|
||||
new FacingInit(facing.Value),
|
||||
]));
|
||||
}
|
||||
|
||||
foreach (var p in info.DropItems)
|
||||
{
|
||||
units.Add(self.World.CreateActor(false, p.ToLowerInvariant(),
|
||||
[
|
||||
new OwnerInit(self.Owner)
|
||||
]));
|
||||
}
|
||||
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
PlayLaunchSounds();
|
||||
|
||||
Actor distanceTestActor = null;
|
||||
|
||||
var passengersPerPlane = (info.DropItems.Length + info.SquadSize - 1) / info.SquadSize;
|
||||
var added = 0;
|
||||
var j = 0;
|
||||
for (var i = -info.SquadSize / 2; i <= info.SquadSize / 2; i++)
|
||||
{
|
||||
// Even-sized squads skip the lead plane
|
||||
if (i == 0 && (info.SquadSize & 1) == 0)
|
||||
continue;
|
||||
|
||||
// Includes the 90 degree rotation between body and world coordinates
|
||||
var so = info.SquadOffset;
|
||||
var spawnOffset = new WVec(i * so.Y, -Math.Abs(i) * so.X, 0).Rotate(dropRotation);
|
||||
var targetOffset = new WVec(i * so.Y, 0, 0).Rotate(dropRotation);
|
||||
var a = aircraft[j++];
|
||||
w.Add(a);
|
||||
|
||||
var drop = a.Trait<ParaDrop>();
|
||||
drop.SetLZ(w.Map.CellContaining(target + targetOffset), !info.AllowImpassableCells);
|
||||
drop.OnEnteredDropRange += OnEnterRange;
|
||||
drop.OnExitedDropRange += OnExitRange;
|
||||
drop.OnRemovedFromWorld += OnRemovedFromWorld;
|
||||
|
||||
var cargo = a.Trait<Cargo>();
|
||||
foreach (var unit in units.Skip(added).Take(passengersPerPlane))
|
||||
{
|
||||
cargo.Load(a, unit);
|
||||
added++;
|
||||
}
|
||||
|
||||
a.QueueActivity(new Fly(a, Target.FromPos(target + spawnOffset)));
|
||||
a.QueueActivity(new Fly(a, Target.FromPos(finishEdge + spawnOffset)));
|
||||
a.QueueActivity(new RemoveSelf());
|
||||
aircraftInRange.Add(a, false);
|
||||
distanceTestActor = a;
|
||||
}
|
||||
|
||||
// Dispose any unused units
|
||||
for (var i = added; i < units.Count; i++)
|
||||
units[i].Dispose();
|
||||
|
||||
if (Info.DisplayBeacon)
|
||||
{
|
||||
var distance = (target - startEdge).HorizontalLength;
|
||||
|
||||
beacon = new Beacon(
|
||||
self.Owner,
|
||||
target - new WVec(0, 0, altitude),
|
||||
Info.BeaconPaletteIsPlayerPalette,
|
||||
Info.BeaconPalette,
|
||||
Info.BeaconImage,
|
||||
Info.BeaconPoster,
|
||||
Info.BeaconPosterPalette,
|
||||
Info.BeaconSequence,
|
||||
Info.ArrowSequence,
|
||||
Info.CircleSequence,
|
||||
Info.ClockSequence,
|
||||
() => 1 - ((distanceTestActor.CenterPosition - target).HorizontalLength - info.BeaconDistanceOffset.Length) * 1f / distance,
|
||||
Info.BeaconDelay);
|
||||
|
||||
w.Add(beacon);
|
||||
}
|
||||
});
|
||||
|
||||
return (aircraft.ToArray(), units.ToArray());
|
||||
}
|
||||
|
||||
void RemoveCamera(Actor camera)
|
||||
{
|
||||
if (camera == null)
|
||||
return;
|
||||
|
||||
camera.QueueActivity(new Wait(info.CameraRemoveDelay));
|
||||
camera.QueueActivity(new RemoveSelf());
|
||||
}
|
||||
|
||||
void RemoveBeacon(Beacon beacon)
|
||||
{
|
||||
if (beacon == null)
|
||||
return;
|
||||
|
||||
Self.World.AddFrameEndTask(w => w.Remove(beacon));
|
||||
}
|
||||
}
|
||||
}
|
||||
114
OpenRA.Mods.Common/Traits/SupportPowers/ProduceActorPower.cs
Normal file
114
OpenRA.Mods.Common/Traits/SupportPowers/ProduceActorPower.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Produces an actor without using the standard production queue.")]
|
||||
public class ProduceActorPowerInfo : SupportPowerInfo
|
||||
{
|
||||
[ActorReference]
|
||||
[FieldLoader.Require]
|
||||
[Desc("Actors to produce.")]
|
||||
public readonly ImmutableArray<string> Actors = default;
|
||||
|
||||
[FieldLoader.Require]
|
||||
[Desc("Production queue type to use")]
|
||||
public readonly string Type = null;
|
||||
|
||||
[NotificationReference("Speech")]
|
||||
[Desc("Speech notification played when production is activated.",
|
||||
"The filename of the audio is defined per faction in notifications.yaml.")]
|
||||
public readonly string ReadyAudio = null;
|
||||
|
||||
[FluentReference(optional: true)]
|
||||
[Desc("Text notification displayed when production is activated.")]
|
||||
public readonly string ReadyTextNotification = null;
|
||||
|
||||
[NotificationReference("Speech")]
|
||||
[Desc("Speech notification played when the exit is jammed.",
|
||||
"The filename of the audio is defined per faction in notifications.yaml.")]
|
||||
public readonly string BlockedAudio = null;
|
||||
|
||||
[FluentReference(optional: true)]
|
||||
[Desc("Text notification displayed when the exit is jammed.")]
|
||||
public readonly string BlockedTextNotification = null;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new ProduceActorPower(init, this); }
|
||||
}
|
||||
|
||||
public class ProduceActorPower : SupportPower
|
||||
{
|
||||
readonly string faction;
|
||||
|
||||
public ProduceActorPower(ActorInitializer init, ProduceActorPowerInfo info)
|
||||
: base(init.Self, info)
|
||||
{
|
||||
faction = init.GetValue<FactionInit, string>(init.Self.Owner.Faction.InternalName);
|
||||
}
|
||||
|
||||
public override void SelectTarget(Actor self, string order, SupportPowerManager manager)
|
||||
{
|
||||
self.World.IssueOrder(new Order(order, manager.Self, false));
|
||||
}
|
||||
|
||||
public override void Activate(Actor self, Order order, SupportPowerManager manager)
|
||||
{
|
||||
base.Activate(self, order, manager);
|
||||
PlayLaunchSounds();
|
||||
|
||||
var info = Info as ProduceActorPowerInfo;
|
||||
var producers = self.World.ActorsWithTrait<Production>()
|
||||
.Where(x => x.Actor.Owner == self.Owner
|
||||
&& !x.Trait.IsTraitDisabled
|
||||
&& x.Trait.Info.Produces.Contains(info.Type))
|
||||
.OrderByDescending(x => x.Actor.IsPrimaryBuilding())
|
||||
.ThenByDescending(x => x.Actor.ActorID);
|
||||
|
||||
// TODO: The power should not reset if the production fails.
|
||||
// Fixing this will require a larger rework of the support power code
|
||||
var activated = false;
|
||||
|
||||
foreach (var p in producers)
|
||||
{
|
||||
foreach (var name in info.Actors)
|
||||
{
|
||||
var ai = self.World.Map.Rules.Actors[name];
|
||||
var inits = new TypeDictionary
|
||||
{
|
||||
new OwnerInit(self.Owner),
|
||||
new FactionInit(BuildableInfo.GetInitialFaction(ai, faction))
|
||||
};
|
||||
|
||||
activated |= p.Trait.Produce(p.Actor, ai, info.Type, inits, 0);
|
||||
}
|
||||
|
||||
if (activated)
|
||||
break;
|
||||
}
|
||||
|
||||
if (activated)
|
||||
{
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, manager.Self.Owner, "Speech", info.ReadyAudio, self.Owner.Faction.InternalName);
|
||||
TextNotificationsManager.AddTransientLine(manager.Self.Owner, info.ReadyTextNotification);
|
||||
}
|
||||
else
|
||||
{
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, manager.Self.Owner, "Speech", info.BlockedAudio, self.Owner.Faction.InternalName);
|
||||
TextNotificationsManager.AddTransientLine(manager.Self.Owner, info.BlockedTextNotification);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Widgets;
|
||||
using OpenRA.Orders;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class SelectDirectionalTarget : IOrderGenerator
|
||||
{
|
||||
const int MinDragThreshold = 20;
|
||||
const int MaxDragThreshold = 75;
|
||||
|
||||
readonly string order;
|
||||
readonly SupportPowerManager manager;
|
||||
readonly GameSettings gameSettings;
|
||||
|
||||
readonly Arrow[] directionArrows;
|
||||
|
||||
CPos targetCell;
|
||||
int2 targetLocation;
|
||||
float2 dragDirection;
|
||||
bool activated;
|
||||
bool dragStarted;
|
||||
Arrow currentArrow;
|
||||
readonly MouseAttachmentWidget mouseAttachment;
|
||||
readonly DirectionalSupportPowerInfo info;
|
||||
|
||||
public SelectDirectionalTarget(World world, string order, SupportPowerManager manager, DirectionalSupportPowerInfo info)
|
||||
{
|
||||
this.order = order;
|
||||
this.manager = manager;
|
||||
this.info = info;
|
||||
gameSettings = Game.Settings.Game;
|
||||
|
||||
directionArrows = LoadArrows(info.DirectionArrowAnimation, world, info.Arrows.Length);
|
||||
mouseAttachment = Ui.Root.Get<MouseAttachmentWidget>("MOUSE_ATTATCHMENT");
|
||||
}
|
||||
|
||||
public MouseButton ActionButton => gameSettings.ResolveActionButton(MouseActionType.SupportPower);
|
||||
public MouseButton CancelButton => gameSettings.ResolveCancelButton(MouseActionType.SupportPower);
|
||||
|
||||
IEnumerable<Order> IOrderGenerator.Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
if (mi.Button == CancelButton)
|
||||
{
|
||||
world.CancelInputMode();
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (mi.Button == ActionButton && mi.Event == MouseInputEvent.Down)
|
||||
{
|
||||
if (!activated && world.Map.Contains(cell))
|
||||
{
|
||||
targetCell = cell;
|
||||
targetLocation = mi.Location;
|
||||
activated = true;
|
||||
Game.Cursor.Lock();
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (!activated)
|
||||
yield break;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Move)
|
||||
{
|
||||
dragDirection += mi.Delta;
|
||||
|
||||
var angle = AngleOf(dragDirection);
|
||||
if (dragDirection.Length > MaxDragThreshold)
|
||||
dragDirection = -MaxDragThreshold * float2.FromAngle((float)(angle * (Math.PI / 180)));
|
||||
|
||||
currentArrow = GetArrow(angle);
|
||||
|
||||
mouseAttachment.SetAttachment(targetLocation, currentArrow.Sprite, info.DirectionArrowPalette);
|
||||
dragStarted = true;
|
||||
}
|
||||
|
||||
if (mi.Button == ActionButton && mi.Event == MouseInputEvent.Up)
|
||||
{
|
||||
yield return new Order(order, manager.Self, Target.FromCell(manager.Self.World, targetCell), false)
|
||||
{
|
||||
SuppressVisualFeedback = true,
|
||||
ExtraData = IsOutsideDragZone ? (uint)currentArrow.Direction.Facing : uint.MaxValue
|
||||
};
|
||||
|
||||
world.CancelInputMode();
|
||||
}
|
||||
}
|
||||
|
||||
void IOrderGenerator.Tick(World world)
|
||||
{
|
||||
// Cancel the OG if we can't use the power
|
||||
if (!manager.Powers.TryGetValue(order, out var p) || !p.Active || !p.Ready)
|
||||
world.CancelInputMode();
|
||||
}
|
||||
|
||||
void IOrderGenerator.SelectionChanged(World world, IEnumerable<Actor> selected) { }
|
||||
|
||||
bool IsOutsideDragZone => dragStarted && dragDirection.Length > MinDragThreshold;
|
||||
|
||||
IEnumerable<IRenderable> IOrderGenerator.Render(WorldRenderer wr, World world) { yield break; }
|
||||
|
||||
IEnumerable<IRenderable> IOrderGenerator.RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
||||
IEnumerable<IRenderable> IOrderGenerator.RenderAnnotations(WorldRenderer wr, World world) { yield break; }
|
||||
|
||||
string IOrderGenerator.GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
return world.Map.Contains(cell) ? info.Cursor : info.BlockedCursor;
|
||||
}
|
||||
|
||||
bool IOrderGenerator.HandleKeyPress(KeyInput e) { return false; }
|
||||
|
||||
void IOrderGenerator.Deactivate()
|
||||
{
|
||||
if (activated)
|
||||
{
|
||||
mouseAttachment.Reset();
|
||||
Game.Cursor.Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
// Starting at (0, -1) and rotating in CCW
|
||||
static double AngleOf(float2 delta)
|
||||
{
|
||||
var radian = Math.Atan2(delta.Y, delta.X);
|
||||
var d = radian * (180 / Math.PI);
|
||||
if (d < 0.0)
|
||||
d += 360.0;
|
||||
var angle = 270.0 - d;
|
||||
if (angle < 0)
|
||||
angle += 360.0;
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
Arrow GetArrow(double degree)
|
||||
{
|
||||
var arrow = directionArrows.FirstOrDefault(d => d.EndAngle >= degree);
|
||||
return arrow ?? directionArrows[0];
|
||||
}
|
||||
|
||||
Arrow[] LoadArrows(string cursorAnimation, World world, int noOfDividingPoints)
|
||||
{
|
||||
var points = new Arrow[noOfDividingPoints];
|
||||
var partAngle = 360 / noOfDividingPoints;
|
||||
var i1 = partAngle / 2d;
|
||||
|
||||
for (var i = 0; i < noOfDividingPoints; i++)
|
||||
{
|
||||
var sprite = world.Map.Sequences.GetSequence(cursorAnimation, info.Arrows[i]).GetSprite(0);
|
||||
|
||||
var angle = i * partAngle;
|
||||
var direction = WAngle.FromDegrees(angle);
|
||||
var endAngle = angle + i1;
|
||||
|
||||
points[i] = new Arrow(sprite, endAngle, direction);
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
sealed record Arrow(Sprite Sprite, double EndAngle, WAngle Direction);
|
||||
}
|
||||
}
|
||||
164
OpenRA.Mods.Common/Traits/SupportPowers/SpawnActorPower.cs
Normal file
164
OpenRA.Mods.Common/Traits/SupportPowers/SpawnActorPower.cs
Normal file
@@ -0,0 +1,164 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Spawns an actor that stays for a limited amount of time.")]
|
||||
public class SpawnActorPowerInfo : SupportPowerInfo
|
||||
{
|
||||
[ActorReference]
|
||||
[FieldLoader.Require]
|
||||
[Desc("Actor to spawn.")]
|
||||
public readonly string Actor = null;
|
||||
|
||||
[Desc("Amount of time to keep the actor alive in ticks. Value < 0 means this actor will not remove itself.")]
|
||||
public readonly int LifeTime = 250;
|
||||
|
||||
[Desc("Only allow this to be spawned on this terrain.")]
|
||||
public readonly ImmutableArray<string> Terrain = default;
|
||||
|
||||
public readonly bool AllowUnderShroud = true;
|
||||
|
||||
public readonly string DeploySound = null;
|
||||
|
||||
public readonly string EffectImage = null;
|
||||
|
||||
[SequenceReference(nameof(EffectImage))]
|
||||
public readonly string EffectSequence = null;
|
||||
|
||||
[PaletteReference(nameof(EffectPaletteIsPlayerPalette))]
|
||||
public readonly string EffectPalette = null;
|
||||
|
||||
public readonly bool EffectPaletteIsPlayerPalette = false;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new SpawnActorPower(init.Self, this); }
|
||||
}
|
||||
|
||||
public class SpawnActorPower : SupportPower
|
||||
{
|
||||
public SpawnActorPower(Actor self, SpawnActorPowerInfo info)
|
||||
: base(self, info) { }
|
||||
|
||||
public override void Activate(Actor self, Order order, SupportPowerManager manager)
|
||||
{
|
||||
var info = Info as SpawnActorPowerInfo;
|
||||
var position = order.Target.CenterPosition;
|
||||
var cell = self.World.Map.CellContaining(position);
|
||||
|
||||
if (!Validate(self.World, info, cell))
|
||||
return;
|
||||
|
||||
base.Activate(self, order, manager);
|
||||
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
PlayLaunchSounds();
|
||||
Game.Sound.Play(SoundType.World, info.DeploySound, position);
|
||||
|
||||
if (!string.IsNullOrEmpty(info.EffectSequence) && !string.IsNullOrEmpty(info.EffectPalette))
|
||||
{
|
||||
var palette = info.EffectPalette;
|
||||
if (info.EffectPaletteIsPlayerPalette)
|
||||
palette += self.Owner.InternalName;
|
||||
|
||||
w.Add(new SpriteEffect(position, w, info.EffectImage, info.EffectSequence, palette));
|
||||
}
|
||||
|
||||
var actor = w.CreateActor(info.Actor,
|
||||
[
|
||||
new LocationInit(cell),
|
||||
new OwnerInit(self.Owner),
|
||||
]);
|
||||
|
||||
if (info.LifeTime > -1)
|
||||
{
|
||||
actor.QueueActivity(new Wait(info.LifeTime));
|
||||
actor.QueueActivity(new RemoveSelf());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public override void SelectTarget(Actor self, string order, SupportPowerManager manager)
|
||||
{
|
||||
Game.Sound.PlayToPlayer(SoundType.UI, manager.Self.Owner, Info.SelectTargetSound);
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech",
|
||||
Info.SelectTargetSpeechNotification, self.Owner.Faction.InternalName);
|
||||
|
||||
TextNotificationsManager.AddTransientLine(manager.Self.Owner, Info.SelectTargetTextNotification);
|
||||
|
||||
self.World.OrderGenerator = new SelectSpawnActorPowerTarget(order, manager, this);
|
||||
}
|
||||
|
||||
public bool Validate(World world, SpawnActorPowerInfo info, CPos cell)
|
||||
{
|
||||
if (!world.Map.Contains(cell))
|
||||
return false;
|
||||
|
||||
if (!info.AllowUnderShroud && world.ShroudObscures(cell))
|
||||
return false;
|
||||
|
||||
if (info.Terrain != null && !info.Terrain.Contains(world.Map.GetTerrainInfo(cell).Type))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class SelectSpawnActorPowerTarget : OrderGenerator
|
||||
{
|
||||
protected override MouseActionType ActionType => MouseActionType.SupportPower;
|
||||
readonly SpawnActorPower power;
|
||||
readonly SpawnActorPowerInfo info;
|
||||
readonly SupportPowerManager manager;
|
||||
|
||||
public string OrderKey { get; }
|
||||
|
||||
public SelectSpawnActorPowerTarget(string order, SupportPowerManager manager, SpawnActorPower power)
|
||||
: base(manager.Self.World)
|
||||
{
|
||||
this.manager = manager;
|
||||
this.power = power;
|
||||
OrderKey = order;
|
||||
|
||||
info = (SpawnActorPowerInfo)power.Info;
|
||||
}
|
||||
|
||||
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
world.CancelInputMode();
|
||||
if (power.Validate(world, info, cell))
|
||||
yield return new Order(OrderKey, manager.Self, Target.FromCell(world, cell), false) { SuppressVisualFeedback = true };
|
||||
}
|
||||
|
||||
protected override void Tick(World world)
|
||||
{
|
||||
// Cancel the OG if we can't use the power
|
||||
if (!manager.Powers.ContainsKey(OrderKey))
|
||||
world.CancelInputMode();
|
||||
}
|
||||
|
||||
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
||||
protected override IEnumerable<IRenderable> RenderAnnotations(WorldRenderer wr, World world) { yield break; }
|
||||
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
return power.Validate(world, info, cell) ? info.Cursor : info.BlockedCursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
261
OpenRA.Mods.Common/Traits/SupportPowers/SupportPower.cs
Normal file
261
OpenRA.Mods.Common/Traits/SupportPowers/SupportPower.cs
Normal file
@@ -0,0 +1,261 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public abstract class SupportPowerInfo : PausableConditionalTraitInfo
|
||||
{
|
||||
[Desc("Measured in ticks.")]
|
||||
public readonly int ChargeInterval = 0;
|
||||
|
||||
public readonly string IconImage = "icon";
|
||||
|
||||
[SequenceReference(nameof(IconImage))]
|
||||
[Desc("Icon sprite displayed in the support power palette.")]
|
||||
public readonly string Icon = null;
|
||||
|
||||
[PaletteReference]
|
||||
[Desc("Palette used for the icon.")]
|
||||
public readonly string IconPalette = "chrome";
|
||||
|
||||
[FluentReference(optional: true)]
|
||||
public readonly string Name = null;
|
||||
|
||||
[FluentReference(optional: true)]
|
||||
public readonly string Description = null;
|
||||
|
||||
[Desc("Allow multiple instances of the same support power.")]
|
||||
public readonly bool AllowMultiple = false;
|
||||
|
||||
[Desc("Allow this to be used only once.")]
|
||||
public readonly bool OneShot = false;
|
||||
|
||||
[CursorReference]
|
||||
[Desc("Cursor to display for using this support power.")]
|
||||
public readonly string Cursor = "ability";
|
||||
|
||||
[CursorReference]
|
||||
[Desc("Cursor when unable to activate on this position. ")]
|
||||
public readonly string BlockedCursor = "generic-blocked";
|
||||
|
||||
[Desc("If set to true, the support power will be fully charged when it becomes available. " +
|
||||
"Normal rules apply for subsequent charges.")]
|
||||
public readonly bool StartFullyCharged = false;
|
||||
|
||||
public readonly ImmutableArray<string> Prerequisites = [];
|
||||
|
||||
public readonly string DetectedSound = null;
|
||||
|
||||
[NotificationReference("Speech")]
|
||||
public readonly string DetectedSpeechNotification = null;
|
||||
|
||||
[FluentReference(optional: true)]
|
||||
public readonly string DetectedTextNotification = null;
|
||||
|
||||
public readonly string BeginChargeSound = null;
|
||||
|
||||
[NotificationReference("Speech")]
|
||||
public readonly string BeginChargeSpeechNotification = null;
|
||||
|
||||
[FluentReference(optional: true)]
|
||||
public readonly string BeginChargeTextNotification = null;
|
||||
|
||||
public readonly string EndChargeSound = null;
|
||||
|
||||
[NotificationReference("Speech")]
|
||||
public readonly string EndChargeSpeechNotification = null;
|
||||
|
||||
[FluentReference(optional: true)]
|
||||
public readonly string EndChargeTextNotification = null;
|
||||
|
||||
public readonly string SelectTargetSound = null;
|
||||
|
||||
[NotificationReference("Speech")]
|
||||
public readonly string SelectTargetSpeechNotification = null;
|
||||
|
||||
[FluentReference(optional: true)]
|
||||
public readonly string SelectTargetTextNotification = null;
|
||||
|
||||
public readonly string InsufficientPowerSound = null;
|
||||
|
||||
[NotificationReference("Speech")]
|
||||
public readonly string InsufficientPowerSpeechNotification = null;
|
||||
|
||||
[FluentReference(optional: true)]
|
||||
public readonly string InsufficientPowerTextNotification = null;
|
||||
|
||||
public readonly string LaunchSound = null;
|
||||
|
||||
[NotificationReference("Speech")]
|
||||
public readonly string LaunchSpeechNotification = null;
|
||||
|
||||
[FluentReference(optional: true)]
|
||||
public readonly string LaunchTextNotification = null;
|
||||
|
||||
public readonly string IncomingSound = null;
|
||||
|
||||
[NotificationReference("Speech")]
|
||||
public readonly string IncomingSpeechNotification = null;
|
||||
|
||||
[FluentReference(optional: true)]
|
||||
public readonly string IncomingTextNotification = null;
|
||||
|
||||
[Desc("Defines to which players the timer is shown.")]
|
||||
public readonly PlayerRelationship DisplayTimerRelationships = PlayerRelationship.None;
|
||||
|
||||
[Desc("Beacons are only supported on the Airstrike, Paratroopers, and Nuke powers")]
|
||||
public readonly bool DisplayBeacon = false;
|
||||
|
||||
public readonly bool BeaconPaletteIsPlayerPalette = true;
|
||||
|
||||
[PaletteReference(nameof(BeaconPaletteIsPlayerPalette))]
|
||||
public readonly string BeaconPalette = "player";
|
||||
|
||||
public readonly string BeaconImage = "beacon";
|
||||
|
||||
[SequenceReference(nameof(BeaconImage))]
|
||||
public readonly string BeaconPoster = null;
|
||||
|
||||
[PaletteReference]
|
||||
public readonly string BeaconPosterPalette = "chrome";
|
||||
|
||||
[SequenceReference(nameof(BeaconImage))]
|
||||
public readonly string ClockSequence = null;
|
||||
|
||||
[SequenceReference(nameof(BeaconImage))]
|
||||
public readonly string BeaconSequence = null;
|
||||
|
||||
[SequenceReference(nameof(BeaconImage))]
|
||||
public readonly string ArrowSequence = null;
|
||||
|
||||
[SequenceReference(nameof(BeaconImage))]
|
||||
public readonly string CircleSequence = null;
|
||||
|
||||
[Desc("Delay after launch, measured in ticks.")]
|
||||
public readonly int BeaconDelay = 0;
|
||||
|
||||
public readonly bool DisplayRadarPing = false;
|
||||
|
||||
[Desc("Measured in ticks.")]
|
||||
public readonly int RadarPingDuration = 125;
|
||||
|
||||
public readonly string OrderName;
|
||||
|
||||
[Desc("Sort order for the support power palette. Smaller numbers are presented earlier.")]
|
||||
public readonly int SupportPowerPaletteOrder = 9999;
|
||||
|
||||
protected SupportPowerInfo() { OrderName = GetType().Name + "Order"; }
|
||||
}
|
||||
|
||||
public abstract class SupportPower : PausableConditionalTrait<SupportPowerInfo>
|
||||
{
|
||||
public readonly Actor Self;
|
||||
readonly SupportPowerInfo info;
|
||||
protected RadarPing ping;
|
||||
|
||||
protected SupportPower(Actor self, SupportPowerInfo info)
|
||||
: base(info)
|
||||
{
|
||||
Self = self;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
protected override void Created(Actor self)
|
||||
{
|
||||
base.Created(self);
|
||||
|
||||
var player = self.World.LocalPlayer;
|
||||
if (player != null && player != self.Owner)
|
||||
{
|
||||
Game.Sound.Play(SoundType.UI, Info.DetectedSound);
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, player, "Speech", info.DetectedSpeechNotification, player.Faction.InternalName);
|
||||
TextNotificationsManager.AddTransientLine(player, info.DetectedTextNotification);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual SupportPowerInstance CreateInstance(string key, SupportPowerManager manager)
|
||||
{
|
||||
return new SupportPowerInstance(key, info, manager);
|
||||
}
|
||||
|
||||
public virtual void Charging(Actor self, string key)
|
||||
{
|
||||
Game.Sound.PlayToPlayer(SoundType.UI, self.Owner, Info.BeginChargeSound);
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech",
|
||||
Info.BeginChargeSpeechNotification, self.Owner.Faction.InternalName);
|
||||
|
||||
TextNotificationsManager.AddTransientLine(self.Owner, Info.BeginChargeTextNotification);
|
||||
}
|
||||
|
||||
public virtual void Charged(Actor self, string key)
|
||||
{
|
||||
Game.Sound.PlayToPlayer(SoundType.UI, self.Owner, Info.EndChargeSound);
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech",
|
||||
Info.EndChargeSpeechNotification, self.Owner.Faction.InternalName);
|
||||
|
||||
TextNotificationsManager.AddTransientLine(self.Owner, Info.EndChargeTextNotification);
|
||||
|
||||
foreach (var notify in self.TraitsImplementing<INotifySupportPower>())
|
||||
notify.Charged(self);
|
||||
}
|
||||
|
||||
public virtual void SelectTarget(Actor self, string order, SupportPowerManager manager)
|
||||
{
|
||||
self.World.OrderGenerator = new SelectGenericPowerTarget(order, manager, info);
|
||||
}
|
||||
|
||||
public virtual void Activate(Actor self, Order order, SupportPowerManager manager)
|
||||
{
|
||||
if (Info.DisplayRadarPing && manager.RadarPings != null)
|
||||
{
|
||||
ping = manager.RadarPings.Value.Add(
|
||||
() => order.Player.IsAlliedWith(self.World.RenderPlayer),
|
||||
order.Target.CenterPosition,
|
||||
order.Player.Color,
|
||||
Info.RadarPingDuration);
|
||||
}
|
||||
|
||||
foreach (var notify in self.TraitsImplementing<INotifySupportPower>())
|
||||
notify.Activated(self);
|
||||
}
|
||||
|
||||
public virtual void PlayLaunchSounds()
|
||||
{
|
||||
var localPlayer = Self.World.LocalPlayer;
|
||||
if (localPlayer == null || localPlayer.Spectating)
|
||||
return;
|
||||
|
||||
var isAllied = Self.Owner.IsAlliedWith(localPlayer);
|
||||
Game.Sound.Play(SoundType.UI, isAllied ? Info.LaunchSound : Info.IncomingSound);
|
||||
|
||||
var speech = isAllied ? Info.LaunchSpeechNotification : Info.IncomingSpeechNotification;
|
||||
Game.Sound.PlayNotification(Self.World.Map.Rules, localPlayer, "Speech", speech, localPlayer.Faction.InternalName);
|
||||
|
||||
var text = isAllied ? Info.LaunchTextNotification : Info.IncomingTextNotification;
|
||||
TextNotificationsManager.AddTransientLine(localPlayer, text);
|
||||
}
|
||||
|
||||
public IEnumerable<CPos> CellsMatching(CPos location, char[] footprint, CVec dimensions)
|
||||
{
|
||||
var index = 0;
|
||||
var x = location.X - (dimensions.X - 1) / 2;
|
||||
var y = location.Y - (dimensions.Y - 1) / 2;
|
||||
for (var j = 0; j < dimensions.Y; j++)
|
||||
for (var i = 0; i < dimensions.X; i++)
|
||||
if (footprint[index++] == 'x')
|
||||
yield return new CPos(x + i, y + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
321
OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs
Normal file
321
OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs
Normal file
@@ -0,0 +1,321 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.Player)]
|
||||
[Desc("Attach this to the player actor.")]
|
||||
public class SupportPowerManagerInfo : TraitInfo, Requires<DeveloperModeInfo>, Requires<TechTreeInfo>
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new SupportPowerManager(init); }
|
||||
}
|
||||
|
||||
public class SupportPowerManager : ITick, IResolveOrder, ITechTreeElement
|
||||
{
|
||||
public readonly Actor Self;
|
||||
public readonly Dictionary<string, SupportPowerInstance> Powers = [];
|
||||
|
||||
public readonly DeveloperMode DevMode;
|
||||
public readonly TechTree TechTree;
|
||||
public readonly Lazy<RadarPings> RadarPings;
|
||||
|
||||
public SupportPowerManager(ActorInitializer init)
|
||||
{
|
||||
Self = init.Self;
|
||||
DevMode = Self.Trait<DeveloperMode>();
|
||||
TechTree = Self.Trait<TechTree>();
|
||||
RadarPings = Exts.Lazy(Self.World.WorldActor.TraitOrDefault<RadarPings>);
|
||||
|
||||
init.World.ActorAdded += ActorAdded;
|
||||
init.World.ActorRemoved += ActorRemoved;
|
||||
}
|
||||
|
||||
static string MakeKey(SupportPower sp)
|
||||
{
|
||||
return sp.Info.AllowMultiple ? sp.Info.OrderName + "_" + sp.Self.ActorID : sp.Info.OrderName;
|
||||
}
|
||||
|
||||
void ActorAdded(Actor a)
|
||||
{
|
||||
if (a.Owner != Self.Owner)
|
||||
return;
|
||||
|
||||
foreach (var t in a.TraitsImplementing<SupportPower>())
|
||||
{
|
||||
var key = MakeKey(t);
|
||||
|
||||
if (!Powers.TryGetValue(key, out var spi))
|
||||
{
|
||||
Powers.Add(key, spi = t.CreateInstance(key, this));
|
||||
|
||||
if (t.Info.Prerequisites.Length > 0)
|
||||
{
|
||||
TechTree.Add(key, t.Info.Prerequisites, 0, this);
|
||||
TechTree.Update();
|
||||
}
|
||||
}
|
||||
|
||||
spi.Instances.Add(t);
|
||||
}
|
||||
}
|
||||
|
||||
void ActorRemoved(Actor a)
|
||||
{
|
||||
if (a.Owner != Self.Owner || !a.Info.HasTraitInfo<SupportPowerInfo>())
|
||||
return;
|
||||
|
||||
foreach (var t in a.TraitsImplementing<SupportPower>())
|
||||
{
|
||||
var key = MakeKey(t);
|
||||
Powers[key].Instances.Remove(t);
|
||||
|
||||
if (Powers[key].Instances.Count == 0 && !Powers[key].Disabled)
|
||||
{
|
||||
Powers.Remove(key);
|
||||
TechTree.Remove(key);
|
||||
TechTree.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ITick.Tick(Actor self)
|
||||
{
|
||||
foreach (var power in Powers.Values)
|
||||
power.Tick();
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
// order.OrderString is the key of the support power
|
||||
if (Powers.TryGetValue(order.OrderString, out var sp))
|
||||
sp.Activate(order);
|
||||
}
|
||||
|
||||
static readonly SupportPowerInstance[] NoInstances = [];
|
||||
|
||||
public IEnumerable<SupportPowerInstance> GetPowersForActor(Actor a)
|
||||
{
|
||||
if (Powers.Count == 0 || a.Owner != Self.Owner || !a.Info.HasTraitInfo<SupportPowerInfo>())
|
||||
return NoInstances;
|
||||
|
||||
return a.TraitsImplementing<SupportPower>()
|
||||
.Select(t => Powers[MakeKey(t)])
|
||||
.Where(p => p.Instances.Any(i => !i.IsTraitDisabled && i.Self == a));
|
||||
}
|
||||
|
||||
public void PrerequisitesAvailable(string key)
|
||||
{
|
||||
if (!Powers.TryGetValue(key, out var sp))
|
||||
return;
|
||||
|
||||
sp.PrerequisitesAvailable(true);
|
||||
}
|
||||
|
||||
public void PrerequisitesUnavailable(string key)
|
||||
{
|
||||
if (!Powers.TryGetValue(key, out var sp))
|
||||
return;
|
||||
|
||||
sp.PrerequisitesAvailable(false);
|
||||
}
|
||||
|
||||
public void PrerequisitesItemHidden(string key) { }
|
||||
public void PrerequisitesItemVisible(string key) { }
|
||||
}
|
||||
|
||||
public class SupportPowerInstance
|
||||
{
|
||||
protected readonly SupportPowerManager Manager;
|
||||
|
||||
public readonly string Key;
|
||||
|
||||
public readonly List<SupportPower> Instances = [];
|
||||
public readonly int TotalTicks;
|
||||
|
||||
protected int remainingSubTicks;
|
||||
public int RemainingTicks => remainingSubTicks / 100;
|
||||
public bool Active { get; private set; }
|
||||
public bool Disabled =>
|
||||
Manager.Self.Owner.WinState == WinState.Lost ||
|
||||
(!prereqsAvailable && !Manager.DevMode.AllTech) ||
|
||||
!instancesEnabled ||
|
||||
oneShotFired;
|
||||
|
||||
public SupportPowerInfo Info { get { return Instances.Select(i => i.Info).FirstOrDefault(); } }
|
||||
public readonly string Name;
|
||||
public readonly string Description;
|
||||
public bool Ready => Active && RemainingTicks == 0;
|
||||
|
||||
bool instancesEnabled;
|
||||
bool prereqsAvailable = true;
|
||||
bool oneShotFired;
|
||||
protected bool notifiedCharging;
|
||||
bool notifiedReady;
|
||||
|
||||
public void ResetTimer()
|
||||
{
|
||||
remainingSubTicks = TotalTicks * 100;
|
||||
}
|
||||
|
||||
public SupportPowerInstance(string key, SupportPowerInfo info, SupportPowerManager manager)
|
||||
{
|
||||
Key = key;
|
||||
TotalTicks = info.ChargeInterval;
|
||||
remainingSubTicks = info.StartFullyCharged ? 0 : TotalTicks * 100;
|
||||
Name = info.Name == null ? string.Empty : FluentProvider.GetMessage(info.Name);
|
||||
Description = info.Description == null ? string.Empty : FluentProvider.GetMessage(info.Description);
|
||||
|
||||
Manager = manager;
|
||||
}
|
||||
|
||||
public virtual void PrerequisitesAvailable(bool available)
|
||||
{
|
||||
prereqsAvailable = available;
|
||||
|
||||
if (!available)
|
||||
remainingSubTicks = TotalTicks * 100;
|
||||
}
|
||||
|
||||
public virtual void Tick()
|
||||
{
|
||||
instancesEnabled = Instances.Any(i => !i.IsTraitDisabled);
|
||||
if (!instancesEnabled)
|
||||
remainingSubTicks = TotalTicks * 100;
|
||||
|
||||
Active = !Disabled && Instances.Any(i => !i.IsTraitPaused);
|
||||
if (!Active)
|
||||
return;
|
||||
|
||||
var power = Instances[0];
|
||||
if (Manager.DevMode.FastCharge && remainingSubTicks > 2500)
|
||||
remainingSubTicks = 2500;
|
||||
|
||||
if (remainingSubTicks > 0)
|
||||
remainingSubTicks = (remainingSubTicks - 100).Clamp(0, TotalTicks * 100);
|
||||
|
||||
if (!notifiedCharging)
|
||||
{
|
||||
power.Charging(power.Self, Key);
|
||||
notifiedCharging = true;
|
||||
}
|
||||
|
||||
if (RemainingTicks == 0 && !notifiedReady)
|
||||
{
|
||||
power.Charged(power.Self, Key);
|
||||
notifiedReady = true;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Target()
|
||||
{
|
||||
if (!Ready)
|
||||
return;
|
||||
|
||||
var power = Instances.FirstOrDefault(i => !i.IsTraitPaused);
|
||||
|
||||
if (power == null)
|
||||
return;
|
||||
|
||||
Game.Sound.PlayToPlayer(SoundType.UI, Manager.Self.Owner, Info.SelectTargetSound);
|
||||
Game.Sound.PlayNotification(power.Self.World.Map.Rules, power.Self.Owner, "Speech",
|
||||
Info.SelectTargetSpeechNotification, power.Self.Owner.Faction.InternalName);
|
||||
|
||||
TextNotificationsManager.AddTransientLine(power.Self.Owner, Info.SelectTargetTextNotification);
|
||||
|
||||
power.SelectTarget(power.Self, Key, Manager);
|
||||
}
|
||||
|
||||
public virtual void Activate(Order order)
|
||||
{
|
||||
if (!Ready)
|
||||
return;
|
||||
|
||||
var power = Instances.Where(i => !i.IsTraitPaused && !i.IsTraitDisabled)
|
||||
.MinByOrDefault(a =>
|
||||
{
|
||||
if (a.Self.OccupiesSpace == null || order.Target.Type == TargetType.Invalid)
|
||||
return 0;
|
||||
|
||||
return (a.Self.CenterPosition - order.Target.CenterPosition).HorizontalLengthSquared;
|
||||
});
|
||||
|
||||
if (power == null)
|
||||
return;
|
||||
|
||||
// Note: order.Subject is the *player* actor
|
||||
power.Activate(power.Self, order, Manager);
|
||||
remainingSubTicks = TotalTicks * 100;
|
||||
notifiedCharging = notifiedReady = false;
|
||||
|
||||
if (Info.OneShot)
|
||||
{
|
||||
PrerequisitesAvailable(false);
|
||||
oneShotFired = true;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string IconOverlayTextOverride()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual string TooltipTimeTextOverride()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class SelectGenericPowerTarget : OrderGenerator
|
||||
{
|
||||
protected override MouseActionType ActionType => MouseActionType.SupportPower;
|
||||
readonly SupportPowerManager manager;
|
||||
readonly SupportPowerInfo info;
|
||||
|
||||
public string OrderKey { get; }
|
||||
|
||||
public SelectGenericPowerTarget(string order, SupportPowerManager manager, SupportPowerInfo info)
|
||||
: base(manager.Self.World)
|
||||
{
|
||||
this.manager = manager;
|
||||
OrderKey = order;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
world.CancelInputMode();
|
||||
if (world.Map.Contains(cell))
|
||||
yield return new Order(OrderKey, manager.Self, Target.FromCell(world, cell), false) { SuppressVisualFeedback = true };
|
||||
}
|
||||
|
||||
protected override void Tick(World world)
|
||||
{
|
||||
// Cancel the OG if we can't use the power
|
||||
if (!manager.Powers.TryGetValue(OrderKey, out var p) || !p.Active || !p.Ready)
|
||||
world.CancelInputMode();
|
||||
}
|
||||
|
||||
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
||||
protected override IEnumerable<IRenderable> RenderAnnotations(WorldRenderer wr, World world) { yield break; }
|
||||
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
return world.Map.Contains(cell) ? info.Cursor : info.BlockedCursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user