
global Score
global End
run script Bowling

begin script ChallengeNotify(Location, Radius)
	Spirit = 0
start
	wait until camera position near [Location] radius Radius and Location viewed
	begin dialogue
		eject good spirit
		make good spirit point to Location
		say "Have a game of bowling!"
		wait until read
		say "Try to get a strike!"
		wait until read
	end dialogue
end script ChallengeNotify

begin script BowlingBall(Cow)
	TmpPos = 0
	CowPos = marker at [Cow]
	Standing = 1
start
	begin loop
/*	when Cow not exists
		Cow = create ANIMAL BOVINE at [CowPos]
		Standing = 1
	when HEALTH of Cow<=0.1 and Cow is not FLYING
		say "Cow died"
		TmpPos = marker at [Cow]
		delete Cow
		Cow = create ANIMAL BOVINE at [TmpPos]
		if(Standing==0)
			Score--
			Standing=1
		end if */
	when Cow is FLYING or Cow is HELD and Standing==1
		Score++
		Standing=0
	when Cow is not FLYING and Cow is not HELD and Standing==0
		Score--
		Standing=1
	when [Cow] not near [CowPos] radius 20
		set Cow position to [CowPos]
	when [Cow] not at [CowPos]
		move Cow position to [CowPos]
	end loop
until End==1
end script BowlingBall

begin script BowlingPin(Man)
	ManPos = marker at [Man]
	TmpPos = 0
	Standing = 1
	Moving = 0
start
	begin loop
	when Man not exists
		Man = create VILLAGER MALE at [ManPos]
		Standing = 1
		Moving = 0
	when HEALTH of Man<=0.1 and Man is not FLYING
		say "Man died"
		TmpPos = marker at [Man]
		delete Man
		Man = create VILLAGER MALE at [TmpPos]
		if(Standing==0)
			Score--
			Standing=1
		end if
	when Man is FLYING and Standing==1
		say "Man got knocked over"
		Score++
		Standing=0
	when Man is not FLYING and Standing==0
		say "Man stood up"
		Score--
		Standing=1
	when [Man] not at [ManPos] and Moving==0
		say "Moving Man"
		move Man position to [ManPos]
		Moving=1
	when [Man] at [ManPos] and Moving==1
		Moving=0
	end loop
until End==1
end script BowlingPin

begin script Bowling
	PinPos = marker at hand position
	CowPos = marker at [PinPos] + [10,10]
	Size = 0.8
	Spirit = 0
	Lock = 0
start
	Score = 0
	End = 0
	run background script BowlingBall(create ANIMAL BOVINE at [CowPos])
	run background script BowlingPin(create VILLAGER MALE at [PinPos]+[0,0,0])
	run background script BowlingPin(create VILLAGER MALE at [PinPos]+[-Size,0,2*Size])
	run background script BowlingPin(create VILLAGER MALE at [PinPos]+[Size,0,2*Size])
	run background script BowlingPin(create VILLAGER MALE at [PinPos]+[-2*Size,0,4*Size])
	run background script BowlingPin(create VILLAGER MALE at [PinPos]+[0,0,4*Size])
	run background script BowlingPin(create VILLAGER MALE at [PinPos]+[2*Size,0,4*Size])
	run background script BowlingPin(create VILLAGER MALE at [PinPos]+[-3*Size,0,6*Size])
	run background script BowlingPin(create VILLAGER MALE at [PinPos]+[-Size,0,6*Size])
	run background script BowlingPin(create VILLAGER MALE at [PinPos]+[Size,0,6*Size])
	run background script BowlingPin(create VILLAGER MALE at [PinPos]+[3*Size,0,6*Size])
	run script ChallengeNotify(CowPos, 60)
	begin loop
	until End==1
	when Score>0 and Lock==0
	begin game speed
		say "Slow-mo"
		set game speed to 0.5
		Lock=1
	end game speed
	when Score==0 and Lock!=0
	begin game speed
		say "Normal"
		set game speed to 1.0
		Lock=0
	end game speed

	when Score==11
		begin dialogue
			eject good spirit
			make good spirit point to PinPos
			say "You got a strike!"
			wait until read
		end dialogue
		End=1
	end loop
	say "Thanks for playing!"
	wait until read
end script Bowling
