label="Yawner vs Odol (11.04.2009)"
version="1.6"
completion="victory"
campaign_type="multiplayer"
difficulty="NORMAL"
random_seed="9913"
random_calls="0"
next_underlying_unit_id="33"
end_text_duration="0"
[variables]
[/variables]
[replay]
	[command]
		[start]
		[/start]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="JJL has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		undo="no"
		[speak]
			id="Yawner"
			message="milej zabawy i powodzenia :)"
			side="1"
		[/speak]
	[/command]
	[command]
		undo="no"
		[speak]
			id="Odol"
			message="Nawzajem"
			side="2"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Kaspar has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[recruit]
			value="4"
			x="18"
			y="28"
		[/recruit]
		[random]
			value="20023"
		[/random]
		[random]
			value="27779"
		[/random]
		[random]
			value="2195"
		[/random]
		[random]
			value="10100"
		[/random]
		[random]
			value="10706"
		[/random]
		[random]
			value="7465"
		[/random]
		[random]
			value="19838"
		[/random]
		[random]
			value="28775"
		[/random]
		[random]
			value="13091"
		[/random]
		[random]
			value="21240"
		[/random]
		[random]
			value="15375"
		[/random]
		[random]
			value="25847"
		[/random]
		[random]
			value="17387"
		[/random]
		[random]
			value="18295"
		[/random]
		[random]
			value="4934"
			[results]
				checksum="uyqOVzDO<ExdHrVAAKrGB6qDQPwqLuEDUSNIMADRBGxxpOFSryqC1rOBpDQNRqrWuTuTxCUFMDPxfDLuyOdqNHp2JuaZJrXGikJwc0bkdie+c.P93obZj,mcoh3b,IXl"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[recruit]
			value="4"
			x="20"
			y="28"
		[/recruit]
		[random]
			value="25190"
		[/random]
		[random]
			value="10304"
		[/random]
		[random]
			value="31971"
		[/random]
		[random]
			value="8915"
		[/random]
		[random]
			value="16940"
		[/random]
		[random]
			value="31381"
		[/random]
		[random]
			value="28721"
		[/random]
		[random]
			value="19526"
		[/random]
		[random]
			value="29947"
		[/random]
		[random]
			value="10480"
		[/random]
		[random]
			value="5128"
		[/random]
		[random]
			value="19014"
		[/random]
		[random]
			value="23465"
		[/random]
		[random]
			value="31518"
		[/random]
		[random]
			value="4626"
			[results]
				checksum="FTxBwyUzhyBkwVHKQOq5AMPytSNtRJzMRsDuHBtnQvBFyQAVsL8qJTmQQNRqrWuTuTxCUFIDPxfDLuyOdqNHp2JuaZMrXGikJwc0bkdie+c.P93obZj,mcol3b,IXl32"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Nero has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="19,20,21,22,23"
			y="28,28,28,27,27"
		[/move]
	[/command]
	[command]
		sent="yes"
		[recruit]
			value="7"
			x="23"
			y="28"
		[/recruit]
		[random]
			value="9118"
		[/random]
		[random]
			value="31942"
		[/random]
		[random]
			value="29046"
		[/random]
		[random]
			value="32416"
		[/random]
		[random]
			value="4707"
		[/random]
		[random]
			value="28296"
		[/random]
		[random]
			value="30781"
		[/random]
		[random]
			value="4961"
		[/random]
		[random]
			value="8480"
		[/random]
		[random]
			value="654"
		[/random]
		[random]
			value="1459"
		[/random]
		[random]
			value="28584"
		[/random]
		[random]
			value="23182"
		[/random]
		[random]
			value="22206"
		[/random]
		[random]
			value="17908"
			[results]
				checksum="86Wmq3.,tb9Th9Xh+8Om3eb898egWbi26k39>2dlaZge0f-9iPif8c7h8k-+v7e7e8fh1b<i8Sem73jI-oaGeRO,h0ybO20xxhh6<5-i30KE4<Yfd6-cbeMq5.ql>pFA"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[recruit]
			value="6"
			x="24"
			y="28"
		[/recruit]
		[random]
			value="28616"
		[/random]
		[random]
			value="20879"
		[/random]
		[random]
			value="6345"
		[/random]
		[random]
			value="8994"
		[/random]
		[random]
			value="13042"
		[/random]
		[random]
			value="18976"
		[/random]
		[random]
			value="30503"
		[/random]
		[random]
			value="1288"
		[/random]
		[random]
			value="5748"
		[/random]
		[random]
			value="820"
		[/random]
		[random]
			value="9049"
		[/random]
		[random]
			value="29547"
		[/random]
		[random]
			value="1699"
		[/random]
		[random]
			value="17375"
		[/random]
		[random]
			value="25584"
			[results]
				checksum="GIsTMzMz9ES2DQOJBEKJhELDntFKRtrHUBCMyPNLLqFJRxvqM3FDTGMqHwEVMDODuIOJsNEBPcOusOKDwebPsxOruODoP.K+zDJqnpswJI0PpQ,UvAQ3huxn.mf5Lj19"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="wads has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="23,22,21"
			y="27,27,28"
		[/move]
	[/command]
	[command]
		sent="yes"
		[countdown_update]
			team="1"
			value="219000"
		[/countdown_update]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Sanzaemon has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[recruit]
			value="5"
			x="20"
			y="4"
		[/recruit]
		[random]
			value="22881"
		[/random]
		[random]
			value="30928"
		[/random]
		[random]
			value="29358"
		[/random]
		[random]
			value="29443"
		[/random]
		[random]
			value="1253"
		[/random]
		[random]
			value="16524"
		[/random]
		[random]
			value="31719"
		[/random]
		[random]
			value="30806"
		[/random]
		[random]
			value="19254"
		[/random]
		[random]
			value="16128"
		[/random]
		[random]
			value="3986"
		[/random]
		[random]
			value="1659"
		[/random]
		[random]
			value="25235"
		[/random]
		[random]
			value="23491"
		[/random]
		[random]
			value="6144"
			[results]
				checksum="wmNPCQ,<jCB,xNaeN9c8kBjp>f.33i3,bi2g6odf4d42johapi+j5>4.,j0+4d89dk>9,2l9F.fc-I>-,WJ2j2m>8oQ0birbp4<4OkUyc1iTJvFiKQ-515ck5WIh5Kjg"
			[/results]
		[/random]
	[/command]
	[command]
		[recruit]
			value="0"
			x="20"
			y="3"
		[/recruit]
		[random]
			value="19684"
		[/random]
		[random]
			value="3993"
		[/random]
		[random]
			value="17500"
		[/random]
		[random]
			value="32225"
		[/random]
		[random]
			value="7834"
		[/random]
		[random]
			value="5767"
		[/random]
		[random]
			value="6821"
		[/random]
		[random]
			value="7178"
		[/random]
		[random]
			value="14926"
		[/random]
		[random]
			value="21785"
		[/random]
		[random]
			value="19743"
		[/random]
		[random]
			value="20554"
		[/random]
		[random]
			value="30658"
		[/random]
		[random]
			value="22111"
		[/random]
		[random]
			value="17325"
			[results]
				checksum="xNa6Bryn.D--c-i+05ERoaOL-EyQovClJF7qE383X-fb-Zy1ji46+2f+9l+5<foc<nn6f23854.p5418om4H8bFWB0pjc+cZng<m8e6X68+vn>t55bKrqZdmOCaJmIaF"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="conormccorry has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[recruit]
			value="3"
			x="19"
			y="4"
		[/recruit]
		[random]
			value="7059"
		[/random]
		[random]
			value="31006"
		[/random]
		[random]
			value="28950"
		[/random]
		[random]
			value="32216"
		[/random]
		[random]
			value="17984"
		[/random]
		[random]
			value="31471"
		[/random]
		[random]
			value="25949"
		[/random]
		[random]
			value="13841"
		[/random]
		[random]
			value="22445"
		[/random]
		[random]
			value="11424"
		[/random]
		[random]
			value="24995"
		[/random]
		[random]
			value="17269"
		[/random]
		[random]
			value="1565"
			[results]
				checksum="wIq0h4Aje6ZNhfnNl+7b,Ha4jCJxd>Z4D>emIBh6hCW2BmtJ8j1v.9xmODNURxriEsBIuurvENcQBQBPqyPrRxP5tBQME,Ezpfu49w6JQVkN94JBwVAIsdMAIZHHpExA"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="wag has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Halfsofar has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="18,17"
			y="3,3"
		[/move]
	[/command]
	[command]
		[countdown_update]
			team="2"
			value="217000"
		[/countdown_update]
	[/command]
	[command]
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="The_Black_Sword has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="MACE has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[move]
			x="21,22,23,24,24,24,24"
			y="28,27,27,26,25,24,23"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Victor has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="24,24,24,24,24,25"
			y="28,27,26,25,24,24"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="23,24,25,26,26,26,27"
			y="28,27,27,26,25,24,24"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="DeadEye has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="20,19,19,19,18"
			y="28,28,27,26,25"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="18,18,17,16,16,15,15,14"
			y="28,27,27,26,25,25,24,23"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Siderathan has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Wolfazz has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="lolman has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="piepork has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[recruit]
			value="2"
			x="22"
			y="23"
		[/recruit]
		[random]
			value="18989"
		[/random]
		[random]
			value="22265"
		[/random]
		[random]
			value="20359"
		[/random]
		[random]
			value="23416"
		[/random]
		[random]
			value="8071"
		[/random]
		[random]
			value="424"
		[/random]
		[random]
			value="24202"
		[/random]
		[random]
			value="21376"
		[/random]
		[random]
			value="20857"
		[/random]
		[random]
			value="492"
		[/random]
		[random]
			value="28332"
		[/random]
		[random]
			value="30358"
		[/random]
		[random]
			value="23305"
		[/random]
		[random]
			value="17674"
		[/random]
		[random]
			value="23850"
			[results]
				checksum="<0CL,>MA07qnKSwEonI1LxtPCvyvIJCEpbxFsqwtpJJCxrnKSQUuOzuQTzBNpzqtPasFJDFNwNCmGSzKQuCQKCMwz5BGNz0sHXttHryoCqiuuzfBrmxtBFTypdZF<gID"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Grossdeutchland has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[recruit]
			value="1"
			x="23"
			y="24"
		[/recruit]
		[random]
			value="29556"
		[/random]
		[random]
			value="7212"
		[/random]
		[random]
			value="27755"
		[/random]
		[random]
			value="28839"
		[/random]
		[random]
			value="18549"
		[/random]
		[random]
			value="2359"
		[/random]
		[random]
			value="19808"
		[/random]
		[random]
			value="4295"
		[/random]
		[random]
			value="27995"
		[/random]
		[random]
			value="8184"
		[/random]
		[random]
			value="14597"
		[/random]
		[random]
			value="32100"
		[/random]
		[random]
			value="23329"
		[/random]
		[random]
			value="29966"
		[/random]
		[random]
			value="13002"
			[results]
				checksum="MppsyKA8tq1G+rohkH2DZ9>b7j1h.rkiw1-Fek9X9FajMic5Q3Y959Xncn>g+J0<5+3mY8je7a461,hkEw7d1pgHD0ytJwg>n6zuefoWmmRC,xvlCaM1htCesyhkpNss"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[countdown_update]
			team="1"
			value="240000"
		[/countdown_update]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="VingadorBRA has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="19,19,18"
			y="4,5,5"
		[/move]
	[/command]
	[command]
		[move]
			x="20,21,22,22,22,22"
			y="3,4,4,5,6,7"
		[/move]
	[/command]
	[command]
		[move]
			x="20,20,20,20,20,19,19,18"
			y="4,5,6,7,8,9,10,10"
		[/move]
	[/command]
	[command]
		[move]
			x="17,18"
			y="3,3"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="salman has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[recruit]
			value="0"
			x="20"
			y="4"
		[/recruit]
		[random]
			value="18256"
		[/random]
		[random]
			value="21199"
		[/random]
		[random]
			value="9217"
		[/random]
		[random]
			value="24844"
		[/random]
		[random]
			value="13555"
		[/random]
		[random]
			value="341"
		[/random]
		[random]
			value="18525"
		[/random]
		[random]
			value="8557"
		[/random]
		[random]
			value="13235"
		[/random]
		[random]
			value="27827"
		[/random]
		[random]
			value="22953"
		[/random]
		[random]
			value="21652"
		[/random]
		[random]
			value="16735"
		[/random]
		[random]
			value="14730"
		[/random]
		[random]
			value="20438"
			[results]
				checksum="xNa6Bryn.D--c-i+04IRoaOL-EyQnvClJF7qE383X-fb-Zy1ji46+2f+9l+5<foc<nn6f23854.o1418om4H8bFWB0pjc+cZng<m8e6X68+vn>t55bKrqZdmOCaJmIaF"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Piolun has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="18,17,16,15,14"
			y="3,3,3,4,4"
		[/move]
	[/command]
	[command]
		[recruit]
			value="1"
			x="13"
			y="4"
		[/recruit]
		[random]
			value="24864"
		[/random]
		[random]
			value="33"
		[/random]
		[random]
			value="28657"
		[/random]
		[random]
			value="29947"
		[/random]
		[random]
			value="30622"
		[/random]
		[random]
			value="19680"
		[/random]
		[random]
			value="15945"
		[/random]
		[random]
			value="15469"
		[/random]
		[random]
			value="6423"
		[/random]
		[random]
			value="21318"
		[/random]
		[random]
			value="29670"
		[/random]
		[random]
			value="9587"
		[/random]
		[random]
			value="5042"
			[results]
				checksum="Dem>c1k,fFB3IPKDDy,IIVsrrz9qrFsKPmsAOVOPtQsRHOMGLquuPuNAtBx6AEqpsGOKxE8KFoBPRQNzSIM0NsInAEUrD<pd7wU07l,LsmkMRAyTOtHFLqpFUIIzsxsc"
			[/results]
		[/random]
	[/command]
	[command]
		[recruit]
			value="3"
			x="15"
			y="4"
		[/recruit]
		[random]
			value="17017"
		[/random]
		[random]
			value="8726"
		[/random]
		[random]
			value="21014"
		[/random]
		[random]
			value="10367"
		[/random]
		[random]
			value="14650"
		[/random]
		[random]
			value="13713"
		[/random]
		[random]
			value="13732"
		[/random]
		[random]
			value="5142"
		[/random]
		[random]
			value="25325"
		[/random]
		[random]
			value="25939"
		[/random]
		[random]
			value="18705"
		[/random]
		[random]
			value="30196"
		[/random]
		[random]
			value="23591"
			[results]
				checksum="wIq0h4Aje6ZNhfnNl+7b,Ha4jCJxd>Z4D>emIBh6hCW2BmtJ8j1v.9xmODNURxriEsBIuurvENcQBQBPqyPrRxP5tBQME,Ezpfu49w6JQVkN94JBwVAIsdMAIZHHpExA"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="RetardsOnViagra has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="macke has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[countdown_update]
			team="2"
			value="240000"
		[/countdown_update]
	[/command]
	[command]
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="mareike has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="27,26,26,26,26,26,25"
			y="24,23,22,21,20,19,19"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="22,22,22,22,23"
			y="23,22,21,20,20"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="23,23,23,23,23,23"
			y="24,23,22,21,20,19"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="25,25,26,26,26,26"
			y="24,23,22,21,20,19"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="14,13,12,11,11,11"
			y="23,24,23,23,22,21"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="18,18,18,18,18,18"
			y="25,24,23,22,21,20"
		[/move]
	[/command]
	[command]
		sent="yes"
		[recruit]
			value="2"
			x="22"
			y="23"
		[/recruit]
		[random]
			value="2677"
		[/random]
		[random]
			value="14969"
		[/random]
		[random]
			value="20150"
		[/random]
		[random]
			value="23760"
		[/random]
		[random]
			value="27390"
		[/random]
		[random]
			value="3122"
		[/random]
		[random]
			value="9677"
		[/random]
		[random]
			value="4"
		[/random]
		[random]
			value="24632"
		[/random]
		[random]
			value="1861"
		[/random]
		[random]
			value="16015"
		[/random]
		[random]
			value="18700"
		[/random]
		[random]
			value="14196"
		[/random]
		[random]
			value="9679"
		[/random]
		[random]
			value="17527"
			[results]
				checksum="<0CL>,MA07qnKSwEonI1LxtPCvyvIJCEpbxFsqwtpJJCxrnKSQUuOzuQTzBNpzqtPasFJDFNwNCmGSzKQuCLJCMwz5BGNz0sHXttHryoCqiuuzfBrmxtBFNypdZF<gID"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="reblaus has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[countdown_update]
			team="1"
			value="240000"
		[/countdown_update]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		[move]
			x="13,12,12,11,11,10"
			y="4,4,5,6,7,7"
		[/move]
	[/command]
	[command]
		[move]
			x="18,17,16,15,14,13,12"
			y="10,11,11,12,11,12,11"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="shadowczech has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="22,21,21,21,22,23"
			y="7,8,9,10,10,11"
		[/move]
	[/command]
	[command]
		[move]
			x="20,21,22,22,22,23"
			y="4,5,5,6,7,8"
		[/move]
	[/command]
	[command]
		[move]
			x="18,18,18,18,18,18"
			y="5,6,7,8,9,10"
		[/move]
	[/command]
	[command]
		[move]
			x="15,14,13,13,13,13"
			y="4,4,5,6,7,8"
		[/move]
	[/command]
	[command]
		[move]
			x="14,13,13,13,14"
			y="4,5,6,7,7"
		[/move]
	[/command]
	[command]
		[move]
			x="14,15"
			y="7,8"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="RazielDavid has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="--Silver-- has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Drydd has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Quetzalcoatl has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="maximus123 has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[countdown_update]
			team="2"
			value="240000"
		[/countdown_update]
	[/command]
	[command]
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[move]
			x="23,23,23"
			y="19,18,17"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="23,23,23"
			y="20,19,18"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="25,25,25"
			y="19,18,17"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="26,25,24"
			y="19,19,18"
		[/move]
	[/command]
	[command]
		sent="yes"
		[recruit]
			value="0"
			x="23"
			y="24"
		[/recruit]
		[random]
			value="24480"
		[/random]
		[random]
			value="28857"
		[/random]
		[random]
			value="6087"
		[/random]
		[random]
			value="22269"
		[/random]
		[random]
			value="29158"
		[/random]
		[random]
			value="30332"
		[/random]
		[random]
			value="3067"
		[/random]
		[random]
			value="14375"
		[/random]
		[random]
			value="10843"
		[/random]
		[random]
			value="31106"
		[/random]
		[random]
			value="15606"
		[/random]
		[random]
			value="14675"
		[/random]
		[random]
			value="9153"
		[/random]
		[random]
			value="27353"
		[/random]
		[random]
			value="21402"
			[results]
				checksum="F.muxQ8q-vqhspPuqvoeBIvxzyqxRKaVOEMsRHPLsxrnKSQUuPzuQTzBNpzqtPasFJDFNwNCmGSzKQuCLHCMwz5BGNz0sHXttHryoCqiuuzfBrmxtBFSypdZF<grEJR6"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[move]
			x="22,22,22,22,22"
			y="23,22,21,20,19"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="24,23,22,21,20,19,18"
			y="23,24,23,23,22,22,21"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="18,17,16,15"
			y="20,20,20,20"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="15,14"
			y="20,19"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="14,13"
			y="19,19"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="11,10,9,8,7,6"
			y="21,21,21,20,20,19"
		[/move]
	[/command]
	[command]
		sent="yes"
		[countdown_update]
			team="1"
			value="240000"
		[/countdown_update]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="peanutwalrus has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="23,24,25,26"
			y="8,8,8,8"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Ruschy has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="12,11,10"
			y="11,12,12"
		[/move]
	[/command]
	[command]
		[move]
			x="10,10,9"
			y="12,13,14"
		[/move]
	[/command]
	[command]
		[move]
			x="9,9,10"
			y="14,13,12"
		[/move]
	[/command]
	[command]
		[move]
			x="10,10,10,11,11,12"
			y="7,8,9,10,11,11"
		[/move]
	[/command]
	[command]
		[move]
			x="23,23"
			y="11,12"
		[/move]
	[/command]
	[command]
		[move]
			x="23,23"
			y="12,13"
		[/move]
	[/command]
	[command]
		[move]
			x="23,23,23"
			y="13,12,11"
		[/move]
	[/command]
	[command]
		[move]
			x="18,18,18,18"
			y="10,11,12,13"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="addk1k has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="13,12,12,11,11,10"
			y="8,8,9,10,11,11"
		[/move]
	[/command]
	[command]
		[move]
			x="15,14,13"
			y="8,7,8"
		[/move]
	[/command]
	[command]
		[recruit]
			value="2"
			x="15"
			y="8"
		[/recruit]
		[random]
			value="12322"
		[/random]
		[random]
			value="5012"
		[/random]
		[random]
			value="17227"
		[/random]
		[random]
			value="9328"
		[/random]
		[random]
			value="29909"
		[/random]
		[random]
			value="6684"
		[/random]
		[random]
			value="20760"
		[/random]
		[random]
			value="14621"
		[/random]
		[random]
			value="5581"
		[/random]
		[random]
			value="20081"
		[/random]
		[random]
			value="20888"
		[/random]
		[random]
			value="13662"
		[/random]
		[random]
			value="9489"
			[results]
				checksum="TuuzMJvu3JOmTCCoKGpBJPA6SCMFtLEzKIxOCmtqSOKJLCFwmIsr1QENmxPFHFw.RFKFnqypNLqM8mwoForIhF8xkkBsH9ih>N4ftxqADyQNdDsofqQwNFrCg8vPGzPi"
			[/results]
		[/random]
	[/command]
	[command]
		[recruit]
			value="0"
			x="14"
			y="7"
		[/recruit]
		[random]
			value="29048"
		[/random]
		[random]
			value="8975"
		[/random]
		[random]
			value="18723"
		[/random]
		[random]
			value="27081"
		[/random]
		[random]
			value="17636"
		[/random]
		[random]
			value="23395"
		[/random]
		[random]
			value="17320"
		[/random]
		[random]
			value="24062"
		[/random]
		[random]
			value="21047"
		[/random]
		[random]
			value="13775"
		[/random]
		[random]
			value="27757"
		[/random]
		[random]
			value="32205"
		[/random]
		[random]
			value="23986"
		[/random]
		[random]
			value="9958"
		[/random]
		[random]
			value="25042"
			[results]
				checksum="xNa6Bryn.D--c-i+04IRoaOL-EyQnvClJF7qE383X-fb-Zy1ji46+2f+9l+5<foc<nn6f23854.o1418om4H8bFWB0pjc+cZng<m8e6X68+vn>t55bKrqZdmOCaJmIaF"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="rycerz has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="shadowczech has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[countdown_update]
			team="2"
			value="207000"
		[/countdown_update]
	[/command]
	[command]
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="JJL has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[move]
			x="18,17,16,15,14,13,12"
			y="21,22,21,21,21,21,21"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Siderathan has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Mythological has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="ghandor has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Fartuess has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="bolek has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="atly has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="23,23,23,23,23"
			y="24,23,22,21,20"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="23,24,25,26,27"
			y="18,17,17,17,18"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="24,25,26,26"
			y="18,18,17,16"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="22,23,23,24"
			y="19,19,18,17"
		[/move]
	[/command]
	[command]
		sent="yes"
		[countdown_update]
			team="1"
			value="240000"
		[/countdown_update]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		[move]
			x="12,12,12,11"
			y="11,12,13,14"
		[/move]
	[/command]
	[command]
		[move]
			x="15,14,14,14,13,12"
			y="8,8,9,10,11,11"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="kaucuk has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="10,9,8,7,6,5,4"
			y="12,13,13,14,14,15,14"
		[/move]
	[/command]
	[command]
		[move]
			x="4,4,3"
			y="14,15,16"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Duke has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="teflontriad has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="10,11,11,11,11"
			y="11,12,13,14,15"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="stas has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="18,19"
			y="13,14"
		[/move]
	[/command]
	[command]
		[move]
			x="19,18"
			y="14,13"
		[/move]
	[/command]
	[command]
		[move]
			x="14,13,12,12,11,11,10"
			y="7,8,8,9,10,11,11"
		[/move]
	[/command]
	[command]
		[recruit]
			value="3"
			x="15"
			y="8"
		[/recruit]
		[random]
			value="29692"
		[/random]
		[random]
			value="1021"
		[/random]
		[random]
			value="3690"
		[/random]
		[random]
			value="32066"
		[/random]
		[random]
			value="3600"
		[/random]
		[random]
			value="27799"
		[/random]
		[random]
			value="25443"
		[/random]
		[random]
			value="14410"
		[/random]
		[random]
			value="31840"
		[/random]
		[random]
			value="23466"
		[/random]
		[random]
			value="8027"
		[/random]
		[random]
			value="17164"
		[/random]
		[random]
			value="4441"
			[results]
				checksum="wIq0h4Aje6ZNhfnNl+7b,Ha4jCJxd>Z4D>emIBh6hCW2BmtJ8j1v.9xmODNURxriEsBIuurvENcQBQBPqyPrRxP5tBQME,Ezpfu49w6JQVkN94JBwVAIsdMAIZHHpExA"
			[/results]
		[/random]
	[/command]
	[command]
		[move]
			x="13,14,15,16,17"
			y="8,8,9,9,10"
		[/move]
	[/command]
	[command]
		[countdown_update]
			team="2"
			value="168000"
		[/countdown_update]
	[/command]
	[command]
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[move]
			x="12,11,10,9"
			y="21,21,21,21"
		[/move]
	[/command]
	[command]
		sent="yes"
		[recruit]
			value="5"
			x="9"
			y="19"
		[/recruit]
		[random]
			value="738"
		[/random]
		[random]
			value="7351"
		[/random]
		[random]
			value="5179"
		[/random]
		[random]
			value="6930"
		[/random]
		[random]
			value="18710"
		[/random]
		[random]
			value="5986"
		[/random]
		[random]
			value="928"
		[/random]
		[random]
			value="22771"
		[/random]
		[random]
			value="27780"
		[/random]
		[random]
			value="4643"
		[/random]
		[random]
			value="28544"
		[/random]
		[random]
			value="24365"
		[/random]
		[random]
			value="24973"
		[/random]
		[random]
			value="27682"
		[/random]
		[random]
			value="17779"
			[results]
				checksum="8ax-d6b6xp8sjgga3aP72g3e+iBm.jefmffY-+6<ip3<5-4egW6m2lahna90i9fl5a1hh7oj8-<F->mkj.91>I6ygXo9WjoolcACZdd9b,<-lvi-OF>N69sv8joLJwPp"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="ping has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="13,14,15"
			y="19,19,20"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="6,6,5,4,3"
			y="19,18,18,17,17"
		[/move]
	[/command]
	[command]
		sent="yes"
		[attack]
			defender_weapon="-1"
			weapon="1"
			[source]
				x="3"
				y="17"
			[/source]
			[destination]
				x="3"
				y="16"
			[/destination]
		[/attack]
		[random]
			value="13402"
			[results]
				chance="40"
				damage="7"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="28494"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[move]
			x="9,8,7,6"
			y="21,20,20,19"
		[/move]
	[/command]
	[command]
		sent="yes"
		[countdown_update]
			team="1"
			value="240000"
		[/countdown_update]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="MACE has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Carty has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="3,3,3,4,5,5,6,6,7"
			y="16,15,14,13,13,12,11,10,10"
		[/move]
	[/command]
	[command]
		[move]
			x="10,11,11,10,10,10"
			y="11,12,13,13,14,15"
		[/move]
	[/command]
	[command]
		[move]
			x="11,10,9,8"
			y="15,15,16,16"
		[/move]
	[/command]
	[command]
		[move]
			x="12,11,11,10,9"
			y="11,12,13,13,14"
		[/move]
	[/command]
	[command]
		[move]
			x="11,11,11,11"
			y="14,15,16,17"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="aC-Thammy has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Frolic has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="tolstoi has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="15,16,17,18,18"
			y="8,8,9,9,10"
		[/move]
	[/command]
	[command]
		[move]
			x="26,25,24,24,24,24"
			y="8,8,8,9,10,11"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Gauteamus has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="17,16,15,14,13"
			y="10,9,9,8,8"
		[/move]
	[/command]
	[command]
		[recruit]
			value="2"
			x="15"
			y="8"
		[/recruit]
		[random]
			value="26427"
		[/random]
		[random]
			value="16228"
		[/random]
		[random]
			value="18825"
		[/random]
		[random]
			value="32171"
		[/random]
		[random]
			value="2627"
		[/random]
		[random]
			value="18288"
		[/random]
		[random]
			value="3390"
		[/random]
		[random]
			value="4421"
		[/random]
		[random]
			value="23690"
		[/random]
		[random]
			value="11678"
		[/random]
		[random]
			value="14057"
		[/random]
		[random]
			value="9703"
		[/random]
		[random]
			value="30462"
			[results]
				checksum="TuuzMJvu3JOmTCCoKGpBJPA6SCMFtLEzKIxOCmtqSOKJLCFwmIsr1QENmxPFHFw.RFKFnqypNLqM8mwoForIhF8xkkBsH9ih>N4ftxqADyQNdDsofqQwNFrCg8vPGzPi"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Herasos has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[countdown_update]
			team="2"
			value="92000"
		[/countdown_update]
	[/command]
	[command]
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[move]
			x="6,7,8,9"
			y="19,20,20,21"
		[/move]
	[/command]
	[command]
		sent="yes"
		[recruit]
			value="0"
			x="9"
			y="20"
		[/recruit]
		[random]
			value="20334"
		[/random]
		[random]
			value="28037"
		[/random]
		[random]
			value="28760"
		[/random]
		[random]
			value="17797"
		[/random]
		[random]
			value="3643"
		[/random]
		[random]
			value="30676"
		[/random]
		[random]
			value="23176"
		[/random]
		[random]
			value="21470"
		[/random]
		[random]
			value="17335"
		[/random]
		[random]
			value="24594"
		[/random]
		[random]
			value="2306"
		[/random]
		[random]
			value="3867"
		[/random]
		[random]
			value="18753"
		[/random]
		[random]
			value="2026"
		[/random]
		[random]
			value="19792"
			[results]
				checksum="F<iuxQ8q-vqhtpPuqvoeBIvxzyqxRKaVOEMsRHPLsxrnKSQUuPzuQTzBNpzqtPasFJDFNwNCmGSzKQuCQLCMwz5BGNz0sHXttHryoCqiuuzfBrmxtBFMypdZF<gxEJR6"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="ultraxxx has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Drydd has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="VingadorBRA has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="23,23,24,24,24"
			y="17,16,15,14,13"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="24,25"
			y="13,13"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="24,24,24,24,24"
			y="17,16,15,14,13"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="27,27,27,27,27"
			y="18,17,16,15,14"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="25,25,25,25"
			y="17,16,15,14"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Bahamut has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="26,26,26,26"
			y="16,15,14,13"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="23,24,25,25,25"
			y="20,19,19,18,17"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="sauron has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Age has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="3,4,5,6,6"
			y="17,17,18,18,19"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="15,14,13,12,11"
			y="20,20,21,21,21"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="9,8,7,6,5"
			y="19,18,18,18,18"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="5,4,3"
			y="18,18,18"
		[/move]
	[/command]
	[command]
		sent="yes"
		[countdown_update]
			team="1"
			value="157000"
		[/countdown_update]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Lelu has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="18,19,20,21,21"
			y="13,13,12,12,11"
		[/move]
	[/command]
	[command]
		[move]
			x="18,19,20"
			y="10,10,10"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="ultraxxx has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Xaoc has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="24,24,24"
			y="11,10,9"
		[/move]
	[/command]
	[command]
		[move]
			x="24,24,25,26"
			y="9,8,8,8"
		[/move]
	[/command]
	[command]
		[move]
			x="15,16,17,18,18,18"
			y="8,8,8,8,9,10"
		[/move]
	[/command]
	[command]
		[countdown_update]
			team="2"
			value="50000"
		[/countdown_update]
	[/command]
	[command]
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Sensei has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="3,3,3,3"
			y="18,17,16,15"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="3,3,3"
			y="15,14,13"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="3,3"
			y="13,12"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="LoL69 has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="bodak has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="9,9,9,8"
			y="20,19,18,17"
		[/move]
	[/command]
	[command]
		sent="yes"
		[attack]
			defender_weapon="0"
			weapon="1"
			[source]
				x="8"
				y="17"
			[/source]
			[destination]
				x="8"
				y="16"
			[/destination]
		[/attack]
		[random]
			value="7750"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="11500"
			[results]
				chance="40"
				damage="4"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="23052"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="2941"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="21420"
			[results]
				chance="40"
				damage="4"
				dies="no"
				hits="yes"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[move]
			x="6,6,6,7"
			y="19,18,17,17"
		[/move]
	[/command]
	[command]
		sent="yes"
		[attack]
			defender_weapon="-1"
			weapon="1"
			[source]
				x="7"
				y="17"
			[/source]
			[destination]
				x="8"
				y="16"
			[/destination]
		[/attack]
		[random]
			value="6741"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="23429"
			[results]
				chance="40"
				damage="5"
				dies="no"
				hits="yes"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[move]
			x="11,10,9,9,9,9"
			y="21,20,20,19,18,17"
		[/move]
	[/command]
	[command]
		sent="yes"
		[attack]
			defender_weapon="-1"
			weapon="1"
			[source]
				x="9"
				y="17"
			[/source]
			[destination]
				x="8"
				y="16"
			[/destination]
		[/attack]
		[random]
			value="6869"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="24450"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[recruit]
			value="0"
			x="9"
			y="19"
		[/recruit]
		[random]
			value="5609"
		[/random]
		[random]
			value="18650"
		[/random]
		[random]
			value="29159"
		[/random]
		[random]
			value="9875"
		[/random]
		[random]
			value="22725"
		[/random]
		[random]
			value="29316"
		[/random]
		[random]
			value="29046"
		[/random]
		[random]
			value="14466"
		[/random]
		[random]
			value="24167"
		[/random]
		[random]
			value="26505"
		[/random]
		[random]
			value="22495"
		[/random]
		[random]
			value="12058"
		[/random]
		[random]
			value="3686"
		[/random]
		[random]
			value="26745"
		[/random]
		[random]
			value="15749"
			[results]
				checksum="F<guxQ8q-vqhspPuqvoeBIvxzyqxRKaVOEMsRHPLsxrnKSQUuPzuQTzBNpzqtPasFJDFNwNCmGSzKQuCQRCMwz5BGNz0sHXttHryoCqiuuzfBrmxtBFSypdZF<gxEJR6"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[move]
			x="25,26,27"
			y="14,13,13"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="ultraxxx has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Skidzy has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Carty has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="27,28,28,28,28"
			y="14,13,12,11,10"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="27,27,27,28,28"
			y="13,12,11,10,9"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="iowaforever has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="aaa2 has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="BoS_Garol has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="26,27,27,28,28,29"
			y="13,13,12,11,10,10"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="24,25,26"
			y="13,13,12"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="25,25,25,25,24"
			y="17,16,15,14,13"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="26,27"
			y="12,13"
		[/move]
	[/command]
	[command]
		sent="yes"
		[countdown_update]
			team="1"
			value="123000"
		[/countdown_update]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Undertaker has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="26,27,28"
			y="8,8,8"
		[/move]
	[/command]
	[command]
		[attack]
			defender_weapon="-1"
			weapon="0"
			[source]
				x="28"
				y="8"
			[/source]
			[destination]
				x="28"
				y="9"
			[/destination]
		[/attack]
		[random]
			value="24265"
			[results]
				chance="70"
				damage="8"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="3405"
			[results]
				chance="70"
				damage="8"
				dies="no"
				hits="yes"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="aaa has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="23,24,24,24,25,26"
			y="11,10,9,8,8,8"
		[/move]
	[/command]
	[command]
		[move]
			x="20,21,22,23"
			y="10,11,11,11"
		[/move]
	[/command]
	[command]
		[move]
			x="18,19,20"
			y="10,10,10"
		[/move]
	[/command]
	[command]
		[move]
			x="9,9,10,10"
			y="14,15,15,16"
		[/move]
	[/command]
	[command]
		[attack]
			defender_weapon="0"
			weapon="0"
			[source]
				x="10"
				y="16"
			[/source]
			[destination]
				x="9"
				y="17"
			[/destination]
		[/attack]
		[random]
			value="16608"
			[results]
				chance="30"
				damage="5"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="22094"
			[results]
				chance="60"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="6424"
			[results]
				chance="30"
				damage="5"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="9221"
			[results]
				chance="60"
				damage="5"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="10315"
			[results]
				chance="30"
				damage="5"
				dies="no"
				hits="yes"
			[/results]
		[/random]
	[/command]
	[command]
		[move]
			x="10,9"
			y="15,16"
		[/move]
	[/command]
	[command]
		[attack]
			defender_weapon="1"
			weapon="0"
			[source]
				x="9"
				y="16"
			[/source]
			[destination]
				x="9"
				y="17"
			[/destination]
		[/attack]
		[random]
			value="5566"
			[results]
				chance="70"
				damage="8"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="23715"
			[results]
				chance="60"
				damage="4"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="18315"
			[results]
				chance="70"
				damage="8"
				dies="yes"
				hits="yes"
			[/results]
		[/random]
	[/command]
	[command]
		[move]
			x="11,10,9"
			y="17,17,17"
		[/move]
	[/command]
	[command]
		[attack]
			defender_weapon="-1"
			weapon="1"
			[source]
				x="9"
				y="17"
			[/source]
			[destination]
				x="8"
				y="17"
			[/destination]
		[/attack]
		[random]
			value="16884"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="20267"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="7993"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
	[/command]
	[command]
		[recruit]
			value="0"
			x="14"
			y="7"
		[/recruit]
		[random]
			value="18052"
		[/random]
		[random]
			value="3302"
		[/random]
		[random]
			value="19859"
		[/random]
		[random]
			value="8194"
		[/random]
		[random]
			value="15235"
		[/random]
		[random]
			value="8"
		[/random]
		[random]
			value="16141"
		[/random]
		[random]
			value="10030"
		[/random]
		[random]
			value="24178"
		[/random]
		[random]
			value="3108"
		[/random]
		[random]
			value="24898"
		[/random]
		[random]
			value="32057"
		[/random]
		[random]
			value="30094"
		[/random]
		[random]
			value="3407"
		[/random]
		[random]
			value="21371"
			[results]
				checksum="xNa6Bryn.D--c-i+05ERoaOL-EyQovClJF7qE383X-fb-Zy1ji46+2f+9l+5<foc<nn6f23854.p5418om4H8bFWB0pjc+cZng<m8e6X68+vn>t55bKrqZdmOCaJmIaF"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="flixil has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="manderin has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[recruit]
			value="0"
			x="15"
			y="8"
		[/recruit]
		[random]
			value="23345"
		[/random]
		[random]
			value="8755"
		[/random]
		[random]
			value="26889"
		[/random]
		[random]
			value="15205"
		[/random]
		[random]
			value="8299"
		[/random]
		[random]
			value="11002"
		[/random]
		[random]
			value="13468"
		[/random]
		[random]
			value="22836"
		[/random]
		[random]
			value="11938"
		[/random]
		[random]
			value="3496"
		[/random]
		[random]
			value="6101"
		[/random]
		[random]
			value="29690"
		[/random]
		[random]
			value="24120"
		[/random]
		[random]
			value="5995"
		[/random]
		[random]
			value="26689"
			[results]
				checksum="LhGI28qHcsJn9Niqer4mpRo6wD4zsHnKP1Hy+wP.,jg1d-5cL>71745hhbgk5n1,oc<nn6f23854.p5418om4H8bFWB0pjc+cZng<m8e6X68+vn>t55bKrqZdmOCaJmI"
			[/results]
		[/random]
	[/command]
	[command]
		[countdown_update]
			team="2"
			value="150000"
		[/countdown_update]
	[/command]
	[command]
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Bennemni has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[move]
			x="3,4,5,6,7,8,9"
			y="12,12,13,13,14,14,15"
		[/move]
	[/command]
	[command]
		sent="yes"
		[attack]
			defender_weapon="-1"
			weapon="0"
			[source]
				x="9"
				y="15"
			[/source]
			[destination]
				x="9"
				y="16"
			[/destination]
		[/attack]
		[random]
			value="9863"
			[results]
				chance="60"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="2131"
			[results]
				chance="60"
				damage="12"
				dies="no"
				hits="yes"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[attack]
			defender_weapon="0"
			weapon="1"
			[source]
				x="8"
				y="17"
			[/source]
			[destination]
				x="8"
				y="16"
			[/destination]
		[/attack]
		[random]
			value="1331"
			[results]
				chance="40"
				damage="11"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="18703"
			[results]
				chance="40"
				damage="4"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="8317"
			[results]
				chance="40"
				damage="11"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="18647"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="16416"
			[results]
				chance="40"
				damage="4"
				dies="no"
				hits="yes"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[attack]
			defender_weapon="-1"
			weapon="1"
			[source]
				x="7"
				y="17"
			[/source]
			[destination]
				x="8"
				y="16"
			[/destination]
		[/attack]
		[random]
			value="32102"
			[results]
				chance="40"
				damage="5"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="1281"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[recruit]
			value="0"
			x="8"
			y="19"
		[/recruit]
		[random]
			value="6890"
		[/random]
		[random]
			value="7797"
		[/random]
		[random]
			value="9777"
		[/random]
		[random]
			value="403"
		[/random]
		[random]
			value="23200"
		[/random]
		[random]
			value="1292"
		[/random]
		[random]
			value="16252"
		[/random]
		[random]
			value="5055"
		[/random]
		[random]
			value="14894"
		[/random]
		[random]
			value="4970"
		[/random]
		[random]
			value="16269"
		[/random]
		[random]
			value="31570"
		[/random]
		[random]
			value="4202"
		[/random]
		[random]
			value="7450"
		[/random]
		[random]
			value="25487"
			[results]
				checksum="F.ouxQ8q-vqhspPuqvoeBIvxzyqxRKaVOEMsRHPLsxrnKSQUuPzuQTzBNpzqtPasFJDFNwNCmGSzKQuCLJCMwz5BGNz0sHXttHryoCqiuuzfBrmxtBFMypdZF<gxEJR6"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="eureka has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Chaos has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="123dave123 has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="9,10,11,11"
			y="19,18,18,17"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="28,28,28,27,27,27,27,26"
			y="9,10,11,12,13,14,15,15"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Dertadios has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Osvaldao has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="jugador has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Therian has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="28,28,28,28,27"
			y="10,11,12,13,14"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="29,29,29,30,30,30"
			y="10,11,12,12,13,14"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="lolman has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="27,27,28"
			y="13,14,14"
		[/move]
	[/command]
	[command]
		sent="yes"
		[countdown_update]
			team="1"
			value="109000"
		[/countdown_update]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		[move]
			x="14,13,13,12,12,12"
			y="7,8,9,9,10,11"
		[/move]
	[/command]
	[command]
		[move]
			x="15,14,14,13"
			y="8,8,9,10"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Helms has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="9,10"
			y="16,15"
		[/move]
	[/command]
	[command]
		[attack]
			defender_weapon="-1"
			weapon="0"
			[source]
				x="10"
				y="15"
			[/source]
			[destination]
				x="9"
				y="15"
			[/destination]
		[/attack]
		[random]
			value="256"
			[results]
				chance="70"
				damage="8"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="3253"
			[results]
				chance="70"
				damage="8"
				dies="no"
				hits="yes"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Xaoc has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="jason has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Tyrion has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="9,9"
			y="17,16"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Gamebreakerr has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="10,9"
			y="16,17"
		[/move]
	[/command]
	[command]
		[attack]
			defender_weapon="0"
			weapon="0"
			[source]
				x="9"
				y="17"
			[/source]
			[destination]
				x="8"
				y="17"
			[/destination]
		[/attack]
		[random]
			value="10103"
			[results]
				chance="40"
				damage="3"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="18520"
			[results]
				chance="40"
				damage="7"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="4463"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="19377"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="5531"
			[results]
				chance="40"
				damage="3"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="21789"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
	[/command]
	[command]
		[attack]
			defender_weapon="-1"
			weapon="1"
			[source]
				x="9"
				y="16"
			[/source]
			[destination]
				x="9"
				y="15"
			[/destination]
		[/attack]
		[random]
			value="524"
			[results]
				chance="50"
				damage="2"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="17521"
			[results]
				chance="50"
				damage="2"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="8776"
			[results]
				chance="50"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
	[/command]
	[command]
		[move]
			x="8,8"
			y="16,15"
		[/move]
	[/command]
	[command]
		[attack]
			defender_weapon="0"
			weapon="0"
			[source]
				x="8"
				y="15"
			[/source]
			[destination]
				x="9"
				y="15"
			[/destination]
		[/attack]
		[random]
			value="24948"
			[results]
				chance="50"
				damage="5"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="7744"
			[results]
				chance="60"
				damage="7"
				dies="yes"
				hits="yes"
			[/results]
		[/random]
	[/command]
	[command]
		[move]
			x="7,7,7,8,8,9"
			y="10,11,12,12,13,14"
		[/move]
	[/command]
	[command]
		[attack]
			defender_weapon="0"
			weapon="0"
			[source]
				x="9"
				y="14"
			[/source]
			[destination]
				x="9"
				y="15"
			[/destination]
		[/attack]
		[random]
			value="19142"
			[results]
				chance="50"
				damage="4"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="9445"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="6382"
			[results]
				chance="50"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="23500"
			[results]
				chance="40"
				damage="12"
				dies="no"
				hits="yes"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Devl1 has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[recruit]
			value="0"
			x="15"
			y="8"
		[/recruit]
		[random]
			value="16100"
		[/random]
		[random]
			value="19950"
		[/random]
		[random]
			value="13308"
		[/random]
		[random]
			value="30786"
		[/random]
		[random]
			value="30804"
		[/random]
		[random]
			value="16607"
		[/random]
		[random]
			value="16045"
		[/random]
		[random]
			value="27113"
		[/random]
		[random]
			value="14706"
		[/random]
		[random]
			value="22924"
		[/random]
		[random]
			value="1483"
		[/random]
		[random]
			value="29016"
		[/random]
		[random]
			value="23557"
		[/random]
		[random]
			value="22902"
		[/random]
		[random]
			value="6248"
			[results]
				checksum="xNa6Bryn.D--c-i+04IRoaOL-EyQnvClJF7qE383X-fb-Zy1ji46+2f+9l+5<foc<nn6f23854.o1418om4H8bFWB0pjc+cZng<m8e6X68+vn>t55bKrqZdmOCaJmIaF"
			[/results]
		[/random]
	[/command]
	[command]
		[move]
			x="26,27,28,28"
			y="8,8,8,9"
		[/move]
	[/command]
	[command]
		[move]
			x="23,24,25"
			y="11,10,11"
		[/move]
	[/command]
	[command]
		[move]
			x="25,26,27,28"
			y="11,11,11,10"
		[/move]
	[/command]
	[command]
		[move]
			x="20,21,22,23"
			y="10,11,11,11"
		[/move]
	[/command]
	[command]
		[move]
			x="21,22,23,23"
			y="11,10,10,9"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Lokii has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="28,28,29"
			y="8,9,10"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="skateu has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Xnodox has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[countdown_update]
			team="2"
			value="131000"
		[/countdown_update]
	[/command]
	[command]
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="wads has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="8,7,7,6"
			y="17,18,19,19"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="9,8,7,7,7,7,7,7,7,7"
			y="15,14,15,16,17,18,19,20,21,22"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="11,12,12,11"
			y="17,16,15,15"
		[/move]
	[/command]
	[command]
		sent="yes"
		[attack]
			defender_weapon="-1"
			weapon="0"
			[source]
				x="11"
				y="15"
			[/source]
			[destination]
				x="10"
				y="15"
			[/destination]
		[/attack]
		[random]
			value="16317"
			[results]
				chance="40"
				damage="8"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="14284"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="32087"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Boucman has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="7,7,7,8,9"
			y="17,16,15,14,15"
		[/move]
	[/command]
	[command]
		sent="yes"
		[attack]
			defender_weapon="-1"
			weapon="0"
			[source]
				x="9"
				y="15"
			[/source]
			[destination]
				x="10"
				y="15"
			[/destination]
		[/attack]
		[random]
			value="4693"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="14397"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Crao has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="smoke has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Tolkien has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="thearchlich has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="kashif has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="8,8,7,7,8"
			y="19,18,18,17,16"
		[/move]
	[/command]
	[command]
		sent="yes"
		[attack]
			defender_weapon="0"
			weapon="0"
			[source]
				x="8"
				y="16"
			[/source]
			[destination]
				x="9"
				y="16"
			[/destination]
		[/attack]
		[random]
			value="29637"
			[results]
				chance="50"
				damage="4"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="26024"
			[results]
				chance="40"
				damage="4"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="7835"
			[results]
				chance="50"
				damage="4"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="13914"
			[results]
				chance="40"
				damage="4"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="17585"
			[results]
				chance="50"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="6863"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="jason has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="9,9,9,9,10,10,11"
			y="21,20,19,18,17,16,16"
		[/move]
	[/command]
	[command]
		sent="yes"
		[attack]
			defender_weapon="-1"
			weapon="0"
			[source]
				x="11"
				y="16"
			[/source]
			[destination]
				x="10"
				y="15"
			[/destination]
		[/attack]
		[random]
			value="1755"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="4696"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="18479"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[move]
			x="24,24,24,24,23"
			y="13,14,15,16,17"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="27,27,27"
			y="14,15,16"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="25,25,25,25,25"
			y="13,14,15,16,17"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="26,26"
			y="15,16"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="30,30,29,29,29,28"
			y="14,15,16,17,18,18"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Shachi has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="28,28,28,28,27"
			y="14,15,16,17,18"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="27,27,28"
			y="16,17,17"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="26,26,25"
			y="16,17,18"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="25,25"
			y="18,19"
		[/move]
	[/command]
	[command]
		sent="yes"
		[countdown_update]
			team="1"
			value="92000"
		[/countdown_update]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="aaa has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="9,10,11"
			y="17,17,17"
		[/move]
	[/command]
	[command]
		[attack]
			defender_weapon="0"
			weapon="0"
			[source]
				x="11"
				y="17"
			[/source]
			[destination]
				x="11"
				y="16"
			[/destination]
		[/attack]
		[random]
			value="24213"
			[results]
				chance="40"
				damage="5"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="25178"
			[results]
				chance="50"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="6532"
			[results]
				chance="40"
				damage="5"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="17254"
			[results]
				chance="50"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="30433"
			[results]
				chance="40"
				damage="5"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="20860"
			[results]
				chance="50"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Titou has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Hagbart has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="13,13,12,12,12,12"
			y="10,11,11,12,13,14"
		[/move]
	[/command]
	[command]
		[attack]
			defender_weapon="-1"
			weapon="0"
			[source]
				x="12"
				y="14"
			[/source]
			[destination]
				x="11"
				y="15"
			[/destination]
		[/attack]
		[random]
			value="22692"
			[results]
				chance="70"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="7220"
			[results]
				chance="70"
				damage="9"
				dies="no"
				hits="yes"
			[/results]
		[/random]
	[/command]
	[command]
		[move]
			x="12,12,12,11"
			y="11,12,13,14"
		[/move]
	[/command]
	[command]
		[attack]
			defender_weapon="-1"
			weapon="0"
			[source]
				x="11"
				y="14"
			[/source]
			[destination]
				x="11"
				y="15"
			[/destination]
		[/attack]
		[random]
			value="3519"
			[results]
				chance="70"
				damage="9"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="17915"
			[results]
				chance="70"
				damage="9"
				dies="no"
				hits="yes"
			[/results]
		[/random]
	[/command]
	[command]
		[attack]
			defender_weapon="-1"
			weapon="0"
			[source]
				x="10"
				y="15"
			[/source]
			[destination]
				x="11"
				y="15"
			[/destination]
		[/attack]
		[random]
			value="3154"
			[results]
				chance="70"
				damage="9"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="10219"
			[results]
				chance="70"
				damage="9"
				dies="yes"
				hits="yes"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Xnodox has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="rycerz has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="anis has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="csl has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="9,10"
			y="16,16"
		[/move]
	[/command]
	[command]
		[attack]
			defender_weapon="1"
			weapon="1"
			[source]
				x="10"
				y="16"
			[/source]
			[destination]
				x="11"
				y="16"
			[/destination]
		[/attack]
		[random]
			value="31218"
			[results]
				chance="40"
				damage="3"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="29172"
			[results]
				chance="50"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="29624"
			[results]
				chance="40"
				damage="3"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="29156"
			[results]
				chance="50"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="11055"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="9473"
			[results]
				chance="50"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="jrika has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="123dave123 has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="9,10,11,12,12"
			y="14,13,14,14,15"
		[/move]
	[/command]
	[command]
		[attack]
			defender_weapon="0"
			weapon="0"
			[source]
				x="12"
				y="15"
			[/source]
			[destination]
				x="11"
				y="16"
			[/destination]
		[/attack]
		[random]
			value="13523"
			[results]
				chance="40"
				damage="6"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="17572"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="31118"
			[results]
				chance="40"
				damage="6"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="2208"
			[results]
				chance="40"
				damage="6"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="20153"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="forby has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="PsychoticKittens has logged into the lobby"
		[/speak]
	[/command]
	[command]
		[move]
			x="15,14,14,14,13,12"
			y="8,8,9,10,11,11"
		[/move]
	[/command]
	[command]
		[recruit]
			value="0"
			x="14"
			y="7"
		[/recruit]
		[random]
			value="4433"
		[/random]
		[random]
			value="28286"
		[/random]
		[random]
			value="19919"
		[/random]
		[random]
			value="28483"
		[/random]
		[random]
			value="8418"
		[/random]
		[random]
			value="3462"
		[/random]
		[random]
			value="14533"
		[/random]
		[random]
			value="17015"
		[/random]
		[random]
			value="9796"
		[/random]
		[random]
			value="20131"
		[/random]
		[random]
			value="5857"
		[/random]
		[random]
			value="1034"
		[/random]
		[random]
			value="3348"
		[/random]
		[random]
			value="22992"
		[/random]
		[random]
			value="28610"
			[results]
				checksum="LhGI28qHcsJn9Niqer4ntRo6wD4zsHoKP1Hy+wP.,jg1d-5cL>71745hhbgk5n1,oc<nn6f23854.o1418om4H8bFWB0pjc+cZng<m8e6X68+vn>t55bKrqZdmOCaJmI"
			[/results]
		[/random]
	[/command]
	[command]
		[move]
			x="23,23"
			y="11,12"
		[/move]
	[/command]
	[command]
		[move]
			x="23,23"
			y="12,11"
		[/move]
	[/command]
	[command]
		[countdown_update]
			team="2"
			value="124000"
		[/countdown_update]
	[/command]
	[command]
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Quetzalcoatl has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="28,27"
			y="18,19"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="27,26"
			y="18,18"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="25,24,23,22,21,20"
			y="17,17,17,17,18,18"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="23,22,21,20,19"
			y="17,17,18,18,19"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="25,24,23,22,21,20,19"
			y="19,19,20,20,20,19,20"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="26,25,24,23"
			y="18,19,19,20"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="27,26,25,24,23"
			y="19,19,20,20,21"
		[/move]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="xapher74 has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="28,27,26,25,24"
			y="17,18,18,19,19"
		[/move]
	[/command]
	[command]
		sent="yes"
		[move]
			x="9,10"
			y="15,14"
		[/move]
	[/command]
	[command]
		sent="yes"
		[attack]
			defender_weapon="-1"
			weapon="0"
			[source]
				x="10"
				y="14"
			[/source]
			[destination]
				x="10"
				y="15"
			[/destination]
		[/attack]
		[random]
			value="25471"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="17692"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Ronny has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="PsychoticKittens has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Volstagg has logged into the lobby"
		[/speak]
	[/command]
	[command]
		undo="no"
		[speak]
			id="Odol"
			message="Mam farta z tym Adeptem..."
			side="2"
		[/speak]
	[/command]
	[command]
		sent="yes"
		undo="no"
		[speak]
			id="Yawner"
			message="ta.."
			side="1"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Rayn has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[move]
			x="6,7,8,8,9"
			y="19,19,18,17,17"
		[/move]
	[/command]
	[command]
		sent="yes"
		[attack]
			defender_weapon="0"
			weapon="0"
			[source]
				x="9"
				y="17"
			[/source]
			[destination]
				x="10"
				y="16"
			[/destination]
		[/attack]
		[random]
			value="27296"
			[results]
				chance="50"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="350"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="1647"
			[results]
				chance="50"
				damage="4"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="23749"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="8641"
			[results]
				chance="50"
				damage="4"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="23158"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[move]
			x="8,9"
			y="16,16"
		[/move]
	[/command]
	[command]
		sent="yes"
		[attack]
			defender_weapon="0"
			weapon="0"
			[source]
				x="9"
				y="16"
			[/source]
			[destination]
				x="10"
				y="16"
			[/destination]
		[/attack]
		[random]
			value="15614"
			[results]
				chance="50"
				damage="4"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="18527"
			[results]
				chance="70"
				damage="4"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="27854"
			[results]
				chance="50"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="6959"
			[results]
				chance="70"
				damage="4"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="8678"
			[results]
				chance="50"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="2137"
			[results]
				chance="70"
				damage="4"
				dies="no"
				hits="yes"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[move]
			x="7,7,8,8,9,9,10"
			y="22,21,20,19,19,18,17"
		[/move]
	[/command]
	[command]
		sent="yes"
		[attack]
			defender_weapon="0"
			weapon="0"
			[source]
				x="10"
				y="17"
			[/source]
			[destination]
				x="10"
				y="16"
			[/destination]
		[/attack]
		[random]
			value="26838"
			[results]
				chance="50"
				damage="6"
				dies="no"
				hits="yes"
			[/results]
		[/random]
		[random]
			value="29466"
			[results]
				chance="50"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="1154"
			[results]
				chance="50"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="16647"
			[results]
				chance="50"
				damage="4"
				dies="yes"
				hits="yes"
			[/results]
		[/random]
	[/command]
	[command]
		sent="yes"
		[move]
			x="11,12,13,14,15,16"
			y="16,16,17,17,18,18"
		[/move]
	[/command]
	[command]
		sent="yes"
		undo="no"
		[speak]
			id="Yawner"
			message="dupa"
			side="1"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[countdown_update]
			team="1"
			value="89000"
		[/countdown_update]
	[/command]
	[command]
		sent="yes"
		[end_turn]
		[/end_turn]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="aaa4 has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Xnodox has logged into the lobby"
		[/speak]
	[/command]
	[command]
		sent="yes"
		undo="no"
		[speak]
			id="Yawner"
			message="czas mi si zaczal konczyc"
			side="1"
		[/speak]
	[/command]
	[command]
		[move]
			x="12,12,13,14,15,16"
			y="15,16,17,17,17,17"
		[/move]
	[/command]
	[command]
		[attack]
			defender_weapon="0"
			weapon="0"
			[source]
				x="16"
				y="17"
			[/source]
			[destination]
				x="16"
				y="18"
			[/destination]
		[/attack]
		[random]
			value="7569"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="6992"
			[results]
				chance="40"
				damage="0"
				dies="no"
				hits="no"
			[/results]
		[/random]
		[random]
			value="31638"
			[results]
				chance="40"
				damage="8"
				dies="yes"
				hits="yes"
			[/results]
		[/random]
	[/command]
	[command]
		[choose]
			value="0"
		[/choose]
	[/command]
	[command]
		sent="yes"
		undo="no"
		[speak]
			id="Yawner"
			message="no i po krolu :p"
			side="1"
		[/speak]
	[/command]
	[command]
		sent="yes"
		undo="no"
		[speak]
			id="Yawner"
			message="dzieki za gre :)"
			side="1"
		[/speak]
	[/command]
	[command]
		undo="no"
		[speak]
			id="Odol"
			message="Dzieki :)"
			side="1"
		[/speak]
	[/command]
	[command]
		sent="yes"
		undo="no"
		[speak]
			id="Yawner"
			message="gratuluje :)"
			side="1"
		[/speak]
	[/command]
	[command]
		undo="no"
		[speak]
			id="Odol"
			message="Thx, GG"
			side="1"
		[/speak]
	[/command]
	[command]
		sent="yes"
		[speak]
			id="server"
			message="Hagbart has logged into the lobby"
		[/speak]
	[/command]
