Moves nearly all ScriptingProperties to Mods.Common
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
#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 Eluant;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ScriptGlobal("Air Support Powers")]
|
||||
public class AirstrikeProperties : ScriptActorProperties, Requires<AirstrikePowerInfo>
|
||||
{
|
||||
readonly AirstrikePower ap;
|
||||
|
||||
public AirstrikeProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
ap = self.TraitsImplementing<AirstrikePower>().First();
|
||||
}
|
||||
|
||||
[Desc("Activate the actor's Airstrike Power.")]
|
||||
public void SendAirstrike(WPos target, bool randomize = true, int facing = 0)
|
||||
{
|
||||
ap.SendAirstrike(Self, target, randomize, facing);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
#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;
|
||||
using System.Linq;
|
||||
using Eluant;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ScriptPropertyGroup("Combat")]
|
||||
public class CombatProperties : ScriptActorProperties, Requires<AttackBaseInfo>, Requires<IMoveInfo>
|
||||
{
|
||||
readonly IMove move;
|
||||
|
||||
public CombatProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
move = self.Trait<IMove>();
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Seek out and attack nearby targets.")]
|
||||
public void Hunt()
|
||||
{
|
||||
Self.QueueActivity(new Hunt(Self));
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Move to a cell, but stop and attack anything within range on the way. " +
|
||||
"closeEnough defines an optional range (in cells) that will be considered " +
|
||||
"close enough to complete the activity.")]
|
||||
public void AttackMove(CPos cell, int closeEnough = 0)
|
||||
{
|
||||
Self.QueueActivity(new AttackMoveActivity(Self, move.MoveTo(cell, closeEnough)));
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Patrol along a set of given waypoints. The action is repeated by default, " +
|
||||
"and the actor will wait for `wait` ticks at each waypoint.")]
|
||||
public void Patrol(CPos[] waypoints, bool loop = true, int wait = 0)
|
||||
{
|
||||
foreach (var wpt in waypoints)
|
||||
{
|
||||
Self.QueueActivity(new AttackMoveActivity(Self, move.MoveTo(wpt, 2)));
|
||||
Self.QueueActivity(new Wait(wait));
|
||||
}
|
||||
|
||||
if (loop)
|
||||
Self.QueueActivity(new CallFunc(() => Patrol(waypoints, loop, wait)));
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Patrol along a set of given waypoints until a condition becomes true. " +
|
||||
"The actor will wait for `wait` ticks at each waypoint.")]
|
||||
public void PatrolUntil(CPos[] waypoints, LuaFunction func, int wait = 0)
|
||||
{
|
||||
Patrol(waypoints, false, wait);
|
||||
|
||||
var repeat = func.Call(Self.ToLuaValue(Context)).First().ToBoolean();
|
||||
if (repeat)
|
||||
using (var f = func.CopyReference() as LuaFunction)
|
||||
Self.QueueActivity(new CallFunc(() => PatrolUntil(waypoints, f, wait)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
#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 Eluant;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ExposedForDestroyedActors]
|
||||
[ScriptPropertyGroup("General")]
|
||||
public class BaseActorProperties : ScriptActorProperties
|
||||
{
|
||||
// Note: This class must not make any trait queries so that this
|
||||
// remains safe to call on dead actors.
|
||||
public BaseActorProperties(ScriptContext context, Actor self)
|
||||
: base(context, self) { }
|
||||
|
||||
[Desc("Specifies whether the actor is in the world.")]
|
||||
public bool IsInWorld
|
||||
{
|
||||
get
|
||||
{
|
||||
return Self.IsInWorld;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
Self.World.AddFrameEndTask(w => w.Add(Self));
|
||||
else
|
||||
Self.World.AddFrameEndTask(w => w.Remove(Self));
|
||||
}
|
||||
}
|
||||
|
||||
[Desc("Specifies whether the actor is alive or dead.")]
|
||||
public bool IsDead { get { return Self.IsDead; } }
|
||||
|
||||
[Desc("Specifies whether the actor is idle (not performing any activities).")]
|
||||
public bool IsIdle { get { return Self.IsIdle; } }
|
||||
|
||||
[Desc("The player that owns the actor.")]
|
||||
public Player Owner
|
||||
{
|
||||
get
|
||||
{
|
||||
return Self.Owner;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (Self.Owner != value)
|
||||
Self.ChangeOwner(value);
|
||||
}
|
||||
}
|
||||
|
||||
[Desc("The type of the actor (e.g. \"e1\").")]
|
||||
public string Type { get { return Self.Info.Name; } }
|
||||
|
||||
[Desc("Test whether an actor has a specific property.")]
|
||||
public bool HasProperty(string name)
|
||||
{
|
||||
return Self.HasScriptProperty(name);
|
||||
}
|
||||
}
|
||||
|
||||
[ScriptPropertyGroup("General")]
|
||||
public class GeneralProperties : ScriptActorProperties
|
||||
{
|
||||
readonly IFacing facing;
|
||||
readonly AutoTarget autotarget;
|
||||
|
||||
public GeneralProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
facing = self.TraitOrDefault<IFacing>();
|
||||
autotarget = self.TraitOrDefault<AutoTarget>();
|
||||
}
|
||||
|
||||
[Desc("The actor position in cell coordinates.")]
|
||||
public CPos Location { get { return Self.Location; } }
|
||||
|
||||
[Desc("The actor position in world coordinates.")]
|
||||
public WPos CenterPosition { get { return Self.CenterPosition; } }
|
||||
|
||||
[Desc("The direction that the actor is facing.")]
|
||||
public int Facing
|
||||
{
|
||||
get
|
||||
{
|
||||
if (facing == null)
|
||||
throw new LuaException("Actor '{0}' doesn't define a facing".F(Self));
|
||||
|
||||
return facing.Facing;
|
||||
}
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Instantly moves the actor to the specified cell.")]
|
||||
public void Teleport(CPos cell)
|
||||
{
|
||||
Self.QueueActivity(new SimpleTeleport(cell));
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Run an arbitrary Lua function.")]
|
||||
public void CallFunc(LuaFunction func)
|
||||
{
|
||||
Self.QueueActivity(new CallLuaFunc(func, Context));
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Wait for a specified number of game ticks (25 ticks = 1 second).")]
|
||||
public void Wait(int ticks)
|
||||
{
|
||||
Self.QueueActivity(new Wait(ticks));
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Remove the actor from the game, without triggering any death notification.")]
|
||||
public void Destroy()
|
||||
{
|
||||
Self.QueueActivity(new RemoveSelf());
|
||||
}
|
||||
|
||||
[Desc("Attempt to cancel any active activities.")]
|
||||
public void Stop()
|
||||
{
|
||||
Self.CancelActivity();
|
||||
}
|
||||
|
||||
[Desc("Current actor stance. Returns nil if this actor doesn't support stances.")]
|
||||
public string Stance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (autotarget == null)
|
||||
return null;
|
||||
|
||||
return autotarget.Stance.ToString();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (autotarget == null)
|
||||
return;
|
||||
|
||||
UnitStance stance;
|
||||
if (!Enum<UnitStance>.TryParse(value, true, out stance))
|
||||
throw new LuaException("Unknown stance type '{0}'".F(value));
|
||||
|
||||
autotarget.Stance = stance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
#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 OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ScriptPropertyGroup("Guard")]
|
||||
public class GuardProperties : ScriptActorProperties, Requires<GuardInfo>, Requires<IMoveInfo>
|
||||
{
|
||||
Guard guard;
|
||||
public GuardProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
guard = self.Trait<Guard>();
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Guard the target actor.")]
|
||||
public void Guard(Actor targetActor)
|
||||
{
|
||||
if (targetActor.HasTrait<Guardable>())
|
||||
guard.GuardTarget(Self, Target.FromActor(targetActor));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
#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 OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ScriptPropertyGroup("Movement")]
|
||||
public class HelicopterProperties : ScriptActorProperties, Requires<HelicopterInfo>
|
||||
{
|
||||
public HelicopterProperties(ScriptContext context, Actor self)
|
||||
: base(context, self) { }
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Fly within the cell grid.")]
|
||||
public void Move(CPos cell)
|
||||
{
|
||||
Self.QueueActivity(new HeliFly(Self, Target.FromCell(Self.World, cell)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
#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;
|
||||
using Eluant;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ScriptPropertyGroup("MissionObjectives")]
|
||||
public class MissionObjectiveProperties : ScriptPlayerProperties
|
||||
{
|
||||
readonly MissionObjectives mo;
|
||||
|
||||
public MissionObjectiveProperties(ScriptContext context, Player player)
|
||||
: base(context, player)
|
||||
{
|
||||
mo = player.PlayerActor.Trait<MissionObjectives>();
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Add a primary mission objective for this player. The function returns the " +
|
||||
"ID of the newly created objective, so that it can be referred to later.")]
|
||||
public int AddPrimaryObjective(string description)
|
||||
{
|
||||
return mo.Add(Player, description, ObjectiveType.Primary);
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Add a secondary mission objective for this player. The function returns the " +
|
||||
"ID of the newly created objective, so that it can be referred to later.")]
|
||||
public int AddSecondaryObjective(string description)
|
||||
{
|
||||
return mo.Add(Player, description, ObjectiveType.Secondary);
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Mark an objective as completed. This needs the objective ID returned " +
|
||||
"by AddObjective as argument. When this player has completed all primary " +
|
||||
"objectives, (s)he has won the game.")]
|
||||
public void MarkCompletedObjective(int id)
|
||||
{
|
||||
if (id < 0 || id >= mo.Objectives.Count)
|
||||
throw new LuaException("Objective ID is out of range.");
|
||||
|
||||
mo.MarkCompleted(Player, id);
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Mark an objective as failed. This needs the objective ID returned " +
|
||||
"by AddObjective as argument. Secondary objectives do not have any " +
|
||||
"influence whatsoever on the outcome of the game.")]
|
||||
public void MarkFailedObjective(int id)
|
||||
{
|
||||
if (id < 0 || id >= mo.Objectives.Count)
|
||||
throw new LuaException("Objective ID is out of range.");
|
||||
|
||||
mo.MarkFailed(Player, id);
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Returns true if the objective has been successfully completed, false otherwise.")]
|
||||
public bool IsObjectiveCompleted(int id)
|
||||
{
|
||||
if (id < 0 || id >= mo.Objectives.Count)
|
||||
throw new LuaException("Objective ID is out of range.");
|
||||
|
||||
return mo.Objectives[id].State == ObjectiveState.Completed;
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Returns true if the objective has been failed, false otherwise.")]
|
||||
public bool IsObjectiveFailed(int id)
|
||||
{
|
||||
if (id < 0 || id >= mo.Objectives.Count)
|
||||
throw new LuaException("Objective ID is out of range.");
|
||||
|
||||
return mo.Objectives[id].State == ObjectiveState.Failed;
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Returns the description of an objective.")]
|
||||
public string GetObjectiveDescription(int id)
|
||||
{
|
||||
if (id < 0 || id >= mo.Objectives.Count)
|
||||
throw new LuaException("Objective ID is out of range.");
|
||||
|
||||
return mo.Objectives[id].Description;
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Returns the type of an objective.")]
|
||||
public string GetObjectiveType(int id)
|
||||
{
|
||||
if (id < 0 || id >= mo.Objectives.Count)
|
||||
throw new LuaException("Objective ID is out of range.");
|
||||
|
||||
return mo.Objectives[id].Type == ObjectiveType.Primary ? "Primary" : "Secondary";
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Returns true if this player has lost all units/actors that have" +
|
||||
"the MustBeDestroyed trait (according to the short game option).")]
|
||||
public bool HasNoRequiredUnits()
|
||||
{
|
||||
return Player.HasNoRequiredUnits();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
#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 OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ScriptPropertyGroup("Movement")]
|
||||
public class MobileProperties : ScriptActorProperties, Requires<MobileInfo>
|
||||
{
|
||||
readonly Mobile mobile;
|
||||
|
||||
public MobileProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Moves within the cell grid. closeEnough defines an optional range " +
|
||||
"(in cells) that will be considered close enough to complete the activity.")]
|
||||
public void Move(CPos cell, int closeEnough = 0)
|
||||
{
|
||||
Self.QueueActivity(new Move(Self, cell, WRange.FromCells(closeEnough)));
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Moves within the cell grid, ignoring lane biases.")]
|
||||
public void ScriptedMove(CPos cell)
|
||||
{
|
||||
Self.QueueActivity(new Move(Self, cell));
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Moves from outside the world into the cell grid")]
|
||||
public void MoveIntoWorld(CPos cell)
|
||||
{
|
||||
Self.QueueActivity(mobile.MoveIntoWorld(Self, cell, mobile.ToSubCell));
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Leave the current position in a random direction.")]
|
||||
public void Scatter()
|
||||
{
|
||||
Self.Trait<Mobile>().Nudge(Self, Self, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
#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 OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ScriptPropertyGroup("Movement")]
|
||||
public class PlaneProperties : ScriptActorProperties, Requires<PlaneInfo>
|
||||
{
|
||||
public PlaneProperties(ScriptContext context, Actor self)
|
||||
: base(context, self) { }
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Fly within the cell grid.")]
|
||||
public void Move(CPos cell)
|
||||
{
|
||||
Self.QueueActivity(new Fly(Self, Target.FromCell(Self.World, cell)));
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Return to the base, which is either the airfield given, or an auto-selected one otherwise.")]
|
||||
public void ReturnToBase(Actor airfield = null)
|
||||
{
|
||||
Self.QueueActivity(new ReturnToBase(Self, airfield));
|
||||
}
|
||||
}
|
||||
|
||||
[ScriptPropertyGroup("Combat")]
|
||||
public class PlaneCombatProperties : ScriptActorProperties, Requires<AttackPlaneInfo>
|
||||
{
|
||||
public PlaneCombatProperties(ScriptContext context, Actor self)
|
||||
: base(context, self) { }
|
||||
|
||||
[Desc("Fly an attack against the target actor.")]
|
||||
public void Attack(Actor target)
|
||||
{
|
||||
Self.QueueActivity(new FlyAttack(Target.FromActor(target)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
#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;
|
||||
using System.Linq;
|
||||
using Eluant;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Traits;
|
||||
using OpenRA.Scripting;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ScriptPropertyGroup("Player")]
|
||||
public class PlayerProperties : ScriptPlayerProperties
|
||||
{
|
||||
public PlayerProperties(ScriptContext context, Player player)
|
||||
: base(context, player) { }
|
||||
|
||||
[Desc("The player's name.")]
|
||||
public string Name { get { return Player.PlayerName; } }
|
||||
|
||||
[Desc("Returns an array of actors representing all ground attack units of this player.")]
|
||||
public Actor[] GetGroundAttackers()
|
||||
{
|
||||
return Player.World.ActorsWithTrait<AttackBase>().Select(a => a.Actor)
|
||||
.Where(a => a.Owner == Player && !a.IsDead && a.IsInWorld && a.HasTrait<Mobile>())
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,279 +0,0 @@
|
||||
#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;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Eluant;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Scripting;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ScriptPropertyGroup("Production")]
|
||||
public class ProductionProperties : ScriptActorProperties, Requires<ProductionInfo>
|
||||
{
|
||||
readonly Production p;
|
||||
|
||||
public ProductionProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
p = self.Trait<Production>();
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Build a unit, ignoring the production queue. The activity will wait if the exit is blocked.")]
|
||||
public void Produce(string actorType, string raceVariant = null)
|
||||
{
|
||||
ActorInfo actorInfo;
|
||||
if (!Self.World.Map.Rules.Actors.TryGetValue(actorType, out actorInfo))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(actorType));
|
||||
|
||||
Self.QueueActivity(new WaitFor(() => p.Produce(Self, actorInfo, raceVariant)));
|
||||
}
|
||||
}
|
||||
|
||||
[ScriptPropertyGroup("Production")]
|
||||
public class RallyPointProperties : ScriptActorProperties, Requires<RallyPointInfo>
|
||||
{
|
||||
readonly RallyPoint rp;
|
||||
|
||||
public RallyPointProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
rp = self.Trait<RallyPoint>();
|
||||
}
|
||||
|
||||
[Desc("Query or set a factory's rally point")]
|
||||
public CPos RallyPoint
|
||||
{
|
||||
get { return rp.Location; }
|
||||
set { rp.Location = value; }
|
||||
}
|
||||
}
|
||||
|
||||
[ScriptPropertyGroup("Production")]
|
||||
public class PrimaryBuildingProperties : ScriptActorProperties, Requires<PrimaryBuildingInfo>
|
||||
{
|
||||
readonly PrimaryBuilding pb;
|
||||
|
||||
public PrimaryBuildingProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
pb = self.Trait<PrimaryBuilding>();
|
||||
}
|
||||
|
||||
[Desc("Query or set the factory's primary building status")]
|
||||
public bool IsPrimaryBuilding
|
||||
{
|
||||
get { return pb.IsPrimary; }
|
||||
set { pb.SetPrimaryProducer(Self, value); }
|
||||
}
|
||||
}
|
||||
|
||||
[ScriptPropertyGroup("Production")]
|
||||
public class ProductionQueueProperties : ScriptActorProperties, Requires<ProductionQueueInfo>, Requires<ScriptTriggersInfo>
|
||||
{
|
||||
readonly List<ProductionQueue> queues;
|
||||
readonly ScriptTriggers triggers;
|
||||
|
||||
public ProductionQueueProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
queues = self.TraitsImplementing<ProductionQueue>().Where(q => q.Enabled).ToList();
|
||||
triggers = TriggerGlobal.GetScriptTriggers(self);
|
||||
}
|
||||
|
||||
[Desc("Build the specified set of actors using a TD-style (per building) production queue. " +
|
||||
"The function will return true if production could be started, false otherwise. " +
|
||||
"If an actionFunc is given, it will be called as actionFunc(Actor[] actors) once " +
|
||||
"production of all actors has been completed. The actors array is guaranteed to " +
|
||||
"only contain alive actors.")]
|
||||
public bool Build(string[] actorTypes, LuaFunction actionFunc = null)
|
||||
{
|
||||
if (triggers.Triggers[Trigger.OnProduction].Any())
|
||||
return false;
|
||||
|
||||
var queue = queues.Where(q => actorTypes.All(t => GetBuildableInfo(t).Queue.Contains(q.Info.Type)))
|
||||
.FirstOrDefault(q => q.CurrentItem() == null);
|
||||
|
||||
if (queue == null)
|
||||
return false;
|
||||
|
||||
if (actionFunc != null)
|
||||
{
|
||||
var playerIndex = Self.Owner.ClientIndex;
|
||||
var squadSize = actorTypes.Length;
|
||||
var squad = new List<Actor>();
|
||||
var func = actionFunc.CopyReference() as LuaFunction;
|
||||
|
||||
Action<Actor, Actor> productionHandler = (_, __) => { };
|
||||
productionHandler = (factory, unit) =>
|
||||
{
|
||||
if (playerIndex != factory.Owner.ClientIndex)
|
||||
{
|
||||
triggers.OnProducedInternal -= productionHandler;
|
||||
return;
|
||||
}
|
||||
|
||||
squad.Add(unit);
|
||||
if (squad.Count >= squadSize)
|
||||
{
|
||||
using (func)
|
||||
using (var luaSquad = squad.Where(u => !u.IsDead).ToArray().ToLuaValue(Context))
|
||||
func.Call(luaSquad).Dispose();
|
||||
|
||||
triggers.OnProducedInternal -= productionHandler;
|
||||
}
|
||||
};
|
||||
|
||||
triggers.OnProducedInternal += productionHandler;
|
||||
}
|
||||
|
||||
foreach (var actorType in actorTypes)
|
||||
queue.ResolveOrder(Self, Order.StartProduction(Self, actorType, 1));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Desc("Check whether the factory's production queue that builds this type of actor is currently busy." +
|
||||
"Note: it does not check whether this particular type of actor is being produced.")]
|
||||
public bool IsProducing(string actorType)
|
||||
{
|
||||
if (triggers.Triggers[Trigger.OnProduction].Any())
|
||||
return true;
|
||||
|
||||
return queues.Where(q => GetBuildableInfo(actorType).Queue.Contains(q.Info.Type))
|
||||
.Any(q => q.CurrentItem() != null);
|
||||
}
|
||||
|
||||
BuildableInfo GetBuildableInfo(string actorType)
|
||||
{
|
||||
var ri = Self.World.Map.Rules.Actors[actorType];
|
||||
var bi = ri.Traits.GetOrDefault<BuildableInfo>();
|
||||
|
||||
if (bi == null)
|
||||
throw new LuaException("Actor of type {0} cannot be produced".F(actorType));
|
||||
else
|
||||
return bi;
|
||||
}
|
||||
}
|
||||
|
||||
[ScriptPropertyGroup("Production")]
|
||||
public class ClassicProductionQueueProperties : ScriptPlayerProperties, Requires<ClassicProductionQueueInfo>, Requires<ScriptTriggersInfo>
|
||||
{
|
||||
readonly Dictionary<string, Action<Actor, Actor>> productionHandlers;
|
||||
readonly Dictionary<string, ClassicProductionQueue> queues;
|
||||
|
||||
public ClassicProductionQueueProperties(ScriptContext context, Player player)
|
||||
: base(context, player)
|
||||
{
|
||||
productionHandlers = new Dictionary<string, Action<Actor, Actor>>();
|
||||
|
||||
queues = new Dictionary<string, ClassicProductionQueue>();
|
||||
foreach (var q in player.PlayerActor.TraitsImplementing<ClassicProductionQueue>().Where(q => q.Enabled))
|
||||
queues.Add(q.Info.Type, q);
|
||||
|
||||
Action<Actor, Actor> globalProductionHandler = (factory, unit) =>
|
||||
{
|
||||
if (factory.Owner != player)
|
||||
return;
|
||||
|
||||
var queue = GetBuildableInfo(unit.Info.Name).Queue.First();
|
||||
|
||||
if (productionHandlers.ContainsKey(queue))
|
||||
productionHandlers[queue](factory, unit);
|
||||
};
|
||||
|
||||
var triggers = TriggerGlobal.GetScriptTriggers(player.PlayerActor);
|
||||
triggers.OnOtherProducedInternal += globalProductionHandler;
|
||||
}
|
||||
|
||||
[Desc("Build the specified set of actors using classic (RA-style) production queues. " +
|
||||
"The function will return true if production could be started, false otherwise. " +
|
||||
"If an actionFunc is given, it will be called as actionFunc(Actor[] actors) once " +
|
||||
"production of all actors has been completed. The actors array is guaranteed to " +
|
||||
"only contain alive actors. Note: This function will fail to work when called " +
|
||||
"during the first tick")]
|
||||
public bool Build(string[] actorTypes, LuaFunction actionFunc = null)
|
||||
{
|
||||
var typeToQueueMap = new Dictionary<string, string>();
|
||||
foreach (var actorType in actorTypes.Distinct())
|
||||
typeToQueueMap.Add(actorType, GetBuildableInfo(actorType).Queue.First());
|
||||
|
||||
var queueTypes = typeToQueueMap.Values.Distinct();
|
||||
|
||||
if (queueTypes.Any(t => !queues.ContainsKey(t) || productionHandlers.ContainsKey(t)))
|
||||
return false;
|
||||
|
||||
if (queueTypes.Any(t => queues[t].CurrentItem() != null))
|
||||
return false;
|
||||
|
||||
if (actionFunc != null)
|
||||
{
|
||||
var squadSize = actorTypes.Length;
|
||||
var squad = new List<Actor>();
|
||||
var func = actionFunc.CopyReference() as LuaFunction;
|
||||
|
||||
Action<Actor, Actor> productionHandler = (factory, unit) =>
|
||||
{
|
||||
squad.Add(unit);
|
||||
if (squad.Count >= squadSize)
|
||||
{
|
||||
using (func)
|
||||
using (var luaSquad = squad.Where(u => !u.IsDead).ToArray().ToLuaValue(Context))
|
||||
func.Call(luaSquad).Dispose();
|
||||
|
||||
foreach (var q in queueTypes)
|
||||
productionHandlers.Remove(q);
|
||||
}
|
||||
};
|
||||
|
||||
foreach (var q in queueTypes)
|
||||
productionHandlers.Add(q, productionHandler);
|
||||
}
|
||||
|
||||
foreach (var actorType in actorTypes)
|
||||
{
|
||||
var queue = queues[typeToQueueMap[actorType]];
|
||||
queue.ResolveOrder(queue.Actor, Order.StartProduction(queue.Actor, actorType, 1));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Desc("Check whether the production queue that builds this type of actor is currently busy." +
|
||||
"Note: it does not check whether this particular type of actor is being produced.")]
|
||||
public bool IsProducing(string actorType)
|
||||
{
|
||||
var queue = GetBuildableInfo(actorType).Queue.First();
|
||||
|
||||
if (!queues.ContainsKey(queue))
|
||||
return true;
|
||||
|
||||
return productionHandlers.ContainsKey(queue) || queues[queue].CurrentItem() != null;
|
||||
}
|
||||
|
||||
BuildableInfo GetBuildableInfo(string actorType)
|
||||
{
|
||||
var ri = Player.World.Map.Rules.Actors[actorType];
|
||||
var bi = ri.Traits.GetOrDefault<BuildableInfo>();
|
||||
|
||||
if (bi == null)
|
||||
throw new LuaException("Actor of type {0} cannot be produced".F(actorType));
|
||||
else
|
||||
return bi;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
#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 OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ScriptPropertyGroup("General")]
|
||||
public class RepairableBuildingProperties : ScriptActorProperties, Requires<RepairableBuildingInfo>
|
||||
{
|
||||
readonly RepairableBuilding rb;
|
||||
|
||||
public RepairableBuildingProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
rb = self.Trait<RepairableBuilding>();
|
||||
}
|
||||
|
||||
[Desc("Start repairs on this building. `repairer` can be an allied player.")]
|
||||
public void StartBuildingRepairs(Player repairer = null)
|
||||
{
|
||||
repairer = repairer ?? Self.Owner;
|
||||
|
||||
if (!rb.Repairers.Contains(repairer))
|
||||
rb.RepairBuilding(Self, repairer);
|
||||
}
|
||||
|
||||
[Desc("Stop repairs on this building. `repairer` can be an allied player.")]
|
||||
public void StopBuildingRepairs(Player repairer = null)
|
||||
{
|
||||
repairer = repairer ?? Self.Owner;
|
||||
|
||||
if (rb.RepairActive && rb.Repairers.Contains(repairer))
|
||||
rb.RepairBuilding(Self, repairer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
#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 OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
[ScriptPropertyGroup("Transform")]
|
||||
public class TransformProperties : ScriptActorProperties, Requires<TransformsInfo>
|
||||
{
|
||||
readonly Transforms transforms;
|
||||
|
||||
public TransformProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
transforms = self.Trait<Transforms>();
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Queue a new transformation.")]
|
||||
public void Deploy()
|
||||
{
|
||||
transforms.DeployTransform(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user