-- DS_GameScript
-- Author: KCucumber
-- DateCreated: 6/21/2017 9:38:27 PM
--------------------------------------------------------------
function UndeadResurrection(playerId)
	local pPlayer = Players[playerId];
	local playerUnits = pPlayer:GetUnits();
	local playerConfig = PlayerConfigurations[playerId];
	local capitalCity = pPlayer:GetCities():GetCapitalCity();
	local UDNumber = 0;
	local UDRNumber = 0;

	if playerConfig:GetCivilizationTypeName() == "CIVILIZATION_FIRELINK" then
	    for i, unit in playerUnits:Members() do
			local unitInfo = GameInfo.Units[unit:GetType()];
			if unitInfo.UnitType == "UNIT_UNDEAD" then
				UDNumber = UDNumber +1;
			end
			if unitInfo.UnitType == "UNIT_UNDEAD_RANGE" then
				UDRNumber = UDRNumber +1;
			end
		end
		if UDNumber < 4 then
			UDNumber = 3 - UDNumber;
			for i = 0, UDNumber, 1 do
				pPlayer:GetUnits():Create(GameInfo.Units["UNIT_UNDEAD"].Index, capitalCity:GetX(), capitalCity:GetY());
			end
		end
		if UDRNumber < 2 then
			UDRNumber = 1 - UDRNumber
			for i = 0, UDRNumber, 1 do
				pPlayer:GetUnits():Create(GameInfo.Units["UNIT_UNDEAD_RANGE"].Index, capitalCity:GetX(), capitalCity:GetY());
			end
		end
	end
end
GameEvents.PlayerTurnStarted.Add(UndeadResurrection);
--------------------------------------------------------------
--function UndeadTeleport(playerId)
--	local pPlayer = Players[playerId];
--	local playerConfig = PlayerConfigurations[playerId];
--	local currentTurn = Game.GetCurrentGameTurn();

--	if (playerConfig:GetCivilizationTypeName() == "CIVILIZATION_FIRELINK" and currentTurn == 1) then
--		pPlayer:GetCulture():SetCivic(GameInfo.Civics["CIVIC_RAPID_DEPLOYMENT"].Index, true);
--		pPlayer:GetTechs():SetTech(GameInfo.Technologies["TECH_ADVANCED_FLIGHT"].Index, true);
--	end
--end
--GameEvents.PlayerTurnStarted.Add(UndeadTeleport);

function UndeadTeleport(playerId)
	local pPlayer = Players[playerId];
	local playerConfig = PlayerConfigurations[playerId];

	if (playerConfig:GetCivilizationTypeName() == "CIVILIZATION_FIRELINK") then
		pPlayer:GetCulture():SetCivic(GameInfo.Civics["CIVIC_RAPID_DEPLOYMENT"].Index, true);
		pPlayer:GetTechs():SetTech(GameInfo.Technologies["TECH_ADVANCED_FLIGHT"].Index, true);
	end
end
Events.PlayerEraChanged.Add(UndeadTeleport);
--------------------------------------------------------------
--function UndeadDead(playerId,unitId)
--	local pPlayer = Players[playerId];
--	local playerConfig = PlayerConfigurations[playerId];

--	if (playerConfig:GetCivilizationTypeName() == "CIVILIZATION_FIRELINK" and (unitId == GameInfo.Units.UNIT_UNDEAD.ID || unitId == GameInfo.Units.UNIT_UNDEAD_RANGE.ID)) then
--		print("YOU DIED");
--	end
--end
--GameCoreEvent.UnitKilledInCombat.Add(UndeadDead);