Esempio n. 1
0
        public ScienceDataValue(ScienceData scienceData, global::Part hostPart)
        {
            this.scienceData = scienceData;
            this.hostPart = hostPart;

            InitializeSuffixes();
        }
Esempio n. 2
0
        public PartValue(global::Part part, SharedObjects sharedObj)
        {
            Part = part;
            Shared = sharedObj;

            // This cannot be called from inside InitializeSuffixes because the base constructor calls
            // InitializeSuffixes first before this constructor has set "Part" to a real value.
            PartInitializeSuffixes();
        }
Esempio n. 3
0
        public ScienceExperimentFields(PartModule module, SharedObjects shared)
            : base(module, shared)
        {
            this.container = module as IScienceDataContainer;
            part = module.part;

            if (container == null)
            {
                throw new KOSException("This module is not a science data container");
            }

            InitializeSuffixes();
        }
Esempio n. 4
0
 /// <summary>
 /// Returns true if this docking port points towards the given part
 /// </summary>
 bool PointsTowards(global::Part otherPart)
 {
     return(Vector3d.Dot(port.nodeTransform.forward, otherPart.transform.position - port.transform.position) > 0);
 }
Esempio n. 5
0
 public EngineValue(global::Part part, IModuleEngine engine, SharedObjects sharedObj)
     : base(part, sharedObj)
 {
     this.engine = engine;
     EngineInitializeSuffixes();
 }
Esempio n. 6
0
 public PartValue(global::Part part, SharedObjects sharedObj)
 {
     Part   = part;
     shared = sharedObj;
 }
Esempio n. 7
0
 public SensorValue(global::Part part, ModuleEnviroSensor sensor, SharedObjects sharedObj) : base(part, sharedObj)
 {
     this.sensor = sensor;
 }
Esempio n. 8
0
 /// <summary>
 /// Do not call! VesselTarget.ConstructPart uses this, would use `friend VesselTarget` if this was C++!
 /// </summary>
 internal RCSValue(SharedObjects shared, global::Part part, PartValue parent, DecouplerValue decoupler, ModuleRCS module)
     : base(shared, part, parent, decoupler)
 {
     this.module = module;
     RegisterInitializer(RCSInitializeSuffixes);
 }
Esempio n. 9
0
        private static void EnqueueChildren(Queue <ElementPair> queue, ElementValue element, global::Part part)
        {
            if (!part.children.Any())
            {
                return;
            }

            foreach (var child in part.children)
            {
                queue.Enqueue(new ElementPair(element, child));
            }
        }
Esempio n. 10
0
 internal static bool Is (global::Part part)
 {
     return part.HasModule<ModuleRCS> ();
 }
Esempio n. 11
0
 public static PartValue Construct(global::Part part, SharedObjects shared)
 {
     return(VesselTarget.CreateOrGetExisting(part.vessel, shared)[part]);
 }
Esempio n. 12
0
 public EngineValue(global::Part part, ModuleEngines engine) : base(part)
 {
     this.engine = engine;
 }
Esempio n. 13
0
 public EngineValue(global::Part part, ModuleEnginesFX enginefFx) : base(part)
 {
     this.enginefFx = enginefFx;
 }
Esempio n. 14
0
 /// <summary>
 /// Do not call! VesselTarget.ConstructPart uses this, would use `friend VesselTarget` if this was C++!
 /// </summary>
 internal LaunchClampValue(SharedObjects shared, global::Part part, PartValue parent, DecouplerValue decoupler)
     : base(shared, part, parent, decoupler)
 {
 }
Esempio n. 15
0
 public ElementPair(ElementValue element, global::Part part) : this()
 {
     Element = element;
     Part = part;
 }
Esempio n. 16
0
 public SensorValue(global::Part part, ModuleEnviroSensor sensor, SharedObjects sharedObj) : base(part, sharedObj)
 {
     this.sensor = sensor;
     SensorInitializeSuffixes();
 }
Esempio n. 17
0
 /// <summary>
 /// Do not call! VesselTarget.ConstructPart uses this, would use `friend VesselTarget` if this was C++!
 /// </summary>
 internal SensorValue(SharedObjects shared, global::Part part, PartValue parent, DecouplerValue decoupler, ModuleEnviroSensor sensor) :
     base(shared, part, parent, decoupler)
 {
     this.sensor = sensor;
     RegisterInitializer(SensorInitializeSuffixes);
 }
