Merge pull request #4179 from ScottNZ/lua

Lua stuffs
This commit is contained in:
Paul Chote
2013-11-29 14:17:17 -08:00
34 changed files with 2679 additions and 48 deletions

View File

@@ -738,8 +738,8 @@ namespace OpenRA.Mods.RA.AI
if (desiredLocation == null)
continue;
world.IssueOrder(new Order("Move", mcv, false) { TargetLocation = desiredLocation.Value });
world.IssueOrder(new Order("DeployTransform", mcv, false));
world.IssueOrder(new Order("Move", mcv, true) { TargetLocation = desiredLocation.Value });
world.IssueOrder(new Order("DeployTransform", mcv, true));
}
}

View File

@@ -0,0 +1,48 @@
#region Copyright & License Information
/*
* Copyright 2007-2013 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.Linq;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Move;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
public class Hunt : Activity
{
readonly IEnumerable<Actor> targets;
public Hunt(Actor self)
{
var attack = self.Trait<AttackBase>();
targets = self.World.Actors.Where(a => self != a && !a.IsDead() && a.IsInWorld && a.AppearsHostileTo(self)
&& a.HasTrait<Huntable>() && attack.HasAnyValidWeapons(Target.FromActor(a)));
}
public override Activity Tick(Actor self)
{
if (IsCanceled)
return NextActivity;
var target = targets.ClosestTo(self);
if (target == null)
return this;
return Util.SequenceActivities(
new AttackMove.AttackMoveActivity(self, new Move.Move(target.Location, WRange.FromCells(2))),
new Wait(25),
this);
}
}
public class HuntableInfo : TraitInfo<Huntable> { }
public class Huntable { }
}

View File

@@ -81,6 +81,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Activities\CaptureActor.cs" />
<Compile Include="Activities\Hunt.cs" />
<Compile Include="AI\AttackOrFleeFuzzy.cs" />
<Compile Include="AI\BaseBuilder.cs" />
<Compile Include="AI\HackyAI.cs" />
@@ -338,6 +339,7 @@
<Compile Include="RepairsUnits.cs" />
<Compile Include="Reservable.cs" />
<Compile Include="ScaredyCat.cs" />
<Compile Include="Scripting\LuaScriptEvents.cs" />
<Compile Include="Scripting\LuaScriptInterface.cs" />
<Compile Include="Scripting\Media.cs" />
<Compile Include="Scripting\RASpecialPowers.cs" />

View File

@@ -0,0 +1,40 @@
#region Copyright & License Information
/*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Scripting
{
public class LuaScriptEventsInfo : TraitInfo<LuaScriptEvents> { }
public class LuaScriptEvents : INotifyKilled, INotifyAddedToWorld, INotifyRemovedFromWorld
{
public event Action<Actor, AttackInfo> OnKilled = (self, e) => { };
public event Action<Actor> OnAddedToWorld = self => { };
public event Action<Actor> OnRemovedFromWorld = self => { };
public void Killed(Actor self, AttackInfo e)
{
OnKilled(self, e);
}
public void AddedToWorld(Actor self)
{
OnAddedToWorld(self);
}
public void RemovedFromWorld(Actor self)
{
OnRemovedFromWorld(self);
}
}
}

View File

@@ -8,12 +8,16 @@
*/
#endregion
using System;
using System.Linq;
using LuaInterface;
using OpenRA.Effects;
using OpenRA.FileFormats;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Air;
using OpenRA.Mods.RA.Missions;
using OpenRA.Scripting;
using OpenRA.Traits;
using System;
using System.Linq;
using WorldRenderer = OpenRA.Graphics.WorldRenderer;
namespace OpenRA.Mods.RA.Scripting
@@ -42,7 +46,7 @@ namespace OpenRA.Mods.RA.Scripting
AddMapActorGlobals();
context.Lua["World"] = w;
context.Lua["WorldRenderer"] = wr;
context.RegisterObject(this, "_OpenRA", false);
context.RegisterObject(this, "Internal", false);
context.RegisterType(typeof(WVec), "WVec", true);
context.RegisterType(typeof(WPos), "WPos", true);
context.RegisterType(typeof(CPos), "CPos", true);
@@ -161,5 +165,101 @@ namespace OpenRA.Mods.RA.Scripting
{
world.AddFrameEndTask(w => w.Add(new DelayedAction((int)delay, func)));
}
[LuaGlobal]
public void PlaySpeechNotification(Player player, string notification)
{
Sound.PlayNotification(player, "Speech", notification, player != null ? player.Country.Race : null);
}
[LuaGlobal]
public void PlaySoundNotification(Player player, string notification)
{
Sound.PlayNotification(player, "Sounds", notification, player != null ? player.Country.Race : null);
}
[LuaGlobal]
public void WaitFor(Actor actor, Func<bool> func)
{
actor.QueueActivity(new WaitFor(func));
}
[LuaGlobal]
public void CallFunc(Actor actor, Action func)
{
actor.QueueActivity(new CallFunc(func));
}
[LuaGlobal]
public int GetFacing(object vec, double currentFacing)
{
if (vec is CVec)
return Util.GetFacing((CVec)vec, (int)currentFacing);
if (vec is WVec)
return Util.GetFacing((WVec)vec, (int)currentFacing);
throw new ArgumentException("Unsupported vector type: {0}".F(vec.GetType()));
}
[LuaGlobal]
public WRange GetWRangeFromCells(double cells)
{
return WRange.FromCells((int)cells);
}
[LuaGlobal]
public void SetWinState(Player player, string winState)
{
player.WinState = Enum<WinState>.Parse(winState);
}
[LuaGlobal]
public void PlayRandomMusic()
{
MissionUtils.PlayMissionMusic();
}
[LuaGlobal]
public bool IsDead(Actor actor)
{
return actor.IsDead();
}
[LuaGlobal]
public void PlayMovieFullscreen(string movie, Action onComplete)
{
Media.PlayFMVFullscreen(world, movie, onComplete);
}
[LuaGlobal]
public void FlyToPos(Actor actor, WPos pos)
{
actor.QueueActivity(Fly.ToPos(pos));
}
[LuaGlobal]
public void FlyAttackActor(Actor actor, Actor targetActor)
{
actor.QueueActivity(new FlyAttack(Target.FromActor(targetActor)));
}
[LuaGlobal]
public void FlyAttackCell(Actor actor, CPos location)
{
actor.QueueActivity(new FlyAttack(Target.FromCell(location)));
}
[LuaGlobal]
public void SetUnitStance(Actor actor, string stance)
{
var at = actor.TraitOrDefault<AutoTarget>();
if (at != null)
at.stance = Enum<UnitStance>.Parse(stance);
}
[LuaGlobal]
public bool RequiredUnitsAreDestroyed(Player player)
{
return world.ActorsWithTrait<MustBeDestroyed>().All(p => p.Actor.Owner != player);
}
}
}

