(version 2)
(include "sci.sh")
(exports
    0 rm4
)
(use "Main")
(use "Class_255_0")
(use "NewFeature")
(use "StopWalk")
(use "Cycle")
(use "Game")
(use "User")
(use "PicView")
(use "Obj")
(script 4)


(local
    local0

)
(instance public rm4 of Rm
    (properties
        picture 4
        north 13
        east 3
        south 45
        west 5
    )

    (method (init)
        (if (>= global101 1)
            Load(rsVIEW 302)
        )
        Load(rsVIEW 1)
        (self:style(
            (switch (gGNumber)
                (case north
                    5
                )
                (case west
                    3
                )
                (case east
                    2
                )
                (case south
                    4
                )
            )
))
        (super:init())
        (switch (gGNumber)
            (case north
                (send gEgo:posn(proc0_17(220 (send gEgo:x) 92) 78))
                proc0_10(44)
            )
            (case south
                (send gEgo:posn(proc0_17(237 (send gEgo:x) 3) 188))
            )
            (case west
                (if (global130)
                    (send gEgo:y(proc0_17(158 (send gEgo:y) 100)))
                )(else
                    (if (< (send gEgo:y) 131)
                        (send gEgo:y(84))
                    )
                )
                (send gEgo:x(4))
            )
            (case east
                (send gEgo:posn(317 125))
            )
            (default 
                (send gEgo:posn(315 145))
            )
        )
        (send gEgo:init())
        (if (not global130)
            proc0_1()
        )
        (if (== gGNumber north)
            (send gEgo:setPri(3))
        )
        (self:setRegions(603))
        (lake1:init())
        (lake2:init())
        (lake3:init())
        (sand1:init())
        (sand2:init())
        (sand3:init())
        (sand4:init())
        (tree1:init())
        (tree2:init())
        (tree3:init())
        (if (>= global101 1)
            (fish:init())
        )
    )


    (method (doit)
        (var temp0)
        (if (proc999_5((send gEgo:onControl(1)) 2 4 8 16) and (<> (send gEgo:illegalBits) -24576))
            (send gEgo:illegalBits(-24576))
        )(else
            (if (not proc999_5((send gEgo:onControl(1)) 2 4 8 16) and (== (send gEgo:illegalBits) -24576))
                (send gEgo:illegalBits(-32768))
            )
        )
        (if (script and not global130)
            (send script:doit())
        )(else
            (if (not (send gEgo:script) and (& (send gEgo:onControl(1)) $0040))
                (send gEgo:setScript(climbBackHill))
            )(else
                (if ((& (send gEgo:onControl(1)) $2000) and (== gNewRoomNumber gNumber))
                    (send global2:setScript(slipIntoWater))
                )(else
                    = temp0 
                        (switch ((send ((User:alterEgo)):edgeHit))
                            (case 1
                                north
                            )
                            (case 2
                                east
                            )
                            (case 3
                                south
                            )
                            (case 4
                                west
                            )
                        )
                    (if (temp0)
                        proc0_11(44)
                        (send gEgo:
                            illegalBits(-32768)
                            priority(-1)
                        )
                        (self:newRoom(temp0))
                    )(else
                        (if ((((proc0_12(44) and (>= (send gEgo:x) 157)) and (>= (send gEgo:y) 95)) and (== (send gEgo:script) 0)) or (((& (send gEgo:onControl(1)) $0200) and not proc0_12(44)) and (== (send gEgo:script) 0)))
                            (send gEgo:setScript(climbHill))
                        )(else
                            (if ((((((not (& (send gEgo:onControl(1)) $4000) and (< (send gEgo:y) 108)) and (> (send gEgo:x) 119)) and (== (send gEgo:script) 0)) and not proc0_12(44)) and (<> (send gEgo:priority) 3)) and not (& (send gEgo:onControl(1)) $0010))
                                = local0 0
                                proc0_10(44)
                                (send gEgo:setPri(3))
                            )(else
                                (if ((((& (send gEgo:onControl(1)) $4000) and not proc0_12(44)) and (== (send gEgo:script) 0)) and (<> (send gEgo:priority) 7))
                                    = local0 0
                                    (send gEgo:setPri(7))
                                )(else
                                    (if ((not 
                                    (if (not (& (send gEgo:onControl(1)) $4000) and (< (send gEgo:y) 108))
                                        (> (send gEgo:x) 119)
                                    )
 and not (& (send gEgo:onControl(1)) $4000)) and (<> local0 1))
                                        = local0 1
                                        proc0_11(44)
                                        (send gEgo:setPri(-1))
                                    )(else
                                        (if (script)
                                            (send script:doit())
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if ((super:handleEvent(pEvent)))
                return 
            )(else
                (if (Said('look,look>'))
                    (if (Said('[<at,around][/room,grass]'))
                        proc255_0(4 0)
                    )(else
                        (if (Said('<down'))
                            (if (& (send gEgo:onControl(1)) $0100)
                                proc255_0(4 1)
                            )(else
                                proc255_0(4 2)
                            )
                        )(else
                            (if (Said('/water,bank,bank'))
                                proc255_0(4 3)
                            )(else
                                (if (Said('[<at]/beach'))
                                    proc255_0(4 4)
                                )(else
                                    (if (Said('/boulder'))
                                        proc255_0(4 5)
                                    )(else
                                        (if (Said('/pebble'))
                                            (if ((send gEgo:has(9)))
                                                (send pEvent:claimed(0))
                                            )(else
                                                (if (& (send gEgo:onControl(1)) $0100)
                                                    proc255_0(4 1)
                                                )(else
                                                    proc255_0(4 6)
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )(else
                    (if (Said('get,get/boulder'))
                        proc255_0(4 7)
                    )(else
                        (if (Said('get,get/pebble'))
                            (if (not & (send gEgo:onControl(1)) $0100)
                                proc255_0(4 8)
                            )(else
                                (if (== global140 5)
                                    proc255_0(4 9)
                                )(else
                                    (if (proc0_12(1))
                                        proc255_0(4 10)
                                    )(else
                                        (send gEgo:setScript(getPebbles))
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )

)
(instance getPebbles of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:
                    view(1)
                    setMotion(0)
                    setCycle(End self)
                )
            )
            (case 1
                proc0_19(91 1)
                (send (ScriptID(0 21)):
                    number(105)
                    loop(1)
                    init()
                    play()
                )
                (switch (global140)
                    (case 0
                        (send gEgo:get(9))
                        proc255_0(4 11)
                    )
                    (case 4
                        proc255_0(4 12)
                    )
                    (default 
                        proc255_0(4 13)
                    )
                )
                = global140 6
                proc0_27()
                = cycles 4
            )
            (case 2
                (send gEgo:setCycle(Beg self))
            )
            (case 3
                proc0_1()
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance climbHill of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (if (not proc0_12(44))
                    (send gEgo:
                        illegalBits(0)
                        setLoop(3)
                        setPri(3)
                        setMotion(MoveTo (send gEgo:x) 94 self)
                    )
                )(else
                    (send gEgo:
                        illegalBits(0)
                        setLoop(2)
                        setMotion(MoveTo 216 84 self)
                    )
                )
            )
            (case 1
                (if (proc0_12(44))
                    proc0_11(44)
                    (send gEgo:
                        setPri(7)
                        setMotion(MoveTo 217 89 self)
                    )
                )(else
                    proc0_10(44)
                    = cycles 1
                )
            )
            (case 2
                proc0_3()
                (send gEgo:
                    setLoop(-1)
                    illegalBits(-32768)
                )
                (self:dispose())
            )
        )
    )

)
(instance climbBackHill of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:
                    illegalBits(0)
                    setLoop(3)
                    setPri(1)
                    setMotion(MoveTo (send gEgo:x) + (send gEgo:y) 5 self)
                )
            )
            (case 1
                proc0_1()
                proc0_3()
                (send global2:newRoom((send global2:north)))
                (self:dispose())
            )
        )
    )

)
(instance slipIntoWater of Script
    (properties)

    (method (doit param1)
        (super:doit(rest param1))
        (if (== state 0)
            (if (& (send gEgo:onControl(1)) $0002)
                (self:changeState(1))
            )(else
                (if (< (send gEgo:yStep) 9)
                    (send gEgo:setStep(-1 (+ (send gEgo:yStep) 2)))
                )
            )
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gEgo:
                    setCycle(0)
                    ignoreActors()
                    setMotion(MoveTo - (send gEgo:x) 200 + (send gEgo:y) 140)
                    setStep(6 4)
                )
                (if (proc0_12(1))
                    proc255_0(4 14)
                    (send gGame:changeScore(-3))
                )
            )
            (case 1
                (send gEgo:
                    posn(- (send gEgo:x) 2 (send gEgo:y))
                    setCycle(StopWalk 2)
                    setStep(3 2)
                    ignoreActors(0)
                    setMotion(0)
                )
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance fishJump of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (fish:
                    posn(Random(10 125) Random(110 140))
                    loop(Random(0 1))
                    setCycle(End self)
                )
            )
            (case 1
                (fish:stopUpd())
                (self:dispose())
            )
        )
    )

)
(instance fish of Prop
    (properties
        view 302
    )

    (method (init)
        (self:
            cycleSpeed(
                (if (>= global101 1)
                    1
                )(else
                    0
                )
)
            ignoreActors()
            stopUpd()
        )
        (super:init())
    )


    (method (doit)
        (super:doit())
        (if (((< Random(1 100) 3) and not (fish:script)) and not global130)
            (fish:setScript(fishJump))
        )
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if ((super:handleEvent(pEvent)))
                return 
            )(else
                (if (Said('look,look/fish'))
                    (self:doVerb(1))
                )(else
                    (if (Said('get,get,capture/fish'))
                        (self:doVerb(7))
                    )
                )
            )
        )
    )


    (method (doVerb theVerb)
        (switch (theVerb)
            (case 1
                (if ((fish:script))
                    proc255_0(4 15)
                )(else
                    proc255_0(4 16)
                )
            )
            (case 7
                proc255_0(4 17)
            )
        )
    )

)
(instance lake1 of NewFeature
    (properties
        x 81
        y 104
        noun 3706
        nsTop 91
        nsBottom 118
        nsRight 163
        description 3811
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        lookStr 3816
    )
)
(instance lake2 of NewFeature
    (properties
        x 85
        y 139
        noun 3706
        nsTop 118
        nsBottom 161
        nsRight 171
        description 3811
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        lookStr 3816
    )
)
(instance lake3 of NewFeature
    (properties
        x 190
        y 135
        noun 3706
        nsTop 122
        nsLeft 170
        nsBottom 149
        nsRight 211
        description 3902
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        lookStr 3816
    )
)
(instance sand1 of NewFeature
    (properties
        x 125
        y 169
        noun 3729
        nsTop 166
        nsLeft 56
        nsBottom 172
        nsRight 195
        description 3908
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 3913
    )
)
(instance sand2 of NewFeature
    (properties
        x 176
        y 164
        noun 3729
        nsTop 162
        nsLeft 155
        nsBottom 166
        nsRight 198
        description 3908
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 3913
    )
)
(instance sand3 of NewFeature
    (properties
        x 188
        y 158
        noun 3729
        nsTop 154
        nsLeft 172
        nsBottom 162
        nsRight 204
        description 3908
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 3913
    )
)
(instance sand4 of NewFeature
    (properties
        x 150
        y 176
        noun 3729
        nsTop 172
        nsLeft 118
        nsBottom 180
        nsRight 183
        description 3908
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 3913
    )
)
(instance tree1 of NewFeature
    (properties
        x 159
        y 34
        noun 3736
        nsTop -1
        nsBottom 69
        nsRight 319
        description 3975
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 3980
    )
)
(instance tree2 of NewFeature
    (properties
        x 178
        y 82
        noun 3736
        nsTop 69
        nsLeft 160
        nsBottom 95
        nsRight 196
        description 3975
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 3980
    )
)
(instance tree3 of NewFeature
    (properties
        x 289
        y 129
        noun 3736
        nsTop 69
        nsLeft 259
        nsBottom 189
        nsRight 320
        description 3975
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 3980
    )
)
