function reticulatingsplines()
    RandomOne = msnMgr:random() % msnMgr:getDiffScale(3,3,3)
    if (RandomOne == 0) then
        prefix = "temperate belt";
        fuelgathered = fuelgathered + 2;
    elseif (RandomOne == 1) then
        prefix = "temperate zone";
        fuelgathered = fuelgathered + 4;
    elseif (RandomOne == 2) then
        prefix = "equatorial belt";
        fuelgathered = fuelgathered + 6;
    elseif (RandomOne == 3) then
        prefix = "equatorial zone";
        fuelgathered = fuelgathered + 8;
    end

    RandomTwo = msnMgr:random() % msnMgr:getDiffScale(3,3,3)
    if (RandomTwo == 0) then
        suffix = " troposphere";
        fuelgathered = fuelgathered + 1;
    elseif (RandomTwo == 1) then
        suffix = " stratosphere";
        fuelgathered = fuelgathered + 3;
    elseif (RandomTwo == 2) then
        suffix = " thermosphere";
        fuelgathered = fuelgathered + 5;
    elseif (RandomTwo == 3) then
        suffix = " exosphere";
        fuelgathered = fuelgathered + 7;
    end

    RandomThree = msnMgr:random() % msnMgr:getDiffScale(3,3,3)
    if (RandomThree == 0) then
        prefix2 = "north polar region";
        fuelgathered2 = fuelgathered2 + 2;
    elseif (RandomThree == 1) then
        prefix2 = "south polar region";
        fuelgathered2 = fuelgathered2 + 4;
    elseif (RandomThree == 2) then
        prefix2 = "north polar region";
        fuelgathered2 = fuelgathered2 + 6;
    elseif (RandomThree == 3) then
        prefix2 = "south polar region";
        fuelgathered2 = fuelgathered2 + 8;
    end

    RandomFour = msnMgr:random() % msnMgr:getDiffScale(3,3,3)
    if (RandomFour == 0) then
        suffix2 = " troposphere";
        fuelgathered2 = fuelgathered2 + 1;
    elseif (RandomFour == 1) then
        suffix2 = " stratosphere";
        fuelgathered2 = fuelgathered2 + 3;
    elseif (RandomFour == 2) then
        suffix2 = " thermosphere";
        fuelgathered2 = fuelgathered2 + 5;
    elseif (RandomFour == 3) then
        suffix2 = " exosphere";
        fuelgathered2 = fuelgathered2 + 7;
    end

    RandomFive = msnMgr:random() % msnMgr:getDiffScale(5,10,15)
    if (RandomFive == 0) then
        prefixsuffix = "unstable vortex";
        fuelgathered3 = fuelgathered3 + msnMgr:random() % msnMgr:getDiffScale(20,15,10);
    elseif (RandomFive == 1) then
        prefixsuffix = "hot spot";
        fuelgathered3 = fuelgathered3 + msnMgr:random() % msnMgr:getDiffScale(25,20,15);
    end
end

