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

(public
	Room49 0
)

(local
	newAct_4
	local1
	newAct_3
	newAct_2
	newAct
	newProp
	newProp_2
	newAct_5
	newProp_3
	local9
	local10
	local11
)
(instance theMusic of Sound
	(properties)
)

(instance throwSound of Sound
	(properties)
)

(instance Room49 of Rm
	(properties
		picture 49
		style $0010
	)
	
	(method (init)
		(Load rsVIEW 541)
		(= global105 0)
		(if (not ((Inv at: 23) ownedBy: 49))
			(Load rsVIEW 351)
			(Load rsVIEW 352)
			(Load rsVIEW 87)
			(Load rsVIEW 15)
		)
		(self setRegions: 602)
		(super init:)
		(if
		(and (> global165 0) (!= global165 5) (not global167))
			(= local1 1)
		)
		(= global101 1)
		(= global189 1)
		(if global100
			((View new:)
				view: 616
				loop: 1
				posn: 50 128
				ignoreActors: 1
				addToPic:
				stopUpd:
			)
		)
		((Prop new:)
			view: 541
			loop: (if global100 1 else 2)
			cel: 0
			posn: 86 136
			ignoreActors: 1
			setPri: 12
			setCycle: Fwd
			init:
			addToPic:
		)
		((= newAct (Act new:))
			view: 351
			illegalBits: 0
			loop: 1
			setStep: 5 2
			posn: (if (== ((gInv at: 23) owner?) 49) 155 else 160) 126
			init:
		)
		(if (== global165 5) ((gInv at: 33) owner: 48))
		(if ((gInv at: 33) ownedBy: 49)
			((= newAct_2 (Act new:))
				view: 360
				posn: 230 129
				init:
				hide:
			)
			(newAct_2 setScript: henPecked)
		)
		((= newProp (Prop new:))
			view: 615
			loop: 0
			cel: 0
			posn: 209 123
			init:
			stopUpd:
		)
		((= newProp_2 (Prop new:))
			view: 616
			ignoreActors: 1
			loop: 0
			posn: 59 129
			init:
		)
		(if (or (== gPrevRoomNum 4) (== gPrevRoomNum 0))
			(newProp_2 setPri: 0 ignoreActors: 1)
			(= global210 1)
			(gEgo
				posn: 53 132
				view: 2
				loop: 0
				setStep: 3 2
				illegalBits: -32768
				init:
			)
			(if (or (> global109 2) (gEgo has: 33))
				(Load rsVIEW 245)
				(Load rsVIEW 48)
				((= newAct_3 (Act new:))
					view: 245
					posn: 65 131
					setStep: 4 2
					init:
					setScript: ogressChase
				)
			)
		)
		(if (== gPrevRoomNum 48)
			(gEgo
				posn: 181 69
				view: 2
				loop: 1
				setStep: 3 2
				illegalBits: -32768
				init:
			)
		)
		(if (== gPrevRoomNum 50)
			(gEgo
				posn: 267 131
				view: 2
				setStep: 3 2
				illegalBits: -32768
				init:
			)
			(if global167
				(Load rsVIEW 245)
				(Load rsVIEW 48)
				((= newAct_3 (Act new:))
					view: 245
					illegalBits: -32768
					posn: 301 131
					setStep: 4 2
					init:
					setScript: ogressChase
				)
			)
			(if (or (== global165 1) (== global165 90))
				(self setScript: ogreStuff)
			)
		)
		(if (== gPrevRoomNum 51)
			(gEgo
				view: 2
				setStep: 3 2
				loop: 2
				illegalBits: -32768
				posn: 225 128
				init:
				setCycle: Walk
				setMotion: 0
			)
			(if (== global165 5)
				(Load rsVIEW 245)
				(Load rsVIEW 48)
				((= newAct_3 (Act new:))
					view: 245
					illegalBits: -32768
					posn: 301 131 4 2
					init:
					setScript: ogressChase
				)
			)
			(if (== global165 4)
				(Load rsVIEW 250)
				(Load rsVIEW 78)
				(Load rsVIEW 79)
				((= newAct_4 (Act new:))
					view: 250
					posn: 235 132
					setStep: 6 2
					init:
					setCycle: Walk
				)
				(= global210 0)
			)
		)
		(if (== global165 2)
			(= global210 0)
			(newProp_2 setPri: -1 cel: 0)
			(Load rsVIEW 250)
			(Load rsVIEW 78)
			(Load rsVIEW 79)
			(Load rsVIEW 256)
			((= newAct_4 (Act new:))
				view: 256
				posn: 201 158
				setStep: 6 2
				init:
				cycleSpeed: 2
				setCycle: Fwd
			)
			(newAct_4 setScript: ogreAwake)
		)
		(if (== global165 3)
			(= global210 0)
			(newProp_2 setPri: -1 cel: 0)
			(Load rsVIEW 250)
			(Load rsVIEW 78)
			(Load rsVIEW 79)
			((= newAct_4 (Act new:))
				illegalBits: 0
				view: 256
				posn: 201 158
				setStep: 6 2
				init:
				cycleSpeed: 2
				setCycle: Fwd
			)
			(newAct_4 setScript: ogreAwake)
		)
		(newProp_2
			cel: (if global210 (newProp_2 lastCel:) else 0)
			init:
			stopUpd:
		)
		(if (not (newProp_2 cel?))
			(gEgo observeControl: 16384)
		else
			(gEgo ignoreControl: 16384)
		)
		(if (== ((gInv at: 23) owner?) 49)
			(newAct setScript: chewBone)
		else
			(newAct setScript: chaseEgo)
		)
	)
	
	(method (doit)
		(super doit:)
		(if (& (gEgo onControl:) $0004)
			(gEgo setPri: 4)
		else
			(gEgo setPri: -1)
		)
		(if
			(and
				global165
				(> (gEgo x?) 111)
				(> (gEgo y?) 123)
				(!= global165 5)
				(!= (self script?) ogreStuff)
				(!= (self script?) ogreAwake)
			)
			(if
				(not
					(if (== gPrevRoomNum 50)
						(if (== global165 4) else (== global165 1))
					)
				)
				(self setScript: ogreStuff)
			)
		)
		(if (& (gEgo onControl: 0) $0040)
			(proc0_9)
			(gRoom newRoom: 4)
		)
		(if
		(and (& (gEgo onControl: 0) $0010) (not local9))
			(proc0_9)
			(gRoom newRoom: 51)
		)
		(if (& (gEgo onControl: 0) $0008)
			(proc0_9)
			(gRoom newRoom: 48)
		)
		(if
		(and (& (gEgo onControl: 0) $0020) (not local9))
			(proc0_9)
			(gRoom newRoom: 50)
		)
		(if
			(and
				(& (gEgo onControl: 0) $0400)
				(!= global105 18)
				(not local9)
			)
			(= global105 18)
			(proc0_8)
			(moveOnTheStairs changeState: 1)
		)
	)
	
	(method (dispose)
		(proc0_9)
		(= global189 0)
		(super dispose:)
	)
	
	(method (handleEvent pEvent &tmp gInvSaidMe)
		(return
			(cond 
				((pEvent claimed?) (return 1))
				((== (pEvent type?) evSAID)
					(cond 
						((Said 'look>')
							(cond 
								((Said '<under/table') (Print 49 0))
								((Said '/table') (if newAct_4 (Print 49 1) else (Print 49 2)))
								((Said '/chair') (Print 49 3))
								((Said '/carpet,carpet') (Print 49 4))
								((Said '/stair') (Print 49 5))
								((Said '/window') (Print 49 6))
								((Said '/door') (Print 49 7))
								((Said '/wall') (Print 49 8))
								((or (Said '/dirt') (Said '<down')) (Print 49 9))
								((Said '/giant')
									(cond 
										((== global165 3) (Print 49 1))
										(global165 (Print 49 10))
										(else (Print 49 11))
									)
								)
								((Said '/bulldog')
									(if (== (newAct script?) chewBone)
										(Print 49 12)
									else
										(Print 49 13)
									)
								)
								((Said '[<around][/room,cottage]') (Print 49 14))
							)
						)
						((Said 'blow/whistle')
							(if
							(and (gEgo has: 27) (gCast contains: newAct_4))
								(if (== global165 3)
									(Print 49 15)
								else
									(Print 49 16)
								)
							else
								(pEvent claimed: 0)
							)
						)
						((Said 'converse/bulldog')
							(if (== (newAct script?) chewBone)
								(Print 49 17)
							else
								(Print 49 18)
							)
						)
						((Said 'kill/bulldog') (Print 49 19))
						((Said 'pat/bulldog') (Print 49 20))
						((Said 'calm/bulldog') (Print 49 21))
						((Said 'get,capture/bulldog') (Print 49 22))
						((Said 'sit>') (Print 49 23) (pEvent claimed: 1))
						((Said 'converse/bulldog')
							(if (== (newAct script?) chewBone)
								(Print 49 17)
							else
								(Print 49 18)
							)
						)
						((Said 'converse,awaken[/giant]')
							(if (gCast contains: newAct_4)
								(if (== global165 3)
									(if
										(and
											(< (gEgo distanceTo: newAct_4) 50)
											(not (ogreAwake state?))
										)
										(Print 49 24)
										(= local11 1)
										(ogreAwake cue:)
									else
										(Print 49 25)
									)
								else
									(Print 49 26)
								)
							else
								(Print 49 27)
							)
						)
						(
						(or (Said 'open/closet') (Said 'open/door<closet'))
							(cond 
								((not (gEgo inRect: 219 123 245 130)) (proc0_13))
								((newProp cel?) (Print 49 28))
								(
									(or
										(gCast contains: newAct_3)
										(gCast contains: newAct_4)
									)
									(Print 49 29)
								)
								((gEgo has: 33) (Print 49 10))
								(else (newProp setScript: doorOpen))
							)
						)
						((Said 'open/door')
							(cond 
								((gEgo inRect: 219 123 245 130)
									(cond 
										((newProp cel?) (Print 49 28))
										(
											(or
												(gCast contains: newAct_3)
												(gCast contains: newAct_4)
											)
											(Print 49 29)
										)
										((gEgo has: 33) (Print 49 10))
										(else (newProp setScript: doorOpen))
									)
								)
								((gEgo inRect: 38 129 73 141)
									(if (not (newProp_2 cel?))
										(cond 
											((gEgo has: 33)
												(newProp_2 ignoreActors: 1 setCycle: End setPri: 0)
												(= global210 1)
												(gEgo ignoreControl: 16384)
												(if
												(and (gEgo has: 33) (== (ogreAwake state?) 0))
													(ogreAwake changeState: 2)
												)
											)
											((gCast contains: newAct_4)
												(if
												(and (== global165 3) (not (ogreAwake state?)))
													(ogreAwake changeState: 2)
												)
											)
											(else
												(newProp_2 ignoreActors: 1 setCycle: End setPri: 0)
												(= global210 1)
												(gEgo ignoreControl: 16384)
											)
										)
									else
										(Print 49 30)
									)
								)
								(else (Print 49 31))
							)
						)
						((Said 'close/door')
							(cond 
								((gEgo inRect: 219 123 245 130)
									(if (newProp cel?)
										(newProp setCycle: Beg)
									else
										(Print 49 32)
									)
								)
								((gEgo inRect: 38 129 73 141)
									(if (newProp_2 cel?)
										(if (gEgo has: 33)
											(Print 49 33)
										else
											(= global210 0)
											(gEgo observeControl: 16384)
											(newProp_2 setCycle: Beg setPri: -1)
										)
									else
										(Print 49 32)
									)
								)
								(else (Print 49 31))
							)
						)
						((Said 'get/egg[<gold]')
							(if newAct_4
								(if (< (gEgo distanceTo: newAct_4) 20)
									(gEgo put: 33 49)
									(ogreAwake changeState: 1)
								else
									(proc0_13)
								)
							else
								(Print 49 34)
							)
						)
						((Said 'get,rob/chicken')
							(cond 
								((not newAct_2) (Print 49 35))
								((gEgo has: 33) (proc0_14))
								(
									(and
										(gEgo inRect: 190 148 264 156)
										(> (gEgo x?) (- (newAct_2 x?) 11))
										(< (gEgo x?) (+ (newAct_2 x?) 11))
									)
									(= global182 1)
									(gEgo get: 33)
									(gGame changeScore: 4)
									(newAct_2 dispose:)
								)
								(else (proc0_13))
							)
						)
						((Said 'kill/giant') (Print 49 36))
						(
							(or
								(Said 'kiss/giant')
								(Said 'kiss/bulldog')
								(Said 'kiss[/!*]')
							)
							(Print 49 37)
						)
						((Said 'fling,deliver,feed/bone')
							(if (gEgo has: 23)
								(if (> (gEgo distanceTo: newAct) 40)
									(proc0_8)
									(newAct setMotion: 0 setCycle: 0 setScript: 0)
									((gInv at: 23) moveTo: 49)
									(gGame changeScore: 4)
									(newAct setScript: catchBone)
								else
									(Print 49 38)
								)
							else
								(Print 49 39)
							)
						)
						((Said 'get,rob/bone')
							(if (== ((gInv at: 23) owner?) 49)
								(Print 49 40)
							else
								(Print 49 41)
							)
						)
						((Said 'get,capture/giant') (Print 49 42))
						(
						(and (Said 'deliver>') (= gInvSaidMe (gInv saidMe:)))
							(if
							(and gInvSaidMe (gEgo has: (gInv indexOf: gInvSaidMe)))
								(if (gCast contains: newAct_4)
									(Print 49 43)
								else
									(Print 49 44)
								)
								(pEvent claimed: 1)
							else
								(Print 49 45)
								(pEvent claimed: 1)
							)
						)
					)
				)
			)
		)
	)
	
	(method (newRoom newRoomNumber)
		(if (== newRoomNumber 4)
			((ScriptID 602) keep: 0)
			(= global189 0)
		)
		(super newRoom: newRoomNumber)
	)
)

