(version 2)
(include "sci.sh")
(exports
    0 OgreStuff
)
(use "Main")
(use "Class_255_0")
(use "Chase")
(use "Timer")
(use "Avoid")
(use "Cycle")
(use "Obj")
(script 803)


(local
    local0
    local1

)
(instance public OgreStuff of Script
    (properties)

    (method (init param1)
        (super:init(rest param1))
        proc255_0(803 0)
    )


    (method (doit)
        (var temp0)
        (super:doit())
        = temp0 proc0_12(1)
        (if (not local0 and temp0)
            = local0 1
            proc255_0(803 6)
            (send gMenace:setMotion(0))
        )(else
            (if ((local0 and not local1) and (< (send gEgo:distanceTo(gMenace)) 12))
                = local1 1
                proc255_0(803 7)
                (self:changeState(2))
            )(else
                (if (local0 and not temp0)
                    = local0 0
                    proc255_0(803 8)
                    (self:changeState(1))
                )
            )
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (if (<> (send (ScriptID(0 21)):signal) -1)
                    (send (ScriptID(0 21)):
                        loop(1)
                        fade()
                    )
                )
                (send (ScriptID(0 23)):
                    number(35)
                    loop(-1)
                    play()
                )
                (send gMenace:
                    view(130)
                    setAvoider(Avoid)
                    illegalBits(-28672)
                    setCycle(Walk)
                    cycleSpeed(0)
                    init()
                )
                (switch (gGNumber)
                    (case (send global2:west)
                        (send gMenace:
                            posn(320 155)
                            setMotion(MoveTo 314 155 self)
                        )
                    )
                    (case (send global2:east)
                        (send gMenace:
                            posn(-10 146)
                            setMotion(MoveTo 10 146 self)
                        )
                    )
                    (default 
                        (if (Random(0 1))
                            (send gMenace:
                                posn(320 160)
                                setMotion(MoveTo 314 155 self)
                            )
                        )(else
                            (send gMenace:
                                posn(-10 146)
                                setMotion(MoveTo 12 146 self)
                            )
                        )
                    )
                )
            )
            (case 1
                (send gMenace:
                    setStep(5 3)
                    setMotion(Chase gEgo 20 self)
                )
            )
            (case 2
                (if (not proc0_12(44) and (== gNewRoomNumber gNumber))
                    proc0_2()
                    (send gMenace:hide())
                    (send gEgo:
                        view(20)
                        setMotion(0)
                        loop(0)
                        cel(0)
                        setCycle(Fwd)
                    )
                    (if (== (send global2:script) ScriptID(782 0))
                        (send (ScriptID(782 1)):stop())
                    )
                    (send (ScriptID(0 21)):
                        number(46)
                        loop(1)
                        init()
                        play(self)
                    )
                )(else
                    (self:changeState(5))
                )
            )
            (case 3
                (send gEgo:
                    loop(1)
                    cel(0)
                    setCycle(End)
                )
                (send gMenace:
                    posn((send gEgo:x) (send gEgo:y))
                    loop(4)
                    show()
                    stopUpd()
                )
                (Timer:set(self 3))
            )
            (case 4
                (send (ScriptID(0 23)):fade())
                proc0_16("You were warned ogre and ogre again...")
            )
            (case 5
                (send gMenace:setMotion(0))
            )
        )
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if ((super:handleEvent(pEvent)))
                return 
            )(else
                (if (Said('look,look/ogre,man[<green]') or proc255_5(gMenace pEvent 3))
                    proc255_0(803 1)
                    (send pEvent:claimed(1))
                )(else
                    (if (Said('talk,speak[/ogre]'))
                        proc255_0(803 2)
                    )(else
                        (if (Said('attack,kill/ogre'))
                            proc255_0(803 3)
                        )(else
                            (if (Said('use,cast/dagger'))
                                (if (not (send gEgo:has(0)))
                                    proc255_0(803 4)
                                )(else
                                    proc255_0(803 5)
                                )
                            )
                        )
                    )
                )
            )
        )
    )

)
