private void restore_payload_resources(PackedVessel payload) { if (payload_resources.Count == 0) { return; } if (HighLogic.LoadedSceneIsEditor) { ResetPayloadResources(); } var res_mass = 0.0; foreach (var r in payload_resources) { var res = part.Resources.Get(r.name); if (res == null) { continue; } res_mass += res.amount * res.info.density; payload.resources.TransferResource(r.name, res.amount); part.Resources.Remove(res); } payload.mass += (float)res_mass; payload_resources.Clear(); Storage.UpdateParams(); }
static void vessels_list(HangarStorage storage, ref Vector2 scroll, ref PackedVessel selected, bool is_lhs = true) { if (storage == null) { return; } scroll = GUILayout.BeginScrollView(scroll, GUILayout.Height(scroll_height), GUILayout.Width(scroll_width)); GUILayout.BeginVertical(); List <PackedVessel> vessels = storage.GetVessels(); vessels.Sort((a, b) => a.name.CompareTo(b.name)); foreach (var v in vessels) { GUILayout.BeginHorizontal(); if (is_lhs) { HangarGUI.PackedVesselLabel(v); } if (GUILayout.Button(is_lhs? ">>" : "<<", Styles.normal_button, GUILayout.ExpandWidth(true))) { selected = v; } if (!is_lhs) { HangarGUI.PackedVesselLabel(v); } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndScrollView(); }
void highlight_content(PackedVessel pc, ContentState state) { if (HighLogic.LoadedSceneIsEditor) { SetHighlightedContent(pc, state); } }
void update_content_orientation_hint(PackedVessel vsl) { var c = vsl.CoG; var e = vsl.extents; var mesh = content_orientation_hint.sharedMesh ?? new Mesh(); mesh.vertices = new Vector3[] { c + new Vector3(0, e.y, e.z), c + new Vector3(-e.x / 4, 0, e.z), c + new Vector3(e.x / 4, 0, e.z), c + new Vector3(0, 0, e.z * 0.8f), }; mesh.triangles = new int[] { 0, 1, 2, 0, 2, 3, 0, 3, 1, 3, 1, 2 }; mesh.RecalculateBounds(); mesh.RecalculateNormals(); mesh.RecalculateTangents(); content_orientation_hint.sharedMesh = mesh; }
void disable_highlight(PackedVessel pc) { if (pc == highlighted_content) { disable_highlight(); } }
public bool CanTransferTo(PackedVessel vsl, HangarPassage other, PassageNode requesting_node = null) { if (!enabled) { return(false); } if (this == other) { return(CanHold(vsl)); } var this_node = requesting_node?.OtherNode; bool can_transfer = false; foreach (var pn in Nodes.Values) { if (pn == this_node) { continue; } var other_passage = pn.CanPassThrough(vsl); if (other_passage != null) { can_transfer = other_passage.CanTransferTo(vsl, other, pn); } if (can_transfer) { break; } } return(can_transfer); }
public virtual bool TryStoreVessel(PackedVessel vsl, bool in_optimal_orientation, bool update_vessel_orientation) { bool stored = false; if (VesselFits(vsl, in_optimal_orientation)) { if (stored_vessels.TryAdd(vsl)) { if (in_optimal_orientation && update_vessel_orientation) { vsl.SpawnRotation = SpawnManager.GetOptimalRotation(vsl.size).eulerAngles; } OnVesselStored(vsl); set_part_params(); stored = true; } else { Utils.Message("There's no room for \"{0}\"", vsl.name); } } else { Utils.Message(5, "Insufficient vessel clearance for safe docking\n" + "\"{0}\" cannot be stored", vsl.name); } if (!stored && HighLogic.LoadedSceneIsEditor && vsl is PackedConstruct pc) { AddUnfit(pc); return(true); } return(stored); }
private void on_ship_removed(PackedVessel pc) { if (HighLogic.LoadedSceneIsEditor) { update_crew_capacity(0); } restore_payload_resources(pc); }
public void ClearSelection() { reset_highlight(lhs); reset_highlight(rhs); lhs = rhs = null; lhs_selected = null; if (storages != null) { storages.ForEach(reset_highlight); } }
public override bool TryStoreVessel(PackedVessel vsl, bool in_optimal_orientation, bool update_vessel_orientation) { if (!(vsl is PackedConstruct)) { Utils.Message("A vessel can be fixed inside this storage only during construction."); return(false); } return(base.TryStoreVessel(vsl, in_optimal_orientation, update_vessel_orientation)); }
public override bool TryStoreVessel(PackedVessel vsl, bool in_optimal_orientation, bool update_vessel_orientation) { if (VesselsCount > 0) { Utils.Message("The storage is already occupied"); return(false); } return(base.TryStoreVessel(vsl, in_optimal_orientation, update_vessel_orientation)); }
void try_repack_construct(PackedVessel pv) { if (!try_pack_construct(pv)) { OnVesselRemoved(pv); if (pv is PackedConstruct pc) { AddUnfit(pc); } } }
protected override bool try_store_packed_vessel(PackedVessel vsl, bool in_flight) { if (!entrance.CanTransferTo(vsl, Storage)) { Utils.Message(8, "There's no room in the hangar for this vessel,\n" + "OR vessel clearance is insufficient for safe docking.\n\n" + "\"{0}\" cannot be stored", vsl.name); return(false); } Storage.StoreVessel(vsl); return(true); }
public void HighlightContentTemporary(PackedVessel pc, float period, ContentState state = ContentState.Remains) { if (highlighted_content == null) { SetHighlightedContent(pc, state); StartCoroutine(stop_highlighting_content_after(period)); } else { stop_at_time = Time.time + period; SetHighlightedContent(pc, state); } }
public bool RemoveVessel(PackedVessel vsl) { if (stored_vessels.Remove(vsl)) { OnVesselRemoved(vsl); if (stored_vessels.Count == 0) { OnStorageEmpty(); } set_part_params(); return(true); } return(false); }
protected override bool can_restore(PackedVessel v) { if (v == null || !base.can_restore(v)) { return(false); } if (!SpawnManager.MetricFits(v.metric, v.GetSpawnRotation())) { Utils.Message(6, "Vessel clearance is insufficient for safe launch.\n\n" + "\"{0}\" cannot be launched", v.name); return(false); } return(true); }
protected override bool can_store_packed_vessel(PackedVessel vsl, bool in_flight) { if (!base.can_store_packed_vessel(vsl, in_flight)) { return(false); } // ReSharper disable once InvertIf if (Storage.VesselsCount > 0) { Utils.Message("Payload is already stored"); return(false); } return(true); }
public void DrawSpawnRotationControls(PackedVessel content) { GUILayout.BeginVertical(); GUILayout.Label("Change launch orientation", Styles.boxed_label, GUILayout.ExpandWidth(true)); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); if (GUILayout.Button("X+", Styles.active_button, GUILayout.ExpandWidth(true))) { StepChangeSpawnRotation(content, 0, true); } if (GUILayout.Button("X-", Styles.active_button, GUILayout.ExpandWidth(true))) { StepChangeSpawnRotation(content, 0, false); } GUILayout.EndVertical(); GUILayout.BeginVertical(); if (GUILayout.Button("Y+", Styles.active_button, GUILayout.ExpandWidth(true))) { StepChangeSpawnRotation(content, 1, true); } if (GUILayout.Button("Y-", Styles.active_button, GUILayout.ExpandWidth(true))) { StepChangeSpawnRotation(content, 1, false); } GUILayout.EndVertical(); GUILayout.BeginVertical(); if (GUILayout.Button("Z+", Styles.active_button, GUILayout.ExpandWidth(true))) { StepChangeSpawnRotation(content, 2, true); } if (GUILayout.Button("Z-", Styles.active_button, GUILayout.ExpandWidth(true))) { StepChangeSpawnRotation(content, 2, false); } GUILayout.EndVertical(); if (HighLogic.LoadedSceneIsEditor) { GUILayout.BeginVertical(); if (GUILayout.Button(opt_button, Styles.good_button, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true))) { SetSpawnRotation(content, spawn_space_manager.GetOptimalRotation(content.size).eulerAngles); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
public bool TryTransferTo(PackedVessel vsl, HangarStorage other) { if (!CanTransferTo(vsl, other)) { Utils.Message("Unable to move \"{0}\" from \"{1}\" to \"{2}\"", vsl.name, this.Title(), other.Title()); return(false); } if (!RemoveVessel(vsl)) { this.Log("TryTransferTo: trying to remove a PackedVessel that is not present."); return(false); } vsl.SpawnRotation = other.SpawnManager.GetOptimalRotation(vsl.size).eulerAngles; other.StoreVessel(vsl); return(true); }
public void TransferVessel() { if (lhs == null || rhs == null) { return; } if (lhs_selected != null) { lhs.TryTransferTo(lhs_selected, rhs); lhs_selected = null; } else if (rhs_selected != null) { rhs.TryTransferTo(rhs_selected, lhs); rhs_selected = null; } }
protected override bool can_store_packed_vessel(PackedVessel vsl, bool in_flight) { if (!base.can_store_packed_vessel(vsl, in_flight)) { return(false); } Quaternion?rotation = AutoPositionVessel && !in_flight ? SpawnManager.GetOptimalRotation(vsl.size) : vsl.GetSpawnRotation(); if (!SpawnManager.MetricFits(vsl.metric, rotation)) { Utils.Message(5, "Insufficient vessel clearance in hangar entrance\n" + "\"{0}\" cannot be stored", vsl.name); return(false); } return(true); }
public HangarPassage CanPassThrough(PackedVessel vsl) { var other_passage = get_other_passage(); if (other_passage == null) { return(null); } var other_node = other_passage.GetNodeByPart(part); if (other_node == null) { return(null); } var size = new Vector2(Mathf.Min(Size.x, other_node.Size.x), Mathf.Min(Size.y, other_node.Size.y)); return(vsl.metric.FitsSomehow(size)? other_passage : null); }
//Vessel selection list void select_vessel(PackedVessel vsl) { if (vsl != null) { vessel_id = vsl.id; if (vsl != selected_vessel) { selected_hangar.ResourceTransferList.Clear(); resources_window.TransferAction = () => selected_hangar.TransferResources(vsl); selected_hangar.SetHighlightedContent(null); } } else { vessel_id = Guid.Empty; resources_window.TransferAction = null; } selected_vessel = vsl; }
public bool VesselFits(PackedVessel pv, bool in_optimal_orientation) { if (pv != null) { Quaternion?rotation = in_optimal_orientation ? SpawnManager.GetOptimalRotation(pv.size) : pv.GetSpawnRotation(); if (SpawnManager.MetricFits(pv.metric, rotation)) { var constraints = FitConstraint.GetInvocationList(); for (int i = 0, len = constraints.Length; i < len; i++) { if (constraints[i] is PackedVesselConstraint cons && !cons(pv)) { return(false); } } return(true); } } return(false); }
private void store_payload_resources(PackedVessel payload) { if (payload_resources.Count > 0) { return; } var res_mass = 0.0; var resources = payload.resources; foreach (var r in resources.resourcesNames) { if (part.Resources.Contains(r)) { continue; } if (Globals.Instance.ResourcesBlacklist.IndexOf(r) >= 0) { continue; } var res = part.Resources.Add(r, resources.ResourceAmount(r), resources.ResourceCapacity(r), true, true, true, true, PartResource.FlowMode.Both); if (res == null) { continue; } payload_resources.Add(new PayloadRes(res)); resources.TransferResource(r, -res.amount); res_mass += res.amount * res.info.density; } payload.mass -= (float)res_mass; Storage.UpdateParams(); }
public void SetHighlightedContent(PackedVessel pc, ContentState state = ContentState.Remains) { highlighted_content = pc; content_hull_mesh.gameObject.SetActive(false); if (highlighted_content != null) { var mesh = highlighted_content.metric.hull_mesh; if (mesh != null) { content_hull_mesh.mesh = mesh; if (state != ContentState.Remains) { content_hull_renderer.material.color = state == ContentState.Fits ? Colors.Good.Alpha(0.25f) : Colors.Danger.Alpha(0.25f); } update_content_hull_mesh(); } } else { stop_at_time = -1; } }
virtual public bool CanHold(PackedVessel vsl) { return(true); }
public bool Contains(PackedVessel item) => stored_vessels.Contains(item);
void highlight_content_unfit(PackedVessel pc) => highlight_content(pc, ContentState.DoesntFit);
void highlight_content_fit(PackedVessel pc) => highlight_content(pc, ContentState.Fits);