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


(local
	[local0 23]
	local23
)
(class User of Obj
	(properties
		alterEgo 0
		canInput 0
		controls 0
		echo 32
		prevDir 0
		prompt {Enter input}
		inputLineAddr 0
		x -1
		y -1
		blocks 1
		mapKeyToDir 1
	)
	
	(method (init param1 param2)
		(= inputLineAddr (if argc param1 else @local0))
		(= local23 (if (== argc 2) param2 else 45))
	)
	
	(method (doit &tmp newEvent newEventType newEventMessage)
		(if ((= newEvent (Event new:)) type?)
			(= gLastEvent newEvent)
			(= newEventType (newEvent type?))
			(if mapKeyToDir (MapKeyToDir newEvent))
			(if TheMenuBar (TheMenuBar handleEvent: newEvent))
			(GlobalToLocal newEvent)
			(gGame handleEvent: newEvent)
			(if (not (newEvent claimed?))
				(switch (newEvent type?)
					(1
						(if
							(and
								controls
								(IsObject alterEgo)
								(gCast contains: alterEgo)
							)
							(alterEgo setMotion: MoveTo (newEvent x?) (newEvent y?))
							(= prevDir 0)
							(newEvent claimed: 1)
						)
					)
					(64
						(if
							(and
								controls
								(IsObject alterEgo)
								(gCast contains: alterEgo)
							)
							(= newEventMessage (newEvent message?))
							(if
								(and
									(== newEventType 4)
									(== newEventMessage prevDir)
									(IsObject (alterEgo mover?))
								)
								(= newEventMessage 0)
							)
							(= prevDir
								(if (== newEventType 4) newEventMessage else 0)
							)
							(alterEgo setDirection: newEventMessage)
							(newEvent claimed: 1)
						)
					)
					(else 
						(gCast handleEvent: newEvent)
					)
				)
			)
			(if
				(and
					(not (newEvent claimed?))
					(== (newEvent type?) 4)
					(or
						(== (newEvent message?) echo)
						(and
							(<= 32 (newEvent message?))
							(<= (newEvent message?) 127)
						)
					)
					canInput
					(self getInput: newEvent)
					(Parse @local0 newEvent)
				)
				(newEvent type: 128)
				(self said: newEvent)
			)
		)
		(newEvent dispose:)
		(= gLastEvent 0)
	)
	
	(method (canControl theControls)
		(if argc (= controls theControls) (= prevDir 0))
		(return controls)
	)
	
	(method (getInput param1 &tmp temp0 temp1)
		(if (!= (param1 type?) 4) (= local0 0))
		(if (!= (param1 message?) echo)
			(Format @local0 996 0 (param1 message?))
		)
		(= temp0 (Sound pause: blocks))
		(= temp1 (EditPrint @local0 local23 prompt 67 x y))
		(Sound pause: temp0)
		(return temp1)
	)
	
	(method (said param1)
		(if TheMenuBar (gSFeatures addToFront: TheMenuBar))
		(if global54
			(__proc984_0 alterEgo gSFeatures gCast gFeatures)
		else
			(gSFeatures add: gCast gFeatures)
		)
		(gSFeatures addToEnd: gGame handleEvent: param1 release:)
		(if
		(and (== (param1 type?) 128) (not (param1 claimed?)))
			(gGame pragmaFail: @local0)
		)
	)
)
