Add production-related Lua functions
This commit is contained in:
@@ -342,5 +342,35 @@ namespace OpenRA.Mods.RA.Scripting
|
||||
{
|
||||
return world.FindActorsInCircle(location, radius).ToArray();
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void BuildWithSharedQueue(Player player, string unit, double amount)
|
||||
{
|
||||
var ri = Rules.Info[unit];
|
||||
if (ri == null || !ri.Traits.Contains<BuildableInfo>())
|
||||
return;
|
||||
|
||||
var category = ri.Traits.Get<BuildableInfo>().Queue;
|
||||
|
||||
var queue = world.ActorsWithTrait<ClassicProductionQueue>()
|
||||
.Where(a => a.Actor.Owner == player && a.Trait.Info.Type == category)
|
||||
.Select(a => a.Trait).FirstOrDefault();
|
||||
|
||||
if (queue != null)
|
||||
queue.ResolveOrder(queue.self, Order.StartProduction(queue.self, unit, (int)amount));
|
||||
}
|
||||
|
||||
[LuaGlobal]
|
||||
public void BuildWithPerFactoryQueue(Actor factory, string unit, double amount)
|
||||
{
|
||||
if (!factory.HasTrait<ProductionQueue>())
|
||||
return;
|
||||
|
||||
var ri = Rules.Info[unit];
|
||||
if (ri == null || !ri.Traits.Contains<BuildableInfo>())
|
||||
return;
|
||||
|
||||
factory.Trait<ProductionQueue>().ResolveOrder(factory, Order.StartProduction(factory, unit, (int)amount));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,3 +180,4 @@ LuaScripts:
|
||||
mods/common/lua/reinforcements.lua
|
||||
mods/common/lua/supportpowers.lua
|
||||
mods/common/lua/rules.lua
|
||||
mods/common/lua/production.lua
|
||||
|
||||
17
mods/common/lua/production.lua
Normal file
17
mods/common/lua/production.lua
Normal file
@@ -0,0 +1,17 @@
|
||||
Production = { }
|
||||
|
||||
Production.BuildWithSharedQueue = function(player, unit, amount)
|
||||
Internal.BuildWithSharedQueue(player, unit, amount or 1)
|
||||
end
|
||||
|
||||
Production.BuildWithPerFactoryQueue = function(factory, unit, amount)
|
||||
Internal.BuildWithPerFactoryQueue(factory, unit, amount or 1)
|
||||
end
|
||||
|
||||
Production.SetRallyPoint = function(factory, location)
|
||||
Actor.Trait(factory, "RallyPoint").rallyPoint = location.Location
|
||||
end
|
||||
|
||||
Production.SetPrimaryBuilding = function(factory)
|
||||
Actor.Trait(factory, "PrimaryBuilding"):SetPrimaryProducer(factory, true)
|
||||
end
|
||||
@@ -161,3 +161,4 @@ LuaScripts:
|
||||
mods/common/lua/reinforcements.lua
|
||||
mods/common/lua/supportpowers.lua
|
||||
mods/common/lua/rules.lua
|
||||
mods/common/lua/production.lua
|
||||
|
||||
@@ -177,3 +177,4 @@ LuaScripts:
|
||||
mods/common/lua/reinforcements.lua
|
||||
mods/common/lua/supportpowers.lua
|
||||
mods/common/lua/rules.lua
|
||||
mods/common/lua/production.lua
|
||||
|
||||
@@ -199,3 +199,4 @@ LuaScripts:
|
||||
mods/common/lua/reinforcements.lua
|
||||
mods/common/lua/supportpowers.lua
|
||||
mods/common/lua/rules.lua
|
||||
mods/common/lua/production.lua
|
||||
|
||||
Reference in New Issue
Block a user