[/replay]
[snapshot]
[/snapshot]
[replay_start]
	current_tod="0"
#textdomain wesnoth-multiplayer
	description=_ "Flooded by the seas and battered by the winter elements, only ruins, water and ice now remain in the shadow of this once mighty empire."
	experience_modifier="70"
	hash="w0,+cAGFJ4mpQeLfM2okH4xJDZ,RHeHQMes8mkISo7Bb+0Jues<4aL3g7BRs93fxsSspDSy<lgboL.,AGypa0LE37KgRjKO.96Itvo2y51,oID3kluarbDjiIcfhR2US"
	id="multiplayer_Sullas_Ruins"
	map_data="border_size=1
usage=map

_off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , Mm          , Gs^Fet      , Hh          , Hh          , Gs          , Gs          , Rd          , Mm^Vhh      , 2 Ke        , Gs^Fp       , Ce          , Gs^Fp       , Wwf         , Mm          , Gs^Fet      , Gs^Fp       , Gs          , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , Hh          , Mm          , Gs          , Gs          , Rd          , Ce          , Ke          , Ce          , Rd          , Gs          , Gs          , Ce          , Ce          , Wwf         , Ke          , Hh          , Ce          , Hh          , Rd          , Rd          , Gs^Fp       , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , Wwf         , Gs          , Wwf         , Gs^Fet      , Gs          , Rd          , Hh          , Rd          , Gs^Fp       , Mm          , Gs^Fp       , Rd          , Gs^Vht      , Gs          , Wwf         , Wwf         , Wwf         , Ce          , Wwf         , Ce          , Ce          , Gs          , Wwf         , Wwf         , Gs          , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , Gs^Fp       , Hh          , Gs          , Wwf         , Chw         , Wwf         , Wwf         , Mm          , Gs          , Gs          , Ww          , Ww          , Ww          , Hh          , Wwf         , Wwf         , Rd          , Gs^Fp       , Gs          , Wwf         , Gs          , Wwf         , Wwf         , Wwf         , Mm          , Gs^Fp       , Gs          , Gs^Fet      , Hh          , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Mm          , Gs          , Gs          , Gs          , Rr          , Gs          , Gs          , Gs^Vht      , Wwf         , Wwf         , Chw         , Chr         , Wo          , Ww          , Mm          , Wwf         , Hh          , Gs          , Rd          , Ss^Vhs      , Gs          , Rd          , Gs          , Gs          , Gs          , Gs          , Hh          , Gs          , Gs          , Wwf         , Mm          , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Gs^Fp       , Rd          , Gs          , Gs          , Gs          , Gs          , Rd          , Hh          , Rr          , Wwf         , Khr         , Rr          , Chw         , Wwf         , Wwf         , Gs          , Gs          , Gs          , Rd          , Gs^Fp       , Hh          , Rd          , Gs          , Ss^Vhs      , Gs          , Khr         , Gs          , Gs          , Wwf         , Gs^Fp       , Wwf         , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Gs          , Chw         , Rd          , Gs          , Gs          , Mm          , Rd          , Gs          , Gs          , Gs          , Wwf         , Wwf         , Wwf         , Ww          , Ww          , Gs          , Gs          , Gs          , Gs          , Hh          , Mm          , Gs          , Ww          , Wo          , Ww          , Chw         , Wwf         , Wwf         , Wwf         , Gs^Fp       , Hh          , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Hh          , Gs          , Gs          , Wwf         , Rr          , Wwf         , Gs          , Wwf         , Rr          , Gs          , Gs^Fp       , Gs          , Gs          , Ww          , Gs          , Ss^Vhs      , Gs^Fp       , Chw         , Gs          , Gs          , Gs          , Wwf         , Ww          , Ww          , Ww          , Chw         , Chw         , Gs          , Gs          , Gs          , Gs          , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Gs          , Gs          , Gs          , Rr          , Wo          , Wo          , Chw         , Chw         , Wwf         , Gs^Vht      , Gs          , Gs          , Ww          , Gs          , Gs          , Gs          , Hh          , Gs          , Chw         , Gs          , Gs^Vht      , Gs^Fp       , Wwf         , Gs          , Wwf         , Wwf         , Rr          , Gs          , Gs          , Mm          , Wo          , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Mm          , Hh          , Gs          , Gs          , Wwf         , Gs          , Rr          , Mm          , Gs          , Gs          , Gs^Fp       , Gs          , Ww          , Wwf         , Wwf         , Wwf         , Gs          , Rr          , Gs          , Gs          , Gs          , Wwf         , Wwf         , Gs          , Gs          , Gs^Fet      , Wwf         , Wwf         , Gs          , Wwf         , Hh          , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Hh          , Gs^Fp       , Gs          , Gs          , Gs          , Gs^Fp       , Gs          , Gs          , Rd          , Rd          , Gs          , Wwf         , Wwf         , Ai          , Aa^Fpa      , Chw         , Wwf         , Wwf         , Rr          , Wwf         , Wwf         , Mm          , Hh          , Gs^Fp       , Rd          , Rd          , Hh          , Gs          , Wwf         , Gs^Fp       , Wwf         , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Wo          , Chw         , Gs          , Gs          , Gs          , Gs          , Gs^Fet      , Gs          , Hh          , Rd          , Hh          , Wwf         , Aa          , Aa^Fpa      , Ha          , Aa^Fpa      , Ai          , Wwf         , Wo          , Gs          , Gs^Fp       , Rd          , Gs          , Rd          , Chw         , Chw         , Rd          , Gs          , Gs          , Rr          , Hh          , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Mm          , Rr          , Gs          , Gs          , Gs          , Rr          , Gs          , Chw         , Chw         , Chw         , Gs          , Chw         , Wwf         , Ha          , Ms          , Khr         , Ha          , Ha          , Wwf         , Chw         , Gs          , Chw         , Chw         , Rd          , Rd          , Gs          , Rd          , Gs          , Gs          , Hh          , Mm          , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Gs^Fet      , Gs          , Gs          , Gs          , Rr          , Chw         , Rd          , Rd          , Rd          , Rd          , Gs          , Gs          , Wwf         , Wwf         , Ha          , Aa^Fpa      , Ms          , Aa^Fpa      , Wwf         , Wwf         , Gs          , Rd          , Rd          , Hh          , Gs          , Gs^Fp       , Gs          , Gs          , Gs          , Gs^Fet      , Wo          , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Wwf         , Wwf         , Wwf         , Wwf         , Gs^Fp       , Hh          , Chw         , Gs          , Hh          , Mm          , Gs^Fp       , Wwf         , Wo          , Wwf         , Ai          , Chw         , Ha          , Ai          , Aa          , Wwf         , Hh          , Rd          , Hh          , Wwf         , Rd          , Hh          , Gs          , Gs          , Gs          , Rd          , Chw         , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Hh          , Gs          , Gs          , Gs          , Wwf         , Wwf         , Gs          , Wwf         , Wwf         , Wwf         , Wwf         , Gs          , Rr          , Rr          , Wwf         , Wwf         , Aa^Fpa      , Wwf         , Wwf         , Gs          , Rd          , Gs^Fp       , Gs          , Wwf         , Mm          , Wwf         , Gs          , Wwf         , Rr          , Gs          , Rd          , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Wo          , Rd          , Gs^Fp       , Gs^Vht      , Gs          , Chw         , Chw         , Ww          , Ww          , Ww          , Gs          , Gs          , Gs          , Gs          , Gs          , Gs          , Wwf         , Gs          , Ww          , Gs          , Rd          , Rd          , Gs^Vht      , Gs          , Chw         , Chw         , Wo          , Wo          , Wwf         , Rr          , Gs          , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Gs          , Hh          , Rd          , Gs          , Gs          , Rr          , Chw         , Ww          , Wo          , Ww          , Wwf         , Gs          , Chw         , Chw         , Hh          , Ss^Vhs      , Gs          , Ww          , Ww          , Gs          , Gs          , Rd          , Rd          , Gs          , Rr          , Gs^Fet      , Gs          , Gs          , Rr          , Chw         , Gs^Fp       , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Mm          , Gs^Fp       , Gs          , Gs          , Gs          , Gs          , Khr         , Wwf         , Ss^Vhs      , Gs          , Gs          , Gs          , Gs          , Gs          , Gs^Fp       , Gs          , Gs          , Ww          , Gs          , Gs^Fp       , Gs          , Gs^Fp       , Rd          , Rd          , Gs          , Mm          , Gs^Fp       , Gs          , Gs          , Gs          , Gs          , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Wwf         , Wwf         , Gs          , Wwf         , Wwf         , Wwf         , Wwf         , Rr          , Gs          , Mm          , Hh          , Gs^Fp       , Mm          , Gs          , Gs          , Gs          , Wwf         , Wwf         , Ww          , Wwf         , Wwf         , Wwf         , Hh          , Gs          , Rd          , Gs          , Gs          , Gs          , Gs          , Gs^Fp       , Hh          , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Gs          , Rr          , Wwf         , Gs          , Gs          , Gs          , Rr          , Gs          , Gs          , Gs          , Hh          , Ss^Vhs      , Rd          , Rd          , Gs          , Wwf         , Wwf         , Gs^Fp       , Wwf         , Chw         , Rr          , Khr         , Wwf         , Wwf         , Hh          , Gs          , Gs          , Gs          , Gs          , Gs          , Gs^Fp       , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Hh          , Gs^Fet      , Rr          , Gs          , Gs          , Gs          , Rr          , Chw         , Gs          , Gs^Fp       , Gs          , Rd          , Rd          , Hh          , Mm          , Wwf         , Hh          , Ww          , Ww          , Wo          , Chr         , Chw         , Rr          , Wwf         , Gs^Vht      , Gs          , Gs          , Wwf         , Gs          , Hh          , Hh          , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , Mm          , Gs^Fp       , Gs          , Gs          , Gs          , Wwf         , Gs          , Wwf         , Ww          , Wwf         , Hh          , Wwf         , Gs          , Gs          , Wwf         , Gs^Vht      , Hh          , Gs          , Ww          , Ww          , Ww          , Gs          , Mm          , Gs          , Wwf         , Wwf         , Wwf         , Gs          , Wwf         , Wwf         , Mm          , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , Gs          , Wwf         , Wwf         , Hh          , Wwf         , Gs^Fp       , Gs          , Gs          , Wwf         , Gs          , Wwf         , Wwf         , Wwf         , Gs^Fp       , Gs          , Rd          , Mm          , Gs          , Gs^Fp       , Gs          , Hh          , Gs          , Gs          , Hh          , Gs          , Gs          , Gs          , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , Mm          , Hh          , Rd          , Rd          , Gs          , Rd          , Mm          , Hh          , Ke          , Wwf         , Gs          , Gs          , Gs          , Gs          , Rd          , Gs          , Ke          , Gs          , Gs          , Hh          , Rd          , Mm          , Gs^Fp       , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , Mm          , Gs^Fp       , Rd          , Ce          , Ce          , Ce          , Ce          , Wwf         , Mm          , Ce          , 1 Ke        , Ce          , Mm^Vhh      , Hh          , Ce          , Ce          , Rd          , Gs^Fp       , Gs^Fp       , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , Gs^Fet      , _off^_usr   , Gs^Fp       , _off^_usr   , Wwf         , _off^_usr   , Hh          , _off^_usr   , Gs^Fet      , _off^_usr   , Gs^Fp       , _off^_usr   , Mm          , _off^_usr   , Rd          , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   
_off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   , _off^_usr   
"
	mp_countdown="yes"
	mp_countdown_action_bonus="10"
	mp_countdown_init_time="180"
	mp_countdown_reservoir_time="240"
	mp_countdown_turn_bonus="45"
	mp_fog="yes"
	mp_shroud="no"
	mp_use_map_settings="yes"
	mp_village_gold="2"
	name=_ "2p - Sulla's Ruins"
	next_underlying_unit_id="0"
