
function ProjectCreatBarbarians(playerId, cityID, projectIndex, buildingIndex, locX, locY, bCanceled)
	local pPlayer = Players[playerId];
	local playerConfig = PlayerConfigurations[playerId];
	local capitalCity = pPlayer:GetCities():GetCapitalCity();
	local pCity = pPlayer:GetCities():FindID(cityID);
	local pDistricts = pCity:GetDistricts();
	local pTheater = pDistricts:GetDistrict(GameInfo.Districts["DISTRICT_THEATER"].Index);
	local projectInfo = GameInfo.Projects[projectIndex];
	local projectType = projectInfo.ProjectType;

	local spawnUnitType = "UNIT_WARRIOR";
	
	local randomNum = math.random(1,5);
	local spawnNum = 1;
	
	if (playerConfig:GetCivilizationTypeName() == "CIVILIZATION_IMAS") then
		if (projectType == "PROJECT_IDOL_SCOUT") then
			if pTheater ~= nil then
				local districtX = pTheater:GetX();
				local districtY = pTheater:GetY();
				if (pPlayer:GetTechs():HasTech(GameInfo.Technologies["TECH_SATELLITES"].Index)) then
					spawnUnitType = "UNIT_MECHANIZED_INFANTRY";
				else
					if (pPlayer:GetTechs():HasTech(GameInfo.Technologies["TECH_REPLACEABLE_PARTS"].Index)) then
						spawnUnitType = "UNIT_INFANTRY";
					else
						if (pPlayer:GetTechs():HasTech(GameInfo.Technologies["TECH_GUNPOWDER"].Index)) then
							spawnUnitType = "UNIT_MUSKETMAN";
						else
							if (pPlayer:GetTechs():HasTech(GameInfo.Technologies["TECH_IRON_WORKING"].Index)) then
								spawnUnitType = "UNIT_SWORDSMAN";
							end
						end
					end
				end
				UnitManager.InitUnitValidAdjacentHex(63, spawnUnitType, districtX, districtY, 1);
				while (spawnNum < randomNum) do
					UnitManager.InitUnitValidAdjacentHex(63, spawnUnitType, districtX, districtY, 1);
					spawnNum = spawnNum + 1;
				end
			end
		end
	end
end
Events.CityProjectCompleted.Add( ProjectCreatBarbarians );