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

(public
	Room56 0
)

(local
	newAct_5
	newAct_4
	newAct_3
	[local3 5]
	newAct_2
	local9
	newAct
	local11
	newProp
	newProp_2
	newProp_3
	newProp_4
	local16
	newView
)
(instance Room56 of Rm
	(properties
		picture 56
		style $0010
		west 55
	)
	
	(method (init)
		(self setRegions: 600)
		(Load rsVIEW 516)
		(Load rsVIEW 283)
		(Load rsVIEW 286)
		(Load rsVIEW 287)
		(Load rsVIEW 4)
		(Load rsVIEW 518)
		(super init:)
		(= global101 1)
		(gEgo view: 4 posn: 65 139 init:)
		(if ((Inv at: 1) ownedBy: gEgo)
			(Load rsVIEW 288)
			(Load rsVIEW 281)
			(Load rsVIEW 523)
			((View new:)
				view: 287
				loop: 3
				cel: 0
				posn: 118 68
				addToPic:
			)
			((View new:)
				view: 286
				loop: 4
				cel: 0
				posn: 70 70
				addToPic:
			)
			((View new:)
				view: 283
				loop: 1
				cel: 0
				posn: 211 99
				addToPic:
			)
			((View new:)
				view: 516
				loop: 0
				cel: 0
				posn: 234 118
				addToPic:
			)
			((= newAct (Act new:))
				isExtra: 1
				view: 287
				setLoop: 1
				illegalBits: 0
				posn: 118 52
				setCycle: Fwd
				init:
			)
			((= newAct_2 (Act new:))
				isExtra: 1
				view: 286
				illegalBits: 0
				posn: 70 54
				setLoop: 2
				setCycle: Fwd
				init:
			)
			((= newAct_3 (Act new:))
				view: 283
				setLoop: 0
				illegalBits: 0
				posn: 211 89
				setCycle: Fwd
				init:
			)
			((= newAct_4 (Act new:))
				view: 281
				loop: 4
				cel: 0
				illegalBits: 0
				posn: 233 129
				setPri: -1
				init:
				stopUpd:
			)
			((= newAct_5 (Act new:))
				view: 281
				illegalBits: 0
				posn: (newAct_4 x?) (- (newAct_4 y?) 18)
				ignoreActors: 1
				init:
				setPri: (CoordPri (newAct_4 y?))
				setLoop: 0
				setCycle: Fwd
			)
			(if (not (gEgo has: 3))
				((= newView (View new:))
					view: 523
					loop: 1
					posn: (- (newAct_4 x?) 18) (- (newAct_4 y?) 1)
					init:
					stopUpd:
				)
			)
			(newAct_5 setScript: dwarvesMove)
		else
			(Load rsVIEW 280)
			((View new:)
				view: 283
				loop: 1
				cel: 0
				posn: 82 70
				addToPic:
			)
			((View new:)
				view: 286
				loop: 4
				cel: 0
				posn: 83 121
				addToPic:
			)
			((View new:)
				view: 287
				loop: 2
				cel: 0
				posn: 109 120
				addToPic:
			)
			((View new:)
				view: 516
				loop: 0
				cel: 0
				posn: 99 72
				addToPic:
			)
			((= newAct_4 (View new:))
				view: 280
				loop: 4
				cel: 0
				posn: 211 98
				setPri: -1
				init:
				stopUpd:
			)
			((= newAct_5 (Act new:))
				view: 280
				illegalBits: 0
				posn: (newAct_4 x?) (- (newAct_4 y?) 18)
				setLoop: 1
				ignoreActors: 1
				setPri: (CoordPri (newAct_4 y?))
				setCycle: Fwd
				init:
			)
			((= newAct_3 (Act new:))
				view: 283
				setLoop: 0
				illegalBits: 0
				posn: 82 60
				setCycle: Fwd
				init:
			)
			((= newAct_2 (Act new:))
				isExtra: 1
				view: 286
				setLoop: 2
				illegalBits: 0
				posn: 89 105
				setPri: 8
				setCycle: Fwd
				init:
			)
			((= newAct (Act new:))
				isExtra: 1
				view: 287
				setLoop: 0
				illegalBits: 0
				posn: 110 106
				setPri: 8
				setCycle: Fwd
				init:
			)
			(newAct_5 setScript: dwarvesMove)
		)
		(if global223
			((= newProp (Prop new:))
				view: 518
				cel: 2
				posn: 86 154
				setPri: 15
				cycleSpeed: 1
				setLoop: 3
				init:
				ignoreActors: 1
				stopUpd:
			)
			((= newProp_2 (Prop new:))
				view: 518
				cel: 1
				posn: 261 117
				setPri: 15
				setLoop: 3
				init:
				ignoreActors: 1
				stopUpd:
			)
			((= newProp_3 (Prop new:))
				view: 518
				posn: 212 118
				cycleSpeed: 1
				setPri: 9
				setLoop: 3
				init:
				ignoreActors: 1
				stopUpd:
			)
			((= newProp_4 (Prop new:))
				view: 518
				cel: 3
				posn: 136 48
				setLoop: 3
				init:
				ignoreActors: 1
				stopUpd:
			)
			(newProp setScript: sparkle)
		)
	)
	
	(method (doit)
		(super doit:)
		(if (& (gEgo onControl: 0) $0040)
			(gRoom newRoom: 55)
		)
	)
	
	(method (handleEvent pEvent)
		(return
			(cond 
				((pEvent claimed?) (return 1))
				((== (pEvent type?) evSAID)
					(cond 
						(
							(or
								(Said 'deliver,return/pouch,diamond[/dwarf]')
								(Said 'deliver,return/dwarf/pouch,diamond')
							)
							(if
								(and
									(== ((Inv at: 1) owner?) gEgo)
									(!= ((Inv at: 3) owner?) gEgo)
								)
								(if (gEgo inRect: 198 122 222 134)
									(proc0_8)
									(gEgo setScript: handOff)
								else
									(Print 56 0)
								)
							else
								(Print 56 1)
							)
						)
						(
							(or
								(Said 'look[<around][/!*]')
								(Said 'look[<around]/room')
								(Said 'look[<around]/mine[<diamond]')
							)
							(Print 56 2)
						)
						((Said 'look>')
							(cond 
								((Said '/dwarf') (Print 56 3))
								((Said '/bucket') (Print 56 4))
							)
						)
						(
							(and
								(< (gEgo distanceTo: newAct_4) 30)
								(Said 'converse[/dwarf]')
							)
							(if (and (gEgo has: 1) (not (gEgo has: 3)))
								(answer1 cue:)
							else
								(Print 56 5)
							)
						)
						(
							(and
								(< (gEgo distanceTo: newAct_4) 20)
								(or (Said 'kiss/dwarf') (Said 'kiss[/!*]'))
							)
							(Print 56 6)
						)
						((Said 'get,rob/bucket') (Print 56 7))
						((Said 'rob/lantern') (Print 56 8))
					)
				)
			)
		)
	)
)

