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

(public
	Room43 0
)
(synonyms
	(dolphin dolphin)
)

(local
	gEgoViewer
	local1
	local2
	local3
	newAct
	newAct_4
	newAct_3
	newProp_4
	newAct_2
	newProp_2
	newProp_3
	local11
	local12
	local13
	[local14 2]
	newProp
)
(instance whistleSound of Sound
	(properties)
)

(instance dolphinTheme of Sound
	(properties
		number 35
	)
)

(instance Room43 of Rm
	(properties)
	
	(method (init)
		(if global100 (= picture 143) else (= picture 43))
		(= south (= north (= west (= east 31))))
		(= horizon 78)
		(= global101 0)
		(= gHorizon horizon)
		(super init:)
		(if (gEgo has: 24)
			(Load rsVIEW 312)
			(Load rsVIEW 311)
			(Load rsVIEW 310)
			(Load rsVIEW 524)
			(Load rsVIEW 306)
			(Load rsSOUND 35)
			(Load rsSOUND 76)
		)
		(Load rsVIEW 320)
		(Load rsVIEW 321)
		(Load rsVIEW 15)
		(Load rsVIEW 670)
		(Load rsVIEW 518)
		(self setRegions: 501 504)
		((View new:)
			view: 670
			posn: 50 142
			setPri: 0
			ignoreActors:
			addToPic:
		)
		((View new:)
			view: 670
			loop: 1
			cel: 2
			posn: 151 174
			setPri: 0
			ignoreActors:
			addToPic:
		)
		((View new:)
			view: 670
			loop: 2
			posn: 284 183
			setPri: 0
			ignoreActors:
			addToPic:
		)
		((View new:)
			view: 670
			loop: 3
			cel: 2
			posn: 301 145
			setPri: 0
			ignoreActors:
			addToPic:
		)
		((View new:)
			view: 670
			loop: 4
			posn: 24 74
			setPri: 0
			ignoreActors:
			addToPic:
		)
		((View new:)
			view: 670
			loop: 5
			cel: 1
			posn: 258 77
			setPri: 0
			ignoreActors:
			addToPic:
		)
		((= newProp (Prop new:))
			view: 670
			posn: 50 142
			setPri: 0
			ignoreActors:
			cycleSpeed: 2
			init:
			setScript: waveScript
		)
		(if (or (gEgo has: 27) (gEgo has: 24)) (= local11 1))
		(cond 
			((and (== global136 101) (== global137 100)) (gEgo posn: 13 91))
			((and (== global136 99) (== global137 100)) (gEgo posn: 294 84))
			((and (== global136 100) (== global137 99)) (gEgo posn: 38 171))
			((and (== global136 100) (== global137 101)) (gEgo posn: (gEgo x?) (+ horizon (gEgo yStep?) 1)))
		)
		(= newProp_2 (Prop new:))
		(newProp_2 setScript: deathTimer init: hide:)
		((= newProp_3 (Prop new:)) init: hide:)
		(if ((Inv at: 27) ownedBy: 207)
			(= newAct (Act new:))
			(newAct
				ignoreHorizon:
				posn: 118 73
				view: 320
				loop: 0
				setPri: 7
				illegalBits: 0
				ignoreActors:
				setCycle: Fwd
				cycleSpeed: 1
				xStep: 5
				yStep: 4
				init:
			)
			(newAct setScript: pelActions)
		)
		(if ((Inv at: 27) ownedBy: 43)
			((= newAct_2 (Act new:))
				posn: 137 106
				ignoreActors:
				illegalBits: 0
				view: 524
				setLoop: 1
				setCel: 0
				setCycle: 0
				init:
				stopUpd:
			)
			(newAct_2 setScript: whistleActions)
			(whistleActions changeState: 1)
		)
		(gEgo view: 8 setStep: 3 2 setScript: bridleActions init:)
	)
	
	(method (dispose)
		(gTimers eachElementDo: #dispose 84)
		(super dispose:)
	)
	
	(method (handleEvent pEvent &tmp gInvSaidMe)
		(if (pEvent claimed?) (return 1))
		(return
			(if (== (pEvent type?) evSAID)
				(cond 
					((Said 'look[<around][/room]') (Print 43 0))
					((Said 'bathe')
						(cond 
							((== (gEgo view?) 2) (Print 43 1))
							((== (gEgo view?) 8) (Print 43 2))
							(
								(or
									(== (gEgo view?) 5)
									(== (gEgo view?) 6)
									(== (gEgo view?) 7)
								)
								(Print 43 3)
							)
							(else (Print 43 4))
						)
					)
					((Said 'get,drink[/drink,water]')
						(cond 
							((!= global105 0) (Print 43 5))
							(
								(or
									(& (= local13 (proc0_2 gEgo 12)) $0008)
									(& local13 $0800)
									(& local13 $0002)
									(& local13 $0200)
								)
								(= gGEgoScript (gEgo script?))
								(gEgo setScript: drinking)
								(drinking changeState: 1)
							)
							(else (Print 800 1))
						)
					)
					((Said 'fish') (Print 43 6))
					((Said 'get,capture/fish') (Print 43 6))
					((Said 'look,find/tamir') (Print 43 7))
					((Said 'look>')
						(cond 
							((Said '/fish')
								(if (gEgo has: 24)
									((Inv at: 24) showSelf:)
								else
									(Print 43 6)
								)
							)
							((Said '/dolphin')
								(cond 
									((gCast contains: newAct_3) (Print 43 8))
									((== (gEgo view?) 312) (Print 43 9))
									(else (Print 43 10))
								)
							)
							((Said '/island') (Print 43 11))
							((Said '<under/water,ocean')
								(if (== (gEgo view?) 2)
									(Print 43 12)
								else
									(Print 43 13)
								)
							)
							((Said '/ocean,water') (Print 43 14))
							((Said '/beach') (Print 43 15))
							(
								(or
									(Said '/dirt')
									(Said '<down')
									(Said '<in/boat,shipwreck')
								)
								(cond 
									(
										(and
											(gEgo inRect: 218 107 254 116)
											((Inv at: 21) ownedBy: 43)
										)
										(gGame changeScore: 3)
										(bridleActions changeState: 1)
									)
									((gCast contains: newAct_2) (Print 43 16))
									(
										(and
											(gEgo inRect: 194 97 310 135)
											((Inv at: 21) ownedBy: 43)
										)
										(Print 43 17)
									)
									(else (Print 43 18))
								)
							)
							((Said '/forest,flora,palm') (Print 43 19))
							((Said '/coconut') (Print 43 20))
							((Said '/boat,shipwreck')
								(Print
									(Format
										@global228
										43
										21
										(if ((Inv at: 21) ownedBy: 43)
											{You see a glint coming from one of the wrecked boats on the beach.}
										else
											{_}
										)
									)
								)
							)
							((Said '/pelican,bird')
								(if (!= local1 4)
									(Print 43 22)
								else
									(Print 43 23)
								)
							)
						)
					)
					((Said 'climb/forest,palm') (Print 43 24))
					((Said 'deliver,fling,feed/fish')
						(if (gEgo has: 24)
							(if (== (gEgo view?) 2)
								(switch local1
									(1
										(if (< (gEgo distanceTo: newAct) 80)
											(if (> (gEgo x?) 121)
												(gGame changeScore: 4)
												(pelActions changeState: 20)
											else
												(Print 43 25)
											)
										else
											(Print 800 1)
										)
									)
									(2 (Print 43 26))
									(3 (Print 43 27))
									(else  (Print 43 28))
								)
							else
								(Print 43 28)
							)
						else
							(Print 43 29)
						)
					)
					((Said 'get,whistle/whistle')
						(cond 
							(((Inv at: 27) ownedBy: 43)
								(if (< (gEgo distanceTo: newAct_2) 15)
									(bridleActions changeState: 10)
									(gGame changeScore: 2)
									(gEgo get: 27)
								else
									(Print 800 1)
								)
							)
							((gEgo has: 27) (Print 43 30))
							(else (Print 43 10))
						)
					)
					((Said 'mount/dolphin')
						(if (gCast contains: newAct_3)
							(if (< (gEgo distanceTo: newAct_3) 14)
								(User canControl: 0)
								(= global205 1)
								(gGame changeScore: 2)
								(dolphActions changeState: 10)
							else
								(Print 800 1)
							)
						else
							(Print 43 31)
						)
					)
					((Said 'play,whistle,blow[/whistle]')
						(if (gEgo has: 27)
							(gSounds eachElementDo: #stop 0)
							(whistleSound number: 76 play:)
							(if (not newAct_3)
								(if (== global217 0)
									(gGame changeScore: 2)
									(= global217 1)
								)
								((= newAct_3 (Act new:)) x: -1000 y: 1000 init:)
								(gRoom setScript: dolphActions)
							else
								(Print 43 32)
							)
						else
							(Print 43 33)
						)
					)
					((Said 'converse>')
						(cond 
							(
								(and
									(gCast contains: newAct)
									(newAct inRect: 0 0 319 189)
									(Said '[/pelican,bird]')
								)
								(Print 43 34)
								(pEvent claimed: 1)
							)
							(
							(and (gCast contains: newAct_3) (Said '[/dolphin]')) (Print 43 35) (pEvent claimed: 1))
							((Said '/bird,gull,gull') (pEvent claimed: 0))
							((Said '[/!*]') (Print 43 36))
						)
					)
					((Said 'feed/pelican,bird')
						(if (and (gCast contains: newAct) (!= local1 4))
							(Print 43 37)
						else
							(Print 43 10)
						)
					)
					((Said 'get/pelican,bird')
						(if (and (gCast contains: newAct) (!= local1 4))
							(Print 43 38)
						else
							(Print 43 10)
						)
					)
					((Said 'capture/pelican,bird')
						(if (and (gCast contains: newAct) (!= local1 4))
							(Print 43 39)
						else
							(Print 43 10)
						)
					)
					((Said 'kiss')
						(cond 
							((and (gCast contains: newAct) (!= local1 4)) (Print 43 39))
							((gCast contains: newAct_3) (Print 43 40))
							(else (pEvent claimed: 0))
						)
					)
					((Said 'deliver>')
						(if (= gInvSaidMe (gInv saidMe:))
							(if (gEgo has: (gInv indexOf: gInvSaidMe))
								(cond 
									(
										(or
											(and (!= local1 4) (gCast contains: newAct))
											(Said '/pelican,bird')
										)
										(Print 43 41)
									)
									(
									(and (gCast contains: newAct_3) (Said '/dolphin')) (Print 43 42))
									(else (Print 43 43) (pEvent claimed: 1))
								)
							else
								(proc0_17)
							)
						)
					)
					((Said 'get,capture/dolphin')
						(cond 
							((gCast contains: newAct_3) (Print 43 44))
							((== (gEgo view?) 312) (Print 43 45))
							(else (Print 43 10))
						)
					)
					((Said 'deliver>')
						(if
							(and
								(= gInvSaidMe (gInv saidMe:))
								(gEgo has: (gInv indexOf: gInvSaidMe))
							)
							(Print 43 46)
						else
							(Print 43 47)
						)
					)
					((Said 'pat/dolphin')
						(if (gCast contains: newAct_3)
							(if (< (gEgo distanceTo: newAct_3) 12)
								(Print 43 48)
							else
								(Print 800 1)
							)
						else
							(Print 43 10)
						)
					)
				)
			else
				0
			)
		)
	)
)

(instance bridleActions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(1
				(proc0_8)
				(gEgo get: 21 setMotion: 0)
				(= gEgoViewer (gEgo viewer?))
				(gEgo
					viewer: 0
					view: 21
					loop: 1
					cel: 255
					setCycle: End self
				)
			)
			(2
				(= global182 1)
				(gEgo setCycle: Beg self)
			)
			(3
				(Print 43 49 67 -1 10)
				(gEgo viewer: gEgoViewer view: 2 setCycle: Walk)
				(proc0_9)
			)
			(10
				(proc0_8)
				(= gEgoViewer (gEgo viewer?))
				(proc0_3 gEgo newAct_2)
				(gEgo
					viewer: 0
					view: 21
					loop: 1
					cel: 255
					setCycle: End self
				)
			)
			(11
				(newAct_2 dispose:)
				(newProp_4 dispose:)
				(= global182 1)
				(gEgo setCycle: Beg self)
			)
			(12
				(gEgo viewer: gEgoViewer view: 2 setCycle: Walk)
				(proc0_9)
			)
		)
	)
)

