#####################################################################
#					UNIFORM AND ORDER SYSTEM		
#####################################################################


#####################################################################
#					INITIALIZE		
#####################################################################
label init_orders():
    #####################################################################
    #                CHARACTER OUTFITS
    #####################################################################
    $ uniformData = [ 

        ["UID1_Free", "Free Uniform", "A uniform chosen by the crew member", 
            {}, {}, True, "ITMUniformFree"], 
        ["UID2_Racy", "Racy Uniform", "A racy, but still somewhat practical uniform", 
            {"EXH": 1, "MOD": 20}, {"MOD": -10}, False, "ITMUniformRacy"], 
        ["UID3_Revealing", "Revealing Uniform", "A quite revealing and impractical uniform", 
            {"EXH":4, "MOD": 40}, {"MOD":-20}, False, "ITMUniformRevealing"], 

        ["UID4_Krell", "Krell Uniform", "A 'uniform' required in Krell Space for crew members", 
            {"EXH":7, "SUB": 3, "MOD": 20}, {"MOD": -40}, False, "ITMUniformKrell"], 

        ["UID5_Nude", "Naked Duty", "Clothing protocol for naked duty", 
            {"EXH":10, "MOD": 20}, {"MOD": -50}, False, "ITMUniformNude"]
    ]

    python:
        for i in uniformData:
            GAME.uniformDB[i[0]] = UniformOrder(i[0], i[1], i[2], i[3], i[4], i[5], i[6])

    #####################################################################
    #					JOBS		
    #####################################################################
    $ jobData = [ 
        ["JOB_Idle", "Relaxing", "Relaxing (Reduces Stress)", {}, {"STS": -50, "MOD": +5}, {}],

        #T'Ris
        ["JOB_Diag", "Run Diagnostics", "Analyzing the ship's condition.", {}, {"STS": 5}, {"TEC": [0.8, 15]}],
        ["JOB_Pods", "Resupply Pods", "Resupply ship with pods (max 5) on docking.", {}, {"STS": 5}, {"TEC": [0.7, 15]}],
        ["JOB_Torps", "Resupply Torpedos", "Resupply ship with high end Torpedos (fill up to 20) on docking.", {}, {"STS": 5}, {"TEC": [0.9, 25]}],
        ["JOB_Nav", "Nav Class", "Attend hyperspace navigation class", {}, {"STS": 20}, {"TEC": [1.1, 20]}],
        ["JOB_Pet", "Pet Class", "Attend pet training class for the day", {}, {"STS": 50}, {}],

        # Nimhe
        ["JOB_Parts", "Get Bot Crates", "Acquire Bot Crates on the market.", {}, {"STS": 10}, {"TEC": [0.5, 10]}],
        ["JOB_Assy", "Assemble Bots", "Assembling and training of Bots.", {}, {"STS": 15}, {"TEC": [0.8, 25]}],
        ["JOB_Hunt", "Hunt For Parts", "Hunt for specific Bot parts.", {}, {"STS": 10}, {"TEC": [0.8, 25]}],
        ["JOB_Upgrade", "Upgrade Parts", "Create higher grade parts (3x) from 3 lower.", {}, {"STS": 10}, {"TEC": [0.6, 25]}],
        ["JOB_Shell_Simple", "Craft Simple Shell", "Craft Bot shells - Type J, K, C (uses 3 Standard Bot crates)", {}, {"STS": 10},{"TEC": [0.8, 25]} ],
        ["JOB_Shell_Exotic", "Craft Exotic Shell", "Craft Bot shells - Type V, N (uses 3 Rare Bot crates)", {}, {"STS": 10}, {"TEC": [0.9, 30]} ],
        ["JOB_Shell_Luxury", "Craft Luxury Shell", "Craft Bot shells - Type L, P (uses 3 Military Bot crates)", {}, {"STS": 10}, {"TEC": [0.9, 35]}],
        ["JOB_Shell_Rarified", "Craft Rarified Shell", "Craft Bot shells - Type I, G (uses 3 Precursor Bot crates)", {}, {"STS": 10}, {"TEC": [0.9, 40]}],

        # Khelara
        ["JOB_Loadout", "Torpedo Loadout", "Ensure Torpedoes are equipped before battle and reload in battle (1 per 9 AP).", {}, {"STS": 10}, {"TEC": [0.7, 20]}],
        ["JOB_Repair", "Ship Repairs", "Automatically address ship repairs", {}, {"STS": 5}, {"TEC": [0.5, 15]}],
        ["JOB_Replate", "Ship Replating", "Automatically replate when docked overnight and set to repair", {}, {"STS": 5}, {"TEC": [0.8, 25]}],

        # Vee
        ["JOB_Astro", "Space Survey", "Analyse current system for Oddities or Underverse Rifts (TEC 40+) worth to explore", {}, {"ENE": 10}, {"TEC": [0.8, 40]}],

       # Seraphine
        ["JOB_Shop", "Shopping", "Browse SectorNet for surprise deals...", {}, {"STS": 10}, {}],

       # Moira
        ["JOB_Wellness", "Crew Wellness", "Administer Crew Wellness and Medicare Program...", {}, {"STS": 10}, {}],
        ["JOB_Pet2", "Advanced Pet Class", "Attend advanced pet training class for the day", {}, {"STS": 50}, {}],

        # BB2
        ["JOB_Uncrate", "Uncrate Cargo", "Uncrate Bot Crates and Liquor Crates...", {}, {"ENE": 10}, {}],
    ]

    python:
        for i in jobData:
            GAME.jobDB[i[0]] = Job(i[0], i[1], i[2], i[3], i[4], i[5])
    return()