(instance ogreStuff of Script
	(properties)
	
	(method (doit)
		(super doit:)
		(if
			(and
				(not global167)
				(== (self state?) 11)
				(> (gEgo y?) 122)
			)
			(self cue:)
		)
	)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(switch global165
					(1
						(if global167
							(self changeState: 11)
						else
							(self changeState: 10)
						)
					)
					(2 (self changeState: 20))
					(3 (self changeState: 30))
				)
			)
			(10
				(if (== (newProp_2 cel?) 0)
					(newProp_2 setCycle: End setPri: 0)
				)
				(theMusic number: 5 loop: -1 play:)
				(self cue:)
			)
			(11
				((= newAct_4 (Act new:))
					view: 250
					posn: 53 132
					setStep: 6 2
					init:
					setCycle: Walk
				)
				(User canInput: 0)
				(if (not global167)
					(newAct_4 setMotion: MoveTo 130 133)
				else
					(proc0_3 newAct_4 gEgo)
				)
			)
			(12
				(= local9 1)
				(newAct_4
					setAvoider: (Avoid new:)
					setCycle: Walk
					setMotion: Chase gEgo 15 self
				)
			)
			(13
				(User canControl: 0 canInput: 0)
				(gEgo dispose:)
				(newAct_4 view: 78 setCycle: End self)
				(Print 49 46 67 -1 20 83)
				(theMusic number: 6 loop: 1 play:)
				(Print 49 47 67 -1 10)
			)
			(14
				(newAct_4
					view: 79
					setPri: 9
					setCycle: Walk
					setAvoider: Avoid
					setMotion: MoveTo 246 132 self
				)
			)
			(15 (= global127 1))
			(20
				(Print 49 48 67 -1 10)
				(ogreAwake state: 0)
				((= newAct_4 (Act new:))
					illegalBits: 0
					view: 256
					loop: 2
					posn: 200 158
					setStep: 6 2
					setPri: 12
					init:
					setScript: ogreAwake
				)
			)
			(30
				(if (== gPrevRoomNum 51) (Print 49 49 67 -1 10))
			)
		)
	)
)

