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

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

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

(instance doorSound of Sound
	(properties
		number 300
		priority 3
	)
)

(instance door of Prop
	(properties)
	
	(method (cue)
		(self ignoreActors:)
		(gRoom newRoom: 69)
	)
)

(instance Room18 of Rm
	(properties
		picture 18
		horizon 85
		north 12
		south 24
		west 17
	)
	
	(method (init)
		(= global101 0)
		(Load rsVIEW 47)
		(gEgo edgeHit: 0 observeControl: 16384)
		(= global186 0)
		(super init:)
		(if global100 (gRoom overlay: 118))
		(self setRegions: 510 511)
		(if global100
			(Load rsVIEW 261)
			(Load rsVIEW 267)
			(Load rsVIEW 269)
			(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: 25 156
				setScript: z1Actions
				init:
				hide:
			)
			(newAct_2
				view: 266
				loop: 0
				cel: 0
				xStep: 2
				yStep: 1
				posn: 109 131
				setScript: z4Actions
				init:
				hide:
			)
			(newAct_3
				view: 268
				loop: 0
				cel: 0
				xStep: 2
				yStep: 1
				posn: 220 165
				setScript: z5Actions
				init:
				hide:
			)
		)
		(if (== global174 2)
			(gEgo ignoreControl: 16384)
			(door
				posn: 273 148
				view: 611
				loop: 0
				cel: 4
				setPri: 0
				ignoreActors:
				init:
				stopUpd:
			)
		else
			(door
				posn: 273 148
				view: 611
				loop: 0
				cel: 0
				setPri: 0
				init:
				stopUpd:
			)
		)
		(switch gPrevRoomNum
			(west (gEgo posn: 2 (gEgo y?)))
			(north
				(gEgo x: 45 y: (+ horizon (gEgo yStep?) 1))
			)
			(south (gEgo posn: 172 188))
			(69
				(gEgo
					x: 266
					y: 153
					xStep: 3
					yStep: 2
					ignoreControl: 16384
				)
				(door
					posn: 273 148
					view: 611
					loop: 0
					cel: 4
					setPri: 0
					ignoreActors:
					init:
					stopUpd:
				)
			)
			(0 (gEgo x: 180 y: 188))
		)
		(= global105 0)
		(gEgo view: 2 init:)
		(= 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)]
					ignoreActors:
					setPri: 0
					addToPic:
					ignoreActors:
				)
			)
			(++ local6)
		)
	)
	
	(method (doit)
		(super doit:)
		(if (& (gEgo onControl: 0) $4000)
			(gRoom newRoom: 69)
		)
	)
	
	(method (handleEvent pEvent)
		(if (pEvent claimed?) (return 1))
		(return
			(if (== (pEvent type?) evSAID)
				(cond 
					((Said 'climb/boulder') (Print 18 0))
					((Said 'open,enter/crypt')
						(if (== global174 2)
							(Print 18 1)
						else
							(Print 18 2)
						)
					)
					((Said 'look>')
						(cond 
							((Said '/boulder') (Print 18 3))
							((Said '/grass') (Print 18 4))
							((Said '/crypt') (Print 18 5))
							((Said '/cliff') (Print 18 6))
							((Said '/gravestone') (Print 18 7))
							((Said '/monument,lion') (Print 18 8))
							((Said '/door')
								(if (== (door cel?) 0)
									(Print 18 9)
								else
									(Print 18 10)
								)
							)
							((Said '/hole')
								(= local7 1)
								(while (<= local7 global113)
									(if
										(and
											(== [gNewPropX (= local5 (* (- local7 1) 3))] 18)
											(<
												(egoDist
													doit: [gNewPropX (+ local5 1)] [gNewPropX (+ local5 2)]
												)
												20
											)
										)
										(= local8 1)
									)
									(++ local7)
								)
								(if (>= global113 0)
									(if local8 (Print 18 11) else (Print 800 1))
								else
									(Print 18 12)
								)
								(= local8 0)
							)
							((Said '[<around][/room]') (Print 18 13) (Print 18 14))
						)
					)
				)
				(cond 
					((Said '/door>')
						(cond 
							((Said 'break') (Print 18 15))
							((Said 'bang')
								(if (gEgo inRect: 262 149 292 157)
									(Print 18 16)
								else
									(Print 800 1)
								)
							)
							((Said 'open')
								(if (gEgo inRect: 262 149 292 157)
									(cond 
										((== global174 1)
											(doorSound play: door)
											(gEgo setMotion: 0 ignoreControl: 16384)
											(proc0_8)
											(= global174 2)
											(= global205 1)
											(door setCycle: End door)
										)
										((== global174 0) (Print 18 17))
										(else (Print 18 18))
									)
								else
									(Print 800 1)
								)
							)
							((Said 'close')
								(if (== (door cel?) 0)
									(Print 18 19)
								else
									(Print 18 20)
									(door setCycle: Beg)
									(gEgo observeControl: 16384)
									(= global174 1)
									(doorSound play:)
								)
							)
							((Said 'latch')
								(if ((Inv at: 20) ownedBy: gEgo)
									(if (gEgo inRect: 262 149 292 157)
										(cond 
											((== global174 1)
												(if
												(and ((Inv at: 4) ownedBy: 69) (== global109 99))
													(Print 18 21 83)
													(gGame changeScore: 2)
													(gEgo put: 20 18)
													(= global174 0)
													(gEgo observeControl: 16384)
												else
													(Print 18 22)
													(= global174 0)
												)
											)
											((== global174 2) (Print 18 23))
											((== global174 0) (Print 18 24))
										)
									else
										(Print 800 1)
									)
								else
									(Print 18 25)
								)
							)
							((Said 'unlatch')
								(if (gEgo inRect: 262 149 292 157)
									(cond 
										((== global174 0)
											(if ((Inv at: 20) ownedBy: gEgo)
												(Print 18 26)
												(if (not global187)
													(gGame changeScore: 3)
													(++ global187)
												)
												(= global174 1)
											else
												(Print 18 27)
											)
										)
										((== global174 2) (Print 18 28))
										((== global174 1) (Print 18 29))
									)
								else
									(Print 800 1)
								)
							)
						)
					)
					((Said 'read,look/epitaph,gravestone,boulder')
						(cond 
							((& (gEgo onControl: 0) $0004) (Print 18 30 30 1 67 -1 15 70 290))
							((& (gEgo onControl: 0) $0080) (Print 18 31 30 1 67 -1 15 70 290))
							((& (gEgo onControl: 0) $0008) (Print 18 32 30 1 67 -1 15 70 290))
							((& (gEgo onControl: 0) $0020) (Print 18 33 30 1 67 -1 15 70 290))
							((& (gEgo onControl: 0) $1000) (Print 18 34 30 1 67 -1 15 70 290))
							((& (gEgo onControl: 0) $0002) (Print 18 35 30 1 67 -1 15 70 290))
							((& (gEgo onControl: 0) $0010) (Print 18 36 30 1 67 -1 15 70 290))
							((& (gEgo onControl: 0) $0100) (Print 18 37 30 1 67 -1 15 70 290))
							(else (Print 800 1))
						)
					)
					((Said 'dig[/hole,grave]')
						(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 18 38)
								)
							else
								(Print 18 39)
							)
						else
							(Print 18 40)
						)
					)
				)
			else
				0
			)
		)
	)
	
	(method (newRoom newRoomNumber)
		(proc0_9)
		(= global189 0)
		(if (== (gEgo view?) 2) (super newRoom: newRoomNumber))
	)
)

