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

(public
	Room13 0
)

(local
	newProp
	newView
	local2
	local3
)
(instance wave1 of Prop
	(properties)
)

(instance wave2 of Prop
	(properties)
)

(instance wave3 of Prop
	(properties)
)

(instance waves of List
	(properties)
)

(instance minBlock of Blk
	(properties
		top 115
		left 262
		bottom 121
		right 266
	)
)

(instance Room13 of Rm
	(properties
		picture 13
	)
	
	(method (init)
		(= north 7)
		(= south 19)
		(= east 14)
		(= west 31)
		(= horizon 80)
		(= global101 0)
		(gEgo edgeHit: 0)
		(super init:)
		(if global100 (gRoom overlay: 113))
		(wave1
			isExtra: 1
			view: 665
			loop: 3
			cel: 2
			posn: 133 91
			setPri: 0
			ignoreActors:
			cycleSpeed: 3
			init:
		)
		(wave2
			isExtra: 1
			view: 665
			loop: 4
			cel: 3
			posn: 126 120
			setPri: 0
			ignoreActors:
			cycleSpeed: 3
			init:
		)
		(wave3
			isExtra: 1
			view: 665
			loop: 5
			cel: 1
			posn: 127 149
			setPri: 0
			ignoreActors:
			cycleSpeed: 3
			init:
		)
		(waves add: wave1 wave2 wave3)
		(wave1 setScript: waveActions)
		(= local3
			(+
				(* (- global160 global213) 60)
				(- global159 global214)
			)
		)
		(if
		(and ((Inv at: 9) ownedBy: 203) (>= local3 3))
			(= global118 (/ (= global118 (Random 1 30)) 10))
		)
		(if (== global118 1)
			((= gNewAct_2 (Act new:))
				view: 174
				loop: 2
				setCel: 0
				illegalBits: 0
				posn: 264 118
				init:
			)
			(gEgo observeBlocks: minBlock)
		)
		(self setRegions: 501 516 503 504 506)
		(if (and (== global116 1) (not global100))
			((= newView (View new:))
				view: 534
				setLoop: 0
				setCel: 0
				posn: 65 54
				init:
				addToPic:
			)
		)
		(= newProp (Prop new:))
		(newProp
			view: 625
			isExtra: 1
			posn: 173 29
			setLoop: 1
			setCycle: Fwd
			cycleSpeed: 2
			init:
		)
		(if (== gPrevRoomNum 14) (= global105 0))
		(switch global105
			(0
				(switch gPrevRoomNum
					(19
						(if (> (gEgo x?) 233)
							(gEgo x: 278 y: 188)
						else
							(gEgo x: 205 y: 188)
						)
					)
					(7
						(if (> (gEgo x?) 208)
							(gEgo x: 194 y: (+ horizon 2))
						else
							(gEgo posn: 148 (+ horizon 2))
						)
					)
					(14
						(if (< (gEgo y?) horizon)
							(gEgo x: 318 y: (+ horizon 2))
						else
							(gEgo x: 318)
						)
					)
				)
			)
			(1
				(switch gPrevRoomNum
					(19 (gEgo x: 88 y: 188))
					(7
						(gEgo x: 133 y: (+ horizon 2))
					)
				)
			)
			(2
				(switch gPrevRoomNum
					(19 (gEgo x: 88 y: 188))
					(7
						(gEgo x: 124 y: (+ horizon 2))
					)
				)
			)
			(3
				(switch gPrevRoomNum
					(19 (gEgo x: 45 y: 188))
					(7
						(gEgo x: 108 y: (+ horizon 2))
					)
				)
			)
			(4
				(switch gPrevRoomNum
					(19 (gEgo x: 16 y: 188))
					(7
						(if (> (gEgo x?) 75)
							(gEgo x: 75 y: (+ horizon 2))
						else
							(gEgo y: (+ horizon (gEgo yStep?) 1))
						)
					)
					(31
						(if (<= (gEgo y?) horizon)
							(gEgo x: 1 y: (+ horizon 2))
						else
							(gEgo x: 1)
						)
					)
				)
			)
		)
		(gEgo init:)
	)
	
	(method (dispose)
		(waves dispose:)
		(super dispose:)
	)
	
	(method (handleEvent pEvent)
		(if (pEvent claimed?) (return 1))
		(return
			(if
			(and (== (pEvent type?) evSAID) (Said 'look>'))
				(cond 
					((Said '/grass') (Print 13 0))
					((Said '/dock')
						(if (== global116 1)
							(Print 13 1)
						else
							(Print 13 2)
						)
					)
					((Said '/cottage') (Print 13 2))
					((Said '/fisherman,man,fishwife,person')
						(cond 
							((gCast contains: gNewAct_2) (pEvent claimed: 0))
							((== global116 1) (Print 13 3))
							(else (Print 13 4))
						)
					)
					((Said '[<around][/room]') (Print 13 5))
				)
			else
				0
			)
		)
	)
	
	(method (newRoom newRoomNumber)
		(if (gCast contains: gNewAct_2)
			(= global213 global160)
			(= global214 global159)
		)
		(super newRoom: newRoomNumber)
	)
)

(instance waveActions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(= local2 0)
				(while (< local2 (waves size?))
					((View new:)
						view: ((waves at: local2) view?)
						loop: ((waves at: local2) loop?)
						cel: 0
						setPri: 0
						ignoreActors:
						x: ((waves at: local2) x?)
						y: ((waves at: local2) y?)
						init:
						addToPic:
						yourself:
					)
					(++ local2)
				)
				(= local2 0)
				(self changeState: 1)
			)
			(1
				((waves at: local2) cel: 255 show: setCycle: End self)
			)
			(2
				((waves at: local2) hide:)
				(if (< local2 (- (waves size?) 1))
					(++ local2)
				else
					(= local2 0)
				)
				(waveActions changeState: 1)
			)
		)
	)
)
