[multiplayer]
	id=multiplayer_Wesbowl
	name= _ "2p - Wesbowl"
	map_data="{multiplayer/maps/2p_Wesbowl.map}"
	description= _ "In Wesbowl, a player has to get any of the balls to the other player's end zone as often as possible. However, the other player can attack your units. Wesbowl is played with blunt weapons, and healers are on hand, so when units are killed, they return to that player's end zone with an injury."
	objectives= _ "
Victory:
@Move either ball to your opponent's end zone more times than they move a ball to yours.
Defeat:
#Opponent moves the balls to your end zone more times than you move them to the opponent's end zone"

	{DEFAULT_SCHEDULE}
	{DEFAULT_MUSIC_PLAYLIST}

	[side]
	side=1
	canrecruit=1
	controller=human
	team_name=west
	user_team_name= _ "teamname^West"
	[/side]
	[side]
	side=2
	canrecruit=1
	controller=human
	team_name=east
	user_team_name= _ "teamname^East"
	[/side]

#define WESBOWL_UNIT SIDE FACING TYPE X Y
	[unit]
	side={SIDE}
	type={TYPE}
	facing={FACING}
	x={X}
	y={Y}
	[/unit]
#enddef

#define WESBOWL_SIDE LEADER SIDE FACING X A B C D E F G H I J K
	[if]
		[have_unit]
		type={LEADER}
		side={SIDE}
		[/have_unit]
		[then]
			{WESBOWL_UNIT {SIDE} {FACING} ({A}) {X} 10}
			{WESBOWL_UNIT {SIDE} {FACING} ({B}) {X} 8}
			{WESBOWL_UNIT {SIDE} {FACING} ({C}) {X} 12}
			{WESBOWL_UNIT {SIDE} {FACING} ({D}) {X} 6}
			{WESBOWL_UNIT {SIDE} {FACING} ({E}) {X} 14}
			{WESBOWL_UNIT {SIDE} {FACING} ({F}) {X} 4}
			{WESBOWL_UNIT {SIDE} {FACING} ({G}) {X} 16}
			{WESBOWL_UNIT {SIDE} {FACING} ({H}) {X} 2}
			{WESBOWL_UNIT {SIDE} {FACING} ({I}) {X} 18}
			{WESBOWL_UNIT {SIDE} {FACING} ({J}) {X} 1}
			{WESBOWL_UNIT {SIDE} {FACING} ({K}) {X} 20}
		[/then]
	[/if]
#enddef

