local AIGold = 110
local AIFaith = 10
function FinishCivic(sCivic, pPlayer, iPlayer)
-- Dunno what this is for, probably checking to see how much culture has already been
-- researched for the civic?
local iCivic = DB.MakeHash(sCivic)
if iCivic ~= nil then
local pCulture = pPlayer:GetCulture()
if pCulture ~= nil then
-- Finding the civic cost, then applying it
local iCivicCost = pCulture:GetCultureCost(iCivic)
pCulture:SetCulturalProgress(iCivic, iCivicCost)
end
end
return nil
end
function GetTechID(sTech)
local tTechData = GameInfo.Technologies[sTech]
if tTechData == nil then
print("GetTechID: invalid sTech, returning -1")
return -1
end
return tTechData.Index
end
function FinishTech(sTech, pPlayer, iPlayer)
local iTech = GetTechID(sTech)
if iTech >= 0 then
local pPlayerTechs = pPlayer:GetTechs()
if pPlayerTechs ~= nil then
local iTechCost = pPlayerTechs:GetResearchCost(iTech)
if (iTechCost ~= nil) and (iTechCost > 0) then
pPlayerTechs:SetResearchProgress(iTech, iTechCost)
return true
end
end
end
return nil
end
function OnCityInit(iPlayer, iCityID, iX, iY)
local pCities = Players[iPlayer]:GetCities()
local pCity = pCities:FindID(iCityID)
if pCity ~= nil then
if (pCity == pCities:GetCapitalCity()) then
-- Add additional population to the city
pCity:ChangePopulation(3)
end
end
end
function Initilize(iPlayer, iCityID, iX, iY)
local pPlayer = Players[iPlayer]
-- Is this the start turn?
--if Game.GetCurrentGameTurn() == GameConfiguration.GetStartTurn() then
-- Is the player human? If yes, skip. They don't get any advantage!
if not pPlayer:IsHuman() then
pPlayer:GetTreasury():SetGoldBalance(AIGold)
pPlayer:GetReligion():SetFaithBalance(AIFaith)
OnCityInit(iPlayer, iCityID, iX, iY)
-- Give the AI all of the ancient era civics
FinishCivic("CIVIC_CODE_OF_LAWS", pPlayer, iPlayer)
FinishCivic("CIVIC_CRAFTSMANSHIP", pPlayer, iPlayer)
FinishCivic("CIVIC_FOREIGN_TRADE", pPlayer, iPlayer)
FinishCivic("CIVIC_MILITARY_TRADITION", pPlayer, iPlayer)
FinishCivic("CIVIC_STATE_WORKFORCE", pPlayer, iPlayer)
FinishCivic("CIVIC_EARLY_EMPIRE", pPlayer, iPlayer)
FinishCivic("CIVIC_MYSTICISM", pPlayer, iPlayer)
-- Give the AI all of the ancient era techs
FinishTech("TECH_POTTERY", pPlayer, iPlayer)
FinishTech("TECH_ANIMAL_HUSBANDRY", pPlayer, iPlayer)
FinishTech("TECH_MINING", pPlayer, iPlayer)
FinishTech("TECH_SAILING", pPlayer, iPlayer)
FinishTech("TECH_ASTROLOGY", pPlayer, iPlayer)
FinishTech("TECH_IRRIGATION", pPlayer, iPlayer)
FinishTech("TECH_WRITING", pPlayer, iPlayer)
FinishTech("TECH_ARCHERY", pPlayer, iPlayer)
FinishTech("TECH_MASONRY", pPlayer, iPlayer)
FinishTech("TECH_BRONZE_WORKING", pPlayer, iPlayer)
FinishTech("TECH_THE_WHEEL", pPlayer, iPlayer)
end
end
-- Function called once a city is founded. Calls initilization if it is the capital city
function OEB_CityFounded(iPlayer, iCityID)
local pCities = Players[iPlayer]:GetCities()
local pCity = pCities:FindID(iCityID)
if pCity ~= nil then
if (pCity == pCities:GetCapitalCity()) and (pCities:GetCount() == 1) then
Initilize(iPlayer, iCityID, pCity:GetX(), pCity:GetY())
end
end
end
-- Give the human a warrior, I guess....
function GiveStupidHumanWarrior(iPlayer)
-- Is this the start turn?
if Game.GetCurrentGameTurn() == GameConfiguration.GetStartTurn() then
local SpawnTurn = 0
local playerUnits
local pPlayer = Players[iPlayer]
local unitPlot
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
local unitIndex = GameInfo.Units["UNIT_WARRIOR"].Index
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
playerUnits:Create(unitIndex, adjacentPlot:GetX(), adjacentPlot:GetY())
lastPlot = adjacentPlot;
break
end
end
-- Remove this event handler so it does not get called on every game turn afterwards
Events.PlayerTurnActivated.Remove(GiveStupidHumanWarrior)
end
end
end
-- Function to inilize OEB_CityFounded function, which runs whenever a city is founded
function OnLoadScreenClose()
Events.CityInitialized.Add(OEB_CityFounded)
--Events.PlayerTurnActivated.Add(OnPlayerTurnActivated);
end
Events.LoadScreenClose.Add(OnLoadScreenClose)
-- Add the function to be called when a player turn is activated (AI or Human)
Events.PlayerTurnActivated.Add(GiveStupidHumanWarrior)