(instance ogreAwake of Script
	(properties)
	
	(method (doit)
		(super doit:)
		(if
			(and
				(not global167)
				(== (self state?) 1)
				(> (gEgo y?) 122)
				(not (& (gEgo onControl:) $0004))
			)
			(self cue:)
		)
	)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(if (!= global165 2)
					(if (== global223 0)
						(= seconds 75)
					else
						(= seconds 60)
					)
				else
					(self cue:)
				)
			)
			(1
				(if (> (gEgo y?) 122) (return))
			)
			(2
				(gEgo observeControl: 4)
				(cond 
					((gEgo has: 33) (if (not local11) (Print 49 50 25 4)))
					((== global165 3) (Print 49 51))
				)
				(theMusic number: 5 loop: -1 play:)
				(newAct_4 cycleSpeed: 0 loop: 1 setCycle: End self)
			)
			(3
				(if (== global223 0) (= seconds 3) else (self cue:))
			)
			(4
				(= global165 4)
				(= local9 1)
				(newAct_4
					view: 250
					posn: (newAct_4 x?) (- (newAct_4 y?) 3)
					setAvoider: Avoid
					setCycle: Walk
					setMotion: Chase gEgo 15 self
				)
			)
			(5
				(User canControl: 0 canInput: 0)
				(if (gEgo has: 33)
					(Print 49 52 83)
				else
					(Print 49 47 83)
				)
				(theMusic number: 6 loop: 1 play:)
				(gEgo dispose:)
				(newAct_4 view: 78 setCycle: End self)
			)
			(6
				(newAct_4
					view: 79
					setCycle: Walk
					illegalBits: -32768
					setPri: -1
					setAvoider: Avoid
					setMotion: MoveTo 246 132 self
				)
			)
			(7 (= global127 1))
		)
	)
)

