Ejemplo n.º 1
0
 //metric copy
 public Metric(Metric m)
 {
     bounds = new Bounds(m.bounds.center, m.bounds.size);
     volume = m.volume;
     area   = m.area;
     mass   = m.mass;
     CrewCapacity = m.CrewCapacity;
 }
Ejemplo n.º 2
0
 public override void Load(ConfigNode node)
 {
     ConfigNode metric_node = node.GetNode("METRIC");
     vessel_node = node.GetNode("VESSEL");
     metric = new Metric(metric_node);
     name   = node.GetValue("name");
     flag   = node.GetValue("flag");
     id     = new Guid(node.GetValue("id"));
 }
Ejemplo n.º 3
0
 public PackedConstruct(string file, string flag)
 {
     this.flag = flag;
     vessel_node = ConfigNode.Load(file);
     vessel_node.name = "VESSEL";
     if(!LoadConstruct()) return;
     metric = new Metric(construct.Parts);
     name = construct.shipName;
     id = Guid.NewGuid();
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Sets up internal properties that depend on Storage
 /// and may change with resizing.
 /// Overrides should always check if Storage is not null.
 /// </summary>
 /// <param name="reset">If set to <c>true</c> reset state befor setup.</param>
 public virtual void Setup(bool reset = false)
 {
     PartMetric = new Metric(part);
 }
Ejemplo n.º 5
0
 public override void Load(ConfigNode node)
 {
     ConfigNode vessel_node = node.GetNode("VESSEL");
     ConfigNode metric_node = node.GetNode("METRIC");
     ConfigNode crew_node   = node.GetNode("CREW");
     proto_vessel = new ProtoVessel(vessel_node, HighLogic.CurrentGame);
     metric = new Metric(metric_node);
     crew   = new List<ProtoCrewMember>();
     foreach(ConfigNode cn in crew_node.nodes)
         crew.Add(new ProtoCrewMember(HighLogic.CurrentGame.Mode, cn));
     id   = proto_vessel.vesselID;
     name = proto_vessel.vesselName;
     resources = new VesselResources<ProtoVessel, ProtoPartSnapshot, ProtoPartResourceSnapshot>(proto_vessel);
 }
Ejemplo n.º 6
0
 public StoredVessel(Vessel vsl, bool compute_hull=false)
 {
     proto_vessel = vsl.BackupVessel();
     metric = new Metric(vsl, compute_hull);
     id     = proto_vessel.vesselID;
     name   = proto_vessel.vesselName;
     crew   = vsl.GetVesselCrew();
     resources = new VesselResources<ProtoVessel, ProtoPartSnapshot, ProtoPartResourceSnapshot>(proto_vessel);
 }
Ejemplo n.º 7
0
 public void UpdateMetric(bool compute_hull = false)
 {
     if(construct == null) return;
     if(construct.parts.Count == 0) return;
     //sort parts from root to leavs
     var parts = construct.parts[0].AllConnectedParts();
     metric = new Metric(parts, compute_hull);
 }
Ejemplo n.º 8
0
 public bool FitsSomehow(Metric other)
 {
     List<float>  D = new List<float>{size.x, size.y, size.z};
     List<float> _D = new List<float>{other.size.x, other.size.y, other.size.z};
     D.Sort(); _D.Sort();
     foreach(float d in D)
     {
         float ud = -1;
         foreach(float _d in _D)
         {
             if(d <= _d)
             {
                 ud = _d;
                 break;
             }
         }
         if(ud < 0) return false;
         _D.Remove(ud);
     }
     return true;
 }
Ejemplo n.º 9
0
 public static void DrawYZ(Metric M, Transform T)
 {
     Utils.GLVec(T.position, T.up * M.extents.y * 0.8f, Color.green);
     Utils.GLVec(T.position, T.forward * M.extents.z * 0.8f, Color.blue);
 }
Ejemplo n.º 10
0
 void change_part_params(Metric delta, float k = 1f)
 {
     vessels_mass += k*delta.mass;
     vessels_cost += k*delta.cost;
     used_volume  += k*delta.volume;
     if(used_volume < 0) used_volume = 0;
     if(vessels_mass < 0) vessels_mass = 0;
     if(vessels_cost < 0) vessels_cost = 0;
     stored_mass = Utils.formatMass(vessels_mass);
     stored_cost = vessels_cost.ToString();
     set_part_params();
 }
Ejemplo n.º 11
0
 protected virtual void UpdatePart()
 {
     animated_nodes.ForEach(n => n.UpdateNode());
     if(prefab_metric == null) return;
     part_metric  = new Metric(part);
     volume_scale = part_metric.volume/prefab_metric.volume;
     part.buoyancy       = prefab.buoyancy*volume_scale;
     part.maximum_drag   = prefab.maximum_drag*volume_scale;
     part.angularDrag    = prefab.angularDrag*volume_scale;
     part.crashTolerance = prefab.crashTolerance*Mathf.Pow(volume_scale, 1/3f);
 }
Ejemplo n.º 12
0
 public override void OnStart(StartState state)
 {
     base.OnStart(state);
     if(state == StartState.None) return;
     //get sound effects
     if(CompressorSound != string.Empty)
     {
         Utils.createFXSound(part, fxSndCompressor, CompressorSound, true);
         fxSndCompressor.audio.volume = GameSettings.SHIP_VOLUME * SoundVolume;
     }
     //get controlled modules
     foreach(string module_name in ControlledModules.Split(' '))
     {
         if(module_name == "") continue;
         if(!part.Modules.Contains(module_name))
         {
             this.Log("OnStart: {0} does not contain {1} module.", part.name, module_name);
             continue;
         }
         var modules = new List<IControllableModule>();
         foreach(PartModule pm in part.Modules)
         {
             if(pm.moduleName == module_name)
             {
                 var controllableModule = pm as IControllableModule;
                 if(controllableModule != null)
                 {
                     modules.Add(controllableModule);
                     if(State != AnimatorState.Opened)
                         controllableModule.Enable(false);
                 }
                 else this.Log("OnStart: {0} is not a ControllableModule. Skipping it.", pm.moduleName);
             }
         }
         controlled_modules.AddRange(modules);
     }
     //get animated nodes
     foreach(string node_name in AnimatedNodes.Split(' '))
     {
         if(node_name == "") continue;
         Transform node_transform = part.FindModelTransform(node_name);
         if(node_transform == null)
         {
             this.Log("OnStart: no transform '{0}' in {1}", node_name, part.name);
             continue;
         }
         AttachNode node = part.findAttachNode(node_name);
         if(node == null) node = part.srfAttachNode.id == node_name? part.srfAttachNode : null;
         if(node == null)
         {
             this.Log("OnStart: no node '{0}' in {1}", node_name, part.name);
             continue;
         }
         var a_node = new AnimatedNode(node, node_transform, part);
         animated_nodes.Add(a_node);
     }
     //calculate prefab metric
     prefab = part.partInfo.partPrefab;
     prefab_metric = new Metric(prefab);
     //get compressed gas for the first time
     if(CompressedGas < 0) CompressedGas = InflatableVolume;
     init_compressor();
     //ignore DragMultiplier as Drag is changed with volume
     DragMultiplier = 1f;
     //prevent accidental looping of animation
     Loop = false;
     //update part, GUI and set the flag
     UpdatePart();
     ToggleEvents();
     StartCoroutine(SlowUpdate());
     isEnabled = false;
     just_loaded = true;
 }
Ejemplo n.º 13
0
 public bool FitsSomehow(Metric other)
 {
     var _D = new List<float>{other.size.x, other.size.y, other.size.z};
     return fits_somehow(_D);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Returns true if THIS metric fits inside the OTHER metric.
 /// </summary>
 /// <param name="this_T">Transform of this metric.</param>
 /// <param name="other_T">Transform of the other metric.</param>
 /// <param name="other">Metric acting as a container.</param>
 public bool FitsAligned(Transform this_T, Transform other_T, Metric other)
 {
     var edges = hull != null? hull.Points.ToArray() : BoundsEdges(bounds);
     for(int i = 0; i < edges.Length; i++)
     {
         Vector3 edge = other_T.InverseTransformPoint(this_T.position+this_T.TransformDirection(edges[i]-center));
         if(other.hull != null)
         { if(!other.hull.Contains(edge)) return false; }
         else if(!other.bounds.Contains(edge)) return false;
     }
     return true;
 }
Ejemplo n.º 15
0
 public override void Load(ConfigNode node)
 {
     ConfigNode vessel_node = node.GetNode("VESSEL");
     ConfigNode metric_node = node.GetNode("METRIC");
     ConfigNode crew_node   = node.GetNode("CREW");
     vessel = new ProtoVessel(vessel_node, FlightDriver.FlightStateCache);
     metric = new Metric(metric_node);
     crew   = new List<ProtoCrewMember>();
     foreach(ConfigNode cn in crew_node.nodes) crew.Add(new ProtoCrewMember(cn));
     id   = vessel.vesselID;
     CoM  = ConfigNode.ParseVector3(node.GetValue("CoM"));
     resources = new VesselResources<ProtoVessel, ProtoPartSnapshot, ProtoPartResourceSnapshot>(vessel);
 }
Ejemplo n.º 16
0
 public StoredVessel(Vessel vsl)
 {
     vessel = vsl.BackupVessel();
     metric = new Metric(vsl);
     id     = vessel.vesselID;
     CoM    = vsl.findLocalCenterOfMass();
     crew   = vsl.GetVesselCrew();
     resources = new VesselResources<ProtoVessel, ProtoPartSnapshot, ProtoPartResourceSnapshot>(vessel);
     //			fixTripLogger(); //FIXME
 }
Ejemplo n.º 17
0
 public override void OnStart(StartState state)
 {
     base.OnStart(state);
     if (state == StartState.None)
     {
         return;
     }
     //init compressor
     if (Compressor.Valid)
     {
         Compressor.Init(part);
         if (CompressorSound != string.Empty)
         {
             Utils.createFXSound(part, fxSndCompressor, CompressorSound, true);
             fxSndCompressor.audio.volume = GameSettings.SHIP_VOLUME * SoundVolume;
         }
     }
     //get controlled modules
     if (!string.IsNullOrEmpty(ControlledModules))
     {
         foreach (string module_name in Utils.ParseLine(ControlledModules, Utils.Delimiters))
         {
             if (module_name == "")
             {
                 continue;
             }
             if (!part.Modules.Contains(module_name))
             {
                 this.Log("OnStart: {} does not contain {} module.", part.name, module_name);
                 continue;
             }
             var modules = new List <IControllableModule>();
             foreach (PartModule pm in part.Modules)
             {
                 if (pm.moduleName == module_name)
                 {
                     var controllableModule = pm as IControllableModule;
                     if (controllableModule != null)
                     {
                         modules.Add(controllableModule);
                         if (State != AnimatorState.Opened)
                         {
                             controllableModule.Enable(false);
                         }
                     }
                     else
                     {
                         this.Log("OnStart: {} is not a ControllableModule. Skipping it.", pm.moduleName);
                     }
                 }
             }
             controlled_modules.AddRange(modules);
         }
     }
     //get animated nodes
     foreach (string node_name in Utils.ParseLine(AnimatedNodes, Utils.Delimiters))
     {
         if (node_name == "")
         {
             continue;
         }
         Transform node_transform = part.FindModelTransform(node_name);
         if (node_transform == null)
         {
             this.Log("OnStart: no transform '{}' in {}", node_name, part.name);
             continue;
         }
         AttachNode node = part.FindAttachNode(node_name);
         if (node == null)
         {
             node = part.srfAttachNode.id == node_name ? part.srfAttachNode : null;
         }
         if (node == null)
         {
             this.Log("OnStart: no node '{}' in {}", node_name, part.name);
             continue;
         }
         var a_node = new AnimatedNode(node, node_transform, part);
         animated_nodes.Add(a_node);
     }
     //calculate prefab metric
     prefab        = part.partInfo.partPrefab;
     prefab_metric = new Metric(prefab);
     //get compressed gas for the first time
     if (CompressedGas < 0 &&
         (state == StartState.Editor ||
          vessel != null && vessel.staticPressurekPa > 1e-6))
     {
         CompressedGas = InflatableVolume;
     }
     //prevent accidental looping of animation
     Loop = false;
     //update part, GUI and set the flag
     UpdatePart();
     ToggleEvents();
     StartCoroutine(SlowUpdate());
     StartCoroutine(FirstTimeUpdateNodes());
     isEnabled = false;
 }
Ejemplo n.º 18
0
 public override void OnStart(StartState state)
 {
     base.OnStart(state);
     if(state == StartState.None) return;
     //get controlled modules
     foreach(string module_name in ControlledModules.Split(' '))
     {
         if(!part.Modules.Contains(module_name))
         {
             Utils.Log("HangarGenericInflatable.OnStart: {0} does not contain {1} module.", part.name, module_name);
             continue;
         }
         List<IControllableModule> modules = new List<IControllableModule>();
         foreach(PartModule pm in part.Modules)
         {
             if(pm.moduleName == module_name)
             {
                 var controllableModule = pm as IControllableModule;
                 if(controllableModule != null)
                 {
                     modules.Add(controllableModule);
                     if(State != AnimatorState.Opened)
                         controllableModule.Enable(false);
                 }
                 else Utils.Log("HangarGenericInflatable.OnStart: {0} is not a ControllableModule. Skipping it.", pm.moduleName);
             }
         }
         controlled_modules.AddRange(modules);
     }
     //get animated nodes
     foreach(string node_name in AnimatedNodes.Split(' '))
     {
         Transform node_transform = part.FindModelTransform(node_name);
         if(node_transform == null)
         {
             Utils.Log("HangarGenericInflatable.OnStart: no transform '{0}' in {1}", node_name, part.name);
             continue;
         }
         AttachNode node = part.findAttachNode(node_name);
         if(node == null) node = part.srfAttachNode.id == node_name? part.srfAttachNode : null;
         if(node == null)
         {
             Utils.Log("HangarGenericInflatable.OnStart: no node '{0}' in {1}", node_name, part.name);
             continue;
         }
         var a_node = new AnimatedNode(node, node_transform, part);
         animated_nodes.Add(a_node);
     }
     //calculate prefab metric
     prefab = part.partInfo.partPrefab;
     prefab_metric = new Metric(prefab);
     //get compressed gas for the first time
     if(CompressedGas < 0) CompressedGas = InflatableVolume;
     //load compressor
     if(CompressorConfig != null)
     {
         compressor = new GasCompressor(part);
         compressor.Load(CompressorConfig);
     }
     //forbid surface attachment for the inflatable
     part.attachRules.allowSrfAttach = false;
     UpdatePart();
     //update GUI and set the flag
     ToggleEvents();
     StartCoroutine(UpdateStatus());
     gui_state = this.DeactivateGUI();
     just_loaded = true;
 }
Ejemplo n.º 19
0
 //operators
 public static Metric operator *(Metric m, float scale)
 {
     Metric _new = new Metric(m);
     _new.Scale(scale);
     return _new;
 }
Ejemplo n.º 20
0
 public void Setup(bool reset = false)
 {
     //recalculate part and hangar metrics
     part_metric = new Metric(part);
     if(HangarSpace != "")
         hangar_metric = new Metric(part, HangarSpace);
     else hangar_metric = null;
     //if hangar metric is not provided, derive it from part metric
     if(hangar_metric == null || hangar_metric.Empty)
         hangar_metric = part_metric*usefull_volume_ratio;
     //setup vessels pack
     stored_vessels.space = hangar_metric;
     packed_constructs.space = hangar_metric;
     //display recalculated values
     hangar_v  = Utils.formatVolume(hangar_metric.volume);
     hangar_d  = Utils.formatDimensions(hangar_metric.size);
     //now recalculate used volume
     if(reset)
     {   //if resetting, try to repack vessels on resize
         List<PackedConstruct> constructs = packed_constructs.Values;
         packed_constructs.Clear();
         foreach(PackedConstruct pc in constructs)
             try_store_construct(pc);
         //no need to change_part_params as set_params is called later
     }
     //calculate used_volume
     used_volume = 0;
     foreach(StoredVessel sv in stored_vessels.Values) used_volume += sv.volume;
     foreach(PackedConstruct pc in packed_constructs.Values) used_volume += pc.metric.volume;
     //then set other part parameters
     set_part_params(reset);
 }
Ejemplo n.º 21
0
 public bool FitsAligned(Transform this_T, Transform other_T, Metric other)
 {
     Vector3[] edges = BoundsEdges(Vector3.zero, bounds.size);
     foreach(Vector3 edge in edges)
     {
         Vector3 _edge = other_T.InverseTransformPoint(this_T.position+this_T.TransformDirection(edge));
         if(!other.bounds.Contains(_edge)) return false;
     }
     return true;
 }
Ejemplo n.º 22
0
 protected virtual void update_metrics()
 {
     PartMetric = new Metric(part);
     HangarMetric = new Metric(part, HangarSpace);
     //if hangar metric is not provided, derive it from part metric
     if(HangarMetric.Empty) HangarMetric = PartMetric*UsefulSizeRatio;
 }
Ejemplo n.º 23
0
 protected override void update_metrics()
 {
     PartMetric = new Metric(part);
     HangarMetric = new Metric(StorageSize);
 }