local Tech_One = GameInfo.Technologies["TECH_POTTERY"];
local Tech_Two = GameInfo.Technologies["TECH_ANIMAL_HUSBANDRY"];
local Tech_Three = GameInfo.Technologies["TECH_MINING"];
local Tech_Four = GameInfo.Technologies["TECH_ASTROLOGY"];
local Tech_Five = GameInfo.Technologies["TECH_IRRIGATION"];
local Tech_Six = GameInfo.Technologies["TECH_WRITING"];
local Tech_Seven = GameInfo.Technologies["TECH_ARCHERY"];
local Tech_Eight = GameInfo.Technologies["TECH_BRONZE_WORKING"];
local Civics_One = GameInfo.Civics["CIVIC_CODE_OF_LAWS"];
local Civics_Two = GameInfo.Civics["CIVIC_CRAFTSMANSHIP"];
local Civics_Three = GameInfo.Civics["CIVIC_FOREIGN_TRADE"];
local Civics_Four = GameInfo.Civics["CIVIC_MILITARY_TRADITION"];
local Civics_Five = GameInfo.Civics["CIVIC_STATE_WORKFORCE"];
local Civics_Six = GameInfo.Civics["CIVIC_EARLY_EMPIRE"];
local Civics_Seven = GameInfo.Civics["CIVIC_MYSTICISM"];
local Civics_Eight = GameInfo.Civics["CIVIC_GAMES_RECREATION"];
function OnPlayerTurnActivated( player, bIsFirstTime )
local currentTurn = Game.GetCurrentGameTurn();
local SpawnTurn = 0;
local playerUnits;
local adjacentPlot;
local unitPlot;
if currentTurn == GameConfiguration.GetStartTurn() then
local pPlayer = Players[player]
if pPlayer:IsHuman() then
playerUnits = pPlayer:GetUnits()
for i, unit in playerUnits:Members() do
local unitTypeName = UnitManager.GetTypeName(unit)
if "LOC_UNIT_SETTLER_NAME" == unitTypeName then
SpawnTurn = 1;
unitPlot = Map.GetPlot(unit:GetX(), unit:GetY());
end
end
end
if SpawnTurn == 1 then
local lastPlot = unitPlot;
if NumOne > 0 then
for i = 1, NumOne 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(iOne, unitPlot:GetX(), unitPlot:GetY())
lastPlot = Map.GetPlot(pUnit:GetX(), pUnit:GetY());
end
end
if NumTwo > 0 then
for i = 1, NumTwo do
for direction = 1, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
adjacentPlot = Map.GetAdjacentPlot((lastPlot:GetX()), (lastPlot:GetY() - 1), direction);
if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) then
break
end
end
pUnit2 = playerUnits:Create(iTwo, adjacentPlot:GetX(), adjacentPlot:GetY())
lastPlot = Map.GetPlot(pUnit:GetX(), pUnit:GetY());
end
end
if NumThree > 0 then
for i = 1, NumThree 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
pUnit3 = playerUnits:Create(iThree, adjacentPlot:GetX(), adjacentPlot:GetY())
lastPlot = Map.GetPlot(pUnit:GetX(), pUnit:GetY());
end
end
if NumFour > 0 then
for i = 1, NumFour do
for direction = 1, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
adjacentPlot = Map.GetAdjacentPlot((lastPlot:GetX() ), (lastPlot:GetY() + 1), direction);
if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) then
break
end
end
pUnit4 = playerUnits:Create(iFour, adjacentPlot:GetX(), adjacentPlot:GetY())
lastPlot = Map.GetPlot(pUnit:GetX(), pUnit:GetY());
end
end
if NumFive > 0 then
for i = 1, NumFive 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
pUnit5 = playerUnits:Create(iFive, lastPlot:GetX(), lastPlot:GetY())
lastPlot = Map.GetPlot(pUnit:GetX(), pUnit:GetY());
end
end
pPlayer:GetTreasury():SetGoldBalance(PlayerGold);
local curPlayerTech = pPlayer:GetTechs();
if(curPlayerTech ~= nil) then
if (Tech_One ~= nil) then
curPlayerTech:SetResearchProgress(Tech_One.Index, curPlayerTech:GetResearchCost(Tech_One.Index));
end
if(Tech_Two ~= nil) then
curPlayerTech:SetResearchProgress(Tech_Two.Index, curPlayerTech:GetResearchCost(Tech_Two.Index));
end
if(Tech_Three ~= nil) then
curPlayerTech:SetResearchProgress(Tech_Three.Index, curPlayerTech:GetResearchCost(Tech_Three.Index));
end
if(Tech_Four ~= nil) then
curPlayerTech:SetResearchProgress(Tech_Four.Index, curPlayerTech:GetResearchCost(Tech_Four.Index));
end
if(Tech_Five ~= nil) then
curPlayerTech:SetResearchProgress(Tech_Five.Index, curPlayerTech:GetResearchCost(Tech_Five.Index));
end
if(Tech_Six ~= nil) then
curPlayerTech:SetResearchProgress(Tech_Six.Index, curPlayerTech:GetResearchCost(Tech_Six.Index));
end
if(Tech_Seven ~= nil) then
curPlayerTech:SetResearchProgress(Tech_Seven.Index, curPlayerTech:GetResearchCost(Tech_Seven.Index));
end
if(Tech_Eight ~= nil) then
curPlayerTech:SetResearchProgress(Tech_Eight.Index, curPlayerTech:GetResearchCost(Tech_Eight.Index));
end
end
local curPlayerCivics = pPlayer:GetCivics();
if(curPlayerCivics ~= nil) then
if (Civics_One ~= nil) then
curPlayerCivics:SetResearchProgress(Civics_One.Index, curPlayerCivics:GetResearchCost(Civics_One.Index));
end
if(Civics_Two ~= nil) then
curPlayerCivics:SetResearchProgress(Civics_Two.Index, curPlayerCivics:GetResearchCost(Civics_Two.Index));
end
if(Civics_Three ~= nil) then
curPlayerCivics:SetResearchProgress(Civics_Three.Index, curPlayerCivics:GetResearchCost(Civics_Three.Index));
end
if(Civics_Four ~= nil) then
curPlayerCivics:SetResearchProgress(Civics_Four.Index, curPlayerCivics:GetResearchCost(Civics_Four.Index));
end
if(Civics_Five ~= nil) then
curPlayerCivics:SetResearchProgress(Civics_Five.Index, curPlayerCivics:GetResearchCost(Civics_Five.Index));
end
if(Civics_Six ~= nil) then
curPlayerCivics:SetResearchProgress(Civics_Six.Index, curPlayerCivics:GetResearchCost(Civics_Six.Index));
end
if(Civics_Seven ~= nil) then
curPlayerCivics:SetResearchProgress(Civics_Seven.Index, curPlayerCivics:GetResearchCost(Civics_Seven.Index));
end
if(Civics_Eight ~= nil) then
curPlayerCivics:SetResearchProgress(Civics_Eight.Index, curPlayerCivics:GetResearchCost(Civics_Eight.Index));
end
end
end
end
end
function Initialize()
Events.LocalPlayerChanged.Add( OnPlayerTurnActivated );
Events.PlayerTurnActivated.Add(OnPlayerTurnActivated);
end
Initialize();