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

(public
	regHauntedHouse 0
)
(synonyms
	(room cottage)
)

(local
	local0
	local1
)
(class GhostWander of Motion
	(properties
		client 0
		caller 0
		x 0
		y 0
		dx 0
		dy 0
		b-moveCnt 0
		b-i1 0
		b-i2 0
		b-di 0
		b-xAxis 0
		b-incr 0
		completed 0
		ux 0
		uy 0
		lx 0
		ly 0
	)
	
	(method (init param1 theUx theUy theLx theLy &tmp theUx_2 theUy_2)
		(= ux theUx)
		(= uy theUy)
		(= lx theLx)
		(= ly theLy)
		(switch (/ (Random 10 29) 10)
			(1 (= theUx_2 ux))
			(2 (= theUx_2 lx))
		)
		(switch (/ (Random 10 29) 10)
			(1 (= theUy_2 uy))
			(2 (= theUy_2 ly))
		)
		(super init: param1 theUx_2 theUy_2)
		(super doit:)
	)
	
	(method (doit)
		(super doit:)
		(if (client isStopped:) (self moveDone:))
	)
	
	(method (moveDone)
		(self init: client ux uy lx ly)
	)
)

(instance theGhost of Act
	(properties)
)

(instance regHauntedHouse of Rgn
	(properties)
	
	(method (init)
		(if initialized (return))
		(= global189 (= keep 1))
		(super init:)
		(if global100
			(theGhost
				view: 201
				illegalBits: 0
				ignoreActors: 1
				posn: 999 999
				init:
			)
			(if (not global134) (= global134 1))
			(self notify: global134)
		)
		(miserGhostMusic owner: self init:)
		(ladyGhostMusic owner: self init:)
		(lordGhostMusic owner: self init:)
		(boyGhostMusic owner: self init:)
	)
	
	(method (dispose)
		(if (== keep 0) (= global189 0) (super dispose:))
	)
	
	(method (newRoom newRoomNumber)
		(gSounds eachElementDo: #stop 0)
		(if (IsObject script) (script cue: -2 newRoomNumber))
		(= global135 0)
		(if (== newRoomNumber 17) (proc0_9))
		(super newRoom: newRoomNumber)
	)
	
	(method (notify param1)
		(cond 
			((and script (not argc)) (script cue:))
			((and script (< param1 0)) (script cue: param1 &rest))
			(else
				(self
					setScript:
						(switch (= global134 param1)
							(1 babyScript)
							(2 miserScript)
							(3 ladyScript)
							(4 lordScript)
							(5 boyScript)
							(else  0)
						)
				)
			)
		)
	)
)

(instance babyScript of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(= global133 59)
				(= seconds 5)
			)
			(1
				(Print 603 0)
				(= seconds 10)
			)
			(2
				(if
					(and
						(!= gCurRoomNum 61)
						(!= gCurRoomNum 66)
						(!= gCurRoomNum 59)
						(!= gCurRoomNum 58)
					)
					(Print 603 1)
				)
				(-- state)
				(= seconds (Random 10 30))
			)
		)
	)
	
	(method (cue)
		(if (not argc) (super cue:))
	)
)

