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

(public
	Room87 0
)

(local
	newAct
	newAct_2
	newAct_3
	newProp_2
	newProp_3
	newProp_4
	newProp
	local7
)
(instance theMusic of Sound
	(properties)
)

(instance doorSound of Sound
	(properties
		number 300
	)
)

(instance Room87 of Rm
	(properties
		picture 87
		style $0010
	)
	
	(method (init)
		(Load rsVIEW 145)
		(Load rsVIEW 141)
		(Load rsVIEW 633)
		(Load rsVIEW 608)
		(Load rsVIEW 147)
		(self setRegions: 604)
		(super init:)
		(proc0_10 604 0)
		(theMusic number: 41 loop: 0 init:)
		((= newProp (Prop new:))
			view: 608
			posn: 140 117
			cel: 0
			init:
			stopUpd:
		)
		((= newProp_2 (Prop new:))
			posn: 24 64
			view: 633
			cel: 2
			init:
			setCycle: Fwd
		)
		((= newProp_3 (Prop new:))
			posn: 32 74
			view: 633
			cel: 0
			init:
			setCycle: Fwd
		)
		((= newProp_4 (Prop new:))
			posn: 42 64
			view: 633
			cel: 1
			init:
			setCycle: Fwd
		)
		(if global169
			((= newAct (Act new:))
				view: 145
				loop: 4
				posn: 200 122
				init:
				setScript: henchChase
			)
		else
			((= newAct (Act new:))
				view: 147
				loop: 1
				cel: 0
				posn: 272 153
				init:
			)
			((= newAct_2 (Act new:))
				view: 147
				loop: 2
				cel: 0
				posn: 250 157
				init:
			)
			((= newAct_3 (Act new:))
				view: 147
				loop: 2
				cel: 0
				posn: 212 158
				init:
			)
			(gEgo observeControl: 1024)
			(newAct setScript: circleJerk)
		)
		(if (or (== gPrevRoomNum 88) (== gPrevRoomNum 0))
			(gEgo posn: 261 133 view: 4 xStep: 4 yStep: 2 init:)
		)
		(if (== gPrevRoomNum 86)
			(gEgo posn: 25 142 view: 4 xStep: 4 yStep: 2 init:)
		)
		(if (== gPrevRoomNum 84)
			(gEgo posn: 131 124 view: 4 xStep: 4 yStep: 2 init:)
		)
	)
	
	(method (doit)
		(super doit:)
		(if (& (gEgo onControl: 0) $0040)
			(gRoom newRoom: 86)
		)
		(if (& (gEgo onControl: 0) $0020)
			(gRoom newRoom: 84)
		)
		(if (& (gEgo onControl: 0) $0010)
			(gRoom newRoom: 88)
		)
	)
	
	(method (dispose)
		(gTimers eachElementDo: #dispose 84)
		(super dispose:)
	)
	
	(method (handleEvent pEvent)
		(return
			(cond 
				((pEvent claimed?) (return 1))
				((== (pEvent type?) evSAID)
					(cond 
						(
							(or
								(Said 'look[<around][/!*]')
								(Said 'look[<around]/room,castle,hall')
							)
							(Print 87 0)
						)
						((Said 'look>')
							(cond 
								((Said '/goon') (Print 87 1 67 -1 10))
								((Said '/door') (Print 87 2))
								((Said '/table') (Print 87 3))
								((Said '/candelabra,candle') (Print 87 4))
								((Said '/wall') (Print 87 5))
								((or (Said '/dirt') (Said '<down')) (Print 87 6))
								(else (pEvent claimed: 0))
							)
						)
						((Said '/man,goon') (if global169 (Print 87 7) else (Print 87 8)))
						((Said 'get/candelabra,candle') (Print 87 9 67 -1 10))
						((Said 'bang/door')
							(if (gEgo inRect: 111 118 140 123)
								(Print 87 10 67 -1 10)
							else
								(Print 800 1)
							)
						)
						((Said 'open/door')
							(cond 
								((!= (newProp cel?) 0) (Print 87 11 67 -1 10))
								((not (gEgo inRect: 111 118 140 123)) (Print 800 1))
								(else (newProp setCycle: End doDoor) (doorSound play:))
							)
						)
						((Said 'close/door') (Print 87 12))
						((Said 'unlatch/door')
							(if (gEgo inRect: 111 118 140 123)
								(Print 87 13)
							else
								(Print 800 1)
							)
						)
						((Said '/goon,man>')
							(cond 
								((Said 'converse') (Print 87 14 67 -1 10))
								((Said 'get,capture') (Print 87 15 67 -1 10))
								((Said 'kiss') (Print 87 16 67 -1 10))
								((Said 'deliver') (Print 87 17 67 -1 10))
							)
						)
					)
				)
			)
		)
	)
)

(instance doDoor of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(newProp stopUpd:)
				(gRoom newRoom: 84)
			)
		)
	)
)

(instance henchChase of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(newAct loop: 2 setCycle: End self)
			)
			(1
				(newAct loop: 0 setCycle: End self)
			)
			(2
				(= global175 1)
				(theMusic number: 41 loop: 10 play:)
				(newAct
					view: 141
					setAvoider: Avoid
					setCycle: Walk
					setMotion: Chase gEgo 15 self
				)
			)
			(3
				(User canControl: 0 canInput: 0)
				(gEgo moveSpeed: 0 setMotion: 0)
				(theMusic number: 42 loop: 1 play:)
				(= seconds 4)
			)
			(4
				(= global205 1)
				(gRoom newRoom: 81)
			)
		)
	)
)

(instance circleJerk of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				((ScriptID 0 4) setReal: self 2)
			)
			(1
				(newAct setCycle: End)
				(newAct_2 setCycle: End)
				(newAct_3 setCycle: End)
				((ScriptID 0 4) setReal: self 5)
			)
			(2
				(newAct_2 setCycle: Beg)
				(newAct setCycle: Beg)
				(newAct_3 setCycle: Beg self)
			)
			(3 (client setScript: 0))
		)
	)
)
