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

(public
	Room58 0
)

(local
	newAct
	local1
	newProp_3
	local3
	newView
	newProp
	newProp_2
)
(instance Room58 of Rm
	(properties
		picture 58
		style $0010
	)
	
	(method (init)
		(Load rsVIEW 58)
		(Load rsVIEW 42)
		(Load rsVIEW 44)
		(Load rsVIEW 521)
		(Load rsSOUND 51)
		(Load rsSOUND 52)
		(Load rsPIC 66)
		(Load rsPIC 61)
		(super init:)
		(self setRegions: 603)
		(theMusic number: 57 loop: 0)
		(if ((gInv at: 20) ownedBy: gCurRoomNum) (= local3 1))
		(if global193 (= local1 1) else (= local1 0))
		((View new:)
			view: 521
			loop: 2
			cel: 0
			posn: 102 74
			setPri: 4
			addToPic:
		)
		((View new:)
			view: 521
			loop: 2
			cel: 1
			posn: 231 74
			setPri: 4
			addToPic:
		)
		((= newProp (Prop new:))
			view: 521
			loop: 3
			posn: 104 58
			setPri: 2
			init:
			setCycle: Fwd
		)
		((= newProp_2 (Prop new:))
			view: 521
			loop: 3
			posn: 228 58
			setPri: 2
			init:
			setCycle: Fwd
		)
		((= newProp_3 (Prop new:))
			view: 521
			loop: 1
			posn: 181 95
			setPri: 5
			init:
		)
		(if global193
			(newProp_3 setCel: 255 addToPic:)
		else
			(newProp_3 hide:)
		)
		(gEgo
			view: 4
			setStep: 4 2
			setPri: 11
			illegalBits: 16384
			posn: 121 154
			baseSetter: (ScriptID 0 1)
			init:
		)
	)
	
	(method (doit)
		(if
			(and
				(& (gEgo onControl:) $0002)
				(== (gEgo illegalBits?) -32768)
				(not (gEgo script?))
			)
			(gEgo
				setPri: 11
				illegalBits: 16384
				baseSetter: (ScriptID 0 1)
			)
		)
		(if
			(and
				(& (gEgo onControl:) $0010)
				(not (& (gEgo onControl: 1) $0002))
				(not (gEgo script?))
			)
			(gEgo setPri: -1 illegalBits: -32768 baseSetter: 0)
		)
		(if
			(and
				(& (gEgo onControl: 0) $0040)
				(!= (gEgo script?) fallHole)
			)
			(gRoom newRoom: 61)
		)
		(if
			(and
				(& (gEgo onControl:) $0004)
				(!= (gEgo illegalBits?) 16384)
				(!= (gEgo script?) fallHole)
			)
			(proc0_8)
			(gEgo setScript: fallHole)
		)
		(super doit:)
	)
	
	(method (handleEvent pEvent)
		(return
			(cond 
				((pEvent claimed?) (return 1))
				((== (pEvent type?) evSAID)
					(cond 
						(
							(or
								(Said 'look[<around][/!*]')
								(Said 'look/room,tower')
							)
							(Print 58 0)
						)
						((Said 'look>')
							(cond 
								((or (Said '<down') (Said '/stair')) (Print 58 1))
								((Said '<behind/organ') (Print 58 2))
								((Said '<in/organ') (Print 58 3))
								((Said '/organ') (Print 58 4))
								((Said '/bench') (Print 58 5))
								((Said '/wall') (Print 58 6))
								((or (Said '/dirt') (Said '<down')) (Print 58 7))
								((Said '/drawer')
									(if local1
										(if local3 (Print 58 8) else (Print 58 9))
									else
										(Print 58 10)
									)
								)
							)
						)
						((Said 'move/bench') (Print 58 11))
						((Said 'play,use/music<sheet')
							(cond 
								((== (gEgo view?) 58)
									(if (gEgo has: 26)
										(Print 58 12)
										(playOrgan changeState: 10)
									else
										(Print 58 13)
									)
								)
								((gEgo has: 26) (Print 58 14))
								(else (Print 58 13))
							)
						)
						(
						(or (Said 'play,use/organ,music') (Said 'play[/!*]'))
							(if (== (gEgo view?) 58)
								(if (gEgo has: 26) (Print 58 15))
								(playOrgan changeState: 0)
							else
								(Print 58 16)
							)
						)
						((or (Said 'sit') (Said 'sit/organ,bench'))
							(cond 
								((== (gEgo view?) 58) (Print 58 17))
								((gEgo inRect: 129 121 195 126) (self setScript: sitOrgan))
								((gEgo inRect: 122 126 211 137) (Print 58 18))
								(else (Print 800 1))
							)
						)
						(
							(or
								(Said 'get<up')
								(Said 'stand[<up]')
								(Said 'exit/organ,bench')
							)
							(if (== (gEgo view?) 58)
								(self setScript: standOrgan)
							else
								(Print 58 19)
							)
						)
						((Said 'get/key')
							(if local1
								(if local3
									(Print 58 20)
									(= local3 0)
									(= global182 1)
									(gEgo get: 20)
									(gGame changeScore: 2)
								else
									(proc0_14)
								)
							else
								(Print 58 21)
							)
						)
						((Said 'close/drawer') (if local1 (Print 58 22) else (Print 58 23)))
						((Said 'open/drawer') (if local1 (Print 58 24) else (Print 58 23)))
						((Said 'open/bench') (Print 58 25))
						((Said 'find/drawer') (if local1 (Print 58 26) else (Print 58 27)))
					)
				)
			)
		)
	)
)

