#####################################################################
#              SANDBOX SPACE
#####################################################################

  
#####################################################################
#                STARFIELD ANI SCREEN AND WRAPPER
#####################################################################

init python:

    #####################################################################
    #                SPACE TRAVEL
    #####################################################################

    from random import randrange

    class ProjectionStarfield(renpy.Displayable):
        def __init__(self,count=0, depth=0,*args,**kwargs):
            super(renpy.Displayable, self).__init__(*args,**kwargs)

            self.count = count
            self.depth = depth

            self.origin_x = config.screen_width /2
            self.origin_y = config.screen_height /2

            #If a perspective amount is provided, use it. If not, use default.
            try:
                self.perspective = kwargs["perspective"]
            except:
                self.perspective = 128.0

            #If a displayable is provided, use that as the star. If not, make a star to use.
            try:
                self.one_star = kwargs["child"]
            except:
                star_colour = Solid((255,255,255,255))
                self.one_star = Fixed(star_colour,xysize=(1,1))
            self.star_positions()

        def star_positions(self):
            #Create the starting positions for the stars, represented as: [X,Y,Z]
            self.stars = []

            for item in range(self.count):
                star = [randrange(-25,25), randrange(-25,25), randrange(1, self.depth)]
                self.stars.append(star)

        def render(self,width,height,st,at):
            render = renpy.Render(0,0)

            for star in self.stars:

                #Z coordinate decreases each redraw.
                star[2] -= 0.19

                #If the star exits the screen, move it to the back of the projection with random X and Y coordinates.
                if star[2] <= 0:
                    star[0] = randrange(-25,25)
                    star[1] = randrange(-25,25)
                    star[2] = self.depth

                #Convert the 3D coordinates to 2D using perspective projection.
                k = self.perspective / star[2]
                x = int(star[0] * k + self.origin_x)
                y = int(star[1] * k + self.origin_y)

                #Draw the star (if it's visible on screen).
                #Using Linear Interpolation, distant stars are smaller and darker than closer stars.
                if 0 <= x < config.screen_width and 0 <= y < config.screen_height:
                    size = (1 - float(star[2]) / self.depth) * 3
                    shade = (1 - float(star[2]) / self.depth)

                    #Apply the size and shade using Transform()
                    t = Transform(child=self.one_star, zoom=size, alpha=shade)
                    child_render = renpy.render(t,0,0,st,at)
                    render.blit(child_render,(x,y))

            renpy.redraw(self,0)
            return render

        def visit(self):
            return [self.one_star]

init:
    define stars = ProjectionStarfield(count=512,depth=16)

screen starfield_scr:
    add stars

label travel(message):
    scene space_bg_smart
    show screen starfield_scr
    "[message]"
    hide screen starfield_scr
    return()

#####################################################################
#              INTERCEPTS (POST ENTRY)
#####################################################################
label sandbox_intercept_space(*args):
    python:
        try:
            transitionInfo = args[2]
        except IndexError:
            transitionInfo = None
    if transitionInfo == "beacon_to_arellarti":
        # animation
        queue sound "audio/teleport.wav"
        scene expression("05_gui/hyperjump.png") with blueflash
        $ n = 5
        while n:
            $ n -= 1 
            queue sound "audio/teleport.wav"
            scene expression("05_gui/hyperjump.png") with vpunch 
        play sound "audio/explode.wav" 
        # prep arrival
        if GAME.ship.starSysID == "SSIDArellarti":
            scene space_bg_smart
            call arellarti_arrival() from _call_arellarti_arrival

    return(True)
#####################################################################
#                NAVIGATE SPACE
#####################################################################

screen sandbox_space_scr(*args):

    $ starSys = GAME.getStarSys()
    $ dueMissionPoints = args[0]
    #text "{}".format("/".join(dueMissionPoints))

    #####################################################################
    #                SPACE LOCS
    #####################################################################
    $ station = {"SSIDArellarti": "LIDStationArellarti", "SSIDXenos": "LIDStationXenos", "SSIDIltari": "LIDStationIltari", "SSIDQuthor": "LIDStationQuthor"}[GAME.getStarSys().ID]
    
    for k in starSys.locs.keys():
        $ xCoord = starSys.locs[k].coord[0]
        $ yCoord = starSys.locs[k].coord[1]
        $ l = starSys.locs[k]

        if l.found:
            imagebutton auto "02_locations/ico {}_%s.png".format(l.guiImg) focus_mask True xalign 0.5 yalign 0.5 xpos xCoord ypos yCoord action Return(["loc", l]) tooltip [l.name, l.coord[0], l.coord[1] ]
            if l.ID in dueMissionPoints: 
                image "05_gui/ico_attention.png"  xpos xCoord-126 ypos yCoord-48# matrixcolor HueMatrix(45)
    


    $ tooltip = GetTooltip()
    if tooltip:
        # paranoid check                                                    # CR-0337
        $ tDict = tooltip.__dict__                                          # CR-0337
        if tDict != {}:                                                     # CR-0337
            pass                                                            # CR-0337
        else:                                                               # CR-0337
            text "{}".format(tooltip[0]) xpos tooltip[1] ypos tooltip[2]    # CR-0337

    #####################################################################
    #                SHIP
    #####################################################################
    $ l = GAME.getSpaceLoc()
    $ xCoord = l.coord[0]
    $ yCoord = l.coord[1]
    imagebutton auto "02_locations/ico GUIShip_%s.png" focus_mask True  xpos xCoord+84 ypos yCoord+64 xalign 0.5 yalign 0.5 action Return(["ship", None]) tooltip ["Ship", xCoord+112,yCoord+80 ]
    vbox  xalign 0.5 yalign 0.95:
        text "X = Return To Ship / B = Back to Station / Due Missions: Click on Location with Red '!' Symbol" size FSIZE_MED

    #####################################################################
    #              SPECIAL COMMANDS
    #####################################################################
    key "b" action Return(["loc", starSys.locs[station]])
    key "x" action Return(["ship", None])
    # if player has hyperdrive and owns active voron gate
    if GAME.ship.hasSubSysType("ITMHyperdriveVoron") and GAME.ship.getSubSysStatus("hyperdrive") > 99 and GAME.surfaces["SUIDTenaris"].elems["SEIDTenarisGate"].found:
        key "j" action Return(["jump_to_base", None])
        imagebutton auto "05_gui/ico_nav_beacon_%s.png" action Return(["jump_to_base", None]) pos -40, -90
        text "To Base (J)" size FSIZE xpos 150 ypos 18 # CR-0860

