예제 #1
0
파일: VOID_Data.cs 프로젝트: toadicus/VOID
        private static void thrustOffSetPerModule(object sender, VOIDForEachPartModuleArgs args)
        {
            PartModule module = args.Data;

            float moduleThrust = 0;

            switch (module.moduleName)
            {
            case "ModuleEngines":
            case "ModuleEnginesFX":
                break;

            default:
                return;
            }

            if (!module.isEnabled)
            {
                return;
            }

            CenterOfThrustQuery cotQuery = new CenterOfThrustQuery();

            if (module is ModuleEngines)
            {
                ModuleEngines engineModule = module as ModuleEngines;

                moduleThrust = engineModule.finalThrust;

                engineModule.OnCenterOfThrustQuery(cotQuery);
            }
            else             // engine is ModuleEnginesFX
            {
                ModuleEnginesFX engineFXModule = module as ModuleEnginesFX;

                moduleThrust = engineFXModule.finalThrust;

                engineFXModule.OnCenterOfThrustQuery(cotQuery);
            }

            if (moduleThrust != 0d)
            {
                cotQuery.thrust = moduleThrust;
            }

            thrustPos += cotQuery.pos * cotQuery.thrust;
            thrustDir += cotQuery.dir * cotQuery.thrust;
            thrust    += cotQuery.thrust;
        }
예제 #2
0
파일: VOID_Data.cs 프로젝트: toadicus/VOID
        private static void intakeAirForEachModule(object sender, VOIDForEachPartModuleArgs args)
        {
            PartModule        module         = args.Data;
            List <Propellant> propellantList = null;

            if (!module.part.enabled)
            {
                return;
            }

            if (module is ModuleEngines)
            {
                propellantList = ((ModuleEngines)module).propellants;
            }
            else if (module is ModuleEnginesFX)
            {
                propellantList = ((ModuleEnginesFX)module).propellants;
            }
            else if (module is ModuleResourceIntake)
            {
                ModuleResourceIntake intakeModule = (ModuleResourceIntake)module;

                if (intakeModule.resourceName == "IntakeAir")
                {
                    airFlowCurrent += intakeModule.airFlow;
                }
            }

            if (propellantList != null)
            {
                Propellant propellant;
                for (int propIdx = 0; propIdx < propellantList.Count; propIdx++)
                {
                    propellant = propellantList[propIdx];

                    if (propellant.name == "IntakeAir")
                    {
                        airFlowRequired += propellant.currentRequirement / TimeWarp.fixedDeltaTime;
                        break;
                    }
                }
            }
        }