(instance ogressChase of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(= local9 1)
				(theMusic number: 10 loop: -1 play:)
				(newAct_3
					illegalBits: -32768
					setAvoider: Avoid
					ignoreActors: 1
					setCycle: Walk
					setMotion: Chase gEgo 15 self
				)
			)
			(1
				(proc0_8)
				(theMusic number: 11 loop: 1 play:)
				(gEgo hide:)
				(newAct_3
					view: 48
					cycleSpeed: 2
					cel: 255
					setCycle: End self
				)
			)
			(2
				(Print 49 53 67 -1 10 83)
				(= seconds 4)
			)
			(3 (= global127 1))
		)
	)
)

(instance henPecked of Script
	(properties)
	
	(method (init param1)
		(super init: param1)
	)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(newAct_2
					view: 360
					posn: 225 129
					loop: 0
					show:
					setPri: 12
					ignoreActors: 1
					setCycle: Walk
					moveSpeed: 2
					cycleSpeed: 0
					setMotion: MoveTo 260 133 self
				)
			)
			(1
				(if (gCast contains: newAct_2)
					(newAct_2
						loop: (+ (newAct_2 loop?) 2)
						setCycle: End self
					)
				)
			)
			(2
				(if (gCast contains: newAct_2)
					(newAct_2
						setCycle: Walk
						setMotion:
							MoveTo
							(if (> (newAct_2 x?) 238)
								(Random 214 230)
							else
								(Random 240 262)
							)
							133
							self
					)
				)
			)
			(3 (= state 0) (self cue:))
		)
	)
)

