SCRIPT_START
NOP
// TERMINATE_THIS_CUSTOM_SCRIPT
SCRIPT_NAME NUBE
//main
{   

    
    main:    
        GOSUB init
        GOSUB read_ini    
        GOSUB load_sky
        GOSUB draw_sky //loop
        GOSUB delete_sky
        GOSUB wait
    GOTO main

    draw_sky:
        CLEO_CALL get_ids 0 () currID nextID show_hide_bitmask
        CLEO_CALL set_status_array 0 (currID, nextID, show_hide_bitmask) 

        WHILE IS_PC_VERSION
        WAIT 0            
            IF CLEO_CALL is_player_near_save_pickup_or_in_interior 0
                RETURN
            ELSE

                GOSUB update_position
                IF IS_LOCAL_VAR_BIT_SET_CONST misc_flags BIT_FLAG_GET_WEATHER_REPORT_EACH_FRAME
                        CLEO_CALL get_ids 0 () currID nextID show_hide_bitmask
                        CLEO_CALL set_status_array 0 (currID, nextID, show_hide_bitmask) 
                        GOSUB clean_unused_skies     
                ELSE
                    READ_MEMORY WEATHER_INTERPOLATION_ADDRESS 4 0 x
                    IF x >= 0.0
                    AND x <= 0.05
                        CLEO_CALL get_ids 0 () currID nextID show_hide_bitmask
                        CLEO_CALL set_status_array 0 (currID, nextID, show_hide_bitmask) 
                        GOSUB clean_unused_skies     
                    ENDIF
                ENDIF

                REPEAT MAX_INDEX temp_int
                    IF NOT sky[temp_int] = DISABLED                    
                        IF IS_LOCAL_VAR_BIT_SET_LVAR show_hide_bitmask temp_int
                            CLEO_CALL draw_this_sky 0 sky[temp_int] temp_int
                        ENDIF
                    ENDIF
                ENDREPEAT

            ENDIF
                
        ENDWHILE

    RETURN

    clean_unused_skies:
        REPEAT MAX_INDEX temp_int
            IF NOT IS_LOCAL_VAR_BIT_SET_LVAR show_hide_bitmask temp_int
                SET_OBJECT_SCALE sky[temp_int] 0.0
            ENDIF
        ENDREPEAT
    RETURN

    update_position:
        GET_ACTIVE_CAMERA_COORDINATES x y z
        // z += 40.0
        SET_OBJECT_COORDINATES center x y z
        // z += 1.0
        SET_OBJECT_COORDINATES center_night x y z

        z = fRotation
        fRotation +=@ fRotationSpeed
        ROTATE_OBJECT center z fRotation 0
    RETURN

    wait:
        WHILE CLEO_CALL is_player_near_save_pickup_or_in_interior 0
            WAIT 0
        ENDWHILE
    RETURN

    delete_sky:
        REPEAT MAX_INDEX temp_int
            DELETE_OBJECT sky[temp_int]
        ENDREPEAT
            DELETE_OBJECT center
            DELETE_OBJECT center_night
    RETURN

    load_sky:
        REQUEST_MODEL MODEL_OBJECT_CENTER
        REPEAT MAX_INDEX temp_int
            IF NOT sky[temp_int] = DISABLED
                REQUEST_MODEL sky[temp_int]
            ENDIF
        ENDREPEAT
        LOAD_ALL_MODELS_NOW

        CREATE_OBJECT MODEL_OBJECT_CENTER x y z center
        SET_OBJECT_VISIBLE center 0
        SET_OBJECT_COLLISION center 0
        SET_OBJECT_SCALE center 0.0
            
        CREATE_OBJECT MODEL_OBJECT_CENTER x y z center_night
        SET_OBJECT_VISIBLE center_night 0
        SET_OBJECT_COLLISION center_night 0
        SET_OBJECT_SCALE center_night 0.0
            


        z = 0.0
        REPEAT MAX_INDEX temp_int
            IF NOT sky[temp_int] = DISABLED
                CLEO_CALL create_this_sky 0 (sky[temp_int]) (sky[temp_int])
                IF temp_int < 10
                    ATTACH_OBJECT_TO_OBJECT sky[temp_int] center (0.0, 0.0, z) (0.0 0.0 0.0)
                ELSE
                    ATTACH_OBJECT_TO_OBJECT sky[temp_int] center_night (0.0, 0.0, z) (0.0 0.0 0.0)
                ENDIF
                z += 0.1
            ENDIF
        ENDREPEAT
            
    RETURN

    read_ini:

        IF DOES_FILE_EXIST "cleo\BetterSkybox.ini"
            READ_FLOAT_FROM_INI_FILE "cleo\BetterSkybox.ini" "Main" "RotationSpeed" fRotationSpeed
            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "Main" "NightStartsAt" temp_int
                CLEO_CALL set_byte 0 (temp_int,20)

            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "Main" "DayStartsAt" temp_int
                CLEO_CALL set_byte 0 (temp_int, 21)
            
            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "Main" "bDisableClouds" temp_int
                IF temp_int = TRUE
                    WRITE_MEMORY (0x53E121, 5, 0x90, 1)  // Disabling Low Clouds 
                    WRITE_MEMORY (0x53E1B4, 5 , 0x90, 1) // Disabling Volumetric Clouds
                    WRITE_MEMORY (0x53DCA2, 5 , 0x90, 1) // DisaSkyStuff
                    WRITE_MEMORY (0x53DFA0, 5 , 0x90, 1) 
                    WRITE_MEMORY (0x53DCA2, 5 , 0x90, 1) 
                ENDIF
            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "Main" "bGetWeatherReportEachFrame" temp_int
                IF temp_int = TRUE
                    SET_LOCAL_VAR_BIT_CONST misc_flags BIT_FLAG_GET_WEATHER_REPORT_EACH_FRAME
                ENDIF
            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "ModelID" "LS_Sunny" sky[0]
            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "ModelID" "SF_Sunny" sky[1]
            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "ModelID" "LV_Sunny" sky[2]
            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "ModelID" "CS_Sunny" sky[3]
            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "ModelID" "DS_Sunny" sky[4]

            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "ModelID" "LS_Cloudy" sky[5]
            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "ModelID" "SF_Cloudy" sky[6]
            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "ModelID" "LV_Cloudy" sky[7]
            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "ModelID" "CS_Cloudy" sky[8]
            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "ModelID" "DS_Cloudy" sky[9]

            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "ModelID" "LS_Night" sky[10]
            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "ModelID" "SF_Night" sky[11]
            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "ModelID" "LV_Night" sky[12]
            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "ModelID" "CS_Night" sky[13]
            READ_INT_FROM_INI_FILE "cleo\BetterSkybox.ini" "ModelID" "DS_Night" sky[14]

        ELSE
            WAIT 5000
            PRINT_FORMATTED_NOW "cleo\BetterSkybox.ini doesnt exist... terminating script" 5000 
            WAIT 5000
            TERMINATE_THIS_CUSTOM_SCRIPT 
        ENDIF
    
    RETURN

    init:
        
        LVAR_INT sky[15] // 4 sunny ; 5 to 9 < cloudy ; 10 to 14 night
        LVAR_INT center center_night
        LVAR_INT temp_int currID nextID show_hide_bitmask misc_flags
        LVAR_FLOAT fScale fRotation fRotationSpeed  
        LVAR_FLOAT x y z

        REPEAT MAX_INDEX temp_int
            sky[temp_int]  = DISABLED
        ENDREPEAT
        //------------------------Model IDs------------------------------
            CONST_INT MODEL_OBJECT_CENTER      4227
        //-----------------------Weather IDs-----------------------------
            CONST_INT LS_ExSunny    0
            CONST_INT LS_Sunny      1
            CONST_INT LS_ExSunSmog  2
            CONST_INT LS_SunSmog    3
            CONST_INT LS_Cloudy     4
            CONST_INT SF_Sunny      5
            CONST_INT SF_ExSunny    6
            CONST_INT SF_Cloudy     7
            CONST_INT SF_Rainy      8
            CONST_INT SF_Foggy      9
            CONST_INT LV_Sunny      10
            CONST_INT LV_ExSunny    11
            CONST_INT LV_Cloudy     12
            CONST_INT CS_ExSunny    13
            CONST_INT CS_Sunny      14
            CONST_INT CS_Cloudy     15
            CONST_INT CS_Rainy      16
            CONST_INT DS_ExSunny    17
            CONST_INT DS_Sunny      18
            CONST_INT DS_Sandstorm  19
        //-----------------------Addresses-------------------------------
            CONST_INT CURR_WEATHER_ADDRESS 0xC81320
            CONST_INT NEXT_WEATHER_ADDRESS 0xC8131C
            CONST_INT WEATHER_INTERPOLATION_ADDRESS 0xC8130C
            CONST_INT CURR_HOUR_ADDRESS 0xB70153
            CONST_INT MENU_ID_ADDRESS 0xBA68A5
            CONST_INT FAR_CLIP_POOL_ADDRESS 0xB7B1D0

            CONST_INT DRAW_DISTANCE_0_ADDRESS 0xB76848 
            CONST_INT DRAW_DISTANCE_1_ADDRESS 0xC3EF9C
            CONST_INT DRAW_DISTANCE_2_ADDRESS 0xC98F1C
            CONST_INT DRAW_DISTANCE_3_ADDRESS 0xC992F8
            CONST_INT DRAW_DISTANCE_4_ADDRESS 0x66415710
            // AKA guru_guru's vars (patent pending)
        
        //----------------------Bitmask Flags------------------------------
            CONST_INT BIT_FLAG_IGNORE_EX_SUNNY 0
            CONST_INT BIT_FLAG_SAMP_COMPATIBILITY 1
            CONST_INT BIT_FLAG_GET_WEATHER_REPORT_EACH_FRAME 2
        //-----------------------Misc------------------------------------
        
            CONST_INT MAX_INDEX 15
            CONST_FLOAT SKYBOX_RADIUS 2100.0 
            CONST_INT SHOW_MARKERS 0
            CONST_INT ENABLED 1
            CONST_INT DISABLED -1 

            CONST_INT IS_SUNNY 0
            CONST_INT IS_CLOUDY 1
            CONST_INT IS_NIGHT 2            
        
    RETURN

}