예제 #3
0
        public virtual void Update()
        {
            this.LoadBeforeUpdate();

            if (
                this.vesselSimActive &&
                (
                    this.Vessel != null ||
                    (
                        HighLogic.LoadedSceneIsEditor &&
                        EditorLogic.RootPart != null &&
                        EditorLogic.SortedShipList.Count > 0
                    )
                )
                )
            {
                Logging.PostDebugMessage(this, "Updating SimManager.");
                this.UpdateSimManager();

                VOIDForEachPartArgs       partArgs;
                VOIDForEachPartModuleArgs moduleArgs;

                Part       part;
                PartModule partModule;

                bool doForEachPart   = this.onForEachPart != null;
                bool doForEachModule = this.onForEachModule != null;

                if (
                    (doForEachPart || doForEachModule) &&
                    (this.Vessel != null) &&
                    (this.Vessel.parts != null) &&
                    this.timeToUpdate
                    )
                {
                    if (this.onPreForEach != null)
                    {
                        this.onPreForEach(this);
                    }

                    for (int pIdx = 0; pIdx < this.Vessel.parts.Count; pIdx++)
                    {
                        part     = this.Vessel.parts[pIdx];
                        partArgs = new VOIDForEachPartArgs(part);

                        if (doForEachPart)
                        {
                            this.onForEachPart(this, partArgs);
                        }

                        if (doForEachModule && part.Modules != null)
                        {
                            for (int mIdx = 0; mIdx < part.Modules.Count; mIdx++)
                            {
                                partModule = part.Modules[mIdx];
                                moduleArgs = new VOIDForEachPartModuleArgs(partModule);

                                if (doForEachModule)
                                {
                                    this.onForEachModule(this, moduleArgs);
                                }
                            }
                        }
                    }

                    if (this.onPostForEach != null)
                    {
                        this.onPostForEach(this);
                    }
                }
            }

            if (!this.GUIRunning && !this.gameUIHidden)
            {
                this.StartGUI();
            }

            IVOID_Module module;

            for (int idx = 0; idx < this.modules.Count; idx++)
            {
                module = this.modules[idx];

                if (
                    !module.GUIRunning &&
                    module.Active &&
                    module.InValidScene &&
                    (
                        !HighLogic.LoadedSceneIsEditor ||
                        (EditorLogic.RootPart != null && EditorLogic.SortedShipList.Count > 0)
                    )
                    )
                {
                    module.StartGUI();
                }
                if (
                    module.GUIRunning &&
                    (
                        !module.Active ||
                        !this.togglePower ||
                        !module.InValidScene ||
                        this.FactoryReset ||
                        (
                            HighLogic.LoadedSceneIsEditor &&
                            (EditorLogic.RootPart == null || EditorLogic.SortedShipList.Count == 0)
                        )
                    )
                    )
                {
                    module.StopGUI();
                }

                if (module is IVOID_BehaviorModule)
                {
                    ((IVOID_BehaviorModule)module).Update();
                }
            }

            if (ToolbarManager.ToolbarAvailable && this.useToolbarManager)
            {
                if (this.ToolbarButton == null)
                {
                    this.ToolbarButton      = ToolbarManager.Instance.add(this.VoidName, "coreToggle");
                    this.ToolbarButton.Text = this.VoidName;
                    this.SetIconTexture(this.powerState | this.activeState);

                    this.ToolbarButton.Visible = true;

                    this.ToolbarButton.OnClick +=
                        (e) =>
                    {
                        this.ToggleMainWindow();
                    };

                    Logging.PostDebugMessage(string.Format("{0}: Toolbar Button initialized.", this.GetType().Name));
                }

                if (this.AppLauncherButton != null)
                {
                    ApplicationLauncher.Instance.RemoveModApplication(this.AppLauncherButton);
                    this.AppLauncherButton = null;
                }
            }
            else
            {
                if (this.AppLauncherButton == null)
                {
                    if (ApplicationLauncher.Instance != null)
                    {
                        this.AppLauncherButton = ApplicationLauncher.Instance.AddModApplication(
                            this.ToggleMainWindow, this.ToggleMainWindow,
                            this.appIconVisibleScenes,
                            this.VOIDIconTexture
                            );

                        Logging.PostDebugMessage(
                            this,
                            "AppLauncherButton initialized in {0}",
                            Enum.GetName(
                                typeof(GameScenes),
                                HighLogic.LoadedScene
                                )
                            );
                    }
                }

                if (this.ToolbarButton != null)
                {
                    this.ToolbarButton.Destroy();
                    this.ToolbarButton = null;
                }
            }

            if (this.onUpdate != null)
            {
                this.onUpdate(this);
            }

            this.saveTimer += Time.deltaTime;

            if (this.modulesLoaded && this.saveTimer > 2f)
            {
                if (this.configDirty)
                {
                    Logging.PostDebugMessage(string.Format(
                                                 "{0}: Time to save, checking if configDirty: {1}",
                                                 this.GetType().Name,
                                                 this.configDirty
                                                 ));

                    this.SaveConfig();
                    this.saveTimer = 0;
                }
            }

            this.UpdateTimer += Time.deltaTime;
        }