(instance chaseEgo of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(Print 49 54 67 -1 10 83)
				(newAct
					setAvoider: (Avoid new:)
					setCycle: Fwd
					ignoreActors: 1
					setMotion: Chase gEgo 15 self
				)
			)
			(1
				(User canInput: 0 canControl: 0)
				(gEgo dispose:)
				(newAct view: 87 loop: 0 setMotion: 0)
				(self cue:)
			)
			(2
				(newAct loop: 1 setCycle: Fwd)
				(theMusic number: 5 loop: -1 play:)
				(= seconds 3)
			)
			(3
				(newAct loop: 3 cycleSpeed: 2 setCycle: End)
				(= seconds 4)
			)
			(4
				((= newProp_3 (Prop new:))
					view: 87
					loop: 4
					cel: 0
					setPri: 15
					posn: (- (newAct x?) 17) (- (newAct y?) 9)
					init:
					cycleSpeed: 1
					setCycle: Fwd
				)
				(= seconds 2)
			)
			(5
				(newProp_3 dispose:)
				(Print 49 55 83 67 -1 10)
				(= global127 1)
			)
		)
	)
)

(instance chewBone of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(newAct
					view: 350
					loop: 2
					ignoreActors: 0
					cycleSpeed: 1
					setCycle: Fwd
				)
				(= seconds 2)
			)
			(1
				(dogsPlace
					top: (newAct nsTop?)
					bottom: (+ (newAct nsBottom?) 1)
					left: (- (newAct nsLeft?) 1)
					right: (+ (newAct nsRight?) 1)
					init:
				)
				(gEgo observeBlocks: dogsPlace)
			)
		)
	)
)