(instance miserScript of Script
	(properties)
	
	(method (changeState newState &tmp temp0 temp1 temp2)
		(switch (= state newState)
			(0
				(Load rsVIEW 200)
				(Load rsVIEW 201)
				(= global133 164)
				(= local0 1)
				(= seconds (Random 5 10))
			)
			(1
				(Print 603 2)
				(= cycles 5)
			)
			(2 (= seconds 3))
			(3
				(if
					(and
						(!= gCurRoomNum 66)
						(!= gCurRoomNum 61)
						(!= gCurRoomNum 58)
					)
					(Print 603 3)
				)
				(-- state)
				(= seconds (Random 40 99))
			)
			(4
				(= seconds 0)
				(= global135 1)
				(miserGhostMusic play:)
				(switch global133
					(67 (= temp1 145))
					(68 (= temp1 180))
					(64 (= temp1 145))
				)
				(switch local0
					(0 (= temp0 -33))
					(1 (= temp0 333))
				)
				(switch local0
					(0 (= temp2 333))
					(1 (= temp2 -33))
				)
				(theGhost
					view: 201
					illegalBits: 0
					posn: temp0 temp1
					ignoreActors: 1
					init:
					setLoop: local0
					setCycle: Walk
					setMotion: MoveTo temp2 temp1 self
				)
				(= global225 1)
			)
			(5 (= global225 0))
			(6
				(proc0_8)
				(Print 603 4)
				(gEgo put: 13 -1)
				(gGame changeScore: 2)
				(theGhost setLoop: setMotion: 0)
				(= seconds 2)
			)
			(7
				(theGhost
					view: 200
					cycleSpeed: 1
					setCel: 255
					setCycle: Beg self
				)
			)
			(8
				(= global225 0)
				(proc0_9)
				(regHauntedHouse notify: 3)
			)
		)
	)
	
	(method (cue param1)
		(cond 
			((not argc) (super cue:))
			((== param1 -1)
				(= seconds 0)
				(self
					changeState: (cond 
						((< state 4) 4)
						((< state 6) 6)
					)
				)
			)
			((== param1 -2)
				(switch global133
					(164
						(= global133 64)
						(= local0 1)
					)
					(64
						(if (== local0 1)
							(= global133 68)
						else
							(= global133 164)
						)
					)
					(68
						(if (== local0 1)
							(= global133 67)
						else
							(= global133 64)
						)
					)
					(67
						(if (== local0 1)
							(= global133 167)
						else
							(= global133 68)
						)
					)
					(167
						(= global133 67)
						(= local0 0)
					)
				)
				(if (< state 6) (self changeState: 2))
			)
		)
	)
	
	(method (handleEvent pEvent &tmp gInvSaidMe)
		(if
			(or
				(pEvent claimed?)
				(!= (pEvent type?) evSAID)
				(!= gCurRoomNum global133)
				(not (gCast contains: theGhost))
				(== global225 0)
			)
			(return)
		)
		(cond 
			((Said 'look/chain') (Print 603 5))
			((Said 'get/chain') (Print 603 6))
			((Said 'deliver>')
				(cond 
					(
						(or
							(not (= gInvSaidMe (gInv saidMe:)))
							(not (gEgo has: (gInv indexOf: gInvSaidMe)))
						)
						(pEvent claimed: 0)
					)
					((> (gEgo distanceTo: theGhost) 30) (proc0_13))
					((!= (gInv indexOf: gInvSaidMe) 13) (Print 603 7))
					(else (self cue: -1))
				)
			)
			((Said 'converse') (Print 603 8))
			((Said 'look') (Print 603 9))
			((Said 'kiss') (Print 603 10))
			((Said 'capture,get') (Print 603 11))
			((Said 'kill') (Print 603 12))
			((Said 'help') (Print 603 13))
		)
	)
)

(instance ladyScript of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(theGhost posn: (theGhost x?) (+ (theGhost y?) 1000))
				(Load rsVIEW 202)
				(Load rsVIEW 203)
				(= global133 60)
				(= global225 0)
				(= seconds 3)
			)
			(1
				(Print 603 14)
				(= seconds (Random 10 30))
			)
			(2 (= seconds 3))
			(3
				(if
					(and
						(!= gCurRoomNum 66)
						(!= gCurRoomNum 61)
						(!= gCurRoomNum 58)
						(!= gCurRoomNum 60)
					)
					(Print 603 15)
				)
				(-- state)
				(= seconds (Random 50 99))
			)
			(4
				(= global135 1)
				(= seconds 3)
			)
			(5
				(ladyGhostMusic play:)
				(= global225 1)
				(theGhost
					view: 202
					posn: 85 133
					ignoreActors: 1
					cycleSpeed: 3
					loop: 0
					cel: 0
					setCycle: End self
					init:
				)
			)
			(6
				(theGhost view: 203 setCycle: Fwd)
			)
			(7
				(proc0_8)
				(theGhost
					view: 202
					loop: 0
					setCel: 255
					setCycle: Beg self
				)
			)
			(8
				(= global225 0)
				(proc0_9)
				(= global133 67)
				(regHauntedHouse notify: 4)
			)
		)
	)
	
	(method (cue param1)
		(cond 
			((not argc) (super cue:))
			((== param1 -1)
				(= seconds 0)
				(self
					changeState: (cond 
						((< state 4) 4)
						((< state 7) 7)
					)
				)
			)
			((and (== param1 -2) (< state 7)) (self changeState: 2))
		)
	)
)