(instance pelActions of Script
	(properties)
	
	(method (doit)
		(if
		(and (== local1 1) (gEgo inRect: 95 92 140 110))
			(pelActions changeState: 10)
		)
	)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(if (gCast contains: newAct)
					(= local1 1)
					(newProp_3 setScript: pelMovement)
					((ScriptID 0 5) setReal: self 30)
				)
			)
			(1 (self changeState: 10))
			(10
				((ScriptID 0 5) dispose: delete:)
				(++ local2)
				(newProp_3 setScript: 0)
				(= local1 2)
				(newAct
					view: 321
					setLoop: 2
					setCel: -1
					cel: 0
					cycleSpeed: 0
					setCycle: End self
				)
			)
			(11
				(newAct
					setLoop: 0
					cel: 0
					setCycle: Fwd
					setMotion: MoveTo 339 20 self
				)
			)
			(12
				(newAct stopUpd:)
				(= local1 4)
				((ScriptID 0 5) setReal: self 1 1)
			)
			(13
				(if
				(and (not (gEgo inRect: 192 108 237 125)) (< local2 3))
					(= local1 2)
					(newAct
						startUpd:
						posn: -20 20
						setCycle: Fwd
						setMotion: MoveTo 118 74 self
					)
				else
					(self changeState: 11)
				)
			)
			(14
				(newAct loop: 1 cel: 255 setCycle: End self)
			)
			(15
				(newAct view: 320 setLoop: 0 cycleSpeed: 1 setCycle: Fwd)
				(= local1 1)
				(newProp_3 setScript: pelMovement)
			)
			(20
				(proc0_8)
				(if (IsObject (ScriptID 0 5))
					((ScriptID 0 5) dispose: delete:)
				)
				(whistleSound number: 63 play:)
				(newProp_3 setScript: 0)
				(= local1 3)
				(proc0_3 gEgo newAct)
				(= gEgoViewer (gEgo viewer?))
				(gEgo viewer: 0 loop: (& (gEgo loop?) $0001))
				(gEgo
					view: 15
					cel: 255
					setMotion: 0
					loop: (& (gEgo loop?) $0001)
					setCycle: End self
				)
			)
			(21
				(= newAct_4 (Act new:))
				(if (gEgo loop?)
					(newAct_4
						posn: (- (gEgo x?) 10) (- (gEgo y?) 15)
						init:
					)
				else
					(newAct_4
						posn: (+ (gEgo x?) 10) (- (gEgo y?) 15)
						init:
					)
				)
				(newAct_4
					view: 306
					ignoreActors:
					illegalBits: 0
					ignoreHorizon:
					setPri: 6
					setLoop: 0
					cel: 0
					setCycle: Fwd
					setMotion: MoveTo (+ (newAct x?) 8) (- (newAct y?) 7) self
				)
				(gEgo viewer: gEgoViewer view: 2 setCycle: Walk)
				(newAct setLoop: 1 setCel: -1 cel: 255 setCycle: End)
			)
			(22
				(= newAct_2 (Act new:))
				(newAct_2 setScript: whistleActions)
				(newAct_2
					posn: 123 63
					ignoreActors:
					illegalBits: 0
					view: 524
					setLoop: 0
					cel: 0
					setMotion: MoveTo 137 106 whistleActions
					yStep: 10
					setCycle: Fwd
					init:
				)
				(newAct setLoop: 2 cel: 255 setCycle: End self)
				(newAct_4 dispose:)
				((Inv at: 27) moveTo: 43)
			)
			(23
				(Print 43 50)
				((Inv at: 24) moveTo: 207)
				(= local2 99)
				(proc0_9)
				(self changeState: 10)
			)
		)
	)
)

