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

(public
	regTroll 0
)
(synonyms
	(dirt dirt dirt dirt dirt)
	(kiss kiss embrace)
	(troll troll troll troll troll man)
)

(local
	newAct
	local1
	local2
	local3
)
(instance trollCaveMusic of Sound
	(properties
		number 66
		priority -1
	)
)

(instance caughtMusic of Sound
	(properties
		number 38
		priority 3
	)
)

(instance trollMusic of Sound
	(properties
		number 37
		priority 2
		loop -1
	)
	
	(method (play)
		(trollCaveMusic client: 0 stop:)
		(super play: &rest)
	)
)

(instance regTroll of Rgn
	(properties)
	
	(method (init)
		(if initialized (return))
		(= keep 1)
		(if (gEgo has: 3) (Load rsVIEW 967))
		(Load rsVIEW 904)
		(Load rsVIEW 190)
		(super init:)
		(= global189 1)
		(= local2 0)
		(= global126 0)
		(= local1 0)
		(= local3 0)
		(trollCaveMusic owner: self init:)
		(trollMusic owner: self init:)
		(caughtMusic owner: self init:)
		(doMusic cue:)
	)
	
	(method (doit)
		(super doit:)
		(if (== script gotchaScript) (return))
		(if
			(and
				(not (proc0_20))
				(not (& (gEgo onControl: 0) $0002))
			)
			(gEgo dispose:)
			(proc0_18)
			(Print 605 1)
			(self setScript: gotchaScript)
			(return)
		)
		(if
		(and (not (gCast contains: newAct)) (== global126 1))
			(trollScript changeState: 1)
		)
		(if (not local1)
			(= local1 1)
			(if
				(and
					(not global126)
					(< (Random 0 100) 50)
					(!= gCurRoomNum 76)
					(!= gCurRoomNum 73)
				)
				(trollScript start: 0)
				(self setScript: trollScript)
			)
		)
	)
	
	(method (dispose)
		(if (== keep 0) (= global189 0) (super dispose:))
	)
	
	(method (handleEvent pEvent &tmp gInvSaidMe temp1 temp2)
		(super handleEvent: pEvent)
		(if (pEvent claimed?) (return 1))
		(return
			(if (== (pEvent type?) evSAID)
				(= temp2 (if (proc0_20) (gEgo has: 3) else 0))
				(cond 
					(
					(and (gEgo has: 3) (Said '/chandelier,lantern[<oil]>'))
						(cond 
							((Said 'extinguish,(turn<off)') (self notify: 0))
							((Said 'light,ignite,(turn<on)') (self notify: 1))
						)
					)
					((Said 'look>')
						(cond 
							((Said '<out[/cave]') (Print 605 2))
							((and temp2 (Said '[<in,at]/cave[<troll,dark]')) (Print 605 3))
							(
							(and temp2 (or (Said '/dirt') (Said '<down'))) (Print 605 4))
							((and temp2 (Said '/passageway')) (Print 605 5))
							((Said '/troll') (Print 605 6))
							((gInv saidMe:) (pEvent claimed: 0))
							(else (Print 605 7) (pEvent claimed: 1))
						)
					)
					(
					(or (Said 'climb/boulder') (Said 'get/boulder')) (Print 605 8))
					((Said 'find/troll') (Print 605 6))
					((gCast contains: newAct)
						(cond 
							((Said 'converse/troll') (Print 605 9))
							((Said 'kill/troll') (Print 605 10))
							((Said 'get,capture/troll') (Print 605 11))
							((or (Said 'kiss/troll') (Said 'kiss[/!*]')) (Print 605 12))
							(
								(and
									(Said 'deliver>')
									(= gInvSaidMe (gInv saidMe:))
									(gEgo has: (gInv indexOf: gInvSaidMe))
								)
								(Print 605 13)
							)
						)
					)
				)
			else
				0
			)
		)
	)
	
	(method (newRoom newRoomNumber)
		(= local1 0)
		(= local3 0)
		(proc0_21)
		(if
			(and
				(!= newRoomNumber 77)
				(!= newRoomNumber 70)
				(not (gCast contains: newAct))
			)
			(doMusic cue:)
		)
		(super newRoom: newRoomNumber)
	)
	
	(method (notify param1)
		(switch param1
			(2
				(gEgo view: 904)
				(theLight dispose:)
			)
			(3
				(gEgo view: 967)
				(theLight setLoop: 4 init:)
			)
			(1
				(gEgo view: 967)
				(theLight setLoop: 4 init:)
				(proc0_18)
				(proc0_20 1)
			)
			(0
				(gEgo view: 904)
				(theLight dispose:)
				(cond 
					(local3 (gEgo dispose:) (proc0_18))
					((& (gEgo onControl: 0) $0002) (proc0_20 0))
					(else
						(gEgo dispose:)
						(proc0_18)
						(Print 605 0)
						(self setScript: gotchaScript)
					)
				)
			)
			(4
				(trollMusic client: 0 stop:)
				(if (IsObject newAct)
					(newAct setMotion: 0 setScript: 0)
				)
			)
		)
	)
)

(instance trollScript of Script
	(properties)
	
	(method (doit)
		(if
			(and
				(gCast contains: newAct)
				(< (self state?) 5)
				(< (gEgo distanceTo: newAct) 5)
			)
			(self changeState: 5)
			(return)
		)
		(super doit:)
	)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(if (not local2) (= seconds 2))
			)
			(1
				(if
					(and
						(not global126)
						(or
							(== gCurRoomNum 71)
							(== gCurRoomNum 72)
							(== gCurRoomNum 74)
							(== gCurRoomNum 75)
						)
					)
					(Print 605 14 67 200 40 88)
					(= global126 1)
					((= newAct (Act new:))
						view: 190
						setAvoider: Avoid 1
						illegalBits: 0
						xStep: 5
						yStep: 2
						init:
						setCycle: Walk
					)
					(switch gCurRoomNum
						(71 (newAct posn: 230 96))
						(72 (newAct posn: 190 180))
						(74 (newAct posn: 73 166))
						(75 (newAct posn: 107 89))
					)
					(trollCaveMusic client: 0 stop:)
					(trollMusic stop: loop: 1 play:)
				else
					(if (or (!= global126 1) (== gCurRoomNum 73)) (return))
					((= newAct (Act new:))
						view: 190
						setAvoider: Avoid 1
						setCycle: Walk
						illegalBits: 0
						ignoreActors: 1
						xStep: 6
						yStep: 2
						init:
					)
					(switch gCurRoomNum
						(71
							(switch gPrevRoomNum
								(74 (newAct posn: 213 210))
								(72 (newAct posn: 250 101))
								(else  (newAct posn: 179 196))
							)
						)
						(72
							(switch gPrevRoomNum
								(71 (newAct posn: 20 92))
								(75 (newAct posn: 180 220))
								(else  (newAct posn: 178 154))
							)
						)
						(74
							(switch gPrevRoomNum
								(71 (newAct posn: 114 -20))
								(75 (newAct posn: 340 170))
								(else  (newAct posn: 158 132))
							)
						)
						(75
							(switch gPrevRoomNum
								(74 (newAct posn: -20 170))
								(76 (newAct posn: 340 170))
								(72 (newAct posn: 140 -20))
								(else  (newAct posn: 148 118))
							)
						)
						(76 (newAct posn: -40 170))
					)
					(if (== gCurRoomNum 76)
						(switch (Random 0 1)
							(0
								(newAct xStep: 6 yStep: 3)
								(gSounds eachElementDo: #stop 0)
								(trollMusic loop: 1 play:)
							)
							(1
								(newAct hide:)
								(= local2 1)
								(self changeState: 7)
								(return)
							)
						)
					else
						(trollCaveMusic client: 0 stop:)
						(trollMusic client: 0 stop: loop: 1 play:)
					)
					(proc0_18)
				)
				(if (not local2) (self cue:) (return))
			)
			(2
				(if (gCast contains: newAct)
					(newAct
						moveSpeed: 1
						cycleSpeed: 1
						setMotion: Chase gEgo 55 self
					)
				else
					(self cue:)
				)
			)
			(3
				(Print 605 15 25 4 67 200 10 88)
				(self cue:)
			)
			(4
				(if (gCast contains: newAct)
					(newAct setMotion: Chase gEgo 4 self)
				else
					(self cue:)
				)
			)
			(5
				(gotchaScript start: 1)
				(gRoom setScript: gotchaScript)
			)
		)
	)
)

(instance gotchaScript of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(proc0_8)
				(proc0_21)
				(trollCaveMusic client: 0 stop:)
				(trollMusic play:)
				(= seconds 5)
			)
			(1
				(proc0_8)
				(trollCaveMusic client: 0 stop:)
				(trollMusic client: 0 stop:)
				(caughtMusic play:)
				(proc0_21)
				(Print 605 16 67 -1 10)
				(= local3 1)
				(regTroll notify: 0)
				(Print 605 17 67 -1 10)
				(= seconds 4)
			)
			(2 (= global127 1))
		)
	)
)

(instance theLight of Prop
	(properties
		view 967
		loop 4
	)
	
	(method (init)
		(self
			posn: (gEgo x?) (- (gEgo y?) 3)
			ignoreActors: 1
			setCycle: Fwd
			priority: (- (gEgo priority?) 1)
		)
		(super init:)
	)
	
	(method (doit)
		(self
			posn: (gEgo x?) (- (gEgo y?) 3)
			priority: (- (gEgo priority?) 1)
		)
		(super doit:)
	)
)

(instance doMusic of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0 (Timer setReal: self 2))
			(1
				(trollCaveMusic loop: 1 playMaybe:)
			)
		)
	)
)
