(version 2)
(include "sci.sh")
(exports
    0 rgTroll
)
(use "Main")
(use "Class_255_0")
(use "Cycle")
(use "Game")
(script 601)



(procedure (localproc_05ac param1)
    localproc_05da()
    proc255_0(rest param1 80 "Troll" 33 4 67 100 18 70 200)
)


(procedure (localproc_05cf)
    proc255_0(601 34)
)


(procedure (localproc_05da)
    (if (gTheNewDialog)
        (send gTheNewDialog:dispose())
    )
)


(procedure (localproc_05e5 param1)
    proc255_4(601 35 rest param1)
)


(procedure (localproc_05f2 param1 param2 param3)
    (if (proc0_12(13))
        (if ((send gEgo:has(param1)))
            (if (localproc_066a())
                proc255_4(601 36 rest param3)
                (send gGame:changeScore(
                    (if (<> param2 0)
                        param2
                    )(else
                        -6
                    )
))
                proc0_11(13)
                (send gEgo:put(param1))
                proc0_10(4)
            )(else
                proc255_0(601 37)
            )
        )(else
            localproc_05e5(rest param3)
        )
    )(else
        localproc_05cf()
    )
)


(procedure (localproc_066a)
    return < (send gEgo:distanceTo(gMenace)) 45
)


