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

(public
	Room81 0
)

(local
	local0
	newAct
	newAct_2
	newProp_3
	newAct_3
	newProp
	newProp_2
	local7
	local8
	local9
	gInvFirst
)
(instance theMusic of Sound
	(properties
		number 43
	)
)

(instance doorOpenMusic of Sound
	(properties
		number 300
	)
)

(instance Room81 of Rm
	(properties
		picture 81
		style $0010
	)
	
	(method (init)
		(super init:)
		(self setRegions: 604)
		((View new:)
			view: 633
			loop: 2
			cel: 0
			posn: 122 70
			setPri: 3
			addToPic:
		)
		((View new:)
			view: 633
			loop: 2
			cel: 0
			posn: 196 71
			setPri: 3
			addToPic:
		)
		(if global100
			((= newProp (Prop new:))
				view: 646
				loop: 1
				cel: 0
				posn: 225 94
				init:
				stopUpd:
			)
			((= newProp_2 (Prop new:))
				view: 646
				loop: 0
				cel: 0
				posn: 91 91
				init:
				stopUpd:
			)
			((View new:)
				view: 633
				loop: 0
				cel: 3
				posn: 20 179
				setPri: 14
				addToPic:
			)
			((Prop new:)
				view: 633
				loop: 0
				cel: 4
				posn: 122 60
				setPri: 2
				init:
				setCycle: Fwd
			)
			((Prop new:)
				view: 633
				loop: 1
				cel: 3
				posn: 197 61
				setPri: 2
				init:
				setCycle: Fwd
			)
		)
		(= local7 0)
		(= local8 0)
		(theMusic init:)
		(doorOpenMusic init:)
		((= newProp_3 (Prop new:))
			view: 604
			posn: 58 151
			cel: 0
			ignoreActors:
			setPri: 12
			init:
			stopUpd:
		)
		(if (or (== gPrevRoomNum 85) (== gPrevRoomNum 0))
			(gEgo
				posn: 68 163
				view: 4
				setStep: 4 2
				illegalBits: -16384
				init:
			)
		)
		(if (and (== gPrevRoomNum 92) (not global175))
			(User canControl: 0 canInput: 0)
			(gEgo
				posn: 83 165
				view: 4
				xStep: 4
				yStep: 2
				setPri: -1
				illegalBits: 0
				ignoreActors: 1
				init:
				setCycle: Walk
				setMotion: 0
			)
			((= newAct (Act new:))
				view: 141
				posn: 98 175
				setStep: 4 2
				ignoreActors: 1
				init:
				setCycle: Walk
			)
			((= newAct_2 (Act new:))
				view: 141
				posn: 115 181
				setStep: 4 2
				ignoreActors: 1
				init:
				setCycle: Walk
			)
			(newProp_3 cel: 4)
			(self setScript: lockUp)
		)
		(if global175
			(= global175 0)
			(User canControl: 0 canInput: 0)
			(gEgo
				posn: 83 165
				view: 4
				illegalBits: -16384
				setStep: 4 2
				setPri: -1
				init:
				setCycle: Walk
			)
			((= newAct (Act new:))
				view: 141
				posn: 115 181
				setStep: 4 2
				ignoreActors: 1
				illegalBits: 0
				init:
				setCycle: Walk
			)
			(newProp_3 cel: 4)
			(self setScript: lockUpLast)
		)
		(= global205 0)
	)
	
	(method (doit)
		(super doit:)
		(if (& (gEgo onControl: 0) $0040)
			(gRoom newRoom: 85)
		)
		(if
			(and
				(gEgo inRect: 61 144 84 157)
				((gInv at: 34) ownedBy: 81)
			)
			(Print 81 0 33 gSmallFont 82 409 0 0 67 -1 20)
			(= global182 1)
			(gEgo get: 34)
		)
	)
	
	(method (handleEvent pEvent)
		(return
			(cond 
				((pEvent claimed?) (return 1))
				((== (pEvent type?) evSAID)
					(cond 
						((not (& (gEgo onControl: 0) $0800))
							(cond 
								(
									(or
										(Said 'look[<around][/!*]')
										(Said 'look/castle,tower,room,bedroom')
									)
									(Print 81 1)
								)
								((Said 'look>')
									(cond 
										((Said '<under/bed') (Print 81 2))
										((Said '/bed') (Print 81 3))
										((Said '/window')
											(if
												(or
													(gEgo inRect: 201 117 238 126)
													(gEgo inRect: 79 113 116 123)
												)
												(Print 81 4)
											else
												(Print 800 1)
											)
										)
										(
											(or
												(Said '<in/chest,dresser')
												(Said '<in/drawer[<chest]')
											)
											(Print 81 5)
										)
										((Said '/chest,dresser') (Print 81 6))
										((or (Said '/dirt') (Said '<down'))
											(if (== ((gInv at: 34) owner?) 81)
												(Print 81 7)
											else
												(Print 81 8)
											)
										)
										((Said '/mirror')
											(if (gEgo inRect: 218 135 272 154)
												(Print 81 9)
											else
												(Print 800 1)
											)
										)
										((Said '/carpet') (Print 81 10))
										((Said '/stair') (Print 81 11))
										((Said '/door') (Print 81 12))
										((Said '/key')
											(if (and (gEgo has: 34) (not (gEgo has: 32)))
												(Print 81 13)
											else
												(pEvent claimed: 0)
											)
										)
									)
								)
								(
								(and (gCast contains: newAct_3) (Said 'converse')) (Print 81 14))
								(
								(and ((gInv at: 34) ownedBy: 81) (Said 'get/rose')) (proc0_13))
								(
									(or
										(Said 'lay,sleep,get/bed')
										(Said 'sleep')
										(Said 'lay<down,sleep')
									)
									(Print 81 15)
								)
								(
								(or (Said 'open/chest') (Said 'open/drawer[<chest]')) (Print 81 5))
								((Said 'open/window') (Print 81 16))
								((Said 'break/window') (Print 81 17))
								((Said '[use]/key<skeleton')
									(cond 
										((not (gEgo has: 20)) (proc0_17))
										((not local8) (Print 81 18))
										(else (Print 81 19))
									)
								)
								((Said 'unlatch/door')
									(cond 
										((== gPrevRoomNum 85) (Print 81 20))
										((not local8) (Print 81 21))
										((not (gEgo inRect: 70 150 84 157)) (Print 800 1))
										((gEgo has: 32) (= local8 0) (Print 81 22) (gGame changeScore: 2))
										(else (Print 81 23))
									)
								)
								((or (Said '[use]/key<gold') (Said 'gold'))
									(cond 
										((not (gEgo inRect: 70 150 84 157)) (Print 800 1))
										((not (gEgo has: 32)) (Print 800 2))
										((not local8) (Print 81 24))
										((or local7 (not (gEgo has: 20))) (Print 81 22) (= local8 0) (gGame changeScore: 2))
										(else (Print 81 25))
									)
								)
								((Said 'open/door')
									(cond 
										((not (gEgo inRect: 70 150 84 157)) (Print 800 1))
										(local8 (Print 81 26))
										((== (newProp_3 cel?) 0)
											(newProp_3 startUpd: setCycle: End doDoor)
											(User canControl: 0 canInput: 0)
											(gEgo posn: (gEgo x?) 146 illegalBits: -32768)
											(doorOpenMusic play:)
										)
										(else (Print 81 27))
									)
								)
								((Said 'close/door')
									(if (== (newProp_3 cel?) 0)
										(Print 81 21)
									else
										(Print 81 28)
									)
								)
								((Said 'get,untie,detach/key')
									(if (and (gEgo has: 34) (not (gEgo has: 32)))
										(Print 81 29)
										(= global182 1)
										(gEgo get: 32)
										(gGame changeScore: 2)
										((gInv at: 34)
											description: {What a beautiful red rose!}
											loop: 1
											cel: 0
										)
									else
										(pEvent claimed: 0)
									)
								)
							)
						)
						(
						(or (Said 'look[<around][/!*]') (Said 'look/room')) (Print 81 30))
						((Said 'look/stair') (Print 81 31))
						((Said 'look/door') (Print 81 12))
						((Said 'look/wall') (Print 81 32))
						((Said 'close/door') (Print 81 28))
						((Said 'open/door')
							(cond 
								((not (gEgo inRect: 57 155 84 165)) (Print 800 1))
								((== (newProp_3 cel?) 0)
									(newProp_3 startUpd: setCycle: End doDoor)
									(User canControl: 0 canInput: 0)
									(gEgo illegalBits: -32768 setMotion: 0)
									(doorOpenMusic play:)
								)
								(else (Print 81 33))
							)
						)
						((Said 'unlatch/*') (Print 81 34))
					)
				)
			)
		)
	)
)

