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

(public
	Room23 0
)

(local
	local0
	local1
	newAct
	local3
	local4
	newProp_5
	gEgoViewer
	newProp_4
	local8
	newProp
	newProp_2
	newProp_3
)
(instance fallSound of Sound
	(properties
		number 51
	)
)

(instance dizzySound of Sound
	(properties
		number 80
	)
)

(instance Room23 of Rm
	(properties
		picture 23
		north 17
		east 24
		south 29
		west 22
	)
	
	(method (init)
		(= north 17)
		(= south 29)
		(= east 24)
		(= west 22)
		(= horizon 74)
		(= global101 0)
		(gEgo edgeHit: 0)
		(super init:)
		(if global100 (gRoom overlay: 123))
		(self setRegions: 508 501 512)
		(Load rsVIEW 17)
		(Load rsVIEW 18)
		(Load rsSOUND 51)
		(Load rsSOUND 80)
		(if ((Inv at: 19) ownedBy: 206)
			(Load rsVIEW 21)
			(Load rsVIEW 348)
		)
		(= newProp (Prop new:))
		(= newProp_2 (Prop new:))
		(= newProp_3 (Prop new:))
		(newProp
			isExtra: 1
			view: 654
			loop: 2
			cel: 1
			posn: 75 157
			setPri: 0
			setCycle: Fwd
			ignoreActors:
			init:
		)
		(newProp_2
			isExtra: 1
			view: 654
			loop: 3
			cel: 2
			posn: 101 164
			setPri: 0
			setCycle: Fwd
			ignoreActors:
			init:
		)
		(newProp_3
			isExtra: 1
			view: 654
			loop: 4
			cel: 2
			posn: 224 115
			setPri: 0
			setCycle: Fwd
			ignoreActors:
			init:
		)
		(= newProp_4 (Prop new:))
		(newProp_4
			isExtra: 1
			view: 654
			loop: 0
			cel: 0
			posn: 146 153
			setPri: 0
			setCycle: Fwd
			ignoreActors:
			init:
		)
		(switch gPrevRoomNum
			(west (gEgo posn: 1 (gEgo y?)))
			(east
				(gEgo x: 318)
				(if (<= (gEgo y?) 109) (gEgo y: 99))
			)
			(north
				(gEgo posn: 120 (+ horizon 1))
			)
			(south (gEgo x: 106 y: 188))
			(0 (gEgo x: 180 y: 188))
		)
		(= gEgoViewer (gEgo viewer?))
		(if
			(and
				(<= (Random 1 100) 50)
				((Inv at: 19) ownedBy: 206)
			)
			(= newAct (Act new:))
			(newAct
				view: 348
				loop: 2
				cel: 0
				setScript: birdActions
				posn: 275 158
				setCycle: Fwd
				illegalBits: 0
				ignoreActors:
				ignoreHorizon:
				init:
			)
			(gRoom setScript: wormActions)
		)
		(gEgo init:)
	)
	
	(method (doit)
		(super doit:)
		(if
			(and
				(!= (= local0 (gEgo onControl: 0)) local1)
				(== (gEgo script?) 0)
			)
			(= local1 local0)
			(if (& local0 $0010) (gEgo setScript: fallRed))
			(if (& local0 $0004) (gEgo setScript: fallSouth))
			(if (& local0 $1000) (gEgo setScript: shortFall))
		)
	)
	
	(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 23 0)
					)
					((Said 'look/cottage') (Print 23 1))
					((Said 'capture,get/earthworm')
						(if (gCast contains: newProp_5)
							(if (< (gEgo distanceTo: newProp_5) 15)
								(proc0_3 gEgo newProp_5)
								(wormActions changeState: 10)
							else
								(Print 800 1)
							)
						else
							(Print 23 2)
						)
					)
					((Said 'look/crow,crow') (pEvent claimed: 0))
					((Said 'look/robin,bird')
						(cond 
							((gCast contains: newAct)
								(if (== (birdActions state?) 0)
									(Print 23 3)
								else
									(Print 23 4)
								)
							)
							((gCast contains: gNewAct_4) (pEvent claimed: 0))
							(else (Print 23 5))
						)
					)
					((Said 'converse/robin,bird')
						(if (== (birdActions state?) 0)
							(Print 23 6)
						else
							(Print 23 7)
						)
					)
					((Said 'kill/robin,bird') (Print 23 8))
					((Said 'capture,get,kiss/robin,bird')
						(if
							(or
								(gCast contains: newAct)
								(gCast contains: gNewAct_4)
							)
							(Print 23 9)
						else
							(Print 23 5)
						)
					)
					((Said 'help/robin,bird') (Print 23 10))
					((Said 'deliver')
						(if (gCast contains: newAct)
							(Print 23 11)
						else
							(Print 23 12)
						)
					)
					((Said 'look/earthworm')
						(cond 
							(
								(and
									(gCast contains: newAct)
									((Inv at: 19) ownedBy: 206)
									(== (birdActions state?) 0)
								)
								(Print 23 3)
							)
							(((Inv at: 19) ownedBy: 23) (Print 23 13))
							((gEgo has: 19) ((Inv at: 19) showSelf:))
							(else (Print 23 5))
						)
					)
					((Said 'look/dirt')
						(cond 
							(((Inv at: 19) ownedBy: 23) (Print 23 13))
							(
								(and
									(== (birdActions state?) 0)
									(gCast contains: newAct)
								)
								(Print 23 3)
							)
							(else (Print 23 14))
						)
					)
				)
			else
				0
			)
		)
	)
	
	(method (newRoom newRoomNumber)
		(gTimers eachElementDo: #dispose 84)
		(if ((Inv at: 19) ownedBy: 23)
			((Inv at: 19) moveTo: 206)
		)
		(super newRoom: newRoomNumber)
	)
)

