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


(local
    newAct
    local1
    local2
    local3
    local4
    local5
    local6
    newAct_2
    newProp
    local9
    local10
    local11
    local12

)
(instance theMusic of Sound
    (properties)
)
(instance public Room49 of Rm
    (properties
        picture 49
        style 16
    )

    (method (init)
        (send (Load(rsVIEW 250)):)
        (if (not (send local6:cel()))
            (send gEgo:observeControl(16384))
        )(else
            (send gEgo:ignoreControl(16384))
        )
        (if (== (send ((send gInv:at(23))):owner()) 49)
            (send local4:setScript(chewBone))
        )(else
            (send local4:setScript(chaseEgo))
        )
    )


    (method (doit)
        (super:doit())
        (if (& (send gEgo:onControl()) $0004)
            (send gEgo:setPri(4))
        )(else
            (send gEgo:setPri(-1))
        )
        (if (((((global165 and (> (send gEgo:x()) 111)) and (> (send gEgo:y()) 123)) and (<> global165 5)) and (<> (self:script()) ogreStuff)) and (<> (self:script()) ogreAwake))
            (if (not 
            (if (not (== gPicture 50) or (== global165 4))
            )(else
                == global165 1
            )
)
                (self:setScript(ogreStuff))
            )
        )
        (if (& (send gEgo:onControl(0)) $0040)
            proc0_11()
            (send global2:newRoom(4))
        )
        (if ((& (send gEgo:onControl(0)) $0010) and not local10)
            proc0_11()
            (send global2:newRoom(51))
        )
        (if (& (send gEgo:onControl(0)) $0008)
            proc0_11()
            (send global2:newRoom(48))
        )
        (if ((& (send gEgo:onControl(0)) $0020) and not local10)
            proc0_11()
            (send global2:newRoom(50))
        )
        (if (((& (send gEgo:onControl(0)) $0400) and not local9) and not local10)
            = local9 1
            proc0_10()
            (moveOnTheStairs:changeState(1))
        )
    )


    (method (dispose)
        (send gSounds:eachElementDo(172))
        proc0_11()
        = global189 0
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (var gInvSaidMe)
        return 
            (if ((send pEvent:claimed()))
                return 1
            )(else
                (if (== (send pEvent:type()) 128)
                    (if (Said('look>'))
                        (if (Said('<under/table'))
                            Print(49 0)
                        )(else
                            (if (Said('/table'))
                                (if (newAct)
                                    Print(49 1)
                                )(else
                                    Print(49 2)
                                )
                            )(else
                                (if (Said('/chair'))
                                    Print(49 3)
                                )(else
                                    (if (Said('/carpet,carpet'))
                                        Print(49 4)
                                    )(else
                                        (if (Said('/stair'))
                                            Print(49 5)
                                        )(else
                                            (if (Said('/window'))
                                                Print(49 6)
                                            )(else
                                                (if (Said('/door'))
                                                    Print(49 7)
                                                )(else
                                                    (if (Said('/wall'))
                                                        Print(49 8)
                                                    )(else
                                                        (if (Said('/dirt') or Said('<down'))
                                                            Print(49 9)
                                                        )(else
                                                            (if (Said('/giant'))
                                                                (if (== global165 3)
                                                                    Print(49 1)
                                                                )(else
                                                                    (if (global165)
                                                                        Print(49 10)
                                                                    )(else
                                                                        Print(49 11)
                                                                    )
                                                                )
                                                            )(else
                                                                (if (Said('/bulldog'))
                                                                    (if (== (send local4:script()) chewBone)
                                                                        Print(49 12)
                                                                    )(else
                                                                        Print(49 13)
                                                                    )
                                                                )(else
                                                                    (if (Said('[<around][/room,cottage]'))
                                                                        Print(49 14)
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )(else
                        (if (Said('blow/whistle'))
                            (if ((send gEgo:has(27)) and (send gCast:contains(newAct)))
                                (if (== global165 3)
                                    Print(49 15)
                                )(else
                                    Print(49 16)
                                )
                            )(else
                                (send pEvent:claimed(0))
                            )
                        )(else
                            (if (Said('converse/bulldog'))
                                (if (== (send local4:script()) chewBone)
                                    Print(49 17)
                                )(else
                                    Print(49 18)
                                )
                            )(else
                                (if (Said('kill/bulldog'))
                                    Print(49 19)
                                )(else
                                    (if (Said('pat/bulldog'))
                                        Print(49 20)
                                    )(else
                                        (if (Said('calm/bulldog'))
                                            Print(49 21)
                                        )(else
                                            (if (Said('get,capture/bulldog'))
                                                Print(49 22)
                                            )(else
                                                (if (Said('sit>'))
                                                    Print(49 23)
                                                    (send pEvent:claimed(1))
                                                )(else
                                                    (if (Said('converse/bulldog'))
                                                        (if (== (send local4:script()) chewBone)
                                                            Print(49 17)
                                                        )(else
                                                            Print(49 18)
                                                        )
                                                    )(else
                                                        (if (Said('converse,awaken[/giant]'))
                                                            (if ((send gCast:contains(newAct)))
                                                                (if (== global165 3)
                                                                    (if ((< (send gEgo:distanceTo(newAct)) 50) and not (ogreAwake:state()))
                                                                        Print(49 24)
                                                                        = local12 1
                                                                        (ogreAwake:cue())
                                                                    )(else
                                                                        Print(49 25)
                                                                    )
                                                                )(else
                                                                    Print(49 26)
                                                                )
                                                            )(else
                                                                Print(49 27)
                                                            )
                                                        )(else
                                                            (if (Said('open/closet') or Said('open/door<closet'))
                                                                (if (not (send gEgo:inRect(219 123 245 130)))
                                                                    proc0_15()
                                                                )(else
                                                                    (if ((send local5:cel()))
                                                                        Print(49 28)
                                                                    )(else
                                                                        (if ((send gEgo:has(33)))
                                                                            Print(49 10)
                                                                        )(else
                                                                            (send local5:setScript(doorOpen))
                                                                        )
                                                                    )
                                                                )
                                                            )(else
                                                                (if (Said('open/door'))
                                                                    (if ((send gEgo:inRect(219 123 245 130)))
                                                                        (if ((send local5:cel()))
                                                                            Print(49 28)
                                                                        )(else
                                                                            (if ((send gEgo:has(33)))
                                                                                Print(49 10)
                                                                            )(else
                                                                                (send local5:setScript(doorOpen))
                                                                            )
                                                                        )
                                                                    )(else
                                                                        (if ((send gEgo:inRect(38 131 93 141)))
                                                                            (if (not (send local6:cel()))
                                                                                (if ((send gEgo:has(33)))
                                                                                    (send local6:
                                                                                        ignoreActors(1)
                                                                                        setCycle(End)
                                                                                        setPri(0)
                                                                                    )
                                                                                    = global210 1
                                                                                    (send gEgo:ignoreControl(16384))
                                                                                    (if ((send gEgo:has(33)) and (== (ogreAwake:state()) 0))
                                                                                        (ogreAwake:changeState(2))
                                                                                    )
                                                                                )(else
                                                                                    (if ((== global165 3) and not (ogreAwake:state()))
                                                                                        (ogreAwake:changeState(2))
                                                                                    )
                                                                                )
                                                                            )(else
                                                                                Print(49 29)
                                                                            )
                                                                        )(else
                                                                            Print(49 30)
                                                                        )
                                                                    )
                                                                )(else
                                                                    (if (Said('close/door'))
                                                                        (if ((send gEgo:inRect(219 123 245 130)))
                                                                            (if ((send local5:cel()))
                                                                                (send local5:setCycle(Beg))
                                                                            )(else
                                                                                Print(49 31)
                                                                            )
                                                                        )(else
                                                                            (if (< (send gEgo:distanceTo(local6)) 25)
                                                                                (if ((send local6:cel()))
                                                                                    (send local6:
                                                                                        setCycle(Beg)
                                                                                        setPri(-1)
                                                                                    )
                                                                                    = global210 0
                                                                                    (send gEgo:observeControl(16384))
                                                                                )(else
                                                                                    Print(49 31)
                                                                                )
                                                                            )(else
                                                                                Print(49 30)
                                                                            )
                                                                        )
                                                                    )(else
                                                                        (if (Said('get/egg[<gold]'))
                                                                            (if (newAct and (< (send gEgo:distanceTo(newAct)) 20))
                                                                                (send gEgo:put(33 49))
                                                                                (ogreAwake:changeState(1))
                                                                            )
                                                                        )(else
                                                                            (if (Said('get,rob/chicken'))
                                                                                (if (not local3)
                                                                                    Print(49 32)
                                                                                )(else
                                                                                    (if ((send gEgo:has(33)))
                                                                                        proc0_16()
                                                                                    )(else
                                                                                        (if (((send gEgo:inRect(190 148 264 156)) and (> (send gEgo:x()) (- (send local3:x()) 11))) and (< (send gEgo:x()) (+ (send local3:x()) 11)))
                                                                                            = global182 1
                                                                                            (send gEgo:get(33))
                                                                                            (send gGame:changeScore(4))
                                                                                            (send local3:dispose())
                                                                                        )(else
                                                                                            proc0_15()
                                                                                        )
                                                                                    )
                                                                                )
                                                                            )(else
                                                                                (if (Said('kill/giant'))
                                                                                    Print(49 33)
                                                                                )(else
                                                                                    (if ((Said('kiss/giant') or Said('kiss/bulldog')) or Said('kiss[/!*]'))
                                                                                        Print(49 34)
                                                                                    )(else
                                                                                        (if (Said('fling,deliver,feed/['))
                                                                                            (if ((send gEgo:has(23)))
                                                                                                (if (> (send gEgo:distanceTo(local4)) 40)
                                                                                                    proc0_10()
                                                                                                    (send local4:
                                                                                                        setMotion(0)
                                                                                                        setCycle(0)
                                                                                                        setScript(0)
                                                                                                    )
                                                                                                    (send ((send gInv:at(23))):moveTo(49))
                                                                                                    (send gGame:changeScore(4))
                                                                                                    (send local4:setScript(catchBone))
                                                                                                )(else
                                                                                                    Print(49 35)
                                                                                                )
                                                                                            )(else
                                                                                                Print(49 36)
                                                                                            )
                                                                                        )(else
                                                                                            (if (Said('get,rob/['))
                                                                                                (if (== (send ((send gInv:at(23))):owner()) 49)
                                                                                                    Print(49 37)
                                                                                                )(else
                                                                                                    Print(49 38)
                                                                                                )
                                                                                            )(else
                                                                                                (if (Said('get,capture/giant'))
                                                                                                    Print(49 39)
                                                                                                )(else
                                                                                                    (if (Said('deliver>') and (= gInvSaidMe (send gInv:saidMe())))
                                                                                                        (if ((= gInvSaidMe (send gInv:saidMe())) and (send gEgo:has((send gInv:indexOf((= gInvSaidMe (send gInv:saidMe())))))))
                                                                                                            (if ((send gCast:contains(newAct)))
                                                                                                                Print(49 40)
                                                                                                            )(else
                                                                                                                Print(49 41)
                                                                                                            )
                                                                                                            (send pEvent:claimed(1))
                                                                                                        )(else
                                                                                                            Print(49 42)
                                                                                                            (send pEvent:claimed(1))
                                                                                                        )
                                                                                                    )
                                                                                                )
                                                                                            )
                                                                                        )
                                                                                    )
                                                                                )
                                                                            )
                                                                        )
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )


    (method (newRoom param1)
        (if (== param1 4)
            (send (ScriptID(602)):keep(0))
            = global189 0
        )
        (super:newRoom(param1))
    )

)
(instance ogreStuff of Script
    (properties)

    (method (doit)
        (super:doit())
        (if ((not global167 and (== (self:state()) 11)) and (> (send gEgo:y()) 122))
            (self:cue())
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (
                (switch (global165)
                    (case 1
                        (
                        (if (global167)
                            (self:changeState(11))
                        )(else
                            (self:changeState(10))
                        )
 )
                    )
                    (case 2
                        ((self:changeState(20))  )
                    )
                    (case 3
                        ((self:changeState(30)) )
                    )
                )
  )
            )
            (case 10
                (
                (if (== (send local6:cel()) 0)
                    (send local6:
                        setCycle(End)
                        setPri(0)
                    )
                )
 (theMusic:
                    number(5)
                    loop(-1)
                    play()
                )
 (self:cue())  )
            )
            (case 11
                ((send (= newAct (Act:new())):
                    view(250)
                    posn(53 133)
                    setStep(6 2)
                    init()
                    setCycle(Walk)
                )
 (User:canInput(0)) 
                (if (not global167)
                    (send newAct:setMotion(MoveTo 130 133))
                )(else
                    proc0_3(newAct gEgo)
                )
 )
            )
            (case 12
                (= local10 1 (send newAct:
                    setAvoider((Avoid:new()))
                    setCycle(Walk)
                    setMotion(Chase gEgo 15 self)
                )
  )
            )
            (case 13
                ((User:
                    canControl(0)
                    canInput(0)
                )
 (send gEgo:dispose()) (send newAct:
                    view(78)
                    setCycle(End self)
                )
 Print(49 43 134 -1 30 166) (theMusic:
                    number(6)
                    loop(1)
                    play()
                )
 Print(49 44 134 -1 20)  )
            )
            (case 14
                ((send newAct:
                    view(79)
                    setPri(9)
                    setCycle(Walk)
                    setAvoider(Avoid)
                    setMotion(MoveTo 246 132 self)
                )
  )
            )
            (case 15
                (= global127 1  )
            )
            (case 20
                (Print(49 45 134 -1 20) (ogreAwake:state(0)) (send (= newAct (Act:new())):
                    illegalBits(0)
                    view(256)
                    loop(2)
                    posn(200 159)
                    setStep(6 2)
                    setPri(12)
                    init()
                    setScript(ogreAwake)
                )
  )
            )
            (case 30
                (
                (if (== gPicture 51)
                    Print(49 46 134 -1 20)
                )
 )
            )
        )
    )

)
(instance ogreAwake of Script
    (properties)

    (method (doit)
        (super:doit())
        (if (((not global167 and (== (self:state()) 1)) and (> (send gEgo:y()) 122)) and not (& (send gEgo:onControl()) $0004))
            (self:cue())
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (
                (if (<> global165 2)
                    = seconds 60
                )(else
                    (self:cue())
                )
 )
            )
            (case 1
                (
                (if (> (send gEgo:y()) 122)
                    return 
                )
 )
            )
            (case 2
                ((send gEgo:observeControl(4)) 
                (if ((send gEgo:has(33)))
                    (if (not local12)
                        Print(49 47 50 4)
                    )
                )(else
                    (if (== global165 3)
                        Print(49 48)
                    )
                )
 (theMusic:
                    number(5)
                    loop(-1)
                    play()
                )
 (send newAct:
                    cycleSpeed(0)
                    loop(1)
                    setCycle(End self)
                )
  )
            )
            (case 3
                (= global165 4 = local10 1 (send newAct:
                    view(250)
                    posn((send newAct:x()) - (send newAct:y()) 3)
                    setAvoider(Avoid)
                    setCycle(Walk)
                    setMotion(Chase gEgo 15 self)
                )
  )
            )
            (case 4
                ((User:
                    canControl(0)
                    canInput(0)
                )
 
                (if ((send gEgo:has(33)))
                    Print(49 49 166)
                )(else
                    Print(49 44 166)
                )
 (theMusic:
                    number(6)
                    loop(1)
                    play()
                )
 (send gEgo:dispose()) (send newAct:
                    view(78)
                    setCycle(End self)
                )
  )
            )
            (case 5
                ((send newAct:
                    view(79)
                    setCycle(Walk)
                    illegalBits(32768)
                    setPri(-1)
                    setAvoider(Avoid)
                    setMotion(MoveTo 246 132 self)
                )
  )
            )
            (case 6
                (= global127 1 )
            )
        )
    )

)
(instance ogressChase of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= local10 1 (theMusic:
                    number(10)
                    loop(-1)
                    play()
                )
 (send local2:
                    illegalBits(32768)
                    setAvoider(Avoid)
                    ignoreActors(1)
                    setCycle(Walk)
                    setMotion(Chase gEgo 15 self)
                )
  )
            )
            (case 1
                (proc0_10() (theMusic:
                    number(11)
                    loop(1)
                    play()
                )
 (send gEgo:hide()) (send local2:
                    view(48)
                    cycleSpeed(2)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 2
                (Print(49 50 134 -1 20 166) = seconds 4  )
            )
            (case 3
                (= global127 1 )
            )
        )
    )

)
(instance henPecked of Script
    (properties)

    (method (init param1)
        (super:init(param1))
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send local3:
                    view(360)
                    posn(225 130)
                    loop(0)
                    show()
                    setPri(12)
                    ignoreActors(1)
                    setCycle(Walk)
                    moveSpeed(2)
                    cycleSpeed(0)
                    setMotion(MoveTo 260 133 self)
                )
  )
            )
            (case 1
                (
                (if ((send gCast:contains(local3)))
                    (send local3:
                        loop(+ (send local3:loop()) 2)
                        setCycle(End self)
                    )
                )
 )
            )
            (case 2
                (
                (if ((send gCast:contains(local3)))
                    (send local3:
                        setCycle(Walk)
                        setMotion(MoveTo 
                            (if (> (send local3:x()) 238)
                                Random(214 230)
                            )(else
                                Random(240 262)
                            )
 133 self)
                    )
                )
 )
            )
            (case 3
                (= state 0 (self:cue()) )
            )
        )
    )

)
(instance chaseEgo of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (Print(49 51 134 -1 20 166) (send local4:
                    setAvoider((Avoid:new()))
                    setCycle(Fwd)
                    ignoreActors(1)
                    setMotion(Chase gEgo 15 self)
                )
  )
            )
            (case 1
                ((User:
                    canInput(0)
                    canControl(0)
                )
 (send gEgo:dispose()) (send local4:
                    view(87)
                    loop(0)
                    setMotion(0)
                )
 (self:cue())  )
            )
            (case 2
                ((send local4:
                    loop(1)
                    setCycle(Fwd)
                )
 (theMusic:
                    number(5)
                    loop(-1)
                    play()
                )
 = seconds 3  )
            )
            (case 3
                ((send local4:
                    loop(3)
                    cycleSpeed(2)
                    setCycle(End)
                )
 = seconds 4  )
            )
            (case 4
                ((send (= newProp (Prop:new())):
                    view(87)
                    loop(4)
                    cel(0)
                    setPri(15)
                    posn(- (send local4:x()) 17 - (send local4:y()) 9)
                    init()
                    cycleSpeed(1)
                    setCycle(Fwd)
                )
 = seconds 2  )
            )
            (case 5
                ((send newProp:dispose()) Print(49 52 166 134 -1 20) = global127 1 )
            )
        )
    )

)
(instance chewBone of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send local4:
                    view(350)
                    loop(2)
                    ignoreActors(0)
                    cycleSpeed(1)
                    setCycle(Fwd)
                )
 = seconds 2  )
            )
            (case 1
                ((dogsPlace:
                    top((send local4:nsTop()))
                    bottom(+ (send local4:nsBottom()) 1)
                    left(- (send local4:nsLeft()) 1)
                    right(+ (send local4:nsRight()) 1)
                    init()
                )
 (send gEgo:observeBlocks(dogsPlace)) )
            )
        )
    )

)
(instance dogsPlace of Blk
    (properties)
)
(instance catchBone of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_3(gEgo local4) (send ((Sound:new())):
                    number(63)
                    loop(1)
                    play()
                )
 (send gEgo:
                    view(15)
                    cycleSpeed(1)
                    cel(0)
                    setCycle(CT 5 1 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    cel(6)
                    setCycle(End)
                )
 (send (= newAct_2 (Act:new())):
                    view(541)
                    illegalBits(0)
                    posn(+ (send gEgo:x()) 3 - (send gEgo:y()) 25)
                    setLoop(0)
                    setPri(14)
                    setStep(6 1)
                    setCycle(Fwd)
                    setMotion(MoveTo - (send local4:x()) 10 - (send local4:y()) 11 self)
                    init()
                )
  )
            )
            (case 2
                (Print(49 53 140 290 134 -1 20 172) (send gEgo:
                    view(2)
                    cycleSpeed(0)
                    setCycle(Walk)
                )
 (send newAct_2:dispose()) (send local4:
                    view(350)
                    loop(3)
                    setCycle(End self)
                )
  )
            )
            (case 3
                ((send local4:
                    view(352)
                    setLoop(
                        (if (< (send local4:x()) 155)
                            0
                        )(else
                            1
                        )
)
                    setCycle(Walk)
                    moveSpeed(1)
                    setMotion(MoveTo 155 126 self)
                )
  )
            )
            (case 4
                ((send local4:
                    view(350)
                    loop(2)
                    ignoreActors(0)
                    cycleSpeed(1)
                    setCycle(Fwd)
                )
 = seconds 10  )
            )
            (case 5
                (
                (if (gTheNewDialog)
                    (send gTheNewDialog:dispose())
                )
 proc0_11() (send local4:setScript(chewBone)) )
            )
        )
    )

)
(instance doorOpen of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() (send gEgo:setMotion(MoveTo (+ (send client:x()) 20) (+ (send client:y()) 9) self))  )
            )
            (case 1
                (proc0_3(gEgo client) (send client:setCycle(End self))  )
            )
            (case 2
                ((send gEgo:setMotion(MoveTo (send gEgo:x()) (+ (send client:y()) 2) self))  )
            )
            (case 3
                (proc0_11() (send global2:newRoom(51)) )
            )
        )
    )

)
(instance moveOnTheStairs of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 1
                ((send gEgo:setStep(2 2)) (send gEgo:illegalBits(0)) 
                (if (> (send gEgo:y()) 100)
                    (send gEgo:setMotion(MoveTo 194 61 self))
                )(else
                    (send gEgo:setMotion(MoveTo 97 123 self))
                )
 )
            )
            (case 2
                (proc0_11() (send gEgo:illegalBits(32768)) (send gEgo:setStep(2 1)) = local9 0 )
            )
        )
    )

)