(instance doDoor of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(newProp_3 stopUpd:)
				(User canControl: 1 canInput: 1)
			)
		)
	)
)

(instance lockUp of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(gEgo
					setMotion: 0
					setLoop: -1
					setMotion: MoveTo 68 165 self
				)
				(newAct setMotion: Follow gEgo 10)
				(newAct_2 setMotion: Follow gEgo 25)
			)
			(1
				(newAct setMotion: 0)
				(newAct_2 setMotion: 0)
				(gEgo setMotion: MoveTo 70 150 self)
			)
			(2
				(gEgo setMotion: MoveTo 106 139 self)
				(= local8 1)
				(newProp_3 setCycle: Beg)
			)
			(3
				(gEgo illegalBits: -16384)
				(newAct_2 illegalBits: 0 setMotion: MoveTo 145 235 self)
				(newAct illegalBits: 0 setMotion: MoveTo 145 239)
			)
			(4
				(User canControl: 1 canInput: 1)
				(newProp_3 stopUpd:)
				(newAct dispose:)
				(newAct_2 dispose:)
				((ScriptID 0 4) setReal: self 2)
			)
			(5
				(Print 81 35 67 -1 30 25 5)
				((ScriptID 0 4) setReal: self 30)
			)
			(6
				(theMusic play:)
				((= newAct_3 (Act new:))
					view: 131
					loop: 1
					posn: 158 215
					illegalBits: 0
					init:
					setCycle: Walk
					setMotion: MoveTo 68 162 self
				)
			)
			(7
				(= local0 (Print 81 36 67 -1 25 88))
				(newAct_3
					cycleSpeed: 7
					setLoop: 0
					cel: 255
					setCycle: CT 10 1
				)
				((ScriptID 0 4) setReal: self 3)
			)
			(8
				(newAct_3 setCycle: End self)
			)
			(9
				(proc0_21)
				((gInv at: 34) moveTo: 81)
				(newAct_3
					view: 130
					setLoop: -1
					illegalBits: 0
					setCycle: Walk
					cycleSpeed: 0
					setMotion: MoveTo 190 249 self
				)
			)
			(10
				(newAct_3 dispose:)
				(theMusic client: 0 stop:)
				(= seconds 120)
			)
			(11
				(proc0_8)
				(gEgo loop: 0)
				(if global100
					(newProp cycleSpeed: 7 cel: 255 setCycle: End self)
					(newProp_2 cycleSpeed: 7 cel: 255 setCycle: End)
				)
			)
			(12
				(Print 81 37 67 -1 10 70 260)
				(= seconds 12)
			)
			(13
				(= global204 0)
				(= global205 1)
				((ScriptID 604) keep: 0)
				(gRoom newRoom: 692)
			)
		)
	)
)