#####################################################################
#					CREW ASSESSMENT		
#####################################################################
label crew_assessment():
    $ GAME.reports = []

    python:
        uniform_crew = set(GAME.crew) - set([bb_2, vee])
        if GAME.questSys.isActive("QID_VEE_FAMILIARIZE"):
            uniform_crew.add(vee)
        # crew stress bonus 
        if "INV_ENTERTAINMENT" in GAME.investments:
            for actor in uniform_crew:
                actor.attr["STS"] = capValue(actor.attr["STS"]-5, 0,100)

        # crew mood assessment
        for actor in uniform_crew:
            
            if actor.uniform == "UID2_Racy":
                actor.tallyUp("Racy Uniform", 1)
                actor.incAttrFrac("EXH", 0.5, 3)

            elif actor.uniform == "UID3_Revealing":
                actor.tallyUp("Revealing Uniform", 1)
                actor.incAttrFrac("EXH", 0.5, 6)

            elif actor.uniform == "UID4_Krell":
                actor.tallyUp("Krell Uniform", 1)

            if actor.isPlugged():
                actor.tallyUp("Plugged", 1)


            # transfer infractions
            if [x for x in actor.status if "INF_" in x]:
                actor.hasDoneToday(x)
                actor.status.remove(x)

            # check, whether mood is high enough for uniform, revert if not
            if not actor.uniformOK(actor.uniform): # current order NOK:
                GAME.reports.append(["UNIFORM REFUSAL!", "{} is in a bad mood and no longer wants to wear her assigned uniform.\n\nImprove her mood with presents or let her relax for a day or two.".format(C_HI_B+actor.name+C_HI_E), ["Continue"], "08_items/ico ITMUniformRacy.png", "blue"])
                actor.uniform = "UID1_Free"
                actor.getDressed("override")
            
            # check, whether stress is too high for work 
            if actor.attr["STS"] > 80:
                GAME.reports.append(["TASK REFUSAL!", "{} is too stressed out to perform her duties today. \n\nI suggest you let her relax for a day or two.".format(C_HI_B+actor.name+C_HI_E), ["Continue"], "08_items/ico ITMSpanner.png", "blue"])
                actor.setJob("JOB_Idle")

    while GAME.reports:
        $ report = GAME.reports.pop(0)
        queue sound "audio/notify.wav"
        call large_notify(report[0], report[1], report[2], report[3], report[4]) from _call_large_notify_39 
    return()

