(version 2)
(include "sci.sh")
(exports
    0 proc7_0
    2 doSleep
    3 showTime
    4 fixTime
    5 egoRests
    6 advanceTime
    7 egoSleeps
)
(use "Main")
(use "GloryWindow")
(use "n026")
(use "IconI")
(use "GameControls")
(use "Obj")
(script 7)


(local
    local0
    newGameControls
    theCursor
    local3

)
(procedure public (proc7_0)
    = temp4 (sleepIcon:cel(0 0))
    (send temp4:
        nsLeft(40)
        nsTop(
            (if (global121)
                96
            )(else
                79
            )
)
        cursor(5)
    )
    (send newGameControls:add(temp4))
    (send newGameControls:
        init()
        show()
        dispose()
    )
    = newGameControls 0
    (switch (theCursor)
        (case 1
            localproc_0052(10)
        )
        (case 2
            localproc_0052(30)
        )
        (case 3
            localproc_0052(60)
        )
        (case 4
            (if (proc999_5(gClientModNum 150 160 170 180 310 390 400 430 440 600 700 770 780 820))
                = newEvent (Event:new())
                (send newEvent:
                    type(1)
                    message(74)
                )
                = temp3 0
                (if (not (send gQg3MDHandler:handleEvent(newEvent)))
                    (send gRegions:handleEvent(newEvent))
                )
                (send newEvent:dispose())
                = temp2 1
            )(else
                (egoSleeps:init(5 0))
            )
        )
        (case 5
            = temp2 1
        )
    )
    (if (temp3)
        (send gGame:setCursor(temp1))
    )
    return temp2
)


(procedure (localproc_0052 param1)
    (var temp0, newEvent)
    (if (proc999_5(gClientModNum 230 400 460 510 520 530 700 810 820 830 851 852 853 854))
        = global455 param1
        = newEvent (Event:new())
        (send newEvent:
            type(1)
            message(65)
        )
        (if (not (send gQg3MDHandler:handleEvent(newEvent)))
            (send gRegions:handleEvent(newEvent))
        )
        (send newEvent:dispose())
    )(else
        (egoRests:init(param1 1))
    )
)