(instance public rgTroll of Rgn
    (properties)

    (method (init)
        Load(rsVIEW 120)
        (self:keep(0))
        (super:init())
        (if (proc0_12(4))
            proc0_11(5)
            proc0_11(4)
        )
        (send gMenace:
            view(120)
            setStep(6 4)
            setCycle(Walk)
            setLoop(-1)
            setPri(-1)
            ignoreHorizon()
            init()
            hide()
        )
        proc0_11(13)
    )


    (method (doit)
        (super:doit())
    )


    (method (handleEvent pEvent)
        (var temp0)
        (super:handleEvent(pEvent))
        (if (((== (send gEgo:view) 54) or (== (send gEgo:view) 14)) and (== (send pEvent:type) 128))
            (if (not 
            (if (Said('swim/') or Said('get,get,drink/water,drink'))
            )(else
                Said('fill/bucket')
            )
)
                proc255_0(601 0)
                (send pEvent:claimed(1))
            )(else
                (send pEvent:claimed(0))
            )
        )
        (if ((send pEvent:claimed) or (<> (send pEvent:type) 128))
            return 
        )
        (if (Said('look,look/troll,man') or proc255_5(gMenace pEvent 3))
            (send gMenace:doVerb(1))
        )(else
            (if (Said('look,look>'))
                (if (Said('<across[/brook,water,brook]'))
                    proc255_0(601 1)
                )(else
                    (if (Said('/brook,water,brook'))
                        proc255_0(601 2)
                    )(else
                        (if (Said('<below,below/bridge'))
                            proc255_0(601 3)
                        )(else
                            (if (Said('/bridge'))
                                (switch ((send gNumber:))
                                    (case 39
                                        proc255_0(601 4)
                                    )
                                    (default 
                                        proc255_0(601 5)
                                        (send pEvent:claimed(1))
                                    )
                                )
                            )
                        )
                    )
                )
            )(else
                (if (Said('use/dagger'))
                    (if ((send gEgo:has(0)))
                        proc255_0(601 6)
                    )(else
                        proc255_0(601 7)
                    )
                )(else
                    (if (Said('attack,kill,shoot/troll,man'))
                        (if (proc0_12(13))
                            proc255_0(601 8)
                        )(else
                            localproc_05cf()
                        )
                    )(else
                        (if (Said('kill>'))
                            (if (Said('/goat'))
                                (if (not proc0_12(2))
                                    proc255_0(601 9)
                                )(else
                                    (if ((send gEgo:has(0)))
                                        proc255_0(601 10)
                                        (send gEgo:put(0))
                                        (send gGame:changeScore(-5))
                                    )
                                )
                            )
                        )(else
                            (if (Said('use/shot'))
                                (if (proc0_12(13))
                                    proc255_0(601 8)
                                )(else
                                    proc255_0(601 11)
                                )
                            )(else
                                (if (not proc0_12(13) and Said('/troll,man'))
                                    localproc_05cf()
                                )(else
                                    (if (not proc0_12(13))
                                        return 
                                    )(else
                                        (if (Said('give>'))
                                            (if (Said('/diamond/troll,man') or Said('/bag[<diamond]/troll,man'))
                                                localproc_05f2(11 
                                                    (if (not proc0_12(62))
                                                        -3
                                                    )(else
                                                        0
                                                    )
 601 12)
                                            )(else
                                                (if (Said('/egg[<gold]/troll,man'))
                                                    localproc_05f2(15 0 601 13)
                                                )(else
                                                    (if (Said('/scepter/troll,man'))
                                                        localproc_05f2(12 0 601 14)
                                                    )(else
                                                        (if (Said('/treasure/troll,man') or Said('/chest[<treasure]/troll,man'))
                                                            localproc_05f2(1 0 601 15)
                                                        )(else
                                                            (if (Said('/nut<gold/troll,man'))
                                                                (if (proc0_12(67))
                                                                    localproc_05f2(18 0 601 16)
                                                                )(else
                                                                    localproc_05e5(601 17)
                                                                )
                                                            )(else
                                                                (if (Said('/nut/troll,man'))
                                                                    (if (proc0_12(13))
                                                                        (if ((send gEgo:has(18)))
                                                                            (if (not proc0_12(67))
                                                                                proc255_0(601 18)
                                                                            )(else
                                                                                localproc_05f2(18 0 601 16)
                                                                            )
                                                                        )(else
                                                                            localproc_05e5(601 19)
                                                                        )
                                                                    )(else
                                                                        localproc_05cf()
                                                                    )
                                                                )(else
                                                                    (if (Said('/diamond,egg,scepter,treasure,nut'))
                                                                        proc255_0(601 20)
                                                                    )(else
                                                                        = temp0 (send gInv:firstTrue(#saidMe))
                                                                        (if (temp0 and (send ((= temp0 (send gInv:firstTrue(#saidMe)))):ownedBy(gEgo)))
                                                                            proc255_0(601 21)
                                                                        )
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )(else
                                            (if (Said('move/troll,man'))
                                                (if (proc0_12(13))
                                                    (if (localproc_066a())
                                                        proc255_0(601 22)
                                                    )(else
                                                        proc255_0(601 23)
                                                    )
                                                )(else
                                                    localproc_05cf()
                                                )
                                            )(else
                                                (if (Said('beg/troll,man'))
                                                    (if (proc0_12(13))
                                                        (if (localproc_066a())
                                                            proc255_0(601 24)
                                                        )(else
                                                            proc255_0(601 25)
                                                        )
                                                    )(else
                                                        localproc_05cf()
                                                    )
                                                )(else
                                                    (if (Said('pay/toll,troll,man'))
                                                        localproc_05ac(601 26)
                                                    )(else
                                                        (if (Said('cast,cast/pebble,boulder,pebble'))
                                                            (if (not proc0_12(13))
                                                                proc255_0(601 27)
                                                            )(else
                                                                (if ((send gEgo:has(9)))
                                                                    proc255_0(601 28)
                                                                    proc0_27()
                                                                )(else
                                                                    proc255_0(601 29)
                                                                )
                                                            )
                                                        )(else
                                                            (if (Said('cast/dagger'))
                                                                (if (proc0_12(13))
                                                                    (if ((send gEgo:has(0)))
                                                                        (if (localproc_066a())
                                                                            proc255_0(601 30)
                                                                        )(else
                                                                            proc255_0(601 31)
                                                                        )
                                                                        (send gEgo:put(0))
                                                                        (send gGame:changeScore(-5))
                                                                    )(else
                                                                        localproc_05e5(601 32)
                                                                    )
                                                                )(else
                                                                    proc255_0(601 33)
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )

)