#define WESBOWL_SIDE_DEFS SIDE FACING X
	{WESBOWL_SIDE (Elvish Captain,Elvish Hero,Elvish Ranger,Elvish Marksman,Elvish Druid,Elvish Sorceress,Elder Wose,Elvish Marshal,Elvish Champion,Elvish Avenger,Elvish Sharpshooter,Elvish Shyde,Elvish Enchantress,Ancient Wose) {SIDE} {FACING} {X} (Merman Fighter) (Elvish Fighter) (Elvish Fighter) (Elvish Archer) (Elvish Archer) Mage Mage (Elvish Shaman) (Elvish Shaman) (Elvish Scout) (Elvish Scout)}
	{WESBOWL_SIDE (Orcish Warrior,Troll,Troll Rocklobber,Orcish Crossbowman,Orcish Slayer,Orcish Warlord,Troll Warrior,Orcish Slurbow) {SIDE} {FACING} {X} (Naga Fighter) (Orcish Grunt) (Orcish Grunt) (Orcish Archer) (Orcish Archer) (Goblin Spearman) (Goblin Spearman) (Troll Whelp) (Troll Whelp) (Wolf Rider) (Wolf Rider)}
	{WESBOWL_SIDE (Dark Sorcerer,Revenant,Deathblade,Bone Shooter,Necrophage,Lich,Necromancer,Draug,Soul Shooter) {SIDE} {FACING} {X} (Vampire Bat) Skeleton Skeleton (Skeleton Archer) (Skeleton Archer) Skeleton Skeleton (Dark Adept) (Dark Adept) Ghost Ghost}
	{WESBOWL_SIDE (Dwarvish Steelclad,Dwarvish Thunderguard,Dwarvish Stalwart,Rogue,Bandit,Trapper,Dwarvish Lord,Dwarvish Dragonguard,Dwarvish Sentinel,Assassin) {SIDE} {FACING} {X} Poacher (Dwarvish Fighter) (Dwarvish Fighter) (Dwarvish Thunderer) (Dwarvish Thunderer) Footpad Footpad Thief Thief (Gryphon Rider) (Gryphon Rider)}
	{WESBOWL_SIDE (Lieutenant,Swordsman,Pikeman,Javelineer,Shock Trooper,Longbowman,White Mage,Red Mage,General,Royal Guard,Halbardier,Iron Mauler,Master Bowman,Mage of Light,Arch Mage,Silver Mage) {SIDE} {FACING} {X} (Naga Fighter) Spearman Spearman Fencer Fencer Horseman Horseman (Heavy Infantryman) (Heavy Infantryman) Cavalryman Cavalryman}
	{WESBOWL_SIDE (Drake Flare,Fire Drake,Drake Slasher,Drake Gladiator,Drake Warrior,Saurian Oracle,Saurian Soothsayer,Drake Flameheart,Inferno Drake,Drake Enforcer,Drake Warden,Drake Blademaster) {SIDE} {FACING} {X} (Saurian Augur) (Drake Fighter) (Drake Fighter) (Drake Burner) (Drake Burner) (Saurian Skirmisher) (Saurian Skirmisher) (Drake Clasher) (Drake Clasher) (Drake Glider) (Drake Glider)}
