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


(local
    local0
    local1

)
(class GhostWander of Motion
    (properties
        client 0
        caller 0
        x 0
        y 0
        dx 0
        dy 0
        {b-moveCnt} 0
        {b-i1} 0
        {b-i2} 0
        {b-di} 0
        {b-xAxis} 0
        {b-incr} 0
        sel_255 0
        sel_256 0
        sel_257 0
        sel_258 0
    )

    (method (init param1 theSel_255 theSel_256 theSel_257 theSel_258)
        (var theSel_255_2, theSel_256_2)
        = sel_255 theSel_255
        = sel_256 theSel_256
        = sel_257 theSel_257
        = sel_258 theSel_258
        (switch (/ Random(10 29) 10)
            (case 1
                (= theSel_255_2 sel_255  )
            )
            (case 2
                (= theSel_255_2 sel_257 )
            )
        )
        (switch (/ Random(10 29) 10)
            (case 1
                (= theSel_256_2 sel_256  )
            )
            (case 2
                (= theSel_256_2 sel_258 )
            )
        )
        (super:init(param1 theSel_255_2 theSel_256_2))
        (super:doit())
    )


    (method (doit)
        (super:doit())
        (if ((send client:isStopped()))
            (self:moveDone())
        )
    )


    (method (moveDone)
        (self:init(client sel_255 sel_256 sel_257 sel_258))
    )

)
(instance theGhost of Act
    (properties)
)
(instance public regHauntedHouse of Rgn
    (properties)

    (method (init)
        (if (initialized)
            return 
        )
        = global189 (= keep 1)
        (super:init())
        (if (global100)
            (theGhost:
                view(201)
                illegalBits(0)
                ignoreActors(1)
                posn(999 999)
                init()
            )
            (if (not global134)
                = global134 1
            )
            (self:notify(global134))
        )
        (miserGhostMusic:init())
        (ladyGhostMusic:init())
        (lordGhostMusic:init())
        (boyGhostMusic:init())
    )


    (method (dispose)
        (if (== keep 0)
            = global189 0
            (super:dispose())
        )
    )


    (method (newRoom param1)
        (miserGhostMusic:dispose())
        (ladyGhostMusic:dispose())
        (lordGhostMusic:dispose())
        (boyGhostMusic:dispose())
        (if (IsObject(script))
            (send script:cue(65534 param1))
        )
        = global135 0
        (if (== param1 17)
            proc0_11()
            (lordGhostMusic:keep(0))
            (miserGhostMusic:keep(0))
            (ladyGhostMusic:keep(0))
            (boyGhostMusic:keep(0))
            (send gSounds:eachElementDo(172))
        )
        (super:newRoom(param1))
    )


    (method (notify param1 param2)
        (if (script and not paramTotal)
            (send script:cue())
        )(else
            (if (script and (< param1 0))
                (send script:cue(param1 rest param2))
            )(else
                (self:setScript(
                    (switch ((= global134 param1))
                        (case 1
                            babyScript
                        )
                        (case 2
                            miserScript
                        )
                        (case 3
                            ladyScript
                        )
                        (case 4
                            lordScript
                        )
                        (case 5
                            boyScript
                        )
                        (default 
                            0
                        )
                    )
))
            )
        )
    )

)
(instance babyScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= global133 59 = seconds 5  )
            )
            (case 1
                (Print(603 0) = seconds 10  )
            )
            (case 2
                (
                (if ((((<> gGNewPropX 61) and (<> gGNewPropX 66)) and (<> gGNewPropX 59)) and (<> gGNewPropX 58))
                    Print(603 1)
                )
 --state = seconds Random(10 30) )
            )
        )
    )


    (method (cue)
        (if (not paramTotal)
            (super:cue())
        )
    )

)
(instance miserScript of Script
    (properties)

    (method (changeState newState)
        (var temp0, temp1, temp2)
        (switch (= state newState)
            (case 0
                (Load(rsVIEW 200) Load(rsVIEW 201) = global133 164 = local0 1 = seconds Random(5 10)  )
            )
            (case 1
                (Print(603 2) = cycles 5  )
            )
            (case 2
                (= seconds 3  )
            )
            (case 3
                (
                (if (((<> gGNewPropX 66) and (<> gGNewPropX 61)) and (<> gGNewPropX 58))
                    Print(603 3)
                )
 --state = seconds Random(40 99)  )
            )
            (case 4
                (= seconds 0 = global135 1 (miserGhostMusic:
                    loop(1)
                    play()
                )
 
                (switch (global133)
                    (case 67
                        (= temp1 145  )
                    )
                    (case 68
                        (= temp1 180  )
                    )
                    (case 64
                        (= temp1 145 )
                    )
                )
 
                (switch (local0)
                    (case 0
                        (= temp0 65503  )
                    )
                    (case 1
                        (= temp0 333 )
                    )
                )
 
                (switch (local0)
                    (case 0
                        (= temp2 333  )
                    )
                    (case 1
                        (= temp2 65503 )
                    )
                )
 (theGhost:
                    view(201)
                    illegalBits(0)
                    posn(temp0 temp1)
                    ignoreActors(1)
                    init()
                    setLoop(local0)
                    setCycle(Walk)
                    setMotion(MoveTo temp2 temp1)
                )
  )
            )
            (case 5
                (proc0_10() Print(603 4) (send gEgo:put(13 -1)) (send gGame:changeScore(2)) (theGhost:
                    setLoop()
                    setMotion(0)
                )
 = seconds 2  )
            )
            (case 6
                ((theGhost:
                    view(200)
                    cycleSpeed(1)
                    setCel(255)
                    setCycle(Beg self)
                )
  )
            )
            (case 7
                (proc0_11() (regHauntedHouse:notify(3)) )
            )
        )
    )


    (method (cue param1)
        (if (not paramTotal)
            (super:cue())
        )(else
            (if (== param1 -1)
                = seconds 0
                (self:changeState(
                    (if (< state 4)
                        4
                    )(else
                        (if (< state 5)
                            5
                        )
                    )
))
            )(else
                (if (== param1 65534)
                    (switch (global133)
                        (case 164
                            = global133 64
                            = local0 1
                        )
                        (case 64
                            (if (== local0 1)
                                = global133 68
                            )(else
                                = global133 164
                            )
                        )
                        (case 68
                            (if (== local0 1)
                                = global133 67
                            )(else
                                = global133 64
                            )
                        )
                        (case 67
                            (if (== local0 1)
                                = global133 167
                            )(else
                                = global133 68
                            )
                        )
                        (case 167
                            = global133 67
                            = local0 0
                        )
                    )
                    (if (< state 5)
                        (self:changeState(2))
                    )
                )
            )
        )
    )


    (method (handleEvent pEvent)
        (var gInvSaidMe)
        (if ((((send pEvent:claimed()) or (<> (send pEvent:type()) 128)) or (<> gGNewPropX global133)) or not (send gCast:contains(theGhost)))
            return 
        )
        (if (Said('look/chain'))
            Print(603 5)
        )(else
            (if (Said('get/chain'))
                Print(603 6)
            )(else
                (if (Said('deliver>'))
                    (if (not (= gInvSaidMe (send gInv:saidMe())) or not (send gEgo:has((send gInv:indexOf(gInvSaidMe)))))
                        (send pEvent:claimed(0))
                    )(else
                        (if (> (send gEgo:distanceTo(theGhost)) 30)
                            proc0_15()
                        )(else
                            (if (<> (send gInv:indexOf(gInvSaidMe)) 13)
                                Print(603 7)
                            )(else
                                (self:cue(-1))
                            )
                        )
                    )
                )(else
                    (if (Said('converse'))
                        Print(603 8)
                    )(else
                        (if (Said('look'))
                            Print(603 9)
                        )(else
                            (if (Said('kiss'))
                                Print(603 10)
                            )(else
                                (if (Said('capture,get'))
                                    Print(603 11)
                                )(else
                                    (if (Said('kill'))
                                        Print(603 12)
                                    )(else
                                        (if (Said('help'))
                                            Print(603 13)
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )

)
(instance ladyScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((theGhost:posn((theGhost:x()) (+ (theGhost:y()) 1000))) Load(rsVIEW 202) Load(rsVIEW 203) = global133 60 = seconds 3  )
            )
            (case 1
                (Print(603 14) = seconds Random(10 30)  )
            )
            (case 2
                (= seconds 3  )
            )
            (case 3
                (
                (if ((((<> gGNewPropX 66) and (<> gGNewPropX 61)) and (<> gGNewPropX 58)) and (<> gGNewPropX 60))
                    Print(603 15)
                )
 --state = seconds Random(50 99)  )
            )
            (case 4
                (= global135 1 = seconds 3  )
            )
            (case 5
                ((ladyGhostMusic:
                    loop(1)
                    play()
                )
 (theGhost:
                    view(202)
                    posn(85 133)
                    ignoreActors(1)
                    cycleSpeed(3)
                    loop(0)
                    cel(0)
                    setCycle(End self)
                    init()
                )
  )
            )
            (case 6
                ((theGhost:
                    view(203)
                    setCycle(Fwd)
                )
  )
            )
            (case 7
                (proc0_10() (theGhost:
                    view(202)
                    loop(0)
                    setCel(255)
                    setCycle(Beg self)
                )
  )
            )
            (case 8
                (proc0_11() = global133 67 (regHauntedHouse:notify(4)) )
            )
        )
    )


    (method (cue param1)
        (if (not paramTotal)
            (super:cue())
        )(else
            (if (== param1 -1)
                = seconds 0
                (self:changeState(
                    (if (< state 4)
                        4
                    )(else
                        (if (< state 7)
                            7
                        )
                    )
))
            )(else
                (if ((== param1 65534) and (< state 7))
                    (self:changeState(2))
                )
            )
        )
    )

)
(instance lordScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((theGhost:posn((theGhost:x()) (+ (theGhost:y()) 1000))) Load(rsVIEW 204) Load(rsVIEW 206) = seconds 3  )
            )
            (case 1
                (Print(603 16) = seconds Random(3 5)  )
            )
            (case 2
                (= seconds 3  )
            )
            (case 3
                (
                (if (((<> gGNewPropX 66) and (<> gGNewPropX 61)) and (<> gGNewPropX 58))
                    Print(603 17)
                )
 --state = seconds Random(40 99)  )
            )
            (case 4
                (= global135 1 = seconds Random(2 5)  )
            )
            (case 5
                (= seconds 0 (lordGhostMusic:
                    loop(1)
                    play()
                )
 (theGhost:
                    view(204)
                    cel(0)
                    posn(150 160)
                    illegalBits(0)
                    cycleSpeed(1)
                    ignoreActors(1)
                    setStep(4 2)
                    setCycle(End self)
                    init()
                )
  )
            )
            (case 6
                ((theGhost:
                    view(206)
                    loop(Random(0 3))
                    moveSpeed(1)
                    cycleSpeed(1)
                    setLoop(-1)
                    setCycle(Walk)
                )
 
                (if (== gGNewPropX 68)
                    (theGhost:setMotion(GhostWander 78 156 225 185))
                )(else
                    (theGhost:setMotion(GhostWander 75 130 225 175))
                )
 = seconds Random(13 30)  )
            )
            (case 7
                ((theGhost:
                    view(204)
                    loop(0)
                    setCel(255)
                    setCycle(Beg self)
                )
  )
            )
            (case 8
                (= state 4 = seconds Random(20 99)  )
            )
            (case 9
                (proc0_10() Print(603 18) (theGhost:setMotion(0)) = seconds 3  )
            )
            (case 10
                (= seconds 0 (send gEgo:put(29 -1)) (send gGame:changeScore(2)) (theGhost:
                    view(204)
                    loop(0)
                    setCel(255)
                    setCycle(Beg self)
                )
  )
            )
            (case 11
                ((regHauntedHouse:notify(5)) )
            )
        )
    )


    (method (cue param1 param2)
        (if (not paramTotal)
            (super:cue())
        )(else
            (if (== param1 -1)
                = seconds 0
                (self:changeState(
                    (if (< state 4)
                        4
                    )(else
                        (if (< state 9)
                            9
                        )
                    )
))
            )(else
                (if (== param1 65534)
                    = global133 
                        (if ((((<= 64 param2) and (<= param2 68)) and (<> param2 66)) and Random(0 1))
                            param2
                        )(else
                            0
                        )
                    (self:changeState(2))
                )
            )
        )
    )


    (method (handleEvent pEvent)
        (var gInvSaidMe)
        (if ((((send pEvent:claimed()) or (<> (send pEvent:type()) 128)) or (<> gGNewPropX global133)) or not global135)
            return 
        )
        (if (Said('deliver>'))
            (if (not (= gInvSaidMe (send gInv:saidMe())) or not (send gEgo:has((send gInv:indexOf(gInvSaidMe)))))
                (send pEvent:claimed(0))
            )(else
                (if (> (send gEgo:distanceTo(theGhost)) 30)
                    proc0_15()
                )(else
                    (if (<> (send gInv:indexOf(gInvSaidMe)) 29)
                        Print(603 19)
                    )(else
                        (self:changeState(9))
                    )
                )
            )
        )(else
            (if (Said('converse'))
                Print(603 20)
            )(else
                (if (Said('look'))
                    Print(603 21)
                )(else
                    (if (Said('kiss'))
                        Print(603 10)
                    )(else
                        (if (Said('get,capture/*'))
                            Print(603 22)
                        )(else
                            (if (Said('kill/*'))
                                Print(603 12)
                            )(else
                                (if (Said('help/*'))
                                    Print(603 23)
                                )
                            )
                        )
                    )
                )
            )
        )
    )

)
(instance boyScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= seconds 2  )
            )
            (case 1
                ((theGhost:posn((theGhost:x()) (+ (theGhost:y()) 1000))) Load(rsVIEW 207) Load(rsVIEW 208) = global134 5 = seconds 2  )
            )
            (case 2
                (proc0_11() (boyGhostMusic:dispose()) 
                (if (== gGNewPropX 60)
                    = global135 1
                    = cycles 1
                )(else
                    (if (((<> gGNewPropX 66) and (<> gGNewPropX 61)) and (<> gGNewPropX 58))
                        = global135 1
                        = seconds Random(1 3)
                    )
                )
 )
            )
            (case 3
                ((boyGhostMusic:
                    loop(1)
                    play()
                )
 (theGhost:
                    view(207)
                    illegalBits(0)
                    ignoreActors(1)
                    setPri(-1)
                    loop(0)
                    cel(0)
                    setCycle(End self)
                    posn(
                        (switch (gGNewPropX)
                            (case 60
                                (159  )
                            )
                            (case 64
                                (83  )
                            )
                            (case 65
                                (255  )
                            )
                            (case 67
                                (239  )
                            )
                            (case 68
                                (165 )
                            )
                        )
 
                        (switch (gGNewPropX)
                            (case 60
                                (136  )
                            )
                            (case 64
                                (124  )
                            )
                            (case 65
                                (148  )
                            )
                            (case 67
                                (136  )
                            )
                            (case 68
                                (83 )
                            )
                        )
)
                    init()
                )
 
                (if (== gGNewPropX 60)
                    (theGhost:setPri(10))
                )
 )
            )
            (case 4
                (
                (if (== local1 0)
                    = local1 1
                    Print(603 24)
                )(else
                    Print(603 25)
                )
 (theGhost:
                    view(208)
                    moveSpeed(0)
                    cycleSpeed(0)
                    setLoop(-1)
                    setCycle(Walk)
                )
 
                (switch (gGNewPropX)
                    (case 60
                        ((theGhost:
                            setPri(10)
                            setCycle(Fwd)
                            setMotion(MoveTo 158 15)
                        )
 = global133 63  )
                    )
                    (case 64
                        ((theGhost:
                            setPri(9)
                            setMotion(MoveTo 0 143 self)
                        )
 = global133 68  )
                    )
                    (case 65
                        ((theGhost:setMotion(MoveTo 240 190 self)) = global133 64  )
                    )
                    (case 67
                        ((theGhost:setMotion(MoveTo 300 136 self)) = global133 68  )
                    )
                    (case 68
                        ((theGhost:setMotion(MoveTo 193 73 self)) = global133 60 )
                    )
                )
  )
            )
            (case 5
                ((theGhost:
                    view(207)
                    loop(0)
                    setCel(255)
                    setCycle(Beg self)
                )
  )
            )
            (case 6
                (= global135 0 (theGhost:posn((theGhost:x()) (+ (theGhost:y()) 1000)))  )
            )
            (case 11
                (= global135 1 Load(rsVIEW 209) (boyGhostMusic:
                    loop(1)
                    play()
                )
 (theGhost:
                    view(207)
                    loop(1)
                    cel(0)
                    posn(167 117)
                    setPri(8)
                    cycleSpeed(1)
                    setCycle(End self)
                    init()
                )
  )
            )
            (case 12
                ((theGhost:
                    view(209)
                    loop(Random(0 3))
                    cycleSpeed(1)
                    setCycle(Fwd)
                )
 = seconds 5  )
            )
            (case 13
                (
                (if (== gGNewPropX 63)
                    Print(603 26)
                )
 = seconds 3  )
            )
            (case 14
                ((theGhost:loop(Random(0 3))) --state = cycles Random(30 60)  )
            )
            (case 21
                (proc0_10() Print(603 27) (send gEgo:put(30 -1)) (send gGame:changeScore(2)) = seconds 2  )
            )
            (case 22
                (= global134 255 (theGhost:
                    view(207)
                    loop(1)
                    setCel(255)
                    setCycle(Beg self)
                    init()
                )
  )
            )
            (case 23
                (proc0_11() (theGhost:dispose()) (regHauntedHouse:notify(255)) )
            )
        )
    )


    (method (cue param1)
        (if (not paramTotal)
            (super:cue())
        )(else
            (if (== param1 -1)
                = seconds 0
                (self:changeState(
                    (if (== gGNewPropX 63)
                        11
                    )(else
                        (if (< state 11)
                            2
                        )
                    )
))
            )
        )
    )


    (method (handleEvent pEvent)
        (var gInvSaidMe)
        (if ((((send pEvent:claimed()) or (<> (send pEvent:type()) 128)) or (<> gGNewPropX global133)) or not global135)
            return 
        )
        (if (Said('deliver>'))
            (if (not (= gInvSaidMe (send gInv:saidMe())) or not (send gEgo:has((send gInv:indexOf(gInvSaidMe)))))
                (send pEvent:claimed(0))
            )(else
                (if (> (send gEgo:distanceTo(theGhost)) 30)
                    proc0_15()
                )(else
                    (if (<> (send gInv:indexOf(gInvSaidMe)) 30)
                        Print(603 28)
                    )(else
                        (if (<> gGNewPropX 63)
                            Print(603 29)
                        )(else
                            (self:changeState(21))
                        )
                    )
                )
            )
        )(else
            (if (Said('converse'))
                Print(603 30)
            )(else
                (if (Said('kiss'))
                    Print(603 10)
                )(else
                    (if (Said('look/ghost[<boy]'))
                        (if (== gGNewPropX 63)
                            Print(603 31)
                        )(else
                            Print(603 32)
                        )
                    )(else
                        (if (Said('play/ghost[<boy]'))
                            Print(603 33)
                        )(else
                            (if (Said('capture,get/ghost[<boy]'))
                                Print(603 11)
                            )(else
                                (if (Said('kill/*'))
                                    Print(603 12)
                                )(else
                                    (if (Said('help,,/*'))
                                        Print(603 34)
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )

)
(instance lordGhostMusic of Sound
    (properties
        number 25
        keep 1
    )
)
(instance miserGhostMusic of Sound
    (properties
        number 23
        keep 1
    )
)
(instance ladyGhostMusic of Sound
    (properties
        number 24
        keep 1
    )
)
(instance boyGhostMusic of Sound
    (properties
        number 26
        keep 1
    )
)
