Remove the temperate RA shellmap and port the desert shellmap to Lua.

This commit is contained in:
ScottNZ
2014-03-02 18:47:24 +13:00
parent 79d1a944bc
commit 7d43ecc33f
17 changed files with 858 additions and 2277 deletions

View File

@@ -76,7 +76,14 @@ Actor.FlyOffMap = function(actor)
end
Actor.Hunt = function(actor)
actor:QueueActivity(OpenRA.New("Hunt", { actor }))
if Actor.HasTrait(actor, "AttackBase") and Actor.HasTrait(actor, "IMove") then
actor:QueueActivity(OpenRA.New("Hunt", { actor }))
end
end
Actor.CargoIsEmpty = function(actor)
local cargo = Actor.TraitOrDefault(actor, "Cargo")
return cargo == nil or cargo:IsEmpty(actor)
end
Actor.UnloadCargo = function(actor, unloadAll)
@@ -163,6 +170,14 @@ Actor.OnCaptured = function(actor, eh)
Actor.Trait(actor, "LuaScriptEvents").OnCaptured:Add(eh)
end
Actor.OnIdle = function(actor, eh)
Actor.Trait(actor, "LuaScriptEvents").OnIdle:Add(eh)
end
Actor.OnProduced = function(actor, eh)
Actor.Trait(actor, "LuaScriptEvents").OnProduced:Add(eh)
end
Actor.ActorsWithTrait = function(className)
local ret = { }
for item in Utils.Enumerate(Internal.ActorsWithTrait(className)) do

View File

@@ -12,10 +12,18 @@ Map.GetRandomEdgeCell = function()
return Internal.GetRandomEdgeCell()
end
Map.IsNamedActor = function(actor)
return Internal.IsNamedActor(actor)
end
Map.GetNamedActor = function(actorName)
return Internal.GetNamedActor(actorName)
end
Map.GetNamedActors = function()
return Internal.GetNamedActors()
end
Map.FindActorsInCircle = function(location, radius, func)
local actors = Internal.FindActorsInCircle(location.CenterPosition, WRange.FromCells(radius))
return Utils.EnumerableWhere(actors, func)
@@ -58,6 +66,10 @@ Map.FindIdleUnitsInBox = function(player, topLeft, bottomRight)
return Map.FindActorsInBox(topLeft, bottomRight, function(a) return Map.__FilterByTraitAndIdle(a, player, "Mobile") end)
end
Map.ExpandFootprint = function(cells, allowDiagonal)
return Utils.EnumerableToTable(Internal.ExpandFootprint(cells, allowDiagonal))
end
CPos.New = function(x, y)
return OpenRA.New("CPos", { { x, "Int32" }, { y, "Int32" } })
end
@@ -90,4 +102,4 @@ end
WRange.FromCells = function(cells)
return WRange.New(cells * 1024)
end
end

View File

@@ -8,6 +8,14 @@ Production.BuildWithPerFactoryQueue = function(factory, unit, amount)
Internal.BuildWithPerFactoryQueue(factory, unit, amount or 1)
end
Production.SharedQueueIsBusy = function(player, category)
return Internal.SharedQueueIsBusy(player, category)
end
Production.PerFactoryQueueIsBusy = function(factory)
return Internal.PerFactoryQueueIsBusy(factory)
end
Production.SetRallyPoint = function(factory, location)
Actor.Trait(factory, "RallyPoint").rallyPoint = location.Location
end

View File