(instance lordScript of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(theGhost posn: (theGhost x?) (+ (theGhost y?) 1000))
				(Load rsVIEW 204)
				(Load rsVIEW 206)
				(= seconds 3)
			)
			(1
				(Print 603 16)
				(= seconds (Random 3 5))
			)
			(2 (= seconds 3))
			(3
				(if
					(and
						(!= gCurRoomNum 66)
						(!= gCurRoomNum 61)
						(!= gCurRoomNum 58)
					)
					(Print 603 17)
				)
				(-- state)
				(= seconds (Random 40 99))
			)
			(4
				(= global135 1)
				(= seconds (Random 2 5))
			)
			(5
				(= seconds 0)
				(lordGhostMusic play:)
				(theGhost
					view: 204
					cel: 0
					posn: 150 160
					illegalBits: 0
					cycleSpeed: 1
					ignoreActors: 1
					setStep: 4 2
					setCycle: End self
					init:
				)
			)
			(6
				(theGhost
					view: 206
					loop: (Random 0 3)
					moveSpeed: 1
					cycleSpeed: 1
					setLoop: -1
					setCycle: Walk
				)
				(if (== gCurRoomNum 68)
					(theGhost setMotion: GhostWander 78 156 225 185)
				else
					(theGhost setMotion: GhostWander 75 130 225 175)
				)
				(= global225 1)
				(= seconds (Random 13 30))
			)
			(7
				(theGhost
					view: 204
					loop: 0
					setCel: 255
					setCycle: Beg self
				)
			)
			(8
				(= global225 0)
				(= state 4)
				(= seconds (Random 20 99))
			)
			(9
				(proc0_8)
				(Print 603 18)
				(theGhost setMotion: 0)
				(= seconds 3)
			)
			(10
				(= seconds 0)
				(gEgo put: 29 -1)
				(gGame changeScore: 2)
				(theGhost
					view: 204
					loop: 0
					setCel: 255
					setCycle: Beg self
				)
			)
			(11
				(proc0_9)
				(= global225 0)
				(regHauntedHouse notify: 5)
			)
		)
	)
	
	(method (cue param1 param2)
		(cond 
			((not argc) (super cue:))
			((== param1 -1)
				(= seconds 0)
				(self
					changeState: (cond 
						((< state 4) 4)
						((< state 9) 9)
					)
				)
			)
			((== param1 -2)
				(= global133
					(if
						(and
							(<= 64 param2)
							(<= param2 68)
							(!= param2 66)
							(Random 0 1)
						)
						param2
					else
						0
					)
				)
				(self changeState: 2)
			)
		)
	)
	
	(method (handleEvent pEvent &tmp gInvSaidMe)
		(if
			(or
				(pEvent claimed?)
				(!= (pEvent type?) evSAID)
				(!= gCurRoomNum global133)
				(not global135)
				(== global225 0)
			)
			(return)
		)
		(cond 
			((Said 'deliver>')
				(cond 
					(
						(or
							(not (= gInvSaidMe (gInv saidMe:)))
							(not (gEgo has: (gInv indexOf: gInvSaidMe)))
						)
						(pEvent claimed: 0)
					)
					((> (gEgo distanceTo: theGhost) 30) (proc0_13))
					((!= (gInv indexOf: gInvSaidMe) 29) (Print 603 19))
					(else (self changeState: 9))
				)
			)
			((Said 'converse') (Print 603 20))
			((Said 'look') (Print 603 21))
			((Said 'kiss') (Print 603 10))
			((Said 'get,capture/*') (Print 603 22))
			((Said 'kill/*') (Print 603 12))
			((Said 'help/*') (Print 603 23))
		)
	)
)

