--__________         __    __  .__           ___________
--\______   \_____ _/  |__/  |_|  |   ____   \_   _____/__________
-- |    |  _/\__  \\   __\   __\  | _/ __ \   |    __)/  _ \_  __ \
-- |    |   \ / __ \|  |  |  | |  |_\  ___/   |     \(  <_> )  | \/
-- |______  /(____  /__|  |__| |____/\___  >  \___  / \____/|__|
--        \/      \/                     \/       \/
--   _____                     .___.__
--  /     \ _____    ____    __| _/|__| ____  ___________
-- /  \ /  \\__  \  /    \  / __ | |  |/ ___\/  _ \_  __ \
--/    Y    \/ __ \|   |  \/ /_/ | |  \  \__(  <_> )  | \/
--\____|__  (____  /___|  /\____ | |__|\___  >____/|__|
--        \/     \/     \/      \/         \/

--      land_attack.lua - Define the land attack AI.
--
--      (c) Copyright 2005 by Kimmo Merikivi
--
--      This program is free software; you can redistribute it and/or modify
--      it under the terms of the GNU General Public License as published by
--      the Free Software Foundation; either version 2 of the License, or
--      (at your option) any later version.
--  
--      This program is distributed in the hope that it will be useful,
--      but WITHOUT ANY WARRANTY; without even the implied warranty of
--      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--      GNU General Public License for more details.
--  
--      You should have received a copy of the GNU General Public License
--      along with this program; if not, write to the Free Software
--      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
--
--      $Id: land_attack-darkness.lua,v 1.3 2005/04/03 10:58:48 mikkommm Exp $

ai_land_attack_func = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
ai_land_attack_end_loop_func = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}

local player

local end_loop_funcs = {
	function() print("Looping !") return false end,
	function() return AiForce(0, {"unit-darkness-spearman", 30, "unit-darkness-bowman", 20}) end,
	function() return AiForce(1, {"unit-darkness-warrior", 50, "unit-darkness-spearman", 50, 
	"unit-darkness-bowman", 50}) end,
	function() return AiWaitForce(1) end,
	function() return AiAttackWithForce(1) end,
	function() return AiAttackWithForce(1) end,
	function() return AiSleep(50) end,
	function() ai_land_attack_end_loop_func[player] = 0; return false end,
}

function AilandAttackDarknessEndloop()
	local ret

	while (true) do
		ret = end_loop_funcs[ai_land_attack_end_loop_func[player]]()
	if (ret) then
		break
end
	ai_land_attack_end_loop_func[player] = ai_land_attack_end_loop_func[player] + 1
end
	return true
end

local land_funcs = {
	function() AiDebug(false) return false end,
	function() return AiNeed("unit-darkness-camp") end,
	function() return AiWait("unit-darkness-camp") end,

	function() return AiSet("unit-darkness-worker", 20) end,
	function() return AiNeed("unit-darkness-blacksmith") end,
	function() return AiResearch("upgrade-darkness-bows") end,
	function() return AiResearch("upgrade-darkness-swords") end,
	function() return AiNeed("unit-darkness-garrison") end,
	function() return AiNeed("unit-darkness-garrison") end,
	function() return AiForce(0, {"unit-darkness-warrior", 5, "unit-darkness-bowman", 2}) end,
	function() return AiForce(1, {"unit-darkness-warrior", 5}) end,
	function() return AiWaitForce(1) end,
	function() return AiAttackWithForce(1) end,
	function() return AiAttackWithForce(1) end,

	function() return AiResearch("upgrade-darkness-level2") end,
	function() return AiSleep(550) end,
	function() return AiSet("unit-darkness-worker", 40) end,

	function() return AiNeed("unit-darkness-garrison") end,
	function() return AiNeed("unit-darkness-blacksmith") end,
	function() return AiNeed("unit-darkness-lumber-storage") end,
	function() return AiResearch("upgrade-darkness-better-swords") end,
	function() return AiResearch("upgrade-darkness-better-shields") end,
	function() return AiResearch("upgrade-darkness-better-helmets") end,
	function() return AiResearch("upgrade-darkness-spears") end,
	function() return AiNeed("unit-darkness-garrison") end,
	function() return AiNeed("unit-darkness-garrison") end,
	function() return AiForce(0, {"unit-darkness-spearman", 10, "unit-darkness-bowman", 10}) end,
	function() return AiForce(1, {"unit-darkness-warrior", 40, "unit-darkness-spearman", 30, 
	"unit-darkness-bowman", 30}) end,
	function() return AiWaitForce(1) end,
	function() return AiAttackWithForce(1) end,
	function() return AiAttackWithForce(1) end,


  -- Everything researched...

	function() return AilandAttackDarknessEndloop() end,
}

function AilandAttackDarkness()
	local ret

	player = AiPlayer() + 1

	while (true) do
--    print("Executing land_funcs[" .. ai_land_attack_func[player] .. "]")
		ret = land_funcs[ai_land_attack_func[player]]()
		if (ret) then
			break
		end
		ai_land_attack_func[player] = ai_land_attack_func[player] + 1
	end
end

DefineAi("wc2-land-attack-darkness", "darkness", "land-attack", AilandAttackDarkness)
