local numSettlers = 3 ----------------------------set number of extra starting settlers for player
local numScouts = 3 ----------------------------set number of extra starting scouts
local numLegions = 3 ----------------------------set number of extra starting legions
local numBuilders = 3 ----------------------------set number of extra starting builders
local iScout = GameInfo.Units["UNIT_SCOUT"].Index
local iSettler = GameInfo.Units["UNIT_SETTLER"].Index
local iLegion = GameInfo.Units["UNIT_LEGION"].Index
local iBuilder = GameInfo.Units["UNIT_BUILDER"].Index
function OnPlayerTurnActivated( player, bIsFirstTime )
print("just a test-------------------------------------------------------------------------------");
local pUnit;
if (bIsFirstTime and player == Game.GetLocalPlayer()) then
local currentTurn = Game.GetCurrentGameTurn();
local SpawnTurn = 0;
local playerUnits;
local adjacentPlot;
local unitPlot;
if 1 == currentTurn then
local pPlayer = Players[player]
if pPlayer:IsHuman() then
playerUnits = pPlayer:GetUnits()
print("SpawnTurn", SpawnTurn) ;
for i, unit in playerUnits:Members() do
local unitTypeName = UnitManager.GetTypeName(unit)
print("unitTypeName", unitTypeName) ;
if "LOC_UNIT_SETTLER_NAME" == unitTypeName then
SpawnTurn = 1;
unitPlot = Map.GetPlot(unit:GetX(), unit:GetY());
print("SpawnTurn", SpawnTurn) ;
end
end
end
if SpawnTurn == 1 then
local lastPlot = unitPlot;
if numScouts > 0 then
for i = 1, numScouts do
for direction = 1, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
adjacentPlot = Map.GetAdjacentPlot((lastPlot:GetX() + 1), lastPlot:GetY(), direction);
if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) then
break
end
end
pUnit = playerUnits:Create(iScout, unitPlot:GetX(), unitPlot:GetY())
lastPlot = Map.GetPlot(pUnit:GetX(), pUnit:GetY());
end
end
if numSettlers > 0 then
for i = 1, numSettlers do
for direction = 1, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
adjacentPlot = Map.GetAdjacentPlot((lastPlot:GetX() ), lastPlot:GetY(), direction);
if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) then
break
end
end
pUnit2 = playerUnits:Create(iSettler, adjacentPlot:GetX(), adjacentPlot:GetY())
lastPlot = Map.GetPlot(pUnit:GetX(), pUnit:GetY());
end
end
if numLegions > 0 then
for i = 1, numLegions do
for direction = 1, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
adjacentPlot = Map.GetAdjacentPlot((lastPlot:GetX() ), lastPlot:GetY(), direction);
if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) then
break
end
end
pUnit2 = playerUnits:Create(iLegion, adjacentPlot:GetX(), adjacentPlot:GetY())
lastPlot = Map.GetPlot(pUnit:GetX(), pUnit:GetY());
end
end
if numBuilders > 0 then
for i = 1, numBuilders do
for direction = 1, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
adjacentPlot = Map.GetAdjacentPlot(lastPlot:GetX(), lastPlot:GetY(), direction);
if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) then
break
end
end
pUnit3 = playerUnits:Create(iBuilder, lastPlot:GetX(), lastPlot:GetY())
lastPlot = Map.GetPlot(pUnit:GetX(), pUnit:GetY());
end
end
Events.PlayerTurnActivated.Remove(OnPlayerTurnActivated)
end
end
end
end
function Initialize()
Events.PlayerTurnActivated.Add(OnPlayerTurnActivated)
print("just a test init-------------------------------------------------------------------------------");
end
Initialize();