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

(public
	Room44 0
)

(local
	newProp
	newAct
	gEgoX
	local3
)
(instance tickleSound of Sound
	(properties
		number 60
	)
)

(instance fallSound of Sound
	(properties
		number 51
	)
)

(instance bottleCage of Cage
	(properties
		top 144
		left 130
		bottom 175
		right 218
	)
)

(instance Room44 of Rm
	(properties
		picture 44
		style $0008
	)
	
	(method (init)
		(= global101 1)
		(super init:)
		(Load rsVIEW 52)
		(Load rsVIEW 17)
		(Load rsVIEW 19)
		(Load rsVIEW 7)
		(Load rsVIEW 6)
		(Load rsVIEW 53)
		(Load rsVIEW 49)
		(Load rsVIEW 21)
		(Load rsVIEW 73)
		(Load rsSOUND 51)
		(if (gEgo has: 8) (Load rsSOUND 60) (Load rsVIEW 51))
		(= global189 1)
		(gEgo view: 8 posn: 39 160 viewer: inWhale init:)
		((= newProp (Prop new:))
			view: 0
			posn: 161 75
			init:
			hide:
		)
		(if ((Inv at: 31) ownedBy: 44)
			(= newAct (Act new:))
			(newAct
				view: 531
				posn: 201 166
				xStep: 1
				yStep: 1
				setLoop: 0
				ignoreActors: 0
				illegalBits: -32768
				observeControl: 4 1
				setCycle: Fwd
				setMotion: Wander 4
				moveSpeed: 8
				cycleSpeed: 2
				observeBlocks: bottleCage
				init:
			)
		)
		(gRoom setScript: deadTimer)
		(Print 44 0)
		(Print 44 1)
		(= global183 1)
		(= local3 0)
	)
	
	(method (doit)
		(super doit:)
		(if
			(and
				(& (gEgo onControl: 0) $0004)
				(== (gEgo script?) 0)
				(== (deadTimer state?) 0)
				(<= (inWhale state?) 0)
			)
			(gEgo setScript: slide)
			(fallSound play:)
			(if (== (gEgo view?) 2)
				(slide changeState: 10)
			else
				(slide changeState: 1)
			)
		)
	)
	
	(method (dispose)
		(gTimers eachElementDo: #dispose 84)
		(super dispose:)
	)
	
	(method (handleEvent pEvent)
		(if (pEvent claimed?) (return 1))
		(return
			(if (== (pEvent type?) evSAID)
				(cond 
					((Said 'get,(look<in)/skeleton,man,person,james') (Print 44 2))
					((or (Said 'get,capture/fish') (Said 'fish')) (Print 44 3))
					((Said 'get,drink[/drink,water]') (Print 44 4))
					((Said 'get/boat') (Print 44 5))
					((Said 'get/bottle')
						(cond 
							(((Inv at: 31) ownedBy: 44)
								(if (< (gEgo distanceTo: newAct) 15)
									(Print 44 6)
									(newAct dispose:)
									(= global182 1)
									(gEgo get: 31)
								else
									(Print 800 1)
								)
							)
							((gEgo has: 31) (Print 44 7))
							(else (Print 44 8))
						)
					)
					((Said 'light,ignite,create,begin/fire') (Print 44 9))
					((Said 'look>')
						(cond 
							((Said '/fish') (Print 44 10))
							((Said '/boat') (Print 44 11))
							((Said '<under/water') (Print 44 12))
							((Said '/belly') (Print 44 13))
							((Said '/tongue') (Print 44 14))
							((Said '/esophagus,lips,molar') (Print 44 15))
							((Said '/uvula') (Print 44 16))
							((Said '/skeleton,james,man,person') (Print 44 17))
							((Said '/water')
								(if ((Inv at: 31) ownedBy: 44)
									(Print 44 18)
								else
									(Print 44 19)
								)
							)
							((Said '[<up,around,at][/room,whale]') (Print 44 0) (Print 44 1))
						)
					)
					((Said 'hit/molar')
						(if (< (gEgo y?) 82)
							(Print 44 20)
						else
							(Print 800 1)
						)
					)
					((Said 'hit/tongue') (Print 44 21))
					((Said 'hit/uvula,esophagus')
						(if (gEgo inRect: 140 71 178 86)
							(Print 44 22)
						else
							(Print 800 1)
						)
					)
					((Said 'climb') (Print 44 23))
					((or (Said 'call,help') (Said 'save/me')) (Print 44 24))
					((Said 'escape') (Print 44 25))
					((Said 'bathe') (Print 44 26))
					((Said 'open,force/lips') (Print 44 27))
					((Said 'light/fire') (Print 44 9))
					((Said 'tickle')
						(if (gEgo has: 8)
							(if (gEgo inRect: 140 71 178 86)
								(gEgo setScript: tickle)
								(tickle changeState: 1)
								(gGame changeScore: 5)
							else
								(Print 44 28)
							)
						else
							(Print 44 29)
						)
					)
				)
			else
				0
			)
		)
	)
)

(instance slide of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(1
				(proc0_8)
				(cond 
					((< (gEgo x?) 50) (= gEgoX (+ (gEgo x?) 20)))
					((> (gEgo x?) 270) (= gEgoX (- (gEgo x?) 20)))
					(else (= gEgoX (gEgo x?)))
				)
				(gEgo
					view: 52
					illegalBits: 0
					setLoop: 2
					setCycle: Fwd
					yStep: 5
					xStep: 3
					setMotion: MoveTo gEgoX 145 self
				)
			)
			(2
				(gEgo view: 19 setLoop: 0 cel: 2 setCycle: End self)
			)
			(3
				(fallSound dispose:)
				(gEgo viewer: inWhale)
				(gEgo
					illegalBits: -32768
					setLoop: -1
					xStep: 2
					yStep: 1
					setScript: 0
				)
				(proc0_9)
			)
			(10
				(proc0_8)
				(gEgo view: 17 setLoop: (& (gEgo loop?) $0001))
				(gEgo illegalBits: 0 cel: 255 setCycle: End self)
			)
			(11 (self changeState: 1))
		)
	)
)