(instance whistleActions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(1
				(newAct_2 setCel: 0 setLoop: 1 setCycle: 0 stopUpd:)
				(= newProp_4 (Prop new:))
				(newProp_4
					view: 518
					setLoop: 4
					ignoreActors:
					posn: (newAct_2 x?) (newAct_2 y?)
					init:
				)
				(self changeState: 2)
			)
			(2
				(newProp_4 cel: 255 setCycle: End self show:)
			)
			(3
				(newProp_4 hide:)
				(= seconds (Random 3 10))
			)
			(4 (self changeState: 2))
		)
	)
)

(instance dolphActions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0 (= seconds 4))
			(1
				(gSounds eachElementDo: #stop 0)
				(dolphinTheme play:)
				(newAct_3
					posn: 284 71
					view: 310
					loop: 0
					cel: 0
					ignoreHorizon:
					setCycle: End self
					init:
				)
			)
			(2
				(newAct_3 view: 311 posn: 283 87 loop: 3 setCycle: Fwd)
				(Print 43 51)
			)
			(10
				(newAct_3 dispose:)
				(= global105 14)
				(gEgo
					view: 312
					loop: 0
					setCycle: Fwd
					setMotion: MoveTo 339 (gEgo y?)
				)
			)
		)
	)
)

(instance deathTimer of Script
	(properties)
	
	(method (doit)
		(if
			(and
				local12
				(<= state 2)
				(or
					(gEgo inRect: 140 98 196 118)
					(gEgo inRect: 146 118 258 150)
				)
			)
			(self changeState: 10)
		)
		(super doit:)
	)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(if local11 (= seconds 240) else (= seconds 120))
			)
			(1 (= local12 1))
			(10
				(proc0_8)
				(gEgo
					illegalBits: -2
					setAvoider: Avoid
					setMotion: MoveTo 184 130 self
				)
			)
			(11
				(gEgo
					setMotion: 0
					viewer: 0
					view: 21
					loop: 2
					cel: 255
					cycleSpeed: 2
					setCycle: End self
				)
			)
			(12
				(gEgo view: 83 loop: 0 cel: 0)
				(= seconds 4)
			)
			(13
				(gEgo cel: 1)
				(= seconds 5)
			)
			(14
				(gEgo cel: 2)
				(= seconds 6)
			)
			(15
				(gEgo cel: 3)
				(= seconds 7)
			)
			(16
				(Print 43 52 67 -1 10)
				(= seconds 6)
			)
			(17 (= global127 1))
		)
	)
)

