Inheritance: Structure, IKOSTargetable
Exemplo n.º 1
0
 public IRServoWrapper(IRWrapper.IServo init, SharedObjects shared)
 {
     servo = init;
     this.shared = shared;
     this.partValue = GetPart();
     InitializeSuffixes();
 }
Exemplo n.º 2
0
        public static PartValue Construct(global::Part part, SharedObjects shared)
        {
            PartValue ret = null;

            for (int i = 0; i < part.Modules.Count; ++i)
            {
                if (part.Modules[i] is MultiModeEngine)
                {
                    return(new EngineValue(part, (MultiModeEngine)part.Modules[i], shared));
                }
                if (part.Modules[i] is ModuleEngines)
                {
                    ret = new EngineValue(part, new ModuleEngineAdapter((ModuleEngines)part.Modules[i]), shared);
                }
                else if (part.Modules[i] is ModuleDockingNode)
                {
                    ret = new DockingPortValue((ModuleDockingNode)part.Modules[i], shared);
                }
                else if (part.Modules[i] is ModuleEnviroSensor)
                {
                    ret = new SensorValue(part, (ModuleEnviroSensor)part.Modules[i], shared);
                }
            }
            if (ret != null)
            {
                return(ret);
            }

            // Fallback if none of the above: then just a normal part:
            return(new PartValue(part, shared));
        }
Exemplo n.º 3
0
Arquivo: Addon.cs Projeto: KSP-KOS/KOS
        private ListValue GetPartServos(PartValue pv)
        {
            var list = new ListValue();

            if (!IRWrapper.APIReady)
            {
                throw new KOSUnavailableAddonException("IR:PARTSERVOS", "Infernal Robotics");
            }

            var controlGroups = IRWrapper.IRController.ServoGroups;

            if (controlGroups == null)
            {
                //Control Groups are somehow null, just return the empty list
                return list;
            }

            foreach (IRWrapper.IControlGroup cg in controlGroups)
            {
                if (cg.Servos == null || (cg.Vessel != null && cg.Vessel != shared.Vessel))
                    continue;

                foreach (IRWrapper.IServo s in cg.Servos)
                {
                    if (s.UID == pv.Part.craftID)
                        list.Add(new IRServoWrapper(s, shared));
                }
            }

            return list;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Do not call! VesselTarget.ConstructPart uses this, would use `friend VesselTarget` if this was C++!
 /// </summary>
 internal PartValue(SharedObjects shared, global::Part part, PartValue parent, DecouplerValue decoupler)
 {
     Shared    = shared;
     Part      = part;
     Parent    = parent;
     Decoupler = decoupler;
     RegisterInitializer(PartInitializeSuffixes);
     Children = new ListValue <PartValue>();
 }
Exemplo n.º 5
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 (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);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Do not call! VesselTarget.ConstructPart uses this, would use `friend VesselTarget` if this was C++!
 /// </summary>
 internal DecouplerValue(SharedObjects shared, global::Part part, PartValue parent, DecouplerValue decoupler)
     : base(shared, part, parent, decoupler)
 {
 }
Exemplo n.º 7
0
 protected bool Equals(PartValue other)
 {
     return(Equals(Part, other.Part));
 }
Exemplo n.º 8
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);
 }
Exemplo n.º 9
0
 protected bool Equals(PartValue other)
 {
     return Equals(Part, other.Part);
 }
Exemplo n.º 10
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);
 }
Exemplo n.º 11
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);
 }