ww2commander
Emperor
Hi guys,
I have written a functioning piece of code that is pretty straight forward, but I would like to make it more randomized if possible. The function performs checks against the current turn to see if the USSR receives reserve units from eastern Russia. Right now the code spawns units on an exact turn, but I would like to make this a bit more random if possible.
I was hoping the more advanced lua gurus might glance over it and suggest a good approach.
First here is the code:
and here is a snipped version of the global table it refers to:
Now as mentioned, the above code does work so don't go thinking there is any problem. What I want is ideas or examples of how I could make the code randomize the arrival turn by plus 3 or minus 3 turns when compared to the "Turn" field in g_EasternReserveUnits table
This is the first time I have tried something like this and figure I need a way to track if a unit has appeared or something.
Any one up to the challenge please post your suggestion. Full credit will be given of course if a workable model is implemented in my scenario.
Cheers
I have written a functioning piece of code that is pretty straight forward, but I would like to make it more randomized if possible. The function performs checks against the current turn to see if the USSR receives reserve units from eastern Russia. Right now the code spawns units on an exact turn, but I would like to make this a bit more random if possible.
I was hoping the more advanced lua gurus might glance over it and suggest a good approach.
First here is the code:
Code:
-- ######################################################################################
-- Eastern Reserves
-- ######################################################################################
-- Function checks turn and determines if USSR receives reserve troops from Eastern locations
-- Historically Siberian, Transbaikal and Central Asian military districts provided units to west.
function DeployEasternReserves(playerID)
local turn = Game.GetGameTurn()
local random = math.random
if turn < EASTERN_RESERVES_END_TURN then
local triggered = false
local player = Players [playerID]
Dprint("--------------------------------------------------------------------------------------------------------")
Dprint(" SCENARIO EVENT TRIGGERED: Eastern Reserves (Turn: "..turn..")")
Dprint("--------------------------------------------------------------------------------------------------------")
for i, unitData in ipairs (g_EasternReserveUnits) do
local turnTrigger = unitData.Turn
if turnTrigger == turn then
local spawnPlot = GetPlot(unitData.X, unitData.Y)
if spawnPlot:GetOwner() == playerID then
triggered = true
local unit = InitNewUnit(player, GameInfoTypes[unitData.UnitType], spawnPlot:GetX(), spawnPlot:GetY())
unit:SetName(unitData.UnitName)
Dprint("Reserve unit "..unit:GetName().." has arrived at plot "..spawnPlot:GetX()..","..spawnPlot:GetY())
end
end
end
if triggered == false then
Dprint("No reserves received this turn")
end
Dprint("-------- SCENARIO EVENT COMPLETED ----------------------------------------------------------------------")
end
end
and here is a snipped version of the global table it refers to:
Code:
g_EasternReserveUnits = {
-- Far East transfers (Plot: Sverdlovsk)
{Turn = 1, X = 89, Y = 67, UnitType = "UNIT_SOV_INF_1" , UnitName = "91" },
{Turn = 1, X = 89, Y = 67, UnitType = "UNIT_SOV_INF_1" , UnitName = "119" },
}
Now as mentioned, the above code does work so don't go thinking there is any problem. What I want is ideas or examples of how I could make the code randomize the arrival turn by plus 3 or minus 3 turns when compared to the "Turn" field in g_EasternReserveUnits table
This is the first time I have tried something like this and figure I need a way to track if a unit has appeared or something.
Any one up to the challenge please post your suggestion. Full credit will be given of course if a workable model is implemented in my scenario.
Cheers