;;; Sierra Script 1.0 - (do not remove this comment)
(script# 31)
(include sci.sh)
(use Main)
(use Class_255_0)
(use Sound)
(use Cycle)
(use Game)
(use User)
(use Feature)
(use Obj)

(public
	Room31 0
)

(local
	newProp
	local1
	local2
	local3
	newView
	newAct
	newAct_2
	local7
	newProp_2
	newAct_3
	local10
	local11
	local12
	local13
)
(instance whaleMusic of Sound
	(properties
		number 36
	)
)

(instance sharkMusic of Sound
	(properties
		number 78
		loop -1
	)
)

(instance Room31 of Rm
	(properties
		style $0009
	)
	
	(method (init)
		(= horizon 75)
		(= global101 0)
		(= local12 4)
		(if global223
			(= newProp (Prop new:))
			(newProp
				view: 650
				loop: 1
				cel: 1
				posn: 155 57
				setPri: 0
				ignoreActors:
				setCycle: Fwd
				init:
				hide:
			)
		)
		(self setRegions: 519 504)
		(Load rsVIEW 8)
		(Load rsVIEW 10)
		(Load rsVIEW 300)
		(Load rsVIEW 84)
		(Load rsVIEW 887)
		(Load rsSOUND 78)
		(if (<= (gEgo y?) (+ gHorizon 2))
			(gEgo y: (- horizon 1))
		)
		(= gHorizon horizon)
		(switch gPrevRoomNum
			(43
				(if (== (gEgo view?) 312)
					(if global100
						(gRoom drawPic: 131)
					else
						(gRoom drawPic: 31)
					)
					(= local2 4)
					(= local1 2)
					(User canControl: 0)
					(= global205 1)
					(gEgo posn: 5 100 setMotion: MoveTo 400 113)
				else
					(= local2 100)
					(= local1 100)
				)
			)
			(44
				(= local2 99)
				(= local1 100)
				((= newView (View new:))
					view: 526
					loop: 0
					cel: 0
					posn: 134 54
					init:
				)
				(if (IsObject newProp) (newProp hide:))
				(if global100
					(gRoom drawPic: 131)
				else
					(gRoom drawPic: 31)
				)
				(gEgo setScript: whaleActions)
				(whaleActions changeState: 10)
			)
			(1 (= local2 4) (= local1 0))
			(95 (= local2 3) (= local1 1))
			(13 (= local2 2) (= local1 0))
			(19 (= local2 1) (= local1 0))
			(25 (= local2 0) (= local1 0))
			(32
				(cond 
					((<= (gEgo x?) 0) (= local2 1) (= local1 5))
					((>= (gEgo y?) 189) (= local2 1) (= local1 3))
					((>= (gEgo x?) 319) (= local2 1) (= local1 3))
					(else (= local2 1) (= local1 3))
				)
			)
			(39 (= local2 2) (= local1 5))
			(41 (= local1 3) (= local2 2))
			(36 (= local2 3) (= local1 5))
			(38 (= local2 3) (= local1 3))
			(33 (= local2 4) (= local1 5))
			(34 (= local2 4) (= local1 4))
			(35 (= local2 4) (= local1 3))
		)
		(= local3 0)
		(= local11 0)
		(if (!= (gEgo view?) 312)
			(if (!= (gEgo view?) 84)
				(gEgo setCycle: Fwd)
				(gEgo view: 8 init: hide: xStep: 2 yStep: 1)
			)
		else
			(gEgo setCycle: Fwd)
			(gEgo init: xStep: 4 yStep: 2)
		)
		(if
			(and
				(== global109 1)
				(< (Random 1 100) 40)
				(!= global105 14)
				(== global183 0)
				(< local1 30)
				(!= (gEgo script?) sharkActions)
			)
			(gEgo setScript: whaleActions)
		)
		(gEgo edgeHit: 0)
		(super init:)
		(self doit:)
		(= local13 local2)
	)
	
	(method (doit)
		(super doit:)
		(if
			(and
				(not global100)
				(== (gRoom script?) 0)
				(== (Random 1 100) 9)
			)
			(gRoom setScript: fish3Actions)
		)
		(if
			(and
				(== (gRoom script?) 0)
				(not global100)
				(== (Random 1 100) 10)
			)
			(gRoom setScript: fishActions)
		)
		(if (gEgo edgeHit?)
			(++ local3)
			(= global136 local1)
			(= global137 local2)
			(if (!= (gEgo view?) 312)
				(if (and (== local3 1) global100)
					(= local1 1000)
					(= local2 1000)
				)
				(if (== local3 4) (Print 31 17))
				(if
					(and
						(== local3 local12)
						(!= (gEgo script?) sharkActions)
					)
					(gEgo setScript: drown)
					(drown changeState: 1)
					1
				)
			)
			(cond 
				((== (gEgo edgeHit?) 1)
					(if (and (< (++ local2) 10) (> local2 4))
						(= local2 0)
					)
					(gEgo posn: (gEgo x?) 188)
				)
				((== (gEgo edgeHit?) 3)
					(if (< (-- local2) 0) (= local2 4))
					(gEgo posn: (gEgo x?) (+ horizon (gEgo yStep?) 2))
				)
				((== (gEgo edgeHit?) 2) (-- local1) (gEgo posn: 1 (gEgo y?)))
				((== (gEgo edgeHit?) 4) (++ local1) (gEgo posn: 318 (gEgo y?)))
			)
			(cond 
				((and (== local1 100) (== local2 100)) (gRoom newRoom: 43))
				((and (== local1 1) (== local2 3)) (gRoom newRoom: 95))
				((== local1 0)
					(switch local2
						(4 (gRoom newRoom: 1))
						(2 (gRoom newRoom: 13))
						(1 (gRoom newRoom: 19))
						(0 (gRoom newRoom: 25))
					)
				)
				(
					(and
						(== local2 1)
						(or (== local1 3) (== local1 4) (== local1 5))
					)
					(gRoom newRoom: 32)
				)
				((and (== local2 2) (== local1 3)) (gRoom newRoom: 41))
				((and (== local2 2) (== local1 5)) (gRoom newRoom: 39))
				((and (== local2 3) (== local1 3))
					(if (== local13 4)
						(gEgo y: 100)
						(gRoom newRoom: 41)
					else
						(gEgo y: 170)
						(gRoom newRoom: 35)
					)
				)
				((and (== local2 3) (== local1 5))
					(if (<= (gEgo y?) 120)
						(gRoom newRoom: 33)
					else
						(gRoom newRoom: 39)
					)
				)
				((and (== local2 4) (== local1 3)) (if (!= (gEgo view?) 312) (gRoom newRoom: 35)))
				((and (== local2 4) (== local1 4)) (if (!= (gEgo view?) 312) (gRoom newRoom: 34)))
				(
					(and
						(== local2 4)
						(== local1 5)
						(!= (gEgo view?) 312)
					)
					(gRoom newRoom: 33)
				)
			)
			(cond 
				((== (gEgo script?) sharkActions)
					(if (gCast contains: newAct_3)
						(cond 
							((< (gEgo x?) 10) (newAct_3 posn: (- (gEgo x?) 30) (gEgo y?)))
							((> (gEgo x?) 300) (newAct_3 posn: (+ (gEgo x?) 30) (gEgo y?)))
							((< (gEgo y?) (+ horizon 10)) (newAct_3 posn: (+ (gEgo x?) 20) (gEgo y?)))
							((> (gEgo y?) 174) (newAct_3 posn: (gEgo x?) (+ (gEgo y?) 30)))
							(else (newAct_3 posn: (- (gEgo x?) 20) (- (gEgo y?) 20)))
						)
					)
				)
				(
					(and
						(or
							(and (== local2 0) (> local1 2) (<= local1 5))
							(and
								(== local2 0)
								(<= local1 2)
								(> (Random 1 100) 50)
							)
							(and (!= global100 0) (<= (Random 100) 40))
							(<= (Random 1 100) 20)
						)
						(!= (gEgo view?) 312)
						(!= (gEgo script?) sharkActions)
						(!= (gEgo script?) whaleActions)
					)
					(gEgo setScript: sharkActions)
				)
			)
			(if (== gNewRoomNumber_2 31)
				(if (gCast contains: newAct)
					(newAct dispose:)
					(gRoom setScript: 0)
				)
				(if (gCast contains: newAct_2)
					(newAct_2 dispose:)
					(gRoom setScript: 0)
				)
				(if
					(and
						(not (if (== local2 99) (== local1 100)))
						(gCast contains: newView)
					)
					(newView dispose:)
					(if (IsObject newProp) (newProp show:))
				)
				(if global100
					(gAddToPics dispose:)
					(gRoom drawPic: 131 9)
					(if (gCast contains: newProp_2)
						(gEgo setScript: 0)
						(newProp_2 dispose:)
						(whaleMusic dispose:)
					)
				else
					(gAddToPics dispose:)
					(gRoom drawPic: 31 9)
					(if (gCast contains: newProp_2)
						(gEgo setScript: 0)
						(newProp_2 dispose:)
						(whaleMusic dispose:)
					)
				)
				(cond 
					((and (== local1 100) (== local2 99))
						(if (not (gCast contains: newView))
							((= newView (View new:))
								view: 526
								loop: 0
								cel: 0
								posn: 134 54
								init:
							)
							(if (IsObject newProp) (newProp hide:))
						)
					)
					((IsObject newProp) (newProp show:))
				)
				(if (not global100)
					((View new:)
						view: 671
						cel: (Random 0 9)
						x: (Random 10 319)
						y: (Random 20 30)
						setPri: 0
						ignoreActors:
						init:
						addToPic:
					)
					((View new:)
						view: 671
						cel: (Random 0 9)
						x: (Random 10 319)
						y: (Random 20 30)
						setPri: 0
						ignoreActors:
						init:
						addToPic:
					)
					((View new:)
						view: 671
						cel: (Random 0 9)
						x: (Random 10 319)
						y: (Random 20 30)
						setPri: 0
						ignoreActors:
						init:
						addToPic:
					)
				)
				(if (!= (gEgo view?) 312) (gEgo setMotion: 0 show:))
			)
		)
	)
	
	(method (dispose)
		(gEgo setLoop: -1)
		(super dispose:)
	)
	
	(method (handleEvent pEvent &tmp gInvSaidMe)
		(if (pEvent claimed?) (return 1))
		(return
			(if (== (pEvent type?) evSAID)
				(cond 
					((Said 'look[<around][/room,ocean,ocean,water]')
						(cond 
							((and (== local2 99) (== local1 100)) (Print 31 0))
							(global100 (Print 31 1))
							((== global105 14) (Print 31 2))
							(else (Print 31 3))
						)
						(if (gCast contains: newAct_3) (Print 31 4))
					)
					((Said 'mount/dolphin')
						(if (== (gEgo view?) 312)
							(Print 31 5)
						else
							(Print 31 6)
						)
					)
					((Said '/shark')
						(if (gCast contains: newAct_3)
							(Print 31 7)
						else
							(Print 31 6)
						)
					)
					((Said 'look/island')
						(if (and (== local2 99) (== local1 100))
							(Print 31 8)
						else
							(Print 31 9)
						)
					)
					((== (gEgo view?) 312)
						(cond 
							((Said 'look/dolphin') (Print 31 10))
							((Said 'kiss/dolphin') (Print 31 11))
							((Said 'deliver>')
								(cond 
									((Said '/*/fish') (Print 31 12))
									((Said '/*/bird,gull') (Print 31 13))
									(
										(and
											(Said '/*/dolphin>')
											(= gInvSaidMe (gInv saidMe:))
										)
										(if (gEgo has: (gInv indexOf: gInvSaidMe))
											(Print 31 14)
										else
											(proc0_17)
										)
									)
								)
							)
							((Said 'converse[/dolphin]') (Print 31 15))
							((Said 'pat/dolphin') (Print 31 16))
							(else (pEvent claimed: 0))
						)
					)
				)
			else
				0
			)
		)
	)
)

(instance fish3Actions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(= newAct (Act new:))
				(= local10 (Random 5 304))
				(= local7 (Random (+ (gRoom horizon?) 10) 179))
				(newAct
					view: 300
					loop: 0
					cel: 255
					posn: local10 local7
					setCycle: End self
					init:
				)
				(if (< (newAct distanceTo: gEgo) 30)
					(newAct setCel: 0)
					(fish3Actions changeState: 1)
				)
			)
			(1
				(if (gCast contains: newAct) (newAct dispose:))
				(= seconds 3)
			)
			(2 (gRoom setScript: 0))
		)
	)
)