//drawthissky
{
    draw_this_sky:
    LVAR_INT sky /*status*/ index
    LVAR_FLOAT fScale
    LVAR_INT status skyType
    
    IF index < 15
        skyType = IS_NIGHT
    ENDIF

    IF index < 10
        skyType = IS_CLOUDY
    ENDIF

    IF index < 5
        skyType = IS_SUNNY
    ENDIF
    CLEO_CALL get_byte 0 (index) (status)

    IF status = 0
        SET_OBJECT_SCALE sky 0.0
        CLEO_RETURN 0
    ELSE
        READ_MEMORY (DRAW_DISTANCE_0_ADDRESS, 4, 0) (fScale)
        fScale /= SKYBOX_RADIUS
        SET_OBJECT_SCALE sky fScale
    ENDIF

    SWITCH skyType
        CASE IS_SUNNY
            CLEO_CALL set_sky_sunny_alpha 0 sky status
        BREAK

        CASE IS_CLOUDY
            CLEO_CALL set_sky_cloudy_alpha 0 sky status
        BREAK
        
        CASE IS_NIGHT
            CLEO_CALL set_sky_night_alpha 0 sky status
        BREAK
    ENDSWITCH

    CLEO_RETURN 0

}

//get_ids
{
    get_ids:
        //returns bitmask of what should be drawn

        LVAR_INT weather[2] id[2] i hours show_hide_bitmask 
        LVAR_INT isDay isNight temp_int
        LVAR_INT nightStartsAt dayStartsAt 

        READ_MEMORY CURR_WEATHER_ADDRESS 2 0 weather[0]
        READ_MEMORY NEXT_WEATHER_ADDRESS 2 0 weather[1]
        READ_MEMORY CURR_HOUR_ADDRESS 1 0 hours
        
        CLEO_CALL get_byte 0 (20,nightStartsAt) 
        CLEO_CALL get_byte 0 (21,dayStartsAt) 

        IF hours >= dayStartsAt
        AND hours <= nightStartsAt
            isDay = TRUE
        ENDIF

        IF hours >= nightStartsAt
        OR hours <= dayStartsAt
            isNight = TRUE
        ENDIF

        
        
        REPEAT 2 i
            IF weather[i] >= LS_ExSunny
            AND weather[i] <= LS_SunSmog
                id[i] = 0 
                GOTO set_sh_bitmask
            ENDIF

            IF weather[i] = SF_ExSunny
            OR weather[i] = SF_Sunny
                id[i] = 1 
                GOTO set_sh_bitmask
            ENDIF 

            IF weather[i] = LV_ExSunny
            OR weather[i] = LV_Sunny
                id[i] = 2 
                GOTO set_sh_bitmask
            ENDIF

            IF weather[i] = CS_ExSunny
            OR weather[i] = CS_Sunny
                id[i] = 3 
                GOTO set_sh_bitmask
            ENDIF

            IF weather[i] = DS_ExSunny
            OR weather[i] = DS_Sunny
                id[i] = 4 
                GOTO set_sh_bitmask
            ENDIF
            
            //-----------------------//

            IF weather[i] = LS_Cloudy
                id[i] = 5
                GOTO set_sh_bitmask
            ENDIF

            IF weather[i] >= SF_Cloudy
            AND weather[i] <= SF_Foggy
                id[i] = 6
                GOTO set_sh_bitmask
            ENDIF

            IF weather[i] = LV_Cloudy
                id[i] = 7
                GOTO set_sh_bitmask
            ENDIF

            IF weather[i] = CS_Rainy
            OR weather[i] = CS_Cloudy
                id[i] = 8
                GOTO set_sh_bitmask
            ENDIF
            
            IF weather[i] = DS_Sandstorm
                id[i] = 9
                GOTO set_sh_bitmask
            ENDIF

            set_sh_bitmask:

            IF id[i] < 5
                IF isDay = TRUE
                    SET_LOCAL_VAR_BIT_LVAR show_hide_bitmask id[i]
                ENDIF

                IF isNight = TRUE
                    temp_int = id[i]
                    temp_int += 10
                    SET_LOCAL_VAR_BIT_LVAR show_hide_bitmask temp_int
                ENDIF
            ELSE
                SET_LOCAL_VAR_BIT_LVAR show_hide_bitmask id[i]
            ENDIF

        ENDREPEAT  

    CLEO_RETURN 0 id[0] id[1] show_hide_bitmask    
}

