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


(local
    newProp
    local1[3]
    newAct
    local5

)
(instance public Room48 of Rm
    (properties
        picture 48
        style 16
    )

    (method (init)
        (super:init())
        Load(rsVIEW 501)
        Load(rsVIEW 2)
        Load(rsVIEW 647)
        Load(rsVIEW 245)
        Load(rsVIEW 48)
        (ogressChaseMusic:init())
        (ogressCatchMusic:init())
        (switch (gPicture)
            (case 49
                (proc0_9(0) (send gEgo:
                    posn(130 124)
                    view(2)
                    loop(0)
                    setStep(2 1)
                    init()
                )
  )
            )
            (default 
                (proc0_9(0) (send gEgo:
                    posn(135 135)
                    view(2)
                    loop(0)
                    setStep(2 1)
                    init()
                )
 )
            )
        )
        (self:setRegions(602))
        (if (global100)
            (send ((View:new())):
                view(647)
                loop(0)
                posn(158 94)
                addToPic()
            )
            (send ((View:new())):
                view(647)
                loop(1)
                posn(263 97)
                addToPic()
            )
            (send ((Prop:new())):
                view(501)
                loop(1)
                posn(221 141)
                setPri(15)
                init()
                setCycle(Fwd)
            )
            (send ((Prop:new())):
                view(501)
                loop(1)
                posn(101 141)
                setPri(15)
                init()
                setCycle(Fwd)
            )
        )(else
            (send ((View:new())):
                view(501)
                loop(0)
                cel(2)
                posn(221 141)
                setPri(15)
                ignoreActors(1)
                addToPic()
            )
            (send ((View:new())):
                view(501)
                loop(0)
                cel(2)
                posn(101 141)
                setPri(15)
                ignoreActors(1)
                addToPic()
            )
        )
        (send ((View:new())):
            view(501)
            loop(0)
            cel(1)
            posn(267 129)
            setPri(11)
            ignoreActors(1)
            addToPic()
        )
        (if (== (send ((send gInv:at(16))):owner()) 48)
            (send (= newProp (Prop:new())):
                view(501)
                loop(0)
                cel(0)
                posn(243 125)
                init()
                stopUpd()
            )
        )
        (send (= newAct (Act:new())):setScript(ogressChase))
    )


    (method (doit)
        (super:doit())
        (if (& (send gEgo:onControl(0)) $0040)
            (send global2:newRoom(49))
        )
    )


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


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed()))
            return 1
        )
        return 
            (if (== (send pEvent:type()) 128)
                (if (Said('look>'))
                    (if (Said('<under/bed'))
                        Print(48 0)
                    )(else
                        (if (Said('/bed'))
                            Print(48 1)
                        )(else
                            (if (Said('<in/chest,dresser,drawer'))
                                Print(48 2)
                            )(else
                                (if (Said('/chest,dresser,drawer'))
                                    Print(48 3)
                                )(else
                                    (if (Said('/carpet'))
                                        Print(48 4)
                                    )(else
                                        (if (Said('/window'))
                                            (if ((send gEgo:inRect(143 119 178 126)) or (send gEgo:inRect(232 126 275 132)))
                                                Print(48 5)
                                            )(else
                                                Print(800 1)
                                            )
                                        )(else
                                            (if (Said('/stair'))
                                                Print(48 6)
                                            )(else
                                                (if (Said('/barrel'))
                                                    Print(48 7)
                                                )(else
                                                    (if (Said('/mirror'))
                                                        (if ((send gEgo:inRect(201 143 282 170)))
                                                            Print(48 8)
                                                        )(else
                                                            Print(800 1)
                                                        )
                                                    )(else
                                                        (if (Said('/door'))
                                                            (if (== (send ((send gInv:at(33))):owner()) 48)
                                                                Print(48 9)
                                                            )(else
                                                                Print(48 10)
                                                            )
                                                        )(else
                                                            (if (Said('/wall'))
                                                                Print(48 11)
                                                            )(else
                                                                (if (Said('/dirt') or Said('<down'))
                                                                    Print(48 12)
                                                                )(else
                                                                    (if (Said('[<around,at][/room,bedroom,cottage]'))
                                                                        Print(Format(@global300 48 13 
                                                                                (if (== (send ((send gInv:at(16))):owner()) 48)
                                                                                    "Against the right wall, leans the ogre's axe."
                                                                                )(else
                                                                                    ""
                                                                                )
))
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )(else
                    (if (Said('get/ax'))
                        (if (== (send ((send gInv:at(16))):owner()) 48)
                            (if (< (send gEgo:distanceTo(newProp)) 20)
                                (send gEgo:get(16))
                                = global182 1
                                (send gGame:changeScore(2))
                                (send newProp:dispose())
                            )(else
                                Print(800 1)
                            )
                        )(else
                            Print(48 14)
                        )
                    )(else
                        (if (Said('sleep') or Said('(lay[<in,on,down]),(get[<in,in])[/bed]'))
                            Print(48 15)
                        )(else
                            (if (Said('open/chest,dresser,drawer'))
                                Print(48 2)
                            )(else
                                (if (Said('open/window'))
                                    (if ((send gEgo:inRect(143 119 178 126)) or (send gEgo:inRect(232 126 275 132)))
                                        Print(48 16)
                                    )(else
                                        Print(800 1)
                                    )
                                )(else
                                    (if (Said('open/door'))
                                        (if ((send gEgo:inRect(25 137 60 154)))
                                            Print(48 17)
                                        )(else
                                            Print(800 1)
                                        )
                                    )(else
                                        (if (Said('unlatch/door'))
                                            (if ((send gEgo:inRect(25 137 60 154)))
                                                Print(48 18)
                                            )(else
                                                Print(800 1)
                                            )
                                        )(else
                                            (if (Said('break/door'))
                                                (if ((send gEgo:inRect(25 137 60 154)))
                                                    Print(48 19)
                                                )(else
                                                    Print(800 1)
                                                )
                                            )(else
                                                (if (Said('bang/door'))
                                                    (if ((send gEgo:inRect(25 137 60 154)))
                                                        (if (== (send ((send gInv:at(33))):owner()) 48)
                                                            Print(48 20)
                                                        )(else
                                                            Print(48 21)
                                                        )
                                                    )(else
                                                        Print(800 1)
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
                (if (not (send pEvent:claimed()) and (> (ogressChase:state()) 0))
                    (if (Said('look/giantess'))
                        Print(48 22)
                    )(else
                        (if (Said('converse[/giantess]'))
                            Print(48 23)
                        )(else
                            (if (Said('kill[/giantess]'))
                                Print(48 24)
                            )(else
                                (if (Said('get,capture/giantess'))
                                    Print(48 25)
                                )(else
                                    (if (Said('deliver'))
                                        Print(48 26)
                                    )
                                )
                            )
                        )
                    )
                )
            )(else
                0
            )
    )

)
(instance ogressChase of Script
    (properties)

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


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send client:
                    view(245)
                    posn(0 0)
                    illegalBits(0)
                    ignoreActors(1)
                    setPri(8)
                    setCycle(Walk)
                    init()
                    hide()
                )
 
                (if (<> global14 0)
                    = seconds 10
                )(else
                    = seconds 60
                )
 )
            )
            (case 1
                (= local5 10 = global204 1 (User:canInput(0)) (playMusic:cue()) (send client:
                    posn(64 139)
                    show()
                    setAvoider(Avoid)
                    setMotion(MoveTo 135 123 self)
                )
  )
            )
            (case 2
                (
                (if ((< (send gEgo:x()) 135) and (> (send gEgo:y()) 128))
                    (send newAct:
                        setAvoider(Avoid)
                        setMotion(MoveTo 145 135 self)
                    )
                )(else
                    (self:cue())
                )
 )
            )
            (case 3
                (Print(48 27) (send client:
                    illegalBits(32768)
                    setPri(-1)
                    setAvoider(Avoid)
                    setMotion(Chase gEgo 15 self)
                )
  )
            )
            (case 4
                (proc0_10() = local5 11 (playMusic:cue()) (send gEgo:hide()) (send gEgo:hide()) (send client:
                    view(48)
                    cycleSpeed(2)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 5
                (Print(48 28 134 -1 20) = seconds 4  )
            )
            (case 6
                (= global127 1 )
            )
        )
    )

)
(instance ogressChaseMusic of Sound
    (properties
        number 10
    )
)
(instance ogressCatchMusic of Sound
    (properties
        number 11
    )
)
(instance playMusic of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (
                (switch (local5)
                    (case 10
                        ((ogressChaseMusic:
                            loop(1)
                            play(self)
                        )
  )
                    )
                    (case 11
                        ((ogressCatchMusic:
                            loop(1)
                            play(self)
                        )
 )
                    )
                )
  )
            )
            (case 1
                (
                (if (<> local5 11)
                    = state -1
                    (self:cue())
                )
 )
            )
        )
    )

)
