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


(local
    local0
    local1
    local2
    local3
    local4
    local5
    local6
    newView
    newProp
    newAct

)
(instance cupidCage of Cage
    (properties)
)
(instance theme of Sound
    (properties)
)
(instance public Room3 of Rm
    (properties
        picture 3
    )

    (method (init)
        = north 27
        = south 9
        = east 4
        = west 2
        = horizon 75
        = global101 0
        (if (global100)
            = picture 103
        )
        (self:setRegions(507))
        (send gEgo:
            view(2)
            init()
        )
        (send gEgo:
            edgeHit(0)
            setScript(fall)
        )
        (super:init())
        (send global2:setScript(egoActions))
        Load(rsVIEW 7)
        Load(rsVIEW 5)
        Load(rsVIEW 6)
        Load(rsVIEW 19)
        Load(rsVIEW 17)
        Load(rsVIEW 21)
        Load(rsSOUND 51)
        (cupidCage:
            top(118)
            left(118)
            bottom(135)
            right(235)
            init()
        )
        = newProp (Prop:new())
        (send newProp:
            view(650)
            loop(0)
            cel(1)
            posn(209 133)
            setCycle(Fwd)
            cycleSpeed(0)
            ignoreActors()
            init()
        )
        (if ((<= Random(1 100) 33) and (send ((Inv:at(14))):ownedBy(202)))
            = newAct (Act:new())
            (send newAct:
                view(160)
                posn(5 72)
                illegalBits(0)
                setPri(7)
                ignoreHorizon()
                setCycle(Fwd)
                xStep(4)
                yStep(2)
                init()
            )
            (send newAct:setScript(doCupid))
        )
        (if ((send ((Inv:at(14))):ownedBy(3)))
            (send ((Inv:at(14))):moveTo(202))
        )
        (switch (gPicture)
            (case 2
                (
                (if (<= (send gEgo:y()) horizon)
                    (send gEgo:
                        x(1)
                        y(+ horizon (+ (send gEgo:yStep()) 1))
                    )
                )(else
                    (send gEgo:x(1))
                )
 )
            )
            (case 4
                (
                (if (< (send gEgo:y()) horizon)
                    (send gEgo:posn(318 (+ horizon (+ (send gEgo:yStep()) 1))))
                )(else
                    (send gEgo:posn(318 (send gEgo:y())))
                )
 )
            )
            (case 9
                ((send gEgo:y(188))  )
            )
            (case 27
                ((send gEgo:posn((send gEgo:x()) (+ horizon 2)))  )
            )
            (case 0
                ((send gEgo:
                    x(98)
                    y(176)
                )
 )
            )
        )
    )


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


    (method (handleEvent pEvent)
        (if ((send pEvent:claimed()))
            return 1
        )
        return 
            (if (== (send pEvent:type()) 128)
                (if (Said('look<under,in/water'))
                    Print(3 0)
                )(else
                    (if (Said('look/pool') or Said('look/water'))
                        (if (== (send gEgo:view()) 2)
                            Print(3 1)
                        )(else
                            Print(3 2)
                        )
                    )(else
                        (if ((Said('look/room') or Said('look/around')) or Said('look[<around][/!*]'))
                            (if (== (send gEgo:view()) 2)
                                Print(3 3)
                            )(else
                                Print(3 4)
                            )
                        )(else
                            (if ((Said('fish<enter') or Said('capture/fish')) or Said('cast/pole'))
                                Print(3 5)
                            )(else
                                (if (Said('look/column'))
                                    Print(3 6)
                                )(else
                                    (if (Said('get/water'))
                                        Print(3 7)
                                    )(else
                                        (if ((Said('enter/bathe') or Said('bathe,dive')) or Said('enter/bathe'))
                                            (if (== (send gEgo:view()) 2)
                                                Print(3 8)
                                            )(else
                                                Print(3 9)
                                            )
                                        )(else
                                            (if (Said('look/stair'))
                                                Print(3 10)
                                            )(else
                                                (if (Said('(,(climb,get<out)'))
                                                    (if (<> (send gEgo:view()) 2)
                                                        Print(3 10)
                                                    )(else
                                                        Print(3 11)
                                                    )
                                                )(else
                                                    (if (Said('hop,dive/pool,water'))
                                                        Print(3 12)
                                                    )(else
                                                        (if (Said('drink') or Said('get/drink'))
                                                            (if (<> (send gEgo:view()) 2)
                                                                Print(3 13)
                                                            )(else
                                                                (if (& (= local0 proc0_2(gEgo 20)) $0008)
                                                                    = local4 1
                                                                    (egoActions:changeState(10))
                                                                )(else
                                                                    Print(800 1)
                                                                )
                                                            )
                                                        )(else
                                                            (if (Said('get/arrow,arrow'))
                                                                (if ((send ((Inv:at(14))):ownedBy(3)) and (((== local1 2) or (== local1 1)) or (== local1 7)))
                                                                    (if (< (send gEgo:distanceTo(newView)) 10)
                                                                        (send ((Inv:at(14))):moveTo(gEgo))
                                                                        (send gGame:changeScore(2))
                                                                        (egoActions:changeState(1))
                                                                    )(else
                                                                        Print(800 1)
                                                                    )
                                                                )(else
                                                                    (if ((send gEgo:has(14)))
                                                                        Print(3 14)
                                                                    )(else
                                                                        (if (not (send gCast:contains(newAct)) and not (send ((Inv:at(14))):ownedBy(3)))
                                                                            Print(3 15)
                                                                        )(else
                                                                            (if (<> local1 2)
                                                                                Print(3 16)
                                                                            )(else
                                                                                (if ((send gEgo:has(14)))
                                                                                    Print(3 17)
                                                                                )(else
                                                                                    Print(3 18)
                                                                                )
                                                                            )
                                                                        )
                                                                    )
                                                                )
                                                            )(else
                                                                (if (Said('rob/arrow'))
                                                                    Print(3 19)
                                                                )(else
                                                                    (if (Said('look/dirt'))
                                                                        (if ((send ((Inv:at(14))):ownedBy(3)))
                                                                            Print(3 20)
                                                                        )(else
                                                                            Print(3 21)
                                                                        )
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )(else
                0
            )
    )


    (method (newRoom param1)
        (if ((send ((Inv:at(14))):ownedBy(3)))
            (send ((Inv:at(14))):moveTo(202))
        )
        (super:newRoom(param1))
    )

)
(instance fall of Script
    (properties)

    (method (doit)
        (super:doit())
        (if ((== local3 0) and (== local4 0))
            (if ((== (send gEgo:onControl(0)) 1) and (<> (send gEgo:view()) 21))
                (send gEgo:view(2))
            )(else
                (if ((& (send gEgo:onControl(0)) $0004) and (== (send gEgo:view()) 2))
                    = local3 1
                    (fall:changeState(1))
                )(else
                    (if (& (send gEgo:onControl(1)) $0800)
                        (send gEgo:view(5))
                    )(else
                        (if (& $0200 (send gEgo:onControl(1)))
                            (send gEgo:view(6))
                        )(else
                            (if (& $0008 (send gEgo:onControl(1)))
                                (send gEgo:view(7))
                            )(else
                                (if (& $0010 (send gEgo:onControl(0)))
                                    (send gEgo:view(2))
                                )
                            )
                        )
                    )
                )
            )
        )(else
            (if ((== (send gEgo:onControl(1)) 4096) and (< (fall:state()) 2))
                (send gEgo:setMotion(0))
                (self:changeState(2))
                (if ((send gTimers:contains(local5)))
                    (send local5:
                        dispose()
                        delete()
                    )
                )
            )
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 1
                ((send gSounds:eachElementDo(172)) (send ((Sound:new())):
                    number(51)
                    loop(1)
                    play()
                )
 proc0_10() (send gEgo:
                    view(17)
                    loop(+ (& (send gEgo:loop()) $0001) 2)
                    illegalBits(0)
                    setCycle(Fwd)
                )
 = local5 (Timer:setCycle(self 20)) (send gEgo:
                    xStep(8)
                    yStep(4)
                    setMotion(MoveTo 170 122)
                )
  )
            )
            (case 2
                ((send gEgo:
                    view(19)
                    xStep(2)
                    yStep(1)
                    setMotion(0)
                    loop(& (send gEgo:loop()) $0001)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 3
                (= local3 0 (send gEgo:view(7)) (send gEgo:
                    illegalBits(-1)
                    ignoreControl(8 4096)
                    setCycle(Walk)
                )
 = seconds 2  )
            )
            (case 4
                ((send gEgo:illegalBits(32768)) proc0_11() (self:changeState(0)) )
            )
        )
    )

)
(instance doCupid of Script
    (properties)

    (method (init param1)
        Load(rsVIEW 160)
        Load(rsVIEW 161)
        Load(rsVIEW 162)
        Load(rsVIEW 163)
        Load(rsVIEW 165)
        Load(rsVIEW 166)
        Load(rsVIEW 167)
        Load(rsVIEW 509)
        (super:init(param1))
    )


    (method (doit)
        (super:doit())
        (if ((== state 5) and ((send gEgo:inRect(220 100 305 140)) or (< (send gEgo:distanceTo(newAct)) 48)))
            (if ((> (send gEgo:x()) 210) and (< (send gEgo:y()) 140))
                (self:changeState(30))
            )(else
                (self:changeState(20))
            )
        )
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= local1 0 (theme:
                    number(9)
                    loop(1)
                    play()
                )
 (send newAct:
                    ignoreActors()
                    setMotion(MoveTo 164 70 self)
                )
  )
            )
            (case 1
                (
                (if ((send gEgo:inRect(171 101 317 183)))
                    (self:changeState(10))
                )(else
                    (send newAct:
                        setPri(-1)
                        setMotion(MoveTo 250 119 self)
                    )
                )
 )
            )
            (case 2
                (= local1 3 (send newAct:
                    view(162)
                    ignoreActors(0)
                    setLoop(0)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 3
                ((send newAct:
                    setLoop(2)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 4
                ((send newAct:
                    ignoreActors(1)
                    view(165)
                    xStep(6)
                    setLoop(1)
                    setCycle(End)
                )
 = newView (View:new()) (send ((Inv:at(14))):moveTo(3)) (send newView:
                    ignoreActors()
                    view(509)
                    x(+ (send newAct:x()) 10)
                    y((send newAct:y()))
                    stopUpd()
                    init()
                )
 (send newAct:setMotion(MoveTo 206 126 self))  )
            )
            (case 5
                (= local1 4 (send newAct:
                    view(167)
                    setLoop(-1)
                    observeControl(1)
                    xStep(1)
                    yStep(1)
                    loop(1)
                    cycleSpeed(1)
                    setCycle(Fwd)
                    setMotion(Wander 6)
                    moveSpeed(1)
                )
 (send newAct:observeBlocks(cupidCage)) = local6 (Timer:setReal(self 15))  )
            )
            (case 6
                (= local1 5 (self:changeState(40))  )
            )
            (case 10
                ((send newAct:setMotion(MoveTo 61 83 self)) 
                (if ((send gTimers:contains(local6)))
                    (send local6:
                        dispose()
                        delete()
                    )
                )
 )
            )
            (case 11
                ((send newAct:setMotion(MoveTo 4 72 self))  )
            )
            (case 12
                ((send newAct:dispose())  )
            )
            (case 20
                (Print(3 35) 
                (if ((send gTimers:contains(local6)))
                    (send local6:
                        dispose()
                        delete()
                    )
                )
 (send newAct:ignoreBlocks(cupidCage)) (send newAct:
                    ignoreControl(1)
                    setLoop(0)
                    xStep(3)
                    yStep(2)
                    moveSpeed(0)
                    setMotion(MoveTo 230 129 self)
                )
 = local1 2  )
            )
            (case 21
                ((send newAct:
                    view(166)
                    setCel(0)
                )
 (send newAct:setMotion(MoveTo 240 129)) (send newAct:
                    cycleSpeed(0)
                    setCycle(End self)
                )
  )
            )
            (case 22
                ((send newAct:
                    view(164)
                    cel(0)
                    setLoop(1)
                    setCycle(End self)
                )
  )
            )
            (case 23
                ((send newAct:
                    view(161)
                    xStep(4)
                    yStep(3)
                    setPri(7)
                    setLoop(1)
                    setCycle(Fwd)
                    setMotion(MoveTo 168 70 self)
                )
  )
            )
            (case 24
                ((send newAct:setMotion(MoveTo 41 70 self))  )
            )
            (case 25
                ((send newAct:dispose())  )
            )
            (case 30
                (Print(3 35) 
                (if ((send gTimers:contains(local6)))
                    (send local6:
                        dispose()
                        delete()
                    )
                )
 (send newAct:
                    ignoreBlocks(cupidCage)
                    ignoreControl(1)
                    xStep(6)
                    yStep(2)
                    setLoop(1)
                    moveSpeed(0)
                    setMotion(MoveTo 100 129 self)
                )
 = local1 2  )
            )
            (case 31
                ((send newAct:
                    xStep(3)
                    setMotion(MoveTo 85 129)
                )
 (send newAct:
                    view(166)
                    setLoop(1)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 32
                ((send newAct:
                    posn(80 125)
                    loop(3)
                    setCycle(End self)
                )
  )
            )
            (case 33
                ((send newAct:
                    view(164)
                    cel(0)
                    setLoop(1)
                    setCycle(End self)
                )
  )
            )
            (case 34
                (= local1 1 (send newAct:
                    view(161)
                    xStep(4)
                    yStep(3)
                    setPri(7)
                    setLoop(1)
                    setCycle(Fwd)
                    setMotion(MoveTo 41 70 self)
                )
  )
            )
            (case 35
                ((self:changeState(11))  )
            )
            (case 40
                ((send newAct:ignoreBlocks(cupidCage)) (send newAct:
                    ignoreControl(1)
                    setLoop(0)
                    xStep(3)
                    yStep(2)
                    moveSpeed(0)
                    setMotion(MoveTo 230 129 self)
                )
 (send ((Inv:at(14))):moveTo(202))  )
            )
            (case 41
                ((send newAct:
                    view(166)
                    setCel(0)
                )
 (send newAct:setMotion(MoveTo 240 129)) (send newAct:
                    cycleSpeed(0)
                    setCycle(End self)
                )
  )
            )
            (case 42
                ((send newAct:
                    ignoreActors()
                    posn(- (send newView:x()) 10 - (send newView:y()) 4)
                )
 (send newAct:
                    view(163)
                    loop(0)
                    cel(0)
                    setCycle(CT 5 1 self)
                )
  )
            )
            (case 43
                ((send newView:dispose()) (send newAct:
                    cel(6)
                    setCycle(End self)
                )
  )
            )
            (case 44
                (= local1 0 (send newAct:
                    view(160)
                    setLoop(1)
                    setCel(0)
                    setCycle(Fwd)
                )
 (send newAct:
                    setPri(7)
                    setMotion(MoveTo 171 80 self)
                )
  )
            )
            (case 45
                ((self:changeState(10)) )
            )
        )
    )


    (method (handleEvent pEvent)
        (var gInvSaidMe)
        (if ((send pEvent:claimed()))
            return 1
        )
        return 
            (if (== (send pEvent:type()) 128)
                (if (Said('look/cupid'))
                    (if (== local1 0)
                        Print(3 22)
                    )(else
                        (if (== local1 4)
                            Print(3 23)
                        )(else
                            (if (== local1 1)
                                Print(3 24)
                            )(else
                                (if (== local1 2)
                                    Print(3 25)
                                )(else
                                    (if (== local1 3)
                                        Print(3 26)
                                    )(else
                                        (if (== local1 5)
                                            Print(3 27)
                                        )
                                    )
                                )
                            )
                        )
                    )
                )(else
                    (if (Said('play/cupid'))
                        Print(3 28)
                    )(else
                        (if (Said('get/cupid'))
                            Print(3 29)
                        )(else
                            (if (Said('kiss'))
                                Print(3 30)
                            )(else
                                (if (Said('converse'))
                                    (if (not (send gCast:contains(newAct)))
                                        (send pEvent:claimed(0))
                                    )(else
                                        (if (== local1 0)
                                            Print(3 31)
                                        )(else
                                            (if (== local1 2)
                                                Print(3 32)
                                            )(else
                                                (if (== local1 4)
                                                    (if (< (send gEgo:distanceTo(newAct)) 40)
                                                        Print(3 33)
                                                        (if ((> (send gEgo:x()) 210) and (< (send gEgo:y()) 140))
                                                            (self:changeState(30))
                                                        )(else
                                                            (self:changeState(20))
                                                        )
                                                    )(else
                                                        Print(3 31)
                                                    )
                                                )(else
                                                    Print(3 31)
                                                )
                                            )
                                        )
                                    )
                                )(else
                                    (if (Said('deliver>') and (= gInvSaidMe (send gInv:saidMe())))
                                        (if ((send gEgo:has((send gInv:indexOf((= gInvSaidMe (send gInv:saidMe())))))))
                                            Print(3 34)
                                        )(else
                                            proc0_19()
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )(else
                0
            )
    )

)
(instance egoActions of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 1
                (proc0_10() proc0_3(gEgo newView) (send gEgo:
                    view(21)
                    setMotion(0)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 2
                (= global182 1 (send newView:dispose()) (send gEgo:setCycle(Beg self))  )
            )
            (case 3
                ((send gEgo:
                    view(2)
                    setCycle(Walk)
                )
 proc0_11()  )
            )
            (case 10
                (proc0_10() (send gEgo:
                    view(21)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 11
                (= seconds 5 = global120 Print(3 36 134 -1 20 172)  )
            )
            (case 12
                ((send gEgo:setCycle(Beg self))  )
            )
            (case 13
                (proc0_23() proc0_11() (send gEgo:
                    view(2)
                    setCycle(Walk)
                )
 = local4 0 )
            )
        )
    )

)
