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


(local
    local0
    local1
    local2
    local3
    local4
    local5
    local6
    local7
    local8
    local9
    local10
    local11[35]

)
(instance public rm30 of Rm
    (properties
        picture 30
        horizon 80
        north 35
        east 31
        south 19
        west 29
    )

    (method (init)
        (var temp0, temp1)
        (asm
            pushi   31
            pushi   1
            lsg     gGNumber
            dup     
            pToa    north
            eq?     
            bnt     code_001f
            ldi     5
            jmp     code_0040
code_001f:  dup     
            pToa    west
            eq?     
            bnt     code_002b
            ldi     3
            jmp     code_0040
code_002b:  dup     
            pToa    east
            eq?     
            bnt     code_0037
            ldi     2
            jmp     code_0040
code_0037:  dup     
            pToa    south
            eq?     
            bnt     code_0040
            ldi     4
code_0040:  toss    
            push    
            self    6
            lsg     global101
            ldi     1
            ge?     
            bnt     code_0056
            pushi   2
            pushi   128
            pushi   205
            callk   Load, 4
code_0056:  pushi   2
            pushi   128
            pushi   230
            callk   Load, 4
            pushi   #has
            pushi   1
            pushi   18
            lag     gEgo
            send    6
            not     
            bnt     code_0076
            pushi   2
            pushi   128
            pushi   1
            callk   Load, 4
code_0076:  pushi   #init
            pushi   0
            super   Rm, 4
            lsg     gGNumber
            dup     
            pToa    north
            eq?     
            bnt     code_00b5
            pushi   225
            pushi   #{-info-}
            pushi   3
            pushi   319
            pushi   3
            pushi   272
            pushi   #x
            pushi   0
            lag     gEgo
            send    4
            push    
            pushi   248
            callb   proc0_18, 6
            push    
            pushi   41
            callb   proc0_17, 6
            push    
            pTos    horizon
            ldi     2
            add     
            push    
            lag     gEgo
            send    8
            jmp     code_0142
code_00b5:  dup     
            pToa    south
            eq?     
            bnt     code_00c9
            pushi   #y
            pushi   1
            pushi   188
            lag     gEgo
            send    6
            jmp     code_0142
code_00c9:  dup     
            pToa    west
            eq?     
            bnt     code_00fe
            pushi   225
            pushi   #{-info-}
            pushi   3
            dup     
            pushi   188
            pushi   3
            pushi   130
            pushi   #y
            pushi   0
            lag     gEgo
            send    4
            push    
            pushi   125
            callb   proc0_18, 6
            push    
            pTos    horizon
            ldi     2
            add     
            push    
            callb   proc0_17, 6
            push    
            lag     gEgo
            send    8
            jmp     code_0142
code_00fe:  dup     
            pToa    east
            eq?     
            bnt     code_0135
            pushi   225
            pushi   #{-info-}
            pushi   317
            pushi   3
            pushi   178
            pushi   3
            pushi   141
            pushi   #y
            pushi   0
            lag     gEgo
            send    4
            push    
            pushi   113
            callb   proc0_18, 6
            push    
            pTos    horizon
            ldi     2
            add     
            push    
            callb   proc0_17, 6
            push    
            lag     gEgo
            send    8
            jmp     code_0142
code_0135:  pushi   #posn
            pushi   2
            pushi   3
            pushi   137
            lag     gEgo
            send    8
code_0142:  toss    
            pushi   #init
            pushi   0
            lag     gEgo
            send    4
            pushi   0
            callb   proc0_1, 0
            pushi   #init
            pushi   0
            lofsa   tree
            send    4
            pushi   #init
            pushi   0
            lofsa   tree1
            send    4
            pushi   #init
            pushi   0
            lofsa   tree2
            send    4
            pushi   #init
            pushi   0
            lofsa   pineTree1
            send    4
            pushi   #init
            pushi   0
            lofsa   trunk
            send    4
            pushi   #init
            pushi   0
            lofsa   smallBush
            send    4
            pushi   #init
            pushi   0
            lofsa   farTree
            send    4
            pushi   #init
            pushi   0
            lofsa   pineTree2
            send    4
            lsg     global101
            ldi     1
            ge?     
            bnt     code_01c3
            pushi   #setStep
            pushi   2
            pushi   5
            dup     
            pushi   131
            pushi   1
            class   Walk
            push    
            pushi   241
            pushi   1
            class   Avoid
            push    
            pushi   231
            pushi   0
            pushi   18
            pushi   1
            pushi   0
            pushi   242
            pushi   0
            pushi   93
            pushi   0
            pushi   226
            pushi   0
            lofsa   squirrel
            send    42
code_01c3:  pushi   1
            lag     global101
            add     
            push    
            ldi     8
            mul     
            sal     local0
            ldi     0
            sal     local6
code_01d1:  lsl     local6
            lal     local0
            lt?     
            bnt     code_023e
            pushi   1
            lofsa   nutView
            push    
            callk   Clone, 2
            push    
            lal     local6
            sali    local11
code_01e6:  pushi   36
            pushi   2
            pushi   10
            pushi   190
            callk   Random, 4
            sat     temp0
            lt?     
            bnt     code_0202
            pprev   
            ldi     130
            lt?     
            bnt     code_0202
            jmp     code_01e6
code_0202:  pushi   164
            pushi   2
            pushi   145
            pushi   185
            callk   Random, 4
            sat     temp1
            lt?     
            bnt     code_0220
            pprev   
            ldi     172
            lt?     
            bnt     code_0220
            jmp     code_0202
code_0220:  pushi   #posn
            pushi   2
            lst     temp0
            lst     temp1
            pushi   93
            pushi   0
            pushi   231
            pushi   0
            pushi   226
            pushi   0
            lal     local6
            lali    local11
            send    20
            +al     local6
            jmp     code_01d1
code_023e:  ret     
        )
    )


    (method (doit)
        (var temp0)
        (if (script)
            (send script:doit())
        )(else
            = temp0 
                (switch ((send ((User:alterEgo)):edgeHit))
                    (case 1
                        north
                    )
                    (case 2
                        east
                    )
                    (case 3
                        south
                    )
                    (case 4
                        west
                    )
                )
            (if (temp0)
                (self:newRoom((= temp0 
                        (switch ((send ((User:alterEgo)):edgeHit))
                            (case 1
                                north
                            )
                            (case 2
                                east
                            )
                            (case 3
                                south
                            )
                            (case 4
                                west
                            )
                        )
)))
            )
        )
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if ((super:handleEvent(pEvent)))
                return 
            )(else
                (if (Said('look,look>'))
                    (if (Said('<around,down') or Said('/grass'))
                        (if (< local10 local0)
                            (if ((send gEgo:inRect(10 145 190 185)))
                                proc255_0(30 0)
                            )(else
                                proc255_0(30 1)
                            )
                        )(else
                            proc255_0(30 2)
                        )
                    )(else
                        (if (Said('[<at,around][/room,clearing,ceder]'))
                            proc255_0(30 3)
                        )(else
                            (if (Said('/ceder<pine'))
                                proc255_0(30 4)
                            )(else
                                (if (Said('/ceder') or Said('/ceder<nut'))
                                    (if ((send gEgo:inRect(10 145 190 185)))
                                        proc255_0(30 5)
                                    )(else
                                        proc255_0(30 3)
                                    )
                                )(else
                                    (if (Said('/nut,nut'))
                                        (if ((send gEgo:has(18)))
                                            (send ((send gInv:at(18))):showSelf(gEgo))
                                        )(else
                                            (if (< local10 local0)
                                                (if ((send gEgo:inRect(10 145 190 185)))
                                                    proc255_0(30 0)
                                                )(else
                                                    proc255_0(30 6)
                                                )
                                            )(else
                                                proc255_0(30 2)
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )(else
                    (if (Said('pick,get,get/nut<gold'))
                        (if (proc0_12(66))
                            proc255_0(30 7)
                        )(else
                            (if ((send gEgo:has(18)) and proc0_12(67))
                                proc255_0(30 8)
                            )(else
                                proc255_0(30 9)
                            )
                        )
                    )(else
                        (if (Said('pick,get,get/nut,nut'))
                            (if (proc0_12(66))
                                proc255_0(30 10)
                            )(else
                                (if ((send gEgo:has(18)))
                                    proc255_0(30 11)
                                )(else
                                    (if (proc0_12(1))
                                        proc255_0(30 12)
                                    )(else
                                        (if (>= local10 local0)
                                            proc255_0(30 2)
                                        )(else
                                            (send gEgo:setScript(getWalnut))
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )

)
(class nutView of View
    (properties
        x 0
        y 0
        z 0
        heading 0
        noun 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        description 3707
        sightAngle 90
        closeRangeDist 50
        longRangeDist 100
        shiftClick -32767
        contClick 7
        actions 0
        control 0
        verbChecks1 -17483
        verbChecks2 -17477
        verbChecks3 -17477
        yStep 2
        view 230
        loop 0
        cel 0
        priority 0
        underBits 0
        signal $0101
        lsTop 0
        lsLeft 0
        lsBottom 0
        lsRight 0
        brTop 0
        brLeft 0
        brBottom 0
        brRight 0
        palette 0
    )

    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if (proc255_5(self pEvent 3))
                proc255_0(30 13)
                (send pEvent:claimed(1))
            )(else
                (super:handleEvent(pEvent))
            )
        )
    )

)
(instance squirrel of Actor
    (properties
        noun 3601
        closeRangeDist 320
        longRangeDist 320
        shiftClick 1
        view 205
    )

    (method (doit param1)
        (super:doit(rest param1))
        (if (((< Random(1 100) 3) and not (squirrel:script)) and not local2)
            (squirrel:setScript(squirrelDash))
        )
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed))
            return 
        )(else
            (if (Said('cast,cast/boulder,pebble,pebble[/squirrel]'))
                (if ((< x 0) or (> x 320))
                    proc255_0(30 14)
                )(else
                    (if ((send gEgo:has(9)))
                        proc255_0(30 15)
                        proc0_27()
                    )(else
                        proc255_0(30 16)
                    )
                )
            )(else
                (if (Said('give/nut,nut/squirrel'))
                    (if ((< x 0) or (> x 320))
                        proc255_0(30 17)
                    )(else
                        proc255_0(30 18)
                    )
                )(else
                    (if (proc255_5(self pEvent 3) or Said('look,look/squirrel'))
                        (if ((> (squirrel:x) 0) and (< (squirrel:x) 320))
                            proc255_0(30 19)
                        )(else
                            proc255_0(30 20)
                        )
                    )(else
                        (if (Said('get,get/squirrel'))
                            (if ((< x 0) or (> x 320))
                                proc255_0(30 17)
                            )(else
                                proc255_0(30 21)
                            )
                        )(else
                            (if (Said('shoot/squirrel[/shot]'))
                                (if (not (send gEgo:has(10)))
                                    proc255_0(30 22)
                                )(else
                                    (if (not (send gEgo:has(9)))
                                        proc255_0(30 23)
                                    )(else
                                        proc255_0(30 24)
                                    )
                                )
                            )(else
                                (if (Said('kill,shoot/squirrel'))
                                    proc255_0(30 25)
                                )(else
                                    (super:handleEvent(pEvent))
                                )
                            )
                        )
                    )
                )
            )
        )
    )

)
(instance squirrelDash of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (if (< local10 local0)
                    = local4 (send local11[local10]:y)
                    = local3 (send local11[local10]:x)
                )(else
                    (if (Random(0 1))
                        = local4 Random(145 163)
                    )(else
                        = local4 Random(169 185)
                    )
                    (if (Random(0 1))
                        = local3 Random(10 47)
                    )(else
                        = local3 Random(118 190)
                    )
                )
                (if (< local3 83)
                    (squirrel:posn(-30 local4))
                    = local5 1
                )(else
                    (squirrel:posn(350 Random(140 170)))
                    = local5 0
                )
                (squirrel:setMotion(MoveTo local3 local4 self))
            )
            (case 1
                (if (< local10 local0)
                    (send local11[local10]:posn(-1 -1))
                    (send local11[local10]:hide())
                    ++local10
                )
                (if (local5)
                    (squirrel:setMotion(MoveTo -30 local4 self))
                )(else
                    (squirrel:setMotion(MoveTo 350 Random(140 170) self))
                )
            )
            (case 2
                (self:dispose())
            )
        )
    )

)
(instance getWalnut of Script
    (properties)

    (method (doit)
        (super:doit())
        (if (((> state 0) and (== (send local11[local8]:x) -1)) and not local1)
            (if (< local10 local0)
                proc255_0(30 26)
                proc255_0(30 27)
                = local1 1
                (self:changeState(0))
            )(else
                proc255_0(30 28)
                (self:changeState(5))
            )
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                = local7 9999
                = local6 0
                (while (< local6 local0)
                    = local9 (send gEgo:distanceTo(local11[local6]))
                    (if (< local9 local7)
                        = local7 local9
                        = local8 local6
                    )
                    ++local6
                )
                (if (< (send gEgo:distanceTo(local11[local8])) 25)
                    (self:cue())
                )(else
                    proc255_0(30 29)
                    proc0_3()
                    (self:dispose())
                )
            )
            (case 1
                (if (< (send gEgo:x) (send local11[local8]:x))
                    (send gEgo:
                        view(0)
                        setCycle(StopWalk 2)
                        setAvoider((Avoid:offScreenOK(0)))
                        setMotion(MoveTo - (send local11[local8]:x) 7 (send local11[local8]:y) self)
                    )
                )(else
                    (send gEgo:
                        view(0)
                        setCycle(StopWalk 2)
                        setAvoider(Avoid)
                        setMotion(MoveTo + (send local11[local8]:x) 7 (send local11[local8]:y) self)
                    )
                )
            )
            (case 2
                (send gEgo:
                    view(1)
                    loop(
                        (if (< (send gEgo:x) (send local11[local8]:x))
                            0
                        )(else
                            1
                        )
)
                    setMotion(0)
                    setCycle(End self)
                )
            )
            (case 3
                (send (ScriptID(0 21)):
                    number(105)
                    loop(1)
                    init()
                    play()
                )
                proc255_0(30 30)
                (send gEgo:get(18))
                (send local11[local8]:hide())
                proc0_19(66 3)
                = cycles 4
                (send gEgo:setAvoider(0))
            )
            (case 4
                (send gEgo:setCycle(Beg self))
            )
            (case 5
                proc0_1()
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance tree of NewFeature
    (properties
        x 104
        y 36
        noun 3675
        nsBottom 72
        nsRight 209
        description 3751
        sightAngle 360
        getableDist 320
        seeableDist 500
        shiftClick 369
        contClick 371
        lookStr 3763
    )
)
(instance tree1 of NewFeature
    (properties
        x 84
        y 115
        noun 3675
        nsTop 72
        nsLeft 67
        nsBottom 158
        nsRight 102
        description 3751
        sightAngle 360
        getableDist 320
        seeableDist 500
        shiftClick 369
        contClick 371
        lookStr 3763
    )
)
(instance tree2 of NewFeature
    (properties
        x 82
        y 162
        noun 3675
        nsTop 157
        nsLeft 56
        nsBottom 168
        nsRight 108
        description 3820
        sightAngle 360
        getableDist 320
        seeableDist 500
        shiftClick 369
        contClick 371
        lookStr 3763
    )
)
(instance pineTree1 of NewFeature
    (properties
        x 272
        y 103
        noun 3684
        nsTop 71
        nsLeft 239
        nsBottom 135
        nsRight 306
        description 3837
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 3847
    )
)
(instance pineTree2 of NewFeature
    (properties
        x 265
        y 50
        noun 3684
        nsTop 31
        nsLeft 246
        nsBottom 70
        nsRight 284
        description 3926
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 3847
    )
)
(instance trunk of NewFeature
    (properties
        x 20
        y 99
        noun 3693
        nsTop 72
        nsLeft 6
        nsBottom 127
        nsRight 35
        description 3946
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 3952
    )
)
(instance smallBush of NewFeature
    (properties
        x 255
        y 171
        noun 3693
        nsTop 159
        nsLeft 213
        nsBottom 183
        nsRight 298
        description 4019
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4030
    )
)
(instance farTree of NewFeature
    (properties
        x 269
        y 13
        noun 3693
        nsTop -1
        nsLeft 220
        nsBottom 27
        nsRight 318
        description 3820
        sightAngle 360
        getableDist 320
        seeableDist 320
        shiftClick 369
        contClick 371
        lookStr 4118
    )
)