//create_this_sky
{
    create_this_sky:
        LVAR_INT id 
        LVAR_FLOAT x y z
        LVAR_INT sky_handle
        IF NOT id = DISABLED 
            CREATE_OBJECT_NO_OFFSET id x y z sky_handle
            SET_OBJECT_VISIBLE sky_handle 1
            SET_OBJECT_COLLISION sky_handle 0
            SET_OBJECT_ALPHA sky_handle 0 
            SET_OBJECT_SCALE sky_handle 0.0
        ELSE
            CLEO_RETURN 0 -1
        ENDIF

    CLEO_RETURN 0 sky_handle 

}

//get_status
{
    get_status:
        LVAR_INT index currWeatherID nextWeatherID
        LVAR_INT skyType isCurrWeatherCloudy isNextWeatherCloudy
        LVAR_INT status
        IF index < 15
            skyType = IS_NIGHT
        ENDIF

        IF index < 10
            skyType = IS_CLOUDY
        ENDIF

        IF index < 5
            skyType = IS_SUNNY
        ENDIF


        IF currWeatherID >= 5
        AND currWeatherID <= 9 
            isCurrWeatherCloudy = TRUE
        ENDIF
    
        IF nextWeatherID >= 5
        AND nextWeatherID <= 9
            isNextWeatherCloudy = TRUE
        ENDIF

        SWITCH skyType

            CASE IS_SUNNY
        
                IF isCurrWeatherCloudy = TRUE  
                AND isNextWeatherCloudy = FALSE 
                    CLEO_RETURN 0 1 //fade in
                ENDIF

                IF  isCurrWeatherCloudy = FALSE
                AND isNextWeatherCloudy = TRUE
                    CLEO_RETURN 0 2 //fade out
                ENDIF

                IF  isCurrWeatherCloudy = FALSE
                AND isNextWeatherCloudy = FALSE
                    IF NOT nextWeatherID = currWeatherID
                        IF index = currWeatherID
                            CLEO_RETURN 0 2
                        ELSE
                            CLEO_RETURN 0 1
                        ENDIF
                    ENDIF
                    CLEO_RETURN 0 3
                ENDIF
                
                IF  isCurrWeatherCloudy = TRUE
                AND isNextWeatherCloudy = TRUE
                    CLEO_RETURN 0 0 //hide
                ENDIF
            BREAK
            
            CASE IS_CLOUDY
                IF  isCurrWeatherCloudy = FALSE
                AND isNextWeatherCloudy = TRUE
                AND index = nextWeatherID
                    CLEO_RETURN 0 1 //fade in
                ENDIF

                IF  isCurrWeatherCloudy = TRUE
                AND isNextWeatherCloudy = FALSE
                AND index = currWeatherID
                    CLEO_RETURN 0 2 //fade out
                ENDIF

                IF  isCurrWeatherCloudy = TRUE
                AND isNextWeatherCloudy = TRUE
                    IF NOT nextWeatherID = currWeatherID
                        IF index = currWeatherID
                            CLEO_RETURN 0 2
                        ELSE
                            CLEO_RETURN 0 1
                        ENDIF
                    ENDIF
                    CLEO_RETURN 0 3 //show
                ENDIF
                
                IF  isCurrWeatherCloudy = FALSE
                AND isNextWeatherCloudy = FALSE
                    CLEO_RETURN 0 0
                ENDIF

            BREAK

            CASE IS_NIGHT

                index -= 10 // 0 <= currID & nextID <= 9

                IF isCurrWeatherCloudy = TRUE  
                AND isNextWeatherCloudy = FALSE 
                    CLEO_RETURN 0 1 //fade in
                ENDIF

                IF isCurrWeatherCloudy = FALSE
                AND isNextWeatherCloudy = TRUE
                    CLEO_RETURN 0 2 //fade out
                ENDIF

                IF  isCurrWeatherCloudy = FALSE
                AND isNextWeatherCloudy = FALSE

                    IF NOT nextWeatherID = currWeatherID
                        IF index = currWeatherID
                            CLEO_RETURN 0 2
                        ELSE
                            CLEO_RETURN 0 1
                        ENDIF
                    ENDIF
                    CLEO_RETURN 0 3
                ENDIF
                
                IF  isCurrWeatherCloudy = TRUE
                AND isNextWeatherCloudy = TRUE
                    CLEO_RETURN 0 0 //hide
                ENDIF

            BREAK

        ENDSWITCH
    CLEO_RETURN 0 status
}

