private void doHijack() { Debug.Log("[AirlockPlus] INFO: hijacking CrewHatchDialog for airlock " + airlock.gameObject.name + " on part " + airlockPart.partInfo.name + " of " + airlockPart.vessel.vesselName); // TextHeader chd.transform.GetChild(0).GetComponent <TextMeshProUGUI>().text = Localizer.Format("#autoLOC_AirlockPlus00000"); // Content transform of Scroll View Transform listContainer = chd.GetComponentInChildren <ContentSizeFitter>().transform; // Wipe the slate clean for (int i = listContainer.childCount - 1; i > 0; i--) { listContainer.GetChild(i).gameObject.SetActive(false); } // EmptyModuleText if (airlockPart.vessel.GetCrewCount() == 0) { listContainer.GetChild(0).gameObject.SetActive(true); chd = null; return; } listContainer.GetChild(0).gameObject.SetActive(false); // Crew in airlock part addCrewToList(listContainer, airlockPart); if (useCLS) { // Crew in other parts ICLSSpace clsSpace = CLSClient.GetCLS().getCLSVessel(airlockPart.vessel).Parts.Find(x => x.Part == airlockPart).Space; foreach (ICLSPart p in clsSpace.Parts) { if (p.Part != airlockPart) { addCrewToList(listContainer.transform, p.Part); } } // TextModuleCrew chd.transform.GetChild(2).GetComponent <TextMeshProUGUI>().text = Localizer.Format("#autoLOC_AirlockPlusAP001", clsSpace.Crew.Count, clsSpace.MaxCrew); } else { // Crew in other parts foreach (Part p in airlockPart.vessel.parts) { if (p != airlockPart) { addCrewToList(listContainer.transform, p); } } // TextModuleCrew chd.transform.GetChild(2).GetComponent <TextMeshProUGUI>().text = Localizer.Format("#autoLOC_AirlockPlusAP001", airlockPart.vessel.GetCrewCount(), airlockPart.vessel.GetCrewCapacity()); } chd = null; }
internal static bool IsClsInSameSpace(Part source, Part target) { bool results = false; if (source == null || target == null) { return(results); } if (SMSettings.EnableCls && SMSettings.RealXfers) { if (SMAddon.ClsAddon.Vessel == null) { return(results); } ICLSSpace sourceSpace = null; ICLSSpace targetSpace = null; List <ICLSPart> .Enumerator parts = SMAddon.ClsAddon.Vessel.Parts.GetEnumerator(); while (parts.MoveNext()) { ICLSPart ipart = parts.Current; if (ipart == null) { continue; } if (ipart.Part == source) { sourceSpace = ipart.Space; } if (ipart.Part == target) { targetSpace = ipart.Space; } if (sourceSpace != null && targetSpace != null) { break; } } parts.Dispose(); if (sourceSpace != null && targetSpace != null && sourceSpace == targetSpace) { results = true; } } else { results = true; } return(results); }
private void CLSBoardAuto() { Debug.Log("[AirlockPlus|BoardingPass] INFO: " + vessel.vesselName + " auto boarding " + tgtAirlockPart.vessel.vesselName + " via " + tgtAirlockPart.partInfo.name); ICLSSpace clsSpace = CLSClient.GetCLS().getCLSVessel(tgtAirlockPart.vessel).Parts.Find(x => x.Part == tgtAirlockPart).Space; // check in case of full vessel first if (clsSpace.Crew.Count >= clsSpace.MaxCrew) { Debug.Log("[AirlockPlus|BoardingPass] INFO: Auto boarding failed - CLS space full"); ScreenMessages.PostScreenMessage(scrmsgVesFull); // HACK: temporarily disable KerbalEVA for one update frame to prevent stock boarding from being registered alongside auto boarding // this prevents "spurious" stock "Cannot board a full module" message appearing alongside our auto boarding "Cannot board a full vessel" keva.enabled = false; autoBoardingFull = true; return; } // find part to board Part dest = null; if (SpaceAvail(tgtAirlockPart)) { // board the part itself if possible dest = tgtAirlockPart; } else { foreach (ICLSPart p in clsSpace.Parts) { if (SpaceAvail(p.Part)) { dest = p.Part; break; } } } if (dest == null) { Debug.Log("[AirlockPlus|BoardingPass] ERROR: Auto boarding target vessel at " + clsSpace.Crew.Count + "/" + clsSpace.MaxCrew + "of CLS space capacity, but somehow unable to find a part with space?!"); return; } keva.BoardPart(dest); }
private void MoveKerbal(ICLSKerbal k) { // Debug.Log("MoveKerbal"); // If there is only one seat in this space, then our friend is not going anywhere! ICLSPart temppart = k.Part; ICLSSpace s = temppart.Space; if (null == s) { Debug.LogWarning("space is null :("); } int maxCrew = s.MaxCrew; if (k.Part.Space.MaxCrew > 1) { //Debug.Log("vessel has more than 1 seat"); List <PartSeat> listSeats = new List <PartSeat>(); // There are other seats in the space that our chosen kerbal is in. Pick one of them at random, and then we can arrange the swap. foreach (ICLSPart p in k.Part.Space.Parts) { for (int counter = 0; counter < p.Part.CrewCapacity; counter++) { //Debug.Log("Adding " + p.partInfo.title + " seat "+counter); listSeats.Add(new PartSeat(p.Part, counter)); } } // Now we have a list of all the possible places we could move the kerbal to - choose one of them. int choosenLocation = this.random.Next(listSeats.Count); // TODO remove debugging //Debug.Log("choosen location: " + choosenLocation); // Do the swap bool kerbalsSwapped = SwapKerbals(k, listSeats[choosenLocation].part, listSeats[choosenLocation].seat); } else { //Debug.Log("Unable to move kerbal as there is only one seat in this vessel!"); } }
private void ChooseAndMoveAKerbal() { // Debug.Log("KHSAddon:ChooseAndMoveAKerbal"); //Debug.Log("Before moving KerbalGUIManager.ActiveCrew.Count:" + KerbalGUIManager.ActiveCrew.Count); // If CLS is not installed then just bug out if (!CLSClient.CLSInstalled) { Debug.LogWarning("Not moving kerbals as the CLS mod is not installed"); return; } ICLSVessel activeVessel = CLSClient.GetCLS().Vessel; if (activeVessel.Spaces.Count > 0) { List <ICLSSpace> crewedSpaces = new List <ICLSSpace>(activeVessel.Spaces.Count); foreach (ICLSSpace s in activeVessel.Spaces) { if (s.Crew.Count > 0) { crewedSpaces.Add(s); } } // now we have got a list of crewed spaces - pick one at random if (crewedSpaces.Count > 0) { ICLSSpace pickedSpace = crewedSpaces[this.random.Next(crewedSpaces.Count)]; // Now pick one of the crew in that space at random! ICLSKerbal pickedKerbel = pickedSpace.Crew[this.random.Next(pickedSpace.Crew.Count)]; // Move move the kerbal somewhere else MoveKerbal(pickedKerbel); } } //Debug.Log("After moving KerbalGUIManager.ActiveCrew.Count:" + KerbalGUIManager.ActiveCrew.Count); }
public void MergeSpaces(ICLSSpace space1, ICLSSpace space2) { if (space1 == space2) { return; } if (listSpaces.Contains(space1) && listSpaces.Contains(space2)) { CLSSpace space1Real = space1 as CLSSpace; List <ICLSPart> partsToAdd = space2.Parts; for (int i = 0; i < partsToAdd.Count; i++) { space1Real.AddPart(partsToAdd[i] as CLSPart); } listSpaces.Remove(space2); // Probably should not fire in this method. // CLSAddon.onCLSVesselChange.Fire(space1Real.Parts[0].Part.vessel); } }