(version 2)
(include "sci.sh")
(exports
    0 Room52
)
(use "Main")
(use "Class_255_0")
(use "AView")
(use "Sound")
(use "Cycle")
(use "Game")
(use "Feature")
(use "Obj")
(script 52)


(local
    local0
    gEgoY
    theGGEgoX
    local3
    local4
    newAct
    theTheGGEgoX
    local7
    local8

)
(instance puss of Prop
    (properties)
)
(instance mouth of Prop
    (properties)
)
(instance tongue of Prop
    (properties)
)
(instance slurp of Sound
    (properties)
)
(instance public Room52 of Rm
    (properties
        picture 52
    )

    (method (init)
        = north 48
        = west 51
        = east 49
        = south 53
        Load(128 78)
        Load(128 122)
        Load(128 777)
        Load(132 82)
        = global109 1
        = global591 1
        (super:init())
        = global116 0
        (if (== global117 52)
            = gNewView (View:new())
            (send gNewView:
                view(78)
                setLoop(8)
                setCel(255)
                setPri(5)
                posn(208 125)
                init()
                stopUpd()
            )
        )
        (if (proc0_13(16 52))
            = gNewView_2 (View:new())
            (send gNewView_2:
                view(120)
                loop(5)
                cel(0)
                ignoreActors()
                posn(209 128)
                setPri(6)
                init()
                stopUpd()
            )
        )
        proc0_1()
        (puss:
            view(78)
            loop(0)
            cel(1)
            posn(204 50)
            setPri(7)
            setCycle(Fwd)
            init()
        )
        (mouth:
            view(777)
            ignoreActors()
            loop(0)
            cel(0)
            posn(207 48)
            setPri(9)
            init()
        )
        (tongue:
            view(777)
            loop(0)
            cel(0)
            ignoreActors()
            posn(207 59)
            setPri(10)
            init()
        )
        (send gEgo:init())
        (switch (global12)
            (case 48
                = global104 2
                (send gEgo:
                    posn(119 70)
                    view(68)
                    setPri(1)
                    ignoreControl(8192)
                )
            )
            (case 53
                proc0_1()
                (send gEgo:
                    view(0)
                    posn((send gEgo:x) 188)
                    observeControl(8192 4096)
                )
            )
            (case 51
                (switch (global104)
                    (case 0
                        (send gEgo:
                            posn(1 (send gEgo:y))
                            setStep(3 2)
                            observeControl(8192 4096)
                            setPri(-1)
                        )
                    )
                    (case 1
                        (send gEgo:
                            posn(1 113)
                            setStep(2 1)
                            view(82)
                            ignoreControl(8192)
                            observeControl(4096)
                            looper(ScriptID(501 1))
                            setPri(1)
                        )
                    )
                    (case 2
                        (send gEgo:
                            view(68)
                            posn(1 85)
                            looper(0)
                            ignoreControl(8192 4096)
                            setStep(1 1)
                            setPri(1)
                        )
                    )
                )
            )
            (case 49
                (send gEgo:
                    view(0)
                    observeControl(8192 4096)
                    setStep(3 2)
                    setPri(-1)
                )
                (if (< (send gEgo:y) 126)
                    (send gEgo:posn(314 102))
                )(else
                    (send gEgo:posn(318 (send gEgo:y)))
                )
            )
            (default 
                (send gEgo:
                    view(0)
                    posn(160 160)
                )
            )
        )
        (self:setRegions(501))
        (switch (global110)
            (case 1
                (if (== Random(1 2) 2)
                    = gNewAct (Act:new())
                    (send gNewAct:
                        posn(1000 1000)
                        init()
                    )
                    = gSeconds Random(2 10)
                )
            )
            (case 2
                = gNewAct (Act:new())
                (send gNewAct:
                    posn(1000 1000)
                    init()
                )
                = gSeconds 3
            )
        )
        (if ((send global5:contains(gNewAct)))
            (send gNewAct:
                view(106)
                setCycle(Walk)
                observeControl(2 8192 4096)
                posn(1000 1000)
                init()
            )
            = gGEgoX 166
            = gGEgoY 105
            (switch (global12)
                (case east
                    (send gNewAct:posn(359 152))
                )
                (case west
                    (send gNewAct:posn(-40 158))
                )
                (case south
                    (send gNewAct:posn(218 249))
                )
                (case north
                    (send gNewAct:posn(166 105))
                )
            )
            = global110 1
            (send (ScriptID(501 0)):notify(1))
        )
    )


    (method (doit)
        (super:doit())
        (if (<> global11 global13)
            return 
        )
        (if (((== global104 0) and (send gEgo:inRect(200 117 237 134))) and (== (send global2:script) 0))
            (self:setScript(egoDeath))
        )
        (if (((send global5:contains(gNewAct)) and (send gNewAct:inRect(200 117 237 134))) and (== (send global2:script) 0))
            (self:setScript(termDeath))
        )
        (if (IsObject((send gEgo:mover)))
            = theTheGGEgoX (send ((send gEgo:mover)):x)
            = local7 (send ((send gEgo:mover)):y)
            = local8 1
        )(else
            = local8 0
        )
        = local0 (send gEgo:onControl(0))
        (if (& local0 $0008)
            (send global2:newRoom(48))
        )(else
            (if ((== global116 2) and not (& local0 $0002))
                = global116 0
                (if (proc501_2(1))
                    (send gEgo:posn((send gEgo:x) (+ (send gEgo:y) 5)))
                )
            )(else
                (if ((== global116 4) and not (& local0 $0004))
                    = global116 0
                    (send gEgo:ignoreControl(4))
                )(else
                    (if ((((& local0 $0002) and (== global104 0)) and not global155) and not global116)
                        = global116 2
                        = global104 1
                        = gGEgoX (send gEgo:x)
                        = gGEgoY (send gEgo:y)
                        (if (local8)
                            (if (gGEgoY)
                                = gEgoY 400
                                = theGGEgoX gGEgoX
                            )(else
                                = gEgoY (+ (- (send gEgo:y) local7) (send gEgo:y))
                                = theGGEgoX theTheGGEgoX
                            )
                        )(else
                            = gEgoY (send gEgo:y)
                            = theGGEgoX (send gEgo:x)
                        )
                        (send gEgo:
                            view(82)
                            looper(ScriptID(501 1))
                            xStep(2)
                            yStep(1)
                            setMotion(MoveTo theGGEgoX gEgoY)
                            setPri(4)
                            ignoreControl(8192)
                        )
                    )(else
                        (if ((((& local0 $0002) and (== global104 1)) and not global155) and not global116)
                            = global104 0
                            = global116 2
                            (if (local8)
                                (if (gGEgoY)
                                    = gEgoY gGEgoY
                                    = theGGEgoX gGEgoX
                                )(else
                                    = gEgoY (+ (- (send gEgo:y) local7) (send gEgo:y))
                                    = theGGEgoX theTheGGEgoX
                                )
                            )(else
                                = gEgoY (send gEgo:y)
                                = theGGEgoX (send gEgo:x)
                            )
                            (send gEgo:
                                view(0)
                                xStep(3)
                                yStep(2)
                                looper(0)
                                setMotion(MoveTo theGGEgoX gEgoY)
                                setPri(-1)
                                observeControl(8192)
                                moveSpeed(0)
                            )
                        )(else
                            (if ((((== global104 1) and (& local0 $0004)) and not global155) and not global116)
                                = global116 4
                                = global104 2
                                (if (local8)
                                    (if (gGEgoY)
                                        = gEgoY gGEgoY
                                        = theGGEgoX gGEgoX
                                    )(else
                                        = gEgoY (+ (- (send gEgo:y) local7) (send gEgo:y))
                                        = theGGEgoX theTheGGEgoX
                                    )
                                )(else
                                    = gEgoY (send gEgo:y)
                                    = theGGEgoX (send gEgo:x)
                                )
                                (send gEgo:
                                    view(68)
                                    posn((send gEgo:x) - (send gEgo:y) 3)
                                    observeControl(4)
                                )
                                proc0_10()
                                (send gEgo:
                                    looper(0)
                                    setStep(1 1)
                                    setPri(4)
                                    ignoreControl(4096)
                                    setMotion(MoveTo theGGEgoX gEgoY)
                                )
                            )(else
                                (if ((((== global104 2) and (& local0 $0004)) and not global155) and not global116)
                                    = global116 4
                                    = global104 1
                                    (if (local8)
                                        (if (gGEgoY)
                                            = gEgoY -400
                                            = theGGEgoX gGEgoX
                                        )(else
                                            = gEgoY (+ (- (send gEgo:y) local7) (send gEgo:y))
                                            = theGGEgoX theTheGGEgoX
                                        )
                                    )(else
                                        = gEgoY (send gEgo:y)
                                        = theGGEgoX (send gEgo:x)
                                    )
                                    (send gEgo:
                                        view(82)
                                        posn((send gEgo:x) - (send gEgo:y) 3)
                                        observeControl(4)
                                    )
                                    proc0_10()
                                    (send gEgo:
                                        looper(ScriptID(501 1))
                                        xStep(2)
                                        yStep(1)
                                        setMotion(MoveTo theGGEgoX gEgoY)
                                        setPri(4)
                                        observeControl(4096)
                                        ignoreControl(8192)
                                    )
                                )(else
                                    (if ((((== global104 0) or (== global104 1)) and (== global116 0)) and (proc501_2(global109) or (< (send gEgo:y) 92)))
                                        = global104 1
                                        = gEgoY 180
                                        = theGGEgoX (send gEgo:x)
                                        (send gEgo:
                                            setPri(2)
                                            posn((send gEgo:x) + (send gEgo:y) 8)
                                        )
                                        proc0_10()
                                        (send gEgo:
                                            posn((send gEgo:x) + (send gEgo:y) 8)
                                            view(82)
                                            looper(ScriptID(501 1))
                                            xStep(2)
                                            yStep(1)
                                            setMotion(MoveTo theGGEgoX gEgoY)
                                            ignoreControl(8192)
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )


    (method (handleEvent pEvent)
        (var temp0[5])
        (if ((send pEvent:claimed))
            return 1
        )
        return 
            (switch ((send pEvent:type))
                (case 128
                    (if (Said('look,explore/android,debris,heap'))
                        (if ((send global5:contains(gNewView)))
                            proc255_0(Format(@global402 52 0 
                                    (if ((proc0_13(16 52) and (< (send gEgo:distanceTo(gNewView)) 60)) and (== global104 0))
                                        "Looking closely, you notice that the terminator's invisibility belt has survived relatively intact."
                                    )(else
                                        ""
                                    )
))
                        )(else
                            (if ((send global5:contains(gNewAct)))
                                proc255_0(52 1)
                            )(else
                                proc255_0(52 2)
                            )
                        )
                    )(else
                        (if (Said('look>'))
                            (if ((Said('/area') or Said('/around')) or Said('[<around][/!*]'))
                                proc255_0(52 3)
                            )(else
                                (if (Said('/chute'))
                                    proc255_0(52 4)
                                )(else
                                    (if (Said('/rock'))
                                        proc255_0(52 5)
                                    )(else
                                        (if (Said('/tongue'))
                                            proc255_0(52 6)
                                        )
                                    )
                                )
                            )
                        )(else
                            (if (Said('converse/chute'))
                                proc255_0(52 7)
                            )(else
                                (if (Said('beat,attack/chute'))
                                    proc255_0(52 8)
                                )(else
                                    (if (Said('get/chute'))
                                        proc255_0(52 9)
                                    )(else
                                        (if (Said('climb/'))
                                            proc255_0(52 10)
                                        )(else
                                            (if ((Said('get/belt/orat,stick') or Said('use/stick,orat')) or Said('get<use<(stick,orat)/belt'))
                                                (if ((send gEgo:has(16)))
                                                    proc255_0(52 11)
                                                )(else
                                                    (if (not proc0_13(16 52))
                                                        proc255_0(52 2)
                                                    )(else
                                                        (if (not (send gEgo:has(4)))
                                                            proc255_0(52 12)
                                                        )(else
                                                            (if (<> global110 3)
                                                                proc255_0(52 13)
                                                            )(else
                                                                (if (not (send gEgo:inRect(160 107 198 147)) or (<> global104 0))
                                                                    proc255_0(52 14)
                                                                )(else
                                                                    (send global2:setScript(ScriptID(520 0)))
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )(else
                                                (if (Said('get/belt/pole') or Said('use/pole'))
                                                    (if ((send gEgo:has(16)))
                                                        proc255_0(52 11)
                                                    )(else
                                                        (if (not proc0_13(16 52))
                                                            proc255_0(52 2)
                                                        )(else
                                                            (if (not (send gEgo:has(9)))
                                                                proc255_0(52 12)
                                                            )(else
                                                                (if (<> global110 3)
                                                                    proc255_0(52 13)
                                                                )(else
                                                                    (if (not (send gEgo:inRect(200 117 237 134)) and (<> global104 0))
                                                                        proc255_0(52 14)
                                                                    )(else
                                                                        (send global2:setScript(ScriptID(521 0)))
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )(else
                                                    (if (Said('get/belt'))
                                                        (if (proc0_13(16 52))
                                                            proc255_0(52 15)
                                                        )(else
                                                            proc255_0(52 2)
                                                        )
                                                    )(else
                                                        (if (Said('/ladder'))
                                                            proc0_9()
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )


    (method (newRoom newRoomNumber)
        (if (not global155)
            proc0_1()
            (if ((send global5:contains(gNewAct)) and (< (send gEgo:distanceTo(gNewAct)) 120))
                = global110 2
            )
            (super:newRoom(newRoomNumber))
        )
    )

)
(instance egoDeath of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = local3 0
                proc0_2()
                (if ((send global5:contains(gNewAct)))
                    (send (ScriptID(501)):notify(2))
                )
                = global116 9999
                (slurp:
                    number(82)
                    priority(3)
                    loop(1)
                    play()
                )
                (mouth:
                    view(78)
                    setLoop(1)
                    cel(255)
                    x((send gEgo:x))
                    setCycle(End self)
                )
            )
            (case 1
                (tongue:
                    view(78)
                    setLoop(2)
                    x((send gEgo:x))
                    show()
                )
                (send gEgo:
                    view(78)
                    setLoop(3)
                    setCycle(Fwd)
                    setPri(8)
                    ignoreActors()
                    illegalBits(0)
                    setMotion(MoveTo (send gEgo:x) 109 self)
                )
            )
            (case 2
                (tongue:setCel(1))
                (send gEgo:setMotion(MoveTo (send gEgo:x) 92 self))
            )
            (case 3
                (tongue:
                    view(777)
                    loop(0)
                )
                (send gEgo:setMotion(MoveTo (send gEgo:x) 78 self))
                = newAct (Act:new())
                (send newAct:
                    view(777)
                    loop(0)
                    init()
                )
            )
            (case 4
                (send gEgo:
                    view(777)
                    loop(0)
                )
                (mouth:
                    setLoop(4)
                    setCycle(Fwd)
                )
                (send newAct:
                    view(78)
                    setLoop(5)
                    ignoreActors()
                    illegalBits(0)
                    posn((send gEgo:x) 67)
                    setPri(8)
                    setStep(1 4)
                    setMotion(MoveTo (send gEgo:x) 129 self)
                )
                = local3 (+ local3 1)
            )
            (case 5
                (if (<= local3 6)
                    = state 3
                    = cycles 2
                )(else
                    (send newAct:dispose())
                    = cycles 1
                )
            )
            (case 6
                proc0_17(901 1 0 999)
            )
        )
    )

)
(instance termDeath of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gNewAct:
                    ignoreActors()
                    setMotion(0)
                )
                (mouth:
                    view(78)
                    setLoop(1)
                    cel(255)
                    x((send gNewAct:x))
                    setCycle(End self)
                )
            )
            (case 1
                (tongue:
                    view(78)
                    setLoop(2)
                    cel(0)
                    x((send gNewAct:x))
                )
                = gNewView (Act:new())
                (send gNewView:
                    view(78)
                    posn((send gNewAct:x) (send gNewAct:y))
                    setLoop(6)
                    setCycle(Fwd)
                    setPri(8)
                    ignoreActors()
                    illegalBits(0)
                    setMotion(MoveTo (send gNewAct:x) 109 self)
                    init()
                )
                (send (ScriptID(501)):notify(2))
            )
            (case 2
                (tongue:setCel(1))
                (send gNewView:setMotion(MoveTo (send gNewView:x) 92 self))
            )
            (case 3
                (tongue:
                    view(777)
                    loop(0)
                )
                (send gNewView:setMotion(MoveTo (send gNewView:x) 78 self))
            )
            (case 4
                (send gNewView:
                    view(777)
                    loop(0)
                )
                (mouth:
                    setLoop(7)
                    setCel(0)
                )
                = seconds 3
            )
            (case 5
                (mouth:setCel(1))
                = cycles 2
            )
            (case 6
                (if (>= (send gNewView:x) 230)
                    = theGGEgoX 230
                )(else
                    (if (<= (send gNewView:x) 208)
                        = theGGEgoX 208
                    )(else
                        = theGGEgoX (send gNewView:x)
                    )
                )
                (send gNewView:
                    view(78)
                    posn((send gNewView:x) 72)
                    setLoop(8)
                    setCel(0)
                    setStep(1 6)
                    setMotion(MoveTo theGGEgoX 125 self)
                )
            )
            (case 7
                (mouth:
                    view(777)
                    loop(0)
                )
                (send global1:changeScore(45))
                (send gNewView:
                    setCel(-1)
                    setPri(5)
                    setCycle(End self)
                )
            )
            (case 8
                proc0_3()
                = gNewView_2 (View:new())
                (send gNewView_2:
                    view(78)
                    loop(9)
                    cel(1)
                    setPri(6)
                    posn((send gNewView:x) + (send gNewView:y) 3)
                    init()
                )
                = global110 3
                = global117 52
                proc0_14(16 52)
                (send global2:setScript(0))
            )
        )
    )

)
