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

(public
	Room51 0
)

(local
	newProp
	newView
	newProp_2
	newProp_3
	newView_2
	newProp_4
	local6
	local7
)
(instance keyholeMusic of Sound
	(properties
		number 61
	)
)

(instance Room51 of Rm
	(properties
		picture 51
		style $0010
	)
	
	(method (init)
		(= global101 1)
		(= global189 1)
		(Load rsVIEW 2)
		(Load rsVIEW 614)
		(Load rsVIEW 647)
		(self setRegions: 602)
		(super init:)
		(keyholeMusic init:)
		(if (and (gEgo has: 33) (< global165 5))
			(= global165 4)
		)
		(if (or (== gPrevRoomNum 49) (== gPrevRoomNum 0))
			(gEgo
				view: 2
				setStep: 3 2
				posn: 156 139
				illegalBits: -32768
				init:
			)
			((= newProp (Prop new:))
				view: 614
				loop: 0
				setCel: 255
				posn: 177 132
				ignoreActors: 0
				setPri: 8
				init:
				setCycle: Beg
			)
			((= newView (View new:))
				view: 614
				setLoop: 1
				posn: 165 105
				init:
				hide:
			)
			(if (and global165 (< global165 5))
				(newView
					cel:
						(switch global165
							(1 0)
							(2 1)
							(3
								(if (gEgo has: 33) 3 else 2)
							)
							(4 0)
						)
					setPri: 2
					show:
				)
			)
			(gEgo loop: 2 setMotion: 0)
		)
	)
	
	(method (dispose)
		(= global189 0)
		(super dispose:)
	)
	
	(method (handleEvent pEvent)
		(return
			(cond 
				((pEvent claimed?) (return 1))
				((== (pEvent type?) evSAID)
					(cond 
						((Said 'look>')
							(cond 
								((Said '/keyhole')
									(if (== (newProp cel?) 0)
										(cond 
											((not global166)
												(if (and (> global165 0) (!= global165 5))
													(self setScript: theKeyhole)
												else
													(self setScript: emptyHole)
												)
											)
											((!= script theKeyhole) (self setScript: emptyHole))
											(else (Print 51 0))
										)
									else
										(Print 51 1)
									)
								)
								((Said '/door') (Print 51 2))
								((Said '/wall') (Print 51 3))
								((or (Said '/dirt') (Said '<down')) (Print 51 4))
								((Said '[<around,at][/room,cottage,closet]') (Print 51 5))
							)
						)
						((Said 'open/door,closet')
							(if (== (newProp cel?) 0)
								(if
								(or global166 (== global165 0) (== global165 5))
									(if (gEgo inRect: 134 131 169 141)
										(newProp setScript: doorOpen)
									else
										(proc0_13)
									)
								else
									(Print 51 6)
								)
							else
								(Print 51 7)
							)
						)
						((Said 'close/door')
							(if (newProp cel?)
								(newProp ignoreActors: 0 setCycle: Beg)
								(newView hide:)
							else
								(Print 51 8)
							)
						)
					)
				)
			)
		)
	)
)