예제 #4
0
        public virtual void Update()
        {
            this.LoadBeforeUpdate();

            if (
                this.vesselSimActive &&
                (
                    this.Vessel != null ||
                    (
                        HighLogic.LoadedSceneIsEditor &&
                        EditorLogic.RootPart != null &&
                        EditorLogic.SortedShipList.Count > 0
                    )
                )
                )
            {
                Logging.PostDebugMessage(this, "Updating SimManager.");
                this.UpdateSimManager();

                VOIDForEachPartArgs       partArgs;
                VOIDForEachPartModuleArgs moduleArgs;

                Part       part;
                PartModule partModule;

                bool doForEachPart   = this.onForEachPart != null;
                bool doForEachModule = this.onForEachModule != null;

                if (
                    (doForEachPart || doForEachModule) &&
                    (this.Vessel != null) &&
                    (this.Vessel.parts != null) &&
                    this.timeToUpdate
                    )
                {
                    if (this.onPreForEach != null)
                    {
                        this.onPreForEach(this);
                    }

                    for (int pIdx = 0; pIdx < this.Vessel.parts.Count; pIdx++)
                    {
                        part     = this.Vessel.parts[pIdx];
                        partArgs = new VOIDForEachPartArgs(part);

                        if (doForEachPart)
                        {
                            this.onForEachPart(this, partArgs);
                        }

                        if (doForEachModule && part.Modules != null)
                        {
                            for (int mIdx = 0; mIdx < part.Modules.Count; mIdx++)
                            {
                                partModule = part.Modules[mIdx];
                                moduleArgs = new VOIDForEachPartModuleArgs(partModule);

                                if (doForEachModule)
                                {
                                    this.onForEachModule(this, moduleArgs);
                                }
                            }
                        }
                    }

                    if (this.onPostForEach != null)
                    {
                        this.onPostForEach(this);
                    }
                }
            }

            if (!this.GUIRunning && !this.gameUIHidden)
            {
                this.StartGUI();
            }

            IVOID_Module module;

            for (int idx = 0; idx < this.modules.Count; idx++)
            {
                module = this.modules[idx];

                if (
                    !module.GUIRunning &&
                    module.Active &&
                    module.InValidScene &&
                    (
                        !HighLogic.LoadedSceneIsEditor ||
                        (EditorLogic.RootPart != null && EditorLogic.SortedShipList.Count > 0)
                    )
                    )
                {
                    module.StartGUI();
                }
                if (
                    module.GUIRunning &&
                    (
                        !module.Active ||
                        !this.togglePower ||
                        !module.InValidScene ||
                        this.FactoryReset ||
                        (
                            HighLogic.LoadedSceneIsEditor &&
                            (EditorLogic.RootPart == null || EditorLogic.SortedShipList.Count == 0)
                        )
                    )
                    )
                {
                    module.StopGUI();
                }

                if (module is IVOID_BehaviorModule)
                {
                    ((IVOID_BehaviorModule)module).Update();
                }
            }

            if (toolbarControl == null)
            {
                toolbarControl = ThisGameObject.thisGameObject.AddComponent <ToolbarControl>();
                toolbarControl.AddToAllToolbars(this.ToggleMainWindow, this.ToggleMainWindow,
                                                this.appIconVisibleScenes,
                                                MODID,
                                                "voidButton",
                                                "",
                                                "",
                                                MODNAME
                                                );
            }
            this.SetIconTexture(this.powerState | this.activeState);
            if (this.onUpdate != null)
            {
                this.onUpdate(this);
            }

            this.saveTimer += Time.deltaTime;

            if (this.modulesLoaded && this.saveTimer > 2f)
            {
                if (this.configDirty)
                {
                    Logging.PostDebugMessage(string.Format(
                                                 "{0}: Time to save, checking if configDirty: {1}",
                                                 this.GetType().Name,
                                                 this.configDirty
                                                 ));

                    this.SaveConfig();
                    this.saveTimer = 0;
                }
            }

            this.UpdateTimer += Time.deltaTime;
        }