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


(local
    newAct_2
    newProp
    newAct
    local3

)
(instance henchCatchMusic of Sound
    (properties
        keep 1
    )
)
(instance henchChaseMusic of Sound
    (properties
        keep 1
    )
)
(instance public regBFCastle of Rgn
    (properties)

    (method (init)
        = keep 1
        Load(rsVIEW 355)
        Load(rsVIEW 356)
        Load(rsVIEW 358)
        = global189 1
        (if (< global109 5)
            = local3 92
        )
        (super:init())
    )


    (method (doit)
        (if ((((((<> global105 16) and global169) and (== (send gEgo:script()) 0)) and (send gCast:contains(newAct))) and (== (send newAct:script()) 0)) and ((((((== gGNewPropX 92) or (== gGNewPropX 91)) and (< (send gEgo:y()) 140)) and (< (send gEgo:distanceTo(newAct)) 45)) and (> Random(1 1000) 996)) or (< (send gEgo:distanceTo(newAct)) 20)))
            (send newAct:setScript(henchChaseReg))
        )
        (super:doit())
    )


    (method (dispose)
        (if (== keep 0)
            (henchCatchMusic:keep(0))
            (henchChaseMusic:keep(0))
            (send gSounds:eachElementDo(172))
            = global189 0
            (super:dispose())
        )
    )


    (method (handleEvent pEvent)
        (var temp0)
        (super:handleEvent(pEvent))
        return 
            (if ((send pEvent:claimed()))
                return 1
            )(else
                (if (== (send pEvent:type()) 128)
                    (if (Said('blow/whistle'))
                        (if ((send gEgo:has(27)))
                            Print(604 0)
                        )(else
                            proc0_19()
                        )
                    )(else
                        (if (Said('look/wall'))
                            Print(604 1)
                        )(else
                            (if ((send gCast:contains(newAct)) and Said('converse[/goon,man]'))
                                (if (global169 and not global175)
                                    (if (< (send gEgo:distanceTo(newAct)) 40)
                                        (send newAct:setScript(henchChaseReg))
                                    )(else
                                        Print(604 2)
                                    )
                                )(else
                                    Print(604 3 134 -1 20)
                                )
                            )(else
                                (if (Said('/goon,man>'))
                                    (if (not (send gCast:contains(newAct)))
                                        Print(604 4)
                                        (send pEvent:claimed(1))
                                    )(else
                                        (if (Said('look'))
                                            (if (global169 and not global175)
                                                Print(604 5)
                                            )(else
                                                Print(604 6 134 -1 20)
                                            )
                                        )(else
                                            (if (Said('awaken'))
                                                (if (global169 and not global175)
                                                    (if (< (send gEgo:distanceTo(newAct)) 40)
                                                        (send newAct:setScript(henchChaseReg))
                                                    )(else
                                                        Print(604 2)
                                                    )
                                                )(else
                                                    Print(604 7)
                                                )
                                            )(else
                                                (if (Said('get,capture'))
                                                    Print(604 8)
                                                )(else
                                                    (if (Said('kiss'))
                                                        Print(604 9)
                                                    )(else
                                                        (if (Said('deliver'))
                                                            Print(604 10)
                                                            (send pEvent:claimed(1))
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )(else
                                    (if (Said('/bird,crow>'))
                                        (if (not (send gCast:contains(newAct_2)))
                                            Print(604 11)
                                            (send pEvent:claimed(1))
                                        )(else
                                            (if (Said('look'))
                                                Print(604 12)
                                            )(else
                                                (if (Said('converse'))
                                                    Print(604 13)
                                                )(else
                                                    (if (Said('get,capture'))
                                                        Print(604 14)
                                                    )(else
                                                        (if (Said('kiss'))
                                                            Print(604 15)
                                                        )(else
                                                            (if (Said('deliver'))
                                                                Print(604 16)
                                                                (send pEvent:claimed(1))
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )


    (method (newRoom param1)
        (if (== param1 30)
            (send gSounds:eachElementDo(172))
        )
        (super:newRoom(param1))
    )


    (method (notify param1)
        (initializeRoom:changeState(param1))
    )

)
(instance initializeRoom of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (
                (if ((== gGNewPropX 91) or (== gGNewPropX 92))
                    (send (= newProp (Prop:new())):
                        view(358)
                        loop(0)
                        cel(0)
                        posn(
                            (switch (gGNewPropX)
                                (case 91
                                    258
                                )
                                (case 92
                                    275
                                )
                            )
 
                            (switch (gGNewPropX)
                                (case 91
                                    136
                                )
                                (case 92
                                    156
                                )
                            )
)
                        init()
                        stopUpd()
                        setScript(ravenStuff)
                    )
                )
 
                (if (((> global109 3) and global169) and ((((== gGNewPropX 90) or (== gGNewPropX 91)) or (== gGNewPropX 92)) or (== gGNewPropX 93)))
                    (send (= newAct (Act:new())):
                        view(145)
                        loop(4)
                        cel(
                            (if (== gGNewPropX 90)
                                1
                            )(else
                                0
                            )
)
                        posn(
                            (switch (gGNewPropX)
                                (case 90
                                    188
                                )
                                (case 91
                                    210
                                )
                                (case 92
                                    200
                                )
                                (case 93
                                    124
                                )
                            )
 
                            (switch (gGNewPropX)
                                (case 90
                                    128
                                )
                                (case 91
                                    119
                                )
                                (case 92
                                    128
                                )
                                (case 93
                                    129
                                )
                            )
)
                        init()
                        setAvoider(Avoid)
                        stopUpd()
                    )
                )
 )
            )
        )
    )

)
(instance ravenStuff of Script
    (properties)

    (method (doit)
        (if ((== gGNewPropX local3) and not (send gCast:contains(newAct_2)))
            (self:changeState(0))
        )
        (if ((send gCast:contains(newAct_2)) and (<> (send newAct_2:priority()) (send newProp:priority())))
            (send newAct_2:setPri(kernel[101]((send newProp:y()))))
        )
        (super:doit())
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (
                (if ((not (send gCast:contains(newAct_2)) and (== gGNewPropX local3)) and ((== gGNewPropX 91) or (== gGNewPropX 92)))
                    (send (= newAct_2 (Act:new())):
                        view(356)
                        ignoreActors(1)
                        illegalBits(0)
                        xStep(6)
                        yStep(2)
                        posn(
                            (switch (gGNewPropX)
                                (case 91
                                    316
                                )
                                (case 92
                                    51
                                )
                            )
 
                            (switch (gGNewPropX)
                                (case 91
                                    90
                                )
                                (case 92
                                    81
                                )
                            )
)
                        init()
                    )
                    (send newAct_2:
                        setPri(+ (send newProp:priority()) 1)
                        setCycle(Fwd)
                        setMotion(MoveTo (send newProp:x()) - (send newProp:y()) 60 self)
                    )
                )(else
                    (self:changeState(5))
                )
 )
            )
            (case 1
                ((send newAct_2:
                    setPri((send newProp:priority()))
                    setMotion(MoveTo (send newProp:x()) - (send newProp:y()) 40 self)
                )
  )
            )
            (case 2
                ((send newAct_2:
                    view(355)
                    loop(3)
                    setMotion(0)
                    setScript(preenShit)
                )
 = seconds 30  )
            )
            (case 3
                ((send newAct_2:
                    setScript(0)
                    setCycle(0)
                )
 (send newAct_2:
                    cel(0)
                    loop(2)
                    setCycle(End self)
                )
  )
            )
            (case 4
                ((send newAct_2:
                    setScript(0)
                    view(356)
                    setPri(11)
                    setLoop(-1)
                    setCycle(Fwd)
                    setMotion(MoveTo 
                        (switch (gGNewPropX)
                            (case 91
                                (316  )
                            )
                            (case 92
                                (53 )
                            )
                        )
 
                        (switch (gGNewPropX)
                            (case 91
                                (103  )
                            )
                            (case 92
                                (81 )
                            )
                        )
 self)
                )
  )
            )
            (case 5
                (
                (if ((send gCast:contains(newAct_2)))
                    (send newAct_2:dispose())
                )
 
                (if (== local3 92)
                    = local3 91
                )(else
                    = local3 92
                )
 (self:cue())  )
            )
            (case 6
                (= state -1 = seconds 30 )
            )
        )
    )

)
(instance preenShit of Script
    (properties)

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


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (
                (switch (/ Random(0 59) 10)
                    (case 1
                        ((send newAct_2:
                            loop(0)
                            setCycle(End self)
                        )
  )
                    )
                    (case 2
                        ((send newAct_2:
                            loop(1)
                            setCycle(End self)
                        )
  )
                    )
                    (default 
                        ((self:cue()) )
                    )
                )
  )
            )
            (case 1
                ((send newAct_2:loop(3)) (send (ScriptID(0 8)):setReal(self 4))  )
            )
            (case 2
                (= state -1 (self:cue()) )
            )
        )
    )

)
(instance henchChaseReg of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send newAct:
                    loop(2)
                    setCycle(End self)
                )
  )
            )
            (case 1
                ((send newAct:
                    loop(0)
                    setCycle(End self)
                )
  )
            )
            (case 2
                (= global175 1 
                (if (not (send gCast:contains(newAct)))
                    (send newAct:
                        setStep(6 3)
                        posn(
                            (switch (gGNewPropX)
                                (case 93
                                    - (send gEgo:x()) 30
                                )
                                (case 91
                                    + (send gEgo:x()) 30
                                )
                            )
 (send gEgo:y()))
                        init()
                    )
                )
 (send newAct:
                    view(141)
                    ignoreActors(1)
                    setStep(6 3)
                    setCycle(Walk)
                    setMotion(Chase gEgo 15 self)
                )
 (henchChaseMusic:
                    number(41)
                    loop(1)
                    play()
                )
  )
            )
            (case 3
                ((User:
                    canControl(0)
                    canInput(0)
                )
 (send gEgo:
                    moveSpeed(0)
                    setMotion(0)
                )
 (henchChaseMusic:dispose()) (henchCatchMusic:
                    number(42)
                    loop(1)
                    play()
                )
 = seconds 4  )
            )
            (case 4
                ((henchCatchMusic:dispose()) = global205 1 (send global2:newRoom(81)) )
            )
        )
    )

)
