Merge pull request #10756 from Mailaender/ts-beacon

Added the Tiberian Sun beacon
This commit is contained in:
Oliver Brakmann
2016-04-26 21:28:22 +02:00
5 changed files with 152 additions and 9 deletions

View File

@@ -0,0 +1,64 @@
#region Copyright & License Information
/*
* Copyright 2007-2016 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, 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.Effects;
using OpenRA.Graphics;
using OpenRA.Scripting;
namespace OpenRA.Mods.TS.Effects
{
public class AnimatedBeacon : IEffect
{
readonly Player owner;
readonly WPos position;
readonly string beaconPalette;
readonly bool isPlayerPalette;
readonly Animation beacon;
public AnimatedBeacon(Player owner, WPos position, int duration, string beaconPalette, bool isPlayerPalette, string beaconImage, string beaconSequence)
{
this.owner = owner;
this.position = position;
this.beaconPalette = beaconPalette;
this.isPlayerPalette = isPlayerPalette;
if (!string.IsNullOrEmpty(beaconSequence))
{
beacon = new Animation(owner.World, beaconImage);
beacon.PlayRepeating(beaconSequence);
}
if (duration > 0)
owner.World.Add(new DelayedAction(duration, () => owner.World.Remove(this)));
}
public void Tick(World world)
{
if (beacon != null)
beacon.Tick();
}
public IEnumerable<IRenderable> Render(WorldRenderer r)
{
if (beacon == null)
return Enumerable.Empty<IRenderable>();
if (!owner.IsAlliedWith(owner.World.RenderPlayer))
return Enumerable.Empty<IRenderable>();
var palette = r.Palette(isPlayerPalette ? beaconPalette + owner.InternalName : beaconPalette);
return beacon.Render(position, palette);
}
}
}

View File

@@ -77,6 +77,8 @@
<Compile Include="UtilityCommands\LegacyTilesetImporter.cs" /> <Compile Include="UtilityCommands\LegacyTilesetImporter.cs" />
<Compile Include="Traits\World\TSShroudPalette.cs" /> <Compile Include="Traits\World\TSShroudPalette.cs" />
<Compile Include="UtilityCommands\ImportTSMapCommand.cs" /> <Compile Include="UtilityCommands\ImportTSMapCommand.cs" />
<Compile Include="Player\PlaceSimpleBeacon.cs" />
<Compile Include="Effects\AnimatedBeacon.cs" />
</ItemGroup> </ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -0,0 +1,81 @@
#region Copyright & License Information
/*
* Copyright 2007-2016 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.TS.Effects;
using OpenRA.Traits;
namespace OpenRA.Mods.TS.Traits
{
[Desc("A beacon that consists of a single sprite that can be animated.")]
public class PlaceSimpleBeaconInfo : ITraitInfo
{
public readonly int Duration = 30 * 25;
public readonly string NotificationType = "Sounds";
public readonly string Notification = "Beacon";
public readonly bool IsPlayerPalette = false;
[PaletteReference("IsPlayerPalette")] public readonly string Palette = "effect";
public readonly string BeaconImage = "beacon";
[SequenceReference("BeaconImage")] public readonly string BeaconSequence = "idle";
public object Create(ActorInitializer init) { return new PlaceSimpleBeacon(init.Self, this); }
}
public class PlaceSimpleBeacon : IResolveOrder
{
readonly PlaceSimpleBeaconInfo info;
readonly RadarPings radarPings;
AnimatedBeacon playerBeacon;
RadarPing playerRadarPing;
public PlaceSimpleBeacon(Actor self, PlaceSimpleBeaconInfo info)
{
radarPings = self.World.WorldActor.TraitOrDefault<RadarPings>();
this.info = info;
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString != "PlaceBeacon")
return;
var pos = self.World.Map.CenterOfCell(order.TargetLocation);
self.World.AddFrameEndTask(w =>
{
if (playerBeacon != null)
self.World.Remove(playerBeacon);
playerBeacon = new AnimatedBeacon(self.Owner, pos, info.Duration, info.Palette, info.IsPlayerPalette, info.BeaconImage, info.BeaconSequence);
self.World.Add(playerBeacon);
if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
Game.Sound.PlayNotification(self.World.Map.Rules, null, info.NotificationType, info.Notification,
self.World.RenderPlayer != null ? self.World.RenderPlayer.Faction.InternalName : null);
if (radarPings != null)
{
if (playerRadarPing != null)
radarPings.Remove(playerRadarPing);
playerRadarPing = radarPings.Add(
() => self.Owner.IsAlliedWith(self.World.RenderPlayer),
pos,
self.Owner.Color.RGB,
info.Duration);
}
});
}
}
}

View File

@@ -50,5 +50,5 @@ Player:
AllyNotification: OurAllyIsUnderAttack AllyNotification: OurAllyIsUnderAttack
HarvesterAttackNotifier: HarvesterAttackNotifier:
PlayerStatistics: PlayerStatistics:
PlaceBeacon: PlaceSimpleBeacon:
ResourceStorageWarning: ResourceStorageWarning:

View File

@@ -34,13 +34,9 @@ rallypoint:
circles: null circles: null
beacon: beacon:
arrow: mouse idle:
Start: 6 Length: 5
Offset: 1,-12 Tick: 200
ZOffset: 2535
circles: ring
Length: 12
BlendMode: Additive
ZOffset: 2047 ZOffset: 2047
crate: crate: