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

(public
	Room29 0
)

(local
	local0
	local1
	local2
	newAct
	local4
	local5
	newProp
	local7
)
(instance fallSound of Sound
	(properties
		number 51
	)
)

(instance Room29 of Rm
	(properties
		picture 29
	)
	
	(method (init)
		(= north 23)
		(= south 5)
		(= east 30)
		(= west 28)
		(= horizon 100)
		(= global101 0)
		(gEgo edgeHit: 0)
		(super init:)
		(if global100 (gRoom overlay: 129))
		(self setRegions: 508)
		(if ((Inv at: 19) ownedBy: 206)
			(Load rsVIEW 21)
			(Load rsVIEW 348)
		)
		(Load rsVIEW 17)
		(Load rsSOUND 51)
		(switch gPrevRoomNum
			(28
				(if (<= (gEgo y?) 156)
					(gEgo x: 1 y: 150)
				else
					(gEgo x: 1 y: 186)
				)
			)
			(30
				(if (<= (gEgo y?) horizon)
					(gEgo x: 318 y: (+ horizon 1))
				else
					(gEgo x: 318)
				)
			)
			(23
				(gEgo x: 264 y: (+ horizon 2))
			)
			(5 (gEgo y: 188))
			(0 (gEgo x: 290 y: 160))
		)
		(if
			(and
				(<= (Random 1 100) 50)
				((Inv at: 19) ownedBy: 206)
			)
			(= newAct (Act new:))
			(newAct
				view: 348
				loop: 2
				cel: 0
				posn: 257 165
				setScript: birdActions
				setCycle: Fwd
				illegalBits: 0
				ignoreActors:
				ignoreHorizon:
				init:
			)
		)
		(gEgo init: view: 2)
		(gRoom setScript: wormActions)
	)
	
	(method (doit)
		(super doit:)
		(if
			(and
				(!= (= local0 (gEgo onControl: 0)) local7)
				(== (gEgo script?) 0)
				(== gNewRoomNumber_2 gCurRoomNum)
			)
			(= local7 local0)
			(if (& local0 $0004)
				(gRoom west: 0)
				(gEgo setScript: fallSouth)
			)
		)
	)
	
	(method (handleEvent pEvent)
		(if (pEvent claimed?) (return 1))
		(return
			(if (== (pEvent type?) evSAID)
				(cond 
					(
						(or
							(Said 'look/around')
							(Said 'look/room')
							(Said 'look[<around][/!*]')
						)
						(Print 29 0)
					)
					((Said 'capture,get/earthworm')
						(if (gCast contains: newProp)
							(if (< (gEgo distanceTo: newProp) 15)
								(proc0_3 gEgo newProp)
								(wormActions changeState: 10)
							else
								(Print 800 1)
							)
						else
							(Print 29 1)
						)
					)
					((Said 'look/crow,crow') (pEvent claimed: 0))
					((Said 'look/robin,bird')
						(cond 
							((gCast contains: newAct)
								(if (== (birdActions state?) 0)
									(Print 29 2)
								else
									(Print 29 3)
								)
							)
							((gCast contains: gNewAct_4) (pEvent claimed: 0))
							(else (Print 29 4))
						)
					)
					((Said 'converse/robin,bird')
						(if (== (birdActions state?) 0)
							(Print 29 5)
						else
							(Print 29 6)
						)
					)
					((Said 'kill/robin,bird') (Print 29 7))
					((Said 'capture,get,kiss/robin,bird')
						(if
							(or
								(gCast contains: newAct)
								(gCast contains: gNewAct_4)
							)
							(Print 800 1)
						else
							(Print 29 4)
						)
					)
					((Said 'help/robin,bird') (Print 29 8))
					((Said 'deliver')
						(if (gCast contains: newAct)
							(Print 29 9)
						else
							(Print 29 10)
						)
					)
					((Said 'look/earthworm')
						(cond 
							(
								(and
									(gCast contains: newAct)
									((Inv at: 19) ownedBy: 206)
									(== (birdActions state?) 0)
								)
								(Print 29 2)
							)
							(((Inv at: 19) ownedBy: 29) (Print 29 11))
							((gEgo has: 19) ((Inv at: 19) showSelf:))
							(else (Print 29 4))
						)
					)
					((Said 'look/dirt')
						(cond 
							(((Inv at: 19) ownedBy: 29) (Print 29 11))
							(
							(and (== (birdActions state?) 0) (!= newAct 0)) (Print 29 2))
							(else (Print 29 12))
						)
					)
				)
			else
				0
			)
		)
	)
	
	(method (newRoom newRoomNumber)
		(gTimers eachElementDo: #dispose 84)
		(if ((Inv at: 19) ownedBy: 29)
			((Inv at: 19) moveTo: 206)
		)
		(super newRoom: newRoomNumber)
	)
)

(instance fallSouth of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(proc0_8)
				(fallSound play:)
				(cond 
					((> (gEgo x?) 100) (= local1 12))
					((>= (gEgo x?) 65) (= local1 20))
					(else (= local1 30))
				)
				(if (> (+ (gEgo y?) local1) 188)
					(= local2 188)
				else
					(= local2 (+ (gEgo y?) local1))
				)
				(gEgo
					yStep: 6
					yStep: 6
					illegalBits: 0
					loop: (& (gEgo loop?) $0001)
					setCel: 0
					view: 17
					setCycle: End
					setMotion: MoveTo (gEgo x?) local2 self
				)
			)
			(1
				(gEgo
					xStep: 3
					yStep: 2
					view: 21
					loop: 2
					setCycle: CT 4 1 self
				)
			)
			(2
				(gEgo view: 21 loop: 2 setCycle: Beg self)
			)
			(3
				(proc0_9)
				(gRoom west: 28)
				(gEgo illegalBits: -32768 setCycle: Walk view: 2)
				(gEgo setScript: 0)
			)
		)
	)
)

(instance birdActions of Script
	(properties)
	
	(method (doit)
		(super doit:)
		(if
			(and
				(gCast contains: newAct)
				(< (newAct distanceTo: gEgo) 30)
				(== (newAct loop?) 2)
			)
			(if (gTimers contains: local4) (local4 dispose:))
			(self changeState: 1)
		)
	)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(= local4 (Timer setReal: self 15))
			)
			(1
				(newAct cel: 255 loop: 3 setCycle: End self)
			)
			(2
				(= newProp (Prop new:))
				(newProp
					view: 348
					setLoop: 0
					setCycle: Fwd
					ignoreActors:
					posn: (- (newAct x?) 8) (newAct y?)
					init:
				)
				(wormActions changeState: 1)
				(newAct
					setPri: 12
					setLoop: 1
					xStep: 7
					yStep: 4
					setMotion: MoveTo 182 51 self
				)
			)
			(3
				(newAct setMotion: MoveTo 20 -6 self)
			)
			(4
				(newAct dispose:)
				(= newAct 0)
			)
		)
	)
)

(instance wormActions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(1
				(= local5 (Timer setReal: self 10))
				((Inv at: 19) moveTo: 29)
			)
			(2
				(newProp dispose:)
				((Inv at: 19) moveTo: 206)
			)
			(10
				(local5 dispose:)
				(proc0_8)
				(gEgo view: 21 setMotion: 0 setCycle: End self)
			)
			(11
				(newProp dispose:)
				(= newProp 0)
				(gEgo setCycle: Beg self)
				(gEgo get: 19)
				(gGame changeScore: 2)
				(= global182 1)
			)
			(12
				(gEgo view: 2 setCycle: Walk)
				(proc0_9)
			)
		)
	)
)