//set_status_array
{
    set_status_array:
        LVAR_INT currID nextID show_hide_bitmask
        LVAR_INT i status

        REPEAT MAX_INDEX i
            IF IS_LOCAL_VAR_BIT_SET_LVAR show_hide_bitmask i
                CLEO_CALL get_status 0 (i currID nextID) (status)
                CLEO_CALL set_byte 0 (status,i)
            ELSE
                CLEO_CALL set_byte 0 (0,i)
            ENDIF
        ENDREPEAT
    CLEO_RETURN 0
}

// set_sky_sunny_alpha
{
    set_sky_sunny_alpha:
        LVAR_INT sky status
        //-------------------------------------
        LVAR_INT model_alpha
        LVAR_INT nightStartsAt dayStartsAt
        LVAR_INT hours minutes

        CLEO_CALL get_byte 0 (20,nightStartsAt) 
        CLEO_CALL get_byte 0 (21, dayStartsAt)

        GET_TIME_OF_DAY hours minutes
        SWITCH status

            CASE 0 //hiding
                SET_OBJECT_ALPHA sky 0
            BREAK

            CASE 1 //fading in
                
                IF  hours >= dayStartsAt
                AND hours <= nightStartsAt
                    CLEO_CALL do_fade_in 0 model_alpha
                    SET_OBJECT_ALPHA sky model_alpha
                ENDIF
            BREAK

            CASE 2 //fading out
                IF  hours >= dayStartsAt
                AND hours <= nightStartsAt
                    CLEO_CALL do_fade_out 0 model_alpha
                    SET_OBJECT_ALPHA sky model_alpha
                ENDIF
            BREAK

            CASE 3 //Showing,Normal Routine
                IF hours = dayStartsAt
                    CLEO_CALL do_fade_in 0 model_alpha
                    SET_OBJECT_ALPHA sky model_alpha
                    CLEO_RETURN 0
                ENDIF

                IF  hours > dayStartsAt
                AND hours < nightStartsAt 
                    SET_OBJECT_ALPHA sky 255
                    CLEO_RETURN 0
                ENDIF

                IF hours = nightStartsAt
                    CLEO_CALL do_fade_out 0 model_alpha
                    SET_OBJECT_ALPHA sky model_alpha
                    CLEO_RETURN 0
                ENDIF

                SET_OBJECT_ALPHA sky 0
            BREAK
        ENDSWITCH
    CLEO_RETURN 0
}

