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


(local
    local0
    newAct
    local2
    local3
    local4
    newActHeading
    newProp
    local7

)
(instance ogressTheme of Sound
    (properties)
)
(instance ogreTheme of Sound
    (properties)
)
(instance door of Prop
    (properties)

    (method (cue)
        proc0_11()
        (send global2:newRoom(49))
    )

)
(instance public Room4 of Rm
    (properties
        picture 4
    )

    (method (init)
        = north 28
        = south 10
        = east 5
        = west 3
        = horizon 75
        = global189 1
        (if (global100)
            = picture 104
        )
        = global101 0
        (send gEgo:edgeHit(0))
        (super:init())
        (self:setRegions(508 517))
        Load(rsVIEW 245)
        Load(rsVIEW 246)
        Load(rsVIEW 57)
        (if ((== gPicture 49) and (send gEgo:has(33)))
            (door:
                view(602)
                loop(0)
                cel(6)
                posn(182 150)
                setPri(10)
                ignoreActors()
                init()
                stopUpd()
            )
        )(else
            (door:
                view(602)
                loop(0)
                cel(0)
                posn(182 150)
                setPri(10)
                init()
                stopUpd()
            )
        )
        (if (<= (send gEgo:y()) horizon)
            (send gEgo:y((+ horizon (send gEgo:yStep()))))
        )
        (switch (gPicture)
            (case 0
                ((send gEgo:posn(128 166))  )
            )
            (case 28
                ((send gEgo:posn(48 (+ horizon (+ (send gEgo:yStep()) 1))))  )
            )
            (case 3
                ((send gEgo:posn(2 (send gEgo:y())))  )
            )
            (case 5
                ((send gEgo:posn(317 (send gEgo:y())))  )
            )
            (case 10
                ((send gEgo:posn((send gEgo:x()) 187))  )
            )
            (case 49
                ((send gEgo:
                    loop(2)
                    posn(173 153)
                )
 )
            )
        )
        (send gEgo:
            view(2)
            xStep(2)
            yStep(1)
            init()
        )
        (if (((== gPicture 10) and gNewAct) and (<> global179 1))
            = gNewAct (Act:new())
            (send gNewAct:
                posn(110 + (+ 189 (- gGNewActY 75)) 80)
                view(250)
                xStep(6)
                yStep(2)
                setCycle(Walk)
                ignoreActors()
                init()
            )
            (send global2:setScript(ogreActions))
            (ogreTheme:
                number(5)
                loop(-1)
                play()
            )
        )(else
            = gNewAct 0
        )
        (if ((== global109 2) and not global163)
            = global163 1
            = newAct (Act:new())
            (send newAct:
                posn(4 142)
                view(246)
                xStep(1)
                yStep(1)
                setCycle(Walk)
                ignoreActors()
                init()
            )
            (send global2:setScript(ogressActions))
            (send newAct:setMotion(MoveTo 103 168 ogressActions))
            (ogressTheme:
                number(10)
                loop(-1)
                play()
            )
        )
        (if ((((not gNewAct and (< Random(1 100) 35)) and (<> global179 1)) and (<> gPicture 49)) and not (send gCast:contains(newAct)))
            = gNewAct (Act:new())
            (send gNewAct:
                posn(1 179)
                view(250)
                xStep(6)
                yStep(2)
                setCycle(Walk)
                ignoreActors()
                init()
            )
            (if (< Random(1 100) 50)
                (send gNewAct:posn(110 239))
            )
            (ogreTheme:
                number(5)
                loop(-1)
                play()
            )
            (send global2:setScript(ogreActions))
        )
        (if (== global165 4)
            (send global2:setScript(ogreActions))
            (ogreActions:changeState(200))
        )
        (if (== (door:cel()) 0)
            (send gEgo:observeControl(16384))
        )
    )


    (method (doit)
        (super:doit())
        (if ((& (send gEgo:onControl(0)) $4000) and (<> (door:cel()) 0))
            (send global2:newRoom(49))
        )
        (if ((send gCast:contains(gEgo)))
            (if ((send gEgo:inRect(143 0 369 136)))
                (send gEgo:setPri(1))
            )(else
                (send gEgo:setPri(-1))
            )
        )
        (if ((send gCast:contains(gNewAct)))
            (if ((send gNewAct:inRect(143 0 369 136)))
                (send gNewAct:setPri(1))
            )(else
                (send gNewAct:setPri(-1))
            )
        )
        (if ((send gCast:contains(newAct)))
            (if ((send newAct:inRect(143 0 369 136)))
                (send newAct:setPri(1))
            )(else
                (if (< (ogressActions:state()) 200)
                    (send newAct:setPri(-1))
                )
            )
        )
        (if (== local3 1)
            (if (not 
            (if ((send gEgo:inRect(134 0 369 137)))
                (send newAct:inRect(104 149 369 185))
            )
 and (< (send gEgo:distanceTo(newAct)) 75))
                = local3 2
                (ogressActions:changeState(10))
                Print(4 0)
            )
        )
        (if (((== local3 1) and not (send gEgo:inRect(134 0 369 137))) and not (send newAct:inRect(104 149 369 185)))
            = local4 GetAngle((send newAct:x()) (send newAct:y()) (send gEgo:x()) (send gEgo:y()))
            (if ((< (= newActHeading (send newAct:heading())) 15) and (> local4 345))
                = newActHeading (+ newActHeading 360)
            )
            (if (< Abs((- local4 newActHeading)) 15)
                = local3 2
                Print(4 0)
                (ogressActions:changeState(10))
            )
        )
    )


    (method (dispose)
        (send gSounds:eachElementDo(172))
        = global189 0
        (send gEgo:setPri(-1))
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed()))
            return 1
        )
        return 
            (if (== (send pEvent:type()) 128)
                (if (Said('look>'))
                    (if (Said('/cottage'))
                        Print(4 1)
                    )(else
                        (if (Said('/door'))
                            Print(4 2)
                        )(else
                            (if (Said('/bucket'))
                                Print(4 3)
                            )(else
                                (if (Said('/buck'))
                                    (if ((send gCast:contains(newAct)))
                                        Print(4 4)
                                    )
                                )(else
                                    (if (Said('/window'))
                                        (if ((send gEgo:inRect(266 140 304 155)))
                                            Print(4 5)
                                        )(else
                                            Print(800 1)
                                        )
                                    )(else
                                        (if (Said('/giantess'))
                                            (if ((send gCast:contains(newAct)))
                                                (switch ((send newAct:view()))
                                                    (case 246
                                                        Print(4 6)
                                                    )
                                                    (case 245
                                                        Print(4 7)
                                                    )
                                                )
                                            )(else
                                                Print(4 8)
                                            )
                                        )(else
                                            (if (Said('[<around][/room]'))
                                                Print(4 9)
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )(else
                    (if ((send gCast:contains(newAct)) and Said('converse'))
                        (if ((== (send newAct:view()) 246) and (<> local3 3))
                            (if (not (send gEgo:inRect(143 0 319 136)))
                                Print(4 10)
                                (ogressActions:changeState(10))
                                = local3 2
                            )(else
                                Print(4 11)
                            )
                        )(else
                            Print(4 12)
                        )
                    )(else
                        (if (Said('get,capture/buck'))
                            (if ((send gCast:contains(newAct)))
                                Print(4 13)
                            )(else
                                (if ((send gCast:contains(newProp)))
                                    Print(4 14)
                                )(else
                                    Print(4 15)
                                )
                            )
                        )(else
                            (if (Said('get,capture/giantess'))
                                Print(4 16)
                            )(else
                                (if (Said('open/door'))
                                    (if ((send gEgo:inRect(163 144 199 155)))
                                        (if ((send gCast:contains(newAct)) or (send gCast:contains(gNewAct)))
                                            Print(4 17)
                                        )(else
                                            (if (<> global109 2)
                                                Print(4 18)
                                            )(else
                                                (send gEgo:loop(3))
                                                proc0_10()
                                                (door:
                                                    setPri(9)
                                                    setCycle(End)
                                                )
                                                (send ((Sound:new())):
                                                    number(300)
                                                    loop(1)
                                                    play(door)
                                                )
                                                (send gEgo:illegalBits(32768))
                                            )
                                        )
                                    )(else
                                        Print(800 1)
                                    )
                                )(else
                                    (if (Said('bang'))
                                        (if (< (send gEgo:distanceTo(door)) 10)
                                            (if ((send gCast:contains(gNewAct)))
                                                Print(4 19)
                                            )(else
                                                (if (<> global109 2)
                                                    Print(4 20)
                                                )(else
                                                    (if (not (send gCast:contains(newAct)))
                                                        Print(4 21)
                                                        (send global2:setScript(ogressActions))
                                                        (ogressActions:changeState(200))
                                                    )(else
                                                        Print(4 22)
                                                    )
                                                )
                                            )
                                        )(else
                                            Print(800 1)
                                        )
                                    )(else
                                        (if (Said('unlatch'))
                                            (if (<> global109 2)
                                                Print(4 18)
                                            )(else
                                                Print(4 23)
                                            )
                                        )(else
                                            (if (Said('break/window'))
                                                Print(4 24)
                                            )(else
                                                (if (Said('break/door'))
                                                    Print(4 25)
                                                )(else
                                                    (if (Said('open/window'))
                                                        Print(4 26)
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )(else
                0
            )
    )


    (method (newRoom param1)
        proc0_11()
        (if ((send gCast:contains(gEgo)))
            (send gEgo:illegalBits(32768))
            (send gEgo:setPri(-1))
        )
        (if (<> param1 49)
            = global165 0
        )
        = global189 0
        (super:newRoom(param1))
    )

)
(instance ogressActions of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (
                (if (newAct)
                    = seconds 3
                )
 )
            )
            (case 1
                (= local3 1 (send newAct:setLoop(0))  )
            )
            (case 2
                ((send newAct:setMotion(MoveTo 183 155 ogressActions))  )
            )
            (case 3
                ((door:setCycle(End self))  )
            )
            (case 4
                (= local3 3 (send newAct:
                    baseSetter(ScriptID(0 1))
                    setPri(9)
                    setMotion(MoveTo 187 144 self)
                )
  )
            )
            (case 5
                ((door:setCycle(Beg self))  )
            )
            (case 6
                (= local3 0 (ogressTheme:dispose()) (send newAct:dispose()) = newAct 0  )
            )
            (case 10
                (= newProp (Prop:new()) (send newProp:
                    view(530)
                    ignoreActors()
                    setPri(+ (send newAct:priority()) 1)
                    posn(- (send newAct:x()) 6 + (send newAct:y()) 3)
                    setCycle(End self)
                    init()
                )
 (send newAct:
                    setLoop(-1)
                    setMotion(0)
                    view(245)
                )
 (door:setCycle(0))  )
            )
            (case 11
                ((send newAct:
                    setAvoider((Avoid:new()))
                    xStep(6)
                    yStep(2)
                    setLoop(-1)
                    setCycle(Walk)
                    ignoreActors()
                    setMotion(Chase gEgo 5 self)
                )
 
                (if ((send gCast:contains(newProp)))
                    (send newProp:
                        ignoreActors(0)
                        setPri(-1)
                    )
                )
 )
            )
            (case 12
                ((ogressTheme:dispose()) (ogressTheme:
                    number(11)
                    loop(1)
                    play(self)
                )
 proc0_10() (send gEgo:dispose()) (send newAct:
                    view(57)
                    setCycle(Fwd)
                )
 Print(4 27 134 -1 20 166)  )
            )
            (case 13
                (= seconds 2  )
            )
            (case 14
                (= global127 1  )
            )
            (case 200
                ((door:setCycle(End self)) = newAct (Act:new()) (send newAct:
                    view(245)
                    setPri(9)
                    loop(2)
                    ignoreActors()
                    baseSetter(ScriptID(0 1))
                    posn(186 145)
                    init()
                )
 proc0_10()  )
            )
            (case 201
                (= seconds 1  )
            )
            (case 202
                ((self:changeState(11)) )
            )
        )
    )

)
(instance ogreActions of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (
                (if ((send gCast:contains(gNewAct)))
                    (ogreActions:changeState(1))
                )
 )
            )
            (case 1
                (= local2 1 
                (if ((send gEgo:inRect(223 74 319 136)))
                    (send gNewAct:setMotion(MoveTo 97 123 self))
                )(else
                    (self:changeState(2))
                )
 )
            )
            (case 2
                ((send gNewAct:
                    setAvoider((Avoid:new()))
                    xStep(6)
                    yStep(2)
                    ignoreActors()
                    setMotion(Chase gEgo 5 self)
                )
  )
            )
            (case 3
                (proc0_10() (send gEgo:dispose()) (send gNewAct:
                    view(78)
                    setCycle(End self)
                )
  )
            )
            (case 4
                ((ogreTheme:dispose()) (ogreTheme:
                    number(6)
                    loop(1)
                    play()
                )
 (send gNewAct:
                    setAvoider(0)
                    view(79)
                    setCycle(Walk self)
                )
 Print(4 28 134 -1 20 166) 
                (if ((send gNewAct:inRect(65486 70 350 93)))
                    (send gNewAct:setMotion(MoveTo 37 87 self))
                )(else
                    (if ((send gNewAct:inRect(65486 93 350 136)) or (send gNewAct:inRect(92 135 141 148)))
                        (self:changeState(5))
                        = local0 (Timer:setReal(killOgre 15))
                    )(else
                        (self:changeState(7))
                        = local0 (Timer:setReal(killOgre 15))
                    )
                )
 )
            )
            (case 5
                ((send gNewAct:setMotion(MoveTo 75 120 self))  )
            )
            (case 6
                ((send gNewAct:setMotion(MoveTo 75 164 self))  )
            )
            (case 7
                ((send gNewAct:setMotion(MoveTo 182 164 self))  )
            )
            (case 8
                (
                (if ((send gTimers:contains(local0)))
                    (send local0:
                        dispose()
                        delete()
                    )
                )
 
                (if (== (door:cel()) 0)
                    (door:setCycle(End self))
                )(else
                    (self:changeState(9))
                )
 )
            )
            (case 9
                ((door:ignoreActors()) (send gNewAct:setMotion(MoveTo 182 154 self))  )
            )
            (case 10
                (= seconds 3  )
            )
            (case 11
                ((send gSounds:eachElementDo(172)) = seconds 2  )
            )
            (case 12
                (= global127 1  )
            )
            (case 200
                (= seconds 5  )
            )
            (case 201
                (= gNewAct (Act:new()) (send gNewAct:
                    loop(2)
                    posn(186 148)
                    view(250)
                    baseSetter(ScriptID(0 1))
                    setCycle(Walk)
                    setAvoider(Avoid)
                    init()
                )
 (ogreTheme:
                    number(5)
                    loop(-1)
                    play()
                )
 
                (if (< (send gNewAct:distanceTo(gEgo)) 10)
                    (self:changeState(1))
                )(else
                    (send gNewAct:setMotion(MoveTo 181 159 self))
                )
 )
            )
            (case 202
                ((send gNewAct:observeControl(16384)) (self:changeState(1)) )
            )
        )
    )

)
(instance killOgre of Script
    (properties)

    (method (cue)
        = global127 1
    )

)
