(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "Sound")
(use "SRDialog")
(use "Cycle")
(use "InvI")
(use "User")
(use "PV")
(use "Obj")
(script 994)



(procedure (localproc_0a56 param1)
    (var temp0, temp1[40], temp41[40], temp81[40])
    = temp0 1
    kernel[103](0 global30 @temp1)
    kernel[103](1 @temp41)
    (if (kernel[103](2 @temp1 @temp41) and kernel[103](3 @temp41))
        Format(@temp81 994 6 
            (if (param1)
                "SAVE GAME"
            )(else
                "GAME"
            )
 @temp41)
        (if (== (= temp0 
            (if (param1)
                Print(@temp81 66 0 162 "OK" 1 162 "Cancel" 0 162 "Change Directory" 2)
            )(else
                Print(@temp81 66 0 162 "OK" 1)
            )
) 2)
            = temp0 proc990_0(global30)
        )
    )
    return temp0
)


(instance cast of Set
    (properties)
)
(instance sounds of Set
    (properties)
)
(instance regions of List
    (properties)
)
(instance addToPics of Set
    (properties)
)
(instance controls of Controls
    (properties)
)
(instance timers of Set
    (properties)
)
(instance ego of Ego
    (properties)
)
(class Game of Obj
    (properties)

    (method (init)
        (var theMotion)
        = theMotion Motion
        = theMotion Sound
        = theMotion Save
        = global3 6
        = global50 10
        = gEgo ego
        (send (= gCast cast):add())
        (send (= gSounds sounds):add())
        (send (= gRegions regions):add())
        (send (= gAddToPics addToPics):add())
        (send (= gTimers timers):add())
        = global30 kernel[104]()
        (Inv:init())
        (User:alterEgo(gEgo))
    )


    (method (doit)
        (send gSounds:eachElementDo(252))
        (send gTimers:eachElementDo(120))
        Animate((send gCast:elements()) 1)
        (send gCast:eachElementDo(192))
        (User:doit())
        (send gRegions:eachElementDo(120))
        (if (<> gTheGGNewPropX gGNewPropX)
            (self:newRoom(gTheGGNewPropX))
        )
        (send gTimers:eachElementDo(192))
        (send gSounds:eachElementDo(192))
        GameIsRestarting(0)
    )


    (method (showSelf)
        (send gRegions:showSelf())
    )


    (method (play)
        = gGame self
        = global20 999
        = global21 997
        = global22 1
        = global26 1
        = global23 4
        = global30 kernel[104]()
        (if (not GameIsRestarting())
            kernel[98](global30)
        )
        (self:setCursor(global21 1))
        (self:init())
        (self:setCursor(global20 HaveMouse()))
        (while (not global4)
            (self:doit())
            = global18 Wait(global3)
        )
    )


    (method (replay)
        (if (gNewEvent)
            (send gNewEvent:dispose())
        )
        (if (gTheNewDialog)
            (send gTheNewDialog:species)
        )
        (send gCast:eachElementDo(178 RU))
        (send gGame:setCursor(global21 1))
        DrawPic((send global2:curPic()) 5)
        (if ((send global2:controls()))
            (send ((send global2:controls())):draw())
        )
        (send gAddToPics:eachElementDo(170))
        (send gGame:setCursor(global20 HaveMouse()))
        (SL:doit())
        DoSound(7)
        (Sound:pause(0))
        (while (not global4)
            (self:doit())
            = global18 Wait(global3)
        )
    )


    (method (newRoom theGTheGGNewPropX)
        (var temp0[4], temp4, temp5)
        (send gAddToPics:dispose())
        (send gCast:eachElementDo(172))
        (send gCast:eachElementDo(192))
        (send gTimers:eachElementDo(192))
        (send gRegions:eachElementDo(172))
        Animate(0)
        = gTheGGNewPropX theGTheGGNewPropX
        = gPicture gGNewPropX
        = gGNewPropX theGTheGGNewPropX
        = temp4 (self:setCursor(global21 1))
        (self:
            startRoom(gGNewPropX)
            checkAni()
            setCursor(temp4 HaveMouse())
        )
        SetSynonyms(gRegions)
        (while ((send (= temp5 (Event:new(3))):type()))
            (send temp5:dispose())
        )
        (send temp5:dispose())
    )


    (method (startRoom param1)
        (if (global14)
            SetDebug()
        )
        (send (= global2 ScriptID(param1)):init())
        (send gRegions:addToFront(global2))
    )


    (method (restart)
        (if (gTheNewDialog)
            (send gTheNewDialog:dispose())
        )
        RestartGame()
    )


    (method (restore param1)
        (var temp0[20], temp20, temp21, temp22)
        Load(rsFONT global23)
        = temp21 (self:setCursor(global20))
        = temp22 (Sound:pause(1))
        (if (localproc_0a56(1))
            (if (gTheNewDialog)
                (send gTheNewDialog:dispose())
            )
            (if (<> (= temp20 (Restore:doit(rest param1))) -1)
                (self:setCursor(global21 1))
                (if (kernel[105](name temp20 global28))
                    (send gCast:eachElementDo(172))
                    (send gCast:eachElementDo(192))
                    RestoreGame(name temp20 global28)
                )(else
                    Print(994 1 66 0 162 "OK" 1)
                    (self:setCursor(temp21 HaveMouse()))
                )
            )
            localproc_0a56(0)
        )
        (Sound:pause(temp22))
    )


    (method (save)
        (var temp0[20], temp20, temp21, temp22)
        Load(rsFONT global23)
        = temp22 (Sound:pause(1))
        (if (localproc_0a56(1))
            (if (gTheNewDialog)
                (send gTheNewDialog:dispose())
            )
            (if (<> (= temp20 (Save:doit(@temp0))) -1)
                = temp21 (self:setCursor(global21 1))
                (if (not SaveGame(name temp20 @temp0 global28))
                    Print(994 0 66 0 162 "OK" 1)
                )
                (self:setCursor(temp21 HaveMouse()))
            )
            localproc_0a56(0)
        )
        (Sound:pause(temp22))
    )


    (method (changeScore param1)
        = global15 (+ global15 param1)
        (SL:doit())
    )


    (method (handleEvent pEvent)
        (send gRegions:eachElementDo(232 pEvent))
    )


    (method (showMem)
        (var temp0[100])
        Print(Format(@temp0 "Free Heap: %u Bytes\nLargest ptr: %u Bytes\nFreeHunk: %u KBytes\nLargest hunk: %u Bytes" MemoryInfo(1) MemoryInfo(0) >> MemoryInfo(3) $0006 MemoryInfo(2)))
    )


    (method (setSpeed param1)
        (var temp0)
        = temp0 global3
        = global3 param1
        return temp0
    )


    (method (setCursor param1 param2)
        (var temp0)
        = temp0 global19
        = global19 param1
        (if (== paramTotal 1)
            SetCursor(param1)
        )(else
            SetCursor(param1 param2)
        )
        return temp0
    )


    (method (checkAni)
        (var temp0)
        Animate((send gCast:elements()) 0)
        Wait(0)
        Animate((send gCast:elements()) 0)
        (while (not (> Wait(0) global50) or (== (= temp0 (send gCast:firstTrue(358))) 0))
        )
    )


    (method (wordFail param1)
        (var temp0[100])
        Print(Format(@temp0 994 2 param1))
        return 0
    )


    (method (syntaxFail)
        Print(994 3)
    )


    (method (semanticFail)
        Print(994 4)
    )


    (method (pragmaFail)
        Print(994 5)
    )

)
(class Rgn of Obj
    (properties
        script 0
        number 0
        timer 0
        keep 0
        initialized 0
    )

    (method (init)
        (if (not initialized)
            = initialized 1
            (if (not (send gRegions:contains(self)))
                (send gRegions:addToEnd(self))
            )
            (super:init())
        )
    )


    (method (doit)
        (if (script)
            (send script:doit())
        )
    )


    (method (dispose)
        (if (not keep)
            (send gRegions:delete(self))
            (if (IsObject(script))
                (send script:dispose())
            )
            (if (IsObject(timer))
                (send timer:dispose())
            )
            DisposeScript(number)
        )
    )


    (method (handleEvent pEvent)
        (if (script)
            (send script:handleEvent(pEvent))
        )
    )


    (method (setScript theScript)
        (if (script)
            (send script:dispose())
        )
        (if (= script theScript)
            (send (= script theScript):init(self))
        )
    )


    (method (cue)
        (if (script)
            (send script:cue())
        )
    )


    (method (newRoom)
    )


    (method (notify)
    )

)
(class Rm of Rgn
    (properties
        script 0
        number 0
        timer 0
        keep 0
        initialized 0
        picture 0
        style -1
        horizon 0
        controls 0
        north 0
        east 0
        south 0
        west 0
        curPic 0
    )

    (method (init)
        (var temp0)
        = number gGNewPropX
        = controls controls
        (if (picture)
            (self:drawPic(picture))
        )
        (switch ((send ((User:alterEgo())):edgeHit()))
            (case 1
                ((send ((User:alterEgo())):y(188))  )
            )
            (case 4
                ((send ((User:alterEgo())):x((- 319 (send ((User:alterEgo())):xStep()))))  )
            )
            (case 3
                ((send ((User:alterEgo())):y((+ horizon (send ((User:alterEgo())):yStep()))))  )
            )
            (case 2
                ((send ((User:alterEgo())):x(1)) )
            )
        )
        (send gEgo:edgeHit(0))
    )


    (method (doit)
        (if (script)
            (send script:doit())
        )
        (switch ((send ((User:alterEgo())):edgeHit()))
            (case 1
                (
                (if (north)
                    (self:newRoom(north))
                )
 )
            )
            (case 2
                (
                (if (east)
                    (self:newRoom(east))
                )
 )
            )
            (case 3
                (
                (if (south)
                    (self:newRoom(south))
                )
 )
            )
            (case 4
                (
                (if (west)
                    (self:newRoom(west))
                )
 )
            )
        )
    )


    (method (dispose)
        (if (controls)
            (send controls:dispose())
        )
        (super:dispose())
    )


    (method (handleEvent pEvent)
        (super:handleEvent(pEvent))
        (if (controls)
            (send controls:handleEvent(pEvent))
        )
    )


    (method (newRoom theGTheGGNewPropX)
        (send gRegions:
            delete(self)
            eachElementDo(444 theGTheGGNewPropX)
            addToFront(self)
        )
        = gTheGGNewPropX theGTheGGNewPropX
        (super:newRoom(theGTheGGNewPropX))
    )


    (method (setRegions param1)
        (var temp0, temp1)
        = temp0 0
        (while (< temp0 paramTotal)
            = temp1 ScriptID(param1[temp0])
            (send temp1:number(param1[temp0]))
            (if (not (send temp1:initialized()))
                (send temp1:init())
            )
            ++temp0
        )
    )


    (method (drawPic theCurPic param2)
        DrawPic(= curPic theCurPic 
            (if (== paramTotal 2)
                param2
            )(else
                (if (<> style -1)
                    style
                )(else
                    global17
                )
            )
)
    )

)
(class SL of Obj
    (properties
        state 0
        code 0
    )

    (method (doit)
        (var temp0[41])
        (if (code)
            (send code:doit(@temp0))
            DrawStatus(
                (if (state)
                    @temp0
                )(else
                    0
                )
)
        )
    )


    (method (enable)
        = state 1
        (self:doit())
    )


    (method (disable)
        = state 0
        (self:doit())
    )

)
(instance RU of Code
    (properties)

    (method (doit param1)
        (var temp0)
        (if ((send param1:underBits()))
            = temp0 (& (= temp0 (| (= temp0 (send param1:signal())) $0001)) $fffb)
            (send param1:
                underBits(0)
                signal(temp0)
            )
        )
    )

)