// set_sky_cloudy_alpha
{
    //exactly the same as set_sky_sunny_alpha,but it shows up no matter what time is it
    set_sky_cloudy_alpha:
        LVAR_INT sky status
        //-------------------------------------
        LVAR_INT model_alpha
       
        SWITCH status

            CASE 0 //hiding
                SET_OBJECT_ALPHA sky 0
            BREAK

            CASE 1 //fading in
                CLEO_CALL do_fade_in 0 model_alpha
                SET_OBJECT_ALPHA sky model_alpha
            BREAK

            CASE 2 //fading out
                CLEO_CALL do_fade_out 0 model_alpha
                SET_OBJECT_ALPHA sky model_alpha
            BREAK

            CASE 3 //Showing,Normal Routine
                SET_OBJECT_ALPHA sky 255
            BREAK
        ENDSWITCH
    CLEO_RETURN 0 

}

//set_sky_night_alpha
{
    set_sky_night_alpha: // it's just sunny_alpha but with inverted time checks
        LVAR_INT sky status
        //-------------------------------------
        LVAR_INT model_alpha
        LVAR_INT dayStartsAt nightStartsAt
        LVAR_INT hours minutes
        CLEO_CALL get_byte 0 (20,nightStartsAt) 
        CLEO_CALL get_byte 0 (21,dayStartsAt) 
        
        GET_TIME_OF_DAY hours minutes
        SWITCH status

            CASE 0 //hiding
                SET_OBJECT_ALPHA sky 0
            BREAK

            CASE 1 //fading in
                IF  hours >= nightStartsAt
                OR hours <= dayStartsAt
                    CLEO_CALL do_fade_in 0 model_alpha
                    SET_OBJECT_ALPHA sky model_alpha
                ENDIF
            BREAK

            CASE 2 //fading out
                IF  hours >= nightStartsAt
                OR hours <= dayStartsAt
                    CLEO_CALL do_fade_out 0 model_alpha
                    SET_OBJECT_ALPHA sky model_alpha
                ENDIF
            BREAK

            CASE 3 //Showing,Normal Routine
                IF hours = dayStartsAt
                    CLEO_CALL do_fade_out 0 model_alpha
                    SET_OBJECT_ALPHA sky model_alpha
                    CLEO_RETURN 0
                ENDIF

                IF  hours > dayStartsAt
                AND hours < nightStartsAt
                    SET_OBJECT_ALPHA sky 0
                    CLEO_RETURN 0
                ENDIF

                IF hours = nightStartsAt
                    CLEO_CALL do_fade_in 0 model_alpha
                    SET_OBJECT_ALPHA sky model_alpha
                    CLEO_RETURN 0
                ENDIF

                SET_OBJECT_ALPHA sky 255
            BREAK
        ENDSWITCH
    CLEO_RETURN 0   
}