(instance dwarvesMove of Script
	(properties)
	
	(method (changeState newState &tmp temp0)
		(switch (= state newState)
			(0 (= cycles 4))
			(1
				(switch (= temp0 (Random 1 6))
					(1
						(if (gCast contains: newAct_2)
							(newAct_2 setCycle: End self)
						else
							(= seconds 2)
						)
					)
					(2
						(newAct_5 loop: 3 cycleSpeed: 2 setCycle: End self)
						(newAct_4 setLoop: 5)
					)
					(3
						(if (gCast contains: newAct)
							(newAct setLoop: 1 setCycle: End self)
						else
							(= seconds 2)
						)
					)
					(4
						(if (gCast contains: newAct_2)
							(newAct_2 setCycle: End self)
						else
							(= seconds 2)
						)
					)
					(5
						(if (gCast contains: newAct)
							(newAct setLoop: 1 setCycle: End self)
						else
							(= seconds 2)
						)
					)
					(6
						(newAct_5 loop: 1 cycleSpeed: 0 setCycle: End self)
						(newAct_4 setLoop: 5)
					)
					(else  (self cue:))
				)
			)
			(2
				(newAct_5 setMotion: 0 stopUpd:)
				(if (gCast contains: newAct_2)
					(newAct_2 setMotion: 0 stopUpd:)
				)
				(if (gCast contains: newAct)
					(newAct setMotion: 0 stopUpd:)
				)
				(self changeState: 1)
			)
		)
	)
)

(instance sparkle of Script
	(properties)
	
	(method (changeState newState &tmp temp0)
		(switch (= state newState)
			(0
				(switch (Random 1 4)
					(1
						(newProp startUpd: setCycle: End self)
					)
					(2
						(newProp_2 startUpd: setCycle: End self)
					)
					(3
						(newProp_3 startUpd: setCycle: End self)
					)
					(4
						(newProp_4 startUpd: setCycle: End self)
					)
				)
			)
			(1
				(newProp stopUpd:)
				(newProp_2 stopUpd:)
				(newProp_3 stopUpd:)
				(newProp_4 stopUpd:)
				(= state -1)
				(self cue:)
			)
		)
	)
)

(instance answer1 of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0 (Print 56 9))
			(1 (Print 56 10))
			(2
				(Print 56 11)
				(= state 1)
			)
		)
	)
)

(instance handOff of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(dwarvesMove changeState: 3)
				(if global223 (sparkle changeState: 2))
				(if (gCast contains: newAct) (newAct dispose: delete:))
				(if (gCast contains:) (newAct_2 dispose: delete:))
				(if (gCast contains: newProp_4)
					(newProp_4 dispose: delete:)
				)
				(gEgo loop: 0)
				(newAct_5 view: 288 loop: 0 setCycle: End)
				(Print 56 12 67 -1 15 70 290 33 gSmallFont 83)
				(self cue:)
			)
			(1
				(newAct_5 loop: 1 cycleSpeed: 1 setCycle: End self)
			)
			(2
				(newAct_5 hide:)
				(newView dispose:)
				(newAct_4
					view: 288
					loop: 2
					cel: 255
					cycleSpeed: 1
					setCycle: End self
				)
				(if (>= (gEgo y?) (newView y?))
					(newAct_4 setPri: (- (gEgo priority?) 1))
				)
				(gEgo get: 3)
				(gGame changeScore: 3)
			)
			(3
				(if global223
					((= newAct (Act new:))
						view: 287
						setLoop: 1
						illegalBits: 0
						posn: 118 52
						setCycle: Fwd
						init:
					)
					((= newAct_2 (Act new:))
						view: 286
						illegalBits: 0
						posn: 70 54
						setLoop: 2
						setCycle: Fwd
						init:
					)
					((= newProp_4 (Prop new:))
						view: 518
						cel: 3
						posn: 136 48
						setLoop: 3
						init:
						ignoreActors: 1
						stopUpd:
					)
					(sparkle changeState: 0)
				)
				(dwarvesMove changeState: 1)
				(newAct_4 setPri: -1)
				(newAct_5 view: 281 loop: 3 cel: 0 cycleSpeed: 0 show:)
				(newAct_4
					view: 281
					loop: 5
					cel: 0
					stopUpd:
					ignoreActors: 0
					init:
				)
				(= seconds 3)
			)
			(4
				(proc0_9)
				(client setScript: 0)
			)
		)
	)
)