Esempio n. 18
0
        /// <summary>
        /// Do not call! VesselTarget.ConstructPart uses this, would use `friend VesselTarget` if this was C++!
        /// </summary>
        internal EngineValue(SharedObjects shared, global::Part part, PartValue parent, DecouplerValue decoupler)
            : base(shared, part, parent, decoupler)
        {
            foreach (var module in part.Modules)
            {
                var mme = module as MultiModeEngine;
                var e   = module as ModuleEngines;
                if (mme != null)
                {
                    if (Multi == null)
                    {
                        Multi = mme;
                    }
                    else
                    {
                        SafeHouse.Logger.LogWarning("Multiple MultiModeEngine on {0}: {1}", part.name, part.partInfo.title);
                    }
                }
                else if (e != null)
                {
                    if (Engine1 == null)
                    {
                        Engine1 = e;
                    }
                    else if (Engine2 == null)
                    {
                        Engine2 = e;
                    }
                    else
                    {
                        SafeHouse.Logger.LogWarning("Third engine on {0}: {1}", part.name, part.partInfo.title);
                    }
                }
            }
            if (Engine1 == null)
            {
                throw new KOSException("Attempted to build an Engine from part with no ModuleEngines on {0}: {1}", part.name, part.partInfo.title);
            }
            if (Engine2 == null)
            {
                if (Multi != null)
                {
                    SafeHouse.Logger.LogWarning("MultiModeEngine without second engine on {0}: {1}", part.name, part.partInfo.title);
                }
            }
            else
            {
                if (Multi == null)
                {
                    Engine2 = null;
                    SafeHouse.Logger.LogWarning("Second engine without multi-mode on {0}: {1}", part.name, part.partInfo.title);
                }
                else
                {
                    if (Multi.primaryEngineID == Engine2.engineID)
                    {
                        var tmp = Engine1;
                        Engine1 = Engine2;
                        Engine2 = tmp;
                    }
                    else if (Multi.primaryEngineID != Engine1.engineID)
                    {
                        SafeHouse.Logger.LogWarning("Primary engine ID={0} does not match multi.e1={1} on {2}: {3}",
                                                    Engine1.engineID, Multi.primaryEngineID, part.name, part.partInfo.title);
                    }
                    if (Multi.secondaryEngineID != Engine2.engineID)
                    {
                        SafeHouse.Logger.LogWarning("Secondary engine ID={0} does not match multi.e2={1} on {2}: {3}",
                                                    Engine2.engineID, Multi.secondaryEngineID, part.name, part.partInfo.title);
                    }
                }
            }

            // if the part definition includes a ModuleGimbal, create GimbalFields and set HasGimbal to true
            var gimbalModule = Part.Modules.GetModules <ModuleGimbal>().FirstOrDefault();

            if (gimbalModule != null)
            {
                Gimbal = new GimbalFields(gimbalModule, Shared);
            }

            RegisterInitializer(InitializeSuffixes);
        }
Esempio n. 19
0
 internal Propellant(global::Propellant propellantResource, global::Part underlyingPart)
 {
     resourceId = propellantResource.id;
     partId     = underlyingPart.flightID;
 }
Esempio n. 20
0
 internal static bool Is(global::Part part)
 {
     return(part.HasModule <ModuleEngines> ());
 }
Esempio n. 21
0
 internal static bool Is(global::Part part)
 {
     return(part.HasModule <ModuleReactionWheel> ());
 }
Esempio n. 22
0
 public void AddPart(global::Part part)
 {
     parts.Add(part);
 }
Esempio n. 23
0
 public ElementPair(ElementValue element, global::Part part) : this()
 {
     Element = element;
     Part    = part;
 }
Esempio n. 24
0
        /// <summary>
        /// Do not call! VesselTarget.ConstructPart uses this, would use `friend VesselTarget` if this was C++!
        /// </summary>
        internal EngineValue(SharedObjects shared, global::Part part, PartValue parent, DecouplerValue decoupler)
            : base(shared, part, parent, decoupler)
        {
            RawEngineList = new List <ModuleEngines>();
            foreach (var module in part.Modules)
            {
                var mme = module as MultiModeEngine;
                var e   = module as ModuleEngines;
                if (mme != null)
                {
                    if (Multi == null)
                    {
                        Multi = mme;
                    }
                    else
                    {
                        SafeHouse.Logger.LogWarning("Multiple MultiModeEngine on {0}: {1}", part.name, part.partInfo.title);
                    }
                }
                else if (e != null)
                {
                    RawEngineList.Add(e);
                }

                if (e != null)
                {
                    HasRealFuels = false;
                    for (System.Type t = module.GetType(); t != null; t = t.BaseType)
                    {
                        if (t.Name.Contains("ModuleEnginesRF"))
                        {
                            HasRealFuels = true;
                            break;
                        }
                    }
                }

                if (module.GetType().Name.Contains("ModuleEngineConfigs"))
                {
                    EngineConfig = module;
                }
            }
            if (RawEngineList.Count < 1)
            {
                throw new KOSException("Attempted to build an Engine from part with no ModuleEngines on {0}: {1}", part.name, part.partInfo.title);
            }
            if (RawEngineList.Count < 2)
            {
                if (Multi != null)
                {
                    SafeHouse.Logger.LogWarning("MultiModeEngine without second engine on {0}: {1}", part.name, part.partInfo.title);
                }
            }
            else
            {
                if (Multi != null)
                {
                    if (Multi.primaryEngineID == RawEngineList[1].engineID)
                    {
                        RawEngineList.Reverse();
                    }
                    else if (Multi.primaryEngineID != RawEngineList[0].engineID)
                    {
                        SafeHouse.Logger.LogWarning("Primary engine ID={0} does not match multi.e1={1} on {2}: {3}",
                                                    RawEngineList[0].engineID, Multi.primaryEngineID, part.name, part.partInfo.title);
                    }
                    if (Multi.secondaryEngineID != RawEngineList[1].engineID)
                    {
                        SafeHouse.Logger.LogWarning("Secondary engine ID={0} does not match multi.e2={1} on {2}: {3}",
                                                    RawEngineList[1].engineID, Multi.secondaryEngineID, part.name, part.partInfo.title);
                    }
                }
            }

            // if the part definition includes a ModuleGimbal, create GimbalFields and set HasGimbal to true
            var gimbalModule = Part.Modules.GetModules <ModuleGimbal>().FirstOrDefault();

            if (gimbalModule != null)
            {
                Gimbal = new GimbalFields(gimbalModule, Shared);
            }

            RegisterInitializer(InitializeSuffixes);
        }