label sandbox_space():
    # prep scene
    $ transition = False
    scene nav_screen_smart with fade
    play music "audio/{}".format(GAME.getStarSys().ambient) fadein 3.0

    show screen header()
    $ GAME.ship.status = "in space"
    $ GAME.setLocID("LOCSpace") # DEPRECATED

    # nav screen loop
    while True:

        ##################################################################### # CR-0342
        #					REFRESH BACKGROUND		                          # CR-0342
        ##################################################################### # CR-0342
        scene nav_screen_smart

        #####################################################################
        #					REFRESH VISIBLE MISSION POINTS		
        #####################################################################
        $ navPoints = [x for x in GAME.getStarSys().locs if "Rendezvous" in x]
        $ missionPoints = [x.sLocID for x in GAME.missionSys.missions]
        $ dueMissionPoints = [x.sLocID for x in GAME.missionSys.getDueMissions()]
        # $ dueMissionPoints = [x.sLocID for x in GAME.missionSys.getDueMissions() if (x.kind == "bounty" or x.due == GAME.day)]

        python:
            for i in navPoints:
                if i in dueMissionPoints:
                    GAME.getSpaceLoc(i).found = True 
                else:
                    GAME.getSpaceLoc(i).found = False 

            if GAME.questSys.inProgress("QID_MULT_FIND"):
                GAME.getSpaceLoc("LIDRendezvous75").found = True
                dueMissionPoints.append("LIDRendezvous75")
            if GAME.questSys.inProgress("QID_MULT_TRANSPORT"):  
                GAME.getSpaceLoc("LIDRendezvous50").found = True
                dueMissionPoints.append("LIDRendezvous50")
            if GAME.questSys.inProgress("QID_SERAPHINE_ARELLARTI_FIND"):  
                GAME.getSpaceLoc("LIDRendezvousArellarti25").found = True
                dueMissionPoints.append("LIDRendezvousArellarti25")    
            if GAME.questSys.inProgress("QID_KRELL_INTERCEPT"):  
                GAME.getSpaceLoc("LIDRendezvousArellarti25").found = True
                dueMissionPoints.append("LIDRendezvousArellarti25")    
            if GAME.questSys.inProgress("QID_KRELL_VORON_LOM"):  
                GAME.getSpaceLoc("LIDRendezvousArellarti25").found = True
                dueMissionPoints.append("LIDRendezvousArellarti25")    
            if GAME.questSys.inProgress('QID_KRELL_YLYEE_PACKAGE'):
                GAME.getSpaceLoc("LIDRendezvousArellarti50").found = True
                dueMissionPoints.append("LIDRendezvousArellarti50")    
            if GAME.questSys.inProgress('QID_MAIN_QUTHOR_CONTACT'):
                GAME.getSpaceLoc("LIDRendezvousQuthor75").found = True
                dueMissionPoints.append("LIDRendezvousQuthor75")  

            # ===== CR-0428 / CR-0430 START =====
            # multiverse prod presence
            if os.path.exists(GAME.podDir+"/multiverse_pod.json") and "pod_retrieved" not in GAME.tags:
                GAME.tags.append("pod_located")
                GAME.getSpaceLoc("LIDRift").found = True
            else:
                GAME.getSpaceLoc("LIDRift").found = False
            # ===== CR-0428 / CR-0430 END =====

        #####################################################################
        #					CHECK FOR ACHIEVEMENTS, IN-SPACE REPORTS, ETC		
        #####################################################################
        if GAME.mc.getTally("Eliminated Ships") >= 30 and not GAME.mc.hasAchievement("combat veteran"):
            call achievement_notify(GAME.mc, "combat veteran") from _call_achievement_notify_6 
        if GAME.mc.getTally("Eliminated Seekers") >= 50 and not GAME.mc.hasAchievement("seeker hunter"):
            call achievement_notify(GAME.mc, "seeker hunter") from _call_achievement_notify_7 
        if GAME.mc.getTally("Mined (t)") >= 1000 and not GAME.mc.hasAchievement("mining tycoon"):
            call achievement_notify(GAME.mc, "mining tycoon") from _call_achievement_notify_8 
        
        #####################################################################
        #					NAV SCREEN		
        #####################################################################

        call screen sandbox_space_scr(dueMissionPoints)
        play sound "audio/click.wav"

        if "ship" in _return:
            $ GAME.setLocID("LOCBridge")
            $ transition = ["transition", GAME.locs["LOCBridge"]]
            #call sandbox_interior_prepare_scene()
            return(transition)

        #####################################################################
        #              HYPERJUMP TO BASE
        #####################################################################
        elif "jump_to_base" in _return:
            if not any([x == GAME.items["ITMBeacon"] for x in GAME.ship.getAddOns("hyperdrive")]):
                queue sound "audio/tech_fail.wav"
                "Navigation Control" "\"No Beacons equipped in Hyperdrive.\""
            elif GAME.hour > 20:
                mc "\"I should do that when I'm better rested...\""
            else:
                queue sound "audio/load.wav"
                "You deploy an Anchor Beacon and get ready for a Hyperjump..."
                # animation
                queue sound "audio/teleport.wav"
                scene expression("05_gui/hyperjump.png") with blueflash
                $ n = 5
                while n:
                    $ n -= 1 
                    queue sound "audio/teleport.wav"
                    scene expression("05_gui/hyperjump.png") with vpunch 
                play sound "audio/explode.wav"     
                # deploy one beacon
                $ GAME.ship.beacon = GAME.getSpaceLoc().ID
                $ beacons = GAME.ship.getAddOns("hyperdrive")
                $ slotNum = beacons.index(GAME.items["ITMBeacon"])
                $ GAME.ship.removeAddOn("hyperdrive", slotNum)

                # Set StarSys and SpaceLoc
                $ jumpFromSys = GAME.getStarSys().ID # CR-0747
                $ GAME.ship.starSysID = "SSIDIltari"
                $ GAME.setSpaceLocID("LIDTenaris")

                scene space_bg_smart with fade

                if jumpFromSys == "SSIDArellarti":
                    call arellarti_leave() from _call_arellarti_leave

                # Sandbox to surface   
                $ surface = GAME.surfaces["SUIDTenaris"]
                call hour_passes() from _call_hour_passes_47
                return(["transition", surface])                  

        #####################################################################
        #              SPACE LOCS
        #####################################################################
        elif "loc" in _return:
            $ spaceLoc = _return[1]
            #####################################################################
            #                NAV AND ENGINE NOTIFICATIONS
            #####################################################################

            if GAME.ship.getSubSysStatus("engines") < 0.1:
                play sound "audio/tech_fail.wav"
                "Navigation Control" "\"Engines are inoperative.\""
                if not  GAME.mc.hasDone("engines inoperative"):
                    mc "\"I better have a look at that engine configuration...\""
                call quest_updater() from _call_quest_updater_111

            elif GAME.ship.getSubSysStatus("engines") < spaceLoc.zone:
                play sound "audio/tech_fail.wav"
                "Navigation Control" "\"Destination cannot be reached with current engine performance.\""
                if not GAME.mc.hasDone("refuse navigate"):
                    mc "\"I better earn some money and upgrade my engines...\""

                call quest_updater() from _call_quest_updater_112

            elif GAME.ship.cargoLoaded() > GAME.ship.cargoLimit():
                play sound "audio/tech_fail.wav"
                "Navigation Control" "\"Ship overloaded. Adjust your cargo.\""
                if not GAME.mc.hasDone("refuse_overload"):
                    mc "\"I better get rid of some cargo items first...\""

      
            #####################################################################
            #              SPECIAL / LOCATION INTERCEPTS
            #####################################################################
            elif spaceLoc.ID in ["LIDStationXenos", "LIDLibraryXenos", "LIDXenos"] and "expo_library_ylyee" not in ylyee.done:
                queue sound "audio/beep.wav"
                "Navigation Control" "\"Xenos Inner System Access Not Authorized.\""
                if not GAME.mc.hasDone("xenos_rejected"):
                    queue sound "audio/drone_beep.wav"
                    bb2 "\"The Vorons do not allow Outsiders into their Inner Systems...\""
                    bb2 "\"They maintain a precarious balance among various Factions...\""
                    bb2 "\"Outsider presence is seen as a complicating factor...\""
                    mc "\"How can we gain access?\""
                    bb2 "\"Ylyee brought us here.\""
                    bb2 "\"I suggest we wait for a few days until word of our arrival has spread...\""
                    bb2 "\"Maye we can explore accessible locations and make some profits in the meantime...\""
                    mc "\"Agreed.\""
                    $ GAME.timerSet("T_XENOS_WAIT",3)
                    call quest_updater() from _call_quest_updater_113
                    call quest_updater() from _call_quest_updater_114

            elif spaceLoc.ID == "LIDLibraryXenos" and not GAME.mc.hasItem("ITMMapPrecursor",2):
                mc "\"Ylyee said I need the Map Fragments from Arellarti and Iltari first...\""
                mc "\"Otherwise the Library can't help me with the Analysis....\""

            elif spaceLoc.ID == "LIDLibraryXenos" and GAME.ship.spaceLocID == "LIDLibraryXenos" and GAME.questSys.inProgress ('QID_MAIN_QUTHOR_MAP3'): # CR-0855
                call cutscene_quthor("library_quthor_map") from _call_cutscene_quthor_19


            elif spaceLoc.ID == "LIDLibraryXenos" and GAME.ship.spaceLocID == "LIDLibraryXenos":
                if 'archive_task_assigned' not in kythera.done:
                    call cutscene("briefing_library") from _call_cutscene_36
                    return(["transition", GAME.locs["LOCHallway1"]])
                elif "mission_debrief" in kythera.done:
                    mc "\"I wouldn't know what to do there now...\""
                elif not GAME.mc.hasItem("ITMMapPrecursor",3):
                    mc "\"I better have all three Map Fragments ready before reporting back.\"" 
                # ===== CR-0691 START    
                elif GAME.hour >= 18:
                    mc "\"It's late.\""
                    mc "\"I better go there tomorrow...\""
                # ===== CR-0691 END
                else:
                    call cutscene("debrief_library") from _call_cutscene_37
                    queue sound "audio/teleport.wav"
                    return(["transition", GAME.locs["LOCHallway1"]])

            elif spaceLoc.ID == "LIDRendezvousQuthor75" and GAME.ship.spaceLocID == "LIDRendezvousQuthor75" and GAME.questSys.inProgress('QID_MAIN_QUTHOR_CONTACT'):
                queue sound "audio/notify.wav"
                mc "\"No one here yet...\""
                mc "\"I should spend a night here and wait...\""

            #####################################################################
            #					MISSION CHECK		
            #####################################################################
            if GAME.missionSys.getLocActive(spaceLoc.ID) and spaceLoc.ID == GAME.ship.spaceLocID: #elif
                $ mission = GAME.missionSys.getLocActive(spaceLoc.ID)

                # Transport Mission
                if mission.kind in ["transport", "smuggling"]:
                    if eval(mission.cond):
                        call mission_scripts(mission, "on_complete") from _call_mission_scripts
                        $ GAME.missionSys.purgeMission(mission)  
                        if "veronica" in mission.ID.lower():
                            $ GAME.mc.done.append("mission_veronica")

                # Bounty Mission 
                elif mission.kind == "bounty":
                    queue sound "audio/notify.wav"
                    call simple_notify("BOUNTY MISSION", "Locating hostiles...", ["Engage", "Abort"], "05_gui/ico_gui_hostile_human.png", "red") from _call_simple_notify_49
                    if _return == "Engage":
                        hide screen header
                        call mg_combat_scenario(mission.attr["mProfile"]) from _call_mg_combat_scenario_3
                        $ result = _return
                        if "victory" in result: # EXP returned
                            $ damage = result[1]
                            $ exp = result[2]
                            queue sound "audio/triumph.wav"
                            call simple_notify("VICTORY", "+[exp:,] EXP gained", ["Continue"], "05_gui/ico_gui_cup.png") from _call_simple_notify_50
                            queue sound "audio/click.wav"            
                            $ GAME.mc.exp += exp
                            call attr_mod(GAME.mc, "NOT", 1, 20, 100, True) from _call_attr_mod_66
                            call mission_scripts(mission, "on_complete") from _call_mission_scripts_1
                            $ GAME.missionSys.purgeMission(mission) 
                            $ GAME.mc.hasDone("first_bounty") # CR-0264
                            $ GAME.mc.tallyUp("Bounty Missions",1)
                            
                        else:
                            $ damage = result[1]
                            "You decide to try your luck another time..."
                            call attr_mod(GAME.mc, "NOT", -1, 0, 100, True) from _call_attr_mod_67

                        if damage:  
                            queue sound "audio/notify.wav"
                            call simple_notify("DAMAGE REPORT", "Subunits lost: {}".format(len(damage)), ["Continue"], "05_gui/ico Ship.png") from _call_simple_notify_51
                            queue sound "audio/click.wav"   
                        show screen header()

                    call quest_updater() from _call_quest_updater_115  
                    call hour_passes() from _call_hour_passes_48                  


            #####################################################################
            #                MINING
            #####################################################################
            elif spaceLoc.ID in ["LIDAsteroidsOuter"] and not GAME.ship.hasSubSysType("ITMMiningMkII"):
                mc "\"I need at least a Mining Laser MkII to mine this Field...\""

            elif spaceLoc.ID in ["LIDRubbleIltari", "LIDAsteroidsIltari", "LIDAsteroidsOuter", "LIDAsteroidsArellarti", "LIDFieldsXenos", "LIDBurningFields"] and spaceLoc.ID == GAME.ship.spaceLocID :
                $ mChoice = False
                # Intercepts
                if GAME.questSys.inProgress("QID_PIRATE_TASK") and spaceLoc.ID == "LIDAsteroidsIltari":
                    queue sound "audio/notify.wav"
                    call large_notify("GHAD THE RENEGADE", "From the information Vigo provided, you are able to locate the renegade pirate in the Asteroid Field.\n\nDo you want to confront him?", ["Confront", "Abort", "Mining"], "05_gui/ico Ship.png", "orange") from _call_large_notify_27
                    if _return == "Abort":
                        $ mChoice = True
                    elif _return == "Confront":
                        hide screen header
                        call mg_combat_scenario("renegade_ghad") from _call_mg_combat_scenario_4
                        $ mChoice = True
                        show screen header()
                        call hour_passes() from _call_hour_passes_49
            
                elif GAME.questSys.inProgress("QID_NIMHE_RETRIEVE_KICKOFF") and spaceLoc.ID == "LIDAsteroidsOuter":
                    queue sound "audio/notify.wav"
                    call large_notify("THE LOST MILITARY BASE", "From the information Nimhe provided, you are able to locate the military research station among the asteroids.\n\nDo you want to explore it?", ["Explore", "Abort", "Mining"], "05_gui/ico Ship.png", "orange") from _call_large_notify_28
                    if _return == "Abort":
                        $ mChoice = True
                    elif _return == "Explore":
                        hide screen header
                        call cutscene_nimhe("shell_find") from _call_cutscene_nimhe_12
                        call hour_passes() from _call_hour_passes_50
                        $ mChoice = True
                        scene nav_screen_smart with fade
                        show screen header()

                elif GAME.questSys.inProgress("QID_QUTHOR_MOIRA_VISIT") and spaceLoc.ID == "LIDAsteroidsOuter":
                    stop music fadeout 2.0
                    queue sound "audio/notify.wav"
                    call large_notify("THE ELUSIVE DOC", "From the information Khelara provided, you are able to locate the Research Facility among the asteroids.\n\nDo you want to contact it?", ["Contact", "Abort", "Mining"], "05_gui/ico Ship.png", "orange") from _call_large_notify_29
                    if _return == "Abort":
                        $ mChoice = True
                    elif _return == "Contact":
                        hide screen header
                        call cutscene_quthor("moira_contact") from _call_cutscene_quthor_10
                        call hour_passes() from _call_hour_passes_51
                        $ mChoice = True
                        scene nav_screen_smart with fade
                        show screen header()

                elif GAME.questSys.inProgress("QID_QUTHOR_MOIRA_GEAR") and spaceLoc.ID == "LIDAsteroidsOuter":
                    stop music fadeout 2.0
                    queue sound "audio/notify.wav"
                    call large_notify("THE ELUSIVE DOC", "You have promised Dr. Morgan to return with the specified amount of Krell Bio Wares.\n\nDo you want to contact her?", ["Contact", "Abort", "Mining"], "05_gui/ico Ship.png", "orange") from _call_large_notify_30
                    if _return == "Abort":
                        $ mChoice = True
                    elif _return == "Contact":
                        hide screen header
                        call cutscene_quthor("moira_pickup") from _call_cutscene_quthor_11
                        call hour_passes() from _call_hour_passes_52
                        $ mChoice = True
                        scene nav_screen_smart with fade
                        show screen header()

                #  Mining
                if mChoice:
                    pass               
                elif GAME.ship.getSubSysStatus("mining") <= 0.0:
                    play sound "audio/beep.wav"
                    "Ship Control" "\"Mining laser is offline.\""
                elif GAME.hour >= 18:
                    mc "\"I should resume that, when I am better rested...\""
                else:
                    #hide screen header
                    hide screen header
                    call mg_mining_pick(spaceLoc.name.upper()) from _call_mg_mining_pick
                    call hour_passes(18-GAME.hour) from _call_hour_passes_53
                    show screen header

            #####################################################################
            #                MULTIVERSE POD
            #####################################################################
            elif spaceLoc.ID in ["LIDRift"] and spaceLoc.ID == GAME.ship.spaceLocID :
                #hide screen header
                hide screen header
                call multiverse_manager("retrieve") from _call_multiverse_manager
                show screen header

            #####################################################################
            #                HYPERGATE
            #####################################################################
            elif spaceLoc.ID in ["LIDGateIltari", "LIDGateArellarti", "LIDGateXenos", "LIDGateQuthor"] and spaceLoc.ID == GAME.ship.spaceLocID :  # CR-0698  
                if "gate_talk" not in tris.done:
                    mc "\"I'm not sure I should venture out ...\""
                    if not GAME.questSys.isActive('QID_VEE_FAMILIARIZE'): 
                        mc "\"I have the feeling my crew is not complete yet...\""
                    elif GAME.questSys.isActive('QID_SERAPHINE_KICKOFF'):
                        mc "\"I am ready to move beyond Iltari...\""
                        mc "\"I should talk to T'Ris.\""
                    else:
                        mc "\"I better find out more about this system first...\""

                elif not GAME.ship.hasSubSys("hyperdrive"):
                    queue sound "audio/drone_beep.wav"
                    bb2 "\"We need a Hyperdrive Subsystem to use the Gate, Captain [GAME.mc.name].\""
                    mc "\"Right.\""
                    mc "\"I better buy one then.\""
                    bb2 "\"Make sure to fully configure it.\""
                    bb2 "\"Hyperdrives need full power to use the Gate.\""
                    mc "\"Understood.\""

                elif GAME.ship.getSubSysStatus("hyperdrive") < 99: # paranoid boundary 
                    queue sound "audio/drone_beep.wav"
                    bb2 "\"We need our Hyperdrive Subsystem at 100 percent to use the Gate, Captain [GAME.mc.name].\""
                    bb2 "\"Otherwise we might end up lost in Hyperspace...\""
                    mc "\"Right, I forgot.\""

                elif not GAME.questSys.isDone('QID_SERAPHINE_CLASS_TRIS'):
                    queue sound "audio/beep.wav"
                    "Jumpgate Control" "\"Jumpgate Access Declined.\""
                    mc "\"Arrgghh....!\""
                    "Jumpgate Control" "\"You do not possess the required [C_HI_B]Hyperjump License.[C_HI_E]\""
                    if not GAME.mc.hasDone("hypergate_reject"):
                        mc "\"Where can I obtain such a License?\""
                        "Jumpgate Control" "\"Hyperjump Licenses are issued at Iltari Station Administration.\""
                    "Jumpgate Control" "\"Iltari Gate Control Out.\""
                    call quest_updater() from _call_quest_updater_116

                elif GAME.hour > 17:
                    mc "\"I should do that when I am better rested.\""

                else:   
                    call navigate_galaxy() from _call_navigate_galaxy

            #####################################################################
            #                WAYPOINTS / QUEST STUFF
            #####################################################################
            elif spaceLoc.ID == "LIDRendezvous75" and GAME.questSys.inProgress("QID_MULT_FIND") and spaceLoc.ID == GAME.ship.spaceLocID:
                scene space_bg_smart
                show image "05_gui/mask_cockpit_space.png"                 
                mc "\"Now let's see whether we can find that crate...\""
                call simple_notify("SCANNING", "You scan the area...", ["Continue"], "05_gui/ico Ship.png") from _call_simple_notify_52 
                queue sound "audio/success.wav"
                $ item = GAME.items["ITMCrateLiquor"]
                call find_notify(item, "ITEM FOUND") from _call_find_notify_11 
                queue sound "audio/load.wav"
                $ GAME.setLocID("LOCCargo")
                mc "\"Let's have a look at what we found...\""  
                scene room_cargo_smart with fade 
                "You open the crate in the cargobay..."
                $ item = GAME.items["ITMLiquorVortex"] 
                call find_notify(item, "ITEM FOUND", 5) from _call_find_notify_12 
                $ GAME.mc.hasDone("vortex_found")
                mc "\"Looks mighty expensive...\""
                mc "\"Let's bring that back to Ylyee...\""
                call quest_updater() from _call_quest_updater_117
                $ GAME.mc.inventory += [item]*5
                call sandbox_interior_navigate_to("LOCBridge") from _call_sandbox_interior_navigate_to_36
                #$ GAME.getStarSys().locs["LIDRendezvous75"].found = True
                return(["transition", GAME.locs["LOCBridge"]]) # CR-0590

            elif spaceLoc.ID == "LIDRendezvous50" and GAME.questSys.inProgress("QID_MULT_TRANSPORT") and spaceLoc.ID == GAME.ship.spaceLocID and "escort" in ylyee.status: # CR-0382
                scene expression("05_gui/mask_cockpit_space.png") with fade 
                mc "\"Let's scan for crafts in the vicinity...\"" 
                queue sound "audio/teleport.wav"
                scene expression("06_cutscenes/cutscene_voronian_cruiser_two.png") with dissolve
                mc  "\"Whoaaa...\""
                queue sound "audio/beep.wav"
                "Voronian Cruiser" "\"This is Imperial Voronian Cruiser Lagdash.\""
                "Voronian Cruiser" "\"Hand over her Exalted Highness immediately!\""
                mc "\"Highness?\"" 
                yly "\"That's me.\"" 
                mc "\"I thought you were some kind of Diplomat?\""
                yly "\"In a sense...\"" 
                yly "\"Lagdash, stand down and prepare for transport.\""
                "Voronian Cruiser" "\"Affirmative.\""
                yly "\"You have been of great service to me.\""
                yly "\"Accept this as a token of my gratitude.\""
                $ item = GAME.items["ITMMultiPod"]
                queue sound "audio/success.wav"
                call find_notify(item, "You receive ") from _call_find_notify_13 
                $ GAME.mc.inventory.append(item)
                mc "\"What is that?\""
                yly "\"A mysterious and powerful device...\""
                yly "\"It can extend itself through the Multiverse...\""
                mc "\"Through what?\""
                yly "\"Use it, when you are ready.\""
                mc "\"Ready?\""
                yly "\"You will know.\"" 
                yly "\"Lagdash, ready to transport.\""
                queue sound "audio/teleport.wav"
                mc "\"Whoaa...\"" with blueflash 
                scene expression("05_gui/mask_cockpit_space.png") with dissolve 
                mc "\"That was odd...\"" 
                $ GAME.mc.hasDone('ylyee_escorted')
                $ ylyee.status.remove("escort") # CR-0382
                mc "\"I better store that pod safely until I am ready to use it.\"" 
                $ GAME.mc.exp += 1000                
                call quest_updater() from _call_quest_updater_118
                call sandbox_interior_navigate_to("LOCBridge") from _call_sandbox_interior_navigate_to_37
                #$ GAME.getStarSys().locs["LIDRendezvous50"].found = False
                return(["transition", GAME.locs["LOCBridge"]]) # CR-0590

            elif spaceLoc.ID == "LIDRendezvousArellarti25" and GAME.questSys.inProgress("QID_SERAPHINE_ARELLARTI_FIND") and spaceLoc.ID == GAME.ship.spaceLocID:
                queue sound "audio/notify.wav"
                call large_notify("RESCUE QUEST!", "Scanning the dense Asteroid Field for anomalous signatures, you locate the vessel of Princess Seraphine. A large group of Krell Lashers is searching nearby...\n\nWhat do you want to do?", ["Attack", "Withdraw"], "05_gui/ico_gui_quest.png", "orange") from _call_large_notify_31
                if _return == "Withdraw":
                    $ mChoice = True
                    "You withdraw until you are better prepared..."
                elif _return =="Attack":
                    hide screen header
                    call mg_combat_scenario("rescue_seraphine") from _call_mg_combat_scenario_5
                    $ mChoice = True
                    show screen header() 
                    call hour_passes() from _call_hour_passes_54                   

            elif spaceLoc.ID == "LIDRendezvousArellarti25" and GAME.questSys.inProgress("QID_KRELL_INTERCEPT") and spaceLoc.ID == GAME.ship.spaceLocID:
                if GAME.hour >= 18:
                    mc "\"I should do that when I am better rested.\""
                else:
                    queue sound "audio/notify.wav"
                    call large_notify("INTERCEPT MISSION!", "Scanning the dense Asteroid Field you locate a vessel which is en route to Arellarti Station from Kranor Biolabs. \n\nWhat do you want to do?", ["Attack", "Withdraw"], "05_gui/ico_gui_quest.png", "orange") from _call_large_notify_32
                    if _return == "Withdraw":
                        $ mChoice = True
                        "You withdraw until you are better prepared..."
                    elif _return =="Attack":
                        hide screen header
                        call mg_combat_scenario("intercept_merchant") from _call_mg_combat_scenario_6
                        $ mChoice = True
                        show screen header() 
                        call hour_passes(18-GAME.hour) from _call_hour_passes_55                  

            elif spaceLoc.ID == "LIDRendezvousArellarti25" and GAME.questSys.inProgress("QID_KRELL_VORON_LOM") and spaceLoc.ID == GAME.ship.spaceLocID:
                if GAME.hour >= 18:
                    mc "\"I should do that when I am better rested.\""
                else:
                    queue sound "audio/notify.wav"
                    call large_notify("INTERCEPT MISSION!", "Scanning the dense Asteroid Field you locate a convoy which is en route to Arellarti Station from Kranor Biolabs. \n\nWhat do you want to do?", ["Attack", "Withdraw"], "05_gui/ico_gui_quest.png", "orange") from _call_large_notify_33
                    if _return == "Withdraw":
                        $ mChoice = True
                        "You withdraw until you are better prepared..."
                    elif _return =="Attack":
                        hide screen header
                        call mg_combat_scenario("intercept_convoy") from _call_mg_combat_scenario_7
                        $ mChoice = True
                        show screen header() 
                        call hour_passes(18-GAME.hour) from _call_hour_passes_56                   

            elif spaceLoc.ID == "LIDRendezvousArellarti50" and GAME.questSys.inProgress("QID_KRELL_YLYEE_PACKAGE") and spaceLoc.ID == GAME.ship.spaceLocID:
                queue sound "audio/notify.wav"
                "At the designated coordinates, you find a container drifting in space..."
                queue sound "audio/notify.wav"
                $ item = GAME.items["ITMShieldVoron"]
                call find_notify(item, "EQUIPMENT FOUND") from _call_find_notify_14
                queue sound "audio/load.wav"
                $ GAME.ship.cargo.append(item)
                call quest_updater() from _call_quest_updater_119

            #####################################################################
            #                DOCKING / TRANSITION
            #####################################################################

            elif spaceLoc.ID in ["LIDStationIltari"] and GAME.ship.spaceLocID == spaceLoc.ID and len([x for x in GAME.ship.cargo if not spaceLoc.isLegal(x.ID)]) > GAME.ship.cargoLimitCloak():
                play sound "audio/drone_beep.wav"
                bb2 "\"I recommend to not dock here.\""
                bb2 "\"You are carrying illegal wares which are not, ahem, cloaked.\""
                bb2 "\"You should eject them prior to docking.\""
                mc "\"Right...\""
                scene nav_screen_smart with fade

            elif spaceLoc.ID in ["LIDStationIltari"] and GAME.ship.spaceLocID == spaceLoc.ID:
                scene expression ("06_cutscenes/cutscene_station_one.png") with fade # CR-0847
                play sound "audio/beep.wav"
                $ response = "Proceed"
                if not GAME.mc.hasDone("docked iltari"):
                    call large_notify("{} Control".format(spaceLoc.name), "\"This is {} Control. Your Docking request has been received. Please standby for Docking Procedure.\n\nDocking fee will be 200 Credits.\"".format(spaceLoc.name), ["Proceed", "Abort"], "05_gui/ico_gui_station.png") from _call_large_notify_34
                    $ response = _return

                if response == "Proceed":
                    if GAME.money < 200:
                        "You lack the required docking fees."
                        scene nav_screen_smart with fade
                    else:
                        scene expression ("06_cutscenes/cutscene_station_three.png") with fade #                         window hide
                        pause
                        play sound "audio/load.wav"
                        $ GAME.ship.status = "docked"
                        $ GAME.setLocID("LOCBridge")
                        call sandbox_interior_prepare_scene() from _call_sandbox_interior_prepare_scene_6
                        call transaction("Docking Fees", -200, True) from _call_transaction_17
                        if "first docking" not in GAME.mc.done:
                            play sound "audio/notify.wav"
                            tri "\"Well, you managed to get us here in one piece.\""
                            tri "\"Impressive.\""
                            tri "\"Thankfully, most ship functions are automated...\""
                            tri "\"I recommend you look for that map now.\""
                            tri "\"I shall continue my diagnostic of the Ship's systems.\""
                            $ GAME.mc.hasDone("first docking")
                        return(["transition", GAME.locs["LOCBridge"]]) # CR-0589

                elif _return == "Abort":
                    scene nav_screen_smart with fade

            elif spaceLoc.ID in ["LIDPirate"] and GAME.ship.spaceLocID == spaceLoc.ID:
                scene expression ("06_cutscenes/cutscene_pirate_hideout.png") with fade
                play sound "audio/beep.wav"
                $ response = "Proceed"
                call large_notify("{} Control".format(spaceLoc.name), "\"This is Tango 4. Your Docking request has been received. Please standby for Docking Procedure.\n\nDocking fee will be 10,000 Credits.\"", ["Proceed", "Abort"], "05_gui/ico_gui_station_pirate.png", "orange") from _call_large_notify_35
                $ response = _return
                if response == "Proceed":
                    $ GAME.mc.hasDone("docked_pirate")
                    if GAME.money < 10000:
                        "You lack the required docking fees."
                        scene nav_screen_smart with fade
                    else:
                        scene expression ("06_cutscenes/cutscene_pirate_hideout_one.png") with fade
                        window hide
                        pause
                        play sound "audio/load.wav"
                        $ GAME.ship.status = "docked"
                        $ GAME.setLocID("LOCBridge")
                        call sandbox_interior_prepare_scene() from _call_sandbox_interior_prepare_scene_7
                        call transaction("Docking Fees", -10000, True) from _call_transaction_18
                        if not GAME.mc.hasDone("first_docking_pirate"):
                            play sound "audio/notify.wav"
                            nim "\"So far so good.\""
                            nim "\"But we better tread lightly here.\""
                            nim "\"I suggest we pay Vigo, my contact, a visit.\""
                            nim "\"I think we can find him in the Cantina.\""
                        return(["transition", GAME.locs["LOCBridge"]]) # CR-0589

                elif _return == "Abort":
                    scene nav_screen_smart with fade

            elif spaceLoc.ID in ["LIDStationArellarti"] and GAME.ship.spaceLocID == spaceLoc.ID:
                scene expression ("06_cutscenes/cutscene_arellarti_station_exterior.png") with fade
                play sound "audio/beep.wav"
                $ response = "Proceed"
                $ fee = 5000
                call large_notify("{} Control".format(spaceLoc.name), "\"This is Arellarti Station. Your Docking request has been received. Please standby for Docking Procedure.\n\nDocking fee will be [fee:,] Credits.\"", ["Proceed", "Abort"], "05_gui/ico_arellarti_station.png", "green") from _call_large_notify_36
                $ response = _return
                if response == "Proceed":
                    $ GAME.mc.hasDone("docked_arellarti_station")
                    if GAME.money < fee:
                        "You lack the required docking fees."
                        scene nav_screen_smart with fade
                    else:
                        scene expression ("06_cutscenes/cutscene_arellarti_station.png") with fade
                        window hide
                        pause
                        play sound "audio/load.wav"
                        $ GAME.ship.status = "docked"
                        $ GAME.setLocID("LOCBridge")
                        call sandbox_interior_prepare_scene() from _call_sandbox_interior_prepare_scene_8
                        call transaction("Docking Fees", -fee, True) from _call_transaction_19
                        if not GAME.mc.hasDone("first_docking_arellarti"):
                            play sound "audio/notify.wav"
                            mc "\"So far so good.\""
                            mc "\"I wonder what opportunities exist for us here...\""
                            mc "\"Those Krell seem very business minded...\""
                        return(["transition", GAME.locs["LOCBridge"]]) # CR-0589

                elif _return == "Abort":
                    scene nav_screen_smart with fade

            elif spaceLoc.ID in ["LIDStationXenos"] and GAME.ship.spaceLocID == spaceLoc.ID:
                scene expression ("06_cutscenes/cutscene_xenos_station_exterior.png") with fade
                play sound "audio/beep.wav"
                $ response = "Proceed"
                $ fee = 5000
                call large_notify("{} Control".format(spaceLoc.name), "\"This is Xenos Station. Your Docking request has been received. Please standby for Docking Procedure.\n\nDocking fee will be [fee:,] Credits.\"", ["Proceed", "Abort"], "05_gui/ico_xenos_station.png", "cyan") from _call_large_notify_37
                $ response = _return
                if response == "Proceed":
                    $ GAME.mc.hasDone("docked_xenos_station")
                    if GAME.money < fee:
                        "You lack the required docking fees."
                        scene nav_screen_smart with fade
                    else:
                        scene expression ("06_cutscenes/cutscene_xenos_station_approach.png") with fade
                        window hide
                        pause
                        play sound "audio/load.wav"
                        $ GAME.ship.status = "docked"
                        $ GAME.setLocID("LOCBridge")
                        call sandbox_interior_prepare_scene() from _call_sandbox_interior_prepare_scene_9
                        call transaction("Docking Fees", -fee, True) from _call_transaction_20
                        return(["transition", GAME.locs["LOCBridge"]]) # CR-0589

                elif _return == "Abort":
                    scene nav_screen_smart with fade

            elif spaceLoc.ID in ["LIDStationQuthor"] and GAME.ship.spaceLocID == spaceLoc.ID:
                scene expression ("06_cutscenes/cutscene_quthor_station_exterior.jpg") with fade
                play sound "audio/beep.wav"
                $ response = "Proceed"
                $ fee = 15000
                call large_notify("{} Control".format(spaceLoc.name), "\"This is Quthor Station. Your Docking request has been received. Please standby for Docking Procedure.\n\nDocking fee will be [fee:,] Credits.\"", ["Proceed", "Abort"], "05_gui/ico_quthor_station.png", "blue") from _call_large_notify_38
                $ response = _return
                if response == "Proceed":
                    $ GAME.mc.hasDone("docked_quthor_station")
                    if GAME.money < fee:
                        "You lack the required docking fees."
                        scene nav_screen_smart with fade
                    else:
                        scene expression ("06_cutscenes/cutscene_quthor_station_approach.jpg") with fade
                        window hide
                        pause
                        play sound "audio/load.wav"
                        $ GAME.ship.status = "docked"
                        $ GAME.setLocID("LOCBridge")
                        call sandbox_interior_prepare_scene() from _call_sandbox_interior_prepare_scene_10
                        call transaction("Docking Fees", -fee, True) from _call_transaction_21
                        return(["transition", GAME.locs["LOCBridge"]]) # CR-0589

                elif _return == "Abort":
                    scene nav_screen_smart with fade

            #####################################################################
            #                TENARIS
            #####################################################################
            elif spaceLoc.ID == "LIDTenaris" and GAME.ship.getSubSysStatus("weapons") == 0:
                play sound "audio/drone_beep.wav"
                bb2 "\"The area around Tenaris is considered dangerous.\""
                bb2 "\"There are slave traders and pirates around.\""
                bb2 "\"You shouldn't go there without shields and weapons.\""
                mc "\"I see...\""
                mc "\"I better get my ship ugraded then...\""

            elif spaceLoc.ID == "LIDTenaris" and GAME.surfaces["SUIDTenaris"].found and GAME.ship.spaceLocID == spaceLoc.ID:
                queue sound "audio/notify.wav"
                call large_notify("TENARIS BASE", "You scan Tenaris, pinpointing the location of the Surface Base. You could land on the Base or go into Orbit.\n\nWhat do you want to do?", ["Land", "Orbit"], "05_gui/ico Ship.png", "blue") from _call_large_notify_39
                if _return == "Land":
                    hide screen header
                    $ surface = GAME.surfaces["SUIDTenaris"]
                    return(["transition", surface]) 
                                
            #####################################################################
            #                JUNKYARD
            #####################################################################
            elif spaceLoc.ID in ["LIDJunkyardArellarti","LIDJunkyardIltari", "LIDJunkyardXenos", "LIDJunkyardQuthor"] and spaceLoc.ID == GAME.ship.spaceLocID:
                $ mapFragmentsPre = GAME.mc.inventory.count(GAME.items["ITMMapPrecursor"]) # CR-0685
                # argus not ready
                if nimhe not in GAME.crew: # CR-0327
                    play sound "audio/beep.wav"
                    queue sound "audio/red alert.wav"
                    pga "\"This area is interdicted.\"" with redflash
                    pga "\"Violators will be disintegrated.\""
                    if not GAME.mc.hasDone("intro_interdiction"):
                        play sound "audio/drone_beep.wav"
                        bb2 "\"Those drones are not to be trifled with.\""
                        mc "\"I need to find a way to incapacitate them...\""
                        bb2 "\"Direct confrontation is not advised.\""
                        bb2 "\"They are Precursor technology and virtually indestructible.\""
                        bb2 "\"Otherwise the wrecks would long have been stripped of their AI Cores...\""
                        mc "\"A more surreptitious approach then...\""
                        mc "\"Maybe I can find a competent hacker to take them offline...\""
                        call quest_updater() from _call_quest_updater_120
                    else:
                        mc "\"This was a, ahem... navigational error.\""
                        mc "\"I'm gone already...\""

                elif GAME.ship.getSubSysStatus("uplink") < 80:
                    queue sound "audio/notify.wav"
                    mc "\"I better bring my Argus System up to max before trying this...\"" 

                # late in the day
                elif GAME.hour >= 18:
                    mc "\"I should do that when I am better rested...\""

                # gear not up to scratch
                elif GAME.ship.getSubSysStatus("shields") == 0 or GAME.ship.getSubSysStatus("weapons") == 0:
                    queue sound "audio/drone_beep.wav"
                    if not GAME.mc.hasDone("illegal_bot_warning"):
                        bb2 "\"I would not go in there yet, Captain [GAME.mc.name].\""
                        mc "\"Why?\""
                        bb2 "\"Although the Argus allows us to sneak in, dangers lurk inside.\""
                        bb2 "\"Our ship should at least be equipped with shields and weapons...\""
                        mc "\"Where can I get those...?\""
                        bb2 "\"There are Pirates who are willing to sell them to you for a price.\""
                        bb2 "\"Nimhe might be able to tell you how to find them...\""
                        mc "\"How so?\""
                        bb2 "\"When she was trading in illegal bots she built up contacts...\""
                        bb2 "\"Just ask her about her illegal bots...\""
                        call quest_updater() from _call_quest_updater_121
                    else:
                        bb2 "\"We better arm our ship before going in there...\""
                        mc "\"Ah, right.\""
                        mc "\"We should pay the Pirate Base a visit for that.\""

                # quest-specific intercepts
                elif spaceLoc.ID == "LIDJunkyardQuthor" and "quthos_pre_approved" not in GAME.mc.done and not GAME.questSys.isDone('QID_MAIN_QUTHOR_QUARRY_MAP'):
                    stop music fadeout 1.0
                    $ GAME.mc.hasDone("quthor_pre_rejected")
                    queue sound "audio/alert.wav"
                    "Quthor Command" "\"This Site is Military Research Use only.\"" with redflash
                    "Quthor Command" "\"Be advised to leave this location immediately.\""
                    queue sound "audio/beep.wav"
                    "Quthor Command" "\"Quthor Command Out.\""
                    mc "{i}\"Too bad...\"{/i}"
                    mc "{i}\"We need to find a way in there somehow...\"{/i}"
                    call quest_updater() from _call_quest_updater_122

                elif "pre_"+GAME.getStarSys().name.lower()+"_3" not in GAME.mc.done:

                    scene expression("11_backgrounds/backdrop_junkyard.jpg") with fade
                    if not GAME.mc.hasDone("argus_comment"):
                        mc "\"Now let's see whether that money for the Argus Uplink was well spent...\""
                    if GAME.getSpaceLoc().ID == "LIDJunkyardQuthor" and GAME.questSys.isDone('QID_MAIN_QUTHOR_QUARRY_MAP'):
                        "Navigating the spacial tendrils of The Quarry, you make your way into the Junkyard..." with fade
                    else:
                        "Scrambling the Guardian's sensors, you make your way into the Junkyard..." with fade
                    $ GAME.mc.hasDone('precursor_core_found') # for first precursor quest progression

                    # ===== CR-0438 START =====
                    # select scenario 
                    $ scenarioID = False
                    if "pre_"+GAME.getStarSys().name.lower()+"_1" not in GAME.mc.done:
                        $ scenarioID = "pre_"+GAME.getStarSys().name.lower()+"_1"
                    elif "pre_"+GAME.getStarSys().name.lower()+"_2" not in GAME.mc.done:
                        $ scenarioID = "pre_"+GAME.getStarSys().name.lower()+"_2"
                    elif "pre_"+GAME.getStarSys().name.lower()+"_3" not in GAME.mc.done:
                        $ scenarioID = "pre_"+GAME.getStarSys().name.lower()+"_3"

                    # combat execution
                    if scenarioID:
                        ###########################################################
                        #              ZEALOT INTERCEPT
                        ###########################################################
                        if "pre_xenos" in scenarioID:
                            if "zealot_accept" in GAME.mc.done:
                                "At strategic positions, you notice the Zealot Guards..."
                                mc "\"Worth a try, but I better not break that deal with the Zealots...\""
                                return(["transition", GAME.getStarSys().locs["LIDJunkyardXenos"]])

                            elif "zealot_oppose" in GAME.mc.done and scenarioID not in GAME.mc.done:
                                $ resume_scenarioID = str(scenarioID) # paranoid
                                call cutscene("zealot_guards") from _call_cutscene_38
                                if "victory" not in _return:
                                    # booted to space
                                    return(["transition", GAME.getStarSys().locs["LIDJunkyardXenos"]])
                                # continue with precursor scenario 
                                mc "\"That was tough...\""
                                mc "\"Now for the Precursors...\""
                                $ scenarioID = resume_scenarioID



                            elif "zealot_encounter" not in GAME.mc.done or "zealot_reconsider" in GAME.mc.done:
                                call cutscene("zealot_encounter") from _call_cutscene_39
                                call quest_updater() from _call_quest_updater_123
                                call quest_updater() from _call_quest_updater_124 
                                return(["transition", GAME.getStarSys().locs["LIDJunkyardXenos"]])
 
                        ###########################################################
                        #              PRECURSOR COMBAT
                        ###########################################################
                        call mg_combat_scenario(scenarioID) from _call_mg_combat_scenario_8
                        $ result = _return
                        if "victory" in result: # EXP returned
                            $ damage = result[1]
                            $ exp = result[2]
                            queue sound "audio/triumph.wav"
                            call simple_notify("VICTORY", "+[exp:,] EXP gained", ["Continue"], "05_gui/ico_gui_cup.png") from _call_simple_notify_53
                            queue sound "audio/click.wav"            
                            $ GAME.mc.exp += exp
                            call attr_mod(GAME.mc, "NOT", 1, 100, 100, True) from _call_attr_mod_68                        
                        else:
                            mc "\"That was close...\""

                        $ mapFragmentsPost = GAME.mc.inventory.count(GAME.items["ITMMapPrecursor"]) # CR-0685
                        
                        if scenarioID == "pre_"+GAME.getStarSys().name.lower()+"_3" and mapFragmentsPost > mapFragmentsPre: # CR-0685
                            tri "\"Excellent!\""
                            tri "\"We have gained a Hyperspace map fragment from this site!\""
                            call attr_mod(tris, "APP", 5, 100, 100, True) from _call_attr_mod_69
                        # =====  CR-0685 START
                        elif scenarioID == "pre_"+GAME.getStarSys().name.lower()+"_3" and mapFragmentsPost <= mapFragmentsPre:
                            tri "\"We failed to gain a Precursor Map Fragment from the site!\""
                            tri "\"We might have to venture in again better prepared.\""                   
                        # =====  CR-0685 END

                        call hour_passes(18-GAME.hour) from _call_hour_passes_57
                        scene nav_screen_smart with fade
                        show screen header()
                        
                    else:
                        mc "\"There is nothing for me left to discover here...\""
                        mc "\"I should look for Precursor sites in other Star Systems...\""

                elif "pre_"+GAME.getStarSys().name.lower()+"_3" in GAME.mc.done:
                    queue sound "audio/notify.wav"
                    mc "\"I have cleaned out that location already...\""
                    mc "\"Maybe there are similar locations in other Star Systems...\""

                # ===== CR-0438 END =====


            #####################################################################
            #                ANOMALY
            #####################################################################
            elif spaceLoc.ID == "LIDAnomalyIltari" and GAME.questSys.inProgress('QID_MAIN_ANOMALY') and spaceLoc.ID == GAME.ship.spaceLocID:
                if GAME.hour > 18:
                    mc "\"We should rest before venturing inside...\""
                else:
                    call cutscene("anomaly investigate") from _call_cutscene_40
                    # "Foo1" CR-0606
                    $ GAME.hour = 20
                    $ GAME.setLocID("LOCCargo")
                    call sandbox_interior_prepare_scene() from _call_sandbox_interior_prepare_scene_11
                    # "Foo2" CR-0606
                    return(["transition", GAME.locs["LOCCargo"]]) # CR-0590


            #####################################################################
            #					ODDITY / MYSTERY		
            #####################################################################
            elif spaceLoc.ID in ["LIDOddityIltari"] and spaceLoc.ID == GAME.ship.spaceLocID:
                $ roll = random.randint(1,100) # CR-0609
                if GAME.hour >= 22:
                    mc "\"It is too late for exploring this site...\""
                
                elif roll < 75 or not GAME.ship.hasSubSys("mining"):
                    queue sound "audio/notify.wav"
                    call simple_notify("ENCOUNTER FROM THE VOID", "Swarm Vessels Emerge!", ["Engage", "Flee"], "05_gui/ico_gui_hostile_swarm.png", "pink") from _call_simple_notify_54
                    queue sound "audio/click.wav"
                    if _return == "Engage":
                        call mg_combat_scenario(random.choice(["swarm_1", "swarm_2", "swarm_3", "swarm_5", "swarm_convoy"])) from _call_mg_combat_scenario_9       
                        if "abort" not in _return:
                            $ spaceLoc.found = False      
                    else:
                        mc "\"Maybe when I am better prepared...\""

                else:
                    queue sound "audio/notify.wav"
                    call simple_notify("THE VOID FIELDS", "Wormhole to The Void!", ["Enter", "Abort"], "08_items/ico ITMNanotubes.png", "pink") from _call_simple_notify_55
                    queue sound "audio/click.wav"
                    if _return == "Enter":
                        # save current loc
                        $ saveSpaceLoc = GAME.getSpaceLoc()
                        $ saveStarSys = GAME.getStarSys()

                        # transfer to void, mining 
                        $ GAME.ship.starSysID = "SSIDVoid"
                        $ GAME.setSpaceLocID("LIDAsteroidsVoid")
                        call mg_mining_pick("THE VOID - ASTEROID FIELD") from _call_mg_mining_pick_1

                        # restor loc
                        $ GAME.ship.starSysID = saveStarSys.ID
                        $ GAME.setSpaceLocID(saveSpaceLoc.ID)
                        $ spaceLoc.found = False
                    else:
                        mc "\"Maybe some other time...\""

            #####################################################################
            #                KRELL / DOME
            #####################################################################
            elif spaceLoc.ID == "LIDDomeArellarti" and spaceLoc.ID == GAME.ship.spaceLocID:
                play sound "audio/beep.wav"
                "Arellarti Dome Administrator" "\"No Access For Humans.\""
                mc "\"I see...\""
                mc "\"I better go elsewhere then...\""

            #####################################################################
            #                KRELL / LAB
            #####################################################################
            elif spaceLoc.ID == "LIDLabsArellarti" and spaceLoc.ID == GAME.ship.spaceLocID:
                # if not GAME.questSys.isActive('QID_KRELL_KICKOFF'):
                #     play sound "audio/beep.wav"
                #     "Kranor Labs Administrator" "\"Top Secret Research going on here.\""
                #     "Kranor Labs Administrator" "\"Move along!\""
                #     mc "\"I see...\""
                #     mc "\"I better go elsewhere then...\""
                
                if not GAME.questSys.isActive('QID_KRELL_INTERCEPT'):
                    call cutscene("inquire_biolab") from _call_cutscene_41

                elif not GAME.questSys.isDone('QID_KRELL_YLYEE_WAIT'):
                    "Kranor Labs Administrator" "\"I've told you to seek business elsewhere!\""

                else:
                    queue sound "audio/beep.wav"
                    "Kranor Labs Administrator" "\"Lab is closed for repairs.\""
                    "Kranor Labs Administrator" "\"Area is not safe!\""
                    mc "\"I see...\""
                    mc "\"I better go elsewhere then...\""

            #####################################################################
            #              QUTHOR
            #####################################################################
            elif spaceLoc.ID == "LIDQuarry" and spaceLoc.ID == GAME.ship.spaceLocID:
                if GAME.questSys.inProgress('QID_MAIN_QUTHOR_BELIT_CASH'):
                    call cutscene_quthor("belit_cash") from _call_cutscene_quthor_12
                    call quest_updater() from _call_quest_updater_125

                elif GAME.questSys.inProgress('QID_MAIN_QUTHOR_BELIT_SHIELD'):
                    call cutscene_quthor("belit_shield") from _call_cutscene_quthor_13
                    call quest_updater() from _call_quest_updater_126

                elif GAME.questSys.isActive('QID_MAIN_QUTHOR_BELIT_MAP'):
                    queue sound "audio/notify.wav"
                    call simple_notify("THE QUARRY", "Contact Belit", ["Contact", "Abort"], "05_gui/ico Ship.png", "orange") from _call_simple_notify_56
                    if _return == "Contact":
                        "You contact Belit..."
                        queue sound "audio/beep.wav"
                        call belit_trader() from _call_belit_trader

                else:
                    queue sound "audio/drone_beep.wav"
                    bb2 "\"I advise to stay clear of that area, Captain [GAME.mc.name].\""
                    mc "\"Why?\""
                    bb2 "\"Sensors indicate a pattern of Fractured Space...\""
                    bb2 "\"We better stay out of there...\""
                    mc "\"Agreed.\""

            elif spaceLoc.ID == "LIDLedruhk" and spaceLoc.ID == GAME.ship.spaceLocID and GAME.questSys.inProgress('QID_MAIN_QUTHOR_ORE'):
                call cutscene_quthor("infernium_delivery") from _call_cutscene_quthor_14
                call quest_updater() from _call_quest_updater_127
            
            elif spaceLoc.ID == "LIDMinosForge" and spaceLoc.ID == GAME.ship.spaceLocID and GAME.questSys.inProgress('QID_MAIN_QUTHOR_PLATING2'):
                call cutscene_quthor("infernium_plating_delivered") from _call_cutscene_quthor_15
                call quest_updater() from _call_quest_updater_128

            elif spaceLoc.ID == "LIDMinosForge" and spaceLoc.ID == GAME.ship.spaceLocID and GAME.questSys.inProgress('QID_MAIN_QUTHOR_MIL_GREASE'):
                call cutscene_quthor("minos_vortex") from _call_cutscene_quthor_16
                call quest_updater() from _call_quest_updater_129


            #####################################################################
            #					EXECUTE TRAVEL							  #
            #####################################################################
            elif _return[1].ID != GAME.ship.spaceLocID: # travel
                if GAME.hour >= 22:
                    mc "\"I should resume exploring tomorrow...\""
                else:
                    $ tgtLocID = _return[1].ID
                    $ tgtLoc = _return[1] 
                    call travel("You speed towards your target...") from _call_travel
                    $ GAME.hour += 1
                    # enable visited locations for missions once intro done
                    if GAME.questSys.isDone("QID_MAIN_STUDYMAP"):
                        $ tgtLoc.mission = True

                    #####################################################################
                    #					QUTHOR BELT CROSSING		
                    #####################################################################
                    if GAME.getStarSys().ID == "SSIDQuthor" and "belt_crossed" not in GAME.mc.doneToday and GAME.getSpaceLoc().zone >=75 and tgtLoc.zone <= 50:
                        queue sound "audio/notify.wav"
                        call large_notify("THE ASTEROID BELT", "Entering the dangerous Quthor Asteroid Belt, you must decide on a course of action.\n\nYou can either risk damage or navigate the pirate infested passages.", ["Damage", "Passage", "Abort"], "05_gui/ico Ship.png", "orange") from _call_large_notify_40 
                        if _return == "Abort":
                            "You turn back your ship and reconsider..."
                            $ tgtLocID = GAME.ship.spaceLocID
                        elif _return == "Damage" and random.randint(1,100) > 30:
                            call check_occurrence(tgtLoc, random.choice(["OCCAsteroidsQuthor001"])) from _call_check_occurrence
                            if random.randint(1,100) > 50:
                                call check_occurrence(tgtLoc, random.choice(["OCCWreckDrengar02", "OCCBotContainer001"])) from _call_check_occurrence_1
                        elif _return == "Damage":
                            "Unexpectedly, you make it through the belt without damage..."
                        elif _return == "Passage" and random.randint(1,100) > 30:
                            call check_occurrence(tgtLoc, random.choice(["OCCHostileDrengar02"])) from _call_check_occurrence_2 
                        elif _return == "Passage":
                            "Unexpectedly, you make it through the belt unscathed..."
                        
                        call travel("You resume your travels...") from _call_travel_1
                        $ GAME.mc.hasDoneToday("belt_crossed")

                    #####################################################################
                    #					KRELL BELT CROSSING		
                    #####################################################################
                    if GAME.getStarSys().ID == "SSIDArellarti" and "belt_crossed" not in GAME.mc.doneToday and GAME.getSpaceLoc().zone >=50 and tgtLoc.zone <= 25:
                        queue sound "audio/notify.wav"
                        call large_notify("THE ASTEROID BELT", "Entering the dense Arellarti Asteroid Belt, you must decide on a course of action.\n\nYou can either risk damage or navigate the pirate infested passages.", ["Damage", "Passage", "Abort"], "05_gui/ico Ship.png", "green") from _call_large_notify_41 
                        if _return == "Abort":
                            "You turn back your ship and reconsider..."
                            $tgtLocID = GAME.ship.spaceLocID
                        elif _return == "Damage" and random.randint(1,100) > 30:
                            call check_occurrence(tgtLoc, random.choice(["OCCAsteroids001"])) from _call_check_occurrence_3
                            if random.randint(1,100) > 50:
                                call check_occurrence(tgtLoc, random.choice(["OCCWreckKrell02", "OCCBotContainer001"])) from _call_check_occurrence_4
                        elif _return == "Damage":
                            "Unexpectedly, you make it through the belt without damage..."
                        elif _return == "Passage" and random.randint(1,100) > 30:
                            call check_occurrence(tgtLoc, random.choice(["OCCHostileKrell01", "OCCHostileKrell02"])) from _call_check_occurrence_5 
                        elif _return == "Passage":
                            "Unexpectedly, you make it through the belt unscathed..."
                        
                        call travel("You resume your travels...") from _call_travel_2
                        $ GAME.mc.hasDoneToday("belt_crossed")
                            
                    #####################################################################
                    #					GENERAL OCCURRENCE		
                    #####################################################################
                    elif "occurrence" not in GAME.mc.doneToday and random.randint(1,100) > 50 and GAME.day > 2:
                        call check_occurrence(tgtLoc) from _call_check_occurrence_6
                        call achievement_updater() from _call_achievement_updater_1
                        $ GAME.mc.hasDoneToday("occurrence")
                        if _return:
                            if _return == True:
                                pass
                            elif "newloc" in _return:
                                $ tgtLocID = _return[1]
                        call travel("You resume your travels...") from _call_travel_3

                    $ GAME.ship.spaceLocID = tgtLocID
                    scene nav_screen_smart with fade


            #####################################################################
            #					MISSION WITHOUT REQUIRED CARGO		
            #####################################################################
            elif GAME.missionSys.getLocActive(spaceLoc.ID, "loc_only") and spaceLoc.ID == GAME.ship.spaceLocID:
                queue sound "audio/notify.wav"
                mc "\"I don't have all the required cargo loaded yet to fulfil this mission...\"" 
                mc "\"I better check my manifest...\"" 

            #####################################################################
            #					DEFAULT		
            #####################################################################
            else:
                mc "\"There is nothing for me to do here right now...\""
