-- DAWS_Package for DCSW -- Enhanced AI -- module Automatic Artillery fire
local MainVersion = "2"
local SubVersion = "3"
local Build = "2351"

-- THANKS TO (cronological order):
	-- Rider (AMVI)
	-- Grimes (ED community)
	-- MBot (ED community)
	-- xcom (ED community)
	-- Ian (ED community)
	-- vicx (ED community)
	-- Pikey (ED community)
	-- ESAC_Matador (ED community)

	
-- ################################################################################################################################
-- ################################################################################################################################
-- ################################################################################################################################
-- ################################################################################################################################
-- ################################################################################################################################
-- ################################################################################################################################
-- ################################################################################################################################

	-- local function copy
	local base 						= _G
	local require 					= base.require
	local table 					= base.table
	local math 						= base.math
	local string					= base.string
	local pairs 					= base.pairs
	local ipairs 					= base.ipairs
	local print 					= base.print
	local io 						= base.io
	local lfs 						= base.lfs
	local os 						= base.os
	local zip 						= minizip
	local loadstring 				= base.loadstring
	--]]--
	
	-- common directory listing
	local mistdirectory 			= mistdirectoryDP -- lfs.currentdir() .. "AMVI/Common/Code/"
	local moddirectory 				= moddirectoryAE 	-- lfs.currentdir() .. "AMVI/AIEnhancement/"
	local debugdirectory  			= debugdirectoryAE	--lfs.currentdir() .. "AMVI/AIEnhancement/Debug/"
	local missionfilesdirectory 	= missionfilesdirectoryDP -- lfs.writedir() .. "Missions/"
	local logsdirectory				= logsdirectoryDP -- lfs.writedir() .. "Logs/"
	local artyactiveforblue			= true -- artyactiveforblueDP
	local artyactiveforred			= true -- artyactiveforredDP
	
	-- common export variables
	local exportfiletype 			= ".csv"
	--reportfiletype 				= ".doc"
	local configfiletype 			= ".csv"
	local tss 						= ";"
	
	--##### INTERNAL VARIABLES
	local debugProcess 				= DAWSdebugProcess -- print information log in dcs.log
	local StatedebugProcess			= DAWSdebugProcess
	--local useDismountedUnits		= false
	local artyRange					= 10000 -- meters. Placeholder since I found a viable way to get each arty unit range
	local mlrsRange					= 20000 -- meters. Placeholder since I found a viable way to get each arty unit range
	local GlobalState				= "A"
	local PastGlobalState			= "X"
	
	
	--improved random
	do
	   local oldrandom = math.random
	   local randomtable
	   math.random = function ()
		  if randomtable == nil then
			 randomtable = {}
			 for i = 1, 97 do
				randomtable[i] = oldrandom()
			 end
		  end
		  local x = oldrandom()
		  local i = 1 + math.floor(97*x)
		  x, randomtable[i] = randomtable[i], x
		  return x
	   end
	end	
	
	local updateShift 				= 0.1 	-- seconds between operations
	local stateShift				= 1		-- seconds between each state
	local cycleShift 				= 300 	-- seconds between the cycle repeat
	local tblArtyCount 				= 0
	
	