// do_fade_in ; 
{
    do_fade_in:
        LVAR_FLOAT fWeatherInterpolation
        LVAR_INT iAlpha
        READ_MEMORY WEATHER_INTERPOLATION_ADDRESS 4 0 fWeatherInterpolation
        fWeatherInterpolation *= 255.0
        CSET_LVAR_INT_TO_LVAR_FLOAT iAlpha fWeatherInterpolation
    CLEO_RETURN 0 iAlpha
}

// do_fade_out
{
    do_fade_out:
        LVAR_FLOAT fWeatherInterpolation
        LVAR_INT iAlpha
        READ_MEMORY WEATHER_INTERPOLATION_ADDRESS 4 0 fWeatherInterpolation
        fWeatherInterpolation *= -255.0
        fWeatherInterpolation += 255.0        
        CSET_LVAR_INT_TO_LVAR_FLOAT iAlpha fWeatherInterpolation
    CLEO_RETURN 0 iAlpha
}

// is_player_near_save_pickup_or_in_interior
{
    is_player_near_save_pickup_or_in_interior: 
        LVAR_INT scplayer object active_interior flag

        GET_AREA_VISIBLE active_interior
        IF active_interior = 0 
            GET_PLAYER_CHAR 0 scplayer
            IF IS_CHAR_ON_FOOT scplayer

                IF LOCATE_CHAR_ANY_MEANS_3D scplayer 416.9548 2538.813 9.5077 3.0 3.0 3.0 SHOW_MARKERS
                    IS_PC_VERSION
                    CLEO_RETURN 0
                ENDIF

                IF LOCATE_CHAR_ANY_MEANS_3D scplayer -2037.89 -2526.96 30.13  3.0 3.0 3.0 SHOW_MARKERS
                    IS_PC_VERSION
                    CLEO_RETURN 0
                ENDIF

                IF LOCATE_CHAR_ANY_MEANS_3D scplayer 877.81 -26.91  62.69  3.0 3.0 3.0 SHOW_MARKERS
                    IS_PC_VERSION
                    CLEO_RETURN 0
                ENDIF
                
                IF LOCATE_CHAR_ANY_MEANS_3D scplayer -2026.481 156.8028 28.5391   3.0 3.0 3.0 SHOW_MARKERS
                    IS_PC_VERSION
                    CLEO_RETURN 0
                ENDIF
                
                IF LOCATE_CHAR_ANY_MEANS_3D scplayer -693.3776 957.824 11.7829   3.0 3.0 3.0 SHOW_MARKERS
                    IS_PC_VERSION
                    CLEO_RETURN 0
                ENDIF

                IF LOCATE_CHAR_ANY_MEANS_3D scplayer 2024.564 996.4728 10.3203  3.0 3.0 3.0 SHOW_MARKERS
                    IS_PC_VERSION
                    CLEO_RETURN 0
                ENDIF
            ENDIF
        ELSE
            IS_PC_VERSION
            CLEO_RETURN 0
        ENDIF

        IS_AUSTRALIAN_GAME
        CLEO_RETURN 0
}

//byte thread mem
{
    set_byte:
        LVAR_INT value, offset
        LVAR_INT pThreadMem
        GET_LABEL_POINTER byte_thread_mem pThreadMem
        pThreadMem += offset
        WRITE_MEMORY pThreadMem 1 value 0 
    CLEO_RETURN 0
}
{
    get_byte: 
        LVAR_INT offset
        LVAR_INT pThreadMem
        LVAR_INT value
        GET_LABEL_POINTER byte_thread_mem pThreadMem
        pThreadMem += offset
        READ_MEMORY pThreadMem 1 0 value
    CLEO_RETURN 0 value
}
{
    byte_thread_mem:
    DUMP
    00 00 00 00 00 
    00 00 00 00 00
    00 00 00 00 00 // skies status array
    00 00 00 00 00 // ???
    00  //Night Starts At
    00  //Day Starts At
    ENDDUMP
}

SCRIPT_END