#####################################################################
#					DAILY ORDERS		
#####################################################################
screen popup_job_scr(*args):
    $ actor = args[0] 
    $ jobIDs = actor.jobs
    $ jobIDsSorted = sorted(jobIDs, key=lambda x: (GAME.jobDB[x].name))
    modal True
    frame xalign 0.5 yalign 0.5 padding 40,40:
        has vbox xsize 460 xalign 0.5 yalign 0.5 spacing 10:
            text "Job Assignment {}".format(actor.name) xalign 0.5 size FSIZE
            bar xsize 340 ysize 3 xalign 0.5 
            for i in jobIDsSorted:
            
                if i == "JOB_Shell_Simple":
                    if any(True for e in ("SHELL_K", "SHELL_C", "SHELL_J") if e in nimhe.done):
                        if not GAME.ship.hasCargo(["ITMCrateBots"]*3):
                            text "Craft Simple Shell{size=18}\n     *requires 3 Bot Crates{/size}" style "text_std" xalign 0.5 tooltip i color "#f00"
                        else:
                            textbutton "{}".format(GAME.jobDB[i].name) action Return(["job", actor, i]) text_style "text_std" xalign 0.5 tooltip i
                    else:
                        pass
                        
                elif i == "JOB_Shell_Exotic":
                    if any(True for e in ("SHELL_V", "SHELL_N") if e in nimhe.done):
                        if not GAME.ship.hasCargo(["ITMCrateBotsRare"]*3):
                            text "Craft Exotic Shell{size=18}\n     *requires 3 Rare Bot Crates{/size}" style "text_std" xalign 0.5 tooltip i color "#f00"
                        else:
                            textbutton "{}".format(GAME.jobDB[i].name) action Return(["job", actor, i]) text_style "text_std" xalign 0.5 tooltip i
                    else:
                        pass
                        
                elif i == "JOB_Shell_Luxury":
                    if any(True for e in ("SHELL_L", "SHELL_P") if e in nimhe.done):
                        if not GAME.ship.hasCargo(["ITMCrateBotsMil"]*3):
                            text "Craft Luxury Shell{size=18}\n     *requires 3 Military Bot Crates{/size}" style "text_std" xalign 0.5 tooltip i color "#f00"
                        else:
                            textbutton "{}".format(GAME.jobDB[i].name) action Return(["job", actor, i]) text_style "text_std" xalign 0.5 tooltip i
                    else:
                        pass
                            
                elif i == "JOB_Shell_Rarified":# in GAME.jobDB[i].name:
                    if any(True for e in ("SHELL_G", "SHELL_I") if e in nimhe.done):
                        if not GAME.ship.hasCargo(["ITMCrateBotsPre"]*3):
                            text "Craft Rarified Shell{size=18}\n     *requires 3 Precursor Bot Crates{/size}" style "text_std" xalign 0.5 tooltip i color "#f00"
                        else:
                            textbutton "{}".format(GAME.jobDB[i].name) action Return(["job", actor, i]) text_style "text_std" xalign 0.5 tooltip i
                    else:
                        pass
                        
                else:
                    textbutton "{}".format(GAME.jobDB[i].name) action Return(["job", actor, i]) text_style "text_std" xalign 0.5 tooltip i

    $ tooltip = GetTooltip()
    if tooltip and tooltip in GAME.jobDB.keys():
        $ job = GAME.jobDB[tooltip]
        vbox xalign 0.5 pos 960, 850:
            text job.description size FSIZE 
            for k in job.skillUp.keys():
                text "- Increases {} by {} up to {}.".format(k, job.skillUp[k][0],job.skillUp[k][1] ) size FSIZE


screen daily_orders_scr(*args):
    $ crew = args[0] # CR-0326
    $ yadj = args[1]
    $ aImgDict = args[2]

    $ C_X_STS = 140
    $ C_X_MOD = 340 
    $ C_X_GIFT = 550
    $ C_X_JOB = 730
    $ C_X_UNI = 990
    $ C_X_DIS = 1210

    text C_HI_B+"DAILY ORDERS"+C_HI_E size FSIZE_LARGE pos 960, 80 xalign 0.5

    side "c r":
        area 400,180,1800,620
        viewport id "vp":
            draggable True
            mousewheel True 
            yadjustment yadj

            # ----- viewport content
            # Crew members list
            vbox spacing 10 xalign 0.5 ypos 200:
                for actor in crew:
                    frame xsize 1475 ysize 96 xalign 0.5 background Solid ("#0099cc88"):
                        button action NullAction() tooltip actor
                        image "01_portrait/ico_char_{}.png".format(actor.ID.lower()) xpos 20 zoom 0.3 yalign 0.5
                        if actor.getLocOverride():
                            image "05_gui/away_hover.png" pos 30,-5
                        # text actor.name yalign 0.5 
                        $ sts = percentColorized(actor.attr["STS"],[0,100], True)
                        if actor == vee:
                            $ ene = percentColorized(actor.attr["ENE"], [0,100])
                            text "Stress: {}{:4d}%{}".format(sts[1],sts[3], sts[2], mod[1]) yalign 0.5 xpos C_X_STS 
                            text "Energy: {}{:5d}%{}".format(ene[1], ene[3], ene[2]) yalign 0.5 xpos C_X_MOD               
                        else:
                            $ mod = percentColorized(actor.attr["MOD"], [0,100])   
                            text "Stress: {}{:4d}%{}".format(sts[1],sts[3], sts[2], mod[1]) yalign 0.5 xpos C_X_STS  
                            text "Mood: {}{:5d}%{}".format(mod[1], mod[3], mod[2]) yalign 0.5 xpos C_X_MOD 
                        
                        
                        # actor specific mood improvement 
                        $ gift = {"ACTNIMHE": "ITMLiquorFairy", "ACTTRIS": "ITMCandle", "ACTKHELARA": "ITMLiquorDrengar", "ACTVEE": "ITMPodEnergy", "ACTSERA": "ITMLiquorVortex", "ACTMOIRA": "ITMLiquorIltari"}[actor.ID]
                        $ item = GAME.items[gift]
                        frame xsize 96 ysize 96 background Solid ("#ffffff00") xpos C_X_GIFT yalign 0.5:
                            image "08_items/ico {}.png".format(item.ID) xalign 0.5 yalign 0.5 zoom 0.25 
                            if gift == "ITMPodEnergy":
                                if GAME.ship.hasCargo([item.ID]):
                                    button action Return(["present", actor, item]) tooltip item
                                else:
                                    button action NullAction() tooltip item
                                text "{}x".format(GAME.ship.cargo.count(item))  yalign 0.5 xpos 140 xalign 1.0 
                            else:
                                if GAME.mc.hasItem(item.ID):
                                    button action Return(["present", actor, item]) tooltip item
                                else:
                                    button action NullAction() tooltip item

                                text "{}x".format(GAME.mc.inventory.count(item))  yalign 0.5 xpos 140 xalign 1.0
                    

                        # Job selection
                        frame xsize 240 ysize 48  yalign 0.5 xpos C_X_JOB background Solid("#0099ccff"):
                            text "{}".format(actor.getJob().name) yalign 0.6 xalign 0.5 size FSIZE
                            button action ShowTransient("popup_job_scr", None, actor)
                                    


                        frame xsize 200 ysize 48  yalign 0.5 xpos C_X_UNI background Solid("#0099ccff"):
                            text "{}".format(GAME.uniformDB[actor.uniform].name) yalign 0.6 xalign 0.5 size FSIZE
                            button action Return(["uniform", actor])
                        if [x for x in GAME.infractions if x[0] == actor]:
                            frame xsize 200 ysize 48  yalign 0.5 xpos C_X_DIS background Solid("#0099ccff"):
                                text "Discipline".format() yalign 0.6 xalign 0.5 size FSIZE
                                button action Return(["discipline", actor])
                text " "
            # ----- viewport content end
        vbar value YScrollValue("vp")

    $ tooltip = GetTooltip()
    if tooltip and isinstance(tooltip, Actor):
        frame xsize 300 ysize 400 pos 40,180 background Solid("#0099cc88"):
            image aImgDict[tooltip.ID] zoom 0.5 ypos -154 xpos 20 
            if tooltip.accessory:
                #image "08_items/ico bg1.png" zoom 0.22 pos 190,20
                image "08_items/ico {}.png".format(tooltip.accessory[0].ID) zoom 0.20 pos 190,20
            frame xsize 288 ysize 50 ypos 338 background Solid("#0099ccff"):
                text tooltip.name xalign 0.5 size FSIZE yalign 0.5

        vbox spacing 10 pos 40, 600:
            text "Outfit Training" size FSIZE xpos 20
            for i in ["Racy Uniform", "Revealing Uniform", "Krell Uniform", "Plugged"]:
                frame xsize 300 ysize 30 background Solid("#00000000"):
                    text i size FSIZE xpos 20
                    $ val = "-"
                    if tooltip.getTally(i):
                        $ val = "{}".format(tooltip.getTally(i))

                    text val xpos 270 xalign 1.0 size FSIZE
    elif tooltip and isinstance(tooltip, Item):
        text "{} - Improves {}".format(tooltip.getName(["col", "noArt", "cap"]), {True: "Mood", False: "Energy"}[tooltip.ID != "ITMPodEnergy"]) size FSIZE xalign 0.5 yalign 0.90



    # Exit button 
    frame xsize 350 ysize 64 pos 0,900 background Solid("#00000000") padding 0,0:
        image "05_gui/gui_menu_option.png" yalign 0.5
        textbutton "Start Day (D)" yalign 0.5 action Return(False) xpos 20
        key "d" action Return(False)
        key "K_SPACE" action Return(False)
        button action Return(False) xpos 20    

label daily_orders():
    show image "05_gui/mask 50.png"
    $ yadj = ui.adjustment()
    $ crew = [tris]
    if nimhe in GAME.crew:
        $ crew.append(nimhe)
    if khelara in GAME.crew:
        $ crew.append(khelara)     
    if moira in GAME.crew:
        $ crew.append(moira)
    if GAME.questSys.isActive("QID_VEE_FAMILIARIZE"):
        $ crew.append(vee)
    if seraphine in GAME.crew:
        $ crew.append(seraphine)

    $ aImgDict = {"ACTTRIS":"side_tris_smart", "ACTMC":"side_mc_smart", "ACTNIMHE":"side_nimhe_smart", "ACTKHELARA": "side_khelara_smart", "ACTVEE":"side_vee_smart", "ACTSERA": "side_seraphine_smart", "ACTMOIRA": "side_moira_smart"}

    $ uniformLoop = True

    while uniformLoop:
        call screen daily_orders_scr(crew, yadj, aImgDict)
        if _return == False:
            $ canExit = True
            queue sound "audio/click.wav"
            hide image "05_gui/mask 50.png" 

            #####################################################################
            #              EXIT CHECKS
            #####################################################################
            if khelara.uniform == "UID2_Racy":
                call transaction("Uniform Duty Surcharges", -2500, True) from _call_transaction_27 
            elif khelara.uniform == "UID3_Revealing":
                call transaction("Uniform Duty Surcharges", -5000, True) from _call_transaction_28 
            elif khelara.uniform == "UID4_Krell":
                call transaction("Uniform Duty Surcharges", -10000, True) from _call_transaction_29 

            #####################################################################
            #              AWAY MISSIONS T'RIS
            #####################################################################
            
            if tris.getJob().ID == "JOB_Nav" and (GAME.ship.status != "docked" or GAME.getSpaceLoc().ID != "LIDStationIltari") and not tris.getLocOverride():
                queue sound "audio/notify.wav"
                "You must be docked in Iltari station to send T'Ris to Nav Class."
                $ canExit = False
            elif tris.getJob().ID == "JOB_Pet" and not (GAME.ship.status == "docked" and GAME.getSpaceLoc().ID == "LIDStationArellarti") and not tris.getLocOverride():
                queue sound "audio/notify.wav"
                "You must be docked in Arellarti Station to send T'Ris to Pet Class."
                $ canExit = False
            elif tris.getJob().ID == "JOB_Pet" and  not any([tris.hasItem(x) for x in ["ITMVoucherPet1", "ITMVoucherPet2", "ITMVoucherPet3"]]):
                queue sound "audio/notify.wav"
                "T'Ris must have a valid training voucher to attend Pet Class."
                $ canExit = False

            elif tris.getJob().ID == "JOB_Nav" and not tris.getLocOverride():
                $ tris.setLocOverride("LOCNavClass")
                queue sound "audio/notify.wav"
                call large_notify("OFF BOARD ASSIGNMENT", "T'Ris leaves for her away mission. She will rejoin you from 18:00 if you are docked at Iltari Station.", ["Continue"], "05_gui/ico Ship.png") from _call_large_notify_40 
                $ tris.hasDoneToday("away_mission")

            elif tris.getJob().ID == "JOB_Pet" and not tris.getLocOverride():
                $ tris.setLocOverride("LOCPetClass")
                queue sound "audio/notify.wav"
                call large_notify("OFF BOARD ASSIGNMENT", "T'Ris leaves for a day of Pet Class.\n\nShe will rejoin you from 18:00 if you are docked at Arellarti Station.", ["Continue"], "05_gui/ico Ship.png") from _call_large_notify_41 
                $ tris.hasDoneToday("away_mission")

            #####################################################################
            #              AWAY MISSIONS MOIRA
            #####################################################################
            if moira.getJob().ID == "JOB_Pet2" and not (GAME.ship.status == "docked" and GAME.getSpaceLoc().ID == "LIDStationArellarti") and not moira.getLocOverride():
                queue sound "audio/notify.wav"
                "You must be docked in Arellarti Station to send Moira to Pet Class."
                $ canExit = False

            elif moira.getJob().ID == "JOB_Pet2" and GAME.questSys.isActive("QID_MOIRA_SUB_PET_HOMEWORK") and not GAME.questSys.isDone("QID_MOIRA_SUB_PET_TRYOUT"):
                queue sound "audio/notify.wav"
                "Moira must gain Milking Machine experience first... (SUB 4)"
                $ canExit = False

            elif moira.getJob().ID == "JOB_Pet2" and  not any([moira.hasItem(x) for x in ["ITMVoucherPet1", "ITMVoucherPet2", "ITMVoucherPet3"]]):
                queue sound "audio/notify.wav"
                "Moira must have a valid training voucher to attend Pet Class."
                $ canExit = False

            elif moira.getJob().ID == "JOB_Pet2" and not moira.getLocOverride():
                $ moira.setLocOverride("LOCPetClass")
                queue sound "audio/notify.wav"
                call large_notify("OFF BOARD ASSIGNMENT", "Moira leaves for a day of Advanced Pet Class.\n\nShe will rejoin you from 18:00 if you are docked at Arellarti Station.", ["Continue"], "05_gui/ico Ship.png") from _call_large_notify_42 
                $ moira.hasDoneToday("away_mission")
                
            #OhWee mod code    
            if nimhe.getJob().ID == "JOB_Shell_Simple": 
                $ shell_list_types = []
                $ Shell_Crafting_Selection = ""
                queue sound "audio/notify.wav"
                $ shell_type_text = "Nimhe may craft the following shell types:{size=20}\n\n"                  
                if "SHELL_J" in nimhe.done:
                    $ shell_list_types.append("TypeJ")
                    $ shell_type_text += "Type J - Personalized\n" 
                if "SHELL_C" in nimhe.done:
                    $ shell_list_types.append("TypeC")
                    $ shell_type_text += "Type C - Krell Concubine\n" 
                if "SHELL_K" in nimhe.done:
                    $ shell_list_types.append("TypeK")
                    $ shell_type_text += "Type K - Krell Palace Mistress\n"
                $ shell_type_text += "\n\n{/size}Which shell type should Nimhe craft next?"
                        
                if len(shell_list_types) > 1:
                    call larger_notify("SELECT SHELL TYPE", "[shell_type_text]", shell_list_types, "side_nimhe_smart") from _call_large_notify_2s
                    $ Shell_Crafting_Selection = _return
                else:
                    $ Shell_Crafting_Selection = "TypeJ"\
                
            elif nimhe.getJob().ID == "JOB_Shell_Exotic": 
                $ shell_list_types = []
                $ Shell_Crafting_Selection = ""
                queue sound "audio/notify.wav"
                $ shell_type_text = "Nimhe may craft the following shell types:{size=20}\n\n"
                if "SHELL_N" in nimhe.done:
                    $ shell_list_types.append("TypeN")
                    $ shell_type_text += "Type N - Ni'Larian Temptress\n" 
                if "SHELL_V" in nimhe.done:
                    $ shell_list_types.append("TypeV")
                    $ shell_type_text += "Type V - Voronian\n"
                $ shell_type_text += "\n\n{/size}Which shell type should Nimhe craft next?"
                        
                if len(shell_list_types) > 1:
                    call larger_notify("SELECT SHELL TYPE", "[shell_type_text]", shell_list_types, "side_nimhe_smart") from _call_large_notify_2e
                    $ Shell_Crafting_Selection = _return
                else:
                    $ Shell_Crafting_Selection = shell_list_types[0]
                
            elif nimhe.getJob().ID == "JOB_Shell_Luxury": 
                $ shell_list_types = []
                $ Shell_Crafting_Selection = ""
                queue sound "audio/notify.wav"
                $ shell_type_text = "Nimhe may craft the following shell types:{size=20}\n\n"
                if "SHELL_L" in nimhe.done:
                    $ shell_list_types.append("TypeL")
                    $ shell_type_text += "Type L - Supermodel\n" 
                if "SHELL_P" in nimhe.done:
                    $ shell_list_types.append("TypeP")
                    $ shell_type_text += "Type P - Protector\n"
                $ shell_type_text += "\n\n{/size}Which shell type should Nimhe craft next?"
                        
                if len(shell_list_types) > 1:
                    call larger_notify("SELECT SHELL TYPE", "[shell_type_text]", shell_list_types, "side_nimhe_smart") from _call_large_notify_2l
                    $ Shell_Crafting_Selection = _return
                else:
                    $ Shell_Crafting_Selection = shell_list_types[0]
                
            elif nimhe.getJob().ID == "JOB_Shell_Rarified": 
                $ shell_list_types = []
                $ Shell_Crafting_Selection = ""
                queue sound "audio/notify.wav"
                $ shell_type_text = "Nimhe may craft the following shell types:{size=20}\n\n"
                if "SHELL_G" in nimhe.done:
                    $ shell_list_types.append("TypeG")
                    $ shell_type_text += "Type G - Golden Seductress\n" 
                if "SHELL_I" in nimhe.done:
                    $ shell_list_types.append("TypeI")
                    $ shell_type_text += "Type I - Infiltrator\n"
                $ shell_type_text += "\n\n{/size}Which shell type should Nimhe craft next?"
                        
                if len(shell_list_types) > 1:
                    call larger_notify("SELECT SHELL TYPE", "[shell_type_text]", shell_list_types, "side_nimhe_smart") from _call_large_notify_2r
                    $ Shell_Crafting_Selection = _return
                else:
                    $ Shell_Crafting_Selection = shell_list_types[0]
                
            #End OhWee mod code



            if canExit:
                $ uniformLoop = False

        elif _return[1].getLocOverride():
            $ actor = _return[1]
            queue sound "audio/notify.wav"
            "[actor.name] is not available for orders at the moment."

        elif "pick_job" in _return:
            pass

        elif "job" in _return:
            queue sound "audio/click.wav"
            $ actor = _return[1] 
            if actor.attr["STS"] > 80:
                play sound "audio/notify.wav"
                call large_notify("STRESSED OUT", "{} is too stressed out to perform a task today. Let her relax for a day or two.\n\nYou might also reduce her stress level by a suitable present.".format(C_HI_B+actor.name+C_HI_E), ["Continue"], "08_items/ico ITMSpanner.png", "red") from _call_large_notify_43
                    
                    
            else:
                $ actor = _return[1] 
                while _return[2] != actor.getJob().ID:
                    $ actor.nextJob()
          
        elif "uniform" in _return:
            queue sound "audio/click.wav"
            $ actor = _return[1] 
            if False: # actor == vee: # CR-0852
                mc "\"I think V's uniform is just fine...\""
            else:
                call uniform_orders(actor) from _call_uniform_orders 

        elif "present" in _return:
            $ actor = _return[1]
            $ item = _return[2]
            if actor.hasDoneToday("gift") and actor != vee:
                mc "\"I shouldn't overdo it with the gifts.\""
            elif actor != vee:
                queue sound "audio/click_soft.wav"
                $ GAME.mc.passItem(item.ID, actor)
                call attr_mod(actor, "MOD", 50, 100, 100, False) from _call_attr_mod_61 
            elif actor == vee:
                queue sound "audio/click_soft.wav"
                $ vee.inventory.append(item)
                $ GAME.ship.unloadWare(item.ID)
                call attr_mod(actor, "ENE", 50, 100, 100, False) from _call_attr_mod_62 
                $ vee.tallyUp("Energy Consumed",1)
 
            queue sound "audio/click.wav"


        elif "discipline" in _return:
            # CR-2102 START
            $ actor = _return[1]
            $ issue = [x for x in GAME.infractions if x[0] == actor][0]
            queue sound "audio/notify.wav"
            mc "\"We have a Discipline Issue this morning!\""
            mc "\"[actor.name], you committed an infraction.\""
            mc "\"Specifically, you [issue[1]].\""
            # CR-2102 END
            $ renpy.say(GAME.adv[actor.ID], vary("Hrmmpfff..."))
            mc "\"Proceed to the Mess Room for Administrative Disciplining.\""
            scene intermission with fade
            "A short while later in the Mess Room..."
            hide screen header
            call mg_spanking("DISCIPLINING - ", actor) from _call_mg_spanking 
            # CR-2130 START
            $ actor.getDressed()
            # CR-2130 END
            show screen header()
            scene room_captain_smart with fade
            $ GAME.infractions = []
            
        else:
            queue sound "audio/click.wav"


    #####################################################################
    #					PROCESS DAILY ORDER EFFECTS		
    #####################################################################
    # uniform progression counters 
    python:
        for actor in [tris]:
            if actor.uniform == "UID1_Free":
                # determine progressive variation 
                uniform = actor.getProgOutfit()

                # moved to night passes housekeeping
                # # increase counter 
                # actor.counters[uniform.ID] = actor.counters.get(uniform.ID, 0) + 1

    return()

#####################################################################
#					UNIFORM ORDERS		
#####################################################################

screen uniform_orders_scr(uniforms, actor=False):
    # headline and headers
    text C_HI_B+"{} - DRESS CODE".format(actor.name.upper())+C_HI_E size FSIZE_LARGE xalign 0.5 ypos 100

    #####################################################################
    #              OUTFIT
    #####################################################################
    frame xalign 0.5 yalign 0.35 xsize 1920 ysize 180 background Solid ("#0099ccaa"):
        text "UNIFORMS" xpos 20 ypos 120 color "#000000ff" size FSIZE_LARGE
        hbox xalign 0.5 yalign 0.5 spacing 20:
            for uniform in uniforms:
                if actor.hasItem(uniform.itemID) or uniform.itemID == "ITMUniformFree":
                    frame xsize 200 ysize 400:
                        if uniform.itemID == "ITMUniformFree": # Free
                            image "05_gui/gui_mannikin_{}.png".format(uniform.ID) xalign 0.5 yalign 0.5 zoom 0.65
                            button action Return(uniform) tooltip uniform
                        elif actor.hasItem(uniform.itemID): # Owns
                            image "05_gui/gui_mannikin_{}.png".format(uniform.ID) xalign 0.5 yalign 0.5 zoom 0.65
                            button action Return(uniform) tooltip uniform
                        else:
                            image "05_gui/ico_gui_padlock.png" xalign 0.5 yalign 0.5 zoom 0.25 
                        if actor.uniform == uniform.ID:
                            # image "05_gui/check.png" xpos 100 ypos -10
                            frame xsize 200 ysize 40 background Solid("#0099ccff") ypos 360 xalign 0.5:
                                text "ORDERS" xalign 0.5 yalign 0.5
                                
                            # button action NullAction() tooltip uniform
                        #hbox ypos 420 xsize 180:
                            #text "{}".format(uniform.name) size FSIZE xalign 0.5
    #####################################################################
    #              ACCESSORIES
    #####################################################################
    frame xalign 0.5 yalign 0.75 xsize 1920 ysize  90 background Solid ("#0099ccaa"):
        text "ACCESSORIES" xpos 20 ypos 32 color "#000000ff" size FSIZE_LARGE
        hbox xalign 0.5 yalign 0.5 spacing 20:
            for item in [x for x in actor.wardrobe if x.slot in ["plug"]]:
                frame xsize 160 ysize 160:
                    image "08_items/ico bg1.png" zoom 0.25 xalign 0.5 yalign 0.5
                    image "08_items/ico {}.png".format(item.ID) zoom 0.25 xalign 0.5 yalign 0.5
                    button action Return(item) tooltip item
                    if item in actor.accessory:
                        frame xsize 160 ysize 40 background Solid("#0099ccff") ypos 120 xalign 0.5:
                            text "ORDERS" xalign 0.5



    $ tooltip = GetTooltip() # xxx
    if tooltip and isinstance(tooltip, UniformOrder): 
        vbox xalign 0.5 ypos 900 xsize 500:
            $ req = "None"
            if tooltip.req:
                $ req = ""
                for k in tooltip.req.keys():
                    $ C_B , C_E = C_GR_B, C_GR_E
                    if not actor.meetsReq(k, tooltip.req):
                        $ C_B , C_E = C_RE_B, C_RE_E
                    $ req += C_B+"{} {}  ".format(k, tooltip.req[k])+C_E

            text C_HI_B+"{}".format(tooltip.name).title()+C_HI_E
            text tooltip.description
            text "Requirements: " + req  

    if tooltip and isinstance(tooltip, Item ):
        vbox xalign 0.5 ypos 900 xsize 500:
            text "{}".format(tooltip.getName(["col", "noArt", "cap"]))
            text "{}".format(tooltip.description)

    #####################################################################
    #                EXIT BUTTON, KEYS, ...
    #####################################################################
    frame xsize 350 ysize 64 pos 0,980 background Solid("#00000000") padding 0,0:
        image "05_gui/gui_menu_option.png" yalign 0.5
        button action Return(False)
        textbutton "Exit (X)" yalign 0.5 action Return(False) xpos 20 # CR-0587
        key "x" action Return(False)
        key "X" action Return(False)
  
label uniform_orders(actor):
    $ uniforms = GAME.uniformDB.values()
    $ uniforms.sort(key = lambda x : x.ID)

    while True:
        call screen uniform_orders_scr(uniforms, actor)
        queue sound "audio/click.wav"
        $ refusal = []
        # intercepts 

        if _return == False:
            return()

        elif _return.ID in ["ITMPlugSwarm", "ITMPlugKrell", "ITMPlugAmplifier"]:
            $ item = _return
            queue sound "audio/squish.wav"
            # CR-2002 START
            if actor.isPlugged():
                python:
                    for i in actor.accessory: 
                        if i.slot == "plug":
                            actor.accessory.remove(i)
            else:
                $ actor.accessory.append(item)
            # CR-2002 END

        # CR-2120 START
        elif _return.ID == "UID4_Krell" and GAME.getStarSys().race == "Krell":
            if actor.hasItem("ITMUniformKrell"):
                $ uniformOrder = _return.ID
                $ uniform = GAME.uniformDB[uniformOrder]
                $ actor.uniform = uniform.ID
                $ actor.getDressed()
        # CR-2120 END

        elif _return.ID != "UID4_Krell" and GAME.getStarSys().race == "Krell":
            queue sound "audio/notify.wav"
            mc "{i}\"I better keep my crew in Krell mandated attire...\"{/i}"
            mc "{i}\"Would hate to get my endorsement for Krell Space withdrawn...\"{/i}"
            if actor == moira and not moira.hasItem("ITMUniformKrell"):
                mc "{i}\"Moira of course being the exception...\"{/i}"
                mc "{i}\"I wish she didn't have that Krell Exemption 41/B...\"{/i}"
            #return()

        elif actor.uniformOK(_return.ID):
            if _return.ID:
                $ uniformOrder = _return.ID
                $ uniform = GAME.uniformDB[uniformOrder]
                $ actor.uniform = uniform.ID
                if actor.uniform != "ITMUniformFree":
                    $ GAME.mc.hasDone("uniform_muster") # first uniform assign quest done
                $ actor.getDressed()        
            #return(_return.ID)

        elif not actor.uniformOK(_return.ID, ["EXH"]):
            $ actor.getDressed()
            queue sound "audio/notify.wav"
            $ refusal.append("I prefer to choose my own uniform today.")
            $ refusal.append("This one is inappropriate.")

        elif not actor.uniformOK(_return.ID, ["SUB"]):
            $ actor.getDressed()
            queue sound "audio/notify.wav"
            $ refusal.append("I won't wear that uniform.")
            $ refusal.append("It is demeaning.")

        elif not actor.uniformOK(_return.ID, ["MOD"]):
            $ actor.getDressed()
            queue sound "audio/notify.wav"
            $ refusal.append("I prefer to choose my own uniform today.")
        else:
            $ actor.getDressed()
            queue sound "audio/notify.wav"
            $ refusal.append("I won't wear that uniform.")

        # Response
        if _return.ID == "UID4_Krell" and GAME.getStarSys().race != "Krell" and actor.uniformOK(_return.ID):
            $ refusal = ["Please note that we are not in Krell Space."]            

        elif _return.ID == "UID4_Krell" and GAME.getStarSys().race != "Krell":
            $ refusal = ["We are not in Krell Space."]+refusal

        while refusal:
            $ msg = refusal.pop(0)
            GAME.adv[actor.ID] "\"[msg]\""

            
    return()


