Skip to content

Commit

Permalink
preliminary 1.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
fingerboxes committed Apr 30, 2015
1 parent 61b5ad1 commit 3614f37
Show file tree
Hide file tree
Showing 10 changed files with 337 additions and 365 deletions.
21 changes: 9 additions & 12 deletions Source/CrewQ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,24 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Assembly-CSharp.dll</HintPath>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\..\..\Games\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Assembly-CSharp-firstpass.dll</HintPath>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>..\..\..\..\..\..\..\Games\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\UnityEngine.dll</HintPath>
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\..\..\..\Games\Kerbal Space Program\KSP_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="API\CrewQAPI.cs" />
<Compile Include="Main.cs" />
<Compile Include="Roster.cs" />
<Compile Include="Settings.cs" />
<Compile Include="CrewQueue.cs" />
<Compile Include="CrewQueueRoster.cs" />
<Compile Include="CrewQueueSettings.cs" />
<Compile Include="Interface\AppLauncher.cs" />
<Compile Include="Interface\EditorModule.cs" />
<Compile Include="Interface\SettingsWindow.cs" />
Expand Down
107 changes: 12 additions & 95 deletions Source/Main.cs → Source/CrewQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@
namespace CrewQueue
{
[KSPAddon(KSPAddon.Startup.EveryScene, true)]
public class Main : MonoBehaviourExtended
public class CrewQueue : MonoBehaviourExtended
{
// ITS OVER NINE THOUSAND!!!!111
internal const ProtoCrewMember.RosterStatus VACATION = (ProtoCrewMember.RosterStatus)9001;
internal const ProtoCrewMember.RosterStatus ROSTERSTATUS_VACATION = (ProtoCrewMember.RosterStatus)9001;

// Singleton boilerplate
private static Main _Instance;
public static Main Instance
private static CrewQueue _Instance;
public static CrewQueue Instance
{
get
{
if (_Instance == null)
{
throw new Exception("ERROR: Attempted to access CrewQueue.Main before it was loaded");
throw new Exception("ERROR: Attempted to access CrewQueue before it was loaded");
}
return _Instance;
}
Expand All @@ -57,87 +57,24 @@ public static Main Instance
// MonoBehaviour Methods
protected override void Awake()
{
Logging.Debug("Loading...");

DontDestroyOnLoad(this);

_Instance = this;

_Instance = this;
GameEvents.OnVesselRecoveryRequested.Add(OnVesselRecoveryRequested);

Logging.Debug("Loaded");
}

// KSP Events
void OnVesselRecoveryRequested(Vessel vessel)
{
double adjustedTime = vessel.missionTime + Planetarium.GetUniversalTime();

adjustedTime = adjustedTime.Clamp(Planetarium.GetUniversalTime() + Settings.Instance.MinimumVacationDays * Utilities.GetDayLength,
Planetarium.GetUniversalTime() + Settings.Instance.MaximumVacationDays * Utilities.GetDayLength);

{
foreach (ProtoCrewMember kerbal in vessel.GetVesselCrew())
{
kerbal.SetVacationTimer(adjustedTime);
}

GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
}

// Our public methods
internal IEnumerable<ProtoCrewMember> AvailableCrew
{
get
{
IEnumerable<ProtoCrewMember> _AvailableCrew;

if (Settings.Instance.VacationHardLock)
{
_AvailableCrew = HighLogic.CurrentGame.CrewRoster.Crew.Where(x => x.OnVacation() == false && x.rosterStatus == ProtoCrewMember.RosterStatus.Available);
}
else
{
_AvailableCrew = HighLogic.CurrentGame.CrewRoster.Crew.Where (x => x.rosterStatus == ProtoCrewMember.RosterStatus.Available);
}

try
{
_AvailableCrew.Except(CMAssignmentDialog.Instance.GetManifest().GetAllCrew(false));
}
catch (Exception)
{
//nothing to see here, move along
}

return _AvailableCrew.OrderBy(x => x.GetVacationTimer());
}
}

internal void HideVacationingCrew()
{
if (Settings.Instance.VacationHardLock)
{
foreach (ProtoCrewMember kerbal in UnavailableCrew)
{
Logging.Debug("HIDING:" + kerbal.name);
kerbal.rosterStatus = VACATION;
}
}
}

internal void ShowVacationingCrew()
{
foreach (ProtoCrewMember kerbal in HighLogic.CurrentGame.CrewRoster.Crew.Where(x => x.rosterStatus == VACATION))
{
Logging.Debug("UNHIDING:" + kerbal.name);
kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Available;
kerbal.SetLastMissionData(vessel.missionTime, Planetarium.GetUniversalTime());
}
}

internal IEnumerable<ProtoCrewMember> GetCrewForPart(Part partPrefab, bool preferVeterans = false)
{
IList<ProtoCrewMember> partCrew = new List<ProtoCrewMember>();
IEnumerable<ProtoCrewMember> availableCrew = (preferVeterans ? VeteranCrew : NewbieCrew);
IEnumerable<ProtoCrewMember> availableCrew = (preferVeterans ? CrewQueueRoster.Instance.MostExperiencedCrew : CrewQueueRoster.Instance.LeastExperiencedCrew);
string[] crewComposition;
int numToSelect = partPrefab.CrewCapacity;
ProtoCrewMember candidate;
Expand All @@ -156,15 +93,16 @@ internal IEnumerable<ProtoCrewMember> GetCrewForPart(Part partPrefab, bool prefe
{
if (i < crewComposition.Length)
{
candidate = availableCrew.Where(x => x.experienceTrait.Title == crewComposition[i]).FirstOrDefault();
candidate = availableCrew.Where(x => x.experienceTrait.Title == crewComposition[i]).FirstOrDefault();
}
else
{
candidate = availableCrew.Where(x => x.experienceTrait.Title == crewComposition[new System.Random().Next(crewComposition.Length)]).FirstOrDefault();
candidate = availableCrew.Where(x => x.experienceTrait.Title == crewComposition[new System.Random().Next(crewComposition.Length)]).FirstOrDefault();
}

if (candidate != null)
{
Logging.Debug("Adding candidate: " + candidate.name);
partCrew.Add(candidate);
}

Expand All @@ -175,27 +113,6 @@ internal IEnumerable<ProtoCrewMember> GetCrewForPart(Part partPrefab, bool prefe
}
}

// The idea here is that we always want to be dealing with ProtoCrewMember outside of this class.
// By making our data available as extension methods, that makes life easier.
public static class CrewQExtensions
{
internal static double GetVacationTimer(this ProtoCrewMember kerbal)
{
return Settings.Instance.GetVacationTimer(kerbal);
}

internal static bool OnVacation(this ProtoCrewMember kerbal)
{
return Settings.Instance.OnVacation(kerbal);
}

internal static void SetVacationTimer(this ProtoCrewMember kerbal, double timeout)
{
Logging.Debug("Attempting to set vacation timer: " + timeout);
Settings.Instance.SetVacationTimer(kerbal, timeout);
}
}

public class ModuleCrewQ : PartModule
{
[KSPField]
Expand Down
Loading

0 comments on commit 3614f37

Please sign in to comment.