(instance playOrgan of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(User canInput: 0)
				(newAct loop: 2 setCycle: Fwd)
				(theMusic number: 56 loop: 1 play: self)
			)
			(1
				(Print 58 28)
				(newAct cel: 0 loop: 4 setCycle: 0)
				(User canInput: 1)
				(theMusic loop: 0)
			)
			(10
				(proc0_8)
				((= newView (View new:))
					view: 521
					loop: 0
					cel: 0
					posn: 162 94
					setPri: 6
					init:
				)
				(newAct loop: 2 setCycle: Fwd)
				(theMusic number: 57 loop: 1 play: self)
			)
			(11
				(if (== global193 0)
					(++ global193)
					(Print 58 29)
					(gGame changeScore: 4)
					(newProp_3 show: setCycle: End)
					(= local1 1)
				else
					(theMusic loop: 0)
					(newView dispose:)
				)
				(newAct cel: 0 loop: 4 setCycle: 0)
				(newView dispose:)
				(User canInput: 1)
			)
		)
	)
)

(instance theMusic of Sound
	(properties)
)

(instance sitOrgan of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(User canControl: 0)
				(gEgo setMotion: MoveTo 164 125 self)
			)
			(1 (gEgo loop: 2) (self cue:))
			(2
				((= newAct (Act new:))
					view: 58
					loop: 0
					cel: 0
					setPri: 9
					posn: (gEgo x?) (- (gEgo y?) 13)
					ignoreActors: 1
					illegalBits: 0
					init:
				)
				(gEgo view: 58 loop: 1 cel: 0)
				(gEgo setCycle: End)
				(newAct setCycle: End self)
			)
			(3 (client setScript: 0))
		)
	)
)

(instance standOrgan of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(proc0_8)
				(gEgo cel: 255 loop: 5 setCycle: End)
				(newAct cel: 255 loop: 4 setCycle: End self)
			)
			(1
				(gEgo setPri: -1 view: 4 loop: 3 setCycle: Walk)
				(newAct dispose:)
				(proc0_9)
				(client setScript: 0)
			)
		)
	)
)

(instance fallHole of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(theMusic number: 51 loop: 1 play: self)
				(gEgo setMotion: 0)
				(proc0_8)
				(gEgo
					view: 44
					setStep: -1 10
					setCycle: Fwd
					setPri: (if (< (gEgo priority?) 11) (gEgo priority?) else 11)
					illegalBits: 0
					setMotion: MoveTo 160 252
				)
			)
			(1
				(gCast eachElementDo: #hide)
				(theMusic client: 0 stop:)
				(gEgo hide:)
				(gRoom drawPic: 61 6)
				(theMusic number: 52 loop: 1 play:)
				(gEgo
					setStep: -1 10
					setCycle: Fwd
					illegalBits: 0
					posn: 160 9
					setPri: 14
					show:
					setLoop: (gEgo loop?)
					setMotion: MoveTo 160 150 self
				)
			)
			(2
				(gEgo setPri: 14 setMotion: MoveTo 160 256 self)
			)
			(3
				(theMusic client: 0 stop:)
				(gEgo hide:)
				(gRoom drawPic: 66 6)
				(theMusic number: 52 loop: 1 play:)
				(gEgo
					posn: 160 9
					show:
					setPri: -1
					setMotion: MoveTo 212 136 self
				)
			)
			(4
				(gSounds eachElementDo: #stop 1)
				(gEgo view: 42)
				(proc0_18)
				(ShakeScreen 10)
				(= seconds 3)
			)
			(5 (= global127 1))
		)
	)
)
