StyleCop clean OpenRA.Game
This commit is contained in:
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
// Find the requested type
|
||||
var typeName = kv.Key.ToString();
|
||||
var initType = Game.modData.ObjectCreator.FindType(typeName + "Init");
|
||||
var initType = Game.ModData.ObjectCreator.FindType(typeName + "Init");
|
||||
if (initType == null)
|
||||
throw new LuaException("Unknown initializer type '{0}'".F(typeName));
|
||||
|
||||
@@ -52,9 +52,9 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
}
|
||||
|
||||
// The actor must be added to the world at the end of the tick
|
||||
var a = context.World.CreateActor(false, type, initDict);
|
||||
var a = Context.World.CreateActor(false, type, initDict);
|
||||
if (addToWorld)
|
||||
context.World.AddFrameEndTask(w => w.Add(a));
|
||||
Context.World.AddFrameEndTask(w => w.Add(a));
|
||||
|
||||
return a;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
public int BuildTime(string type)
|
||||
{
|
||||
ActorInfo ai;
|
||||
if (!context.World.Map.Rules.Actors.TryGetValue(type, out ai))
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out ai))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(type));
|
||||
|
||||
return ai.GetBuildTime();
|
||||
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
public int CruiseAltitude(string type)
|
||||
{
|
||||
ActorInfo ai;
|
||||
if (!context.World.Map.Rules.Actors.TryGetValue(type, out ai))
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out ai))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(type));
|
||||
|
||||
var pi = ai.Traits.GetOrDefault<ICruiseAltitudeInfo>();
|
||||
|
||||
@@ -21,8 +21,8 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[Desc("The center of the visible viewport.")]
|
||||
public WPos Position
|
||||
{
|
||||
get { return context.WorldRenderer.Viewport.CenterPosition; }
|
||||
set { context.WorldRenderer.Viewport.Center(value); }
|
||||
get { return Context.WorldRenderer.Viewport.CenterPosition; }
|
||||
set { Context.WorldRenderer.Viewport.Center(value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[Desc("Get the current game time (in ticks)")]
|
||||
public int GameTime
|
||||
{
|
||||
get { return context.World.WorldTick; }
|
||||
get { return Context.World.WorldTick; }
|
||||
}
|
||||
|
||||
[Desc("Converts the number of seconds into game time (ticks).")]
|
||||
|
||||
@@ -32,13 +32,13 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[Desc("Returns a table of all actors within the requested region, filtered using the specified function.")]
|
||||
public Actor[] ActorsInCircle(WPos location, WRange radius, LuaFunction filter = null)
|
||||
{
|
||||
var actors = context.World.FindActorsInCircle(location, radius);
|
||||
var actors = Context.World.FindActorsInCircle(location, radius);
|
||||
|
||||
if (filter != null)
|
||||
{
|
||||
actors = actors.Where(a =>
|
||||
{
|
||||
using (var f = filter.Call(a.ToLuaValue(context)))
|
||||
using (var f = filter.Call(a.ToLuaValue(Context)))
|
||||
return f.First().ToBoolean();
|
||||
});
|
||||
}
|
||||
@@ -49,13 +49,13 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[Desc("Returns a table of all actors within the requested rectangle, filtered using the specified function.")]
|
||||
public Actor[] ActorsInBox(WPos topLeft, WPos bottomRight, LuaFunction filter = null)
|
||||
{
|
||||
var actors = context.World.ActorMap.ActorsInBox(topLeft, bottomRight);
|
||||
var actors = Context.World.ActorMap.ActorsInBox(topLeft, bottomRight);
|
||||
|
||||
if (filter != null)
|
||||
{
|
||||
actors = actors.Where(a =>
|
||||
{
|
||||
using (var f = filter.Call(a.ToLuaValue(context)))
|
||||
using (var f = filter.Call(a.ToLuaValue(Context)))
|
||||
return f.First().ToBoolean();
|
||||
});
|
||||
}
|
||||
@@ -66,38 +66,38 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[Desc("Returns the location of the top-left corner of the map.")]
|
||||
public WPos TopLeft
|
||||
{
|
||||
get { return new WPos(context.World.Map.Bounds.Left * 1024, context.World.Map.Bounds.Top * 1024, 0); }
|
||||
get { return new WPos(Context.World.Map.Bounds.Left * 1024, Context.World.Map.Bounds.Top * 1024, 0); }
|
||||
}
|
||||
|
||||
[Desc("Returns the location of the bottom-right corner of the map.")]
|
||||
public WPos BottomRight
|
||||
{
|
||||
get { return new WPos(context.World.Map.Bounds.Right * 1024, context.World.Map.Bounds.Bottom * 1024, 0); }
|
||||
get { return new WPos(Context.World.Map.Bounds.Right * 1024, Context.World.Map.Bounds.Bottom * 1024, 0); }
|
||||
}
|
||||
|
||||
[Desc("Returns a random cell inside the visible region of the map.")]
|
||||
public CPos RandomCell()
|
||||
{
|
||||
return context.World.Map.ChooseRandomCell(context.World.SharedRandom);
|
||||
return Context.World.Map.ChooseRandomCell(Context.World.SharedRandom);
|
||||
}
|
||||
|
||||
[Desc("Returns a random cell on the visible border of the map.")]
|
||||
public CPos RandomEdgeCell()
|
||||
{
|
||||
return context.World.Map.ChooseRandomEdgeCell(context.World.SharedRandom);
|
||||
return Context.World.Map.ChooseRandomEdgeCell(Context.World.SharedRandom);
|
||||
}
|
||||
|
||||
[Desc("Returns the center of a cell in world coordinates.")]
|
||||
public WPos CenterOfCell(CPos cell)
|
||||
{
|
||||
return context.World.Map.CenterOfCell(cell);
|
||||
return Context.World.Map.CenterOfCell(cell);
|
||||
}
|
||||
|
||||
[Desc("Returns true if there is only one human player.")]
|
||||
public bool IsSinglePlayer { get { return context.World.LobbyInfo.IsSinglePlayer; } }
|
||||
public bool IsSinglePlayer { get { return Context.World.LobbyInfo.IsSinglePlayer; } }
|
||||
|
||||
[Desc("Returns the difficulty selected by the player before starting the mission.")]
|
||||
public string Difficulty { get { return context.World.LobbyInfo.GlobalSettings.Difficulty; } }
|
||||
public string Difficulty { get { return Context.World.LobbyInfo.GlobalSettings.Difficulty; } }
|
||||
|
||||
[Desc("Returns a table of all the actors that were specified in the map file.")]
|
||||
public Actor[] NamedActors { get { return sma.Actors.Values.ToArray(); } }
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
}
|
||||
catch (LuaException e)
|
||||
{
|
||||
context.FatalError(e.Message);
|
||||
Context.FatalError(e.Message);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,16 +22,16 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[Desc("Returns the player with the specified internal name, or nil if a match is not found.")]
|
||||
public Player GetPlayer(string name)
|
||||
{
|
||||
return context.World.Players.FirstOrDefault(p => p.InternalName == name);
|
||||
return Context.World.Players.FirstOrDefault(p => p.InternalName == name);
|
||||
}
|
||||
|
||||
[Desc("Returns a table of players filtered by the specified function.")]
|
||||
public Player[] GetPlayers(LuaFunction filter)
|
||||
{
|
||||
return context.World.Players
|
||||
return Context.World.Players
|
||||
.Where(p =>
|
||||
{
|
||||
using (var f = filter.Call(p.ToLuaValue(context)))
|
||||
using (var f = filter.Call(p.ToLuaValue(Context)))
|
||||
return f.First().ToBoolean();
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
@@ -45,32 +45,32 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
context.FatalError(e.Message);
|
||||
Context.FatalError(e.Message);
|
||||
}
|
||||
};
|
||||
|
||||
context.World.AddFrameEndTask(w => w.Add(new DelayedAction(delay, doCall)));
|
||||
Context.World.AddFrameEndTask(w => w.Add(new DelayedAction(delay, doCall)));
|
||||
}
|
||||
|
||||
[Desc("Call a function each tick that the actor is idle. " +
|
||||
"The callback function will be called as func(Actor self).")]
|
||||
public void OnIdle(Actor a, LuaFunction func)
|
||||
{
|
||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnIdle, func, context);
|
||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnIdle, func, Context);
|
||||
}
|
||||
|
||||
[Desc("Call a function when the actor is damaged. The callback " +
|
||||
"function will be called as func(Actor self, Actor attacker).")]
|
||||
public void OnDamaged(Actor a, LuaFunction func)
|
||||
{
|
||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnDamaged, func, context);
|
||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnDamaged, func, Context);
|
||||
}
|
||||
|
||||
[Desc("Call a function when the actor is killed. The callback " +
|
||||
"function will be called as func(Actor self, Actor killer).")]
|
||||
public void OnKilled(Actor a, LuaFunction func)
|
||||
{
|
||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnKilled, func, context);
|
||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnKilled, func, Context);
|
||||
}
|
||||
|
||||
[Desc("Call a function when all of the actors in a group are killed. The callback " +
|
||||
@@ -92,7 +92,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
context.FatalError(e.Message);
|
||||
Context.FatalError(e.Message);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
if (called)
|
||||
return;
|
||||
|
||||
using (var killed = m.ToLuaValue(context))
|
||||
using (var killed = m.ToLuaValue(Context))
|
||||
copy.Call(killed).Dispose();
|
||||
|
||||
copy.Dispose();
|
||||
@@ -121,7 +121,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
context.FatalError(e.Message);
|
||||
Context.FatalError(e.Message);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -133,56 +133,56 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
"The callback function will be called as func(Actor producer, Actor produced).")]
|
||||
public void OnProduction(Actor a, LuaFunction func)
|
||||
{
|
||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnProduction, func, context);
|
||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnProduction, func, Context);
|
||||
}
|
||||
|
||||
[Desc("Call a function when this player completes all primary objectives. " +
|
||||
"The callback function will be called as func(Player player).")]
|
||||
public void OnPlayerWon(Player player, LuaFunction func)
|
||||
{
|
||||
GetScriptTriggers(player.PlayerActor).RegisterCallback(Trigger.OnPlayerWon, func, context);
|
||||
GetScriptTriggers(player.PlayerActor).RegisterCallback(Trigger.OnPlayerWon, func, Context);
|
||||
}
|
||||
|
||||
[Desc("Call a function when this player fails any primary objective. " +
|
||||
"The callback function will be called as func(Player player).")]
|
||||
public void OnPlayerLost(Player player, LuaFunction func)
|
||||
{
|
||||
GetScriptTriggers(player.PlayerActor).RegisterCallback(Trigger.OnPlayerLost, func, context);
|
||||
GetScriptTriggers(player.PlayerActor).RegisterCallback(Trigger.OnPlayerLost, func, Context);
|
||||
}
|
||||
|
||||
[Desc("Call a function when this player is assigned a new objective. " +
|
||||
"The callback function will be called as func(Player player, int objectiveID).")]
|
||||
public void OnObjectiveAdded(Player player, LuaFunction func)
|
||||
{
|
||||
GetScriptTriggers(player.PlayerActor).RegisterCallback(Trigger.OnObjectiveAdded, func, context);
|
||||
GetScriptTriggers(player.PlayerActor).RegisterCallback(Trigger.OnObjectiveAdded, func, Context);
|
||||
}
|
||||
|
||||
[Desc("Call a function when this player completes an objective. " +
|
||||
"The callback function will be called as func(Player player, int objectiveID).")]
|
||||
public void OnObjectiveCompleted(Player player, LuaFunction func)
|
||||
{
|
||||
GetScriptTriggers(player.PlayerActor).RegisterCallback(Trigger.OnObjectiveCompleted, func, context);
|
||||
GetScriptTriggers(player.PlayerActor).RegisterCallback(Trigger.OnObjectiveCompleted, func, Context);
|
||||
}
|
||||
|
||||
[Desc("Call a function when this player fails an objective. " +
|
||||
"The callback function will be called as func(Player player, int objectiveID).")]
|
||||
public void OnObjectiveFailed(Player player, LuaFunction func)
|
||||
{
|
||||
GetScriptTriggers(player.PlayerActor).RegisterCallback(Trigger.OnObjectiveFailed, func, context);
|
||||
GetScriptTriggers(player.PlayerActor).RegisterCallback(Trigger.OnObjectiveFailed, func, Context);
|
||||
}
|
||||
|
||||
[Desc("Call a function when this actor is added to the world. " +
|
||||
"The callback function will be called as func(Actor self).")]
|
||||
public void OnAddedToWorld(Actor a, LuaFunction func)
|
||||
{
|
||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnAddedToWorld, func, context);
|
||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnAddedToWorld, func, Context);
|
||||
}
|
||||
|
||||
[Desc("Call a function when this actor is removed from the world. " +
|
||||
"The callback function will be called as func(Actor self).")]
|
||||
public void OnRemovedFromWorld(Actor a, LuaFunction func)
|
||||
{
|
||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnRemovedFromWorld, func, context);
|
||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnRemovedFromWorld, func, Context);
|
||||
}
|
||||
|
||||
[Desc("Call a function when all of the actors in a group have been removed from the world. " +
|
||||
@@ -205,7 +205,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
context.FatalError(e.Message);
|
||||
Context.FatalError(e.Message);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -217,7 +217,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
"will be called as func(Actor self, Actor captor, Player oldOwner, Player newOwner).")]
|
||||
public void OnCapture(Actor a, LuaFunction func)
|
||||
{
|
||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnCapture, func, context);
|
||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnCapture, func, Context);
|
||||
}
|
||||
|
||||
[Desc("Call a function when this actor is killed or captured. " +
|
||||
@@ -240,7 +240,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
context.FatalError(e.Message);
|
||||
Context.FatalError(e.Message);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -271,7 +271,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
context.FatalError(e.Message);
|
||||
Context.FatalError(e.Message);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -293,17 +293,17 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var luaActor = a.ToLuaValue(context))
|
||||
using (var id = triggerId.ToLuaValue(context))
|
||||
using (var luaActor = a.ToLuaValue(Context))
|
||||
using (var id = triggerId.ToLuaValue(Context))
|
||||
onEntry.Call(luaActor, id).Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
context.FatalError(e.Message);
|
||||
Context.FatalError(e.Message);
|
||||
}
|
||||
};
|
||||
|
||||
triggerId = context.World.ActorMap.AddCellTrigger(cells, invokeEntry, null);
|
||||
triggerId = Context.World.ActorMap.AddCellTrigger(cells, invokeEntry, null);
|
||||
|
||||
return triggerId;
|
||||
}
|
||||
@@ -319,17 +319,17 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var luaActor = a.ToLuaValue(context))
|
||||
using (var id = triggerId.ToLuaValue(context))
|
||||
using (var luaActor = a.ToLuaValue(Context))
|
||||
using (var id = triggerId.ToLuaValue(Context))
|
||||
onExit.Call(luaActor, id).Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
context.FatalError(e.Message);
|
||||
Context.FatalError(e.Message);
|
||||
}
|
||||
};
|
||||
|
||||
triggerId = context.World.ActorMap.AddCellTrigger(cells, null, invokeExit);
|
||||
triggerId = Context.World.ActorMap.AddCellTrigger(cells, null, invokeExit);
|
||||
|
||||
return triggerId;
|
||||
}
|
||||
@@ -337,7 +337,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[Desc("Removes a previously created footprint trigger.")]
|
||||
public void RemoveFootprintTrigger(int id)
|
||||
{
|
||||
context.World.ActorMap.RemoveCellTrigger(id);
|
||||
Context.World.ActorMap.RemoveCellTrigger(id);
|
||||
}
|
||||
|
||||
[Desc("Call a function when an actor enters this range." +
|
||||
@@ -351,17 +351,17 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var luaActor = a.ToLuaValue(context))
|
||||
using (var id = triggerId.ToLuaValue(context))
|
||||
using (var luaActor = a.ToLuaValue(Context))
|
||||
using (var id = triggerId.ToLuaValue(Context))
|
||||
onEntry.Call(luaActor, id).Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
context.FatalError(e.Message);
|
||||
Context.FatalError(e.Message);
|
||||
}
|
||||
};
|
||||
|
||||
triggerId = context.World.ActorMap.AddProximityTrigger(pos, range, invokeEntry, null);
|
||||
triggerId = Context.World.ActorMap.AddProximityTrigger(pos, range, invokeEntry, null);
|
||||
|
||||
return triggerId;
|
||||
}
|
||||
@@ -377,17 +377,17 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var luaActor = a.ToLuaValue(context))
|
||||
using (var id = triggerId.ToLuaValue(context))
|
||||
using (var luaActor = a.ToLuaValue(Context))
|
||||
using (var id = triggerId.ToLuaValue(Context))
|
||||
onExit.Call(luaActor, id).Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
context.FatalError(e.Message);
|
||||
Context.FatalError(e.Message);
|
||||
}
|
||||
};
|
||||
|
||||
triggerId = context.World.ActorMap.AddProximityTrigger(pos, range, null, invokeExit);
|
||||
triggerId = Context.World.ActorMap.AddProximityTrigger(pos, range, null, invokeExit);
|
||||
|
||||
return triggerId;
|
||||
}
|
||||
@@ -395,14 +395,14 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[Desc("Removes a previously created proximitry trigger.")]
|
||||
public void RemoveProximityTrigger(int id)
|
||||
{
|
||||
context.World.ActorMap.RemoveProximityTrigger(id);
|
||||
Context.World.ActorMap.RemoveProximityTrigger(id);
|
||||
}
|
||||
|
||||
[Desc("Call a function when this actor is infiltrated. The callback function " +
|
||||
"will be called as func(Actor self, Actor infiltrator).")]
|
||||
public void OnInfiltrated(Actor a, LuaFunction func)
|
||||
{
|
||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnInfiltrated, func, context);
|
||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnInfiltrated, func, Context);
|
||||
}
|
||||
|
||||
[Desc("Removes all triggers from this actor." +
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[Desc("Skips over the first numElements members of a table and return the rest.")]
|
||||
public LuaTable Skip(LuaTable table, int numElements)
|
||||
{
|
||||
var t = context.CreateTable();
|
||||
var t = Context.CreateTable();
|
||||
|
||||
for (var i = numElements; i <= table.Count; i++)
|
||||
t.Add(t.Count + 1, table[i]);
|
||||
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[Desc("Returns a random value from a collection.")]
|
||||
public LuaValue Random(LuaValue[] collection)
|
||||
{
|
||||
return collection.Random(context.World.SharedRandom);
|
||||
return collection.Random(Context.World.SharedRandom);
|
||||
}
|
||||
|
||||
[Desc("Expands the given footprint one step along the coordinate axes, and (if requested) diagonals.")]
|
||||
@@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
if (high <= low)
|
||||
return low;
|
||||
|
||||
return context.World.SharedRandom.Next(low, high);
|
||||
return Context.World.SharedRandom.Next(low, high);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user