#textdomain wesnoth
	objectives=_ "Victory:
@Defeat enemy leader(s)"
	observer="yes"
	random_seed="9913"
	random_start_time="no"
	scenario="Ladder, Yawner 1450"
	turns="-1"
	version="1.6"
	[time]
		green="-20"
		id="dawn"
		image="misc/schedule-dawn.png"
		name=_ "Dawn"
		red="-20"
		sound="ambient/morning.ogg"
	[/time]
	[time]
		id="morning"
		image="misc/schedule-morning.png"
		lawful_bonus="25"
		name=_ "Morning"
	[/time]
	[time]
		id="afternoon"
		image="misc/schedule-afternoon.png"
		lawful_bonus="25"
		name=_ "Afternoon"
	[/time]
	[time]
		blue="-20"
		green="-20"
		id="dusk"
		image="misc/schedule-dusk.png"
		name=_ "Dusk"
		sound="ambient/night.ogg"
	[/time]
	[time]
		blue="-10"
		green="-40"
		id="first_watch"
		image="misc/schedule-firstwatch.png"
		lawful_bonus="-25"
		name=_ "First Watch"
		red="-40"
	[/time]
	[time]
		blue="-10"
		green="-40"
		id="second_watch"
		image="misc/schedule-secondwatch.png"
		lawful_bonus="-25"
		name=_ "Second Watch"
		red="-40"
	[/time]
	[music]
		ms_before="12000"
		name="knolls.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="wanderer.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="battle.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="transience.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="the_king_is_dead.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="knalgan_theme.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="the_city_falls.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="nunc_dimittis.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="revelation.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="loyalists.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="breaking_the_chains.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="elvish-theme.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="legends_of_the_north.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="traveling_minstrels.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="underground.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="vengeful.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="frantic.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="the_dangerous_symphony.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="heroes_rite.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="suspense.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="the_deep_path.ogg"
	[/music]
	[music]
		append="yes"
		ms_before="12000"
		name="siege_of_laurelmor.ogg"
	[/music]
	[event]
		name="prestart"
		[music]
			ms_before="12000"
			name="knolls.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="wanderer.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="battle.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="transience.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="revelation.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="loyalists.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="the_king_is_dead.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="knalgan_theme.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="the_city_falls.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="nunc_dimittis.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="breaking_the_chains.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="elvish-theme.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="legends_of_the_north.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="traveling_minstrels.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="underground.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="vengeful.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="frantic.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="the_dangerous_symphony.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="heroes_rite.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="suspense.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="the_deep_path.ogg"
		[/music]
		[music]
			append="yes"
			ms_before="12000"
			name="siege_of_laurelmor.ogg"
		[/music]
	[/event]
	[era]
		id="era_default"