#enddef

	[event]
	name=prestart
	{WESBOWL_SIDE_DEFS 1 normal 5}
	{WESBOWL_SIDE_DEFS 2 reverse 37}

	{VARIABLE b1x 7}
	{VARIABLE b1y 9}
	{VARIABLE b2x 35}
	{VARIABLE b2y 11}
	{VARIABLE b1down yes}
	{VARIABLE b2down yes}

	{VARIABLE redscore 0}
	{VARIABLE bluescore 0}

		[item]
		image=items/ball.png
		x,y=$b1x,$b1y
		[/item]
		[item]
		image=items/ball.png
		x,y=$b2x,$b2y
		[/item]
	[/event]

	[event]
	name=moveto
	first_time_only=no
		[filter]
		x,y=$b1x,$b1y
		[/filter]
		[if]
			[variable]
			name=b1down
			equals=yes
			[/variable]
			[variable]
			name=unit.variables.has_ball2
			not_equals=yes
			[/variable]
			[then]
				[removeitem]
				x,y=$b1x,$b1y
				[/removeitem]
				{VARIABLE b1down no}
				{VARIABLE unit.variables.has_ball1 yes}
				[unstore_unit]
				variable=unit
				[/unstore_unit]
				[unit_overlay]
				x,y=$b1x,$b1y
				image=items/ball.png
				[/unit_overlay]
			[/then]
		[/if]
	[/event]

	[event]
	name=die
	first_time_only=no

		[if]
			[variable]
			name=unit.variables.has_ball1
			equals=yes
			[/variable]
			[then]
				[item]
				x,y=$x1,$y1
				image=items/ball.png
				[/item]
				{VARIABLE b1x $x1}
				{VARIABLE b1y $y1}
				{VARIABLE unit.variables.has_ball1 no}
				{VARIABLE b1down yes}
				[unstore_unit]
				variable=unit
				[/unstore_unit]
				[remove_unit_overlay]
				x,y=$x1,$y1
				image=items/ball.png
				[/remove_unit_overlay]
			[/then]
		[/if]
	[/event]

	[event]
	name=moveto
	first_time_only=no
		[filter]
		side=1
		x=38-40
		y=1-20
		[/filter]
		[if]
			[variable]
			name=unit.variables.has_ball1
			equals=yes
			[/variable]
			[then]
				[set_variable]
				name=redscore
				add=1
				[/set_variable]
				[message]
				speaker=narrator
				message= _ "Red scores! Current score is $redscore-$bluescore"
				[/message]
				{VARIABLE b1x 7}
				{VARIABLE b1y 9}
				{VARIABLE unit.variables.has_ball1 no}
				{VARIABLE b1down yes}

				[unstore_unit]
				variable=unit
				[/unstore_unit]
				[remove_unit_overlay]
				x,y=$x1,$y1
				image=items/ball.png
				[/remove_unit_overlay]
				[item]
				x,y=$b1x,$b1y
				image=items/ball.png
				[/item]
			[/then]
		[/if]
	[/event]

	[event]
	name=moveto
	first_time_only=no
		[filter]
		side=2
		x=1-3
		y=1-20
		[/filter]
		[if]
			[variable]
			name=unit.variables.has_ball1
			equals=yes
			[/variable]
			[then]
				[set_variable]
				name=bluescore
				add=1
				[/set_variable]
				[message]
				speaker=narrator
				message= _ "Blue scores! Current score is $redscore-$bluescore"
				[/message]
				{VARIABLE b1x 35}
				{VARIABLE b1y 11}
				{VARIABLE unit.variables.has_ball1 no}
				{VARIABLE b1down yes}

				[unstore_unit]
				variable=unit
				[/unstore_unit]
				[remove_unit_overlay]
				x,y=$x1,$y1
				image=items/ball.png
				[/remove_unit_overlay]
				[item]
				x,y=$b1x,$b1y
				image=items/ball.png
				[/item]
			[/then]
		[/if]
	[/event]

	#event to transfer control of the ball by passing, after movement
	[event]
	name=moveto
	first_time_only=no
		[if]
			[variable]
			name=unit.variables.has_ball1
			equals=yes
			[/variable]
			[then]
				[store_locations]
				variable=locs
				x,y,radius=$x1,$y1,1
				[/store_locations]
				{VARIABLE passed no}
				{FOREACH locs i}
					{VARIABLE_OP xloc to_variable locs[$i].x}
					{VARIABLE_OP yloc to_variable locs[$i].y}
					[if]
						[or]
							[variable]
							name=xloc
							not_equals=$x1
							[/variable]
							[variable]
							name=passed
							equals=no
							[/variable]
							[have_unit]
							x,y=$xloc,$yloc
							side=$unit.side
							[/have_unit]
						[/or]
						[or]
							[variable]
							name=yloc
							not_equals=$y1
							[/variable]
							[variable]
							name=passed
							equals=no
							[/variable]
							[have_unit]
							x,y=$xloc,$yloc
							side=$unit.side
							[/have_unit]
						[/or]
						[then]
							[store_unit]
								variable=passto
								[filter]
								x,y=$xloc,$yloc
								[/filter]
							[/store_unit]
							[if]
								[variable]
								name=passto.variables.has_ball2
								not_equals=yes
								[/variable]
								[then]
									[message]
									speaker=unit
									message= _ "Should I pass the ball to $passto.type ($xloc,$yloc)?"
										[option]
										message= _ "Yes!"
											[command]
											{VARIABLE passed yes}
											{VARIABLE unit.variables.has_ball1 no}
											{VARIABLE passto.variables.has_ball1 yes}
												[unstore_unit]
												variable=passto
												[/unstore_unit]
												[unstore_unit]
												variable=unit
												[/unstore_unit]
												[remove_unit_overlay]
												x,y=$x1,$y1
												image=items/ball.png
												[/remove_unit_overlay]
												[unit_overlay]
												x,y=$xloc,$yloc
												image=items/ball.png
												[/unit_overlay]
											[/command]
										[/option]
										[option]
										message= _ "No"
										[/option]
									[/message]
								[/then]
							[/if]
						[/then]
					[/if]

				{NEXT i}
			[/then]
		[/if]
	[/event]

	#control of the second ball. Exactly the same as control of the first
	#ball, with different variable names
	[event]
	name=moveto
	first_time_only=no
		[filter]
		x,y=$b2x,$b2y
		[/filter]
		[if]
			[variable]
			name=b2down
			equals=yes
			[/variable]
			[variable]
			name=unit.variables.has_ball1
			not_equals=yes
			[/variable]
			[then]
				[removeitem]
				x,y=$b2x,$b2y
				[/removeitem]
				{VARIABLE b2down no}
				{VARIABLE unit.variables.has_ball2 yes}
				[unstore_unit]
				variable=unit
				[/unstore_unit]
				[unit_overlay]
				x,y=$b2x,$b2y
				image=items/ball.png
				[/unit_overlay]
			[/then]
		[/if]
	[/event]

	[event]
	name=die
	first_time_only=no

		[if]
			[variable]
			name=unit.variables.has_ball2
			equals=yes
			[/variable]
			[then]
				[item]
				x,y=$x1,$y1
				image=items/ball.png
				[/item]
				{VARIABLE b2x $x1}
				{VARIABLE b2y $y1}
				{VARIABLE unit.variables.has_ball2 no}
				{VARIABLE b2down yes}
				[unstore_unit]
				variable=unit
				[/unstore_unit]
				[remove_unit_overlay]
				x,y=$x1,$y1
				image=items/ball.png
				[/remove_unit_overlay]
			[/then]
		[/if]
	[/event]

	[event]
	name=moveto
	first_time_only=no
		[filter]
		side=1
		x=38-40
		y=1-20
		[/filter]
		[if]
			[variable]
			name=unit.variables.has_ball2
			equals=yes
			[/variable]
			[then]
				[set_variable]
				name=redscore
				add=1
				[/set_variable]
				[message]
				speaker=narrator
				message= _ "Red scores! Current score is $redscore-$bluescore"
				[/message]
				{VARIABLE b2x 7}
				{VARIABLE b2y 9}
				{VARIABLE unit.variables.has_ball2 no}
				{VARIABLE b2down yes}

				[unstore_unit]
				variable=unit
				[/unstore_unit]
				[remove_unit_overlay]
				x,y=$x1,$y1
				image=items/ball.png
				[/remove_unit_overlay]
				[item]
				x,y=$b2x,$b2y
				image=items/ball.png
				[/item]
			[/then]
		[/if]
	[/event]

	[event]
	name=moveto
	first_time_only=no
		[filter]
		side=2
		x=1-3
		y=1-20
		[/filter]
		[if]
			[variable]
			name=unit.variables.has_ball2
			equals=yes
			[/variable]
			[then]
				[set_variable]
				name=bluescore
				add=1
				[/set_variable]
				[message]
				speaker=narrator
				message= _ "Blue scores! Current score is $redscore-$bluescore"
				[/message]
				{VARIABLE b2x 35}
				{VARIABLE b2y 11}
				{VARIABLE unit.variables.has_ball2 no}
				{VARIABLE b2down yes}

				[unstore_unit]
				variable=unit
				[/unstore_unit]
				[remove_unit_overlay]
				x,y=$x1,$y1
				image=items/ball.png
				[/remove_unit_overlay]
				[item]
				x,y=$b2x,$b2y
				image=items/ball.png
				[/item]
			[/then]
		[/if]
	[/event]

	#event to transfer control of the ball by passing, after movement
	[event]
	name=moveto
	first_time_only=no
		[if]
			[variable]
			name=unit.variables.has_ball2
			equals=yes
			[/variable]
			[then]
				[store_locations]
				variable=locs
				x,y,radius=$x1,$y1,1
				[/store_locations]
				{VARIABLE passed no}
				{FOREACH locs i}
					{VARIABLE_OP xloc to_variable locs[$i].x}
					{VARIABLE_OP yloc to_variable locs[$i].y}
					[if]
						[or]
							[variable]
							name=xloc
							not_equals=$x1
							[/variable]
							[variable]
							name=passed
							equals=no
							[/variable]
							[have_unit]
							x,y=$xloc,$yloc
							side=$unit.side
							[/have_unit]
						[/or]
						[or]
							[variable]
							name=yloc
							not_equals=$y1
							[/variable]
							[variable]
							name=passed
							equals=no
							[/variable]
							[have_unit]
							x,y=$xloc,$yloc
							side=$unit.side
							[/have_unit]
						[/or]
						[then]
							[store_unit]
								variable=passto
								[filter]
								x,y=$xloc,$yloc
								[/filter]
							[/store_unit]
							[if]
								[variable]
								name=passto.variables.has_ball1
								not_equals=yes
								[/variable]
								[then]
									[message]
									speaker=unit
									message= _ "Should I pass the ball to $passto.type ($xloc,$yloc)?"
										[option]
										message= _ "Yes!"
											[command]
											{VARIABLE passed yes}
											{VARIABLE unit.variables.has_ball2 no}
											{VARIABLE passto.variables.has_ball2 yes}
												[unstore_unit]
												variable=passto
												[/unstore_unit]
												[unstore_unit]
												variable=unit
												[/unstore_unit]
												[remove_unit_overlay]
												x,y=$x1,$y1
												image=items/ball.png
												[/remove_unit_overlay]
												[unit_overlay]
												x,y=$xloc,$yloc
												image=items/ball.png
												[/unit_overlay]
											[/command]
										[/option]
										[option]
										message= _ "No"
										[/option]
									[/message]
								[/then]
							[/if]
						[/then]
					[/if]

				{NEXT i}
			[/then]
		[/if]
	[/event]

	[event]
	name=time over
		[if]
			[variable]
			name=redscore
			less_than=$bluescore
			[/variable]
			[then]
				[message]
				speaker=narrator
				message= _ "Blue team wins! Final score: $redscore-$bluescore"
				[/message]
			[/then]
		[/if]
		[if]
			[variable]
			name=redscore
			greater_than=$bluescore
			[/variable]
			[then]
				[message]
				speaker=narrator
				message= _ "Red team wins! Final score: $redscore-$bluescore"
				[/message]
			[/then]
		[/if]
		[if]
			[variable]
			name=redscore
			equals=$bluescore
			[/variable]
			[then]
				[message]
				speaker=narrator
				message= _ "Draw! Final score: $redscore-$bluescore"
				[/message]
			[/then]
		[/if]

		[endlevel]
		result=continue
		[/endlevel]
	[/event]

	#if a unit dies, then it gets sent to its side's starting location
	[event]
	name=die
	first_time_only=no
		#give the unit an injury
		[object]
			silent=yes
			[filter]
			x,y=$x1,$y1
			[/filter]
			[effect]
			apply_to=movement
			increase=-25%
			[/effect]
			[effect]
			apply_to=hitpoints
			increase_total=-25%
			heal_full=yes
			[/effect]
			#in case of Orcish Slayers
			[effect]
			apply_to=status
			remove=poisoned
			[/effect]
		[/object]

		[store_unit]
			variable=unit
			kill=yes
			[filter]
			x,y=$x1,$y1
			[/filter]
		[/store_unit]
		[if]
			[variable]
			name=unit.side
			equals=1
			[/variable]
			[then]
				{VARIABLE unit.x 2}
				{VARIABLE unit.y 10}
			[/then]
			[else]
				{VARIABLE unit.x 40}
				{VARIABLE unit.y 10}
			[/else]
		[/if]

		[unstore_unit]
		find_vacant=yes
		variable=unit
		[/unstore_unit]
	[/event]

#undef WESBOWL_UNIT
#undef WESBOWL_SIDE
#undef WESBOWL_SIDE_DEFS

[/multiplayer]
