Skip to content

Commit

Permalink
Merge pull request #5832 from obrakmann/fix-old-lua-breakage
Browse files Browse the repository at this point in the history
Fix breakage of the old Lua API due to recent changes
  • Loading branch information
Mailaender committed Jul 6, 2014
2 parents ee2dc60 + 3a67b3d commit 9be8f4c
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 16 deletions.
6 changes: 6 additions & 0 deletions OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,5 +461,11 @@ public IEnumerable<CPos> ExpandFootprint(LuaTable cells, bool allowDiagonal)
{
return Util.ExpandFootprint(cells.Values.Cast<CPos>(), allowDiagonal);
}

[LuaGlobal]
public WPos CenterOfCell(CPos position)
{
return world.Map.CenterOfCell(position);
}
}
}
4 changes: 2 additions & 2 deletions mods/cnc/maps/gdi03/gdi03.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end
AttackPlayer = function()
if not Actor.IsDead(NodBarracks) then
Production.BuildWithPerFactoryQueue(NodBarracks, "e1", 5)
attackSquad = Team.New(Map.FindUnitsInCircle(enemy, NodBarracks.location, 3))
attackSquad = Team.New(Map.FindUnitsInCircle(enemy, NodBarracks, 3))
Team.Do(attackSquad, function(unit)
Actor.AttackMove(unit, waypoint9.location)
Actor.Hunt(unit)
Expand All @@ -38,4 +38,4 @@ Tick = function()
if Mission.RequiredUnitsAreDestroyed(enemy) then
MissionAccomplished()
end
end
end
2 changes: 1 addition & 1 deletion mods/cnc/maps/gdi04a/gdi04a.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ HeliAction = function(heliActor, team)
Actor.AfterMove(heliActor)
Actor.UnloadCargo(heliActor, true)
Actor.Wait(heliActor, Utils.Seconds(2))
Actor.ScriptedMove(heliActor, NodHeliEntry)
Actor.ScriptedMove(heliActor, NodHeliEntry.Location)
Actor.RemoveSelf(heliActor)

Team.Do(team, function(actor)
Expand Down
2 changes: 1 addition & 1 deletion mods/cnc/maps/gdi04b/gdi04b.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ HeliAction = function(heliActor, team)
Actor.AfterMove(heliActor)
Actor.UnloadCargo(heliActor, true)
Actor.Wait(heliActor, Utils.Seconds(2))
Actor.ScriptedMove(heliActor, HeliEntry)
Actor.ScriptedMove(heliActor, HeliEntry.Location)
Actor.RemoveSelf(heliActor)

Team.Do(team, function(actor)
Expand Down
2 changes: 1 addition & 1 deletion mods/common/lua/actor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ end

Actor.ScriptedMove = function(actor, location)
if Actor.HasTrait(actor, "Helicopter") then
Internal.HeliFlyToPos(actor, location.CenterPosition)
Internal.HeliFlyToPos(actor, Map.CenterOfCell(location))
else
actor:QueueActivity(OpenRA.New("Move", { location }))
end
Expand Down
6 changes: 5 additions & 1 deletion mods/common/lua/map.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ Map.ExpandFootprint = function(cells, allowDiagonal)
return Utils.EnumerableToTable(Internal.ExpandFootprint(cells, allowDiagonal))
end

Map.CenterOfCell = function(position)
return Internal.CenterOfCell(position)
end

CPos.New = function(x, y)
return OpenRA.New("CPos", { { x, "Int32" }, { y, "Int32" } })
end
Expand Down Expand Up @@ -102,4 +106,4 @@ end

WRange.FromCells = function(cells)
return WRange.New(cells * 1024)
end
end
4 changes: 2 additions & 2 deletions mods/common/lua/reinforcements.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Reinforcements = { }

Reinforcements.Insert = function(owner, transportName, passengerNames, enterPath, exitPath)
local facing = { Map.GetFacing(CPos.op_Subtraction(enterPath[2], enterPath[1]), 0), "Int32" }
local center = WPos.op_Addition(enterPath[1].CenterPosition, WVec.New(0, 0, Rules.InitialAltitude(transportName)))
local center = WPos.op_Addition(Map.CenterOfCell(enterPath[1]), WVec.New(0, 0, Rules.InitialAltitude(transportName)))
local transport = Actor.Create(transportName, { Owner = owner, Location = enterPath[1], CenterPosition = center, Facing = facing })
local cargo = Actor.Trait(transport, "Cargo")
local passengers = { }
Expand All @@ -24,7 +24,7 @@ end

Reinforcements.Extract = function(owner, transportName, passengerNames, enterPath, exitPath)
local facing = { Map.GetFacing(CPos.op_Subtraction(enterPath[2], enterPath[1]), 0), "Int32" }
local center = WPos.op_Addition(enterPath[1].CenterPosition, WVec.New(0, 0, Rules.InitialAltitude(transportName)))
local center = WPos.op_Addition(Map.CenterOfCell(enterPath[1]), WVec.New(0, 0, Rules.InitialAltitude(transportName)))
local transport = Actor.Create(transportName, { Owner = owner, Location = enterPath[1], CenterPosition = center, Facing = facing })
local cargo = Actor.Trait(transport, "Cargo")

Expand Down
13 changes: 7 additions & 6 deletions mods/common/lua/supportpowers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ SupportPowers = { }

SupportPowers.Airstrike = function(owner, planeName, enterLocation, bombLocation)
local facing = { Map.GetFacing(CPos.op_Subtraction(bombLocation, enterLocation), 0), "Int32" }
local center = WPos.op_Addition(enterLocation.CenterPosition, WVec.New(0, 0, Rules.InitialAltitude(planeName)))
local center = WPos.op_Addition(Map.CenterOfCell(enterLocation), 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)
local bombLoc = Map.CenterOfCell(bombLocation)
Actor.Trait(plane, "AttackBomber"):SetTarget(bombLoc)
Actor.Fly(plane, bombLoc)
Actor.FlyOffMap(plane)
Actor.RemoveSelf(plane)
return plane
end

SupportPowers.Paradrop = function(owner, planeName, passengerNames, enterLocation, dropLocation)
local facing = { Map.GetFacing(CPos.op_Subtraction(dropLocation, enterLocation), 0), "Int32" }
local center = WPos.op_Addition(enterLocation.CenterPosition, WVec.New(0, 0, Rules.InitialAltitude(planeName)))
local center = WPos.op_Addition(Map.CenterOfCell(enterLocation), 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)
Actor.Trait(plane, "ParaDrop"):SetLZ(dropLocation, true)
local cargo = Actor.Trait(plane, "Cargo")
local passengers = { }
for i, passengerName in ipairs(passengerNames) do
Expand All @@ -38,4 +39,4 @@ SupportPowers.Chronoshift = function(unitLocationPairs, chronosphere, duration,
cs:Teleport(unit, cell, duration, killCargo, chronosphere)
end
end)
end
end
3 changes: 1 addition & 2 deletions mods/ra/maps/intervention/mission.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ Reinforcements.ReinforceAir = function(owner, planeNames, entrypoint, rallypoint
local flight = { }

for i, planeName in ipairs(planeNames) do
local plane = Actor.Create(planeName, { AddToWorld = false, Location = entrypoint.Location, Owner = owner, Facing = facing })
local enterLocation = entrypoint.Location
local enterPosition = WPos.op_Addition(entrypoint.CenterPosition, WVec.New(0, 0, Rules.InitialAltitude(planeName)))
local plane = Actor.Create(planeName, { AddToWorld = false, Location = entrypoint.Location, CenterPosition = enterPosition, Owner = owner, Facing = facing })
flight[i] = plane
OpenRA.RunAfterDelay((i - 1) * interval, function()
World:Add(plane)
Expand Down

0 comments on commit 9be8f4c

Please sign in to comment.