#textdomain wesnoth-multiplayer
		name=_ "Default"
		[multiplayer_side]
			flag_rgb="magenta"
			id="Random"
			image="units/random-dice.png"
			name=_ "Random"
			random_faction="yes"
		[/multiplayer_side]
		[multiplayer_side]
			flag_rgb="magenta"
			id="Loyalists"
			image="units/human-loyalists/lieutenant.png"
			leader="Lieutenant,Swordsman,Pikeman,Javelineer,Shock Trooper,Longbowman,White Mage,Red Mage"
			name=_ "Loyalists"
			random_leader="Lieutenant,Swordsman,Pikeman,Javelineer,Longbowman,Red Mage"
			recruit="Cavalryman,Horseman,Spearman,Fencer,Heavy Infantryman,Bowman,Mage,Merman Fighter"
			terrain_liked="Gg, Ww, Wo"
			type="Lieutenant"
			[ai]
				recruitment_pattern="fighter,fighter,fighter,archer,mixed fighter,scout"
				[team_formula]
					rulebase="fai 'recruitment.fai'
		# ===== Some general functions used later ==== #

def sumarize_values( input_map )
	sum(
		values(input_map)
	);

def lowest_value( input_map )
	choose( input_map, -value ).value;

def highest_value( input_map )
	choose( input_map, value ).value;

def change_numbers_to_percents( input_map )
	map( input_map, 
		(value*100) / highest_value(input_map) 
	);

def add_number_to_values( input_map, number )
	map( input_map, 
		value + number 
	);

#make sure we have only positive values in a map #

def make_positive_only( input_map )
	if( lowest_value( input_map ) < 0, 
		add_number_to_values( 
			input_map, 
			abs(lowest_value(input_map))
		), 
		input_map 
	);

def sumarize_maps_values( map_A, map_B )
	map( map_A + map_B, 
		value + map_A[key]
	);

		#===== Evaluation how good unit is on a map ===== #

# ==1==  evaluate average defense #
#gives map where key is id of terrain, and value is number of hexes of that terrain on a gamemap#

def locations_map(ai*) 
	tomap( 
		map( 
			map.terrain, 
			id 
		) 
	);

#filters terrain map, min_percent it minimal % of map that terrain has to occupy to be considered in later evaluations# 

def filtered_locations_map(ai*, min_percent)
	filter( 
		locations_map(ai) , 
		value >  (map.w * map.h) / ( 100 / min_percent ) 
	);

#returns average defense of the unit #

def unit_average_defense(ai*, unit, terrain_min_percent )
	sum( 
		values( 
			map(
				filtered_locations_map(ai,terrain_min_percent), 
				defense_on( 
					unit, 
					find(map.terrain,id=key).loc
				) *
				value
			) 
		) 
	) / 
	sum(
		values(
			filtered_locations_map(
				ai,
				terrain_min_percent
			)
		)
	);

#returns map of units from units_list and their average defense (more -> better) #

def map_units_average_defense(ai*, units_list, terrain_min_percent) 
	tomap(
		map( 
			units_list, 
			id 
		), 
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	);

def units_average_defense(ai*, units_list, terrain_min_percent)
	sum(
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	) /
	size(
		units_list
	);


# ==2== TODO: evaluate unit effectivness based on movement points and movement cost#


		#===== Evaluation of game state - how good is ai doing ===== #

# ==1== based on unit cost and current amount of gold #
# returns number between 0 and 100 where: 0 we are losing, 100 we are winning #

def units_cost_gold_eval(ai*)
	min(
		[
			(
				(
					sum(
						map(
							allies, 'team', 
							sum(
								map(
									units_of_side[team], 
									cost
								)
							) + 
							teams[team].gold 
						)
					) * 
					100
				) / 
				sum(
					map(
						enemies, 'team', 
						sum(
							map(
								units_of_side[team], 
								cost
							)
						) + 
						max(
							[teams[team].gold, 0]
						) 
					)
				)
			) / 2,
			100
		]
	);

# ==2== based on village possession #

def count_allied_villages(ai*)
	sum(
		map(
			allies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

def count_enemy_villages(ai*)
	sum(
		map(
			enemies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

# multipled by 1000 to increase precision #

def village_evaluation(ai*)
	(
		50000 + 
		(
			count_allied_villages(ai) - 
			count_enemy_villages(ai)
		) * 
		(
			50000 /
			size(
				villages
			)
		)
	) /
	1000;

# ==3== combined 2 of the above #

def eval(ai*)
	( 
		units_cost_gold_eval(ai) + 
		village_evaluation(ai)
	) / 
	2;

		#===== Evaluation how effective my units are against the enemy ===== #

#==1==  basic evaluation #

# evaluate how much damage unit can inflict - how much damage unit can get#

def evaluate_attacker_against_opponents(ai*, unit, enemy_units)
	sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( unit, enemy_unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				) 
			)
		)
	);

def evaluate_defender_against_opponents(ai*, unit, enemy_units)
	-sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( enemy_unit, unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				)
			)
		)
	);

def units_hp_map(ai*, units)
	tomap( 
		map(
			units, 
			id
		), 
		map( 
			units, 
			hitpoints
		)
	);

#in case side's gold is more than 50, add units that side can recruit to the side's unit list#

def create_side_unit_list(ai*, side)
	if( 
		teams[side].gold > 50, 
		recruits_of_side[side], 
		[]
	) + 
	units_of_side[side];

def evaluate_my_recruits_as_attackers(ai*)
	tomap( 
		map(
			my_recruits, 
			id
		), 
		map(
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_attacker_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai, 
							enemy_side
						)
					)
				)
			)
		)
	);

def evaluate_my_recruits_as_defenders(ai*)
	tomap(
		map(
			my_recruits, 
			id
		),
		map( 
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_defender_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai,
							enemy_side
						)
					)
				)
			)
		)
	);


# === 2 ===  now consider abilities and weapon specials  #

def abilities_weights()
	['skirmisher' -> 15, 'ambush' -> 10, 'nightstalk' -> 20, 'regenerates' -> 20, 'healing' -> 15, 'curing' -> 10, 'leadership' -> 20, 'illumination' -> 15, 'teleport' -> 10, 'steadfast' -> 15 ];

def weapon_specials_weights()
	[ 'backstab' -> 20 ,'slow' -> 10 ,'berserk' -> 20 ,'stones' -> 60 ,'plague' -> 10 ,'marksman' -> 30 ,'magical' -> 40 ,'charge' -> 30 ,'drains' -> 30,  'firststrike' -> 10, 'poison' -> 25 ];

def apply_abilities_weights( units_map )
	map( 
		units_map, 
		value +
		(
			value * 
			max(
				map(
					get_unit_type( key ).abilities, 'ability',
					abilities_weights()[ability]
				)
			)
		) / 100
	);

def apply_weapon_specials_weights( units_map )
	map(
		units_map, 
		value +
		(
			value *
			max(
				map(
					get_unit_type( key ).attacks, 'attack',
					vars.weapon_specials[attack.special]
				)
			)
		) / 100
	);

# since undead units don't get random traits and are balanced with that, we need to lower their evaluation a bit to match fairly the living units #

def undead_malus( units_map )
	map( 
		units_map, 
		if(
			get_unit_type(key).undead,
			( value * 90 ) / 100,
			value 
		)
	);

# === 3 ===  pit 1 and 2 together  #

def evaluate_attackers(ai*)
	change_numbers_to_percents(
		apply_abilities_weights(
			apply_weapon_specials_weights(
				undead_malus( 
					make_positive_only(
						evaluate_my_recruits_as_attackers( ai )	
					)
				)
			)
		)
	);

def evaluate_defenders(ai*)
	map(
		map(
			change_numbers_to_percents(
				apply_abilities_weights(
					apply_weapon_specials_weights(
						undead_malus( 
							make_positive_only(
								evaluate_my_recruits_as_defenders( ai )	
							)
						)
					)
				)
			),
			value / 3
		), 
		value +
		map(
			change_numbers_to_percents(
				units_hp_map(
					ai,
					my_recruits
				)
			),
		value * 2 / 3
		)[key]
	);

	#=========== we have evaluation of game state and units, time to combine them: ==========#
		#=========	recruitment_list_builder	=========#

def rlb_apply_eval(eval, attackers_map, defenders_map, offset)
	map(
		sumarize_maps_values(
			map(
				attackers_map, 
				value * (eval+offset)
			),
			map(
				defenders_map,
				value * ( (100 - eval) - offset )
			)
		),
		value / 100
	);

def rlb_remove_lowest( input_map, percent)
	filter(
		input_map, 
		value > 
		(
			(
				percent * sumarize_values(input_map)
			) / 100
		)
	);

def rlb_first_step(eval, attackers_map, defenders_map, offset)
	rlb_remove_lowest(
		rlb_apply_eval(
			eval,
			attackers_map,
			defenders_map,
			offset
		),
		10
	);

def recruitment_list_builder(eval, attackers_map, defenders_map)
	map(
		rlb_first_step(
			eval,
			attackers_map,
			defenders_map,
			40
		),
		(
			(
				value * 100
			) / 
			sumarize_values(
				rlb_first_step(
					eval,
					attackers_map,
					defenders_map,
					40
				)
			)
		)
	);

		# ========== choose the unit to recruit now ========= #

def unit_chooser(ai*,unit_map) 
	choose(
		keys(unit_map), 'unit_type',
		unit_map[unit_type] - 
		(
			(
				100 * 
				size(
					filter(
						my_units, 
						type = unit_type
					)
				)
			) / 
			size(my_units)
		)
	);

def unit_map_cost_filter(ai*, unit_map)
	filter( unit_map,
		get_unit_type(key).cost < my_side.gold
	);

		# ==========	Main formula section 	========== #

def initialize_weapon_specials_map(ai*)
	if(vars.weapon_specials_init != turn,
		[
			set_var('weapon_specials_init', turn),
			set_var('weapon_specials',
				map(
					weapon_specials_weights(),
					if( key = 'magical',
						units_average_defense(ai, enemy_units, 10),
						if( key = 'marksman',
							units_average_defense(ai, enemy_units, 10) - 10,
							value
						)
					)
				)
			)
		],
		[]
	);

def create_recruits_map(ai*)
	if(vars.recruits_map_creator != turn,
		[
			set_var('recruits_map_creator', turn ),
			set_var('recruits_map',
				debug_print('final unit evaluation: ', recruitment_list_builder(
					debug_print('current AI evaluation (0-100): ', eval(ai)),
					debug_print('attackers evaluation: ',evaluate_attackers(ai)),
					debug_print('defenders evaluation: ',evaluate_defenders(ai))
				))
			)
		],
		[]
	);

def castle_space(ai*)
	filter( map( castle_locs( my_leader.loc ), 'location', if( unit_at( location ), 1, 0 ) ), self = 0  ).size;

if(vars.turn_initialized = turn,
		if( my_leader.loc = nearest_keep( my_leader.loc ),
			if( 
				get_unit_type(
					choose(
						vars.recruits_map,
						-get_unit_type(key).cost
					).key
				).cost <
				my_side.gold,
				if( castle_space(self),
					recruit(debug_print(
						unit_chooser(
							self,
							unit_map_cost_filter(
								self,
								vars.recruits_map
							)
						)
					)),
					fallback()
				),
				fallback() 
			),
			if( my_leader.movement_left > 0,
				move( my_leader.loc, nearest_keep( my_leader.loc ) ),
				fallback()
			)
		),
	[set_var(debug_print('turn_initialized'), turn)] +
	initialize_weapon_specials_map(self) +
	create_recruits_map(self)
)

faiend
"
				[/team_formula]
			[/ai]
		[/multiplayer_side]
		[multiplayer_side]
			flag_rgb="magenta"
			id="Rebels"
			image="units/elves-wood/captain.png"
			leader="Elvish Captain,Elvish Hero,Elvish Ranger,Elvish Marksman,Elvish Druid,Elvish Sorceress,White Mage,Red Mage,Elder Wose"
			name=_ "Rebels"
			random_leader="Elvish Captain,Elvish Hero,Elvish Ranger,Elvish Marksman,Elvish Druid,Elvish Sorceress,Red Mage"
			recruit="Elvish Fighter,Elvish Archer,Mage,Elvish Shaman,Elvish Scout,Wose,Merman Hunter"
			terrain_liked="Ff, Fa, Ss, Ww"
			type="Elvish Captain"
			[ai]
				recruitment_pattern="fighter,fighter,archer,archer,mixed fighter,healer,scout"
				[team_formula]
					rulebase="fai 'recruitment.fai'
		# ===== Some general functions used later ==== #

def sumarize_values( input_map )
	sum(
		values(input_map)
	);

def lowest_value( input_map )
	choose( input_map, -value ).value;

def highest_value( input_map )
	choose( input_map, value ).value;

def change_numbers_to_percents( input_map )
	map( input_map, 
		(value*100) / highest_value(input_map) 
	);

def add_number_to_values( input_map, number )
	map( input_map, 
		value + number 
	);

#make sure we have only positive values in a map #

def make_positive_only( input_map )
	if( lowest_value( input_map ) < 0, 
		add_number_to_values( 
			input_map, 
			abs(lowest_value(input_map))
		), 
		input_map 
	);

def sumarize_maps_values( map_A, map_B )
	map( map_A + map_B, 
		value + map_A[key]
	);

		#===== Evaluation how good unit is on a map ===== #

# ==1==  evaluate average defense #
#gives map where key is id of terrain, and value is number of hexes of that terrain on a gamemap#

def locations_map(ai*) 
	tomap( 
		map( 
			map.terrain, 
			id 
		) 
	);

#filters terrain map, min_percent it minimal % of map that terrain has to occupy to be considered in later evaluations# 

def filtered_locations_map(ai*, min_percent)
	filter( 
		locations_map(ai) , 
		value >  (map.w * map.h) / ( 100 / min_percent ) 
	);

#returns average defense of the unit #

def unit_average_defense(ai*, unit, terrain_min_percent )
	sum( 
		values( 
			map(
				filtered_locations_map(ai,terrain_min_percent), 
				defense_on( 
					unit, 
					find(map.terrain,id=key).loc
				) *
				value
			) 
		) 
	) / 
	sum(
		values(
			filtered_locations_map(
				ai,
				terrain_min_percent
			)
		)
	);

#returns map of units from units_list and their average defense (more -> better) #

def map_units_average_defense(ai*, units_list, terrain_min_percent) 
	tomap(
		map( 
			units_list, 
			id 
		), 
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	);

def units_average_defense(ai*, units_list, terrain_min_percent)
	sum(
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	) /
	size(
		units_list
	);


# ==2== TODO: evaluate unit effectivness based on movement points and movement cost#


		#===== Evaluation of game state - how good is ai doing ===== #

# ==1== based on unit cost and current amount of gold #
# returns number between 0 and 100 where: 0 we are losing, 100 we are winning #

def units_cost_gold_eval(ai*)
	min(
		[
			(
				(
					sum(
						map(
							allies, 'team', 
							sum(
								map(
									units_of_side[team], 
									cost
								)
							) + 
							teams[team].gold 
						)
					) * 
					100
				) / 
				sum(
					map(
						enemies, 'team', 
						sum(
							map(
								units_of_side[team], 
								cost
							)
						) + 
						max(
							[teams[team].gold, 0]
						) 
					)
				)
			) / 2,
			100
		]
	);

# ==2== based on village possession #

def count_allied_villages(ai*)
	sum(
		map(
			allies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

def count_enemy_villages(ai*)
	sum(
		map(
			enemies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

# multipled by 1000 to increase precision #

def village_evaluation(ai*)
	(
		50000 + 
		(
			count_allied_villages(ai) - 
			count_enemy_villages(ai)
		) * 
		(
			50000 /
			size(
				villages
			)
		)
	) /
	1000;

# ==3== combined 2 of the above #

def eval(ai*)
	( 
		units_cost_gold_eval(ai) + 
		village_evaluation(ai)
	) / 
	2;

		#===== Evaluation how effective my units are against the enemy ===== #

#==1==  basic evaluation #

# evaluate how much damage unit can inflict - how much damage unit can get#

def evaluate_attacker_against_opponents(ai*, unit, enemy_units)
	sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( unit, enemy_unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				) 
			)
		)
	);

def evaluate_defender_against_opponents(ai*, unit, enemy_units)
	-sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( enemy_unit, unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				)
			)
		)
	);

def units_hp_map(ai*, units)
	tomap( 
		map(
			units, 
			id
		), 
		map( 
			units, 
			hitpoints
		)
	);

#in case side's gold is more than 50, add units that side can recruit to the side's unit list#

def create_side_unit_list(ai*, side)
	if( 
		teams[side].gold > 50, 
		recruits_of_side[side], 
		[]
	) + 
	units_of_side[side];

def evaluate_my_recruits_as_attackers(ai*)
	tomap( 
		map(
			my_recruits, 
			id
		), 
		map(
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_attacker_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai, 
							enemy_side
						)
					)
				)
			)
		)
	);

def evaluate_my_recruits_as_defenders(ai*)
	tomap(
		map(
			my_recruits, 
			id
		),
		map( 
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_defender_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai,
							enemy_side
						)
					)
				)
			)
		)
	);


# === 2 ===  now consider abilities and weapon specials  #

def abilities_weights()
	['skirmisher' -> 15, 'ambush' -> 10, 'nightstalk' -> 20, 'regenerates' -> 20, 'healing' -> 15, 'curing' -> 10, 'leadership' -> 20, 'illumination' -> 15, 'teleport' -> 10, 'steadfast' -> 15 ];

def weapon_specials_weights()
	[ 'backstab' -> 20 ,'slow' -> 10 ,'berserk' -> 20 ,'stones' -> 60 ,'plague' -> 10 ,'marksman' -> 30 ,'magical' -> 40 ,'charge' -> 30 ,'drains' -> 30,  'firststrike' -> 10, 'poison' -> 25 ];

def apply_abilities_weights( units_map )
	map( 
		units_map, 
		value +
		(
			value * 
			max(
				map(
					get_unit_type( key ).abilities, 'ability',
					abilities_weights()[ability]
				)
			)
		) / 100
	);

def apply_weapon_specials_weights( units_map )
	map(
		units_map, 
		value +
		(
			value *
			max(
				map(
					get_unit_type( key ).attacks, 'attack',
					vars.weapon_specials[attack.special]
				)
			)
		) / 100
	);

# since undead units don't get random traits and are balanced with that, we need to lower their evaluation a bit to match fairly the living units #

def undead_malus( units_map )
	map( 
		units_map, 
		if(
			get_unit_type(key).undead,
			( value * 90 ) / 100,
			value 
		)
	);

# === 3 ===  pit 1 and 2 together  #

def evaluate_attackers(ai*)
	change_numbers_to_percents(
		apply_abilities_weights(
			apply_weapon_specials_weights(
				undead_malus( 
					make_positive_only(
						evaluate_my_recruits_as_attackers( ai )	
					)
				)
			)
		)
	);