(instance boyScript of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0 (= seconds 2))
			(1
				(theGhost posn: (theGhost x?) (+ (theGhost y?) 1000))
				(Load rsVIEW 207)
				(Load rsVIEW 208)
				(= global134 5)
				(= seconds 2)
			)
			(2
				(boyGhostMusic client: 0 stop:)
				(cond 
					((== gCurRoomNum 60) (= global135 1) (= cycles 1))
					(
						(and
							(!= gCurRoomNum 66)
							(!= gCurRoomNum 61)
							(!= gCurRoomNum 58)
						)
						(= global135 1)
						(= seconds (Random 1 3))
					)
				)
			)
			(3
				(boyGhostMusic play:)
				(theGhost
					view: 207
					illegalBits: 0
					ignoreActors: 1
					setPri: -1
					loop: 0
					cel: 0
					setCycle: End self
					posn:
						(switch gCurRoomNum
							(60 159)
							(64 83)
							(65 255)
							(67 239)
							(68 165)
						)
						(switch gCurRoomNum
							(60 136)
							(64 124)
							(65 148)
							(67 136)
							(68 83)
						)
					init:
				)
				(if (== gCurRoomNum 60) (theGhost setPri: 10))
			)
			(4
				(if (== local1 0)
					(= local1 1)
					(Print 603 24)
				else
					(Print 603 25)
				)
				(theGhost
					view: 208
					moveSpeed: 0
					cycleSpeed: 0
					setLoop: -1
					setCycle: Walk
				)
				(switch gCurRoomNum
					(60
						(theGhost
							setPri: 10
							setCycle: Fwd
							setMotion: MoveTo 158 15
						)
						(= global133 63)
					)
					(64
						(theGhost setPri: 9 setMotion: MoveTo 0 143 self)
						(= global133 68)
					)
					(65
						(theGhost setMotion: MoveTo 240 190 self)
						(= global133 64)
					)
					(67
						(theGhost setMotion: MoveTo 300 136 self)
						(= global133 68)
					)
					(68
						(theGhost setMotion: MoveTo 193 73 self)
						(= global133 60)
					)
				)
			)
			(5
				(theGhost
					view: 207
					loop: 0
					setCel: 255
					setCycle: Beg self
				)
			)
			(6
				(= global135 0)
				(theGhost posn: (theGhost x?) (+ (theGhost y?) 1000))
			)
			(11
				(= global135 1)
				(Load rsVIEW 209)
				(boyGhostMusic play:)
				(theGhost
					view: 207
					loop: 1
					cel: 0
					posn: 167 117
					setPri: 8
					cycleSpeed: 1
					setCycle: End self
					illegalBits: 0
					ignoreActors:
					init:
				)
			)
			(12
				(theGhost
					view: 209
					loop: (Random 0 3)
					cycleSpeed: 1
					setCycle: Fwd
				)
				(= seconds 5)
			)
			(13
				(if (== gCurRoomNum 63) (Print 603 26))
				(= seconds 3)
			)
			(14
				(theGhost loop: (Random 0 3))
				(-- state)
				(= cycles (Random 30 60))
			)
			(21
				(proc0_8)
				(Print 603 27)
				(gEgo put: 30 -1)
				(gGame changeScore: 2)
				(= seconds 2)
			)
			(22
				(= global134 255)
				(theGhost
					view: 207
					loop: 1
					setCel: 255
					setCycle: Beg self
					init:
				)
			)
			(23
				(proc0_9)
				(theGhost dispose:)
				(regHauntedHouse notify: 255)
			)
		)
	)
	
	(method (cue param1)
		(cond 
			((not argc) (super cue:))
			((== param1 -1)
				(= seconds 0)
				(self
					changeState: (cond 
						((== gCurRoomNum 63) 11)
						((< state 11) 2)
					)
				)
			)
		)
	)
	
	(method (handleEvent pEvent &tmp gInvSaidMe)
		(if
			(or
				(pEvent claimed?)
				(!= (pEvent type?) evSAID)
				(!= gCurRoomNum global133)
				(not global135)
			)
			(return)
		)
		(cond 
			((Said 'deliver>')
				(cond 
					(
						(or
							(not (= gInvSaidMe (gInv saidMe:)))
							(not (gEgo has: (gInv indexOf: gInvSaidMe)))
						)
						(pEvent claimed: 0)
					)
					((> (gEgo distanceTo: theGhost) 30) (proc0_13))
					((!= (gInv indexOf: gInvSaidMe) 30) (Print 603 28))
					((!= gCurRoomNum 63) (Print 603 29))
					(else (self changeState: 21))
				)
			)
			((Said 'converse') (Print 603 30))
			((Said 'kiss') (Print 603 10))
			((Said 'look/ghost[<boy]')
				(if (== gCurRoomNum 63)
					(Print 603 31)
				else
					(Print 603 32)
				)
			)
			((Said 'play/ghost[<boy]') (Print 603 33))
			((Said 'capture,get/ghost[<boy]') (Print 603 11))
			((Said 'kill/*') (Print 603 12))
			((Said 'help,save/*') (Print 603 34))
		)
	)
)

(instance lordGhostMusic of Sound
	(properties
		number 25
	)
)

(instance miserGhostMusic of Sound
	(properties
		number 23
	)
)

(instance ladyGhostMusic of Sound
	(properties
		number 24
	)
)

(instance boyGhostMusic of Sound
	(properties
		number 26
	)
)
