/******************************************************************************/
(script 998)
/******************************************************************************/
(include "sci.sh")
/******************************************************************************/
(use "main")
(use "controls")
(use "feature")
(use "cycle")
(use "obj")
/******************************************************************************/
(class PicView of Feature
	(properties
		x 0
		y 0
		z 0
		heading 0
		noun 0
		nsTop 0
		nsLeft 0
		nsBottom 0
		nsRight 0
		description 0
		sightAngle $6789
		actions 0
		onMeCheck $6789
		approachX 0
		approachY 0
		approachDist 0
		{_approachVerbs} $6789
		lookStr 0
		view 0
		loop 0
		cel 0
		priority -1
		signal 0
		palette 0
	)
	(method (init params)
		(send global[$A]:add(self))
		SetNowSeen(self)
		(super:init(rest params))
	)
	(method (dispose)
		(if(actions)
			(send actions:dispose())
			= actions NULL
		)
		(send global[$20]:delete(self))
		DisposeClone(self)
	)
	(method (showSelf)
		Print(objectName #icon view loop cel)
	)
	(method (onMe params)
		return((if(& signal $80)
			FALSE
		)(else
			(super:onMe(rest params))
		))
	)
)
/******************************************************************************/
(class View of Feature
	(properties
		x 0
		y 0
		z 0
		heading 0
		noun 0
		nsTop 0
		nsLeft 0
		nsBottom 0
		nsRight 0
		description 0
		sightAngle $6789
		actions 0
		onMeCheck $6789
		approachX 0
		approachY 0
		approachDist 0
		{_approachVerbs} $6789
		lookStr 0
		yStep 2
		view 0
		loop 0
		cel 0
		priority 0
		underBits 0
		signal $101
		lsTop 0
		lsLeft 0
		lsBottom 0
		lsRight 0
		brTop 0
		brLeft 0
		brBottom 0
		brRight 0
		palette 0
	)
	(method (init param1 param2)
		= signal (& signal $7FFF)
		(if(not(send gCast:contains(self)))
			= lsTop 0
			= lsLeft 0
			= lsBottom 0
			= lsRight 0
			= signal (& signal $FF77)
		)
		BaseSetter(self)
		(super:init(rest param2))
		(self:checkDetail())
	)
	(method (dispose)
		(self:
			startUpd()
			hide()
		)
		
		= signal (| signal $8000)
	)
	(method (showSelf)
		Print(objectName #icon view loop cel)
	)
	(method (isNotHidden)
		return(not (& signal $88))
	)
	(method (onMe params)
		return((if(self:isNotHidden())
			(super:onMe(rest params))
		)(else
			0
		))
	)
	(method (posn newX newY newZ)
		(if(>= paramTotal 1)
		    = x newX
		    (if(>= paramTotal 2)
		    	= y newY
		    	(if(>= paramTotal 3)
		   			= z newZ
		   		)
		   	)
		)
  		BaseSetter(self)
  		(self:forceUpd())
	)
	(method (stopUpd)
		= signal (| signal 1)
		= signal (& signal $FFFD)
	)
	(method (forceUpd)
		= signal (| signal $40)
	)
	(method (startUpd)
		= signal (| signal 2)
		= signal (& signal $FFFE)
	)
	(method (setPri param1)
		(if(== paramTotal 0)
		    = signal (| signal $10)
		)(else
  			(if(== param1 -1)
		    	= signal (& signal $FFEF)
		    )(else
  		 		= priority param1
  		 		= signal (| signal $10)
  		 	)
		)
  		(self:forceUpd())
	)
	(method (setLoop param1)
		(if(== paramTotal 0)
		    = signal (| signal $800)
		)(else
  			(if(== param1 -1)
		    	= signal (& signal $F7FF)
		   	)(else 
		    	= loop param1
		    	= signal (| signal $800)
		    )
		)   
  		(self:forceUpd())
	)
	(method (setCel param1)
		(if(== paramTotal 0)
		    = signal (| signal $1000)
		)(else
  			(if(== param1 -1)
		    	= signal (& signal $EFFF)
		   	)(else 
		    	= signal (| signal $1000)
		    	= cel (if(>= param1 (self:lastCel))
		    		(self:lastCel)
		    	)(else
		    		param1
		    	)
		    )
		)   
  		(self:forceUpd())
	)
	(method (ignoreActors param1)
		(if(== 0 paramTotal or param1)
			= signal (| signal $4000)
		)(else
			= signal (& signal $BFFF)
		)
	)
	(method (hide)
		= signal (| signal 8)
	)
	(method (show)
		= signal (& signal $FFF7)
	)
	(method (delete)
		(if(& signal $8000)
		    = signal (& signal $7FFF)
		    (send gCast:delete(self))
		    (if(underBits)
		   		UnLoad(rsMEMORY underBits)
		   		= underBits NULL
			)
  			(if(& signal $20)
		    	(send global[$A]:
		    		add(
		    			(send (PicView:new()):
		    				view(view)
		    				loop(loop)
		    				cel(cel)
		    				x(x)
		    				y(y)
		    				z(z)
		    				priority(priority)
		    				signal(signal)
		    				yourself()
		    			)
		    		)
		    	)
				(send global[$20]:add(self))
			)(else
				DisposeClone(self)
			)
  			(if(IsObject(actions))
			   	(send actions:dispose())
			)
  			= actions NULL
  		)
	)
	(method (addToPic)
		(if(not(send gCast:contains(self)))
			(self:init())
		)
		(self:signal( | signal $8021 ))
	)
	(method (lastCel)
		return(- NumCels(self) 1)
	)
	(method (isExtra param1)
		(var temp0)
		= temp0 (& signal $200)
		(if(paramTotal)
			(if(param1)
				= signal (| signal $200)
			)(else
				= signal (& signal $FDFF)
			)
		)
		return(temp0)
	)
	(method (motionCue))
	(method (checkDetail))
)
/******************************************************************************/
(class Prop of View
	(properties
		x 0
		y 0
		z 0
		heading 0
		noun 0
		nsTop 0
		nsLeft 0
		nsBottom 0
		nsRight 0
		description 0
		sightAngle $6789
		actions 0
		onMeCheck $6789
		approachX 0
		approachY 0
		approachDist 0
		{_approachVerbs} $6789
		lookStr 0
		yStep 2
		view 0
		loop 0
		cel 0
		priority 0
		underBits 0
		signal 0
		lsTop 0
		lsLeft 0
		lsBottom 0
		lsRight 0
		brTop 0
		brLeft 0
		brBottom 0
		brRight 0
		palette 0
		cycleSpeed 0
		script 0
		cycler 0
		timer 0
		detailLevel 0
	)
	(method (doit)
		(var temp0)
		SetNowSeen(self nsTop)
		(if(& signal $8000)
			return
		)
		(if(script)
			(send script:doit())
		)
		(if((& signal 4) and not(& signal 2))
			return
		)
		(if(cycler)
			(send cycler:doit())
		)
	)
	(method (handleEvent pEvent)
		(if(script)
			(send script:handleEvent(pEvent))
		)
		(super:handleEvent(pEvent))
	)
	(method (delete)
		(if(& signal $8000)
			(self:
				setScript(0)
				setCycle(0)
			)
			(if(timer)
				(send timer:dispose())
			)
			(super:delete())
		)
	)
	(method (motionCue)
		(if(cycler and (send cycler:completed))
			(send cycler:motionCue())
		)
	)
	(method (checkDetail param1)
		(if(not detailLevel)
		)(else
  			(if(< 
  				(if(paramTotal)
  					(param1)
  				)(else	
  					(send gGame:detailLevel)
  				)
  				detailLevel)
		    		(self:stopUpd())
		    )(else
  					(if(cycler)
  						(self:startUpd())
  					)
  			)
  		)
	)
	(method (setCycle param1 param2)
		(if(cycler)
			(send cycler:dispose())
		)
		(if(param1)
		    (self:setCel(-1))
		    (self:startUpd())
		    = cycler 
		    	(if(& (send param1:{-info-}) $8000)
		    		(send param1:new())
		    	)(else
		    		(param1)
		    	)
		    (send cycler:init(self rest param2))
		)(else
			= cycler NULL
		)
	)
	(method (setScript param1 param2)
		(if(IsObject(script))
			(send script:dispose())
		)
		(if(param1)
			(send param1:init(self rest param2))
		)
	)
	(method (cue)
		(if(script)
			(send script:cue())
		)
	)
)
/******************************************************************************/
(class Actor of Prop
	(properties
		x 0
		y 0
		z 0
		heading 0
		noun 0
		nsTop 0
		nsLeft 0
		nsBottom 0
		nsRight 0
		description 0
		sightAngle $6789
		actions 0
		onMeCheck $6789
		approachX 0
		approachY 0
		approachDist 0
		{_approachVerbs} $6789
		lookStr 0
		yStep 2
		view 0
		loop 0
		cel 0
		priority 0
		underBits 0
		signal 0
		lsTop 0
		lsLeft 0
		lsBottom 0
		lsRight 0
		brTop 0
		brLeft 0
		brBottom 0
		brRight 0
		palette 0
		cycleSpeed 0
		script 0
		cycler 0
		timer 0
		detailLevel 0
		illegalBits $8000
		xLast 0
		yLast 0
		xStep 3
		moveSpeed 0
		blocks 0
		baseSetter 0
		mover 0
		looper 0
		viewer 0
		avoider 0
		code 0
	)
	(method (init params)
		(super:init(rest params))
		= xLast x
		= yLast y
	)
	(method (doit)
		(var temp0, temp1, temp2)
		(if(& signal $8000)
			return
		)
		(if(script)
			(send script:doit())
		)
		(if(code)
		 	(send code:doit(self))
		)
		(if(& signal 4 and not & signal 2)
			return
		)
		(if(viewer)
			(send viewer:doit(self))
		)
		(if(avoider)
			(send avoider:doit())
		)(else
			(if(mover)
				(send mover:doit())
			)
		)
		(if(cycler)
			= temp1 brLeft
			= temp2 brRight
			(send cycler:doit())
			(if(baseSetter)
				(send baseSetter:doit(self))
			)(else
				BaseSetter(self)
			)
			(if(<> temp1 brLeft or <> temp2 brRight)
		    	(if(self:cantBeHere())
		    		(self:findPosn())
		    	)
		    )
		)
		= xLast x
		= yLast y
	)
	(method (posn param1 param2 param3)
		(super:posn(param1 param2 rest param3))
		= xLast param1
		= yLast param2
		(if(self:cantBeHere())
			(self:findPosn())
		)
	)
	(method (setLoop param1 param2)/*
		(var temp0 = 0)
		(if(== paramTotal 0)
			(super:setLoop())
			0
		)(else
			(if(not IsObject(param1))
				(super:setLoop(param1 rest param2))
			)(else
				= temp0  (if(& (send param1:{-info-}) $8000)
					(send param1:new())
				)(else
		    		param1
		    	) 
		    )
		)
		(if(temp0)
			(if(looper)
				(send looper:dispose())
			)
			(send (= looper temp0):init(self rest param2))
		)*/
		
		(var temp0)
		= temp0 (if(== paramTotal 0)
		    (super:setLoop())
		    0
		)(else
  			(if(not IsObject(param1))
		    	(super:setLoop(param1 rest param2))
		    	0
			)(else
  				(if(& (send param1:{-info-}) $8000) 
		    		(send param1:new())
		    	)(else
		    		(param1)
		    	)
		    )
		)
		(if(temp0)
		    (if(looper)
		    	(send looper:dispose())
		    )
  			(send (= looper temp0):init(self rest param2))
		)
	)
	(method (delete)
		(if(& signal $8000)
			(if(<> mover -1)
				(self:setMotion(NULL))
			)
			(self:setAvoider(NULL))
			(if(baseSetter)
				(send baseSetter:dispose())
				= baseSetter NULL
			)
			(if(looper)
				(send looper:dispose())
				= looper NULL
			)
			(if(viewer)
				(send viewer:dispose())
				= viewer NULL
			)
			(if(blocks)
				(send blocks:dispose())
				= blocks NULL
			)
			(if(code)
				(send code:dispose())
				= code NULL
			)
			(if(IsObject(actions))
				(send actions:dispose())
				= actions NULL
			)
			(super:delete())
		)
	)
	(method (motionCue)
		(if(mover and (send mover:completed))
			(send mover:motionCue())
		)
		(super:motionCue())
	)
	(method (checkDetail param1)
		(if(not detailLevel)
		)(else
  			(if(< 
  				(if(paramTotal)
  					(param1)
  				)(else	
  					(send gGame:detailLevel)
  				)
  				detailLevel)
		    		(self:stopUpd())
		    )(else
  					(if(cycler or mover)
  						(self:startUpd())
  					)
  			)
  		)
	)
	(method (setMotion param1 param2)
		(if(mover and (<> mover -1))
			(send mover:dispose())
		)
		(if(param1)
			(self:startUpd())
			= mover (if(& (send param1:{-info-}) $8000)
				(send param1:new())
			)(else
		    	param1 
			)
			(send mover:init(self rest param2))
		)(else
			= mover NULL
		)
	)
	(method (setAvoider param1 param2)
		(if(avoider)
			(send avoider:dispose())
		)
		= avoider (if(IsObject(param1) and (& (send param1:{-info-}) $8000))
			(send param1:new())
		)(else
		    param1 
		)
		(if(avoider)
			(send avoider:init(self rest param2))
		)
	)
	(method (ignoreHorizon param1)
		(if(not(paramTotal) or param1)
			= signal (| signal $2000)
		)(else
			= signal (& signal $DFFF)
		)
	)
	(method (observeControl params)
		(var temp0)
		= temp0 0
		(while(< temp0 paramTotal)
			= illegalBits (| illegalBits params[temp0])
			++temp0
		)
	)
	(method (ignoreControl params)
		(var temp0)
		= temp0 0
		(while(< temp0 paramTotal)
			= illegalBits (& illegalBits bnot(params[temp0]))
			++temp0
		)
	)
	(method (observeBlocks params)
		(if(not blocks)
			= blocks (Set:new())
		)
		(send blocks:add(rest params))
	)
	(method (ignoreBlocks params)
		(send blocks:delete(rest params))
		(if(send blocks:isEmpty)
			(send blocks:dispose())
			= blocks NULL
		)
	)
	(method (isStopped)
		return(
			(if(not(IsObject(mover)) or (== x (send mover:xLast)) and (== y (send mover:yLast))))
		)
	)
	(method (isBlocked)
		return(& signal $400)
	)
	(method (findPosn)
		(var temp0, temp1, temp2, temp3, temp4)
		= temp2 x
		= temp3 y
		= temp4 0
		= temp1 1
  		(while(not temp4)
		    = temp0 0
		    (while((not temp4) and (< temp0 8))
		    	= x (+ temp2 (* temp1 proc999_0(CosMult((* temp0 45) 100))))
		   	 	= y (- temp3 (* temp1 proc999_0(SinMult((* temp0 45) 100))))
		    	= temp4 (if(not (self:cantBeHere()))
		    		(self:onControl())
				)
		    	++temp0 
		    )
		    ++temp1 
		)
  		(self:posn(x y))
	)
	(method (inRect param1 param2 param3 param4)
		return(if((<= param1 x) and (<  x param3) and
			(<= param2 y) and (<  y param4)))
	)
	(method (onControl param1)
		(if(paramTotal and param1)
			return(OnControl(4 x y))
		)
		return(OnControl(4 brLeft brTop brRight brBottom))
	)
	(method (distanceTo param1)
		GetDistance(x y (send param1:x) (send param1:y) global[$1F])
	)
	(method (cantBeHere)
		(var temp0)
		(if(baseSetter)
			(send baseSetter:doit(self))
		)(else
			BaseSetter(self)
		)
		= temp0 (if(CanBeHere(self (send gCast:elements)))
		)(else
  			(if(not(& signal $2000) and IsObject(gRoom) and (< y (send gRoom:horizon)))
		    	-1
		    )(else
  				(if(blocks)
  					(if(not (send blocks:allTrue(#doit self)))
  						-2
  					)
  				)
			)
		)
		return(temp0)
	)
	(method (setStep param1 param2)
		(if((>= paramTotal 1) and (<> param1 -1))
		    = xStep param1
		)
		(if((>= paramTotal 2) and (<> param2 -1))
			= yStep param2
		)
		(if((mover) and (<> -1 mover))
		    (if(send mover:isMemberOf(MoveTo))
		    	return(send (self:mover):init())
		    )
		)
	)
	(method (setDirection param1)
		(var temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7)
		= temp1 (send gRoom:vanishingY)
		= temp0 (if(== temp1 -30000)
			x
		)(else
  			(send gRoom:vanishingX)
		)
		(if((== xStep 0) and (== yStep 0))
			return
		)
		= temp5 (/ 32000 proc999_3(xStep yStep))
		(switch(param1)
			(case 0
				return(self:setMotion(NULL))
		    )(case 1
		    	= temp2 (- temp0 x)
		    	= temp3 (- temp1 y)
		    )(case 5
		    	= temp2 (- x temp0)
		    	= temp3 (- y temp1)
			)(case 3
				= temp2 temp5
				= temp3 0
			)(case 7
				= temp2 neg temp5
				= temp3 0
			)(default
				(if(< 180 (=temp4 GetAngle(x y temp0 temp1)))
					= temp4 (- temp4 360)
 				)
 				= temp4 (+ (/ (+ temp4 90) 2) (* 45 (- param1 2)))
 				= temp2 SinMult(temp4 100)
 				= temp3 neg(CosMult(temp4 100))
		    )
  		)
  		= temp5 (/ temp5 5)
  		(while((< Abs(temp3) temp5) and (< Abs(temp2) temp5))
		    = temp2 (* temp2 5)
		    = temp3 (* temp3 5)
		)
  		(if((= temp7 (send gRoom:obstacles)) and global[$43])
		    = temp6 AvoidPath(
		    	x y (+ x temp2) (+ y temp3) 
		    	(send temp7:elements) (send temp7:size) 0
		    )
		    = temp2 (- proc999_6(temp6 2) x)
		   	= temp3 (- proc999_6(temp6 3) y)
		   	Memory(3 temp6)
		)
		(if(temp2 or temp3)
		    (self:
		    	setMotion(
		    		MoveTo
		    		(+ x temp2)
		    		(+ y temp3)
		    	)
		    )
		)(else
		    (if(param1)
		    	(self:
		    		setMotion(NULL)
		    		setHeading(* (- param1 1) 45)
		    	)
			)(else
  				(self:setMotion(NULL))
  			)
		)
	)
	(method (setHeading param1 param2 param3)
		(if(paramTotal)
			= heading param1
		)
		(if(looper)
			(send looper:
				doit(
					self
					heading
					(if(>= paramTotal 2)
						param2
					)
				)
			)
		)(else
			DirLoop(self heading)
			(if(>= paramTotal 2 and IsObject(param2))
				(send param2:cue(rest param3))
			)
		)
		return(heading)
	)
)
/******************************************************************************/