-- ################################################################################################################################
-- ################################################################################################################################
-- ################################################################################################################################
-- ################################################################################################################################
-- ################################################################################################################################
-- ################################################################################################################################
-- ################################################################################################################################

	
	--Table that holds all ground units that have at least an arty unit
	local tblArtyGroups = {}
	if debugProcess == true then
		env.info(("DAWS AIE  -  Automatic Artillery fire is loading..."))
	end
	
	--Table that holds all ground groups name for faster recalling
	local tblGroupsNames = {}

	--Table that holds all current known and in visual targets
	local tblKnownEnemy = {}		
	
	-- populate arty table
	createArtyTable = function()
		if debugProcess == true then
			env.info(("DAWS AIE  -  launching createArtyTable"))
		end	
		
		local red_groups = coalition.getGroups(1)
		if debugProcess == true then
			env.info(("DAWS AIE  -  createArtyTable: red_groups gathered"))
		end			
		for _, group_data in pairs(red_groups) do
			local grouphasarty 		= false
			local grouphasMLRS 		= false			
			local groupName 		= Group.getName(group_data)
			if debugProcess == true then
				env.info(("DAWS AIE  -  createArtyTable: groupName gathered"))
			end			
			local groupCoa			= "red"
			if debugProcess == true then
				env.info(("DAWS AIE  -  createArtyTable: groupCoa gathered"))
			end				
			local groupUnits		= Group.getUnits(group_data)
			if debugProcess == true then
				env.info(("DAWS AIE  -  createArtyTable: groupUnits gathered"))
			end
			local groupPos			= nil -- retrieve from units
			if debugProcess == true then
				env.info(("DAWS AIE  -  createArtyTable: groupPos gathered"))
			end	
			
			tblGroupsNames[#tblGroupsNames + 1] = {name = groupName, coa = groupCoa}
			if debugProcess == true then
				env.info(("DAWS AIE  -  adding " .. groupName .. " to tblGroupsNames"))
			end
			
			if  groupUnits and #groupUnits > 0 then
				local posalreadyfound = false
				for id, unitData in pairs(groupUnits) do
					if unitData then
						local unitName = Unit.getName(unitData)
						if posalreadyfound == false then
							groupPos = Unit.getPosition(unitData).p
							posalreadyfound = true
						end
						if debugProcess == true then
							env.info(("DAWS AIE  -  from " .. groupName .. " evaluating " .. unitName))
						end												
						if unitData:hasAttribute("Artillery") then
							grouphasarty = true
							if debugProcess == true then
								env.info(("DAWS AIE  -  from " .. groupName .. " evaluating " .. unitName .. ": is arty"))
							end										
						elseif unitData:hasAttribute("MLRS") then
							grouphasMLRS = true
							if debugProcess == true then
								env.info(("DAWS AIE  -  from " .. groupName .. " evaluating " .. unitName .. ": is MLRS"))
							end												
						end
					end
				end
			end
			
			if grouphasarty == true then
				if debugProcess == true then
					env.info(("DAWS AIE  -  adding " .. groupName .. " to tblArtyGroups"))
				end											
				tblArtyGroups[#tblArtyGroups + 1] = {name = groupName, range = artyRange, coa = groupCoa, position = groupPos, hasmission = false}
			elseif grouphasMLRS == true then	
				if debugProcess == true then
					env.info(("DAWS AIE  -  adding " .. groupName .. " to tblArtyGroups"))
				end											
				tblArtyGroups[#tblArtyGroups + 1] = {name = groupName, range = mlrsRange, coa = groupCoa, position = groupPos, hasmission = false}										
			end		
		end
		
		local blue_groups = coalition.getGroups(2)
		if debugProcess == true then
			env.info(("DAWS AIE  -  createArtyTable: blue_groups gathered"))
		end			
		for _, group_data in pairs(blue_groups) do
			local grouphasarty 		= false
			local grouphasMLRS 		= false			
			local groupName 		= Group.getName(group_data)
			if debugProcess == true then
				env.info(("DAWS AIE  -  createArtyTable: groupName gathered"))
			end			
			local groupCoa			= "blue"
			if debugProcess == true then
				env.info(("DAWS AIE  -  createArtyTable: groupCoa gathered"))
			end				
			local groupUnits		= Group.getUnits(group_data)
			if debugProcess == true then
				env.info(("DAWS AIE  -  createArtyTable: groupUnits gathered"))
			end				
			local groupPos			= nil -- retrieve from units
			if debugProcess == true then
				env.info(("DAWS AIE  -  createArtyTable: groupPos gathered"))
			end	
			
			tblGroupsNames[#tblGroupsNames + 1] = {name = groupName, coa = groupCoa}
			if debugProcess == true then
				env.info(("DAWS AIE  -  adding " .. groupName .. " to tblGroupsNames"))
			end
			
			if  groupUnits and #groupUnits > 0 then
				local posalreadyfound = false
				for id, unitData in pairs(groupUnits) do
					if unitData then
						local unitName = Unit.getName(unitData)
						if posalreadyfound == false then
							groupPos = Unit.getPosition(unitData).p
							posalreadyfound = true
						end
						if debugProcess == true then
							env.info(("DAWS AIE  -  from " .. groupName .. " evaluating " .. unitName))
						end												
						if unitData:hasAttribute("Artillery") then
							grouphasarty = true
							if debugProcess == true then
								env.info(("DAWS AIE  -  from " .. groupName .. " evaluating " .. unitName .. ": is arty"))
							end										
						elseif unitData:hasAttribute("MLRS") then
							grouphasMLRS = true
							if debugProcess == true then
								env.info(("DAWS AIE  -  from " .. groupName .. " evaluating " .. unitName .. ": is MLRS"))
							end												
						end
					end
				end
			end
			
			if grouphasarty == true then
				if debugProcess == true then
					env.info(("DAWS AIE  -  adding " .. groupName .. " to tblArtyGroups"))
				end											
				tblArtyGroups[#tblArtyGroups + 1] = {name = groupName, range = artyRange, coa = groupCoa, position = groupPos, hasmission = false}
			elseif grouphasMLRS == true then	
				if debugProcess == true then
					env.info(("DAWS AIE  -  adding " .. groupName .. " to tblArtyGroups"))
				end											
				tblArtyGroups[#tblArtyGroups + 1] = {name = groupName, range = mlrsRange, coa = groupCoa, position = groupPos, hasmission = false}										
			end		
		end		
		
		if tblArtyGroups then
			tblArtyCount = table.getn(tblArtyGroups)
		end
		if debugProcess == true then
			env.info(("DAWS AIE  -  tblArtyCount:" .. tonumber(tblArtyCount)))
		end			
		if debugProcess == true then
			if DAWS.dumpTable then
				DAWS.dumpTable("tblArtyGroups.lua", tblArtyGroups)
				DAWS.dumpTable("tblGroupsNames.lua", tblGroupsNames)
			end
		end
	end
	
	-- check known groups
	local UpdateArtyIntel_statenum = 1		
	UpdateArtyIntel = function()		
		if debugProcess == true then
			env.info(("DAWS AIE  -  UpdateArtyIntel has been launched"))
		end		
		local numfound = false
		
		for id, groupData in pairs(tblGroupsNames) do
			if id == UpdateArtyIntel_statenum then
				numfound = true
				local groupTargets = Group.getByName(groupData.name):getController():getDetectedTargets()
				
				if type(groupTargets) == 'table' and #groupTargets > 0 then
					if debugProcess == true then
						env.info(("DAWS AIE  -  UpdateArtyIntel found tgt table for " .. groupData.name .. " with " .. table.getn(groupTargets) .. " targets"))
					end				
				
					for _, targets in pairs(groupTargets) do
						if debugProcess == true then
							env.info(("DAWS AIE  -  UpdateArtyIntel found tgt as vehicle or static"))
						end						
						local tgtData 			= targets.object
						if debugProcess == true then
							env.info(("DAWS AIE  -  UpdateArtyIntel tgt tgtData table gathered"))
						end						
						local tunitPos 			= tgtData:getPosition().p
						if debugProcess == true then
							env.info(("DAWS AIE  -  UpdateArtyIntel tgt tunitPos gathered"))
						end						
						local tunitPriority 	= 1 -- placeholder for further improvements
						if debugProcess == true then
							env.info(("DAWS AIE  -  UpdateArtyIntel tgt tunitPriority gathered"))
						end						
						local tunitVelocity 	= tgtData:getVelocity()
						if debugProcess == true then
							env.info(("DAWS AIE  -  UpdateArtyIntel tgt tunitVelocity gathered"))
						end						
						local tunitTime 		= timer.getAbsTime() -- simulation time in seconds
						if debugProcess == true then
							env.info(("DAWS AIE  -  UpdateArtyIntel tgt tunitTime gathered"))
						end						
						local tunitId 			= tgtData.id_
						if debugProcess == true then
							env.info(("DAWS AIE  -  UpdateArtyIntel tgt tunitId gathered"))
						end						
						local tunitFlying 		= tgtData:inAir()
						if debugProcess == true then
							env.info(("DAWS AIE  -  UpdateArtyIntel tgt tunitFlying gathered"))
						end	
						local tunitCoa = nil
						local tunitCoaNum 		= tgtData:getCoalition()
						if tunitCoaNum == 1 then
							tunitCoa = "red"
						elseif tunitCoaNum == 2 then
							tunitCoa = "blue"
						end						
						if debugProcess == true then
							env.info(("DAWS AIE  -  UpdateArtyIntel tgt tunitCoa gathered"))
						end						
						local tunitType 		= tgtData:getTypeName()
						if debugProcess == true then
							env.info(("DAWS AIE  -  UpdateArtyIntel tgt tunitType gathered"))
						end
								
						local tunitisnotmoving = false
						--checkspeed = 0
						if tunitVelocity then
							if tunitVelocity.x == 0 and tunitVelocity.z == 0 then
								tunitisnotmoving = true
								if debugProcess == true then
									env.info(("DAWS AIE  -  UpdateArtyIntel tgt data: tunitvelocity is 0"))
								end
							end
						end
						
						if debugProcess == true then
							env.info(("DAWS AIE  -  UpdateArtyIntel tgt data: Type = " .. tunitType .. ", Coa = " .. tunitCoa .. ", Time = " .. tunitTime))
						end
						if tunitisnotmoving == true then
							if table.getn(tblKnownEnemy) > 0 then
								for tid, knownData in pairs (tblKnownEnemy) do
									if knownData.unitId == tunitId then
										table.remove(tblKnownEnemy, tid)
									end
								end
								tblKnownEnemy[#tblKnownEnemy + 1] = {unitId = tunitId, unitType = tunitType, unitPos = tunitPos, unitCoa = tunitCoa, unitTime = tunitTime}
							else
								tblKnownEnemy[#tblKnownEnemy + 1] = {unitId = tunitId, unitType = tunitType, unitPos = tunitPos, unitCoa = tunitCoa, unitTime = tunitTime}
							end
						end 
						
					end
				else
					if debugProcess == true then
						env.info(("DAWS AIE  -  UpdateArtyIntel did not find targets for " .. groupData.name))
					end								
				end
			end
		end
		
		if numfound == false then
			UpdateArtyIntel_statenum = 1
			if debugProcess == true then
				env.info(("DAWS AIE  -  UpdateArtyIntel has ended its cycle"))
			end
			if DAWS.dumpTable then
				DAWS.dumpTable("tblKnownEnemy.lua", tblKnownEnemy)
			end			
			timer.scheduleFunction(ChangeArtyState, {}, timer.getTime()+ 1)
			
		else
			UpdateArtyIntel_statenum = UpdateArtyIntel_statenum + 1		
			timer.scheduleFunction(UpdateArtyIntel, {}, timer.getTime()+ updateShift)
		end			
	end	
	
	-- set fire missions
	local InsertArtyFireMission_statenum = 1	
	local CurrentNumTargets = 1
	InsertArtyFireMission = function()		
		if debugProcess == true then
			env.info(("DAWS AIE  -  InsertArtyFireMission has been launched"))
		end		
		local numfound = false
		local numtargets = table.getn(tblKnownEnemy)
		
		if numtargets > 0 then
			for id, groupData in pairs(tblArtyGroups) do
				if id == InsertArtyFireMission_statenum then
					numfound = true
					
					if debugProcess == true then
						env.info(("DAWS AIE  -  InsertArtyFireMission is evaluating data for " .. groupData.name))
					end		
					
					local artyPos = groupData.position
					local artyCoa = groupData.coa
					local currentTargetsArrayPoint = CurrentNumTargets
					local repeatcycle = false
					for tid, tgtData in pairs(tblKnownEnemy) do
						if tid >= currentTargetsArrayPoint and tid < currentTargetsArrayPoint+10 then
							repeatcycle = true
							if tgtData.unitCoa ~= artyCoa then
								if debugProcess == true then
									env.info(("DAWS AIE  -  InsertArtyFireMission is evaluating data for " .. groupData.name .. ", evaluating distance from a " .. tgtData.unitType))
								end								
								local tPos = tgtData.unitPos
								local distance = mist.utils.get3DDist(artyPos, tPos)
								if distance < groupData.range and groupData.hasmission == false then
									if debugProcess == true then
										env.info(("DAWS AIE  -  InsertArtyFireMission is evaluating data for " .. groupData.name .. ", target is in range, setting fire mission"))
									end											
									
									groupData.hasmission = true
									
									local target = {}
									target.x = tPos.x
									target.y = tPos.z
									target.radius = 200
									target.expendQty = 40
									target.expendQtyEnabled = true
									local fire = {id = 'FireAtPoint', params = target}
								
									if debugProcess == true then
										env.info(("DAWS AIE  -  InsertArtyFireMission is evaluating data for " .. groupData.name .. ", fire parameters gathered"))
									end	
									
									Group.getByName(groupData.name):getController():pushTask(fire)					

									local firetime = mist.time.getDHMS(timer.getAbsTime() + 180)
									local artyLLx, artyLLy = coord.LOtoLL(artyPos)
									local artyMGRS  = coord.LLtoMGRS(artyLLx, artyLLy)
									
									local artyString = tostring(artyMGRS.MGRSDigraph .. " " .. string.sub(artyMGRS.Northing, 1,2) .. " " .. string.sub(artyMGRS.Easting, 1,2)) --mist.tostringMGRS(artyMGRS, 3)
									
									
									local tLLx, tLLy = coord.LOtoLL(tPos)
									local tMGRS  = coord.LLtoMGRS(tLLx, tLLy)
									
									local tString = tostring(tMGRS.MGRSDigraph .. " " .. string.sub(tMGRS.Northing, 1,2) .. " " .. string.sub(tMGRS.Easting, 1,2)) --mist.tostringMGRS(tMGRS, 3)									
									
									if debugProcess == true then
										env.info(("DAWS AIE  -  InsertArtyFireMission is evaluating data for " .. groupData.name .. ", text file elements ready"))
									end									
									
									local text 	= "To all flight, artillery fire starting at time "
												.. string.format("%02d", firetime.h) .. ":" .. string.format("%02d", firetime.m) .. ", from "
												.. tostring(artyString) .. " to "
												.. tostring(tString)
									
									if debugProcess == true then
										env.info(("DAWS AIE  -  InsertArtyFireMission is evaluating data for " .. groupData.name .. ", fire message: " .. text))
									end										
									
									if artyCoa == "blue" then 
										trigger.action.outTextForCoalition(coalition.side.BLUE, text, 30)
										if debugProcess == true then
											env.info(("DAWS AIE  -  InsertArtyFireMission has planned a mission for coa BLUE, group: " .. groupData.name))
										end										
									else
										if debugProcess == true then
											env.info(("DAWS AIE  -  InsertArtyFireMission has planned a mission for coa RED, group: " .. groupData.name))
										end										
										trigger.action.outTextForCoalition(coalition.side.RED, text, 30)
									end
									
									if debugProcess == true then
										env.info(("DAWS AIE  -  InsertArtyFireMission is evaluating data for " .. groupData.name .. ", fire message online "))
									end										
									
									
								end
							end
						elseif tid >= currentTargetsArrayPoint+10 then					
							break
						end	
					end
								
					if repeatcycle == false then
						InsertArtyFireMission_statenum = InsertArtyFireMission_statenum + 1
					end
				end
			end
		else
			if debugProcess == true then
				env.info(("DAWS AIE  -  InsertArtyFireMission: no targets available"))
			end		
		end

		if numfound == false then
			InsertArtyFireMission_statenum = 1
			CurrentNumTargets = 1
			if debugProcess == true then
				env.info(("DAWS AIE  -  InsertArtyFireMission has ended its cycle"))
			end
			timer.scheduleFunction(ChangeArtyState, {}, timer.getTime()+ stateShift)		
		else
			CurrentNumTargets = CurrentNumTargets+10
			timer.scheduleFunction(InsertArtyFireMission, {}, timer.getTime()+ updateShift)
		end	
	end
	
	--[[ reset mission assignement state 
	ResetArtyFireMission = function()
		for id, groupData in pairs(tblArtyGroups) do
			groupData.hasmission = false
		end
		timer.scheduleFunction(ChangeArtyState, {}, timer.getTime()+ stateShift)
		if debugProcess == true then
			env.info(("DAWS AIE  -  ResetArtyFireMission has ended its cycle"))
		end		
	end
	--]]--
	
	-- GSC
	ChangeArtyState = function()
		if GlobalState == "A" then -- start looping state filter...
			if StatedebugProcess == true then
				env.info(("DAWS AIE  -  globalStateChanger is in state " .. GlobalState))
			end		
			GlobalState = "B"
			if StatedebugProcess == true then
				env.info(("DAWS AIE  -  globalStateChanger change state to " .. GlobalState))
			end
			--timer.scheduleFunction(ExecuteArtyPeriodicCycle, {}, timer.getTime() + 1)
			timer.scheduleFunction(ExecuteArtyPeriodicCycle, {}, timer.getTime() + stateShift)
			if StatedebugProcess == true then
				env.info(("DAWS AIE  -  globalStateChanger called the schedule"))
			end
			return
		elseif GlobalState == "B" then
			if StatedebugProcess == true then
				env.info(("DAWS AIE  -  globalStateChanger is in state " .. GlobalState))
			end				
			GlobalState = "C"				
			if StatedebugProcess == true then
				env.info(("DAWS AIE  -  globalStateChanger change state to " .. GlobalState))
			end
			timer.scheduleFunction(ExecuteArtyPeriodicCycle, {}, timer.getTime() + stateShift)
			if StatedebugProcess == true then
				env.info(("DAWS AIE  -  globalStateChanger called the schedule"))
			end
			return			
		elseif GlobalState == "C" then
			if StatedebugProcess == true then
				env.info(("DAWS AIE  -  globalStateChanger is in state " .. GlobalState))
			end				
			GlobalState = "A"
			if StatedebugProcess == true then
				env.info(("DAWS AIE  -  globalStateChanger change state to " .. GlobalState))
			end
			timer.scheduleFunction(ExecuteArtyPeriodicCycle, {}, timer.getTime() + stateShift)
			if StatedebugProcess == true then
				env.info(("DAWS AIE  -  globalStateChanger called the schedule"))
			end
			if debugProcess == true then
				env.info(("DAWS AIE  -  globalStateChanger loop complete at time " .. timer.getAbsTime()))
			end			
			return
		else
			if StatedebugProcess == true then
				env.info(("DAWS AIE  -  globalStateChanger can't find reference"))
			end		
			return
		end
	end
	--]]--	
		
	-- EPC
	ExecuteArtyPeriodicCycle = function() 
		
		if StatedebugProcess == true then
			env.info(("DAWS AIE  -  ExecuteArtyPeriodicCycle check init, looking for state " .. GlobalState))
		end		
		
		if GlobalState ~= PastGlobalState then

			if GlobalState == "A" then -- start looping state filter...
				if StatedebugProcess == true then
					env.info(("DAWS AIE  -  ExecuteArtyPeriodicCycle is inside state A"))
				end
				PastGlobalState = "A"
				if tblArtyCount > 0 then
					if StatedebugProcess == true then
						env.info(("DAWS AIE  -  ExecuteArtyPeriodicCycle launched UpdateArtyIntel() cycle at time " .. timer.getAbsTime()))
					end				
					UpdateArtyIntel()
				else
					timer.scheduleFunction(ChangeArtyState, {}, timer.getTime() + stateShift)
				end
				return
			elseif GlobalState == "B" then
				if StatedebugProcess == true then
					env.info(("DAWS AIE  -  ExecuteArtyPeriodicCycle is inside state B"))
				end					
				PastGlobalState = "B"
				if tblArtyCount > 0 then
					if StatedebugProcess == true then
						env.info(("DAWS AIE  -  ExecuteArtyPeriodicCycle launched InsertArtyFireMission() cycle at time " .. timer.getAbsTime()))
					end					
					InsertArtyFireMission()
				else
					timer.scheduleFunction(ChangeArtyState, {}, timer.getTime() + cycleShift)
				end
				return
			elseif GlobalState == "C" then
				if StatedebugProcess == true then
					env.info(("DAWS AIE  -  ExecuteArtyPeriodicCycle is inside state C"))
				end				
				tblKnownEnemy = {} -- reset known target
				PastGlobalState = "C"
				if tblArtyCount > 0 then
					if StatedebugProcess == true then
						env.info(("DAWS AIE  -  ExecuteArtyPeriodicCycle launched ResetArtyFireMission() cycle at time " .. timer.getAbsTime()))
					end					
					createArtyTable()
					timer.scheduleFunction(createArtyTable, {}, timer.getTime() + 5)
				else
					timer.scheduleFunction(ChangeArtyState, {}, timer.getTime() + stateShift)
				end
				return
			else
				if StatedebugProcess == true then
					env.info(("DAWS AIE  -  ExecuteArtyPeriodicCycle can't find reference"))
				end				
				return
			end
		else
			if StatedebugProcess == true then
				env.info(("DAWS AIE  -  ExecuteArtyPeriodicCycle blocked due to no pastglobalstate change"))
			end			
		end

	end
	--]]--
	
	--Initialization
	timer.scheduleFunction(createArtyTable, {}, timer.getTime() + 5)
	timer.scheduleFunction(ExecuteArtyPeriodicCycle, {}, timer.getTime() + 10)	
	


	env.info(("DAWS AI Enhancement version - Automatic artillery is initiated"))
	-- ~=
	
