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

(public
	Room4 0
)
(synonyms
	(giantess giantess giantess giantess giantess fishwife giantess)
)

(local
	local0
	newAct
	local2
	local3
	local4
	newActHeading
	newProp
	local7
)
(instance doorSound of Sound
	(properties)
)

(instance ogressTheme of Sound
	(properties)
)

(instance ogreTheme of Sound
	(properties)
)

(instance door of Prop
	(properties)
	
	(method (cue)
		(if (!= (door cel?) (door lastCel:))
			(self setCycle: End self)
		else
			(proc0_9)
			(gRoom newRoom: 49)
		)
	)
)

(instance Room4 of Rm
	(properties
		picture 4
	)
	
	(method (init)
		(= north 28)
		(= south 10)
		(= east 5)
		(= west 3)
		(= horizon 75)
		(= global189 1)
		(= global101 0)
		(gEgo edgeHit: 0)
		(super init:)
		(if global100 (gRoom overlay: 104))
		(self setRegions: 508 517)
		(if (and (== global109 2) (== global163 0))
			(Load rsVIEW 245)
			(Load rsVIEW 246)
			(Load rsVIEW 57)
		)
		(if (and (== gPrevRoomNum 49) (gEgo has: 33))
			(door
				view: 602
				loop: 0
				cel: 6
				posn: 181 145
				setPri: 10
				ignoreActors:
				init:
				stopUpd:
			)
		else
			(door
				view: 602
				loop: 0
				cel: 0
				posn: 181 145
				setPri: 10
				init:
				stopUpd:
			)
		)
		(if (<= (gEgo y?) horizon)
			(gEgo y: (+ horizon (gEgo yStep?)))
		)
		(switch gPrevRoomNum
			(0 (gEgo posn: 128 166))
			(28
				(gEgo posn: 48 (+ horizon (gEgo yStep?) 1))
			)
			(3 (gEgo posn: 2 (gEgo y?)))
			(5 (gEgo posn: 317 (gEgo y?)))
			(10 (gEgo posn: (gEgo x?) 187))
			(49
				(gEgo loop: 2 posn: 173 152)
			)
		)
		(gEgo view: 2 init:)
		(gEgo setStep: 3 2)
		(if
		(and (== gPrevRoomNum 10) gNewAct (!= global179 1))
			(= gNewAct (Act new:))
			(gNewAct
				posn: 110 (+ 189 (- gGNewActY 75) 80)
				view: 250
				xStep: 6
				yStep: 2
				setCycle: Walk
				ignoreActors:
				init:
			)
			(gRoom setScript: ogreActions)
			(ogreTheme number: 5 loop: -1 play:)
		else
			(= gNewAct 0)
		)
		(if (and (== global109 2) (not global163))
			(= global163 1)
			(= newAct (Act new:))
			(newAct
				posn: 4 141
				view: 246
				xStep: 1
				yStep: 1
				setCycle: Walk
				ignoreActors:
				init:
			)
			(gRoom setScript: ogressActions)
			(newAct setMotion: MoveTo 103 168 ogressActions)
			(ogressTheme number: 10 loop: -1 play:)
		)
		(if
			(and
				(not gNewAct)
				(< (Random 1 100) 35)
				(!= global179 1)
				(!= gPrevRoomNum 49)
				(not (gCast contains: newAct))
			)
			(= gNewAct (Act new:))
			(gNewAct
				posn: 1 169
				view: 250
				xStep: 6
				yStep: 2
				setCycle: Walk
				ignoreActors:
				init:
			)
			(if (< (Random 1 100) 50) (gNewAct posn: 110 239))
			(ogreTheme number: 5 loop: -1 play:)
			(gRoom setScript: ogreActions)
		)
		(if (== global165 4)
			(gRoom setScript: ogreActions)
			(ogreActions changeState: 200)
		)
		(if (== (door cel?) 0) (gEgo observeControl: 16384))
	)
	
	(method (doit)
		(super doit:)
		(if
		(and (& (gEgo onControl: 0) $4000) (!= (door cel?) 0))
			(gRoom newRoom: 49)
		)
		(if (gCast contains: gEgo)
			(if (gEgo inRect: 143 0 369 136)
				(gEgo setPri: 1)
			else
				(gEgo setPri: -1)
			)
		)
		(if (gCast contains: gNewAct)
			(if (gNewAct inRect: 143 0 369 136)
				(gNewAct setPri: 1)
			else
				(gNewAct setPri: -1)
			)
		)
		(if (gCast contains: newAct)
			(cond 
				((newAct inRect: 143 0 369 136) (newAct setPri: 1))
				((< (ogressActions state?) 200) (newAct setPri: -1))
			)
		)
		(if (== local3 1)
			(if
				(and
					(not
						(if (gEgo inRect: 134 0 369 137)
							(newAct inRect: 104 149 369 185)
						)
					)
					(< (gEgo distanceTo: newAct) 75)
				)
				(= local3 2)
				(ogressActions changeState: 10)
				(Print 4 0)
			)
		)
		(if
			(and
				(== local3 1)
				(not (gEgo inRect: 134 0 369 137))
				(not (newAct inRect: 104 149 369 185))
			)
			(= local4
				(GetAngle (newAct x?) (newAct y?) (gEgo x?) (gEgo y?))
			)
			(if
				(and
					(< (= newActHeading (newAct heading?)) 15)
					(> local4 345)
				)
				(= newActHeading (+ newActHeading 360))
			)
			(if (< (Abs (- local4 newActHeading)) 15)
				(= local3 2)
				(Print 4 0)
				(ogressActions changeState: 10)
			)
		)
	)
	
	(method (dispose)
		(= global189 0)
		(gEgo setPri: -1)
		(super dispose:)
	)
	
	(method (handleEvent pEvent)
		(if (pEvent claimed?) (return 1))
		(return
			(if (== (pEvent type?) evSAID)
				(cond 
					((Said 'look>')
						(cond 
							((Said '/cottage') (Print 4 1))
							((Said '/door') (Print 4 2))
							((Said '/bucket') (Print 4 3))
							((Said '/buck') (if (gCast contains: newAct) (Print 4 4)))
							((Said '/window')
								(if (gEgo inRect: 266 140 304 155)
									(Print 4 5)
								else
									(Print 800 1)
								)
							)
							((Said '/giantess')
								(if (gCast contains: newAct)
									(switch (newAct view?)
										(246 (Print 4 6))
										(245 (Print 4 7))
									)
								else
									(Print 4 8)
								)
							)
							((Said '[<around][/room]') (Print 4 9))
						)
					)
					(
					(and (gCast contains: newAct) (Said 'converse'))
						(if (and (== (newAct view?) 246) (!= local3 3))
							(if (not (gEgo inRect: 143 0 319 136))
								(Print 4 10)
								(ogressActions changeState: 10)
								(= local3 2)
							else
								(Print 4 11)
							)
						else
							(Print 4 12)
						)
					)
					((Said 'get,capture/buck')
						(cond 
							((gCast contains: newAct) (Print 4 13))
							((gCast contains: newProp) (Print 4 14))
							(else (Print 4 15))
						)
					)
					((Said 'get,capture/giantess') (Print 4 16))
					((Said 'open/door')
						(if (gEgo inRect: 163 144 199 155)
							(cond 
								(
								(or (gCast contains: newAct) (gCast contains: gNewAct)) (Print 4 17))
								((!= global109 2) (Print 4 18))
								(else
									(gEgo loop: 3)
									(proc0_8)
									(door setPri: 9 setCycle: End)
									(doorSound number: 300 play: door)
									(gEgo illegalBits: -32768)
								)
							)
						else
							(Print 800 1)
						)
					)
					((Said 'bang')
						(if (< (gEgo distanceTo: door) 10)
							(cond 
								((gCast contains: gNewAct) (Print 4 19))
								((!= global109 2) (Print 4 20))
								((not (gCast contains: newAct))
									(Print 4 21)
									(gRoom setScript: ogressActions)
									(ogressActions changeState: 200)
								)
								(else (Print 4 22))
							)
						else
							(Print 800 1)
						)
					)
					((Said 'unlatch')
						(if (!= global109 2)
							(Print 4 18)
						else
							(Print 4 23)
						)
					)
					((Said 'break/window') (Print 4 24))
					((Said 'break/door') (Print 4 25))
					((Said 'open/window') (Print 4 26))
				)
			else
				0
			)
		)
	)
	
	(method (newRoom newRoomNumber)
		(proc0_9)
		(if (gCast contains: gEgo)
			(gEgo illegalBits: -32768)
			(gEgo setPri: -1)
		)
		(if (!= newRoomNumber 49) (= global165 0))
		(= global189 0)
		(super newRoom: newRoomNumber)
	)
)

