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

(public
	Room16 0
)
(synonyms
	(kiss kiss embrace)
	(ghoul ghoul ghoul ghoul man ghoul ghoul)
)

(local
	newAct
	newAct_2
	newAct_3
	newProp
	local4
	local5
	local6
	local7
	local8
)
(instance zTheme of Sound
	(properties
		number 20
		priority 1
		loop -1
	)
)

(instance Room16 of Rm
	(properties
		picture 16
	)
	
	(method (init)
		(= north 10)
		(= south 22)
		(= east 17)
		(= west 15)
		(= horizon 80)
		(= global101 0)
		(= global186 0)
		(Load rsVIEW 47)
		(if (<= (gEgo y?) (+ horizon 1))
			(gEgo y: (+ horizon 1))
		)
		(if (== gPrevRoomNum 22) (gEgo x: 158))
		(super init:)
		(if global100 (gRoom overlay: 116))
		(self setRegions: 510)
		(if global100
			(Load rsVIEW 261)
			(Load rsVIEW 263)
			(Load rsVIEW 265)
			(Load rsVIEW 36)
			(Load rsVIEW 46)
			(Load rsVIEW 45)
			(Load rsVIEW 21)
			(= newAct (Act new:))
			(= newAct_2 (Act new:))
			(= newAct_3 (Act new:))
			(newAct
				view: 260
				loop: 0
				cel: 0
				xStep: 2
				yStep: 1
				posn: 250 116
				setScript: z1Actions
				init:
				hide:
			)
			(newAct_2
				view: 262
				loop: 0
				cel: 0
				xStep: 2
				yStep: 1
				posn: 70 123
				setScript: z2Actions
				init:
				hide:
			)
			(newAct_3
				view: 264
				loop: 0
				cel: 0
				xStep: 2
				yStep: 1
				posn: 103 172
				setScript: z3Actions
				init:
				hide:
			)
		)
		(gEgo view: 2 observeControl: 16384 init:)
		(= global105 0)
		(gRoom setScript: holeActions)
		(= local6 1)
		(while (<= local6 global113)
			(if
				(==
					[gNewPropX (= local5 (* (- local6 1) 3))]
					gCurRoomNum
				)
				((View new:)
					view: 528
					loop: 0
					cel: 6
					posn: [gNewPropX (+ local5 1)] [gNewPropX (+ local5 2)]
					setPri: 0
					addToPic:
					ignoreActors:
				)
			)
			(++ local6)
		)
	)
	
	(method (handleEvent pEvent)
		(if (pEvent claimed?) (return 1))
		(return
			(if (== (pEvent type?) evSAID)
				(cond 
					((Said 'look/gravestone') (Print 16 0))
					((Said 'read,look/epitaph,gravestone,boulder')
						(cond 
							((& (gEgo onControl: 0) $0008) (Print 16 1 30 1 67 -1 15 70 290))
							((& (gEgo onControl: 0) $0020) (Print 16 2 30 1 67 -1 15 70 290))
							((& (gEgo onControl: 0) $0100) (Print 16 3 30 1 67 -1 15 70 290))
							((& (gEgo onControl: 0) $0200) (Print 16 4 30 1 67 -1 15 70 290))
							((& (gEgo onControl: 0) $0004) (Print 16 5 30 1 67 -1 15 70 290))
							((& (gEgo onControl: 0) $0002) (Print 16 6 30 1 67 -1 15 70 290))
							((& (gEgo onControl: 0) $0080) (Print 16 7 30 1 67 -1 15 70 290))
							((& (gEgo onControl: 0) $0040) (Print 16 8 30 1 67 -1 15 70 290))
							((& (gEgo onControl: 0) $0010) (Print 16 9 30 1 67 -1 15 70 290))
							((& (gEgo onControl: 0) $0400) (Print 16 10 30 1 67 -1 15 70 290))
							((& (gEgo onControl: 0) $1000) (Print 16 11 30 1 67 -1 15 70 290))
							(else (Print 800 1))
						)
					)
					((Said 'look>')
						(cond 
							((or (Said '<in/forest') (Said '/forest<hole'))
								(if (gEgo inRect: 103 115 226 177)
									(Print 16 12)
								else
									(Print 800 1)
								)
							)
							((Said '/cross') (Print 16 13))
							((Said '/forest') (Print 16 14))
							((Said '/hole')
								(= local7 1)
								(while (<= local7 global113)
									(if
										(and
											(== [gNewPropX (= local5 (* (- local7 1) 3))] 16)
											(<
												(egoDist
													doit: [gNewPropX (+ local5 1)] [gNewPropX (+ local5 2)]
												)
												20
											)
										)
										(= local8 1)
									)
									(++ local7)
								)
								(cond 
									(local8 (Print 16 15))
									((gEgo inRect: 103 115 226 177) (Print 16 12))
									(else (Print 800 1))
								)
								(= local8 0)
							)
							((Said '[<around][/room]') (Print 16 16))
						)
					)
					((Said 'dig[/grave,hole]')
						(if
						(and (gEgo has: 15) (== 0 ((Inv at: 15) loop?)))
							(if (> global134 0)
								(if (& (gEgo onControl: 0) $7fff)
									(gEgo setScript: digging)
									(digging changeState: 1)
								else
									(Print 16 17)
								)
							else
								(Print 16 18)
							)
						else
							(Print 16 19)
						)
					)
				)
			else
				0
			)
		)
	)
	
	(method (newRoom newRoomNumber)
		(gEgo illegalBits: -32768)
		(= global189 0)
		(if (== (gEgo view?) 2) (super newRoom: newRoomNumber))
	)
)