def evaluate_defenders(ai*)
	map(
		map(
			change_numbers_to_percents(
				apply_abilities_weights(
					apply_weapon_specials_weights(
						undead_malus( 
							make_positive_only(
								evaluate_my_recruits_as_defenders( ai )	
							)
						)
					)
				)
			),
			value / 3
		), 
		value +
		map(
			change_numbers_to_percents(
				units_hp_map(
					ai,
					my_recruits
				)
			),
		value * 2 / 3
		)[key]
	);

	#=========== we have evaluation of game state and units, time to combine them: ==========#
		#=========	recruitment_list_builder	=========#

def rlb_apply_eval(eval, attackers_map, defenders_map, offset)
	map(
		sumarize_maps_values(
			map(
				attackers_map, 
				value * (eval+offset)
			),
			map(
				defenders_map,
				value * ( (100 - eval) - offset )
			)
		),
		value / 100
	);

def rlb_remove_lowest( input_map, percent)
	filter(
		input_map, 
		value > 
		(
			(
				percent * sumarize_values(input_map)
			) / 100
		)
	);

def rlb_first_step(eval, attackers_map, defenders_map, offset)
	rlb_remove_lowest(
		rlb_apply_eval(
			eval,
			attackers_map,
			defenders_map,
			offset
		),
		10
	);

def recruitment_list_builder(eval, attackers_map, defenders_map)
	map(
		rlb_first_step(
			eval,
			attackers_map,
			defenders_map,
			40
		),
		(
			(
				value * 100
			) / 
			sumarize_values(
				rlb_first_step(
					eval,
					attackers_map,
					defenders_map,
					40
				)
			)
		)
	);

		# ========== choose the unit to recruit now ========= #

def unit_chooser(ai*,unit_map) 
	choose(
		keys(unit_map), 'unit_type',
		unit_map[unit_type] - 
		(
			(
				100 * 
				size(
					filter(
						my_units, 
						type = unit_type
					)
				)
			) / 
			size(my_units)
		)
	);

def unit_map_cost_filter(ai*, unit_map)
	filter( unit_map,
		get_unit_type(key).cost < my_side.gold
	);

		# ==========	Main formula section 	========== #

def initialize_weapon_specials_map(ai*)
	if(vars.weapon_specials_init != turn,
		[
			set_var('weapon_specials_init', turn),
			set_var('weapon_specials',
				map(
					weapon_specials_weights(),
					if( key = 'magical',
						units_average_defense(ai, enemy_units, 10),
						if( key = 'marksman',
							units_average_defense(ai, enemy_units, 10) - 10,
							value
						)
					)
				)
			)
		],
		[]
	);

def create_recruits_map(ai*)
	if(vars.recruits_map_creator != turn,
		[
			set_var('recruits_map_creator', turn ),
			set_var('recruits_map',
				debug_print('final unit evaluation: ', recruitment_list_builder(
					debug_print('current AI evaluation (0-100): ', eval(ai)),
					debug_print('attackers evaluation: ',evaluate_attackers(ai)),
					debug_print('defenders evaluation: ',evaluate_defenders(ai))
				))
			)
		],
		[]
	);

def castle_space(ai*)
	filter( map( castle_locs( my_leader.loc ), 'location', if( unit_at( location ), 1, 0 ) ), self = 0  ).size;

if(vars.turn_initialized = turn,
		if( my_leader.loc = nearest_keep( my_leader.loc ),
			if( 
				get_unit_type(
					choose(
						vars.recruits_map,
						-get_unit_type(key).cost
					).key
				).cost <
				my_side.gold,
				if( castle_space(self),
					recruit(debug_print(
						unit_chooser(
							self,
							unit_map_cost_filter(
								self,
								vars.recruits_map
							)
						)
					)),
					fallback()
				),
				fallback() 
			),
			if( my_leader.movement_left > 0,
				move( my_leader.loc, nearest_keep( my_leader.loc ) ),
				fallback()
			)
		),
	[set_var(debug_print('turn_initialized'), turn)] +
	initialize_weapon_specials_map(self) +
	create_recruits_map(self)
)

faiend
"
				[/team_formula]
			[/ai]
		[/multiplayer_side]
		[multiplayer_side]
			flag_rgb="magenta"
			id="Northerners"
			image="units/orcs/warrior.png"
			leader="Orcish Warrior,Troll,Troll Rocklobber,Orcish Crossbowman,Orcish Slayer"
			name=_ "Northerners"
			recruit="Orcish Grunt,Troll Whelp,Wolf Rider,Orcish Archer,Orcish Assassin,Naga Fighter,Goblin Spearman"
			terrain_liked="Hh, Ha, Mm, Ss"
			type="Orcish Warrior"
			[ai]
				recruitment_pattern="fighter,fighter,fighter,mixed fighter,archer,scout"
				[team_formula]
					rulebase="fai 'recruitment.fai'
		# ===== Some general functions used later ==== #

def sumarize_values( input_map )
	sum(
		values(input_map)
	);

def lowest_value( input_map )
	choose( input_map, -value ).value;

def highest_value( input_map )
	choose( input_map, value ).value;

def change_numbers_to_percents( input_map )
	map( input_map, 
		(value*100) / highest_value(input_map) 
	);

def add_number_to_values( input_map, number )
	map( input_map, 
		value + number 
	);

#make sure we have only positive values in a map #

def make_positive_only( input_map )
	if( lowest_value( input_map ) < 0, 
		add_number_to_values( 
			input_map, 
			abs(lowest_value(input_map))
		), 
		input_map 
	);

def sumarize_maps_values( map_A, map_B )
	map( map_A + map_B, 
		value + map_A[key]
	);

		#===== Evaluation how good unit is on a map ===== #

# ==1==  evaluate average defense #
#gives map where key is id of terrain, and value is number of hexes of that terrain on a gamemap#

def locations_map(ai*) 
	tomap( 
		map( 
			map.terrain, 
			id 
		) 
	);

#filters terrain map, min_percent it minimal % of map that terrain has to occupy to be considered in later evaluations# 

def filtered_locations_map(ai*, min_percent)
	filter( 
		locations_map(ai) , 
		value >  (map.w * map.h) / ( 100 / min_percent ) 
	);

#returns average defense of the unit #

def unit_average_defense(ai*, unit, terrain_min_percent )
	sum( 
		values( 
			map(
				filtered_locations_map(ai,terrain_min_percent), 
				defense_on( 
					unit, 
					find(map.terrain,id=key).loc
				) *
				value
			) 
		) 
	) / 
	sum(
		values(
			filtered_locations_map(
				ai,
				terrain_min_percent
			)
		)
	);

#returns map of units from units_list and their average defense (more -> better) #

def map_units_average_defense(ai*, units_list, terrain_min_percent) 
	tomap(
		map( 
			units_list, 
			id 
		), 
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	);

def units_average_defense(ai*, units_list, terrain_min_percent)
	sum(
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	) /
	size(
		units_list
	);


# ==2== TODO: evaluate unit effectivness based on movement points and movement cost#


		#===== Evaluation of game state - how good is ai doing ===== #

# ==1== based on unit cost and current amount of gold #
# returns number between 0 and 100 where: 0 we are losing, 100 we are winning #

def units_cost_gold_eval(ai*)
	min(
		[
			(
				(
					sum(
						map(
							allies, 'team', 
							sum(
								map(
									units_of_side[team], 
									cost
								)
							) + 
							teams[team].gold 
						)
					) * 
					100
				) / 
				sum(
					map(
						enemies, 'team', 
						sum(
							map(
								units_of_side[team], 
								cost
							)
						) + 
						max(
							[teams[team].gold, 0]
						) 
					)
				)
			) / 2,
			100
		]
	);

# ==2== based on village possession #

def count_allied_villages(ai*)
	sum(
		map(
			allies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

def count_enemy_villages(ai*)
	sum(
		map(
			enemies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

# multipled by 1000 to increase precision #

def village_evaluation(ai*)
	(
		50000 + 
		(
			count_allied_villages(ai) - 
			count_enemy_villages(ai)
		) * 
		(
			50000 /
			size(
				villages
			)
		)
	) /
	1000;

# ==3== combined 2 of the above #

def eval(ai*)
	( 
		units_cost_gold_eval(ai) + 
		village_evaluation(ai)
	) / 
	2;

		#===== Evaluation how effective my units are against the enemy ===== #

#==1==  basic evaluation #

# evaluate how much damage unit can inflict - how much damage unit can get#

def evaluate_attacker_against_opponents(ai*, unit, enemy_units)
	sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( unit, enemy_unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				) 
			)
		)
	);

def evaluate_defender_against_opponents(ai*, unit, enemy_units)
	-sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( enemy_unit, unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				)
			)
		)
	);

def units_hp_map(ai*, units)
	tomap( 
		map(
			units, 
			id
		), 
		map( 
			units, 
			hitpoints
		)
	);

#in case side's gold is more than 50, add units that side can recruit to the side's unit list#

def create_side_unit_list(ai*, side)
	if( 
		teams[side].gold > 50, 
		recruits_of_side[side], 
		[]
	) + 
	units_of_side[side];

def evaluate_my_recruits_as_attackers(ai*)
	tomap( 
		map(
			my_recruits, 
			id
		), 
		map(
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_attacker_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai, 
							enemy_side
						)
					)
				)
			)
		)
	);

def evaluate_my_recruits_as_defenders(ai*)
	tomap(
		map(
			my_recruits, 
			id
		),
		map( 
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_defender_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai,
							enemy_side
						)
					)
				)
			)
		)
	);


# === 2 ===  now consider abilities and weapon specials  #

def abilities_weights()
	['skirmisher' -> 15, 'ambush' -> 10, 'nightstalk' -> 20, 'regenerates' -> 20, 'healing' -> 15, 'curing' -> 10, 'leadership' -> 20, 'illumination' -> 15, 'teleport' -> 10, 'steadfast' -> 15 ];

def weapon_specials_weights()
	[ 'backstab' -> 20 ,'slow' -> 10 ,'berserk' -> 20 ,'stones' -> 60 ,'plague' -> 10 ,'marksman' -> 30 ,'magical' -> 40 ,'charge' -> 30 ,'drains' -> 30,  'firststrike' -> 10, 'poison' -> 25 ];

def apply_abilities_weights( units_map )
	map( 
		units_map, 
		value +
		(
			value * 
			max(
				map(
					get_unit_type( key ).abilities, 'ability',
					abilities_weights()[ability]
				)
			)
		) / 100
	);

def apply_weapon_specials_weights( units_map )
	map(
		units_map, 
		value +
		(
			value *
			max(
				map(
					get_unit_type( key ).attacks, 'attack',
					vars.weapon_specials[attack.special]
				)
			)
		) / 100
	);

# since undead units don't get random traits and are balanced with that, we need to lower their evaluation a bit to match fairly the living units #

def undead_malus( units_map )
	map( 
		units_map, 
		if(
			get_unit_type(key).undead,
			( value * 90 ) / 100,
			value 
		)
	);

# === 3 ===  pit 1 and 2 together  #

def evaluate_attackers(ai*)
	change_numbers_to_percents(
		apply_abilities_weights(
			apply_weapon_specials_weights(
				undead_malus( 
					make_positive_only(
						evaluate_my_recruits_as_attackers( ai )	
					)
				)
			)
		)
	);

def evaluate_defenders(ai*)
	map(
		map(
			change_numbers_to_percents(
				apply_abilities_weights(
					apply_weapon_specials_weights(
						undead_malus( 
							make_positive_only(
								evaluate_my_recruits_as_defenders( ai )	
							)
						)
					)
				)
			),
			value / 3
		), 
		value +
		map(
			change_numbers_to_percents(
				units_hp_map(
					ai,
					my_recruits
				)
			),
		value * 2 / 3
		)[key]
	);

	#=========== we have evaluation of game state and units, time to combine them: ==========#
		#=========	recruitment_list_builder	=========#

def rlb_apply_eval(eval, attackers_map, defenders_map, offset)
	map(
		sumarize_maps_values(
			map(
				attackers_map, 
				value * (eval+offset)
			),
			map(
				defenders_map,
				value * ( (100 - eval) - offset )
			)
		),
		value / 100
	);

def rlb_remove_lowest( input_map, percent)
	filter(
		input_map, 
		value > 
		(
			(
				percent * sumarize_values(input_map)
			) / 100
		)
	);

def rlb_first_step(eval, attackers_map, defenders_map, offset)
	rlb_remove_lowest(
		rlb_apply_eval(
			eval,
			attackers_map,
			defenders_map,
			offset
		),
		10
	);

def recruitment_list_builder(eval, attackers_map, defenders_map)
	map(
		rlb_first_step(
			eval,
			attackers_map,
			defenders_map,
			40
		),
		(
			(
				value * 100
			) / 
			sumarize_values(
				rlb_first_step(
					eval,
					attackers_map,
					defenders_map,
					40
				)
			)
		)
	);

		# ========== choose the unit to recruit now ========= #

def unit_chooser(ai*,unit_map) 
	choose(
		keys(unit_map), 'unit_type',
		unit_map[unit_type] - 
		(
			(
				100 * 
				size(
					filter(
						my_units, 
						type = unit_type
					)
				)
			) / 
			size(my_units)
		)
	);

def unit_map_cost_filter(ai*, unit_map)
	filter( unit_map,
		get_unit_type(key).cost < my_side.gold
	);

		# ==========	Main formula section 	========== #

def initialize_weapon_specials_map(ai*)
	if(vars.weapon_specials_init != turn,
		[
			set_var('weapon_specials_init', turn),
			set_var('weapon_specials',
				map(
					weapon_specials_weights(),
					if( key = 'magical',
						units_average_defense(ai, enemy_units, 10),
						if( key = 'marksman',
							units_average_defense(ai, enemy_units, 10) - 10,
							value
						)
					)
				)
			)
		],
		[]
	);

def create_recruits_map(ai*)
	if(vars.recruits_map_creator != turn,
		[
			set_var('recruits_map_creator', turn ),
			set_var('recruits_map',
				debug_print('final unit evaluation: ', recruitment_list_builder(
					debug_print('current AI evaluation (0-100): ', eval(ai)),
					debug_print('attackers evaluation: ',evaluate_attackers(ai)),
					debug_print('defenders evaluation: ',evaluate_defenders(ai))
				))
			)
		],
		[]
	);

def castle_space(ai*)
	filter( map( castle_locs( my_leader.loc ), 'location', if( unit_at( location ), 1, 0 ) ), self = 0  ).size;

if(vars.turn_initialized = turn,
		if( my_leader.loc = nearest_keep( my_leader.loc ),
			if( 
				get_unit_type(
					choose(
						vars.recruits_map,
						-get_unit_type(key).cost
					).key
				).cost <
				my_side.gold,
				if( castle_space(self),
					recruit(debug_print(
						unit_chooser(
							self,
							unit_map_cost_filter(
								self,
								vars.recruits_map
							)
						)
					)),
					fallback()
				),
				fallback() 
			),
			if( my_leader.movement_left > 0,
				move( my_leader.loc, nearest_keep( my_leader.loc ) ),
				fallback()
			)
		),
	[set_var(debug_print('turn_initialized'), turn)] +
	initialize_weapon_specials_map(self) +
	create_recruits_map(self)
)

faiend
"
				[/team_formula]
			[/ai]
		[/multiplayer_side]
		[multiplayer_side]
			flag_rgb="magenta"
			id="Undead"
			image="units/undead-necromancers/dark-sorcerer.png"
			leader="Dark Sorcerer,Revenant,Deathblade,Bone Shooter,Necrophage"
			name=_ "Undead"
			random_leader="Dark Sorcerer,Revenant,Deathblade,Bone Shooter"
			recruit="Skeleton,Skeleton Archer,Walking Corpse,Ghost,Vampire Bat,Dark Adept,Ghoul"
			terrain_liked="Ss, Hh, Ha, Ww"
			type="Dark Sorcerer"
			[ai]
				recruitment_pattern="fighter,fighter,archer,fighter,scout,archer"
				[team_formula]
					rulebase="fai 'recruitment.fai'
		# ===== Some general functions used later ==== #

def sumarize_values( input_map )
	sum(
		values(input_map)
	);

def lowest_value( input_map )
	choose( input_map, -value ).value;

def highest_value( input_map )
	choose( input_map, value ).value;

def change_numbers_to_percents( input_map )
	map( input_map, 
		(value*100) / highest_value(input_map) 
	);

def add_number_to_values( input_map, number )
	map( input_map, 
		value + number 
	);

#make sure we have only positive values in a map #

def make_positive_only( input_map )
	if( lowest_value( input_map ) < 0, 
		add_number_to_values( 
			input_map, 
			abs(lowest_value(input_map))
		), 
		input_map 
	);

def sumarize_maps_values( map_A, map_B )
	map( map_A + map_B, 
		value + map_A[key]
	);

		#===== Evaluation how good unit is on a map ===== #

# ==1==  evaluate average defense #
#gives map where key is id of terrain, and value is number of hexes of that terrain on a gamemap#

def locations_map(ai*) 
	tomap( 
		map( 
			map.terrain, 
			id 
		) 
	);

#filters terrain map, min_percent it minimal % of map that terrain has to occupy to be considered in later evaluations# 

def filtered_locations_map(ai*, min_percent)
	filter( 
		locations_map(ai) , 
		value >  (map.w * map.h) / ( 100 / min_percent ) 
	);

#returns average defense of the unit #

def unit_average_defense(ai*, unit, terrain_min_percent )
	sum( 
		values( 
			map(
				filtered_locations_map(ai,terrain_min_percent), 
				defense_on( 
					unit, 
					find(map.terrain,id=key).loc
				) *
				value
			) 
		) 
	) / 
	sum(
		values(
			filtered_locations_map(
				ai,
				terrain_min_percent
			)
		)
	);

#returns map of units from units_list and their average defense (more -> better) #

def map_units_average_defense(ai*, units_list, terrain_min_percent) 
	tomap(
		map( 
			units_list, 
			id 
		), 
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	);

def units_average_defense(ai*, units_list, terrain_min_percent)
	sum(
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	) /
	size(
		units_list
	);


# ==2== TODO: evaluate unit effectivness based on movement points and movement cost#


		#===== Evaluation of game state - how good is ai doing ===== #

# ==1== based on unit cost and current amount of gold #
# returns number between 0 and 100 where: 0 we are losing, 100 we are winning #

def units_cost_gold_eval(ai*)
	min(
		[
			(
				(
					sum(
						map(
							allies, 'team', 
							sum(
								map(
									units_of_side[team], 
									cost
								)
							) + 
							teams[team].gold 
						)
					) * 
					100
				) / 
				sum(
					map(
						enemies, 'team', 
						sum(
							map(
								units_of_side[team], 
								cost
							)
						) + 
						max(
							[teams[team].gold, 0]
						) 
					)
				)
			) / 2,
			100
		]
	);

# ==2== based on village possession #

def count_allied_villages(ai*)
	sum(
		map(
			allies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

def count_enemy_villages(ai*)
	sum(
		map(
			enemies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

# multipled by 1000 to increase precision #

def village_evaluation(ai*)
	(
		50000 + 
		(
			count_allied_villages(ai) - 
			count_enemy_villages(ai)
		) * 
		(
			50000 /
			size(
				villages
			)
		)
	) /
	1000;

# ==3== combined 2 of the above #

def eval(ai*)
	( 
		units_cost_gold_eval(ai) + 
		village_evaluation(ai)
	) / 
	2;

		#===== Evaluation how effective my units are against the enemy ===== #

#==1==  basic evaluation #

# evaluate how much damage unit can inflict - how much damage unit can get#

def evaluate_attacker_against_opponents(ai*, unit, enemy_units)
	sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( unit, enemy_unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				) 
			)
		)
	);

def evaluate_defender_against_opponents(ai*, unit, enemy_units)
	-sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( enemy_unit, unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				)
			)
		)
	);

def units_hp_map(ai*, units)
	tomap( 
		map(
			units, 
			id
		), 
		map( 
			units, 
			hitpoints
		)
	);

#in case side's gold is more than 50, add units that side can recruit to the side's unit list#

def create_side_unit_list(ai*, side)
	if( 
		teams[side].gold > 50, 
		recruits_of_side[side], 
		[]
	) + 
	units_of_side[side];

def evaluate_my_recruits_as_attackers(ai*)
	tomap( 
		map(
			my_recruits, 
			id
		), 
		map(
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_attacker_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai, 
							enemy_side
						)
					)
				)
			)
		)
	);

def evaluate_my_recruits_as_defenders(ai*)
	tomap(
		map(
			my_recruits, 
			id
		),
		map( 
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_defender_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai,
							enemy_side
						)
					)
				)
			)
		)
	);


# === 2 ===  now consider abilities and weapon specials  #

def abilities_weights()
	['skirmisher' -> 15, 'ambush' -> 10, 'nightstalk' -> 20, 'regenerates' -> 20, 'healing' -> 15, 'curing' -> 10, 'leadership' -> 20, 'illumination' -> 15, 'teleport' -> 10, 'steadfast' -> 15 ];

def weapon_specials_weights()
	[ 'backstab' -> 20 ,'slow' -> 10 ,'berserk' -> 20 ,'stones' -> 60 ,'plague' -> 10 ,'marksman' -> 30 ,'magical' -> 40 ,'charge' -> 30 ,'drains' -> 30,  'firststrike' -> 10, 'poison' -> 25 ];

def apply_abilities_weights( units_map )
	map( 
		units_map, 
		value +
		(
			value * 
			max(
				map(
					get_unit_type( key ).abilities, 'ability',
					abilities_weights()[ability]
				)
			)
		) / 100
	);

def apply_weapon_specials_weights( units_map )
	map(
		units_map, 
		value +
		(
			value *
			max(
				map(
					get_unit_type( key ).attacks, 'attack',
					vars.weapon_specials[attack.special]
				)
			)
		) / 100
	);

# since undead units don't get random traits and are balanced with that, we need to lower their evaluation a bit to match fairly the living units #

def undead_malus( units_map )
	map( 
		units_map, 
		if(
			get_unit_type(key).undead,
			( value * 90 ) / 100,
			value 
		)
	);

# === 3 ===  pit 1 and 2 together  #

def evaluate_attackers(ai*)
	change_numbers_to_percents(
		apply_abilities_weights(
			apply_weapon_specials_weights(
				undead_malus( 
					make_positive_only(
						evaluate_my_recruits_as_attackers( ai )	
					)
				)
			)
		)
	);

def evaluate_defenders(ai*)
	map(
		map(
			change_numbers_to_percents(
				apply_abilities_weights(
					apply_weapon_specials_weights(
						undead_malus( 
							make_positive_only(
								evaluate_my_recruits_as_defenders( ai )	
							)
						)
					)
				)
			),
			value / 3
		), 
		value +
		map(
			change_numbers_to_percents(
				units_hp_map(
					ai,
					my_recruits
				)
			),
		value * 2 / 3
		)[key]
	);

	#=========== we have evaluation of game state and units, time to combine them: ==========#
		#=========	recruitment_list_builder	=========#

def rlb_apply_eval(eval, attackers_map, defenders_map, offset)
	map(
		sumarize_maps_values(
			map(
				attackers_map, 
				value * (eval+offset)
			),
			map(
				defenders_map,
				value * ( (100 - eval) - offset )
			)
		),
		value / 100
	);

def rlb_remove_lowest( input_map, percent)
	filter(
		input_map, 
		value > 
		(
			(
				percent * sumarize_values(input_map)
			) / 100
		)
	);

def rlb_first_step(eval, attackers_map, defenders_map, offset)
	rlb_remove_lowest(
		rlb_apply_eval(
			eval,
			attackers_map,
			defenders_map,
			offset
		),
		10
	);