function piloting()
    pilotCrew = charMgr:randomCrew()
    pilotName = charMgr:getCharColoredName(pilotCrew)

    pilotTrait = "None"
    for key, trait in pairs(traitList) do
        if (charMgr:getCharTrait(pilotCrew, trait)) then
            pilotTrait = trait
        end
        if (pilotTrait ~= "None") then
            break
        end
    end

    if (msnMgr:random() % msnMgr:getDiffScale(5,10,15) <= charMgr:getCharAttr(pilotCrew, "mental")) then
        if (pilotTrait == "Farmer") then
            msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. They manage to spot a few cloud bands where fuel seems to be more concentrated.")
            msnMgr:addMessage(" ")
        elseif (pilotTrait == "Addicted") then
            msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. They seem to focus on the brightest cloud bands, even if they're not the best sources of fuel.")
            msnMgr:addMessage(" ")
        elseif (pilotTrait == "Lucky") then
            msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. They seem to pilot a bit randomly, but somehow manage to find some excellent gas pockets.")
            msnMgr:addMessage(" ")
        elseif (pilotTrait == "Reckless") then
            msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. Their piloting is quite reckless and it's a good thing that the shuttle doesn't have any crew on board.")
            msnMgr:addMessage(" ")
        elseif (pilotTrait == "Observant") then
            msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. They're quite keenly observant and spot some good areas for harvest that even the sensors missed.")
            msnMgr:addMessage(" ")
        elseif (pilotTrait == "Xenophobic") then
            msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. There's clearly no possibility of alien life here, but they fly somewhat hesitantly as if they expect to be shot down by a flying saucer.")
            msnMgr:addMessage(" ")
        elseif (pilotTrait == "Scientist") then
            msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. They approach the task methodically and carefully, as you expected.")
            msnMgr:addMessage(" ")
        elseif (pilotTrait == "Competitive") then
            msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. They seem to be more interested in showing off than actually doing a good job, though.")
            msnMgr:addMessage(" ")
        elseif (pilotTrait == "Teamworker") then
            msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. They get in trouble a few times but immediately ask for your help.")
            msnMgr:addMessage(" ")
        elseif (pilotTrait == "Distracted") then
            msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. They don't seem very focused on the task, however, and the job is somewhat sloppy.")
            msnMgr:addMessage(" ")
        elseif (pilotTrait == "Confident") then
            msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. They fly steadily and confidently, as if they'd done it a thousand times before.")
            msnMgr:addMessage(" ")
        elseif (pilotTrait == "Violent") then
            msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. They fly as if it was some sort of combat ship, banking wildly and no doubt missing some opportunities for harvesting fuel.")
            msnMgr:addMessage(" ")
        elseif (pilotTrait == "Soldier") then
            msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. They've clearly got some flying under their belt as part of their military career, and are quite good at it.")
            msnMgr:addMessage(" ")
        elseif (pilotTrait == "Surgeon") then
            msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. They do so with a deft hand and precise movements that are almost imperceptible.")
            msnMgr:addMessage(" ")
        elseif (pilotTrait == "Cautious") then
            msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. They steer clear of some harsh weather patterns and end up harvesting slightly more fuel.")
            msnMgr:addMessage(" ")
        elseif (pilotTrait == "Mechanic") then
            msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. They've tinkered with the shuttle before, and seem almost as if they were one with the craft.")
            msnMgr:addMessage(" ")
        else
            SmartName = getColoredNameForCrewWithMost("mental")
            msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. They perform capably.")
            msnMgr:addMessage(" ")
        end
    else
        SmartName = getColoredNameForCrewWithMost("mental")
        msnMgr:addMessage("Back on the ship, " .. pilotName .. " volunteers to remote pilot the shuttle. They perform capably.")
        msnMgr:addMessage(" ")
    end

    positiveTrait = false
    for key, trait in pairs(traitListPositive) do
        if (pilotTrait == trait) then
            positiveTrait = true
            break
        end
    end

    if (positiveTrait) then
        fuelgathered = fuelgathered + 5;
        fuelgathered2 = fuelgathered2 + 5;
        fuelgathered3 = fuelgathered3 + 5;
    else
        fuelgathered = fuelgathered - 5;
        fuelgathered2 = fuelgathered2 - 5;
        fuelgathered3 = fuelgathered3 - 5;
    end
end

function mission()
    msnMgr:addHeader("Sensors are not getting a good reading on this planet, and there's nowhere to land a shuttle anyway, so it's impossible to send the crew down. You detach the shuttle for a quick excursion to scoop up some raw materials.")
    msnMgr:addHeader(" ")
    msnMgr:addHeader("There are two spots where it seems like you might have a good chance at harvesting fuel. You only have time for one of them, however, and in either case it's going to be a very quick pass.")
    msnMgr:addHeader(" ")

    if (RandomFive <= 1) then
        msnMgr:buildChoice("Collection site 1: " .. prefixsuffix .. " in the troposphere")
    else
        msnMgr:buildChoice("Collection site 1: " .. prefix .. " in the" .. suffix)
    end
    msnMgr:buildChoice("Collection site 2: " .. prefix2 .. " in the" .. suffix2)
    msnMgr:finalizeChoice()
    if(not waitUserInput(choices)) then
        return
    end

    FuelChoice = msnMgr:getChoiceResponse(choices)
    choices = choices + 1

    msnMgr:addMessage(" ")

    piloting()

    msnMgr:addMessage("By flying with the airlock open, the shuttle scoops up a sample of hopefully useful gas, then heads quickly back to the ship. By the time it docks, the onboard drones have compressed the gas into a usable form.")
    msnMgr:addMessage(" ")

    if (FuelChoice == 0) then
        if (RandomFive <= 1) then
            fuelgatheredfinal = fuelgathered3;
        else
            fuelgatheredfinal = fuelgathered;
        end
    elseif (FuelChoice == 1) then
        fuelgatheredfinal = fuelgathered2;
    end

    if (fuelgatheredfinal >= 1) then
        ship:adjustFuel(fuelgatheredfinal)
    else
        ship:adjustFuel(1)
    end

end

-- Set Hidden Flags and other items

choices = 0;
prefix = 0;
prefix2 = 0;
suffix = 0;
suffix2 = 0;
prefixsuffix = 0;
fuelgathered = 0;
fuelgathered2 = 0;
fuelgathered3 = 0;
fuelgatheredfinal = 0;
pilotCrew = -1
pilotTrait = ""
traitList = {"Farmer", "Addicted", "Lucky", "Reckless", "Observant", "Xenophobic", "Scientist", "Competitive", "Teamworker", "Distracted", "Confident", "Violent", "Soldier", "Surgeon", "Cautious", "Mechanic"}
traitListPositive = {"Farmer", "Lucky", "Observant", "Scientist", "Teamworker", "Confident", "Soldier", "Surgeon", "Cautious", "Mechanic"}
traitList = shuffleList(traitList)

crewTraits()

missionStart()

reticulatingsplines()
mission()

missionOverview()

msnMgr:endMission(true)