(instance z1Actions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0 (= seconds 4))
			(1
				(= global189 1)
				(zTheme play:)
				(newAct show: setCycle: End self)
				(++ global186)
				((View new:)
					view: 260
					posn: (newAct x?) (newAct y?)
					ignoreActors:
					addToPic:
				)
			)
			(2
				(if (== global105 0)
					(newAct
						view: 261
						setCycle: Walk
						setAvoider: (Avoid new:)
						setMotion: Chase gEgo 12 self
					)
				else
					(newAct
						view: 261
						setCycle: Walk
						setAvoider: (Avoid new:)
						setMotion: Wander 50
					)
				)
			)
			(3
				(cond 
					((gEgo has: 7) (self changeState: 4))
					((== global105 0) (self changeState: 10))
				)
			)
			(4
				(Print 16 20 67 -1 20)
				(if (== (-- global186) 0)
					(zTheme loop: 1 changeState:)
				)
				(newAct setMotion: 0 view: 260 cel: 0 setCycle: Beg self)
			)
			(5
				(newAct ignoreActors: addToPic:)
			)
			(10
				(proc0_8)
				(= global105 17)
				(zTheme stop:)
				(zTheme number: 21 loop: 1 play:)
				(gEgo view: 36 cel: 0 setCycle: End self)
				(newAct setMotion: Wander)
				(if
					(and
						(gCast contains: newAct_2)
						(== (newAct_2 mover?) Chase)
					)
					(newAct_2 setMotion: Wander)
				)
				(if
					(and
						(gCast contains: newAct_3)
						(== (newAct_3 mover?) Chase)
					)
					(newAct_3 setMotion: Wander)
				)
			)
			(11
				(gEgo view: 46 cel: 0 setCycle: End self)
			)
			(12
				(= global120 (Print 16 21 67 -1 20 88))
				(gEgo view: 45 setCycle: Walk setMotion: Wander)
				(= seconds 12)
			)
			(13
				(proc0_21)
				(zTheme stop:)
				(= global127 1)
			)
		)
	)
)