@@ -2,8 +2,8 @@ SupportPowers = { }
SupportPowers.Airstrike = function(owner, planeName, enterLocation, bombLocation)
local facing = { Map.GetFacing(CPos.op_Subtraction(bombLocation, enterLocation), 0), "Int32" }
local altitude = { Rules.TraitInfo(planeName, "AircraftInfo").CruiseAltitude, "Int32" }
local plane = Actor.Create(planeName, { Location = enterLocation, Owner = owner, Facing = facing, Altitude = altitude })
local center = WPos.op_Addition(enterLocation.CenterPosition, WVec.New(0, 0, Rules.InitialAltitude(planeName)))
local plane = Actor.Create(planeName, { Location = enterLocation, Owner = owner, Facing = facing, CenterPosition = center })
Actor.Trait(plane, "AttackBomber"):SetTarget(bombLocation.CenterPosition)
Actor.Fly(plane, bombLocation.CenterPosition)
Actor.FlyOffMap(plane)
@@ -13,8 +13,8 @@ end
SupportPowers.Paradrop = function(owner, planeName, passengerNames, enterLocation, dropLocation)
local facing = { Map.GetFacing(CPos.op_Subtraction(dropLocation, enterLocation), 0), "Int32" }
local altitude = { Rules.TraitInfo(planeName, "AircraftInfo").CruiseAltitude, "Int32" }
local plane = Actor.Create(planeName, { Location = enterLocation, Owner = owner, Facing = facing, Altitude = altitude })
local center = WPos.op_Addition(enterLocation.CenterPosition, WVec.New(0, 0, Rules.InitialAltitude(planeName)))
local plane = Actor.Create(planeName, { Location = enterLocation, Owner = owner, Facing = facing, CenterPosition = center })
Actor.FlyAttackCell(plane, dropLocation)
Actor.Trait(plane, "ParaDrop"):SetLZ(dropLocation)
local cargo = Actor.Trait(plane, "Cargo")
@@ -25,4 +25,17 @@ SupportPowers.Paradrop = function(owner, planeName, passengerNames, enterLocatio
cargo:Load(plane, passenger)
end
return plane, passengers
end
SupportPowers.Chronoshift = function(unitLocationPairs, chronosphere, duration, killCargo)
duration = duration or -1
killCargo = killCargo or true
Utils.Do(unitLocationPairs, function(pair)
local unit = pair[1]
local cell = pair[2]
local cs = Actor.TraitOrDefault(unit, "Chronoshiftable")
if cs ~= nil and cs:CanChronoshiftTo(unit, cell) then
cs:Teleport(unit, cell, duration, killCargo, chronosphere)
end
end)
end

View File

@@ -28,6 +28,14 @@ Utils.EnumerableWhere = function(netEnumerable, func)
return ret
end
Utils.EnumerableToTable = function(netEnumerable, func)
local ret = { }
for item in Utils.Enumerate(netEnumerable) do
table.insert(ret, item)
end
return ret
end
Utils.Where = function(array, func)
local ret = { }
for i, item in ipairs(array) do

View File

@@ -0,0 +1,154 @@
local ants = OpenRA.GetRandomInteger(0, 51) == 0
if ants then
UnitTypes = { "ant", "ant", "ant" }
BeachUnitTypes = { "ant", "ant" }
ParadropUnitTypes = { "ant", "ant", "ant", "ant", "ant" }
ProducedUnitTypes =
{
{ AlliedBarracks1, { "e1", "e3" } },
{ AlliedBarracks2, { "e1", "e3" } },
{ SovietBarracks1, { "ant" } },
{ SovietBarracks2, { "ant" } },
{ SovietBarracks3, { "ant" } },
{ AlliedWarFactory1, { "jeep", "1tnk", "2tnk", "arty", "ctnk" } },
{ SovietWarFactory1, { "3tnk", "4tnk", "v2rl", "ttnk", "apc" } }
}
else
UnitTypes = { "3tnk", "ftrk", "ttnk", "apc" }
BeachUnitTypes = { "e1", "e2", "e3", "e4", "e1", "e2", "e3", "e4", "e1", "e2", "e3", "e4", "e1", "e2", "e3", "e4" }
ParadropUnitTypes = { "e1", "e1", "e2", "e3", "e4" }
ProducedUnitTypes =
{
{ AlliedBarracks1, { "e1", "e3" } },
{ AlliedBarracks2, { "e1", "e3" } },
{ SovietBarracks1, { "dog", "e1", "e2", "e3", "e4", "shok" } },
{ SovietBarracks2, { "dog", "e1", "e2", "e3", "e4", "shok" } },
{ SovietBarracks3, { "dog", "e1", "e2", "e3", "e4", "shok" } },
{ AlliedWarFactory1, { "jeep", "1tnk", "2tnk", "arty", "ctnk" } },
{ SovietWarFactory1, { "3tnk", "4tnk", "v2rl", "ttnk", "apc" } }
}
end
ParadropPlaneType = "badr"
ParadropWaypointCount = 8
SendSovietUnits = function(entryCell, unitTypes, interval)
local units = Reinforcements.Reinforce(soviets, unitTypes, entryCell, entryCell, interval)
local team = Team.New(units)
Team.AddEventHandler(team.OnAllKilled, function()
SendSovietUnits(entryCell, unitTypes, interval)
end)
Team.Do(team, function(a)
Actor.OnDamaged(a, function()
if not Actor.CargoIsEmpty(a) then
Actor.Stop(a)
Actor.UnloadCargo(a, true)
end
end)
Actor.OnIdle(a, function() Actor.AttackMove(a, AlliedTechnologyCenter.Location) end)
end)
end
ShipAlliedUnits = function()
local transport, reinforcements = Reinforcements.Insert(allies, "lst", { "1tnk", "1tnk", "jeep", "2tnk", "2tnk" }, { LstEntry.Location, LstUnload.Location }, { LstEntry.Location })
Utils.Do(reinforcements, function(a) Actor.OnIdle(a, Actor.Hunt) end)
OpenRA.RunAfterDelay(60 * 25, ShipAlliedUnits)
end
ParadropSovietUnits = function()
local lz = Map.GetNamedActor("Paradrop" .. OpenRA.GetRandomInteger(1, ParadropWaypointCount - 1)).Location
local plane, passengers = SupportPowers.Paradrop(soviets, ParadropPlaneType, ParadropUnitTypes, Map.GetRandomEdgeCell(), lz)
Utils.Do(passengers, function(a) Actor.OnIdle(a, Actor.Hunt) end)
OpenRA.RunAfterDelay(35 * 25, ParadropSovietUnits)
end
ProduceUnits = function()
Utils.Do(ProducedUnitTypes, function(t)
local factory = t[1]
if not Actor.IsDead(factory) and not Production.PerFactoryQueueIsBusy(factory) then
local unitType = t[2][OpenRA.GetRandomInteger(1, #t[2] + 1)]
Production.BuildWithPerFactoryQueue(factory, unitType)
end
end)
OpenRA.RunAfterDelay(15, ProduceUnits)
end
SetupAlliedUnits = function()
for a in Utils.Enumerate(Map.GetNamedActors()) do
if Actor.Owner(a) == allies then
if Actor.HasTrait(a, "LuaScriptEvents") then
a:AddTrait(OpenRA.New("Invulnerable")) -- todo: replace
end
Actor.SetStance(a, "Defend")
end
end
end
SetupFactories = function()
Utils.Do(ProducedUnitTypes, function(pair)
Actor.OnProduced(pair[1], function(self, other, ex)
Actor.Hunt(other)
Actor.OnDamaged(other, function()
if not Actor.CargoIsEmpty(other) then
Actor.Stop(other)
Actor.UnloadCargo(other, true)
end
end)
end)
end)
end
ChronoshiftAlliedUnits = function()
local cells = Map.ExpandFootprint({ ChronoshiftLocation.Location }, false)
local units = { }
for i = 1, #cells do
local unit = Actor.Create("2tnk", { Owner = allies, Facing = { 0, "Int32" } })
Actor.OnIdle(unit, Actor.Hunt)
table.insert(units, { unit, cells[i] })
end
SupportPowers.Chronoshift(units, Chronosphere)
OpenRA.RunAfterDelay(60 * 25, ChronoshiftAlliedUnits)
end
ticks = 0
speed = 5
Tick = function()
ticks = ticks + 1
local t = (ticks + 45) % (360 * speed) * (math.pi / 180) / speed;
OpenRA.SetViewportCenterPosition(WPos.op_Addition(viewportOrigin, WVec.New(19200 * math.sin(t), 20480 * math.cos(t))))
if ticks % 150 == 0 then
Utils.Do(Actor.ActorsWithTrait("AttackBase"), function(a)
if Actor.IsIdle(a) and not Map.IsNamedActor(a) and not Actor.IsDead(a) and Actor.IsInWorld(a) and (Actor.Owner(a) == soviets or Actor.Owner(a) == allies) then
Actor.Hunt(a)
end
end)
end
end
WorldLoaded = function()
allies = OpenRA.GetPlayer("Allies")
soviets = OpenRA.GetPlayer("Soviets")
viewportOrigin = OpenRA.GetViewportCenterPosition()
SetupAlliedUnits()
SetupFactories()
ProduceUnits()
ShipAlliedUnits()
ParadropSovietUnits()
OpenRA.RunAfterDelay(5 * 25, ChronoshiftAlliedUnits)
OpenRA.GiveCash(allies, 1000000)
OpenRA.GiveCash(soviets, 1000000)
SendSovietUnits(Entry1.Location, UnitTypes, 50)
SendSovietUnits(Entry2.Location, UnitTypes, 50)
SendSovietUnits(Entry3.Location, UnitTypes, 50)
SendSovietUnits(Entry4.Location, UnitTypes, 50)
SendSovietUnits(Entry5.Location, UnitTypes, 50)
SendSovietUnits(Entry6.Location, UnitTypes, 50)
SendSovietUnits(Entry7.Location, BeachUnitTypes, 15)
end

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff