#####################################################################
#              SANDBOX INTERIOR
#####################################################################

#####################################################################
#              SUPPORT ROUTINES xxx
#####################################################################
label turbolift_nav(deck = 0):

    $ mActiveElem = []
    $ liftOptions = [
        "Deck 1 Blue/1", "True",
        "Deck 2 Red/2", "True",
        "Deck 3 Green/3", "True",
        "Exit/x", "True"
        ]

    if deck in [1,2,3]:
        $ result = {1: "Deck 1 Blue", 2: "Deck 2 Red", 3: "Deck 3 Green"}[deck]
    else:
        queue sound "audio/beep.wav"
        call screen menu_interactive_scr(" ", liftOptions, mActiveElem)
        play sound "audio/click.wav"
        $ result = _return

    # swap to new loc minimap
    if result == "Deck 1 Blue":
        if GAME.miniMapActive.ID == "MMIDShip":
            queue sound "audio/tech_fail.wav" 
        else:
            play sound "audio/door_scifi.wav"
            $ GAME.miniMapActive = GAME.miniMaps["MMIDShip"]
            call sandbox_interior_navigate_to("LOCHallway1") from _call_sandbox_interior_navigate_to_83 
    elif result == "Deck 2 Red":
        if GAME.miniMapActive.ID == "MMIDShipLower":
            queue sound "audio/tech_fail.wav"  
        else:       
            play sound "audio/door_scifi.wav"
            $ GAME.miniMapActive = GAME.miniMaps["MMIDShipLower"]
            call sandbox_interior_navigate_to("LOCHallwayLower1") from _call_sandbox_interior_navigate_to_84 
    elif result == "Deck 3 Green":
        if GAME.miniMapActive.ID == "MMIDShipLower2":
            queue sound "audio/tech_fail.wav"     
        else:    
            play sound "audio/door_scifi.wav"
            $ GAME.miniMapActive = GAME.miniMaps["MMIDShipLower2"]
            call sandbox_interior_navigate_to("LOCHallwayLower2") from _call_sandbox_interior_navigate_to_85 
    return()

#####################################################################
#                INTERIOR NAVIGATE
#####################################################################
screen sandbox_interior_navigate_scr(mode="normal"): # CR-0597

    #####################################################################
    #                Integrate Inner Screens
    #####################################################################
    for i in GAME.getLoc().screens:
        use expression (i)

    #####################################################################
    #                Active Elements / NORMAL
    #####################################################################
    $ loc = GAME.getLoc().ID

    if mode == "use":
        $ nCurs = "myMouseUse"
        $ aElems = [x for x in GAME.aElem.values() if x.loc == loc]
        $ aElems.sort(key = lambda x : ("sprite" in x.tags, x.ID))
        for i in aElems: #[x for x in GAME.aElem.values() if x.loc == loc]:
            if eval(i.cond):
                if "hidden" in i.tags:
                    imagebutton hover "{}_smart".format(i.ID) idle "{}_smart".format(i.ID) focus_mask True action Return(["action", i]) pos i.coord mouse nCurs
                else:
                    imagebutton auto "{}_smart_%s".format(i.ID) focus_mask True action Return(["action", i]) pos i.coord mouse nCurs

    elif mode == "normal":
        $ aElems = [x for x in GAME.aElem.values() if x.loc == loc]
        $ aElems.sort(key = lambda x : ("sprite" in x.tags, x.ID))
        for i in aElems: # [x for x in GAME.aElem.values() if x.loc == loc]:
            if eval(i.cond):
                if "hidden" in i.tags:
                    imagebutton hover "{}_smart".format(i.ID) idle "{}_smart".format(i.ID) focus_mask True action Return(["action", i]) pos i.coord
                else:
                    imagebutton auto "{}_smart_%s".format(i.ID) focus_mask True action Return(["action", i]) pos i.coord

    #####################################################################
    #   Missions Icon - OhWeeMod
    $ missiontooltip = "          Contracts:\n\n"
    fixed:
        for i in GAME.missionSys.getDueMissions():

                # mission location
                if i.sLocID:
                    $ sLoc = GAME.getSpaceLoc(i.sLocID)
                    $ missiontooltip += sLoc.name + " - "

                # specifics
                if i.kind in ["transport", "smuggling"]:
                    $ itemID = i.attr["wareID"]
                    $ amount = i.attr["amount"]
                    $ missiontooltip += (GAME.items[itemID].getName(["cap"])) + " ("
                    $ missiontooltip += str(amount) + "t) - "
                else: #elif i.kind == "bounty":
                    $ missiontooltip +="Bounty Level " + str(i.lvl) + " - "


                # due date
                $ dueDays = i.due-GAME.day
                if dueDays == 0:
                    $ missiontooltip += "Due Today!\n"
                elif dueDays == 1:
                    $ missiontooltip += "Due in 1 Day\n"
                else:
                    $ missiontooltip += "Due in " + str(dueDays) + " Days\n"
                    
    imagebutton auto "05_gui/ico_Missions_%s.png" xpos 5 ypos 0:
        at customzoom50
        action Return(["missions"]) tooltip missiontooltip
    # end OhWee mod        
    #####################################################################

    #####################################################################
    #              SHORTCUTS NEW
    #####################################################################
    # ===== CR-0605 START
    hbox pos 40,1000 spacing 3:       
        textbutton "HOTKEYS" text_style "text_std" action Return("hotkeys")
        if "sleep" in GAME.mc.done and GAME.miniMapActive.ID in ["MMIDShip", "MMIDShipLower2", "MMIDShipLower"]:
            if GAME.guiInt["hotkeys"]:
                imagebutton auto "05_gui/moon_%s.png"  yalign 0.5 action Return(["sleep"])
                text "(A)" size FSIZE yalign 0.7
                text " " size FSIZE
            key "a" action Return(["sleep"])
            
        if "cargo" in GAME.mc.done and GAME.miniMapActive.ID in ["MMIDShip", "MMIDShipLower2", "MMIDShipLower"]:
            if GAME.guiInt["hotkeys"]:
                imagebutton auto "05_gui/cargo_%s.png" yalign 0.5 action Return(["cargo"])
                text " " size FSIZE
                text "(C)" size FSIZE yalign 0.7
            key "c" action Return(["cargo"])
            
        if "engine" in GAME.mc.done and GAME.miniMapActive.ID in ["MMIDShip", "MMIDShipLower2", "MMIDShipLower"]:
            if GAME.guiInt["hotkeys"]:
                imagebutton auto "05_gui/engine_%s.png" yalign 0.5 action Return(["engine"])
                text "(E)" size FSIZE yalign 0.7
            key "e" action Return(["engine"])

        if GAME.questSys.isDone('QID_INTRO_LOWER3') and GAME.miniMapActive.ID in ["MMIDShip", "MMIDShipLower2", "MMIDShipLower"]:
            if GAME.guiInt["hotkeys"]:
                imagebutton auto "05_gui/lift_%s.png" yalign 0.5 action Return(["turbolift", "menu"]) # CR-0665
                text "(T)" size FSIZE yalign 0.7
            key "t" action Return(["turbolift", "menu"])

        if GAME.guiInt["hotkeys"]:
            imagebutton auto "05_gui/GUI_PDA_%s.png"  yalign 0.5 action Return(["pda", None])
            text "(P)" size FSIZE yalign 0.6
            text " " size FSIZE
            
        # CR-0911 ====== START
        if GAME.questSys.isDone('QID_INTRO_COMMAND') and GAME.hour < 21:
            if GAME.guiInt["hotkeys"]:
                imagebutton auto "05_gui/hourglass_%s.png"  yalign 0.5 action Return(["hour", None])
                text "(Q)" size FSIZE yalign 0.6
                text " " size FSIZE
        # CR-0911 ====== END

        if bb_2 in GAME.crew:
            if GAME.guiInt["hotkeys"]:
                imagebutton hover "05_gui/gui_mini_list.png" idle "05_gui/gui_mini_list.png"  yalign 0.5 action Return(["stats", None])
                text "(L)" size FSIZE yalign 0.6
                text " " size FSIZE
            key "l" action Return(["stats", None]) 


            # ===== CR-0605 END

    $ yOff = 80
    $ xOff = 1910

            
    #####################################################################
    #                MINI MAP NEW
    #####################################################################
    # ===== CR-0857 START
    grid 3 5 pos 40, 160 spacing 10:
        for i in range(5):
            for j in range(3):
                $ cell = GAME.miniMapActive.cells[i][j]
                if cell != 0:
                    $ locID = GAME.miniMapActive.cells[i][j].locID
                    $ loc = GAME.locs[locID]
                    if loc.found:
                        $ locColor = "#0099cc88"
                        if cell.ID in ["AL"] and GAME.ship.status not in ["docked", "landed"]: # CR-0741
                            $ locColor = "#cc440088"
                        elif cell.ID in ["AL", "SH", "EX", "TL"]:
                            $ locColor = "#44cc0088"

                        frame xsize 52 ysize 52 background Solid(locColor) padding (0,0):
                            text cell.ID xalign 0.5 yalign 0.5 size FSIZE
                            button action Return(["nav", cell]) tooltip ["nav", cell]
                            if loc.ID == GAME.getLoc().ID:
                                image "05_gui/gui_minimap_frame.png" xalign 0.5 yalign 0.5
                            if "chair activated" in GAME.mc.done:
                                for n in GAME.crew:
                                    if loc.ID == n.isAt():
                                        image "05_gui/px_1x1_red.png" xsize 8 ysize 8 # pos -4,-4 
                            if GAME.hasRepSpot(locID) and tris.getJob().ID == "JOB_Diag":
                                image "05_gui/px_1x1_yellow.png" xsize 8 ysize 8 pos 44, 0     
                    else:
                        frame xsize 52 ysize 52 background Solid("#88888888") padding (0,0):
                            button action Return(["nav_hint", cell]) tooltip ["nav_unknown", cell]

                else:
                    text " "
    # ===== CR-0857 END

    #####################################################################
    #					WIDGETS NOTIFIERS xxx				   
    #####################################################################
    vbox pos 40,454 spacing 5:

        if GAME.miniMapActive.ID in ["MMIDShip", "MMIDShipLower", "MMIDShipLower2"]:
            # ===== CR-2014 START
            if GAME.questSys.isDone("QID_INTRO_LOWER3"): 
                textbutton "DECKS" text_style "text_std" action Return("ship_decks")
                $ dCols = {1: "#f5b04188", 2: "#f5b04188", 3: "#f5b04188"}
                # $ dCols = {1: "#0099cc88", 2: "#cc440088", 3: "#44cc0088"}

                hbox spacing 10:
                    if GAME.guiInt["ship_decks"]:
                        for i in range(3):
                            frame xsize 52 ysize 52 background Solid ("88888888") padding 0,0:
                                frame xsize 52 ysize 52 background Solid (dCols[i+1]) padding 0,0 yalign 0.5
                                text "{}".format(i+1) xalign 0.5 ypos 16 size FSIZE
                                button action Return(["turbolift", i+1])
                text " " size FSIZE_MED
            ## ===== CR-2014 END

            textbutton "SHIP STATS" text_style "text_std" action Return("ship_stats")
            
            if GAME.guiInt["ship_stats"] and GAME.questSys.isActive("QID_INTRO_ENGINE"): # CR-0597
                # SUBSYSTEMS
                $ sysSummary = GAME.ship.getSubSysSummary()
                $ sysName = {
                             "CA": "Cargo", 
                             "EN": "Engine",
                             "HY": "H.Drive", 
                             "LA": "Launcher",
                             "MI": "M.Laser",
                             "SH": "Shields", 
                             "UP": "Uplink", 
                             "WE":"Weapon"
                            }
                            
                vpgrid:
                    cols 2
                    spacing 5
                    xoffset -20
                #grid G_X G_Y spacing 5 xoffset -20:
                    for i in range(len(sysSummary)):
                        #if i < len(sysSummary):
                            frame xsize 150 ysize 35 background Solid("#00000088"): #Solid("#88888888")
                                #text sysSummary[i][0] size FSIZE
                                text sysName[sysSummary[i][0]] size 24
                                text sysSummary[i][1] size FSIZE xpos 90
                        #else:
                            #frame xsize 150 ysize 35 background Solid("#00000000")

                # HULL
                frame xsize 128 ysize 128 background Solid("#00000000") xoffset -25:
                    $ hull = GAME.ship.getHullState()
                    image "05_gui/hull_ship.png" xalign 0.5 yalign 0.5 zoom 0.25
                    for i in hull.keys():
                        image "05_gui/hull_{}_{}.png".format(i, hull[i]) xalign 0.5 yalign 0.5 zoom 0.25
                    # CR-0968 START ====
                    if "red" in hull.values():
                        image "05_gui/ico_attention_256x256.png" xpos -3 ypos -10 zoom 0.5
                text "Ablative Rating:" size 24 xpos 100 ypos -120 color "#999"
                text "{:,} GW".format(round(GAME.ship.getTotalAblation_NEW(),1)) xpos 135 ypos -118 size FSIZE
                    # CR-0968 END ====
                        
            if not GAME.ship.subSys["launcher"][0] == False and GAME.guiInt["ship_stats"]:
                text "Torpedo Loadout:" size 24 xoffset 100 yoffset -95 color "#999"
                $ maxLoadout = GAME.ship.getLoadoutMax("launcher")
                $ addOns = GAME.ship.getAddOns("launcher")
                hbox spacing 8 yoffset -95:
                    if maxLoadout < 5:
                        xoffset 96
                    else:
                        xoffset 272 - (maxLoadout * 44)
                    for i in range(6):
                        if maxLoadout > i:
                            frame xsize 36 ysize 36 background Solid("#00000088"):
                                image "03_minigames/ico_slot_subunit.png" xalign 0.5 yalign 0.5 zoom 0.375
                                if khelara in GAME.crew:
                                    button action Return(["managetorploadout", "launcher", i, addOns[i]])
                                if addOns[i]:
                                    image "08_items/ico {}.png".format(addOns[i].ID) xalign 0.5 yalign 0.5 zoom 0.125
                
        $ missions = [x for x in GAME.missionSys.getDueMissions() if x.due == GAME.day]
        $ sLoc = GAME.getSpaceLoc()

    vbox pos 240,140 spacing 5:
        if [x for x in GAME.ship.cargo if not sLoc.isLegal(x.ID)] and GAME.ship.boarded():
            text C_RE_B+"ILLEGAL CARGO!"+C_RE_E size FSIZE
        if missions:
            text C_YE_B+"DUE MISSIONS! ({})".format(len(missions))+C_YE_E size FSIZE
        if GAME.repQueue and "JOB_Diag" == tris.getJob().ID:
            text C_YE_B+"REPAIRS ({}x)".format(len(GAME.repQueue))+C_YE_E size FSIZE

    #####################################################################
    #              PET WIDGET xxxx
    #####################################################################
    vbox pos 50,600 spacing 5:
        for actor in [tris, moira, seraphine, nimhe]:
            if actor.isAt() == "LOCPetwalk":
                frame xsize 136 ysize 136 background Solid("#00000088"):
                    image "05_gui/ico_pet_{}.png".format(actor.ID) xalign 0.5 yalign 0.5
                    button action Return(["pet", actor])


    #####################################################################
    #                INVENTORY
    #####################################################################

    #vbox pos xOff-80, yOff xalign 1.0:
    #    textbutton "INVENTORY" text_style "text_std" action Return("gui_inventory")
           
    if GAME.guiInt["inventory"]:
        frame xsize 200 ysize 160 pos xOff-30, yOff+20 xalign 1.0 background Solid("#ffffff00"):
            image "05_gui/ico ITMBoxSmall.png" zoom 0.5  xalign 0.5 yalign 0.5
            button action Return(["inventory", None])


    hbox xalign 1.0 pos xOff-10, yOff+200+580+20:
        if GAME.mc.invHistory:
            imagebutton hover "05_gui/gui arrow left.png" idle "05_gui/gui arrow left.png" xalign 0.5 yalign 0.5 action Return(["gui", "left"])
            frame xsize 128 ysize 128 xalign 0.5 yalign 0.5 background Solid("#00000000"):
                image "08_items/ico bg1.png" zoom 0.25 xalign 0.5 yalign 0.5
                image "08_items/ico {}.png".format(GAME.mc.invHistory[-1].ID) zoom 0.25 xalign 0.5 yalign 0.5
                button action Return(["use", GAME.mc.invHistory[-1]])
            imagebutton hover "05_gui/gui arrow right.png" idle "05_gui/gui arrow right.png" xalign 0.5 yalign 0.5 action Return(["gui", "right"])
            key "b" action Return(["use", GAME.mc.invHistory[-1]])

        else:
            frame xsize 128 ysize 128 xalign 0.5 yalign 0.5 background Solid("#00000000")

    if GAME.mc.invHistory:
        if mode == "use":
            text "[C_YE_B]Use Mode[C_YE_E]" size FSIZE pos 1772, yOff+330+580 xalign 0.5
        else:
            text "Click To Use (B)" size FSIZE pos 1772,yOff+330+580 xalign 0.5

    # # Holodeck controls 
    # if GAME.getLoc().ID in ["LOCHolo", "LOCHoloCastle", "LOCHoloBlank"] and "holo_repaired" in khelara.done:
    #     frame xsize 200 ysize 200 pos xOff-30, yOff+600 xalign 1.0 yalign 0.5 background Solid("#00000000"):
    #         image "08_items/ico bg1.png" zoom 0.25 xalign 0.5 yalign 0.5
    #         image "08_items/ico ITMCardHolo.png"zoom 0.5 xalign 0.5 yalign 0.5
    #         button action Return( ["holodeck", None])

    key "K_LEFT" action Return(["gui", "left"])
    key "K_RIGHT" action Return(["gui", "right"])
    key "i" action Return(["inventory", None])
    key "p" action Return(["pda", None])
    key "x" action Return(["console", "None"])
    # CRQ-0946 START ========
    if GAME.questSys.isDone("QID_INTRO_COMMAND") and GAME.hour < 22:
        key "q" action Return(["hour", None])
    # CRQ-0946 END ========

    # key "l" action Return(["stats", None]) # CR-0422



    #####################################################################
    #                Tooltip & Console
    #####################################################################
    # use console_overlay 

    $ tooltip = GetTooltip()
    if tooltip and isinstance(tooltip, list):
        if "nav" in tooltip:
            text "{}".format(tooltip[1].name) size FSIZE pos 124, 120 xalign 0.5
        elif "nav_unknown" in tooltip:
            text "Undiscovered" size FSIZE pos 124, 120 xalign 0.5
    elif tooltip and tooltip == missiontooltip:
        text [tooltip] size 20 pos 20, 25
    #else:
        #if tooltip != None:
            #text [tooltip]
        

    #####################################################################
    #					DEBUGMODE		
    #####################################################################
    if "on" in GAME.debugMode:
        vbox xsize 200:
            text "{}".format(" / ".join(GAME.locHistory)) size FSIZE_MED

label sandbox_interior():

    $ mode = "normal"
    $ useItem = False
    $ transition = False 
    # attr = {"ship_stats": True} # CR-0597

    #####################################################################
    #              PREP SCENE xxx
    #####################################################################
    call sandbox_interior_navigate_to(GAME.sandboxLoc.ID) from _call_sandbox_interior_navigate_to_86 
    #call sandbox_interior_prepare_scene()

    while True:

        #####################################################################
        #                INTERCEPTS & NOTIFICATIONS
        #####################################################################
        call intercept() from _call_intercept 
        call quest_updater() from _call_quest_updater_207 

        if GAME.hour >= 23:
            if not "evening_visit" in GAME.mc.doneToday:
                "It has grown late and you call it a day..."
            $ GAME.setLocID("LOCCaptain")
            $ GAME.miniMapActive = GAME.miniMaps["MMIDShip"]
            call night_passes() from _call_night_passes_1 

        #####################################################################
        #                SCENE AND NAVIGATOR
        #####################################################################
        # Get navigation command
        show screen header()
        python:
            if GAME.mc.invHistory:
                for i in GAME.mc.invHistory:
                    if i not in GAME.mc.inventory:
                        GAME.mc.invHistory.remove(i)

        call screen sandbox_interior_navigate_scr(mode)
        #"Foo"

        #####################################################################
        #					MISC  xxx											  #
        #####################################################################
        if _return == "debug":
            play sound "audio/click.wav"
            if "on" in GAME.debugMode:
                $ GAME.debugMode.remove("on")
            else:
                $ GAME.debugMode.append("on")

        elif _return == "ship_stats":
            queue sound "audio/click.wav"
            $ GAME.guiInt["ship_stats"] = not GAME.guiInt["ship_stats"]
   
        elif _return == "ship_decks":
            queue sound "audio/click.wav"
            $ GAME.guiInt["ship_decks"] = not GAME.guiInt["ship_decks"]

        elif _return == "hotkeys":
            queue sound "audio/click.wav"
            $ GAME.guiInt["hotkeys"] = not GAME.guiInt["hotkeys"]

        elif _return == "gui_inventory":
            queue sound "audio/click.wav"
            $ GAME.guiInt["inventory"] = not GAME.guiInt["inventory"]

        elif _return == "forward": # deprecated
            if GAME.hour < 12:
                scene intermission with dissolve
                call hour_passes(12-GAME.hour) from _call_hour_passes_91 
                "It has become noon..."
            elif GAME.hour < 18:
                scene intermission with dissolve
                call hour_passes(18-GAME.hour) from _call_hour_passes_92 
                "It has become evening..."
            else:
                scene intermission with dissolve
                "You call it a day..."
                call night_passes() from _call_night_passes_2 

        #####################################################################
        #					NAVIGATE						  
        #####################################################################
        elif "console" in _return:
            $ GAME.console = not GAME.console
            
        #####################################################################
        # OhWee mod code w/transplanted yv0751 code
        elif "missions" in _return:

            $ mStarSysOptions = [x for x in GAME.starSys.values() if x.ID in GAME.mc.done]
            $ mStarSys = GAME.getStarSys()

            # shift StarSysuntil current system is pos 0:
            python:
                while mStarSysOptions[0] != mStarSys and mStarSys in mStarSysOptions:
                    mStarSysOptions = mStarSysOptions[1:]+ mStarSysOptions[:1] 

            $ mSelect = True
            $ mFilter = {"transport": True, "smuggling": True, "bounty":True}

            while mSelect:
                #call mg_computer_captain()
                call screen mission_selector_scr(mStarSysOptions, mFilter)
                queue sound "audio/click.wav"
                if _return == False:
                    $ mSelect = False
                            
                elif "abandon" in _return:
                    queue sound "audio/notify.wav"
                    "You abandon the mission... [C_RE_B](REP -1)[C_RE_E]"
                    $ GAME.mc.attr["REP"] = max(0, GAME.mc.attr["REP"]-1)
                    $ GAME.missionSys.purgeMission(_return[1])

                elif "sign" in _return:
                    $ mission = _return[1]
                    $ fee = int(mission.reward * 0.05)
                    if fee > GAME.money:
                        queue sound "audio/tech_fail.wav"
                        
                    elif len(GAME.missionSys.missions) >= 3: # CR-0443
                        queue sound "audio/drone_beep.wav"
                        bb2 "\"I recommend to first complete some of the missions we have already contracted.\""
                        bb2 "\"It would be not good if we lost track of them.\""
                        
                    else:
                        # check ware exclusivity and issue warning 
                        $ accept = True
                        if mission.kind == "transport":
                            if "wareID" in mission.attr.keys():
                                $ ware = GAME.items[mission.attr["wareID"]]
                                if "exclusive" in ware.attr.keys(): 
                                    if ware.attr["exclusive"] != GAME.getStarSys().ID:
                                        queue sound "audio/notify.wav"
                                        call large_notify("MISSION CONFIRMATION", "{} are not available for purchase in {} System\n\nAre you sure you want to sign this transport mission?".format(ware.getName(["col", "cap", "noArt"]), GAME.getStarSys().name), ["Sign", "Abort"], "08_items/ico {}.png".format(ware.ID)) from _call_large_notify_667 
                                        if _return == "Abort":
                                            $ accept = False
                        
                        #####################################################################
                        #					CONTRACT		
                        #####################################################################
                        if accept:
                            queue sound "audio/coin.wav"  
                            call transaction("Signing Fees", -fee, True) from _call_transaction_640 
                            $ GAME.missionSys.acceptMission(mission)
                            $ GAME.starSys[mission.starSysID].missions.remove(mission)
                            #####################################################################
                            #					TUTORIAL BB2		
                            #####################################################################
                            if mission.kind == "transport":
                                if not GAME.mc.hasDone("mission_tut_transport"): # CR-0304
                                    queue sound "audio/drone_beep.wav" # CR-0304
                                    bb2 "\"Excellent, your first delivery mission!\"" # CR-0304
                                    bb2 "\"It will help you to increase your reputation around here.\"" # CR-0304
                                    bb2 "\"This is how it's done:....\"" # CR-0304
                                    bb2 "\"First, collect enough of the ware you have to deliver in your Cargo Bay.\"" # CR-0304
                                    bb2 "\"Then, anytime prior to the due date fly to the delivery nav location.\"" # CR-0304
                                    bb2 "\"You will find the location marked on your nav screen.\"" # CR-0304
                                    bb2 "\"Then click on the nav location to confirm your arrival and have the ware unloaded.\"" # CR-0304
                                    bb2 "\"Don't be too late, or the mission is forfeit and your reputation will suffer.\"" # CR-0304
                                    mc "\"Understood\"" # CR-0304
                            elif mission.kind == "smuggling":
                                if not GAME.mc.hasDone("mission_tut_smuggling"): 
                                    queue sound "audio/drone_beep.wav" 
                                    bb2 "\"Excellent, your first smuggling mission!\"" 
                                    bb2 "\"It will help you to increase your notoriety.\"" 
                                    bb2 "\"This is how it's done:....\"" 
                                    bb2 "\"First, collect enough of the ware you have to deliver in your Cargo Bay.\"" 
                                    bb2 "\"Then, anytime prior to the due date of the delivery fly to the delivery nav location.\"" 
                                    bb2 "\"Make sure to either cloak your cargo or avoid Space Patrol!\"" 
                                    bb2 "\"Don't be too late, or the mission is forfeit and your notoriety will suffer.\"" 
                                    mc "\"Understood\"" 
                            elif mission.kind == "bounty":
                                if not GAME.mc.hasDone("mission_tut_bounty"): 
                                    queue sound "audio/drone_beep.wav" 
                                    bb2 "\"Excellent, your first bounty mission!\"" 
                                    bb2 "\"It will help you to increase your notoriety.\"" 
                                    bb2 "\"This is how it's done:....\"" 
                                    bb2 "\"Check your shields and arms and load torpedoes.\"" 
                                    bb2 "\"Make sure you have good enough gear for the bounty you're taking on.\"" 
                                    bb2 "\"You best start with level 1 or 2 bounties.\"" 
                                    bb2 "\"You can keep and sell the loot you might find on the mission.\"" 
                                    mc "\"Understood\"" 

                        else:
                            queue sound "audio/click.wav"
                elif "filter" in _return:
                    $ mFilter[_return[1]] = not mFilter[_return[1]] 
                elif _return == "left":
                    $ mStarSysOptions = mStarSysOptions[1:]+ mStarSysOptions[:1]
                elif _return == "right":
                    $ mStarSysOptions = mStarSysOptions[-1:]+ mStarSysOptions[:-1]

                
        #end OhWee mod code
        ####################################################################

        elif "sleep" in _return:
            if GAME.miniMapActive != GAME.miniMaps["MMIDShip"]:
                mc "\"I better get back to the Ship's Upper Deck first.\""
            else:
                # ===== CR-0746 START
                $ GAME.setLocID("LOCCaptain")
                call night_passes() from _call_night_passes_3 
                # ===== CR-0746 END

        elif "cargo" in _return:
            if GAME.miniMapActive != GAME.miniMaps["MMIDShip"]:
                mc "\"I better get back to the Ship's Upper Deck first.\""
            else:
                scene room_cargo_smart with fade
                call cargo_manager() from _call_cargo_manager_7 
                $ GAME.setLocID("LOCCargo")

        elif "engine" in _return: # xxxx
            if GAME.miniMapActive != GAME.miniMaps["MMIDShip"]:
                mc "\"I better get back to the Ship's Upper Deck first.\""
            else:
                scene room_engine_smart with fade
                call mg_maintenance() from _call_mg_maintenance_2 
                $ GAME.setLocID("LOCEngine")

        elif "stats" in _return:
            queue sound "audio/click.wav"
            call show_stats(GAME.mc) from _call_show_stats_6 

        elif "hour" in _return and GAME.hour < 22: 
            scene intermission with fade
            if any ([x for x in ["LOCGuest1", "LOCNav", "LOCGuest2"] if GAME.getLoc().ID == x]):
                $ GAME.setLocID("LOCHallway1")
            elif any ([x for x in ["LOCLab", "LOCMaintenance", "LOCCrew1", "LOCCrew2"] if GAME.getLoc().ID == x]): 
                $ GAME.setLocID("LOCHallwayLower1")
            elif any ([x for x in ["LOCMedBay"] if GAME.getLoc().ID == x]): 
                $ GAME.setLocID("LOCHallwayLower2")
            call sandbox_interior_prepare_scene() from _call_sandbox_interior_prepare_scene_50 
            call hour_passes() from _call_hour_passes_93 

        elif "pda" in _return:
            play sound "audio/click.wav"
            call quest_help() from _call_quest_help_1 
            play sound "audio/click.wav"
            call sandbox_interior_prepare_scene() from _call_sandbox_interior_prepare_scene_51 

        elif "turbolift" in _return:
            call turbolift_nav(_return[1]) from _call_turbolift_nav 

        elif "nav_hint" in _return:
            queue sound "audio/notify.wav"
            mc "\"I don't know how to get there...\""
            mc "\"Maybe I can find a way looking around...\""

        elif "nav" in _return:
            $ cell = _return[1]
            # is cell an airlock cell?
            if cell.kind == "airlock":
                if GAME.ship.status == "docked" and GAME.getSpaceLoc().ID == "LIDStationQuthor":
                    queue sound "audio/drone_beep.wav"
                    bb2 "\"We better not leave the ship, Captain [GAME.mc.name]\""
                    bb2 "\"It might take a while  the quarantine is lifted...\""
                    mc "\"Ah right...\""

                elif GAME.ship.status == "docked":
                    # swap to new loc minimap
                    play sound "audio/door_scifi.wav"
                    $ GAME.miniMapActive = GAME.getSpaceLoc().getMiniMap()
                    # navigate to target
                    $ cell = GAME.miniMapActive.getDockingCell()
                    if "galactic_gate_duty" in vee.done and GAME.getSpaceLoc().ID == "LIDWaystation":
                        $ vee.setLocOverride("LOCWayControlRoom") # Waystation duty
                    call sandbox_interior_navigate_to(cell.locID) from _call_sandbox_interior_navigate_to_87 

                elif GAME.ship.status == "landed":
                    #"You exit through the Airlock..."
                    play sound "audio/door_scifi.wav"
                    $ surfaceLoc = GAME.getSandboxLoc(GAME.ship.surfaceID)
                    return(["transition", surfaceLoc])

                else:
                    play sound "audio/tech_fail.wav"
                    "Ship Controls" "\"Danger. Access Denied.\""
                    mc "\"We are in space...\""
                    mc "\"I better leave that Airlock alone...\""

            # turbolift connection
            elif cell.kind == "turbolift":
                call turbolift_nav() from _call_turbolift_nav_1 


            # is cell an exit cell to new loc & minimap?
            elif cell.kind == "exit":       
                $ target = cell.linksTo()
                if target[0] == "MMIDShip":
                    call boarding() from _call_boarding_5 
                else:
                    $ GAME.miniMapActive = GAME.miniMaps[target[0]]
                    call sandbox_interior_navigate_to(target[1]) from _call_sandbox_interior_navigate_to_88 
            
            # normal navigation
            else:
                play sound "audio/click.wav"
                $ loc = GAME.locs[_return[1].locID]
                call sandbox_interior_navigate_to(loc.ID) from _call_sandbox_interior_navigate_to_89 

        #####################################################################
        #              PET Related xxxx
        #####################################################################
        elif "pet" in _return:
            call interact_pet(_return[1]) from _call_interact_pet 

        #####################################################################
        #					INVENTORY RELATED 									  
        #####################################################################
 
        elif "inventory" in _return:
            play sound "audio/equip.wav"
            call item_show(GAME.mc.inventory) from _call_item_show_2 
            if _return:
                if _return in GAME.mc.invHistory:
                    $ GAME.mc.invHistory.remove(_return)
                $ GAME.mc.invHistory.append(_return)
                if len(GAME.mc.invHistory) > 5:
                    $ GAME.mc.invHistory = GAME.mc.invHistory[-5:]
                $ mode = "normal"

            play sound "audio/equip.wav"

        elif "left" in _return:
            # cycle use history
            if GAME.mc.invHistory:
                $ GAME.mc.invHistory = GAME.mc.invHistory[1:] + GAME.mc.invHistory[:1]
            $ useItem = False
            $ mode = "normal"
            play sound "audio/click.wav"
            pass

        elif "right" in _return:
            # cycle use history
            if GAME.mc.invHistory:
                $ GAME.mc.invHistory = GAME.mc.invHistory[-1:] + GAME.mc.invHistory[:-1]
            $ useItem = False
            $ mode = "normal"
            play sound "audio/click.wav"
            pass

        elif "use" in _return:
            # use item
            $ useItem = _return[1]
            if mode == "use":
                $ mode = "normal"
                $ useItem = False
            elif mode == "normal":
                $ mode = "use"
                $ useItem = _return[1]
            play sound "audio/click.wav"
            
        elif "managetorploadout" in _return:
            $ subSysKey = _return[1]
            $ slot = _return[2]
            $ equipped = _return[3]
            # addon selection
            if equipped:
                $ result = GAME.ship.unEquipAddOn(subSysKey, slot)
                if result:
                    play sound "audio/install.wav"
                    if reloadingbanter == False:
                        if khelara.isAt() == "LOCEngine":
                            mc "You direct Khelara to unload the specified torpedo from one of the tubes."
                            khe "As you wish!"
                        else:
                            mc "You direct BB2 to unload the specified torpedo from one of the tubes."
                            bb2 "By your command!"
                else:
                    play sound "audio/tech_fail.wav"
            else:
                show image "room_engine_smart"
                call item_show(GAME.ship.cargo, ["module"], "CARGO - ADDON MODULES") from _call_item_show_555 
                hide image "room_engine_smart"                 
                $ item = _return 

                if _return:
                    # paranoid duplicate pointer cleanup (from bad patch)
                    $ itemScrubbed = item.scrub() # WIP 1.60 Cleanup
                    if itemScrubbed in GAME.ship.supportedAddOns(subSysKey): # WIP 1.60 Cleanup
                        $ GAME.ship.equipAddOn(subSysKey, item.ID, slot)
                        $ GAME.ship.cargo.remove(item)
                        play sound "audio/install.wav"
                        if reloadingbanter == False:
                            if khelara.isAt() == "LOCEngine":
                                mc "You direct Khelara to load the specified torpedo into one of the tubes."
                                khe "Sure thing cap!"
                            else:
                                mc "You direct BB2 to load the specified torpedo into one of the tubes."
                                bb2 "Roger Roger!"
                            $ reloadingbanter = True
                    else:
                        play sound "audio/tech_fail.wav"

        #####################################################################
        #					USE HANDLING & SUBSCREEN HANDLING
        #####################################################################
        elif "action" in _return:
            if useItem:
                call use_item(_return[1], useItem) from _call_use_item 
                $ useItem = False
                $ mode = "normal"
            else:
                call interact_room(_return[1]) from _call_interact_room 

            if "transition" in _return:
                $ transition = _return # ["transition",locObj] as return   
                return(transition)  

        elif "screen" in _return: # subscreen action
            call interact_room(_return[1], [_return[2]]) from _call_interact_room_1 


    return(transition)

#####################################################################
#              AUXILIARY MODULES INTERIOR NAVIGATE
#####################################################################

label sandbox_interior_navigate_to(locID, p_mode = False):
    hide screen displayPresentActors
    call intercept_exit(locID) from _call_intercept_exit 

    $ loc = GAME.locs[locID]

    # holodeck check for running program and switch loc
    if loc.ID == "LOCHolo" and loc.status == "castle":
        $ loc = GAME.locs["LOCHoloCastle"]
    elif loc.ID == "LOCHolo" and loc.status == "blank":
        $ loc = GAME.locs["LOCHoloBlank"]
    $ locID = loc.ID  

    # continue loc switching
    call intercept_pre(locID) from _call_intercept_pre 
    if not _return:
        # call quest_updater()
        return(False)
  
    $ GAME.setLocID(locID)
    call sandbox_interior_prepare_scene(p_mode) from _call_sandbox_interior_prepare_scene_52 
    call intercept_post(locID) from _call_intercept_post 

    if not _return:
        call sandbox_interior_prepare_scene() from _call_sandbox_interior_prepare_scene_53 

    # check minimap swap out
    if GAME.getMiniMapMatch(locID): # paranoid check
        if GAME.getMiniMapMatch(locID) != GAME.miniMapActive:
            $ GAME.miniMapActive = GAME.getMiniMapMatch(locID)
    
    # call intercept_post(locID)
    # if not _return:
    #     call sandbox_interior_prepare_scene() # rollback location setup 

    # wrap up
    call quest_updater() from _call_quest_updater_208 
    return(True)

label sandbox_interior_prepare_scene(p_mode = False):
    hide screen displayPresentActors
    call version_check() from _call_version_check_1 
    $ loc = GAME.getLoc()
    # entry sound
    if GAME.locHasChanged() or "ambient"in tags:
        stop music
        # play ambient for specific rooms
        if loc.ID == "LOCEngine" and 'reactor activated' in GAME.mc.done:
            play music "audio/{}".format(loc.attr["ambient"]) fadein 2.0
        elif "ambient" in loc.attr.keys():
            play music "audio/{}".format(loc.attr["ambient"]) fadein 2.0
    # scene
    if GAME.locHasChanged():
        scene expression ("{}".format(GAME.locs[loc.ID].img)) with dissolve
        $ GAME.setLocID(loc.ID)
        if not GAME.locs[loc.ID].found:
            $ GAME.locs[loc.ID].found = True
    elif p_mode == "fade":
        scene expression ("{}".format(GAME.locs[loc.ID].img)) with fade
    else:
        scene expression ("{}".format(GAME.locs[loc.ID].img))
    return()