(instance z2Actions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0 (= seconds 10))
			(1
				(if (== (zTheme state?) 0) (zTheme play:))
				(if (== (zTheme loop?) 1)
					(zTheme loop: -1 changeState:)
				)
				(++ global186)
				(newAct_2 show: setCycle: End self)
				((View new:)
					view: 262
					cel: 0
					posn: (newAct_2 x?) (newAct_2 y?)
					ignoreActors:
					addToPic:
				)
			)
			(2
				(if (== global105 0)
					(newAct_2
						view: 263
						setCycle: Walk
						setAvoider: (Avoid new:)
						setMotion: Chase gEgo 12 self
					)
				else
					(newAct_2
						view: 263
						setCycle: Walk
						setAvoider: (Avoid new:)
						setMotion: Wander 50
					)
				)
			)
			(3
				(cond 
					((gEgo has: 7) (self changeState: 4))
					((== global105 0) (self changeState: 10))
				)
			)
			(4
				(newAct_2
					setMotion: 0
					view: 262
					cel: 0
					setCycle: Beg self
				)
				(Print 16 20 67 -1 20)
				(if (== (-- global186) 0)
					(zTheme loop: 1 changeState:)
				)
			)
			(5
				(newAct_2 ignoreActors: addToPic:)
			)
			(10
				(proc0_8)
				(= global105 17)
				(zTheme stop:)
				(zTheme number: 21 loop: 1 play:)
				(gEgo view: 36 cel: 0 setMotion: 0 setCycle: End self)
				(newAct_2 setMotion: Wander)
				(if
					(and
						(gCast contains: newAct)
						(== (newAct mover?) Chase)
					)
					(newAct setMotion: Wander)
				)
				(if
					(and
						(gCast contains: newAct_3)
						(== (newAct_3 mover?) Chase)
					)
					(newAct_3 setMotion: Wander)
				)
			)
			(11
				(gEgo view: 46 cel: 0 setCycle: End self)
			)
			(12
				(= global120 (Print 16 21 67 -1 20 88))
				(gEgo view: 45 setCycle: Walk setMotion: Wander)
				(= seconds 12)
			)
			(13
				(proc0_21)
				(zTheme stop:)
				(= global127 1)
			)
		)
	)
)

(instance z3Actions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0 (= seconds 15))
			(1
				(if (== (zTheme state?) 0) (zTheme play:))
				(if (== (zTheme loop?) 1)
					(zTheme loop: -1 changeState:)
				)
				(++ global186)
				(newAct_3 show: setCycle: End self)
				((View new:)
					view: 264
					posn: (newAct_3 x?) (newAct_3 y?)
					ignoreActors:
					addToPic:
				)
			)
			(2
				(if (== global105 0)
					(newAct_3
						view: 265
						setCycle: Walk
						setAvoider: (Avoid new:)
						setMotion: Chase gEgo 12 self
					)
				else
					(newAct_3
						view: 265
						setCycle: Walk
						setAvoider: (Avoid new:)
						setMotion: Wander 50
					)
				)
			)
			(3
				(cond 
					((gEgo has: 7) (self changeState: 4))
					((== global105 0) (self changeState: 10))
				)
			)
			(4
				(Print 16 20 67 -1 20)
				(if (== (-- global186) 0)
					(zTheme loop: 1 changeState:)
				)
				(newAct_3
					setMotion: 0
					view: 264
					cel: 0
					setCycle: Beg self
				)
			)
			(5
				(newAct_3 ignoreActors: addToPic:)
			)
			(10
				(proc0_8)
				(= global105 17)
				(zTheme stop:)
				(zTheme number: 21 loop: 1 play:)
				(gEgo view: 36 cel: 0 setMotion: 0 setCycle: End self)
				(newAct_3 setMotion: Wander)
				(if
					(and
						(gCast contains: newAct)
						(== (newAct mover?) Chase)
					)
					(newAct setMotion: Wander)
				)
				(if
					(and
						(gCast contains: newAct_2)
						(== (newAct_2 mover?) Chase)
					)
					(newAct_2 setMotion: Wander)
				)
			)
			(11
				(gEgo view: 46 cel: 0 setCycle: End self)
			)
			(12
				(= global120 (Print 16 21 67 -1 20 88))
				(gEgo view: 45 setCycle: Walk setMotion: Wander)
				(= seconds 12)
			)
			(13
				(proc0_21)
				(zTheme stop:)
				(= global127 1)
			)
		)
	)
)