(instance dogsPlace of Blk
	(properties)
)

(instance catchBone of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(proc0_3 gEgo newAct)
				(throwSound number: 63 play:)
				(gEgo
					view: 15
					cycleSpeed: 1
					cel: 255
					setCycle: CT 5 1 self
				)
			)
			(1
				(gEgo cel: 6 setCycle: End)
				((= newAct_5 (Act new:))
					view: 541
					illegalBits: 0
					posn: (+ (gEgo x?) 3) (- (gEgo y?) 25)
					setLoop: 0
					setPri: 14
					setStep: 6 1
					setCycle: Fwd
					setMotion: MoveTo (- (newAct x?) 10) (- (newAct y?) 11) self
					init:
				)
			)
			(2
				(Print 49 56 70 290 67 -1 10 88)
				(gEgo view: 2 cycleSpeed: 0 setCycle: Walk)
				(newAct_5 dispose:)
				(newAct view: 350 loop: 3 setCycle: End self)
			)
			(3
				(newAct
					view: 352
					setLoop: (if (< (newAct x?) 155) 0 else 1)
					setCycle: Walk
					moveSpeed: 1
					setMotion: MoveTo 155 126 self
				)
			)
			(4
				(newAct
					view: 350
					loop: 2
					ignoreActors: 0
					cycleSpeed: 1
					setCycle: Fwd
				)
				(= seconds 8)
			)
			(5
				(if gModelessDlg (gModelessDlg dispose:))
				(proc0_9)
				(newAct setScript: chewBone)
			)
		)
	)
)

(instance doorOpen of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(0
				(proc0_8)
				(gEgo
					setMotion: MoveTo (+ (client x?) 20) (+ (client y?) 9) self
				)
			)
			(1
				(proc0_3 gEgo client)
				(client setCycle: End self)
			)
			(2
				(gEgo
					setMotion: MoveTo (gEgo x?) (+ (client y?) 2) self
				)
			)
			(3
				(proc0_9)
				(gRoom newRoom: 51)
			)
		)
	)
)

(instance moveOnTheStairs of Script
	(properties)
	
	(method (changeState newState)
		(switch (= state newState)
			(1
				(gEgo setStep: 2 2)
				(gEgo illegalBits: 0)
				(if (> (gEgo y?) 100)
					(gEgo setMotion: MoveTo 194 61 self)
				else
					(gEgo setMotion: MoveTo 97 123 self)
				)
			)
			(2
				(proc0_9)
				(gEgo illegalBits: -32768)
				(if (== global210 0) (gEgo observeControl: 16384))
				(gEgo setStep: 3 2)
				(= global105 0)
			)
		)
	)
)