(instance theKeyhole of Script
	(properties)
	
	(method (init param1)
		(Load rsVIEW 70)
		(Load rsVIEW 251)
		(Load rsVIEW 252)
		(Load rsVIEW 253)
		(Load rsVIEW 254)
		(Load rsVIEW 255)
		(Load rsVIEW 647)
		(Load rsPIC 52)
		((= newProp_2 (Prop new:))
			view: 251
			loop: 0
			cel: 1
			posn: 152 89
			init:
			hide:
		)
		((= newProp_3 (Prop new:))
			view: 251
			loop: 1
			posn: 175 65
			init:
			hide:
		)
		((= newView_2 (View new:))
			view: 251
			loop: 0
			cel: 0
			posn: 162 115
			init:
			hide:
		)
		((= newProp_4 (Prop new:))
			view: 253
			loop: 0
			cel: 0
			posn: 134 88
			init:
			hide:
		)
		(super init: param1)
	)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(proc0_8)
				(gEgo setMotion: MoveTo 144 134 self)
			)
			(1
				(gEgo view: 70 loop: 0 cel: 255 setCycle: End self)
			)
			(2
				(gEgo hide:)
				(newView hide:)
				(newProp hide:)
				(gRoom drawPic: 52 15)
				(= global166 1)
				(if global100
					((View new:) view: 647 loop: 3 posn: 184 87 addToPic:)
				)
				(newProp_2 show:)
				(newProp_3
					setPri: (+ (newProp_2 priority?) 1)
					show:
					cycleSpeed: 1
					setCycle: Fwd
				)
				(newView_2 show: stopUpd:)
				(keyholeMusic play:)
				(= local7 (Print 51 9 33 gSmallFont 67 -1 5 25 12))
				(= seconds 2)
			)
			(3
				(newProp_3 setCycle: 0 stopUpd:)
				(Print 51 10 33 gSmallFont 67 -1 15 70 290 88)
				(newProp_3 dispose:)
				(newProp_2
					view: 252
					loop: 0
					cel: 255
					posn: 152 88
					setCycle: End
				)
				(= seconds 2)
			)
			(4
				(newProp_2 loop: 1 cel: 0 cycleSpeed: 2 setCycle: Fwd)
				(= seconds 10)
			)
			(5
				(proc0_21)
				(newProp_2 loop: 1 cel: 0)
				(= seconds 2)
			)
			(6
				(newProp_2 loop: 1 cel: 255 setCycle: End self)
			)
			(7
				(newProp_2 loop: 0 cel: 0)
				(newProp_4 show: setCycle: End)
				(= seconds 3)
			)
			(8
				(Print 51 11 33 gSmallFont 67 -1 10 25 10)
				(= seconds 3)
			)
			(9
				(newProp_4 loop: 1 cel: 255 setCycle: End)
				((gInv at: 33) moveTo: 49)
				(= seconds 3)
			)
			(10
				(Print 51 12 33 gSmallFont 67 -1 20 83 25 5)
				(Print 51 13 33 gSmallFont 67 -1 15 70 290 88)
				(= seconds 5)
			)
			(11
				(newProp_4 dispose:)
				(newProp_2
					view: 254
					loop: 0
					cel: 255
					ignoreActors: 1
					cycleSpeed: 2
					setCycle: End
				)
				(= seconds 5)
			)
			(12
				(newProp_2
					view: 255
					loop: 0
					cel: 255
					cycleSpeed: 0
					setCycle: End self
				)
			)
			(13
				(newProp_2 loop: 1 cel: 0 cycleSpeed: 2 setCycle: Fwd)
				(= seconds 5)
			)
			(14
				(proc0_21)
				(= global165 3)
				(= seconds 5)
			)
			(15
				(newProp_2 dispose:)
				(newView_2 dispose:)
				(gRoom drawPic: 51 15)
				(proc0_9)
				(newProp show:)
				(gEgo show: setCycle: Beg self)
			)
			(16
				(gEgo view: 2 loop: 3 setMotion: 0 setCycle: Walk)
				(proc0_9)
				(= seconds 60)
			)
			(17
				(Print 51 14)
				(= global165 5)
				(client setScript: 0)
			)
		)
	)
)

(instance emptyHole of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(proc0_8)
				(gEgo setMotion: MoveTo 144 134 self)
			)
			(1
				(gEgo view: 70 loop: 0 cel: 255 setCycle: End self)
			)
			(2
				(gEgo hide:)
				(newView hide:)
				(newProp hide:)
				(gRoom drawPic: 52 15)
				(if global100
					((View new:) view: 647 loop: 3 posn: 184 87 addToPic:)
				)
				(keyholeMusic play:)
				(if (== global165 3)
					((= newProp_2 (Prop new:))
						view: 255
						loop: 1
						cel: 0
						posn: 152 89
						init:
						cycleSpeed: 2
						setCycle: Fwd
					)
					((= newView_2 (View new:))
						view: 251
						loop: 0
						cel: 0
						posn: 162 115
						addToPic:
					)
					(= local7 (Print 51 15 67 -1 10 83 88))
				)
				(= seconds 5)
			)
			(3
				(proc0_21)
				(if (IsObject newProp_2) (newProp_2 dispose:))
				(gRoom drawPic: 51 15)
				(newProp show:)
				(gEgo view: 70 loop: 0 setCycle: Beg self show:)
			)
			(4
				(gEgo view: 2 loop: 3 setCycle: Walk)
				(proc0_9)
			)
		)
	)
)

(instance doorOpen of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(proc0_8)
				(if (and (> global165 1) (< global165 5))
					(newView
						cel:
							(switch global165
								(1 0)
								(2 1)
								(3
									(if (gEgo has: 33) 3 else 2)
								)
								(4 0)
							)
						setPri: 2
						show:
					)
				else
					(newView hide:)
				)
				(client ignoreActors: 1 setCycle: End self)
			)
			(1
				(proc0_18)
				(proc0_9)
				(gRoom newRoom: 49)
			)
		)
	)
)