(instance ogressActions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0 (if newAct (= seconds 3)))
			(1
				(= local3 1)
				(newAct setLoop: 0)
			)
			(2
				(newAct setMotion: MoveTo 183 155 ogressActions)
			)
			(3 (door setCycle: End self))
			(4
				(= local3 3)
				(newAct
					baseSetter: (ScriptID 0 1)
					setPri: 9
					setMotion: MoveTo 187 144 self
				)
			)
			(5 (door setCycle: Beg self))
			(6
				(= local3 0)
				(ogressTheme client: 0 stop:)
				(newAct dispose:)
				(= newAct 0)
			)
			(10
				(= newProp (Prop new:))
				(newProp
					view: 530
					ignoreActors:
					setPri: (+ (newAct priority?) 1)
					posn: (- (newAct x?) 6) (+ (newAct y?) 3)
					setCycle: End self
					init:
				)
				(newAct setLoop: -1 setMotion: 0 view: 245)
				(door setCycle: 0)
			)
			(11
				(newAct
					setAvoider: (Avoid new:)
					xStep: 6
					yStep: 2
					setLoop: -1
					setCycle: Walk
					ignoreActors:
					setMotion: Chase gEgo 5 self
				)
				(if (gCast contains: newProp)
					(newProp ignoreActors: 0 setPri: -1)
				)
			)
			(12
				(ogressTheme client: 0 stop:)
				(ogressTheme number: 11 loop: 1 play: self)
				(proc0_8)
				(gEgo dispose:)
				(newAct view: 57 setCycle: Fwd)
				(Print 4 27 67 -1 10 83)
			)
			(13 (= seconds 2))
			(14 (= global127 1))
			(200
				(door setCycle: End self)
				(= newAct (Act new:))
				(newAct
					view: 245
					setPri: 9
					loop: 2
					ignoreActors:
					baseSetter: (ScriptID 0 1)
					posn: 186 145
					init:
				)
				(proc0_8)
			)
			(201 (= seconds 1))
			(202 (self changeState: 11))
		)
	)
)