(instance lockUpLast of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(proc0_8)
				(= gInvFirst (gInv first:))
				(while gInvFirst
					(if
						(and
							(= local9 (NodeValue gInvFirst))
							(== (local9 owner?) gEgo)
						)
						(local9 owner: 89)
					)
					(= gInvFirst (gInv next: gInvFirst))
				)
				(gEgo setMotion: 0 illegalBits: 0)
				(newAct setMotion: Follow gEgo 10)
				(gEgo setLoop: -1 setMotion: MoveTo 68 165 self)
			)
			(1
				(newAct setMotion: 0)
				(gEgo setMotion: MoveTo 70 150 self)
			)
			(2
				(gEgo setMotion: MoveTo 106 139 self)
				(= local8 1)
				(newProp_3 setCycle: Beg)
			)
			(3
				(newAct ignoreActors: 1 setMotion: MoveTo 150 225 self)
			)
			(4
				(gEgo setMotion: MoveTo 182 147 self)
				(newProp_3 stopUpd:)
				(newAct dispose:)
			)
			(5
				(gEgo setMotion: MoveTo 216 124 self)
			)
			(6
				(gEgo loop: 0)
				(if global100
					(newProp cycleSpeed: 7 cel: 255 setCycle: End self)
					(newProp_2 cycleSpeed: 7 cel: 255 setCycle: End)
				)
			)
			(7
				(Print 81 38 67 -1 10 70 260 25 10)
				(gEgo setMotion: MoveTo 160 149 self)
			)
			(8
				(gEgo loop: 2)
				(= seconds 3)
			)
			(9
				(= global205 1)
				(= global204 0)
				((ScriptID 604) keep: 0)
				(gRoom newRoom: 692)
				(= global189 0)
			)
		)
	)
)
