Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CrewTransfer #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions kOS-EVA/Addon.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Linq;
using System.Text;
Expand All @@ -13,6 +13,7 @@

using System.Collections.Generic;
using System.Reflection;
using kOS.Utilities;

namespace kOS.AddOns.kOSEVA
{
Expand Down Expand Up @@ -60,6 +61,7 @@ private void InitializeSuffixes()
AddSuffix("JUMP", new NoArgsVoidSuffix(Jump));
AddSuffix("SPRINT", new SetSuffix<BooleanValue>(() => evacontrol.Sprint, value => evacontrol.Sprint = value));
AddSuffix("STATE", new Suffix<StringValue>(() => kerbaleva.fsm.currentState.name));
AddSuffix("TRANSFERCREW", new TwoArgsSuffix<BooleanValue, CrewMember, Suffixed.Part.PartValue>(TransferCrew, "Transfer CrewMember to the Part"));

// Set a default bootfilename, when no other has been set.
if (shared.Vessel.isEVA && shared.KSPPart.GetComponentCached<Module.kOSProcessor>(ref _myprocessor).bootFile.ToLower() == "none" )
Expand Down Expand Up @@ -571,6 +573,46 @@ private void TurnTo(Vector direction)
CheckEvaController();
this.evacontrol.LookDirection = direction.ToVector3D();
}

private BooleanValue TransferCrew(CrewMember kerbal, Suffixed.Part.PartValue aimedPart)
{
Part destPart = null;
ProtoCrewMember safeCrewMember = null;

foreach (var vesselPart in shared.Vessel.Parts)
{
if (vesselPart.uid() == aimedPart.Part.uid())
{
destPart = vesselPart;
break;
}
}

foreach (var vesselCrew in shared.Vessel.GetVesselCrew())
{
if (vesselCrew.name.ToLower() == kerbal.Name.ToLower())
{
safeCrewMember = vesselCrew;
break;
}
}

if (safeCrewMember == null || destPart == null || destPart.protoModuleCrew.Count() >= destPart.CrewCapacity)
{
return false;
}

var transfer = CrewTransfer.Create(safeCrewMember.seat.part, safeCrewMember, delegate { });
try
{
transfer.MoveCrewTo(destPart);
}
catch (Exception ex)
{
Debug.LogWarning("kOSEVA: CrewTransfer failed: " + ex.ToString());
}
return true;
}
#endregion

#region internal functions
Expand All @@ -582,4 +624,4 @@ internal Vector3d v_rotate(Vector3d vec_from, Vector3d vec_to, double deg)
#endregion

}
}
}