Esempio n. 25
0
 internal static bool Is(global::Part part)
 {
     return(part.HasModule <ModuleControlSurface> ());
 }
Esempio n. 26
0
 public PartValue(global::Part part)
 {
     Part = part;
 }
Esempio n. 27
0
 /// <summary>
 /// Do not call! VesselTarget.ConstructPart uses this, would use `friend VesselTarget` if this was C++!
 /// </summary>
 internal DockingPortValue(SharedObjects shared, global::Part part, PartValue parent, DecouplerValue decoupler, ModuleDockingNode module)
     : base(shared, part, parent, decoupler)
 {
     this.module = module;
     RegisterInitializer(DockingInitializeSuffixes);
 }
Esempio n. 28
0
        private void ConstructPart(global::Part part, PartValue parent, DecouplerValue decoupler)
        {
            if (part.State == PartStates.DEAD || part.transform == null)
            {
                return;
            }

            // Modules can be in any order, so to enforce some sort of priority for parts which are multiple types,
            // gather all potential modules and then select from those valid.
            IEngineStatus      engine    = null;
            ModuleRCS          rcs       = null;
            PartValue          separator = null;
            ModuleEnviroSensor sensor    = null;

            foreach (var module in part.Modules)
            {
                if (module is IEngineStatus)
                {
                    engine = module as IEngineStatus;
                }
                else if (module is ModuleRCS)
                {
                    rcs = module as ModuleRCS;
                }
                else if (module is IStageSeparator)
                {
                    var dock = module as ModuleDockingNode;
                    if (dock != null)
                    {
                        var port = new DockingPortValue(Shared, part, parent, decoupler, dock);
                        separator = port;
                        dockingPorts.Add(port);
                        if (!module.StagingEnabled())
                        {
                            continue;
                        }
                        decoupler = port;
                        decouplers.Add(decoupler);
                    }
                    // ignore anything with staging disabled and continue the search
                    // this can e.g. be heat shield or some sensor with integrated decoupler
                    else
                    {
                        if (!module.StagingEnabled())
                        {
                            continue;
                        }
                        if (module is LaunchClamp)
                        {
                            separator = decoupler = new LaunchClampValue(Shared, part, parent, decoupler);
                        }
                        else if (module is ModuleDecouple || module is ModuleAnchoredDecoupler)
                        {
                            separator = decoupler = new DecouplerValue(Shared, part, parent, decoupler);
                        }
                        else // ModuleServiceModule ?
                        {
                            continue; // rather continue the search
                        }
                        decouplers.Add(decoupler);
                    }
                    // ignore leftover decouplers
                    if (decoupler == null || decoupler.Part.inverseStage >= StageManager.CurrentStage)
                    {
                        continue;
                    }
                    // check if we just created closer decoupler (see StageValues.CreatePartSet)
                    if (nextDecoupler == null || decoupler.Part.inverseStage > nextDecoupler.Part.inverseStage)
                    {
                        nextDecoupler = decoupler;
                    }
                }
                else if (module is ModuleEnviroSensor)
                {
                    sensor = module as ModuleEnviroSensor;
                }
            }

            // Select part value in priority order
            PartValue self;

            if (engine != null)
            {
                self = new EngineValue(Shared, part, parent, decoupler);
            }
            else if (rcs != null)
            {
                self = new RCSValue(Shared, part, parent, decoupler, rcs);
            }
            else if (separator != null)
            {
                self = separator;
            }
            else if (sensor != null)
            {
                self = new SensorValue(Shared, part, parent, decoupler, sensor);
            }
            else
            {
                self = new PartValue(Shared, part, parent, decoupler);
            }

            if (rootPart == null)
            {
                rootPart = self;
            }
            partCache[part] = self;
            allParts.Add(self);
            foreach (var child in part.children)
            {
                ConstructPart(child, self, decoupler);
            }
            self.Children.IsReadOnly = true;
        }