(instance drinking of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(1
				(proc0_8)
				(= gEgoViewer (gEgo viewer?))
				(gEgo viewer: 0 view: 21 cel: 255 setCycle: End self)
			)
			(2
				(= global120 (Print 43 5 67 -1 10 88))
				(= seconds 5)
			)
			(3 (gEgo setCycle: Beg self))
			(4
				(proc0_21)
				(gEgo view: 2 setCycle: Walk)
				(gEgo script: gGEgoScript viewer: gEgoViewer)
				(proc0_9)
			)
		)
	)
)

(instance pelMovement of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(if (== local1 1) (newAct setCycle: Fwd))
				(= seconds (Random 3 7))
			)
			(1
				(if (== local1 1)
					(newAct setCycle: 0)
					(= seconds (Random 3 7))
				)
			)
			(2 (self changeState: 0))
		)
	)
)

(instance waveScript of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0 (= cycles (Random 2 6)))
			(1
				(newProp loop: 0 cel: 0 posn: 50 142 setCycle: End self)
				(= state 6)
			)
			(2
				(newProp loop: 1 cel: 2 posn: 151 174 setCycle: End self)
				(= state 6)
			)
			(3
				(newProp loop: 2 cel: 0 posn: 284 183 setCycle: End self)
				(= state 6)
			)
			(4
				(newProp loop: 3 cel: 2 posn: 301 145 setCycle: End self)
				(= state 6)
			)
			(5
				(newProp loop: 4 cel: 0 posn: 24 74 setCycle: End self)
				(= state 6)
			)
			(6
				(newProp loop: 5 cel: 1 posn: 258 77 setCycle: End self)
			)
			(7
				(newProp posn: 999 999)
				(= cycles (Random 2 10))
				(= state (Random 1 6))
			)
		)
	)
)