(instance public doSleep of Code
    (properties)

    (method (init)
        (var newEvent, temp1, temp2, temp3, temp4, temp5[60])
        = temp3 1
        = temp2 0
        = temp1 (send gGame:setCursor(999))
        (if (proc999_5(gClientModNum 150 160 170 180))
            = local3 40
            = newGameControls (GameControls:new())
            (send newGameControls:window((send ((GloryWindow:new())):
                    top(40)
                    left(65)
                    bottom(80)
                    right(256)
                    priority(15)
                    yourself()
                )
))
            = temp4 (sleepIcon:new(1 0 1 1))
            (send temp4:
                view(935)
                loop(1)
                cel(0)
                nsTop(2)
                nsLeft(2)
                modifiers(1)
            )
            (send newGameControls:add(temp4))
            = temp4 (sleepIcon:new(1 0 0 1))
            (send temp4:
                nsTop(25)
                nsLeft(25)
                cursor(1)
            )
            (send newGameControls:add(temp4))
            = temp4 (sleepIcon:new(1 0 0 2))
            (send temp4:
                nsTop(25)
                nsLeft(105)
                cursor(2)
            )
            (send newGameControls:add(temp4))
            (send newGameControls:
                init()
                show()
                dispose()
            )
            = newGameControls 0
            (switch (theCursor)
                (case 1
                    = newEvent (Event:new())
                    (send newEvent:
                        type(1)
                        message(74)
                    )
                    = temp3 0
                    (if (not (send gQg3MDHandler:handleEvent(newEvent)))
                        (send gRegions:handleEvent(newEvent))
                    )
                    (send newEvent:dispose())
                    = temp2 1
                )
                (case 2
                    = temp2 0
                )
            )
        )(else
            = local3 120
            = newGameControls (GameControls:new())
            (send newGameControls:window((send ((GloryWindow:new())):
                    top(40)
                    left(65)
                    bottom(155)
                    right(256)
                    priority(15)
                    yourself()
                )
))
            = temp4 (sleepIcon:new(2 0 1 1))
            (send temp4:
                view(935)
                loop(1)
                cel(0)
                nsTop(2)
                nsLeft(2)
                modifiers(1)
            )
            (send newGameControls:add(temp4))
            = temp4 (sleepIcon:new(2 0 0 1))
            (send temp4:
                nsLeft(40)
                nsTop(28)
                cursor(1)
            )
            (send newGameControls:add(temp4))
            = temp4 (sleepIcon:new(2 0 0 2))
            (send temp4:
                nsLeft(40)
                nsTop(45)
                cursor(2)
            )
            (send newGameControls:add(temp4))
            = temp4 (sleepIcon:new(2 0 0 3))
            (send temp4:
                nsLeft(40)
                nsTop(62)
                cursor(3)
            )
            (send newGameControls:add(temp4))
            (if (global121)
                = temp4 (sleepIcon:new(2 0 0 4))
                (send temp4:
                    nsLeft(40)
                    nsTop(79)
                    cursor(4)
                )
                (send newGameControls:add(temp4))
            )(else
                (send ((send newGameControls:window)):bottom(138))
            )
            = temp4 (sleepIcon:new(2 0 0 5))
            (send temp4:
                nsLeft(40)
                nsTop(
                    (if (global121)
                        96
                    )(else
                        79
                    )
)
                cursor(5)
            )
            (send newGameControls:add(temp4))
            (send newGameControls:
                init()
                show()
                dispose()
            )
            = newGameControls 0
            (switch (theCursor)
                (case 1
                    localproc_0052(10)
                )
                (case 2
                    localproc_0052(30)
                )
                (case 3
                    localproc_0052(60)
                )
                (case 4
                    (if (proc999_5(gClientModNum 150 160 170 180 310 390 400 430 440 600 700 770 780 820))
                        = newEvent (Event:new())
                        (send newEvent:
                            type(1)
                            message(74)
                        )
                        = temp3 0
                        (if (not (send gQg3MDHandler:handleEvent(newEvent)))
                            (send gRegions:handleEvent(newEvent))
                        )
                        (send newEvent:dispose())
                        = temp2 1
                    )(else
                        (egoSleeps:init(5 0))
                    )
                )
                (case 5
                    = temp2 1
                )
            )
        )
        (if (temp3)
            (send gGame:setCursor(temp1))
        )
        return temp2
    )

)
(instance public egoSleeps of Code
    (properties)

    (method (init param1 param2)
        (var temp0, temp1, temp2[60])
        (if (proc999_5(gClientModNum 150 160 170 180 310 390 400 430 440 600 700 770 780 820))
            = global137 0
            = temp1 global120
            (switch (paramTotal)
                (case 0
                    (fixTime:init(5))
                )
                (case 1
                    (fixTime:init(param1))
                )
                (default 
                    (fixTime:init(param1 param2))
                )
            )
            = temp0 (/ (% (- (+ global120 3600) temp1) 3600) 150)
            = gGOwnerMaxStamina[17] (send gOwner:maxStamina())
            (if (not (send gOwner:takeDamage(neg (/ (* temp0 (send gOwner:maxHealth())) 16))) and proc0_6(115))
                proc26_0(27 28)
                return 
            )
            (send gOwner:useMana(neg (/ (* temp0 (send gOwner:maxMana())) 16)))
            (if ((> temp1 global120) and proc0_6(31))
                proc0_11()
            )
            (if (< temp0 2)
                (send gQg3Messager:say(0 0 12 1 0 7))
            )(else
                (send gQg3Messager:say(0 0 3 1 0 7))
            )
        )(else
            (send gQg3Messager:say(3 6 11 0 0 7))
        )
    )

)
(instance public showTime of Code
    (properties)

    (method (init)
        (var temp0, newEvent, temp2, temp3, temp4, temp5[30], temp35[7])
        = temp0 global122
        Message(0 7 0 0 10 1 @temp5)
        Format(@temp35 "%d" + global122 1)
        (if ((<> global123 6) or (> global120 500))
            ++temp0
        )
        = temp2 global120
        (if (>= temp2 2750)
            = temp2 (- temp2 3600)
        )
        (if (< temp2 790)
            = temp2 (+ temp2 1800)
        )
        = temp2 (- temp2 1800)
        = temp3 (/ temp2 16)
        = temp4 Abs((/ temp2 24))
        = temp4 (+ temp4 3)
        = temp3 (+ temp3 71)
        = local0 (send ((GloryWindow:new())):
                top(0)
                left(84)
                bottom(74)
                right(240)
                priority(15)
                open()
                yourself()
            )
        Display(@temp5 102 17 100 0 66 106 156 105 999)
        Display(@temp35 102 17 100 40 66 106 156 105 999)
        (if (not global121)
            DrawCel(938 1 0 0 3)
            DrawCel(938 2 0 temp3 temp4)
            DrawCel(938 0 0 0 3)
        )(else
            DrawCel(938 4 0 0 3)
            DrawCel(938 5 0 temp3 temp4)
            DrawCel(938 3 0 0 3)
        )
        (while (1)
            = newEvent (Event:new())
            (if ((((== (send newEvent:type) 4) and proc999_5((send newEvent:message) 13 27)) or (== (send newEvent:type) 1)) or (== (send newEvent:type) 256))
                break
            )
            (send newEvent:dispose())
        )
        (send newEvent:dispose())
        (send local0:dispose())
        (self:dispose())
    )

)
(instance public fixTime of Code
    (properties)

    (method (init param1 param2)
        (var temp0, temp1)
        = temp1 global120
        (if (>= paramTotal 1)
            = global120 (* 150 param1)
            = global124 GetTime(1)
            (if (>= paramTotal 2)
                = global120 (+ global120 (/ (* 150 param2) 60))
            )
        )
        = temp0 global123
        (if (< (^ global120 $0001) 300)
            = global123 6
        )(else
            (if (< (^ global120 $0001) 750)
                = global123 7
            )(else
                (if (< (^ global120 $0001) 1200)
                    = global123 0
                )(else
                    (if (< (^ global120 $0001) 1650)
                        = global123 1
                    )(else
                        (if (< (^ global120 $0001) 2100)
                            = global123 2
                        )(else
                            (if (< (^ global120 $0001) 2550)
                                = global123 3
                            )(else
                                (if (< (^ global120 $0001) 3000)
                                    = global123 4
                                )(else
                                    (if (< (^ global120 $0001) 3450)
                                        = global123 5
                                    )(else
                                        = global123 6
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
        (if (< global120 temp1)
            proc0_11()
        )
        (if ((== global123 6) and (<> temp0 6))
            (if (== ++global137 1)
                (send gQg3Messager:say(0 0 6 1 0 7))
            )(else
                (send gQg3Messager:say(0 0 7 1 0 7))
            )
        )
    )

)
(instance public egoRests of Code
    (properties)

    (method (init param1 param2)
        (if (((<= global122 global106) and (<= global120 (+ global105 150))) and (> gGOwnerMaxStamina[17] (/ (send gOwner:maxStamina()) 2)))
            (send gQg3Messager:say(0 0 8 1 0 7))
        )(else
            = global106 global122
            = global105 global120
            (send gOwner:
                useStamina(neg param1)
                useMana(neg / param1 5)
                takeDamage(neg / (+ param1 5) 15)
            )
            (if (param2)
                (if (proc0_6(115))
                    (send gQg3Messager:say(0 0 13 1 0 7))
                )(else
                    (send gQg3Messager:say(0 0 9 1 0 7))
                )
            )
            (advanceTime:init(0 param1))
        )
    )

)
(instance public advanceTime of Code
    (properties)

    (method (init param1 param2)
        (var temp0)
        (switch (paramTotal)
            (case 1
                = temp0 (+ global120 (* 150 param1))
            )
            (case 2
                = temp0 (+ (+ global120 (* 150 param1)) (/ (* 150 param2) 60))
            )
        )
        = temp0 (^ temp0 $0001)
        (if (((< global120 1100) and (> temp0 1200)) or ((< global120 2500) and ((> temp0 2600) or (< temp0 global120))))
            (send gOwner:eatMeal())
        )
        (while (>= temp0 3600)
            = temp0 (- temp0 3600)
            ++global122
        )
        (fixTime:init((/ temp0 150) (/ (* (% temp0 150) 60) 150)))
    )

)
(instance sleepIcon of IconI
    (properties
        view 935
        loop 2
        cel 0
    )

    (method (new param1 param2 param3 param4)
        (var temp0, temp1, temp2)
        = temp0 Clone(self)
        (if (paramTotal)
            = temp1 Message(2 7 param1 param2 param3 param4)
            (send temp0:message(Memory(2 temp1)))
            Message(0 7 param1 param2 param3 param4 (send temp0:message))
        )
        return temp0
    )


    (method (dispose)
        Memory(3 message)
        (super:dispose())
    )


    (method (show)
        = nsRight (+ nsLeft 
            (if (== loop 1)
                0
            )(else
                (+ local3 20)
            )
)
        = nsBottom 
            (if (== loop 1)
                nsTop
            )(else
                (+ nsTop 15)
            )
        DrawCel(view loop cel nsLeft nsTop -1)
        Display(message 100 
            (if (== loop 1)
                nsLeft
            )(else
                + nsLeft 20
            )
 
            (if (== loop 1)
                + nsTop 2
            )(else
                nsTop
            )
 105 123 102 17 101 modifiers 106 
            (if (== loop 1)
                189
            )(else
                local3
            )
)
    )


    (method (select)
        return 
            (if (<> loop 1)
                = theCursor cursor
                (send newGameControls:state((& (send newGameControls:state) $ffdf)))
            )(else
                return 0
            )
    )


    (method (highlight param1)
        (var temp0)
        (if (<> loop 1)
            (if (param1)
                DrawCel(view loop 1 nsLeft nsTop -1)
                = temp0 46
            )(else
                DrawCel(view loop 0 nsLeft nsTop -1)
                = temp0 17
            )
            Display(message 100 
                (if (== loop 1)
                    nsLeft
                )(else
                    + nsLeft 20
                )
 nsTop 105 123 102 temp0 101 modifiers 106 
                (if (== loop 1)
                    189
                )(else
                    local3
                )
)
        )
    )

)
