(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "Sound")
(use "Cycle")
(use "Game")
(use "InvI")
(use "PV")
(use "Obj")
(script 18)


(local
    newAct_2
    newAct_3
    newAct
    newProp
    local4
    local5
    local6
    local7
    local8

)
(instance zTheme of Sound
    (properties)
)
(instance door of Prop
    (properties)

    (method (cue)
        (self:ignoreActors())
        (send global2:newRoom(69))
    )

)
(instance public Room18 of Rm
    (properties
        picture 18
        horizon 85
        north 12
        south 24
        west 17
    )

    (method (init)
        = global101 0
        (if (global100)
            = picture 118
        )
        Load(rsVIEW 47)
        Load(rsVIEW 21)
        (send gEgo:
            edgeHit(0)
            observeControl(16384)
        )
        = global186 0
        (super:init())
        (self:setRegions(510 511))
        (if (global100)
            Load(rsVIEW 261)
            Load(rsVIEW 267)
            Load(rsVIEW 269)
            Load(rsVIEW 36)
            Load(rsVIEW 46)
            Load(rsVIEW 45)
            = newAct (Act:new())
            = newAct_2 (Act:new())
            = newAct_3 (Act:new())
            (send newAct:
                view(260)
                loop(0)
                cel(0)
                xStep(2)
                yStep(1)
                posn(25 157)
                setScript(z1Actions)
                init()
                hide()
            )
            (send newAct_2:
                view(266)
                loop(0)
                cel(0)
                xStep(2)
                yStep(1)
                posn(109 132)
                setScript(z4Actions)
                init()
                hide()
            )
            (send newAct_3:
                view(268)
                loop(0)
                cel(0)
                xStep(2)
                yStep(1)
                posn(220 166)
                setScript(z5Actions)
                init()
                hide()
            )
        )
        (if (== global174 2)
            (send gEgo:ignoreControl(16384))
            (door:
                posn(273 149)
                view(611)
                loop(0)
                cel(4)
                setPri(0)
                ignoreActors()
                init()
                stopUpd()
            )
        )(else
            (door:
                posn(273 149)
                view(611)
                loop(0)
                cel(0)
                setPri(0)
                init()
                stopUpd()
            )
        )
        (switch (gPicture)
            (case west
                ((send gEgo:posn(2 (send gEgo:y())))  )
            )
            (case north
                ((send gEgo:
                    x(45)
                    y(+ horizon (+ (send gEgo:yStep()) 1))
                )
  )
            )
            (case south
                ((send gEgo:posn(172 188))  )
            )
            (case 69
                ((send gEgo:
                    x(275)
                    y(153)
                    xStep(2)
                    yStep(1)
                    ignoreControl(16384)
                )
 (door:
                    posn(273 149)
                    view(611)
                    loop(0)
                    cel(4)
                    setPri(0)
                    ignoreActors()
                    init()
                    stopUpd()
                )
  )
            )
            (case 0
                ((send gEgo:
                    x(180)
                    y(188)
                )
 )
            )
        )
        = global105 0
        (send gEgo:
            view(2)
            init()
        )
        = local6 1
        (while (<= local6 global113)
            (if (== gNewPropX[(= local5 (* (- local6 1) 3))] gGNewPropX)
                (send ((View:new())):
                    view(528)
                    loop(0)
                    cel(6)
                    posn(gNewPropX[+ local5 1] gNewPropX[+ local5 2])
                    ignoreActors()
                    setPri(0)
                    addToPic()
                    ignoreActors()
                )
            )
            ++local6
        )
    )


    (method (doit)
        (super:doit())
        (if (& (send gEgo:onControl(0)) $4000)
            (send global2:newRoom(69))
        )
    )


    (method (dispose)
        (send gSounds:eachElementDo(172))
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed()))
            return 1
        )
        return 
            (if (== (send pEvent:type()) 128)
                (if (Said('climb/boulder'))
                    Print(18 0)
                )(else
                    (if (Said('open,enter/crypt'))
                        (if (== global174 2)
                            Print(18 1)
                        )(else
                            Print(18 2)
                        )
                    )(else
                        (if (Said('look>'))
                            (if (Said('/boulder'))
                                Print(18 3)
                            )(else
                                (if (Said('/grass'))
                                    Print(18 4)
                                )(else
                                    (if (Said('/crypt'))
                                        Print(18 5)
                                    )(else
                                        (if (Said('/cliff'))
                                            Print(18 6)
                                        )(else
                                            (if (Said('/gravestone'))
                                                Print(18 7)
                                            )(else
                                                (if (Said('/monument,lion'))
                                                    Print(18 8)
                                                )(else
                                                    (if (Said('/door'))
                                                        (if (== (door:cel()) 0)
                                                            Print(18 9)
                                                        )(else
                                                            Print(18 10)
                                                        )
                                                    )(else
                                                        (if (Said('/hole'))
                                                            = local7 1
                                                            (while (<= local7 global113)
                                                                (if ((== gNewPropX[(= local5 (* (- local7 1) 3))] 18) and (< (egoDist:doit(gNewPropX[(+ local5 1)] gNewPropX[(+ local5 2)])) 20))
                                                                    = local8 1
                                                                )
                                                                ++local7
                                                            )
                                                            (if (>= global113 0)
                                                                (if (local8)
                                                                    Print(18 11)
                                                                )(else
                                                                    Print(800 1)
                                                                )
                                                            )(else
                                                                Print(18 12)
                                                            )
                                                            = local8 0
                                                        )(else
                                                            (if (Said('[<around][/room]'))
                                                                Print(18 13)
                                                                Print(18 14)
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
                (if (Said('/door>'))
                    (if (Said('break'))
                        Print(18 15)
                    )(else
                        (if (Said('bang'))
                            (if ((send gEgo:inRect(262 149 292 157)))
                                Print(18 16)
                            )(else
                                Print(800 1)
                            )
                        )(else
                            (if (Said('open'))
                                (if ((send gEgo:inRect(262 149 292 157)))
                                    (if (== global174 1)
                                        (send ((Sound:new())):
                                            number(300)
                                            loop(1)
                                            play(door)
                                        )
                                        (send gEgo:
                                            setMotion(0)
                                            ignoreControl(16384)
                                        )
                                        proc0_10()
                                        = global174 2
                                        = global205 1
                                        (door:setCycle(End door))
                                    )(else
                                        (if (== global174 0)
                                            Print(18 17)
                                        )(else
                                            Print(18 18)
                                        )
                                    )
                                )(else
                                    Print(800 1)
                                )
                            )(else
                                (if (Said('close'))
                                    (if (== (door:cel()) 0)
                                        Print(18 19)
                                    )(else
                                        Print(18 20)
                                        (door:setCycle(Beg))
                                        (send gEgo:observeControl(16384))
                                        = global174 1
                                        (send ((Sound:new())):
                                            number(300)
                                            loop(1)
                                            priority(-1)
                                            play()
                                        )
                                    )
                                )(else
                                    (if (Said('latch'))
                                        (if ((send ((Inv:at(20))):ownedBy(gEgo)))
                                            (if ((send gEgo:inRect(262 149 292 157)))
                                                (if (== global174 1)
                                                    (if ((send ((Inv:at(4))):ownedBy(69)) and (== global109 99))
                                                        Print(18 21 166)
                                                        (send gGame:changeScore(2))
                                                        (send gEgo:put(20 18))
                                                        = global174 0
                                                        (send gEgo:observeControl(16384))
                                                    )(else
                                                        Print(18 22)
                                                        = global174 0
                                                    )
                                                )(else
                                                    (if (== global174 2)
                                                        Print(18 23)
                                                    )(else
                                                        (if (== global174 0)
                                                            Print(18 24)
                                                        )
                                                    )
                                                )
                                            )(else
                                                Print(800 1)
                                            )
                                        )(else
                                            Print(18 25)
                                        )
                                    )(else
                                        (if (Said('unlatch'))
                                            (if ((send gEgo:inRect(262 149 292 157)))
                                                (if (== global174 0)
                                                    (if ((send ((Inv:at(20))):ownedBy(gEgo)))
                                                        Print(18 26)
                                                        (if (not global187)
                                                            (send gGame:changeScore(3))
                                                            ++global187
                                                        )
                                                        = global174 1
                                                    )(else
                                                        Print(18 27)
                                                    )
                                                )(else
                                                    (if (== global174 2)
                                                        Print(18 28)
                                                    )(else
                                                        (if (== global174 1)
                                                            Print(18 29)
                                                        )
                                                    )
                                                )
                                            )(else
                                                Print(800 1)
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )(else
                    (if (Said('read,look/epitaph,gravestone,boulder'))
                        (if (& (send gEgo:onControl(0)) $0004)
                            Print(18 30 60 1 134 -1 15 140 290)
                        )(else
                            (if (& (send gEgo:onControl(0)) $0080)
                                Print(18 31 60 1 134 -1 15 140 290)
                            )(else
                                (if (& (send gEgo:onControl(0)) $0008)
                                    Print(18 32 60 1 134 -1 15 140 290)
                                )(else
                                    (if (& (send gEgo:onControl(0)) $0020)
                                        Print(18 33 60 1 134 -1 15 140 290)
                                    )(else
                                        (if (& (send gEgo:onControl(0)) $1000)
                                            Print(18 34 60 1 134 -1 15 140 290)
                                        )(else
                                            (if (& (send gEgo:onControl(0)) $0002)
                                                Print(18 35 60 1 134 -1 15 140 290)
                                            )(else
                                                (if (& (send gEgo:onControl(0)) $0010)
                                                    Print(18 36 60 1 134 -1 15 140 290)
                                                )(else
                                                    (if (& (send gEgo:onControl(0)) $0100)
                                                        Print(18 37 60 1 134 -1 15 140 290)
                                                    )(else
                                                        Print(800 1)
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )(else
                        (if (Said('dig[/hole,grave]'))
                            (if ((send gEgo:has(15)) and (== 0 (send ((Inv:at(15))):loop())))
                                (if (> global134 0)
                                    (if (& (send gEgo:onControl(0)) $7fff)
                                        (send gEgo:setScript(digging))
                                        (digging:changeState(1))
                                    )(else
                                        Print(18 38)
                                    )
                                )(else
                                    Print(18 39)
                                )
                            )(else
                                Print(18 40)
                            )
                        )
                    )
                )
            )(else
                0
            )
    )


    (method (newRoom param1)
        proc0_11()
        = global189 0
        (if (== (send gEgo:view()) 2)
            (super:newRoom(param1))
        )
    )

)
(instance z4Actions of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= seconds 4  )
            )
            (case 1
                (= global189 1 (zTheme:
                    number(20)
                    loop(-1)
                    play()
                )
 ++global186 (send newAct_2:
                    show()
                    setCycle(End self)
                )
 (send ((View:new())):
                    view(266)
                    posn((send newAct_2:x()) (send newAct_2:y()))
                    ignoreActors()
                    addToPic()
                )
  )
            )
            (case 2
                (
                (if (== global105 0)
                    (send newAct_2:
                        view(267)
                        setCycle(Walk)
                        setAvoider((Avoid:new()))
                        setMotion(Chase gEgo 12 self)
                    )
                )(else
                    (send newAct_2:
                        view(267)
                        setCycle(Walk)
                        setAvoider((Avoid:new()))
                        setMotion(Wander 50)
                    )
                )
 )
            )
            (case 3
                (
                (if ((send gEgo:has(7)))
                    (self:changeState(4))
                )(else
                    (if (== global105 0)
                        (self:changeState(10))
                    )
                )
 )
            )
            (case 4
                ((send newAct_2:
                    view(266)
                    cel(11)
                    setCycle(Beg self)
                )
 Print(18 41) 
                (if (== --global186 0)
                    (zTheme:dispose())
                )
 )
            )
            (case 5
                ((send newAct_2:
                    ignoreActors()
                    addToPic()
                )
  )
            )
            (case 10
                (proc0_10() = global105 17 (zTheme:dispose()) (zTheme:
                    number(21)
                    play()
                )
 (send gEgo:
                    view(36)
                    cel(0)
                    setCycle(End self)
                )
 
                (if ((send gCast:contains(newAct)))
                    (send newAct:setMotion(Wander))
                )
 
                (if ((send gCast:contains(newAct_3)))
                    (send newAct_3:setMotion(Wander))
                )
 (send newAct_2:setMotion(Wander))  )
            )
            (case 11
                ((send gEgo:
                    view(46)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 12
                (= global120 Print(18 42 134 -1 10 172) (send gEgo:
                    view(45)
                    setCycle(Walk)
                    setMotion(Wander)
                )
 = seconds 9  )
            )
            (case 13
                (proc0_23() (zTheme:dispose()) = global127 1 )
            )
        )
    )

)
(instance z5Actions of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= seconds 10  )
            )
            (case 1
                (++global186 (zTheme:
                    number(20)
                    loop(-1)
                    play()
                )
 (send newAct_3:
                    show()
                    setCycle(End self)
                )
 (send ((View:new())):
                    view(268)
                    cel(0)
                    posn((send newAct_3:x()) (send newAct_3:y()))
                    ignoreActors()
                    addToPic()
                )
  )
            )
            (case 2
                (
                (if (== global105 0)
                    (send newAct_3:
                        view(269)
                        setCycle(Walk)
                        setAvoider((Avoid:new()))
                        setMotion(Chase gEgo 12 self)
                    )
                )(else
                    (send newAct_3:
                        view(269)
                        setCycle(Walk)
                        setAvoider((Avoid:new()))
                        setMotion(Wander 50 self)
                    )
                )
 )
            )
            (case 3
                (
                (if ((send gEgo:has(7)))
                    (self:changeState(4))
                )(else
                    (if (== global105 0)
                        (self:changeState(10))
                    )
                )
 )
            )
            (case 4
                (Print(18 41) 
                (if (== --global186 0)
                    (zTheme:dispose())
                )
 (send newAct_3:
                    view(268)
                    cel(11)
                    setCycle(Beg self)
                )
  )
            )
            (case 5
                ((send newAct_3:
                    ignoreActors()
                    addToPic()
                )
  )
            )
            (case 10
                (proc0_10() = global105 17 (zTheme:dispose()) (zTheme:
                    number(21)
                    play()
                )
 (send gEgo:
                    view(36)
                    cel(0)
                    setMotion(0)
                    setCycle(End self)
                )
 (send newAct_3:setMotion(Wander)) 
                (if ((send gCast:contains(newAct)))
                    (send newAct:setMotion(Wander))
                )
 
                (if ((send gCast:contains(newAct_3)))
                    (send newAct_2:setMotion(Wander))
                )
 )
            )
            (case 11
                ((send gEgo:
                    view(46)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 12
                (= global120 Print(18 42 134 -1 10 172) (send gEgo:
                    view(45)
                    setCycle(Walk)
                    setMotion(Wander)
                )
 = seconds 9  )
            )
            (case 13
                (proc0_23() (zTheme:dispose()) = global127 1 )
            )
        )
    )

)
(instance holeActions of Script
    (properties)

    (method (cue)
        (var temp0)
        = temp0 (send newProp:cel())
        ++temp0
        (if (>= state 0)
            (send newProp:cel(temp0))
        )(else
            ++state
        )
    )

)
(instance digging of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 1
                (proc0_10() (send gEgo:
                    view(47)
                    loop(& (send gEgo:loop()) $0001)
                    cel(0)
                    setCycle(End self)
                )
 = newProp (Prop:new()) (send newProp:
                    posn(
                        (if (== (send gEgo:loop()) 1)
                            - (send gEgo:x()) 16
                        )(else
                            + (send gEgo:x()) 16
                        )
 + (send gEgo:y()) 4)
                    view(528)
                    cel(0)
                    setPri(0)
                    ignoreActors()
                    init()
                )
  )
            )
            (case 2
                ((send gEgo:
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 3
                (
                (if (>= global113 5)
                    Print(18 43)
                    (send gEgo:
                        view(2)
                        setCycle(Walk)
                    )
                    (send ((Inv:at(15))):loop(1))
                    (self:changeState(0))
                    proc0_11()
                )(else
                    (send gEgo:
                        cel(0)
                        setCycle(End self)
                    )
                )
 )
            )
            (case 4
                ((send gEgo:
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 5
                ((holeActions:cue()) 
                (if (< (send newProp:cel()) 6)
                    (self:changeState(2))
                )(else
                    (self:changeState(6))
                )
 )
            )
            (case 6
                (= gNewPropX[(= local5 (* (- ++global113 1) 3))] gGNewPropX = gNewPropX[(+ local5 1)] (send newProp:x()) = gNewPropX[(+ local5 2)] (send newProp:y()) (send gEgo:
                    view(2)
                    setCycle(Walk)
                )
 proc0_11() 
                (if (((& (send gEgo:onControl(0)) $0020) and (== global134 5)) and (send ((Inv:at(30))):ownedBy(88)))
                    (send newProp:
                        setLoop(1)
                        cel(4)
                    )
                    Print(18 44 166)
                    (send gEgo:setScript(getItems))
                    (send gEgo:get(30))
                    (getItems:changeState(1))
                    (send gGame:changeScore(3))
                )(else
                    (if (((& (send gEgo:onControl(0)) $0004) and (== global134 3)) and (send ((Inv:at(28))):ownedBy(88)))
                        (send newProp:
                            setLoop(1)
                            cel(0)
                        )
                        Print(18 45 166)
                        (send gEgo:setScript(getItems))
                        (getItems:changeState(1))
                        (send gEgo:get(28))
                        (send gGame:changeScore(3))
                    )(else
                        Print(18 46)
                    )
                )
 proc0_11() )
            )
        )
    )

)
(instance getItems of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 1
                (proc0_10() (send gEgo:
                    view(21)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 2
                ((send newProp:
                    setLoop(0)
                    cel(6)
                )
 = global182 1 (send gEgo:setCycle(Beg self))  )
            )
            (case 3
                ((send gEgo:
                    view(2)
                    setCycle(Walk)
                )
 Print(18 47) proc0_11() )
            )
        )
    )

)
(instance z1Actions of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= seconds 10  )
            )
            (case 1
                ((zTheme:
                    number(20)
                    loop(-1)
                    play()
                )
 = global189 1 (send newAct:
                    show()
                    setCycle(End self)
                )
 (send ((View:new())):
                    view(260)
                    posn((send newAct:x()) (send newAct:y()))
                    ignoreActors()
                    addToPic()
                )
 ++global186  )
            )
            (case 2
                (
                (if (== global105 0)
                    (send newAct:
                        view(261)
                        setCycle(Walk)
                        setAvoider((Avoid:new()))
                        setMotion(Chase gEgo 12 self)
                    )
                )(else
                    (send newAct:
                        view(261)
                        setCycle(Walk)
                        setAvoider((Avoid:new()))
                        setMotion(Wander 50)
                    )
                )
 )
            )
            (case 3
                (
                (if ((send gEgo:has(7)))
                    (self:changeState(4))
                )(else
                    (if (== global105 0)
                        (self:changeState(10))
                    )
                )
 )
            )
            (case 4
                (Print(18 41) 
                (if (== --global186 0)
                    (zTheme:dispose())
                )
 (send newAct:
                    setMotion(0)
                    view(260)
                    cel(11)
                    setCycle(Beg self)
                )
  )
            )
            (case 5
                ((send newAct:
                    ignoreActors()
                    addToPic()
                )
  )
            )
            (case 10
                (proc0_10() = global105 17 (zTheme:dispose()) (zTheme:
                    number(21)
                    play()
                )
 (send gEgo:
                    view(36)
                    cel(0)
                    setMotion(0)
                    setCycle(End self)
                )
 (send newAct:setMotion(Wander)) 
                (if ((send gCast:contains(newAct_3)))
                    (send newAct_3:setMotion(Wander))
                )
 
                (if ((send gCast:contains(newAct_2)))
                    (send newAct_2:setMotion(Wander))
                )
 )
            )
            (case 11
                ((send gEgo:
                    view(46)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 12
                (= global120 Print(18 42 134 -1 10 172) (send gEgo:
                    view(45)
                    setCycle(Walk)
                    setMotion(Wander)
                )
 = seconds 9  )
            )
            (case 13
                (proc0_23() (zTheme:dispose()) = global127 1 )
            )
        )
    )

)
(instance egoDist of Code
    (properties)

    (method (doit param1 param2)
        (var temp0)
        = temp0 Sqrt((+ (* Abs((- (send gEgo:y()) param2)) Abs((- (send gEgo:y()) param2))) (* Abs((- (send gEgo:x()) param1)) Abs((- (send gEgo:x()) param1)))))
    )

)
