Add a lua function for beacons

This commit is contained in:
abcdefg30
2015-06-22 18:49:23 +02:00
parent 31986469a9
commit a4fd34558d
3 changed files with 50 additions and 1 deletions

View File

@@ -12,10 +12,11 @@ using System;
using System.Collections.Generic;
using OpenRA.Effects;
using OpenRA.Graphics;
using OpenRA.Scripting;
namespace OpenRA.Mods.Common.Effects
{
public class Beacon : IEffect
public class Beacon : IEffect, IScriptBindable
{
static readonly int MaxArrowHeight = 512;

View File

@@ -213,6 +213,7 @@
<Compile Include="Scripting\Media.cs" />
<Compile Include="Scripting\ScriptTriggers.cs" />
<Compile Include="Scripting\Global\ActorGlobal.cs" />
<Compile Include="Scripting\Global\BeaconGlobal.cs" />
<Compile Include="Scripting\Global\CameraGlobal.cs" />
<Compile Include="Scripting\Global\CoordinateGlobals.cs" />
<Compile Include="Scripting\Global\DateTimeGlobal.cs" />

View File

@@ -0,0 +1,47 @@
#region Copyright & License Information
/*
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Linq;
using OpenRA.Mods.Common.Effects;
using OpenRA.Mods.Common.Traits;
using OpenRA.Scripting;
namespace OpenRA.Mods.Common.Scripting
{
[ScriptGlobal("Beacon")]
public class BeaconGlobal : ScriptGlobal
{
readonly RadarPings radarPings;
public BeaconGlobal(ScriptContext context) : base(context)
{
radarPings = context.World.WorldActor.TraitOrDefault<RadarPings>();
}
[Desc("Creates a new beacon that stays for the specified time at the specified WPos." +
"Does not remove player set beacons, nor gets removed by placing them.")]
public Beacon New(Player owner, WPos position, int duration = 30 * 25, bool showRadarPings = true, string palettePrefix = "player")
{
var playerBeacon = new Beacon(owner, position, duration, palettePrefix);
owner.PlayerActor.World.AddFrameEndTask(w => w.Add(playerBeacon));
if (showRadarPings && radarPings != null)
{
radarPings.Add(
() => owner.IsAlliedWith(owner.World.RenderPlayer),
position,
owner.Color.RGB,
duration);
}
return playerBeacon;
}
}
}