(instance holeActions of Script
	(properties)
	
	(method (cue &tmp temp0)
		(= temp0 (newProp cel?))
		(++ temp0)
		(if (>= state 0) (newProp cel: temp0) else (++ state))
	)
)

(instance digging of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(1
				(proc0_8)
				(gEgo
					view: 47
					loop: (& (gEgo loop?) $0001)
					cel: 0
					setCycle: End self
				)
				(= newProp (Prop new:))
				(newProp
					posn:
						(if (== (gEgo loop?) 1)
							(- (gEgo x?) 16)
						else
							(+ (gEgo x?) 16)
						)
						(+ (gEgo y?) 4)
					view: 528
					cel: 0
					setPri: 0
					ignoreActors:
					init:
				)
			)
			(2
				(gEgo cel: 0 setCycle: End self)
			)
			(3
				(if (>= global113 5)
					(Print 16 22)
					(gEgo view: 2 setCycle: Walk)
					((Inv at: 15) loop: 1)
					(self changeState: 0)
					(proc0_9)
				else
					(gEgo cel: 0 setCycle: End self)
				)
			)
			(4
				(gEgo cel: 0 setCycle: End self)
			)
			(5
				(holeActions cue:)
				(if (< (newProp cel?) 6)
					(self changeState: 2)
				else
					(self changeState: 6)
				)
			)
			(6
				(= [gNewPropX (= local5 (* (- (++ global113) 1) 3))]
					gCurRoomNum
				)
				(= [gNewPropX (+ local5 1)] (newProp x?))
				(= [gNewPropX (+ local5 2)] (newProp y?))
				(gEgo view: 2 setCycle: Walk)
				(proc0_9)
				(cond 
					(
						(and
							(& (gEgo onControl: 0) $0008)
							(== global134 2)
							((Inv at: 13) ownedBy: 88)
						)
						(newProp setLoop: 1 cel: 2)
						(Print 16 23 67 -1 20 83)
						((Inv at: 13) moveTo: 16)
						(gEgo setScript: getItems)
						(getItems changeState: 1)
						(gEgo get: 13)
						(gGame changeScore: 3)
					)
					(
						(and
							(& (gEgo onControl: 0) $0100)
							(== global134 1)
							((Inv at: 12) ownedBy: 88)
						)
						(newProp setLoop: 1 cel: 1)
						(Print 16 24 67 -1 20 83)
						(gEgo setScript: getItems)
						(getItems changeState: 1)
						(gGame changeScore: 3)
						(gEgo get: 12)
					)
					(
						(and
							(& (gEgo onControl: 0) $0004)
							(== global134 4)
							((Inv at: 29) ownedBy: 88)
						)
						(newProp setLoop: 1 cel: 3)
						(Print 16 25 67 -1 20 83)
						((Inv at: 29) moveTo: 16)
						(gEgo setScript: getItems)
						(getItems changeState: 1)
						(gEgo get: 29)
						(gGame changeScore: 3)
					)
					(else (proc0_9) (Print 16 26 67 -1 20))
				)
			)
		)
	)
)

(instance getItems of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(1
				(proc0_8)
				(proc0_3 gEgo newProp)
				(gEgo view: 21 cel: 255 setCycle: End self)
			)
			(2
				(newProp setLoop: 0 cel: 6)
				(= global182 1)
				(gEgo setCycle: Beg self)
			)
			(3 (= cycles 6))
			(4
				(Print 16 27)
				(gEgo view: 2 setCycle: Walk)
				(proc0_9)
			)
		)
	)
)

(instance egoDist of Code
	(properties)
	
	(method (doit param1 param2 &tmp temp0)
		(= temp0
			(Sqrt
				(+
					(*
						(Abs (- (gEgo y?) param2))
						(Abs (- (gEgo y?) param2))
					)
					(*
						(Abs (- (gEgo x?) param1))
						(Abs (- (gEgo x?) param1))
					)
				)
			)
		)
	)
)