(instance ogreActions of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(if (gCast contains: gNewAct)
					(ogreActions changeState: 1)
				)
			)
			(1
				(= local2 1)
				(if (gEgo inRect: 223 74 319 136)
					(gNewAct setMotion: MoveTo 97 123 self)
				else
					(self changeState: 2)
				)
			)
			(2
				(gNewAct
					setAvoider: (Avoid new:)
					xStep: 6
					yStep: 2
					ignoreActors:
					setMotion: Chase gEgo 5 self
				)
			)
			(3
				(proc0_8)
				(gEgo dispose:)
				(gNewAct view: 78 setCycle: End self)
			)
			(4
				(ogreTheme client: 0 stop:)
				(ogreTheme number: 6 loop: 1 play:)
				(gNewAct setAvoider: 0 view: 79 setCycle: Walk self)
				(Print 4 28 67 -1 10 83)
				(cond 
					((gNewAct inRect: -50 70 350 93) (gNewAct setMotion: MoveTo 37 87 self))
					(
						(or
							(gNewAct inRect: -50 93 350 136)
							(gNewAct inRect: 92 135 141 148)
						)
						(self changeState: 5)
						(= local0 (Timer setReal: killOgre 15))
					)
					(else
						(self changeState: 7)
						(= local0 (Timer setReal: killOgre 15))
					)
				)
			)
			(5
				(gNewAct setMotion: MoveTo 75 120 self)
			)
			(6
				(gNewAct setMotion: MoveTo 75 164 self)
			)
			(7
				(gNewAct setMotion: MoveTo 182 164 self)
			)
			(8
				(if (gTimers contains: local0)
					(local0 dispose: delete:)
				)
				(if (== (door cel?) 0)
					(door setCycle: End self)
				else
					(self changeState: 9)
				)
			)
			(9
				(door ignoreActors:)
				(gNewAct setMotion: MoveTo 182 154 self)
			)
			(10 (= seconds 3))
			(11
				(gSounds eachElementDo: #stop 0)
				(= seconds 2)
			)
			(12 (= global127 1))
			(200 (= seconds 5))
			(201
				(= gNewAct (Act new:))
				(gNewAct
					loop: 2
					posn: 186 147
					view: 250
					baseSetter: (ScriptID 0 1)
					setCycle: Walk
					setAvoider: Avoid
					init:
				)
				(ogreTheme number: 5 loop: -1 play:)
				(if (< (gNewAct distanceTo: gEgo) 10)
					(self changeState: 1)
				else
					(gNewAct setMotion: MoveTo 181 159 self)
				)
			)
			(202
				(gNewAct observeControl: 16384)
				(self changeState: 1)
			)
		)
	)
)

(instance killOgre of Script
	(properties)
	
	(method (cue)
		(= global127 1)
	)
)