(instance fallSouth of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(proc0_8)
				(fallSound play:)
				(gEgo
					viewer: 0
					yStep: 6
					yStep: 6
					illegalBits: 0
					loop: (& (gEgo loop?) $0001)
					setCel: 0
					view: 17
					setCycle: End
					setMotion: MoveTo (gEgo x?) 141 self
				)
			)
			(1
				(gEgo xStep: 3 yStep: 2 view: 18 loop: 0 setCycle: Fwd)
				(gSounds eachElementDo: #stop 0)
				(dizzySound play:)
				(= seconds 4)
			)
			(2
				(gEgo view: 21 loop: 2 cel: 4 setCycle: Beg self)
			)
			(3
				(proc0_9)
				(gEgo
					illegalBits: -32768
					setCycle: Walk
					view: 2
					viewer: gEgoViewer
				)
				(gEgo setScript: 0)
			)
		)
	)
)

(instance fallRed of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(proc0_8)
				(fallSound play:)
				(gEgo
					viewer: 0
					yStep: 6
					yStep: 6
					illegalBits: 0
					loop: (& (gEgo loop?) $0001)
					setCel: 0
					view: 17
					setCycle: End
					setMotion: MoveTo (gEgo x?) (+ (gEgo y?) 18) self
				)
			)
			(1
				(gEgo xStep: 3 yStep: 2 view: 18 loop: 0 setCycle: Fwd)
				(gSounds eachElementDo: #stop 0)
				(dizzySound play:)
				(= seconds 4)
			)
			(2
				(gEgo view: 21 loop: 2 cel: 4 setCycle: Beg self)
			)
			(3
				(proc0_9)
				(gEgo
					illegalBits: -32768
					setCycle: Walk
					view: 2
					viewer: gEgoViewer
				)
				(gEgo setScript: 0)
			)
		)
	)
)

(instance shortFall of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(proc0_8)
				(fallSound play:)
				(gEgo
					viewer: 0
					view: 17
					loop: (& (gEgo loop?) $0001)
					setCel: 0
					setStep: 6 6
					illegalBits: 0
					setCycle: End
					setMotion: MoveTo (gEgo x?) (+ (gEgo y?) 11) self
				)
			)
			(1
				(gEgo view: 18 setStep: 3 2 loop: 0 setCycle: Fwd)
				(gSounds eachElementDo: #stop 0)
				(dizzySound play:)
				(= seconds 4)
			)
			(2
				(gEgo view: 21 loop: 2 cel: 4 setCycle: Beg self)
			)
			(3
				(gEgo
					illegalBits: -32768
					setCycle: Walk
					view: 2
					viewer: gEgoViewer
				)
				(proc0_9)
				(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 local3 (local3 dispose:))
			(self changeState: 1)
		)
	)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(= local3 (Timer setReal: self 15))
			)
			(1
				(newAct cel: 255 loop: 3 setCycle: End self)
			)
			(2
				(= newProp_5 (Prop new:))
				(newProp_5
					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
				(= local4 (Timer setReal: self 12))
				((Inv at: 19) moveTo: 23)
			)
			(2
				(newProp_5 dispose:)
				((Inv at: 19) moveTo: 206)
			)
			(10
				(proc0_8)
				(local4 dispose:)
				(gEgo viewer: 0 view: 21 setCycle: End self)
			)
			(11
				(newProp_5 dispose:)
				(= newProp_5 0)
				(gEgo setCycle: Beg self)
				(gEgo get: 19)
				(= global182 1)
				(gGame changeScore: 2)
			)
			(12
				(gEgo view: 2 setCycle: Walk)
				(gEgo viewer: gEgoViewer)
				(proc0_9)
			)
		)
	)
)