def recruitment_list_builder(eval, attackers_map, defenders_map)
	map(
		rlb_first_step(
			eval,
			attackers_map,
			defenders_map,
			40
		),
		(
			(
				value * 100
			) / 
			sumarize_values(
				rlb_first_step(
					eval,
					attackers_map,
					defenders_map,
					40
				)
			)
		)
	);

		# ========== choose the unit to recruit now ========= #

def unit_chooser(ai*,unit_map) 
	choose(
		keys(unit_map), 'unit_type',
		unit_map[unit_type] - 
		(
			(
				100 * 
				size(
					filter(
						my_units, 
						type = unit_type
					)
				)
			) / 
			size(my_units)
		)
	);

def unit_map_cost_filter(ai*, unit_map)
	filter( unit_map,
		get_unit_type(key).cost < my_side.gold
	);

		# ==========	Main formula section 	========== #

def initialize_weapon_specials_map(ai*)
	if(vars.weapon_specials_init != turn,
		[
			set_var('weapon_specials_init', turn),
			set_var('weapon_specials',
				map(
					weapon_specials_weights(),
					if( key = 'magical',
						units_average_defense(ai, enemy_units, 10),
						if( key = 'marksman',
							units_average_defense(ai, enemy_units, 10) - 10,
							value
						)
					)
				)
			)
		],
		[]
	);

def create_recruits_map(ai*)
	if(vars.recruits_map_creator != turn,
		[
			set_var('recruits_map_creator', turn ),
			set_var('recruits_map',
				debug_print('final unit evaluation: ', recruitment_list_builder(
					debug_print('current AI evaluation (0-100): ', eval(ai)),
					debug_print('attackers evaluation: ',evaluate_attackers(ai)),
					debug_print('defenders evaluation: ',evaluate_defenders(ai))
				))
			)
		],
		[]
	);

def castle_space(ai*)
	filter( map( castle_locs( my_leader.loc ), 'location', if( unit_at( location ), 1, 0 ) ), self = 0  ).size;

if(vars.turn_initialized = turn,
		if( my_leader.loc = nearest_keep( my_leader.loc ),
			if( 
				get_unit_type(
					choose(
						vars.recruits_map,
						-get_unit_type(key).cost
					).key
				).cost <
				my_side.gold,
				if( castle_space(self),
					recruit(debug_print(
						unit_chooser(
							self,
							unit_map_cost_filter(
								self,
								vars.recruits_map
							)
						)
					)),
					fallback()
				),
				fallback() 
			),
			if( my_leader.movement_left > 0,
				move( my_leader.loc, nearest_keep( my_leader.loc ) ),
				fallback()
			)
		),
	[set_var(debug_print('turn_initialized'), turn)] +
	initialize_weapon_specials_map(self) +
	create_recruits_map(self)
)

faiend
"
				[/team_formula]
			[/ai]
		[/multiplayer_side]
		[multiplayer_side]
			flag_rgb="magenta"
			id="Knalgan Alliance"
			image="units/dwarves/steelclad.png"
			leader="Dwarvish Steelclad,Dwarvish Thunderguard,Dwarvish Stalwart,Rogue,Trapper"
			name=_ "Knalgan Alliance"
			random_leader="Dwarvish Steelclad,Dwarvish Thunderguard,Rogue,Trapper"
			recruit="Dwarvish Guardsman,Dwarvish Fighter,Dwarvish Ulfserker,Dwarvish Thunderer,Thief,Poacher,Footpad,Gryphon Rider"
			terrain_liked="Hh, Ha, Mm"
			type="Dwarvish Steelclad"
			[ai]
				recruitment_pattern="fighter,fighter,fighter,mixed fighter,archer,scout"
				[team_formula]
					rulebase="fai 'recruitment.fai'
		# ===== Some general functions used later ==== #

def sumarize_values( input_map )
	sum(
		values(input_map)
	);

def lowest_value( input_map )
	choose( input_map, -value ).value;

def highest_value( input_map )
	choose( input_map, value ).value;

def change_numbers_to_percents( input_map )
	map( input_map, 
		(value*100) / highest_value(input_map) 
	);

def add_number_to_values( input_map, number )
	map( input_map, 
		value + number 
	);

#make sure we have only positive values in a map #

def make_positive_only( input_map )
	if( lowest_value( input_map ) < 0, 
		add_number_to_values( 
			input_map, 
			abs(lowest_value(input_map))
		), 
		input_map 
	);

def sumarize_maps_values( map_A, map_B )
	map( map_A + map_B, 
		value + map_A[key]
	);

		#===== Evaluation how good unit is on a map ===== #

# ==1==  evaluate average defense #
#gives map where key is id of terrain, and value is number of hexes of that terrain on a gamemap#

def locations_map(ai*) 
	tomap( 
		map( 
			map.terrain, 
			id 
		) 
	);

#filters terrain map, min_percent it minimal % of map that terrain has to occupy to be considered in later evaluations# 

def filtered_locations_map(ai*, min_percent)
	filter( 
		locations_map(ai) , 
		value >  (map.w * map.h) / ( 100 / min_percent ) 
	);

#returns average defense of the unit #

def unit_average_defense(ai*, unit, terrain_min_percent )
	sum( 
		values( 
			map(
				filtered_locations_map(ai,terrain_min_percent), 
				defense_on( 
					unit, 
					find(map.terrain,id=key).loc
				) *
				value
			) 
		) 
	) / 
	sum(
		values(
			filtered_locations_map(
				ai,
				terrain_min_percent
			)
		)
	);

#returns map of units from units_list and their average defense (more -> better) #

def map_units_average_defense(ai*, units_list, terrain_min_percent) 
	tomap(
		map( 
			units_list, 
			id 
		), 
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	);

def units_average_defense(ai*, units_list, terrain_min_percent)
	sum(
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	) /
	size(
		units_list
	);


# ==2== TODO: evaluate unit effectivness based on movement points and movement cost#


		#===== Evaluation of game state - how good is ai doing ===== #

# ==1== based on unit cost and current amount of gold #
# returns number between 0 and 100 where: 0 we are losing, 100 we are winning #

def units_cost_gold_eval(ai*)
	min(
		[
			(
				(
					sum(
						map(
							allies, 'team', 
							sum(
								map(
									units_of_side[team], 
									cost
								)
							) + 
							teams[team].gold 
						)
					) * 
					100
				) / 
				sum(
					map(
						enemies, 'team', 
						sum(
							map(
								units_of_side[team], 
								cost
							)
						) + 
						max(
							[teams[team].gold, 0]
						) 
					)
				)
			) / 2,
			100
		]
	);

# ==2== based on village possession #

def count_allied_villages(ai*)
	sum(
		map(
			allies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

def count_enemy_villages(ai*)
	sum(
		map(
			enemies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

# multipled by 1000 to increase precision #

def village_evaluation(ai*)
	(
		50000 + 
		(
			count_allied_villages(ai) - 
			count_enemy_villages(ai)
		) * 
		(
			50000 /
			size(
				villages
			)
		)
	) /
	1000;

# ==3== combined 2 of the above #

def eval(ai*)
	( 
		units_cost_gold_eval(ai) + 
		village_evaluation(ai)
	) / 
	2;

		#===== Evaluation how effective my units are against the enemy ===== #

#==1==  basic evaluation #

# evaluate how much damage unit can inflict - how much damage unit can get#

def evaluate_attacker_against_opponents(ai*, unit, enemy_units)
	sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( unit, enemy_unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				) 
			)
		)
	);

def evaluate_defender_against_opponents(ai*, unit, enemy_units)
	-sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( enemy_unit, unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				)
			)
		)
	);

def units_hp_map(ai*, units)
	tomap( 
		map(
			units, 
			id
		), 
		map( 
			units, 
			hitpoints
		)
	);

#in case side's gold is more than 50, add units that side can recruit to the side's unit list#

def create_side_unit_list(ai*, side)
	if( 
		teams[side].gold > 50, 
		recruits_of_side[side], 
		[]
	) + 
	units_of_side[side];

def evaluate_my_recruits_as_attackers(ai*)
	tomap( 
		map(
			my_recruits, 
			id
		), 
		map(
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_attacker_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai, 
							enemy_side
						)
					)
				)
			)
		)
	);

def evaluate_my_recruits_as_defenders(ai*)
	tomap(
		map(
			my_recruits, 
			id
		),
		map( 
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_defender_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai,
							enemy_side
						)
					)
				)
			)
		)
	);


# === 2 ===  now consider abilities and weapon specials  #

def abilities_weights()
	['skirmisher' -> 15, 'ambush' -> 10, 'nightstalk' -> 20, 'regenerates' -> 20, 'healing' -> 15, 'curing' -> 10, 'leadership' -> 20, 'illumination' -> 15, 'teleport' -> 10, 'steadfast' -> 15 ];

def weapon_specials_weights()
	[ 'backstab' -> 20 ,'slow' -> 10 ,'berserk' -> 20 ,'stones' -> 60 ,'plague' -> 10 ,'marksman' -> 30 ,'magical' -> 40 ,'charge' -> 30 ,'drains' -> 30,  'firststrike' -> 10, 'poison' -> 25 ];

def apply_abilities_weights( units_map )
	map( 
		units_map, 
		value +
		(
			value * 
			max(
				map(
					get_unit_type( key ).abilities, 'ability',
					abilities_weights()[ability]
				)
			)
		) / 100
	);

def apply_weapon_specials_weights( units_map )
	map(
		units_map, 
		value +
		(
			value *
			max(
				map(
					get_unit_type( key ).attacks, 'attack',
					vars.weapon_specials[attack.special]
				)
			)
		) / 100
	);

# since undead units don't get random traits and are balanced with that, we need to lower their evaluation a bit to match fairly the living units #

def undead_malus( units_map )
	map( 
		units_map, 
		if(
			get_unit_type(key).undead,
			( value * 90 ) / 100,
			value 
		)
	);

# === 3 ===  pit 1 and 2 together  #

def evaluate_attackers(ai*)
	change_numbers_to_percents(
		apply_abilities_weights(
			apply_weapon_specials_weights(
				undead_malus( 
					make_positive_only(
						evaluate_my_recruits_as_attackers( ai )	
					)
				)
			)
		)
	);

def evaluate_defenders(ai*)
	map(
		map(
			change_numbers_to_percents(
				apply_abilities_weights(
					apply_weapon_specials_weights(
						undead_malus( 
							make_positive_only(
								evaluate_my_recruits_as_defenders( ai )	
							)
						)
					)
				)
			),
			value / 3
		), 
		value +
		map(
			change_numbers_to_percents(
				units_hp_map(
					ai,
					my_recruits
				)
			),
		value * 2 / 3
		)[key]
	);

	#=========== we have evaluation of game state and units, time to combine them: ==========#
		#=========	recruitment_list_builder	=========#

def rlb_apply_eval(eval, attackers_map, defenders_map, offset)
	map(
		sumarize_maps_values(
			map(
				attackers_map, 
				value * (eval+offset)
			),
			map(
				defenders_map,
				value * ( (100 - eval) - offset )
			)
		),
		value / 100
	);

def rlb_remove_lowest( input_map, percent)
	filter(
		input_map, 
		value > 
		(
			(
				percent * sumarize_values(input_map)
			) / 100
		)
	);

def rlb_first_step(eval, attackers_map, defenders_map, offset)
	rlb_remove_lowest(
		rlb_apply_eval(
			eval,
			attackers_map,
			defenders_map,
			offset
		),
		10
	);

def recruitment_list_builder(eval, attackers_map, defenders_map)
	map(
		rlb_first_step(
			eval,
			attackers_map,
			defenders_map,
			40
		),
		(
			(
				value * 100
			) / 
			sumarize_values(
				rlb_first_step(
					eval,
					attackers_map,
					defenders_map,
					40
				)
			)
		)
	);

		# ========== choose the unit to recruit now ========= #

def unit_chooser(ai*,unit_map) 
	choose(
		keys(unit_map), 'unit_type',
		unit_map[unit_type] - 
		(
			(
				100 * 
				size(
					filter(
						my_units, 
						type = unit_type
					)
				)
			) / 
			size(my_units)
		)
	);

def unit_map_cost_filter(ai*, unit_map)
	filter( unit_map,
		get_unit_type(key).cost < my_side.gold
	);

		# ==========	Main formula section 	========== #

def initialize_weapon_specials_map(ai*)
	if(vars.weapon_specials_init != turn,
		[
			set_var('weapon_specials_init', turn),
			set_var('weapon_specials',
				map(
					weapon_specials_weights(),
					if( key = 'magical',
						units_average_defense(ai, enemy_units, 10),
						if( key = 'marksman',
							units_average_defense(ai, enemy_units, 10) - 10,
							value
						)
					)
				)
			)
		],
		[]
	);

def create_recruits_map(ai*)
	if(vars.recruits_map_creator != turn,
		[
			set_var('recruits_map_creator', turn ),
			set_var('recruits_map',
				debug_print('final unit evaluation: ', recruitment_list_builder(
					debug_print('current AI evaluation (0-100): ', eval(ai)),
					debug_print('attackers evaluation: ',evaluate_attackers(ai)),
					debug_print('defenders evaluation: ',evaluate_defenders(ai))
				))
			)
		],
		[]
	);

def castle_space(ai*)
	filter( map( castle_locs( my_leader.loc ), 'location', if( unit_at( location ), 1, 0 ) ), self = 0  ).size;

if(vars.turn_initialized = turn,
		if( my_leader.loc = nearest_keep( my_leader.loc ),
			if( 
				get_unit_type(
					choose(
						vars.recruits_map,
						-get_unit_type(key).cost
					).key
				).cost <
				my_side.gold,
				if( castle_space(self),
					recruit(debug_print(
						unit_chooser(
							self,
							unit_map_cost_filter(
								self,
								vars.recruits_map
							)
						)
					)),
					fallback()
				),
				fallback() 
			),
			if( my_leader.movement_left > 0,
				move( my_leader.loc, nearest_keep( my_leader.loc ) ),
				fallback()
			)
		),
	[set_var(debug_print('turn_initialized'), turn)] +
	initialize_weapon_specials_map(self) +
	create_recruits_map(self)
)

faiend
"
				[/team_formula]
			[/ai]
		[/multiplayer_side]
		[multiplayer_side]
			flag_rgb="magenta"
			id="Drakes"
			image="units/drakes/flare.png"
			leader="Drake Flare,Fire Drake,Drake Slasher,Drake Gladiator,Drake Warrior,Saurian Oracle,Saurian Soothsayer"
			name=_ "Drakes"
			random_leader="Drake Flare,Fire Drake,Drake Slasher,Drake Gladiator,Drake Warrior"
			recruit="Drake Burner,Drake Clasher,Drake Glider,Drake Fighter,Saurian Skirmisher,Saurian Augur"
			terrain_liked="Hh, Ha, Ds, Ss"
			type="Drake Flare"
			[ai]
				recruitment_pattern="fighter,fighter,archer,healer,scout,scout"
				[team_formula]
					rulebase="fai 'recruitment.fai'
		# ===== Some general functions used later ==== #

def sumarize_values( input_map )
	sum(
		values(input_map)
	);

def lowest_value( input_map )
	choose( input_map, -value ).value;

def highest_value( input_map )
	choose( input_map, value ).value;

def change_numbers_to_percents( input_map )
	map( input_map, 
		(value*100) / highest_value(input_map) 
	);

def add_number_to_values( input_map, number )
	map( input_map, 
		value + number 
	);

#make sure we have only positive values in a map #

def make_positive_only( input_map )
	if( lowest_value( input_map ) < 0, 
		add_number_to_values( 
			input_map, 
			abs(lowest_value(input_map))
		), 
		input_map 
	);

def sumarize_maps_values( map_A, map_B )
	map( map_A + map_B, 
		value + map_A[key]
	);

		#===== Evaluation how good unit is on a map ===== #

# ==1==  evaluate average defense #
#gives map where key is id of terrain, and value is number of hexes of that terrain on a gamemap#

def locations_map(ai*) 
	tomap( 
		map( 
			map.terrain, 
			id 
		) 
	);

#filters terrain map, min_percent it minimal % of map that terrain has to occupy to be considered in later evaluations# 

def filtered_locations_map(ai*, min_percent)
	filter( 
		locations_map(ai) , 
		value >  (map.w * map.h) / ( 100 / min_percent ) 
	);

#returns average defense of the unit #

def unit_average_defense(ai*, unit, terrain_min_percent )
	sum( 
		values( 
			map(
				filtered_locations_map(ai,terrain_min_percent), 
				defense_on( 
					unit, 
					find(map.terrain,id=key).loc
				) *
				value
			) 
		) 
	) / 
	sum(
		values(
			filtered_locations_map(
				ai,
				terrain_min_percent
			)
		)
	);

#returns map of units from units_list and their average defense (more -> better) #

def map_units_average_defense(ai*, units_list, terrain_min_percent) 
	tomap(
		map( 
			units_list, 
			id 
		), 
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	);

def units_average_defense(ai*, units_list, terrain_min_percent)
	sum(
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	) /
	size(
		units_list
	);


# ==2== TODO: evaluate unit effectivness based on movement points and movement cost#


		#===== Evaluation of game state - how good is ai doing ===== #

# ==1== based on unit cost and current amount of gold #
# returns number between 0 and 100 where: 0 we are losing, 100 we are winning #

def units_cost_gold_eval(ai*)
	min(
		[
			(
				(
					sum(
						map(
							allies, 'team', 
							sum(
								map(
									units_of_side[team], 
									cost
								)
							) + 
							teams[team].gold 
						)
					) * 
					100
				) / 
				sum(
					map(
						enemies, 'team', 
						sum(
							map(
								units_of_side[team], 
								cost
							)
						) + 
						max(
							[teams[team].gold, 0]
						) 
					)
				)
			) / 2,
			100
		]
	);

# ==2== based on village possession #

def count_allied_villages(ai*)
	sum(
		map(
			allies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

def count_enemy_villages(ai*)
	sum(
		map(
			enemies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

# multipled by 1000 to increase precision #

def village_evaluation(ai*)
	(
		50000 + 
		(
			count_allied_villages(ai) - 
			count_enemy_villages(ai)
		) * 
		(
			50000 /
			size(
				villages
			)
		)
	) /
	1000;

# ==3== combined 2 of the above #

def eval(ai*)
	( 
		units_cost_gold_eval(ai) + 
		village_evaluation(ai)
	) / 
	2;

		#===== Evaluation how effective my units are against the enemy ===== #

#==1==  basic evaluation #

# evaluate how much damage unit can inflict - how much damage unit can get#

def evaluate_attacker_against_opponents(ai*, unit, enemy_units)
	sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( unit, enemy_unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				) 
			)
		)
	);

def evaluate_defender_against_opponents(ai*, unit, enemy_units)
	-sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( enemy_unit, unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				)
			)
		)
	);

def units_hp_map(ai*, units)
	tomap( 
		map(
			units, 
			id
		), 
		map( 
			units, 
			hitpoints
		)
	);

#in case side's gold is more than 50, add units that side can recruit to the side's unit list#

def create_side_unit_list(ai*, side)
	if( 
		teams[side].gold > 50, 
		recruits_of_side[side], 
		[]
	) + 
	units_of_side[side];

def evaluate_my_recruits_as_attackers(ai*)
	tomap( 
		map(
			my_recruits, 
			id
		), 
		map(
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_attacker_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai, 
							enemy_side
						)
					)
				)
			)
		)
	);

def evaluate_my_recruits_as_defenders(ai*)
	tomap(
		map(
			my_recruits, 
			id
		),
		map( 
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_defender_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai,
							enemy_side
						)
					)
				)
			)
		)
	);


# === 2 ===  now consider abilities and weapon specials  #

def abilities_weights()
	['skirmisher' -> 15, 'ambush' -> 10, 'nightstalk' -> 20, 'regenerates' -> 20, 'healing' -> 15, 'curing' -> 10, 'leadership' -> 20, 'illumination' -> 15, 'teleport' -> 10, 'steadfast' -> 15 ];

def weapon_specials_weights()
	[ 'backstab' -> 20 ,'slow' -> 10 ,'berserk' -> 20 ,'stones' -> 60 ,'plague' -> 10 ,'marksman' -> 30 ,'magical' -> 40 ,'charge' -> 30 ,'drains' -> 30,  'firststrike' -> 10, 'poison' -> 25 ];

def apply_abilities_weights( units_map )
	map( 
		units_map, 
		value +
		(
			value * 
			max(
				map(
					get_unit_type( key ).abilities, 'ability',
					abilities_weights()[ability]
				)
			)
		) / 100
	);

def apply_weapon_specials_weights( units_map )
	map(
		units_map, 
		value +
		(
			value *
			max(
				map(
					get_unit_type( key ).attacks, 'attack',
					vars.weapon_specials[attack.special]
				)
			)
		) / 100
	);

# since undead units don't get random traits and are balanced with that, we need to lower their evaluation a bit to match fairly the living units #

def undead_malus( units_map )
	map( 
		units_map, 
		if(
			get_unit_type(key).undead,
			( value * 90 ) / 100,
			value 
		)
	);

# === 3 ===  pit 1 and 2 together  #

def evaluate_attackers(ai*)
	change_numbers_to_percents(
		apply_abilities_weights(
			apply_weapon_specials_weights(
				undead_malus( 
					make_positive_only(
						evaluate_my_recruits_as_attackers( ai )	
					)
				)
			)
		)
	);

def evaluate_defenders(ai*)
	map(
		map(
			change_numbers_to_percents(
				apply_abilities_weights(
					apply_weapon_specials_weights(
						undead_malus( 
							make_positive_only(
								evaluate_my_recruits_as_defenders( ai )	
							)
						)
					)
				)
			),
			value / 3
		), 
		value +
		map(
			change_numbers_to_percents(
				units_hp_map(
					ai,
					my_recruits
				)
			),
		value * 2 / 3
		)[key]
	);

	#=========== we have evaluation of game state and units, time to combine them: ==========#
		#=========	recruitment_list_builder	=========#

def rlb_apply_eval(eval, attackers_map, defenders_map, offset)
	map(
		sumarize_maps_values(
			map(
				attackers_map, 
				value * (eval+offset)
			),
			map(
				defenders_map,
				value * ( (100 - eval) - offset )
			)
		),
		value / 100
	);

def rlb_remove_lowest( input_map, percent)
	filter(
		input_map, 
		value > 
		(
			(
				percent * sumarize_values(input_map)
			) / 100
		)
	);

def rlb_first_step(eval, attackers_map, defenders_map, offset)
	rlb_remove_lowest(
		rlb_apply_eval(
			eval,
			attackers_map,
			defenders_map,
			offset
		),
		10
	);

def recruitment_list_builder(eval, attackers_map, defenders_map)
	map(
		rlb_first_step(
			eval,
			attackers_map,
			defenders_map,
			40
		),
		(
			(
				value * 100
			) / 
			sumarize_values(
				rlb_first_step(
					eval,
					attackers_map,
					defenders_map,
					40
				)
			)
		)
	);

		# ========== choose the unit to recruit now ========= #

def unit_chooser(ai*,unit_map) 
	choose(
		keys(unit_map), 'unit_type',
		unit_map[unit_type] - 
		(
			(
				100 * 
				size(
					filter(
						my_units, 
						type = unit_type
					)
				)
			) / 
			size(my_units)
		)
	);

def unit_map_cost_filter(ai*, unit_map)
	filter( unit_map,
		get_unit_type(key).cost < my_side.gold
	);

		# ==========	Main formula section 	========== #

def initialize_weapon_specials_map(ai*)
	if(vars.weapon_specials_init != turn,
		[
			set_var('weapon_specials_init', turn),
			set_var('weapon_specials',
				map(
					weapon_specials_weights(),
					if( key = 'magical',
						units_average_defense(ai, enemy_units, 10),
						if( key = 'marksman',
							units_average_defense(ai, enemy_units, 10) - 10,
							value
						)
					)
				)
			)
		],
		[]
	);