(instance inWhale of Script
	(properties)
	
	(method (doit)
		(super doit:)
		(if (== (gEgo script?) 0)
			(cond 
				((& (gEgo onControl: 1) $0200) (gEgo view: 8 xStep: 2 yStep: 1 setCycle: Fwd))
				((& (gEgo onControl: 1) $0008) (gEgo view: 7 xStep: 2 yStep: 1 setCycle: Walk))
				((& (gEgo onControl: 1) $0800) (gEgo view: 6 xStep: 2 yStep: 1 setCycle: Walk))
				((& (gEgo onControl: 1) $0001)
					(if (== (gEgo view?) 2)
						(slide changeState: 1)
					else
						(gEgo view: 53 setCycle: Walk setStep: 1 1)
					)
				)
				(
					(and
						(!= (gEgo view?) 2)
						(& (gEgo onControl: 1) $0010)
						(== (gEgo script?) 0)
						(<= state 0)
						(<= (deadTimer state?) 0)
					)
					(self changeState: 1)
				)
			)
		)
	)
	
	(method (changeState newState)
		(switch (= state newState)
			(1
				(if (!= (gEgo view?) 2)
					(proc0_8)
					(gEgo
						viewer: 0
						view: 49
						setMotion: 0
						loop: (& (gEgo loop?) $0001)
						cel: 4
						setCycle: Beg self
					)
				else
					(self changeState: 0)
				)
			)
			(2
				(gEgo view: 21 cel: 6 setCycle: Beg self)
			)
			(3
				(gEgo view: 2 setStep: 2 1 setCycle: Walk viewer: inWhale)
				(= state 0)
				(proc0_9)
			)
		)
	)
)

(instance tickle of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(1
				(proc0_8)
				(gTimers eachElementDo: #dispose 84)
				(gRoom script: 0)
				(tickleSound play: self)
				(gEgo setMotion: 0 viewer: 0)
				(proc0_3 gEgo newProp)
				(gEgo loop: (& (gEgo loop?) $0001))
				(gEgo
					view: 51
					loop: (& (gEgo loop?) $0001)
					setCycle: Fwd
				)
			)
			(2
				(Print 44 30)
				(gEgo setLoop: -1 setCel: -1)
				(proc0_9)
				(= global189 0)
				(gRoom newRoom: 31)
			)
		)
	)
)

(instance deadTimer of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(if (gEgo has: 8)
					((ScriptID 0 5) setReal: self 1 4)
				else
					((ScriptID 0 5) setReal: self 2 1)
				)
			)
			(1
				(gEgo viewer: 0)
				(++ local3)
				(if (and (> (inWhale state?) 0) (< local3 4))
					(-- state)
					(= seconds 2)
				else
					(self cue:)
				)
			)
			(2
				(proc0_8)
				(gSounds eachElementDo: #stop 0)
				(cond 
					((< (gEgo x?) 50) (= gEgoX (+ (gEgo x?) 20)))
					((> (gEgo x?) 270) (= gEgoX (- (gEgo x?) 20)))
					(else (= gEgoX (gEgo x?)))
				)
				(cond 
					((== (gEgo view?) 2) (self changeState: 10))
					((== (gEgo view?) 53)
						(fallSound play:)
						(gEgo
							view: 52
							setLoop: 2
							setCycle: Fwd (gEgo yStep: 5)
							setMotion: MoveTo gEgoX 145 self
						)
					)
					(else (self changeState: 4))
				)
			)
			(3
				(gEgo view: 19 setLoop: 0 cel: 2 setCycle: End self)
			)
			(4 (self changeState: 20))
			(10
				(fallSound play:)
				(gEgo
					setLoop: (& (gEgo loop?) $0001)
					view: 17
					cel: 255
					setCycle: End self
				)
			)
			(11
				(gEgo
					view: 52
					setLoop: 2
					setCycle: Fwd
					yStep: 5
					xStep: 3
					illegalBits: 0
					setMotion: MoveTo gEgoX 145 self
				)
			)
			(12 (self changeState: 3))
			(20
				(gEgo view: 73 setLoop: 0 cel: 6 setCycle: End self)
			)
			(21
				(gEgo hide:)
				(Print 44 31)
				((ScriptID 0 5) setReal: self 5)
			)
			(22 (= global127 1))
		)
	)
)
