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

(public
	Room85 0
)

(instance fallMusic of Sound
	(properties
		number 52
	)
)

(instance Room85 of Rm
	(properties
		picture 85
		style $0010
	)
	
	(method (init)
		(Load rsSOUND 52)
		(self setRegions: 604)
		(super init:)
		((View new:)
			view: 634
			loop: 1
			cel: 1
			posn: 223 163
			setPri: 12
			addToPic:
		)
		((Prop new:)
			view: 512
			loop: 0
			cel: 4
			posn: 223 151
			setPri: 11
			init:
			setCycle: Fwd
		)
		(if (or (== gPrevRoomNum 90) (== gPrevRoomNum 0))
			(gEgo
				posn: 117 169
				view: 4
				baseSetter: (ScriptID 0 1)
				setStep: 4 2
				init:
			)
		)
		(if (== gPrevRoomNum 81)
			(gEgo
				posn: 131 35
				view: 4
				baseSetter: (ScriptID 0 1)
				looper: myLooper
				setLoop: -1
				setStep: 4 2
				init:
			)
		)
	)
	
	(method (doit)
		(super doit:)
		(if (!= (self script?) fallStairs)
			(if (& (gEgo onControl: 0) $0040)
				(gEgo baseSetter: 0 looper: 0)
				(gRoom newRoom: 90)
			)
			(if (& (gEgo onControl: 0) $0020)
				(gEgo baseSetter: 0 looper: 0)
				(gRoom newRoom: 81)
			)
			(if (& (gEgo onControl:) $0004)
				(self setScript: fallStairs)
			)
			(cond 
				((& (gEgo onControl: 0) $0002) (gEgo looper: myLooper))
				((> (gEgo y?) 110) (gEgo looper: 0))
			)
		)
	)
	
	(method (handleEvent pEvent)
		(return
			(cond 
				((pEvent claimed?) (return 1))
				((== (pEvent type?) evSAID)
					(cond 
						(
							(or
								(Said 'look[<around][/!*]')
								(Said 'look/room,tower,castle')
							)
							(Print 85 0)
						)
						((Said 'look>')
							(cond 
								((or (Said '/dirt') (Said '<down')) (Print 85 1))
								((or (Said '/sky') (Said '<up')) (Print 85 2))
								((Said '/stair') (Print 85 3))
								((Said '/stair') (Print 85 4))
							)
						)
					)
				)
			)
		)
	)
)

(instance myLooper of Code
	(properties)
	
	(method (doit param1)
		(param1
			loop:
				(cond 
					(
						(or
							(>= (param1 heading?) 305)
							(<= (param1 heading?) 45)
						)
						2
					)
					(
						(and
							(>= (param1 heading?) 135)
							(<= (param1 heading?) 225)
						)
						3
					)
					(
						(and
							(> (param1 heading?) 45)
							(< (param1 heading?) 135)
						)
						0
					)
					(else 1)
				)
		)
	)
)

(instance fallStairs of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(User canControl: 0 canInput: 0)
				(= global105 16)
				(gEgo
					view: 44
					illegalBits: 0
					ignoreActors: 1
					moveSpeed: 0
					setLoop: (if (== (gEgo loop?) 1) 1 else 0)
					setCycle: End self
				)
				(fallMusic play:)
			)
			(1
				(gEgo
					setStep: 10 10
					setLoop: (+ 2 (gEgo loop?))
					setCycle: Fwd
					setPri: -1
					setMotion:
						MoveTo
						(if (< (gEgo y?) 130)
							(- (gEgo x?) 20)
						else
							(+ (gEgo x?) 10)
						)
						220
						self
				)
			)
			(2
				(gCast eachElementDo: #hide)
				(DrawPic 90)
				((View new:)
					view: 634
					loop: 1
					cel: 1
					posn: 209 77
					setPri: 4
					addToPic:
				)
				((Prop new:)
					view: 512
					loop: 0
					posn: 209 65
					setPri: 3
					init:
					setCycle: Fwd
				)
				(if global169
					((View new:)
						view: 145
						ignoreActors: 1
						loop: 4
						cel: 0
						posn: 188 127
						init:
						addToPic:
					)
				)
				(gEgo
					show:
					posn: 190 9
					setStep: 10 30
					setMotion: MoveTo 190 147 self
				)
			)
			(3
				(gEgo view: 42 loop: (if (== (gEgo loop?) 2) 0 else 1))
				(proc0_18)
				(fallMusic dispose:)
				(ShakeScreen 5)
				(= seconds 4)
			)
			(4
				(= global127 1)
				(client setScript: 0)
			)
		)
	)
)