def create_recruits_map(ai*)
	if(vars.recruits_map_creator != turn,
		[
			set_var('recruits_map_creator', turn ),
			set_var('recruits_map',
				debug_print('final unit evaluation: ', recruitment_list_builder(
					debug_print('current AI evaluation (0-100): ', eval(ai)),
					debug_print('attackers evaluation: ',evaluate_attackers(ai)),
					debug_print('defenders evaluation: ',evaluate_defenders(ai))
				))
			)
		],
		[]
	);

def castle_space(ai*)
	filter( map( castle_locs( my_leader.loc ), 'location', if( unit_at( location ), 1, 0 ) ), self = 0  ).size;

if(vars.turn_initialized = turn,
		if( my_leader.loc = nearest_keep( my_leader.loc ),
			if( 
				get_unit_type(
					choose(
						vars.recruits_map,
						-get_unit_type(key).cost
					).key
				).cost <
				my_side.gold,
				if( castle_space(self),
					recruit(debug_print(
						unit_chooser(
							self,
							unit_map_cost_filter(
								self,
								vars.recruits_map
							)
						)
					)),
					fallback()
				),
				fallback() 
			),
			if( my_leader.movement_left > 0,
				move( my_leader.loc, nearest_keep( my_leader.loc ) ),
				fallback()
			)
		),
	[set_var(debug_print('turn_initialized'), turn)] +
	initialize_weapon_specials_map(self) +
	create_recruits_map(self)
)

faiend
"
				[/team_formula]
			[/ai]
		[/multiplayer_side]
		[event]
			name="prestart"
			[store_unit]
				kill="yes"
				variable="leaders_to_make_quick"
				[filter]
					canrecruit="yes"
					[filter_wml]
						max_moves="4"
					[/filter_wml]
				[/filter]
			[/store_unit]
			[set_variable]
				name="i"
				value="0"
			[/set_variable]
			[while]
				[variable]
					less_than="$leaders_to_make_quick.length"
					name="i"
				[/variable]
				[do]
					[set_variables]
						mode="merge"
						name="leaders_to_make_quick[$i].modifications"
						[literal]
							[trait]
#textdomain wesnoth
								female_name=_ "female^quick"
								id="quick"
								male_name=_ "quick"
								[effect]
									apply_to="movement"
									increase="1"
								[/effect]
								[effect]
									apply_to="hitpoints"
									increase_total="-5%"
								[/effect]
							[/trait]
						[/literal]
					[/set_variables]
					[clear_variable]
						name="leaders_to_make_quick[$i].max_moves,leaders_to_make_quick[$i].moves,leaders_to_make_quick[$i].max_hitpoints,leaders_to_make_quick[$i].hitpoints"
					[/clear_variable]
					[unstore_unit]
						variable="leaders_to_make_quick[$i]"
					[/unstore_unit]
					[set_variable]
						add="1"
						name="i"
					[/set_variable]
				[/do]
			[/while]
			[clear_variable]
				name="i"
			[/clear_variable]
			[clear_variable]
				name="leaders_to_make_quick"
			[/clear_variable]
		[/event]
	[/era]
	[side]
		allow_changes="yes"
		allow_player="yes"
		canrecruit="yes"
		colour="1"
		controller="human"
		current_player="Yawner"
		flag_rgb="magenta"
		fog="yes"
		gender="male"
		gold="100"
		id="Yawner1"
		image="units/dwarves/steelclad.png"
		income="0"
		leader="Dwarvish Steelclad,Dwarvish Thunderguard,Dwarvish Stalwart,Rogue,Trapper"
		mp_countdown="yes"
		mp_countdown_action_bonus="10"
		mp_countdown_init_time="180"
		mp_countdown_reservoir_time="240"
		mp_countdown_turn_bonus="45"
		name="Yawner"
		random_leader="Dwarvish Steelclad,Dwarvish Thunderguard,Rogue,Trapper"
		recruit="Dwarvish Guardsman,Dwarvish Fighter,Dwarvish Ulfserker,Dwarvish Thunderer,Thief,Poacher,Footpad,Gryphon Rider"
		save_id="Yawner1"
		share_maps="no"
		share_view="yes"
		shroud="no"
		side="1"
		team_name="south"
		terrain_liked="Hh, Ha, Mm"
		type="Rogue"
		user_team_name="wesnoth-multiplayerteamname^South"
		village_gold="2"
		[ai]
			recruitment_pattern="fighter,fighter,fighter,mixed fighter,archer,scout"
			villages_per_scout="8"
			[team_formula]
				rulebase="fai 'recruitment.fai'
		# ===== Some general functions used later ==== #

def sumarize_values( input_map )
	sum(
		values(input_map)
	);

def lowest_value( input_map )
	choose( input_map, -value ).value;

def highest_value( input_map )
	choose( input_map, value ).value;

def change_numbers_to_percents( input_map )
	map( input_map, 
		(value*100) / highest_value(input_map) 
	);

def add_number_to_values( input_map, number )
	map( input_map, 
		value + number 
	);

#make sure we have only positive values in a map #

def make_positive_only( input_map )
	if( lowest_value( input_map ) < 0, 
		add_number_to_values( 
			input_map, 
			abs(lowest_value(input_map))
		), 
		input_map 
	);

def sumarize_maps_values( map_A, map_B )
	map( map_A + map_B, 
		value + map_A[key]
	);

		#===== Evaluation how good unit is on a map ===== #

# ==1==  evaluate average defense #
#gives map where key is id of terrain, and value is number of hexes of that terrain on a gamemap#

def locations_map(ai*) 
	tomap( 
		map( 
			map.terrain, 
			id 
		) 
	);

#filters terrain map, min_percent it minimal % of map that terrain has to occupy to be considered in later evaluations# 

def filtered_locations_map(ai*, min_percent)
	filter( 
		locations_map(ai) , 
		value >  (map.w * map.h) / ( 100 / min_percent ) 
	);

#returns average defense of the unit #

def unit_average_defense(ai*, unit, terrain_min_percent )
	sum( 
		values( 
			map(
				filtered_locations_map(ai,terrain_min_percent), 
				defense_on( 
					unit, 
					find(map.terrain,id=key).loc
				) *
				value
			) 
		) 
	) / 
	sum(
		values(
			filtered_locations_map(
				ai,
				terrain_min_percent
			)
		)
	);

#returns map of units from units_list and their average defense (more -> better) #

def map_units_average_defense(ai*, units_list, terrain_min_percent) 
	tomap(
		map( 
			units_list, 
			id 
		), 
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	);

def units_average_defense(ai*, units_list, terrain_min_percent)
	sum(
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	) /
	size(
		units_list
	);


# ==2== TODO: evaluate unit effectivness based on movement points and movement cost#


		#===== Evaluation of game state - how good is ai doing ===== #

# ==1== based on unit cost and current amount of gold #
# returns number between 0 and 100 where: 0 we are losing, 100 we are winning #

def units_cost_gold_eval(ai*)
	min(
		[
			(
				(
					sum(
						map(
							allies, 'team', 
							sum(
								map(
									units_of_side[team], 
									cost
								)
							) + 
							teams[team].gold 
						)
					) * 
					100
				) / 
				sum(
					map(
						enemies, 'team', 
						sum(
							map(
								units_of_side[team], 
								cost
							)
						) + 
						max(
							[teams[team].gold, 0]
						) 
					)
				)
			) / 2,
			100
		]
	);

# ==2== based on village possession #

def count_allied_villages(ai*)
	sum(
		map(
			allies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

def count_enemy_villages(ai*)
	sum(
		map(
			enemies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

# multipled by 1000 to increase precision #

def village_evaluation(ai*)
	(
		50000 + 
		(
			count_allied_villages(ai) - 
			count_enemy_villages(ai)
		) * 
		(
			50000 /
			size(
				villages
			)
		)
	) /
	1000;

# ==3== combined 2 of the above #

def eval(ai*)
	( 
		units_cost_gold_eval(ai) + 
		village_evaluation(ai)
	) / 
	2;

		#===== Evaluation how effective my units are against the enemy ===== #

#==1==  basic evaluation #

# evaluate how much damage unit can inflict - how much damage unit can get#

def evaluate_attacker_against_opponents(ai*, unit, enemy_units)
	sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( unit, enemy_unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				) 
			)
		)
	);

def evaluate_defender_against_opponents(ai*, unit, enemy_units)
	-sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( enemy_unit, unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				)
			)
		)
	);

def units_hp_map(ai*, units)
	tomap( 
		map(
			units, 
			id
		), 
		map( 
			units, 
			hitpoints
		)
	);

#in case side's gold is more than 50, add units that side can recruit to the side's unit list#

def create_side_unit_list(ai*, side)
	if( 
		teams[side].gold > 50, 
		recruits_of_side[side], 
		[]
	) + 
	units_of_side[side];

def evaluate_my_recruits_as_attackers(ai*)
	tomap( 
		map(
			my_recruits, 
			id
		), 
		map(
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_attacker_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai, 
							enemy_side
						)
					)
				)
			)
		)
	);

def evaluate_my_recruits_as_defenders(ai*)
	tomap(
		map(
			my_recruits, 
			id
		),
		map( 
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_defender_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai,
							enemy_side
						)
					)
				)
			)
		)
	);


# === 2 ===  now consider abilities and weapon specials  #

def abilities_weights()
	['skirmisher' -> 15, 'ambush' -> 10, 'nightstalk' -> 20, 'regenerates' -> 20, 'healing' -> 15, 'curing' -> 10, 'leadership' -> 20, 'illumination' -> 15, 'teleport' -> 10, 'steadfast' -> 15 ];

def weapon_specials_weights()
	[ 'backstab' -> 20 ,'slow' -> 10 ,'berserk' -> 20 ,'stones' -> 60 ,'plague' -> 10 ,'marksman' -> 30 ,'magical' -> 40 ,'charge' -> 30 ,'drains' -> 30,  'firststrike' -> 10, 'poison' -> 25 ];

def apply_abilities_weights( units_map )
	map( 
		units_map, 
		value +
		(
			value * 
			max(
				map(
					get_unit_type( key ).abilities, 'ability',
					abilities_weights()[ability]
				)
			)
		) / 100
	);

def apply_weapon_specials_weights( units_map )
	map(
		units_map, 
		value +
		(
			value *
			max(
				map(
					get_unit_type( key ).attacks, 'attack',
					vars.weapon_specials[attack.special]
				)
			)
		) / 100
	);

# since undead units don't get random traits and are balanced with that, we need to lower their evaluation a bit to match fairly the living units #

def undead_malus( units_map )
	map( 
		units_map, 
		if(
			get_unit_type(key).undead,
			( value * 90 ) / 100,
			value 
		)
	);

# === 3 ===  pit 1 and 2 together  #

def evaluate_attackers(ai*)
	change_numbers_to_percents(
		apply_abilities_weights(
			apply_weapon_specials_weights(
				undead_malus( 
					make_positive_only(
						evaluate_my_recruits_as_attackers( ai )	
					)
				)
			)
		)
	);

def evaluate_defenders(ai*)
	map(
		map(
			change_numbers_to_percents(
				apply_abilities_weights(
					apply_weapon_specials_weights(
						undead_malus( 
							make_positive_only(
								evaluate_my_recruits_as_defenders( ai )	
							)
						)
					)
				)
			),
			value / 3
		), 
		value +
		map(
			change_numbers_to_percents(
				units_hp_map(
					ai,
					my_recruits
				)
			),
		value * 2 / 3
		)[key]
	);

	#=========== we have evaluation of game state and units, time to combine them: ==========#
		#=========	recruitment_list_builder	=========#

def rlb_apply_eval(eval, attackers_map, defenders_map, offset)
	map(
		sumarize_maps_values(
			map(
				attackers_map, 
				value * (eval+offset)
			),
			map(
				defenders_map,
				value * ( (100 - eval) - offset )
			)
		),
		value / 100
	);

def rlb_remove_lowest( input_map, percent)
	filter(
		input_map, 
		value > 
		(
			(
				percent * sumarize_values(input_map)
			) / 100
		)
	);

def rlb_first_step(eval, attackers_map, defenders_map, offset)
	rlb_remove_lowest(
		rlb_apply_eval(
			eval,
			attackers_map,
			defenders_map,
			offset
		),
		10
	);

def recruitment_list_builder(eval, attackers_map, defenders_map)
	map(
		rlb_first_step(
			eval,
			attackers_map,
			defenders_map,
			40
		),
		(
			(
				value * 100
			) / 
			sumarize_values(
				rlb_first_step(
					eval,
					attackers_map,
					defenders_map,
					40
				)
			)
		)
	);

		# ========== choose the unit to recruit now ========= #

def unit_chooser(ai*,unit_map) 
	choose(
		keys(unit_map), 'unit_type',
		unit_map[unit_type] - 
		(
			(
				100 * 
				size(
					filter(
						my_units, 
						type = unit_type
					)
				)
			) / 
			size(my_units)
		)
	);

def unit_map_cost_filter(ai*, unit_map)
	filter( unit_map,
		get_unit_type(key).cost < my_side.gold
	);

		# ==========	Main formula section 	========== #

def initialize_weapon_specials_map(ai*)
	if(vars.weapon_specials_init != turn,
		[
			set_var('weapon_specials_init', turn),
			set_var('weapon_specials',
				map(
					weapon_specials_weights(),
					if( key = 'magical',
						units_average_defense(ai, enemy_units, 10),
						if( key = 'marksman',
							units_average_defense(ai, enemy_units, 10) - 10,
							value
						)
					)
				)
			)
		],
		[]
	);

def create_recruits_map(ai*)
	if(vars.recruits_map_creator != turn,
		[
			set_var('recruits_map_creator', turn ),
			set_var('recruits_map',
				debug_print('final unit evaluation: ', recruitment_list_builder(
					debug_print('current AI evaluation (0-100): ', eval(ai)),
					debug_print('attackers evaluation: ',evaluate_attackers(ai)),
					debug_print('defenders evaluation: ',evaluate_defenders(ai))
				))
			)
		],
		[]
	);

def castle_space(ai*)
	filter( map( castle_locs( my_leader.loc ), 'location', if( unit_at( location ), 1, 0 ) ), self = 0  ).size;

if(vars.turn_initialized = turn,
		if( my_leader.loc = nearest_keep( my_leader.loc ),
			if( 
				get_unit_type(
					choose(
						vars.recruits_map,
						-get_unit_type(key).cost
					).key
				).cost <
				my_side.gold,
				if( castle_space(self),
					recruit(debug_print(
						unit_chooser(
							self,
							unit_map_cost_filter(
								self,
								vars.recruits_map
							)
						)
					)),
					fallback()
				),
				fallback() 
			),
			if( my_leader.movement_left > 0,
				move( my_leader.loc, nearest_keep( my_leader.loc ) ),
				fallback()
			)
		),
	[set_var(debug_print('turn_initialized'), turn)] +
	initialize_weapon_specials_map(self) +
	create_recruits_map(self)
)

faiend
"
			[/team_formula]
		[/ai]
		[ai]
			villages_per_scout="8"
		[/ai]
	[/side]
	[side]
		allow_changes="yes"
		allow_player="yes"
		canrecruit="yes"
		colour="2"
		controller="network"
		current_player="Odol"
		flag_rgb="magenta"
		fog="yes"
		gender="male"
		gold="100"
		id="Odol2"
		image="units/undead-necromancers/dark-sorcerer.png"
		income="0"
		leader="Dark Sorcerer,Revenant,Deathblade,Bone Shooter,Necrophage"
		mp_countdown="yes"
		mp_countdown_action_bonus="10"
		mp_countdown_init_time="180"
		mp_countdown_reservoir_time="240"
		mp_countdown_turn_bonus="45"
		name="Odol"
		random_leader="Dark Sorcerer,Revenant,Deathblade,Bone Shooter"
		recruit="Skeleton,Skeleton Archer,Walking Corpse,Ghost,Vampire Bat,Dark Adept,Ghoul"
		save_id="Odol2"
		share_maps="no"
		share_view="yes"
		shroud="no"
		side="2"
		team_name="north"
		terrain_liked="Ss, Hh, Ha, Ww"
		type="Bone Shooter"
		user_team_name="wesnoth-multiplayerteamname^North"
		village_gold="2"
		[ai]
			recruitment_pattern="fighter,fighter,archer,fighter,scout,archer"
			villages_per_scout="8"
			[team_formula]
				rulebase="fai 'recruitment.fai'
		# ===== Some general functions used later ==== #

def sumarize_values( input_map )
	sum(
		values(input_map)
	);

def lowest_value( input_map )
	choose( input_map, -value ).value;

def highest_value( input_map )
	choose( input_map, value ).value;

def change_numbers_to_percents( input_map )
	map( input_map, 
		(value*100) / highest_value(input_map) 
	);

def add_number_to_values( input_map, number )
	map( input_map, 
		value + number 
	);

#make sure we have only positive values in a map #

def make_positive_only( input_map )
	if( lowest_value( input_map ) < 0, 
		add_number_to_values( 
			input_map, 
			abs(lowest_value(input_map))
		), 
		input_map 
	);

def sumarize_maps_values( map_A, map_B )
	map( map_A + map_B, 
		value + map_A[key]
	);

		#===== Evaluation how good unit is on a map ===== #

# ==1==  evaluate average defense #
#gives map where key is id of terrain, and value is number of hexes of that terrain on a gamemap#

def locations_map(ai*) 
	tomap( 
		map( 
			map.terrain, 
			id 
		) 
	);

#filters terrain map, min_percent it minimal % of map that terrain has to occupy to be considered in later evaluations# 

def filtered_locations_map(ai*, min_percent)
	filter( 
		locations_map(ai) , 
		value >  (map.w * map.h) / ( 100 / min_percent ) 
	);

#returns average defense of the unit #

def unit_average_defense(ai*, unit, terrain_min_percent )
	sum( 
		values( 
			map(
				filtered_locations_map(ai,terrain_min_percent), 
				defense_on( 
					unit, 
					find(map.terrain,id=key).loc
				) *
				value
			) 
		) 
	) / 
	sum(
		values(
			filtered_locations_map(
				ai,
				terrain_min_percent
			)
		)
	);

#returns map of units from units_list and their average defense (more -> better) #

def map_units_average_defense(ai*, units_list, terrain_min_percent) 
	tomap(
		map( 
			units_list, 
			id 
		), 
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	);

def units_average_defense(ai*, units_list, terrain_min_percent)
	sum(
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	) /
	size(
		units_list
	);


# ==2== TODO: evaluate unit effectivness based on movement points and movement cost#


		#===== Evaluation of game state - how good is ai doing ===== #

# ==1== based on unit cost and current amount of gold #
# returns number between 0 and 100 where: 0 we are losing, 100 we are winning #

def units_cost_gold_eval(ai*)
	min(
		[
			(
				(
					sum(
						map(
							allies, 'team', 
							sum(
								map(
									units_of_side[team], 
									cost
								)
							) + 
							teams[team].gold 
						)
					) * 
					100
				) / 
				sum(
					map(
						enemies, 'team', 
						sum(
							map(
								units_of_side[team], 
								cost
							)
						) + 
						max(
							[teams[team].gold, 0]
						) 
					)
				)
			) / 2,
			100
		]
	);

# ==2== based on village possession #

def count_allied_villages(ai*)
	sum(
		map(
			allies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

def count_enemy_villages(ai*)
	sum(
		map(
			enemies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

# multipled by 1000 to increase precision #

def village_evaluation(ai*)
	(
		50000 + 
		(
			count_allied_villages(ai) - 
			count_enemy_villages(ai)
		) * 
		(
			50000 /
			size(
				villages
			)
		)
	) /
	1000;

# ==3== combined 2 of the above #

def eval(ai*)
	( 
		units_cost_gold_eval(ai) + 
		village_evaluation(ai)
	) / 
	2;

		#===== Evaluation how effective my units are against the enemy ===== #

#==1==  basic evaluation #

# evaluate how much damage unit can inflict - how much damage unit can get#

def evaluate_attacker_against_opponents(ai*, unit, enemy_units)
	sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( unit, enemy_unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				) 
			)
		)
	);

def evaluate_defender_against_opponents(ai*, unit, enemy_units)
	-sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( enemy_unit, unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				)
			)
		)
	);

def units_hp_map(ai*, units)
	tomap( 
		map(
			units, 
			id
		), 
		map( 
			units, 
			hitpoints
		)
	);

#in case side's gold is more than 50, add units that side can recruit to the side's unit list#

def create_side_unit_list(ai*, side)
	if( 
		teams[side].gold > 50, 
		recruits_of_side[side], 
		[]
	) + 
	units_of_side[side];

def evaluate_my_recruits_as_attackers(ai*)
	tomap( 
		map(
			my_recruits, 
			id
		), 
		map(
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_attacker_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai, 
							enemy_side
						)
					)
				)
			)
		)
	);

def evaluate_my_recruits_as_defenders(ai*)
	tomap(
		map(
			my_recruits, 
			id
		),
		map( 
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_defender_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai,
							enemy_side
						)
					)
				)
			)
		)
	);


# === 2 ===  now consider abilities and weapon specials  #

def abilities_weights()
	['skirmisher' -> 15, 'ambush' -> 10, 'nightstalk' -> 20, 'regenerates' -> 20, 'healing' -> 15, 'curing' -> 10, 'leadership' -> 20, 'illumination' -> 15, 'teleport' -> 10, 'steadfast' -> 15 ];

def weapon_specials_weights()
	[ 'backstab' -> 20 ,'slow' -> 10 ,'berserk' -> 20 ,'stones' -> 60 ,'plague' -> 10 ,'marksman' -> 30 ,'magical' -> 40 ,'charge' -> 30 ,'drains' -> 30,  'firststrike' -> 10, 'poison' -> 25 ];

def apply_abilities_weights( units_map )
	map( 
		units_map, 
		value +
		(
			value * 
			max(
				map(
					get_unit_type( key ).abilities, 'ability',
					abilities_weights()[ability]
				)
			)
		) / 100
	);

def apply_weapon_specials_weights( units_map )
	map(
		units_map, 
		value +
		(
			value *
			max(
				map(
					get_unit_type( key ).attacks, 'attack',
					vars.weapon_specials[attack.special]
				)
			)
		) / 100
	);

# since undead units don't get random traits and are balanced with that, we need to lower their evaluation a bit to match fairly the living units #

def undead_malus( units_map )
	map( 
		units_map, 
		if(
			get_unit_type(key).undead,
			( value * 90 ) / 100,
			value 
		)
	);

# === 3 ===  pit 1 and 2 together  #

def evaluate_attackers(ai*)
	change_numbers_to_percents(
		apply_abilities_weights(
			apply_weapon_specials_weights(
				undead_malus( 
					make_positive_only(
						evaluate_my_recruits_as_attackers( ai )	
					)
				)
			)
		)
	);

def evaluate_defenders(ai*)
	map(
		map(
			change_numbers_to_percents(
				apply_abilities_weights(
					apply_weapon_specials_weights(
						undead_malus( 
							make_positive_only(
								evaluate_my_recruits_as_defenders( ai )	
							)
						)
					)
				)
			),
			value / 3
		), 
		value +
		map(
			change_numbers_to_percents(
				units_hp_map(
					ai,
					my_recruits
				)
			),
		value * 2 / 3
		)[key]
	);

	#=========== we have evaluation of game state and units, time to combine them: ==========#
		#=========	recruitment_list_builder	=========#