(instance z4Actions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0 (= seconds 4))
			(1
				(= global189 1)
				(zTheme loop: -1 play:)
				(++ global186)
				(newAct_2 show: setCycle: End self)
				((View new:)
					view: 266
					posn: (newAct_2 x?) (newAct_2 y?)
					ignoreActors:
					addToPic:
				)
			)
			(2
				(if (== global105 0)
					(newAct_2
						view: 267
						setCycle: Walk
						setAvoider: (Avoid new:)
						setMotion: Chase gEgo 12 self
					)
				else
					(newAct_2
						view: 267
						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: 266
					cel: 0
					setCycle: Beg self
				)
				(Print 18 41)
				(if (== (-- global186) 0)
					(zTheme loop: 1 changeState:)
				)
			)
			(5
				(newAct_2 ignoreActors: addToPic:)
			)
			(10
				(proc0_8)
				(= global105 17)
				(zTheme dispose: number: 21 play:)
				(gEgo view: 36 cel: 255 setCycle: End self)
				(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)
				)
				(if (gCast contains: newAct) (newAct setMotion: Wander))
				(newAct_2 setMotion: Wander)
			)
			(11
				(gEgo view: 46 cel: 255 setCycle: End self)
			)
			(12
				(= global120 (Print 18 42 67 -1 0 88))
				(gEgo view: 45 setCycle: Walk setMotion: Wander)
				(= seconds 12)
			)
			(13
				(proc0_21)
				(zTheme stop:)
				(= global127 1)
			)
		)
	)
)

