ww2commander
Emperor
I have a modified version of Gedemons rotation code which I need to loop through all units on the map and make sure they are facing in a south-east direction always.
The code seems to work correctly and sets the facing to 2 (south-east) but visually the counters are still rotated incorrectly on the map. What could I be doing wrong??
The code seems to work correctly and sets the facing to 2 (south-east) but visually the counters are still rotated incorrectly on the map. What could I be doing wrong??
Code:
function SetUnitDirection()
-- This function makes sure that all units are facing South-East as which is the correct
-- visual orientation for the scenario counter units.
for playerID = 0, GameDefines.MAX_CIV_PLAYERS - 1 do
local player = Players[playerID]
for unit in player:Units() do
SetDirection(unit, 2) -- 2 is South-East
Dprint("Unit direction:"..unit:GetFacingDirection())
end
end
end
function SetDirection (unit, requiredDirection)
local direction_types = {
DirectionTypes.DIRECTION_NORTHEAST,
DirectionTypes.DIRECTION_EAST,
DirectionTypes.DIRECTION_SOUTHEAST,
DirectionTypes.DIRECTION_SOUTHWEST,
DirectionTypes.DIRECTION_WEST,
DirectionTypes.DIRECTION_NORTHWEST
}
for loop, direction in ipairs(direction_types) do
if unit:GetFacingDirection() == requiredDirection then
return
else
unit:RotateFacingDirectionClockwise(1);
end
end
end