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

(public
	Room89 0
)

(local
	newProp
	newProp_2
	newView
	newView_2
	gInvFirst
	local5
	local6
	local7
)
(procedure (localproc_000c &tmp temp0)
	(= temp0 0)
	(= gInvFirst (gInv first:))
	(while gInvFirst
		(if
			(and
				(= local5 (NodeValue gInvFirst))
				(== (local5 owner?) 89)
			)
			(= temp0 1)
		)
		(= gInvFirst (gInv next: gInvFirst))
	)
	(return temp0)
)

(instance Room89 of Rm
	(properties
		picture 89
		style $0010
	)
	
	(method (init)
		(Load rsVIEW 606)
		(Load rsVIEW 649)
		(Load rsVIEW 634)
		(Load rsVIEW 512)
		(self setRegions: 604)
		(super init:)
		((View new:)
			view: 634
			loop: 1
			cel: 0
			posn: 57 88
			setPri: 6
			init:
			addToPic:
		)
		(if global100
			((Prop new:)
				view: 512
				loop: 0
				posn: 59 76
				setPri: 6
				init:
				setCycle: Fwd
			)
			((View new:)
				view: 649
				loop: 2
				cel: 0
				posn: 264 105
				setPri: 7
				init:
				addToPic:
			)
		)
		((= newProp (Prop new:))
			view: 606
			loop: 0
			posn: 241 108
			init:
			setPri: 8
			stopUpd:
		)
		((= newProp_2 (Prop new:))
			view: 606
			posn: 76 108
			loop: 1
			init:
			setPri: 8
			stopUpd:
		)
		((= newView (View new:))
			view: 606
			posn: 222 108
			loop: 2
			cel: 0
			ignoreActors: 1
			init:
			stopUpd:
		)
		(if (not (= local7 (localproc_000c)))
			(newView cel: 2 forceUpd:)
		)
		((= newView_2 (View new:))
			view: 606
			posn: 96 108
			loop: 2
			cel: 1
			ignoreActors: 1
			init:
			stopUpd:
		)
		(if (or (== gPrevRoomNum 91) (== gPrevRoomNum 0))
			(gEgo posn: 38 151 view: 4 xStep: 4 yStep: 2 init:)
			(if global175 (= global175 0))
		)
	)
	
	(method (doit)
		(super doit:)
		(if (& (gEgo onControl: 0) $0040)
			(gRoom newRoom: 91)
		)
	)
	
	(method (handleEvent pEvent)
		(return
			(cond 
				((pEvent claimed?) (return 1))
				((== (pEvent type?) evSAID)
					(cond 
						(
							(or
								(Said 'look[<around][/!*]')
								(Said 'look/room,castle,kitchen')
							)
							(Print 89 0)
						)
						((Said 'look>')
							(cond 
								((Said '<in/cabinet')
									(if
										(or
											(< (gEgo distanceTo: newProp) 25)
											(< (gEgo distanceTo: newProp_2) 25)
										)
										(if (< (gEgo distanceTo: newProp) 25)
											(if (== (newProp cel?) 0)
												(newProp setCycle: End rightCabinet)
											)
											(if local7 (Print 89 1) else (Print 89 2))
										)
										(if (< (gEgo distanceTo: newProp_2) 25)
											(if (== (newProp_2 cel?) 0)
												(newProp_2 setCycle: End leftCabinet)
											)
											(Print 89 3)
										)
									else
										(Print 800 1)
									)
								)
								((Said '/cabinet') (Print 89 4))
								((Said '<under/table') (Print 89 5))
								((Said '/table') (Print 89 6))
								((Said '/fireplace') (Print 89 7))
								((Said '/caldron') (Print 89 8))
								((Said '/barrel') (Print 89 9))
								((Said '/wall') (Print 89 10))
								((or (Said '/dirt') (Said '<down')) (Print 89 11))
								((Said '/window')
									(if (gEgo inRect: 220 124 282 146)
										(Print 89 12)
									else
										(Print 800 1)
									)
								)
								((Said '/door') (Print 89 13))
							)
						)
						((Said 'open>')
							(cond 
								((Said '/barrel') (Print 89 14))
								((Said '/window') (Print 89 15))
								((Said '/cabinet,door')
									(cond 
										((gEgo inRect: 210 123 249 133)
											(if (== (newProp cel?) 0)
												(newProp setCycle: End rightCabinet)
												(if local7 (Print 89 16) else (Print 89 2))
											else
												(Print 89 17)
											)
										)
										((gEgo inRect: 74 122 100 133)
											(if (== (newProp_2 cel?) 0)
												(newProp_2 setCycle: End leftCabinet)
												(Print 89 3)
											else
												(Print 89 17)
											)
										)
										(else (Print 800 1))
									)
								)
							)
						)
						((Said 'close/cabinet,door')
							(cond 
								((< (gEgo distanceTo: newProp) 25)
									(if (newProp cel?)
										(newProp setCycle: Beg rightCabinet)
									else
										(Print 89 18)
									)
								)
								((< (gEgo distanceTo: newProp_2) 25)
									(if (newProp_2 cel?)
										(newProp_2 setCycle: Beg leftCabinet)
									else
										(Print 89 18)
									)
								)
								(else (Print 800 1))
							)
						)
						((Said 'break/window') (Print 89 19))
						((Said 'get>')
							(cond 
								((Said '/caldron') (Print 89 20))
								((Said '/dish')
									(if (not (newProp_2 cel?))
										(Print 89 21)
									else
										(Print 89 22)
									)
								)
								((Said '/all,possessions,inventory')
									(cond 
										((not local7) (Print 89 2))
										((not (newProp cel?)) (Print 89 21))
										((> (gEgo distanceTo: newProp) 25) (Print 800 1))
										(else
											(= local6 1)
											(= gInvFirst (gInv first:))
											(while gInvFirst
												(if
													(and
														(= local5 (NodeValue gInvFirst))
														(== (local5 owner?) 89)
													)
													(local5 owner: gEgo)
													(= local6 0)
												)
												(= gInvFirst (gInv next: gInvFirst))
											)
											(if (not local6)
												(gGame changeScore: 4)
												(newView loop: 2 cel: 2 startUpd: forceUpd:)
												(= global182 1)
												(= local7 0)
											else
												(Print 89 2)
											)
											(newView stopUpd:)
										)
									)
								)
								(
									(and
										local7
										(< (gEgo distanceTo: newProp) 25)
										(!= (newProp cel?) (- (NumCels newProp) 1))
									)
									(Print 89 23)
									(pEvent claimed: 1)
								)
							)
						)
					)
				)
			)
		)
	)
)

(instance rightCabinet of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(newProp stopUpd:)
				(= state -1)
			)
		)
	)
)

(instance leftCabinet of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(newProp_2 stopUpd:)
				(= state -1)
			)
		)
	)
)