def rlb_apply_eval(eval, attackers_map, defenders_map, offset)
	map(
		sumarize_maps_values(
			map(
				attackers_map, 
				value * (eval+offset)
			),
			map(
				defenders_map,
				value * ( (100 - eval) - offset )
			)
		),
		value / 100
	);

def rlb_remove_lowest( input_map, percent)
	filter(
		input_map, 
		value > 
		(
			(
				percent * sumarize_values(input_map)
			) / 100
		)
	);

def rlb_first_step(eval, attackers_map, defenders_map, offset)
	rlb_remove_lowest(
		rlb_apply_eval(
			eval,
			attackers_map,
			defenders_map,
			offset
		),
		10
	);

def recruitment_list_builder(eval, attackers_map, defenders_map)
	map(
		rlb_first_step(
			eval,
			attackers_map,
			defenders_map,
			40
		),
		(
			(
				value * 100
			) / 
			sumarize_values(
				rlb_first_step(
					eval,
					attackers_map,
					defenders_map,
					40
				)
			)
		)
	);

		# ========== choose the unit to recruit now ========= #

def unit_chooser(ai*,unit_map) 
	choose(
		keys(unit_map), 'unit_type',
		unit_map[unit_type] - 
		(
			(
				100 * 
				size(
					filter(
						my_units, 
						type = unit_type
					)
				)
			) / 
			size(my_units)
		)
	);

def unit_map_cost_filter(ai*, unit_map)
	filter( unit_map,
		get_unit_type(key).cost < my_side.gold
	);

		# ==========	Main formula section 	========== #

def initialize_weapon_specials_map(ai*)
	if(vars.weapon_specials_init != turn,
		[
			set_var('weapon_specials_init', turn),
			set_var('weapon_specials',
				map(
					weapon_specials_weights(),
					if( key = 'magical',
						units_average_defense(ai, enemy_units, 10),
						if( key = 'marksman',
							units_average_defense(ai, enemy_units, 10) - 10,
							value
						)
					)
				)
			)
		],
		[]
	);

def create_recruits_map(ai*)
	if(vars.recruits_map_creator != turn,
		[
			set_var('recruits_map_creator', turn ),
			set_var('recruits_map',
				debug_print('final unit evaluation: ', recruitment_list_builder(
					debug_print('current AI evaluation (0-100): ', eval(ai)),
					debug_print('attackers evaluation: ',evaluate_attackers(ai)),
					debug_print('defenders evaluation: ',evaluate_defenders(ai))
				))
			)
		],
		[]
	);

def castle_space(ai*)
	filter( map( castle_locs( my_leader.loc ), 'location', if( unit_at( location ), 1, 0 ) ), self = 0  ).size;

if(vars.turn_initialized = turn,
		if( my_leader.loc = nearest_keep( my_leader.loc ),
			if( 
				get_unit_type(
					choose(
						vars.recruits_map,
						-get_unit_type(key).cost
					).key
				).cost <
				my_side.gold,
				if( castle_space(self),
					recruit(debug_print(
						unit_chooser(
							self,
							unit_map_cost_filter(
								self,
								vars.recruits_map
							)
						)
					)),
					fallback()
				),
				fallback() 
			),
			if( my_leader.movement_left > 0,
				move( my_leader.loc, nearest_keep( my_leader.loc ) ),
				fallback()
			)
		),
	[set_var(debug_print('turn_initialized'), turn)] +
	initialize_weapon_specials_map(self) +
	create_recruits_map(self)
)

faiend
"
			[/team_formula]
		[/ai]
		[ai]
			villages_per_scout="8"
		[/ai]
	[/side]
	[side]
		allow_changes="yes"
		allow_player="no"
		canrecruit="no"
		colour="5"
		controller="ai"
		flag_rgb="magenta"
		fog="yes"
		gender="male"
		gold="100"
		hidden="yes"
		id="ai3"
		image="units/human-loyalists/lieutenant.png"
		income="0"
		leader="Lieutenant,Swordsman,Pikeman,Javelineer,Shock Trooper,Longbowman,White Mage,Red Mage"
		mp_countdown="yes"
		mp_countdown_action_bonus="10"
		mp_countdown_init_time="180"
		mp_countdown_reservoir_time="240"
		mp_countdown_turn_bonus="45"
		name=_ "Computer player"
		no_leader="yes"
		random_leader="Lieutenant,Swordsman,Pikeman,Javelineer,Longbowman,Red Mage"
		recruit="Cavalryman,Horseman,Spearman,Fencer,Heavy Infantryman,Bowman,Mage,Merman Fighter"
		save_id="ai3"
		share_maps="no"
		share_view="yes"
		shroud="no"
		side="3"
		team_name="statues"
		terrain_liked="Gg, Ww, Wo"
		type="Pikeman"
		user_team_name="statues"
		village_gold="2"
		[unit]
#textdomain wesnoth-multiplayer
			description=_ "A stone-carved likeness of Sulla the Great, also known as Sulla the Just, Sulla the Tyrant, Empress of the Sinking Tower, Lady of the Walking Glacier, Sulla the Incinerator, Sulla the Proud and Sulla the Righteous."
			facing="se"
			gender="female"
			name="`~`" + 
				_ "Statue of Sulla"
			random_traits="no"
			type="Great Mage"
			unrenamable="yes"
			x="18"
			y="15"
			[status]
				stoned="on"
			[/status]
			[modifications]
				[trait]
					description=_ "This is a sculpture made of stone."
					id="remove_hp"
					name=_ "statue"
					[effect]
						apply_to="hitpoints"
						increase_total="-100%"
					[/effect]
					[effect]
						apply_to="movement"
						set="0"
					[/effect]
				[/trait]
			[/modifications]
		[/unit]
		[unit]
			description=_ "A stone-carved likeness of Lhun-dup, Servant of Sulla."
			facing="sw"
			name="`~`" + 
				_ "Statue of Lhun-dup"
			random_traits="no"
			type="Yeti"
			unrenamable="yes"
			x="20"
			y="11"
			[status]
				stoned="on"
			[/status]
			[modifications]
				[trait]
					description=_ "This is a sculpture made of stone."
					id="remove_hp"
					name=_ "statue"
					[effect]
						apply_to="hitpoints"
						increase_total="-100%"
					[/effect]
					[effect]
						apply_to="movement"
						set="0"
					[/effect]
				[/trait]
			[/modifications]
		[/unit]
		[unit]
			description=_ "A stone-carved likeness of Ri-nzen, Servant of Sulla."
			facing="sw"
			name="`~`" + 
				_ "Statue of Ri-nzen"
			random_traits="no"
			type="Yeti"
			unrenamable="yes"
			x="23"
			y="15"
			[status]
				stoned="on"
			[/status]
			[modifications]
				[trait]
					description=_ "This is a sculpture made of stone."
					id="remove_hp"
					name=_ "statue"
					[effect]
						apply_to="hitpoints"
						increase_total="-100%"
					[/effect]
					[effect]
						apply_to="movement"
						set="0"
					[/effect]
				[/trait]
			[/modifications]
		[/unit]
		[unit]
			description=_ "A stone-carved likeness of Ten-zin, Servant of Sulla."
			facing="se"
			name="`~`" + 
				_ "Statue of Ten-zin"
			random_traits="no"
			type="Yeti"
			unrenamable="yes"
			x="13"
			y="16"
			[status]
				stoned="on"
			[/status]
			[modifications]
				[trait]
					description=_ "This is a sculpture made of stone."
					id="remove_hp"
					name=_ "statue"
					[effect]
						apply_to="hitpoints"
						increase_total="-100%"
					[/effect]
					[effect]
						apply_to="movement"
						set="0"
					[/effect]
				[/trait]
			[/modifications]
		[/unit]
		[unit]
			description=_ "A stone-carved likeness of Lo-bsang, Servant of Sulla."
			facing="se"
			name="`~`" + 
				_ "Statue of Lo-bsang"
			random_traits="no"
			type="Yeti"
			unrenamable="yes"
			x="16"
			y="19"
			[status]
				stoned="on"
			[/status]
			[modifications]
				[trait]
					description=_ "This is a sculpture made of stone."
					id="remove_hp"
					name=_ "statue"
					[effect]
						apply_to="hitpoints"
						increase_total="-100%"
					[/effect]
					[effect]
						apply_to="movement"
						set="0"
					[/effect]
				[/trait]
			[/modifications]
		[/unit]
		[ai]
			recruitment_pattern="fighter,fighter,fighter,archer,mixed fighter,scout"
			[team_formula]
				rulebase="fai 'recruitment.fai'
		# ===== Some general functions used later ==== #

def sumarize_values( input_map )
	sum(
		values(input_map)
	);

def lowest_value( input_map )
	choose( input_map, -value ).value;

def highest_value( input_map )
	choose( input_map, value ).value;

def change_numbers_to_percents( input_map )
	map( input_map, 
		(value*100) / highest_value(input_map) 
	);

def add_number_to_values( input_map, number )
	map( input_map, 
		value + number 
	);

#make sure we have only positive values in a map #

def make_positive_only( input_map )
	if( lowest_value( input_map ) < 0, 
		add_number_to_values( 
			input_map, 
			abs(lowest_value(input_map))
		), 
		input_map 
	);

def sumarize_maps_values( map_A, map_B )
	map( map_A + map_B, 
		value + map_A[key]
	);

		#===== Evaluation how good unit is on a map ===== #

# ==1==  evaluate average defense #
#gives map where key is id of terrain, and value is number of hexes of that terrain on a gamemap#

def locations_map(ai*) 
	tomap( 
		map( 
			map.terrain, 
			id 
		) 
	);

#filters terrain map, min_percent it minimal % of map that terrain has to occupy to be considered in later evaluations# 

def filtered_locations_map(ai*, min_percent)
	filter( 
		locations_map(ai) , 
		value >  (map.w * map.h) / ( 100 / min_percent ) 
	);

#returns average defense of the unit #

def unit_average_defense(ai*, unit, terrain_min_percent )
	sum( 
		values( 
			map(
				filtered_locations_map(ai,terrain_min_percent), 
				defense_on( 
					unit, 
					find(map.terrain,id=key).loc
				) *
				value
			) 
		) 
	) / 
	sum(
		values(
			filtered_locations_map(
				ai,
				terrain_min_percent
			)
		)
	);

#returns map of units from units_list and their average defense (more -> better) #

def map_units_average_defense(ai*, units_list, terrain_min_percent) 
	tomap(
		map( 
			units_list, 
			id 
		), 
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	);

def units_average_defense(ai*, units_list, terrain_min_percent)
	sum(
		map( 
			units_list, 'unit', 
			unit_average_defense(
				ai, 
				unit, 
				terrain_min_percent 
			) 
		) 
	) /
	size(
		units_list
	);


# ==2== TODO: evaluate unit effectivness based on movement points and movement cost#


		#===== Evaluation of game state - how good is ai doing ===== #

# ==1== based on unit cost and current amount of gold #
# returns number between 0 and 100 where: 0 we are losing, 100 we are winning #

def units_cost_gold_eval(ai*)
	min(
		[
			(
				(
					sum(
						map(
							allies, 'team', 
							sum(
								map(
									units_of_side[team], 
									cost
								)
							) + 
							teams[team].gold 
						)
					) * 
					100
				) / 
				sum(
					map(
						enemies, 'team', 
						sum(
							map(
								units_of_side[team], 
								cost
							)
						) + 
						max(
							[teams[team].gold, 0]
						) 
					)
				)
			) / 2,
			100
		]
	);

# ==2== based on village possession #

def count_allied_villages(ai*)
	sum(
		map(
			allies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

def count_enemy_villages(ai*)
	sum(
		map(
			enemies, 'side', 
			size(
				villages_of_side[side]
			)
		)
	);

# multipled by 1000 to increase precision #

def village_evaluation(ai*)
	(
		50000 + 
		(
			count_allied_villages(ai) - 
			count_enemy_villages(ai)
		) * 
		(
			50000 /
			size(
				villages
			)
		)
	) /
	1000;

# ==3== combined 2 of the above #

def eval(ai*)
	( 
		units_cost_gold_eval(ai) + 
		village_evaluation(ai)
	) / 
	2;

		#===== Evaluation how effective my units are against the enemy ===== #

#==1==  basic evaluation #

# evaluate how much damage unit can inflict - how much damage unit can get#

def evaluate_attacker_against_opponents(ai*, unit, enemy_units)
	sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( unit, enemy_unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				) 
			)
		)
	);

def evaluate_defender_against_opponents(ai*, unit, enemy_units)
	-sum( 
		map( 
			enemy_units, 'enemy_unit', 
			sum(
				map(
					[
						max_possible_damage_with_retaliation( enemy_unit, unit )
					],
					max(
						[
							self[0] - self[2],
							self[1] - self[3]
						]
					)
				)
			)
		)
	);

def units_hp_map(ai*, units)
	tomap( 
		map(
			units, 
			id
		), 
		map( 
			units, 
			hitpoints
		)
	);

#in case side's gold is more than 50, add units that side can recruit to the side's unit list#

def create_side_unit_list(ai*, side)
	if( 
		teams[side].gold > 50, 
		recruits_of_side[side], 
		[]
	) + 
	units_of_side[side];

def evaluate_my_recruits_as_attackers(ai*)
	tomap( 
		map(
			my_recruits, 
			id
		), 
		map(
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_attacker_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai, 
							enemy_side
						)
					)
				)
			)
		)
	);

def evaluate_my_recruits_as_defenders(ai*)
	tomap(
		map(
			my_recruits, 
			id
		),
		map( 
			my_recruits, 'my_unit',
			sum(
				map(
					enemies, 'enemy_side',
					evaluate_defender_against_opponents(
						ai,
						my_unit,
						create_side_unit_list(
							ai,
							enemy_side
						)
					)
				)
			)
		)
	);


# === 2 ===  now consider abilities and weapon specials  #

def abilities_weights()
	['skirmisher' -> 15, 'ambush' -> 10, 'nightstalk' -> 20, 'regenerates' -> 20, 'healing' -> 15, 'curing' -> 10, 'leadership' -> 20, 'illumination' -> 15, 'teleport' -> 10, 'steadfast' -> 15 ];

def weapon_specials_weights()
	[ 'backstab' -> 20 ,'slow' -> 10 ,'berserk' -> 20 ,'stones' -> 60 ,'plague' -> 10 ,'marksman' -> 30 ,'magical' -> 40 ,'charge' -> 30 ,'drains' -> 30,  'firststrike' -> 10, 'poison' -> 25 ];

def apply_abilities_weights( units_map )
	map( 
		units_map, 
		value +
		(
			value * 
			max(
				map(
					get_unit_type( key ).abilities, 'ability',
					abilities_weights()[ability]
				)
			)
		) / 100
	);

def apply_weapon_specials_weights( units_map )
	map(
		units_map, 
		value +
		(
			value *
			max(
				map(
					get_unit_type( key ).attacks, 'attack',
					vars.weapon_specials[attack.special]
				)
			)
		) / 100
	);

# since undead units don't get random traits and are balanced with that, we need to lower their evaluation a bit to match fairly the living units #

def undead_malus( units_map )
	map( 
		units_map, 
		if(
			get_unit_type(key).undead,
			( value * 90 ) / 100,
			value 
		)
	);

# === 3 ===  pit 1 and 2 together  #

def evaluate_attackers(ai*)
	change_numbers_to_percents(
		apply_abilities_weights(
			apply_weapon_specials_weights(
				undead_malus( 
					make_positive_only(
						evaluate_my_recruits_as_attackers( ai )	
					)
				)
			)
		)
	);

def evaluate_defenders(ai*)
	map(
		map(
			change_numbers_to_percents(
				apply_abilities_weights(
					apply_weapon_specials_weights(
						undead_malus( 
							make_positive_only(
								evaluate_my_recruits_as_defenders( ai )	
							)
						)
					)
				)
			),
			value / 3
		), 
		value +
		map(
			change_numbers_to_percents(
				units_hp_map(
					ai,
					my_recruits
				)
			),
		value * 2 / 3
		)[key]
	);

	#=========== we have evaluation of game state and units, time to combine them: ==========#
		#=========	recruitment_list_builder	=========#

def rlb_apply_eval(eval, attackers_map, defenders_map, offset)
	map(
		sumarize_maps_values(
			map(
				attackers_map, 
				value * (eval+offset)
			),
			map(
				defenders_map,
				value * ( (100 - eval) - offset )
			)
		),
		value / 100
	);

def rlb_remove_lowest( input_map, percent)
	filter(
		input_map, 
		value > 
		(
			(
				percent * sumarize_values(input_map)
			) / 100
		)
	);

def rlb_first_step(eval, attackers_map, defenders_map, offset)
	rlb_remove_lowest(
		rlb_apply_eval(
			eval,
			attackers_map,
			defenders_map,
			offset
		),
		10
	);

def recruitment_list_builder(eval, attackers_map, defenders_map)
	map(
		rlb_first_step(
			eval,
			attackers_map,
			defenders_map,
			40
		),
		(
			(
				value * 100
			) / 
			sumarize_values(
				rlb_first_step(
					eval,
					attackers_map,
					defenders_map,
					40
				)
			)
		)
	);

		# ========== choose the unit to recruit now ========= #

def unit_chooser(ai*,unit_map) 
	choose(
		keys(unit_map), 'unit_type',
		unit_map[unit_type] - 
		(
			(
				100 * 
				size(
					filter(
						my_units, 
						type = unit_type
					)
				)
			) / 
			size(my_units)
		)
	);

def unit_map_cost_filter(ai*, unit_map)
	filter( unit_map,
		get_unit_type(key).cost < my_side.gold
	);

		# ==========	Main formula section 	========== #

def initialize_weapon_specials_map(ai*)
	if(vars.weapon_specials_init != turn,
		[
			set_var('weapon_specials_init', turn),
			set_var('weapon_specials',
				map(
					weapon_specials_weights(),
					if( key = 'magical',
						units_average_defense(ai, enemy_units, 10),
						if( key = 'marksman',
							units_average_defense(ai, enemy_units, 10) - 10,
							value
						)
					)
				)
			)
		],
		[]
	);

def create_recruits_map(ai*)
	if(vars.recruits_map_creator != turn,
		[
			set_var('recruits_map_creator', turn ),
			set_var('recruits_map',
				debug_print('final unit evaluation: ', recruitment_list_builder(
					debug_print('current AI evaluation (0-100): ', eval(ai)),
					debug_print('attackers evaluation: ',evaluate_attackers(ai)),
					debug_print('defenders evaluation: ',evaluate_defenders(ai))
				))
			)
		],
		[]
	);

def castle_space(ai*)
	filter( map( castle_locs( my_leader.loc ), 'location', if( unit_at( location ), 1, 0 ) ), self = 0  ).size;

if(vars.turn_initialized = turn,
		if( my_leader.loc = nearest_keep( my_leader.loc ),
			if( 
				get_unit_type(
					choose(
						vars.recruits_map,
						-get_unit_type(key).cost
					).key
				).cost <
				my_side.gold,
				if( castle_space(self),
					recruit(debug_print(
						unit_chooser(
							self,
							unit_map_cost_filter(
								self,
								vars.recruits_map
							)
						)
					)),
					fallback()
				),
				fallback() 
			),
			if( my_leader.movement_left > 0,
				move( my_leader.loc, nearest_keep( my_leader.loc ) ),
				fallback()
			)
		),
	[set_var(debug_print('turn_initialized'), turn)] +
	initialize_weapon_specials_map(self) +
	create_recruits_map(self)
)

faiend
"
			[/team_formula]
		[/ai]
	[/side]
[/replay_start]
[statistics]
	mid_scenario="yes"
	[scenario]
		scenario="2g - Ruiny Sullas"
		[team]
			[recruits]
				Dark Adept="7"
				Ghost="1"
				Ghoul="2"
				Skeleton="3"
				Vampire Bat="1"
			[/recruits]
			[recalls]
			[/recalls]
			[advances]
				Blood Bat="1"
			[/advances]
			[deaths]
				Skeleton="1"
			[/deaths]
			[killed]
				Dwarvish Fighter="1"
				Footpad="1"
				Gryphon Rider="1"
				Rogue="1"
			[/killed]
			[attacks]
				[sequence]
					s111="1"
					_num="30"
				[/sequence]
				[sequence]
					s000="1"
					s01="1"
					s101="1"
					s11="1"
					s110="1"
					s111="1"
					_num="40"
				[/sequence]
				[sequence]
					s1="1"
					s10="1"
					s110="1"
					_num="50"
				[/sequence]
				[sequence]
					s01="1"
					s11="5"
					_num="70"
				[/sequence]
			[/attacks]
			[defends]
				[sequence]
					s="9"
					_num="0"
				[/sequence]
				[sequence]
					s000="1"
					s101="2"
					s110="1"
					_num="40"
				[/sequence]
				[sequence]
					s01="1"
					_num="50"
				[/sequence]
				[sequence]
					s111="1"
					_num="70"
				[/sequence]
			[/defends]
			recruit_cost="222"
			recall_cost="0"
			damage_inflicted="194"
			damage_taken="102"
			expected_damage_inflicted="132169"
			expected_damage_taken="108778"
			turn_damage_inflicted="1"
			turn_damage_taken="0"
			turn_expected_damage_inflicted="640"
			turn_expected_damage_taken="-6836"
			save_id="Odol2"
		[/team]
		[team]
			[recruits]
				Dwarvish Fighter="4"
				Dwarvish Guardsman="1"
				Dwarvish Thunderer="2"
				Footpad="2"
				Gryphon Rider="1"
				Poacher="1"
				Thief="1"
			[/recruits]
			[recalls]
			[/recalls]
			[advances]
			[/advances]
			[deaths]
				Dwarvish Fighter="1"
				Footpad="1"
				Gryphon Rider="1"
				Rogue="1"
			[/deaths]
			[killed]
				Skeleton="1"
			[/killed]
			[attacks]
				[sequence]
					s00="4"
					s000="1"
					s01="1"
					s10="2"
					s100="1"
					s11="1"
					_num="40"
				[/sequence]
				[sequence]
					s011="1"
					s10="1"
					s100="1"
					s110="1"
					_num="50"
				[/sequence]
				[sequence]
					s01="1"
					_num="60"
				[/sequence]
			[/attacks]
			[defends]
				[sequence]
					s="7"
					_num="0"
				[/sequence]
				[sequence]
					s0="1"
					s01="1"
					s010="1"
					s100="1"
					_num="40"
				[/sequence]
				[sequence]
					s000="2"
					_num="50"
				[/sequence]
				[sequence]
					s01="1"
					s1="2"
					_num="60"
				[/sequence]
			[/defends]
			recruit_cost="196"
			recall_cost="0"
			damage_inflicted="102"
			damage_taken="194"
			expected_damage_inflicted="108778"
			expected_damage_taken="132169"
			turn_damage_inflicted="11"
			turn_damage_taken="16"
			turn_expected_damage_inflicted="4047"
			turn_expected_damage_taken="13819"
			save_id="Yawner1"
		[/team]
		[team]
			[recruits]
			[/recruits]
			[recalls]
			[/recalls]
			[advances]
			[/advances]
			[deaths]
			[/deaths]
			[killed]
			[/killed]
			[attacks]
			[/attacks]
			[defends]
			[/defends]
			recruit_cost="0"
			recall_cost="0"
			damage_inflicted="0"
			damage_taken="0"
			expected_damage_inflicted="0"
			expected_damage_taken="0"
			turn_damage_inflicted="0"
			turn_damage_taken="0"
			turn_expected_damage_inflicted="0"
			turn_expected_damage_taken="0"
			save_id="ai3"
		[/team]
	[/scenario]
[/statistics]