(instance z5Actions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0 (= seconds 8))
			(1
				(++ global186)
				(if (== (zTheme state?) 0) (zTheme loop: -1 play:))
				(if (== (zTheme loop?) 1)
					(zTheme loop: -1 changeState:)
				)
				(newAct_3 show: setCycle: End self)
				((View new:)
					view: 268
					cel: 0
					posn: (newAct_3 x?) (newAct_3 y?)
					ignoreActors:
					addToPic:
				)
			)
			(2
				(if (== global105 0)
					(newAct_3
						view: 269
						setCycle: Walk
						setAvoider: (Avoid new:)
						setMotion: Chase gEgo 12 self
					)
				else
					(newAct_3
						view: 269
						setCycle: Walk
						setAvoider: (Avoid new:)
						setMotion: Wander 50 self
					)
				)
			)
			(3
				(cond 
					((gEgo has: 7) (self changeState: 4))
					((== global105 0) (self changeState: 10))
				)
			)
			(4
				(Print 18 41)
				(if (== (-- global186) 0)
					(zTheme loop: 1 changeState:)
				)
				(newAct_3
					setMotion: 0
					view: 268
					cel: 0
					setCycle: Beg self
				)
			)
			(5
				(newAct_3 ignoreActors: addToPic:)
			)
			(10
				(proc0_8)
				(= global105 17)
				(zTheme dispose: number: 21 play:)
				(gEgo view: 36 cel: 255 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_3)
						(== (newAct_2 mover?) Chase)
					)
					(newAct_2 setMotion: Wander)
				)
			)
			(11
				(gEgo view: 46 cel: 255 setCycle: End self)
			)
			(12
				(= global120 (Print 18 42 67 -1 0 88))
				(gEgo view: 45 setCycle: Walk setMotion: Wander)
				(= seconds 12)
			)
			(13
				(proc0_21)
				(zTheme stop:)
				(= global127 1)
			)
		)
	)
)

(instance z1Actions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0 (= seconds 10))
			(1
				(if (== (zTheme state?) 0) (zTheme loop: -1 play:))
				(if (== (zTheme loop?) 1)
					(zTheme loop: -1 changeState:)
				)
				(++ global186)
				(= global189 1)
				(newAct show: setCycle: End self)
				((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 18 41)
				(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 dispose: number: 21 play:)
				(gEgo view: 36 cel: 255 setMotion: 0 setCycle: End self)
				(newAct setMotion: Wander)
				(if
					(and
						(gCast contains: newAct_3)
						(== (newAct_3 mover?) Chase)
					)
					(newAct_3 setMotion: Wander)
				)
				(if
					(and
						(gCast contains: newAct_2)
						(== (newAct_2 mover?) Chase)
					)
					(newAct_2 setMotion: Wander)
				)
			)
			(11
				(gEgo view: 46 cel: 255 setCycle: End self)
			)
			(12
				(= global120 (Print 18 42 67 -1 0 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: 255
					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: 255 setCycle: End self)
			)
			(3
				(if (>= global113 5)
					(Print 18 43)
					(gEgo view: 2 setCycle: Walk)
					((Inv at: 15) loop: 1)
					(self changeState: 0)
					(proc0_9)
				else
					(gEgo cel: 255 setCycle: End self)
				)
			)
			(4
				(gEgo cel: 255 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) $0020)
							(== global134 5)
							((Inv at: 30) ownedBy: 88)
						)
						(newProp setLoop: 1 cel: 4)
						(Print 18 44 83)
						(gEgo setScript: getItems)
						(gEgo get: 30)
						(getItems changeState: 1)
						(gGame changeScore: 3)
					)
					(
						(and
							(& (gEgo onControl: 0) $0004)
							(== global134 3)
							((Inv at: 28) ownedBy: 88)
						)
						(newProp setLoop: 1 cel: 0)
						(Print 18 45 83)
						(gEgo setScript: getItems)
						(getItems changeState: 1)
						(gEgo get: 28)
						(gGame changeScore: 3)
					)
					(else (Print 18 46))
				)
				(proc0_9)
			)
		)
	)
)

(instance getItems of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(1
				(proc0_8)
				(gEgo view: 21 cel: 255 setCycle: End self)
			)
			(2
				(newProp setLoop: 0 cel: 6)
				(= global182 1)
				(gEgo setCycle: Beg self)
			)
			(3
				(gEgo view: 2 setCycle: Walk)
				(Print 18 47)
				(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))
					)
				)
			)
		)
	)
)