(instance fishActions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(= newAct_2 (Act new:))
				(= local10 (Random 5 304))
				(= local7 (Random (+ (gRoom horizon?) 10) 179))
				(newAct_2
					view: 301
					loop: 0
					cel: 255
					posn: local10 local7
					setCycle: End self
					init:
				)
				(if (< (newAct_2 distanceTo: gEgo) 30)
					(newAct_2 setCel: 0)
					(fishActions changeState: 1)
				)
			)
			(1
				(if (gCast contains: newAct_2) (newAct_2 dispose:))
				(= seconds 3)
			)
			(2 (gRoom setScript: 0))
		)
	)
)

(instance drown of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(1 (= seconds 10))
			(2
				(proc0_8)
				(gEgo
					view: 10
					setMotion: 0
					loop: 0
					cel: 255
					setCycle: End self
				)
			)
			(3
				(gEgo cel: 255 setCycle: End self)
			)
			(4
				(gEgo cel: 255 setCycle: End self)
			)
			(5
				(gEgo hide:)
				(if global100
					(Print 31 18 67 -1 10)
				else
					(Print 31 19 67 -1 10)
				)
				(= global127 1)
			)
		)
	)
)

(instance whaleActions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0 (= seconds (Random 2 8)))
			(1
				(= newProp_2 (Prop new:))
				(whaleMusic play:)
				(newProp_2
					view: 315
					cel: 255
					loop: 0
					posn: 120 66
					init:
					setCycle: End self
				)
			)
			(2
				(if (gCast contains: newProp_2)
					(newProp_2 loop: 1 setCycle: Fwd)
					(= seconds 3)
				)
			)
			(3
				(if (gCast contains: newProp_2)
					(newProp_2 loop: 2 cel: 255 setCycle: End self)
				)
			)
			(4
				(if (gCast contains: newProp_2) (newProp_2 dispose:))
				(= seconds 5)
			)
			(5
				(if (> (gEgo y?) 93)
					(proc0_8)
					(gEgo
						view: 84
						setMotion: 0
						cel: 255
						setLoop: 0
						setCycle: End self
					)
				else
					(self changeState: 12)
				)
			)
			(6
				(gEgo hide:)
				(proc0_9)
				(gRoom newRoom: 44)
			)
			(10
				(= seconds 0)
				(gEgo
					view: 84
					setLoop: 1
					cel: 255
					posn: 160 129
					setCycle: End self
					init:
				)
			)
			(11
				(Print 31 20)
				(gEgo view: 8 setCycle: Fwd setLoop: -1)
				(proc0_9)
				(gEgo script: 0)
			)
		)
	)
)

(instance sharkActions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0 (= seconds (Random 1 5)))
			(1
				(sharkMusic play:)
				((= newAct_3 (Act new:))
					ignoreHorizon:
					posn: (Random 100 200) (Random 75 189)
					view: 887
					setCycle: Walk
					ignoreActors:
					xStep: 5
					yStep: 4
					setMotion: Chase gEgo 10 self
					init:
				)
			)
			(2
				(proc0_8)
				(gEgo
					setMotion: 0
					view: 10
					loop: 0
					cel: 6
					setCycle: End self
				)
			)
			(3
				(gEgo hide:)
				(sharkMusic dispose:)
				(if (gCast contains: newAct_3)
					(newAct_3 setMotion: MoveTo -20 100)
				)
				(= seconds 3)
			)
			(4
				(= global204 0)
				(Print 31 21 67 -1 10)
				(= global127 1)
			)
		)
	)
)
