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

(public
	Room22 0
)

(local
	local0
	newProp_2
	newProp_3
	newProp_4
	newProp_5
	newProp
)
(instance doorSound of Sound
	(properties)
)

(instance door of Prop
	(properties)
	
	(method (cue)
		(if (!= (door cel?) (door lastCel:))
			(self setCycle: End self)
		else
			(proc0_9)
			(gRoom newRoom: 54)
		)
	)
)

(instance Room22 of Rm
	(properties
		picture 22
	)
	
	(method (init)
		(= north 16)
		(= south 28)
		(= east 23)
		(= west 21)
		(= horizon 75)
		(= global101 0)
		(gEgo edgeHit: 0)
		(super init:)
		(if global100 (gRoom overlay: 122))
		(self setRegions: 501 512 508)
		(Load rsVIEW 612)
		(= newProp (Prop new:))
		(newProp
			isExtra: 1
			view: 627
			loop: 0
			cel: 3
			posn: 158 25
			setPri: 0
			cycleSpeed: 2
			setCycle: Fwd
			ignoreActors:
			init:
		)
		(= newProp_2 (Prop new:))
		(= newProp_3 (Prop new:))
		(= newProp_4 (Prop new:))
		(= newProp_5 (Prop new:))
		(newProp_2
			isExtra: 1
			view: 656
			loop: 0
			cel: 2
			posn: 23 110
			setPri: 0
			setCycle: Fwd
			ignoreActors:
			init:
		)
		(newProp_3
			isExtra: 1
			view: 656
			loop: 1
			cel: 1
			posn: 309 156
			setPri: 0
			setCycle: Fwd
			ignoreActors:
			init:
		)
		(newProp_4
			isExtra: 1
			view: 656
			loop: 2
			cel: 2
			posn: 226 168
			setPri: 0
			setCycle: Fwd
			ignoreActors:
			init:
		)
		(newProp_5
			isExtra: 1
			view: 656
			loop: 3
			cel: 1
			posn: 41 125
			setPri: 0
			setCycle: Fwd
			ignoreActors:
			init:
		)
		(door
			view: 612
			loop: 0
			cel: 0
			posn: 179 111
			setPri: 6
			stopUpd:
			init:
		)
		(if global100 (door loop: 1))
		(switch gPrevRoomNum
			(21
				(if (<= (gEgo y?) horizon)
					(gEgo posn: 1 (+ horizon 2))
				)
				(if (and (>= (gEgo y?) 126) (< (gEgo y?) 130))
					(gEgo posn: 1 127)
				else
					(gEgo posn: 1 (gEgo y?))
				)
			)
			(16
				(gEgo x: 27 y: (+ horizon (gEgo yStep?) 1))
			)
			(28 (gEgo x: 171 y: 188))
			(23 (gEgo posn: 317 (gEgo y?)))
			(53
				(gEgo view: 2 loop: 2 x: 188 y: 114)
				(if (== global102 2) (gRoom setScript: doorActions))
			)
			(54
				(if (== global102 2) (gRoom setScript: doorActions))
				(gEgo view: 2 x: 188 y: 114)
			)
			(0 (gEgo x: 318 y: 123))
		)
		(gEgo xStep: 3 yStep: 2 init:)
		(proc0_9)
	)
	
	(method (doit)
		(super doit:)
		(if
			(and
				(gEgo inRect: 167 140 201 149)
				(!= (gEgo view?) 2)
			)
			(gEgo setPri: 11)
		else
			(gEgo setPri: -1)
		)
	)
	
	(method (handleEvent pEvent)
		(if (pEvent claimed?) (return 1))
		(return
			(if (== (pEvent type?) evSAID)
				(cond 
					((Said 'look/cottage') (Print 22 0))
					((Said 'look/window')
						(if
							(or
								(gEgo inRect: 140 112 170 124)
								(gEgo inRect: 170 112 202 120)
							)
							(Print 22 1)
						else
							(Print 800 1)
						)
					)
					((Said 'look/blossom') (Print 22 2))
					((Said 'get/blossom') (Print 22 3))
					((Said 'look/door') (Print 22 4))
					((Said 'break/window') (Print 22 5))
					((Said 'break/door') (Print 22 6))
					((Said 'open/window') (Print 22 7))
					((Said 'open/door')
						(if (gEgo inRect: 170 112 202 120)
							(cond 
								((== local0 1) (Print 22 8))
								((not global100)
									(proc0_8)
									(gEgo loop: 3)
									(doorSound number: 300 play: door)
									(door setCycle: End)
								)
								(else (Print 22 9))
							)
						else
							(Print 800 1)
						)
					)
					((Said 'unlatch/door')
						(if (gEgo inRect: 170 112 202 120)
							(if (not global100)
								(Print 22 10)
							else
								(Print 22 11)
							)
						else
							(Print 800 1)
						)
					)
					((Said 'bang/door')
						(if (gEgo inRect: 170 112 202 120)
							(cond 
								((== local0 1) (Print 22 12))
								(global100 (Print 22 13))
								(else (Print 22 14))
							)
						else
							(Print 800 1)
						)
					)
					((Said 'look/wheel') (Print 22 15))
					((Said 'look[<around][/room]') (Print 22 16))
				)
			else
				0
			)
		)
	)
	
	(method (newRoom newRoomNumber)
		(User canControl: 1 canInput: 1)
		(super newRoom: newRoomNumber)
	)
)

(instance doorActions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(= global102 0)
				(= local0 1)
				(door ignoreActors: 0 setCycle: Beg self)
			)
			(1 (Print 22 17))
		)
	)
)