View File

@@ -68,29 +68,31 @@ namespace OpenRA.Mods.RA
return null;
}
public void DeployTransform()
{
var b = self.TraitOrDefault<Building>();
if (!CanDeploy() || (b != null && !b.Lock()))
{
foreach (var s in Info.NoTransformSounds)
Sound.PlayToPlayer(self.Owner, s);
return;
}
if (self.HasTrait<IFacing>())
self.QueueActivity(new Turn(Info.Facing));
var rb = self.TraitOrDefault<RenderBuilding>();
if (rb != null && self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation)
self.QueueActivity(new MakeAnimation(self, true, () => rb.PlayCustomAnim(self, "make")));
self.QueueActivity(new Transform(self, Info.IntoActor) { Offset = (CVec)Info.Offset, Facing = Info.Facing, Sounds = Info.TransformSounds });
}
public void ResolveOrder( Actor self, Order order )
{
if (order.OrderString == "DeployTransform")
{
var b = self.TraitOrDefault<Building>();
if (!CanDeploy() || (b != null && !b.Lock()))
{
foreach (var s in Info.NoTransformSounds)
Sound.PlayToPlayer(self.Owner, s);
return;
}
self.CancelActivity();
if (self.HasTrait<IFacing>())
self.QueueActivity(new Turn(Info.Facing));
var rb = self.TraitOrDefault<RenderBuilding>();
if (rb != null && self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation)
self.QueueActivity(new MakeAnimation(self, true, () => rb.PlayCustomAnim(self, "make")));
self.QueueActivity(new Transform(self, Info.IntoActor) { Offset = (CVec)Info.Offset, Facing = Info.Facing, Sounds = Info.TransformSounds });
}
DeployTransform();
}
}
}