Ejemplo n.º 1
0
        //删除存储区域的模块列表
        public bool DelModuleList(ModuleCommand module)
        {
            bool             flag     = false;
            List <ATCommand> tempList = XMLUnitRead();
            List <ATCommand> fullList = new List <ATCommand>();

            foreach (ATCommand _module in tempList)
            {
                if (_module.Function != module.Function || _module.Module != module.Module)
                {
                    fullList.Add(_module);
                }
            }
            if (fullList.Count == 0 && File.Exists(filePath))
            {
                File.Delete(filePath);
                return(true);
            }
            XmlSerializer serializer = new XmlSerializer(typeof(List <ATCommand>));

            using (FileStream fs = new FileStream(filePath, FileMode.Create))
            {
                serializer.Serialize(fs, fullList);
            }

            return(flag);
        }
Ejemplo n.º 2
0
 private List <ATCommand> MoreList(List <ATCommand> fullList)
 {
     if (File.Exists(filePath))
     {
         Application.DoEvents();
         ModuleCommand    mc          = fullList[0];
         List <ATCommand> tempList    = XMLUnitRead();
         List <ATCommand> deltempList = new List <ATCommand>();
         foreach (ATCommand temp in tempList)
         {
             if (temp.Module == mc.Module && temp.Function == mc.Function)
             {
                 deltempList.Add(temp);
             }
         }
         if (deltempList.Count > 0)
         {
             foreach (ATCommand TEMP in deltempList)
             {
                 tempList.Remove(TEMP);
             }
         }
         foreach (ATCommand TEMP in fullList)
         {
             tempList.Add(TEMP);
         }
         return(tempList);
     }
     return(fullList);
 }
Ejemplo n.º 3
0
        public override void OnStart(StartState state)
        {
            // parent OnStart
            base.OnStart(state);

            module = Utils.getModuleByType<ModuleCommand>(base.part);
        }
Ejemplo n.º 4
0
 private void AddFunctionRB(ModuleCommand module, List <ModuleCommand> moduleList)
 {
     if (module.Function != "")
     {
         int step = 0;
         for (int i = 0; i < moduleList.Count; i++)
         {
             if (moduleList[i].Module.Equals(module.Module))
             {
                 if (moduleList[i].Function != null)
                 {
                     RadioButton rb = IRadioButton("rbf", moduleList[i].Function, step);
                     rb.MouseClick += Rb_MouseClick;
                     if (!moduleList[i].Function.Equals(""))
                     {
                         panel2.Controls.Add(rb);
                         step++;
                     }
                 }
             }
         }
         RadioButton checkRB = panel2.Controls.Find("rbf" + module.Function, true)[0] as RadioButton;
         checkRB.Checked     = true;
         functionCheckedText = checkRB.Text;
     }
 }
Ejemplo n.º 5
0
        public override void OnFixedUpdate()
        {
            base.OnFixedUpdate();

            if (this.part.parent == parentPart)
            {
                return;
            }
            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return;
            }
            if (this.part.parent == null)
            {
                return;
            }

            ModuleCommand cmd = this.part.parent.FindModuleImplementing <ModuleCommand>();
            bool          attachedToRechargePart = this.part.parent.CrewCapacity > 0 && cmd != null;

            Events["RefuelEVA"].guiActive          = attachedToRechargePart;
            Events["RefuelEVA"].guiActiveUnfocused = attachedToRechargePart;

            parentPart = this.part.parent;
        }
Ejemplo n.º 6
0
        public void GetPartModules()
        {
            commandModule = this.part.FindModuleImplementing <ModuleCommand>();
            if (commandModule != null)
            {
                foreach (BaseEvent cmdEvent in commandModule.Events)
                {
                    cmdEvent.guiActive          = false;
                    cmdEvent.guiActiveUnfocused = false;
                }
            }

            switcher = this.part.FindModuleImplementing <WBIResourceSwitcher>();
            if (switcher != null)
            {
                switcher.Events["ToggleDecals"].guiActive          = false;
                switcher.Events["ToggleDecals"].guiActiveUnfocused = false;
            }

            lightModule = this.part.FindModuleImplementing <WBILight>();
            if (lightModule != null)
            {
                lightModule.showGui(false);
            }
        }
        public override void OnStart(StartState state)
        {
            if (HighLogic.LoadedScene != GameScenes.FLIGHT)
            {
                return;
            }

            Events["ToggleFlightMarkers"].guiName = FlightMarkers.LocalStrings[FlightMarkers.Strings.FlightMarkersOn];
            Events["ToggleCombineLift"].guiName   = FlightMarkers.LocalStrings[FlightMarkers.Strings.CombineLiftOn];

            // ControlFromWhere
            ModuleCommand commandModule = part.FindModuleImplementing <ModuleCommand>();

            if (commandModule != null)
            {
                BaseEvent toggleEvent = commandModule.Events["ToggleControlPointVisual"];
                if (toggleEvent != null)
                {
                    toggleEvent.active          = true;
                    toggleEvent.guiActive       = true;
                    toggleEvent.guiActiveEditor = true;
                }
                else
                {
                    Debug.LogError("[FlightMarkers] ERROR: ToggleControlPointVisual not found");
                }
            }
        }
Ejemplo n.º 8
0
        public void GetPartModules()
        {
            BaseEvent cmdEvent;
            int       totalEvents;

            commandModule = this.part.FindModuleImplementing <ModuleCommand>();
            if (commandModule != null)
            {
                totalEvents = commandModule.Events.Count;
                for (int index = 0; index < totalEvents; index++)
                {
                    cmdEvent                    = commandModule.Events.GetByIndex(index);
                    cmdEvent.guiActive          = false;
                    cmdEvent.guiActiveUnfocused = false;
                }
            }

            switcher = this.part.FindModuleImplementing <WBIResourceSwitcher>();
            if (switcher != null)
            {
                switcher.Events["ToggleDecals"].guiActive           = false;
                switcher.Events["ToggleDecals"].guiActiveUnfocused  = false;
                switcher.Events["DumpResources"].guiActive          = false;
                switcher.Events["DumpResources"].guiActiveUnfocused = false;
            }

            lightModule = this.part.FindModuleImplementing <WBILight>();

            qualityControl = this.part.FindModuleImplementing <BaseQualityControl>();
        }
Ejemplo n.º 9
0
        protected double ResourceRate()
        {
            ModuleCommand mC = part.FindModuleImplementing <ModuleCommand>();

            if (mC != null)
            {
                foreach (ModuleResource r in mC.resHandler.inputResources)
                {
                    if (r.id == PartResourceLibrary.ElectricityHashcode)
                    {
                        commandChargeResource = r;
                        if (GetEnabledkW() < 0)
                        {
                            enabledkW = (float)r.rate;
                        }
                        else
                        {
                            r.rate = GetEnabledkW();
                        }
                        return(r.rate);
                    }
                }
            }
            return(-1);
        }
Ejemplo n.º 10
0
        public void AddCommandsGeneral_Test()
        {
            var server = EnvironmentGlobal.CreateGameServer("CommandsTests");

            var gameSession = EnvironmentGlobal.GetSession(server);

            var spaceship = gameSession.GetPlayerSpaceShip();

            var module = spaceship.GetPropulsionModules().First();

            server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Braking));

            Assert.AreEqual(1, server.Commands.Count);

            server.TurnCalculation(1);

            server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Braking));

            Assert.AreEqual(0, server.Commands.Count);

            server.TurnCalculation(5);

            Assert.AreEqual(0, server.Commands.Count);

            server.TurnCalculation(1);
            server.Wait(5);

            server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Braking));

            Assert.AreEqual(1, server.Commands.Count);

            server.TurnCalculation(1);
        }
Ejemplo n.º 11
0
		void Process_command(ModuleCommand command)
		{
			foreach (ModuleResource res in command.resHandler.inputResources)
			{
				Resource(res.name).Consume(res.rate, "command");
			}
		}
Ejemplo n.º 12
0
        protected IEnumerator CheckRenameDebris()
        {
            bool rename = true;

            yield return(new WaitForSeconds(1f));

            if (vessel != FlightGlobals.ActiveVessel)
            {
                foreach (Part p in vessel.Parts)
                {
                    ModuleAvionics avionics = p.FindModuleImplementing <ModuleAvionics>();
                    ModuleCommand  command  = p.FindModuleImplementing <ModuleCommand>();
                    bool           debris   = avionics?.setToDebrisOnStage ?? true;
                    if (command && !debris)
                    {
                        rename = false;
                        break;
                    }
                }

                if (rename)
                {
                    vessel.vesselType = VesselType.Debris;
                }
            }
        }
Ejemplo n.º 13
0
        public void Reloading_MicroWarpDrive_Test()
        {
            var server = EnvironmentGlobal.CreateGameServer("Reloading");

            var gameSession = EnvironmentGlobal.GetSession(server);

            var spaceship = gameSession.GetPlayerSpaceShip();

            var module = spaceship.GetPropulsionModules().First();

            Assert.AreEqual(2.0f, module.Reloading);

            server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Braking));

            Assert.AreEqual(1, server.Commands.Count);

            Assert.AreEqual(7, gameSession.GetCelestialObject(spaceship.Id).Speed);

            server.TurnCalculation(1);

            gameSession = EnvironmentGlobal.GetSession(server);

            spaceship = gameSession.GetPlayerSpaceShip();

            module = spaceship.GetPropulsionModules().First();

            Assert.AreEqual(0.05, module.Reloading);

            server.TurnCalculation(5);

            module = EnvironmentGlobal.GetSessionServerSide(server).GetPlayerSpaceShip().GetPropulsionModules().First();

            Assert.AreEqual(0.3, module.Reloading);
        }
Ejemplo n.º 14
0
        //添加模块/功能列表界面的按钮点击事件
        private void Form2Btn_Click(object sender, EventArgs e)
        {
            Button        btn      = sender as Button;
            TextBox       tbox     = btn.FindForm().Controls.Find("textBox1", true)[0] as TextBox;
            string        tboxText = tbox.Text.Trim();
            ModuleCommand MC       = new ModuleCommand();

            //添加模块界面保存
            if (btn.Name.Equals("button1") && moduleAddFlag)
            {
                if (!tboxText.Equals(""))
                {
                    MC.Module = tboxText;
                    foreach (ModuleCommand temp in _moduleList)
                    {
                        if (temp.Module.ToUpper().Equals(MC.Module.ToUpper()))
                        {
                            MessageBox.Show("模块" + MC.Module + "已存在.", "警告!!!", MessageBoxButtons.OK);
                            return;
                        }
                    }
                    _moduleList.Add(MC);
                    AddModuleRB(_moduleList, _moduleList.Count - 1);
                }
                btn.FindForm().Close();
            }
            //添加功能界面保存
            if (btn.Name.Equals("button1") && !moduleAddFlag)
            {
                if (!tboxText.Equals(""))
                {
                    MC.Module   = _moduleList[checkedNum].Module;
                    MC.Function = tboxText;

                    if (_moduleList[checkedNum].Function == null)
                    {
                        _moduleList[checkedNum].Function = tboxText;
                    }
                    else
                    {
                        foreach (ModuleCommand temp in _moduleList)
                        {
                            if (temp.Module.ToUpper().Equals(MC.Module.ToUpper()) && temp.Function.ToUpper().Equals(MC.Function.ToUpper()))
                            {
                                MessageBox.Show("模块" + MC.Module + "下的功能" + MC.Function + "已存在.", "警告!!!", MessageBoxButtons.OK);
                                return;
                            }
                        }
                        _moduleList.Add(MC);
                    }
                    AddModuleRB(_moduleList, _moduleList.Count - 1);
                }
                btn.FindForm().Close();
            }
            if (btn.Name.Equals("button2"))
            {
                btn.FindForm().Close();
            }
        }
Ejemplo n.º 15
0
        private void ButtonRead_Click(object sender, EventArgs e)
        {
            ModuleCommand module  = new ModuleCommand(moduleCheckedText, functionCheckedText);
            XMLUnit       xmlUnit = new XMLUnit();

            atCommands = xmlUnit.XMLUnitRead(module);
            this.Close();
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 树形加载模块
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public IHttpActionResult TreeList(ModuleCommand command)
        {
            var dxClientId = (int)DxClient.Administrator;
            var menus      = _dxModuleService.FindMenusByClientId(dxClientId.ToString()).Select(x => x.ToJsonModel()).ToList();
            var json       = menus.BuildTreeMenu();

            return(Ok(json));
        }
Ejemplo n.º 17
0
        public override void OnStart(PartModule.StartState state)
        {
            ModuleCommand cmdModule = part.Modules.OfType <ModuleCommand>().First();

            originalChargeRate = cmdModule.inputResources.First().rate;

            updateControlState();
        }
Ejemplo n.º 18
0
 public CSPPacket(int headerValues, short dataSize, ModuleCommand command)
 {
     PartTransmitted = 0;
     DataSize        = dataSize;
     Header          = new BitVector32(headerValues);
     ErrorDetected   = false;
     Command         = command;
 }
Ejemplo n.º 19
0
 public CSPPacket(BitVector32 header, short dataSize, ModuleCommand command)
 {
     PartTransmitted = 0;
     DataSize        = dataSize;
     Header          = header;
     ErrorDetected   = false;
     Command         = command;
 }
        // Public Overrides
        public override void OnStart(StartState state)
        {
            if (!Kerbalism.IsLoaded)
            {
                resourcesToSupply = new[] { ResourceSettings.Config.ElectricPowerInMegawatt }
            }
            ;

            _isEnabledField      = Fields[nameof(IsEnabled)];
            _isPoweredField      = Fields[nameof(IsPowered)];
            _upgradeCostStrField = Fields[nameof(upgradeCostStr)];
            _retrofitCoreEvent   = Events[nameof(RetrofitCore)];
            _nameStrField        = Fields[nameof(nameStr)];
            _scienceRateField    = Fields[nameof(scienceRate)];

            if (state == StartState.Editor)
            {
                if (!this.HasTechsRequiredToUpgrade())
                {
                    return;
                }

                isupgraded = true;
                upgradePartModule();
                return;
            }

            Debug.Log("[KSPI]: ComputerCore on " + part.name + " was Force Activated");
            part.force_activate();

            _moduleDataTransmitter = part.FindModuleImplementing <ModuleDataTransmitter>();
            _moduleCommand         = part.FindModuleImplementing <ModuleCommand>();

            if (isupgraded || !PluginHelper.TechnologyIsInUse)
            {
                upgradePartModule();
            }
            else
            {
                computercoreType = originalName;
            }

            if (IsEnabled)
            {
                var timeDifference     = Planetarium.GetUniversalTime() - last_active_time;
                var altitudeMultiplier = vessel.altitude / vessel.mainBody.Radius;
                altitudeMultiplier = Math.Max(altitudeMultiplier, 1);

                var scienceMultiplier = PluginHelper.GetScienceMultiplier(vessel);

                var scienceToIncrement = baseScienceRate * timeDifference / GameConstants.KEBRIN_DAY_SECONDS * electrical_power_ratio * scienceMultiplier / (Math.Sqrt(altitudeMultiplier));
                scienceToIncrement = (double.IsNaN(scienceToIncrement) || double.IsInfinity(scienceToIncrement)) ? 0 : scienceToIncrement;
                science_to_add    += scienceToIncrement;
            }

            _effectivePowerRequirement = (isupgraded ? upgradedMegajouleRate : megajouleRate) * powerReqMult;
        }
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            Logger.Debug($"Window_KeyDown - Handle the KeyDown event {e.KeyCode} ");

            var spacecraft = _environment.Session.GetPlayerSpaceShip();

            string commandBody;

            switch (e.KeyCode)
            {
            case Keys.S:
                if (_environment.Session.IsPause)
                {
                    return;
                }
                commandBody = ModuleCommand.ToJson(_environment.Session, spacecraft.GetPropulsionModules()[0].Braking);
                Global.Game.ExecuteCommand(new EngineCore.Command(commandBody));
                break;

            case Keys.D:
                if (_environment.Session.IsPause)
                {
                    return;
                }
                commandBody = ModuleCommand.ToJson(_environment.Session, spacecraft.GetPropulsionModules()[0].TurnRight);
                Global.Game.ExecuteCommand(new EngineCore.Command(commandBody));
                break;

            case Keys.A:
                if (_environment.Session.IsPause)
                {
                    return;
                }
                commandBody = ModuleCommand.ToJson(_environment.Session, spacecraft.GetPropulsionModules()[0].TurnLeft);
                Global.Game.ExecuteCommand(new EngineCore.Command(commandBody));
                break;

            case Keys.W:
                if (_environment.Session.IsPause)
                {
                    return;
                }
                commandBody = ModuleCommand.ToJson(_environment.Session, spacecraft.GetPropulsionModules()[0].Acceleration);
                Global.Game.ExecuteCommand(new EngineCore.Command(commandBody));
                break;

            case Keys.Escape:
                _environment.CancelAction();
                if (_environment.Session.IsPause)
                {
                    Global.Game.SessionResume();
                }
                break;
            }
        }
Ejemplo n.º 22
0
        private void Rb_MouseClick(object sender, MouseEventArgs e)
        {
            if (startTime == 0)
            {
                startTime = (long)DateTime.UtcNow.Ticks / 10000;
            }
            else
            {
                long endTime = (long)DateTime.UtcNow.Ticks / 10000;
                if (endTime - startTime < 500)
                {
                    RadioButton rb = sender as RadioButton;
                    //处理双击事件
                    Form2 form  = new Form2((sender as RadioButton).Text);
                    Label label = form.Controls.Find("label1", true)[0] as Label;
                    //label.Text = _moduleList[checkedNum].Module;
                    ModuleCommand oldM = _moduleList[checkedNum];
                    ModuleCommand newM = new ModuleCommand();
                    form.StartPosition = FormStartPosition.CenterParent;
                    TextBox tBoxNote  = form.Controls.Find("textBox1", true)[0] as TextBox;
                    Button  btnSave   = form.Controls.Find("button1", true)[0] as Button;
                    Button  btnCancel = form.Controls.Find("button2", true)[0] as Button;
                    tBoxNote.TextChanged += TBoxNote_TextChanged;

                    btnSave.DialogResult   = DialogResult.Yes;
                    btnCancel.DialogResult = DialogResult.No;
                    DialogResult result = form.ShowDialog();
                    if (result == DialogResult.Yes)
                    {
                        if (rb.Name.StartsWith("rbf"))
                        {
                            newM = new ModuleCommand(oldM.Module, newFunction == null?oldM.Function:newFunction);
                            foreach (ModuleCommand mb in _moduleList)
                            {
                                if (mb.Function.ToUpper() == newM.Function.ToUpper() && mb.Module.ToUpper() == newM.Module.ToUpper())
                                {
                                    DialogResult RESULT = MessageBox.Show("模块" + mb.Module + "下的功能" + mb.Function + "已存在.", "警告!!!", MessageBoxButtons.OK);
                                    return;
                                }
                            }
                            XMLUnit xml = new XMLUnit();
                            xml.ChangeModultList(oldM, newM);
                            _moduleList = xml.QueryModuleList();
                            AddModuleRB(_moduleList, checkedNum);
                        }
                    }
                    else
                    {
                        Console.WriteLine("不保存列表");
                    }
                }
                startTime = 0;
            }
        }
        // Public Overrides
        public override void OnStart(PartModule.StartState state)
        {
            String[] resources_to_supply = { ResourceManager.FNRESOURCE_THERMALPOWER, ResourceManager.FNRESOURCE_CHARGED_PARTICLES, ResourceManager.FNRESOURCE_MEGAJOULES, ResourceManager.FNRESOURCE_WASTEHEAT, };
            this.resources_to_supply = resources_to_supply;

            _isEnabledField      = Fields["IsEnabled"];
            _isPoweredField      = Fields["IsPowered"];
            _upgradeCostStrField = Fields["upgradeCostStr"];
            _retrofitCoreEvent   = Events["RetrofitCore"];
            _nameStrField        = Fields["nameStr"];
            _scienceRateField    = Fields["scienceRate"];

            if (state == StartState.Editor)
            {
                if (this.HasTechsRequiredToUpgrade())
                {
                    isupgraded = true;
                    upgradePartModule();
                }
                return;
            }

            UnityEngine.Debug.Log("[KSPI]: ComputerCore on " + part.name + " was Force Activated");
            this.part.force_activate();

            _moduleDataTransmitter = part.FindModuleImplementing <ModuleDataTransmitter>();
            moduleCommand          = part.FindModuleImplementing <ModuleCommand>();

            if (isupgraded || !PluginHelper.TechnologyIsInUse)
            {
                upgradePartModule();
            }
            else
            {
                computercoreType = originalName;
            }

            if (IsEnabled)
            {
                double time_diff           = Planetarium.GetUniversalTime() - last_active_time;
                double altitude_multiplier = vessel.altitude / vessel.mainBody.Radius;
                altitude_multiplier = Math.Max(altitude_multiplier, 1);

                var scienceMultiplier = PluginHelper.getScienceMultiplier(vessel);

                double science_to_increment = baseScienceRate * time_diff / GameConstants.KEBRIN_DAY_SECONDS * electrical_power_ratio * scienceMultiplier / (Math.Sqrt(altitude_multiplier));
                science_to_increment = (double.IsNaN(science_to_increment) || double.IsInfinity(science_to_increment)) ? 0 : science_to_increment;
                science_to_add      += science_to_increment;
            }

            effectivePowerRequirement = (isupgraded ? upgradedMegajouleRate : megajouleRate) * powerReqMult;
        }
Ejemplo n.º 24
0
 public void HandleCommand(ModuleCommand sender)
 {
     if (sender.Status == ModuleCommand.CommandStatus.Idle)
     {
         StartMenu.ShowMenu();
         sender.Status = ModuleCommand.CommandStatus.Active;
     }
     else
     {
         StartMenu.HideMenu();
         sender.Status = ModuleCommand.CommandStatus.Idle;
     }
 }
Ejemplo n.º 25
0
        private void setGroupText(ModuleCommand module)
        {
            GroupBox groupbox = panel1.FindForm().Controls.Find("gboxMCL", true)[0] as GroupBox;

            if (module.Function != null)
            {
                groupbox.Text = module.Module + "----" + module.Function;
            }
            else
            {
                groupbox.Text = "多条指令";
            }
        }
Ejemplo n.º 26
0
        void ButtonAddClick(object sender, EventArgs e)
        {
            if (listViewAvailablePriveleges.SelectedItems.Count > 0)
            {
                Module        m = modules[comboBoxModule.SelectedIndex];
                ModuleCommand c = m.Commands[listViewAvailablePriveleges.SelectedItems[0].Index];

                UserModule module = user.GetModule(m);
                module.AddCommand(c);

                ComboBoxModuleSelectedIndexChanged(sender, e);
            }
        }
Ejemplo n.º 27
0
 void ButtonEditClick(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count > 0)
     {
         ModuleCommand command = module.Commands[listView1.SelectedItems[0].Index];
         using (ModuleCommandForm f = new ModuleCommandForm(command)) {
             f.Text = "Edit Module Command";
             if (WorkbenchSingleton.AddDialog(f) == DialogResult.OK)
             {
                 ModuleCommandsChanged(this, null);
             }
         }
     }
 }
Ejemplo n.º 28
0
        /// <summary>
        /// 根据选列表,XML反序列化
        /// </summary>
        /// <param name="module"></param>
        /// <returns></returns>
        public List <ATCommand> XMLUnitRead(ModuleCommand module)
        {
            List <ATCommand> temp     = XMLUnitRead();
            List <ATCommand> fullList = new List <ATCommand>();

            foreach (ATCommand command in temp)
            {
                if (command.Module.Equals(module.Module) && command.Function.Equals(module.Function))
                {
                    fullList.Add(command);
                }
            }
            return(fullList);
        }
Ejemplo n.º 29
0
 public void setDevice(ModuleCommand.command cmd, Action<ModuleCommand.command> callback)
 {
     myCallBack = callback;
     myCommand = cmd;
     switch (cmd.Name)
     {
         case stateName.打开:
             打开风扇(Program.getRemoteIPEndPoint());
             break;
         case stateName.关闭:
             关闭风扇(Program.getRemoteIPEndPoint());
             break;
     }
 }
Ejemplo n.º 30
0
        public override void OnStart(PartModule.StartState state)
        {
            String[] resources_to_supply = { ResourceManager.FNRESOURCE_MEGAJOULES };
            this.resources_to_supply = resources_to_supply;

            if (state == StartState.Editor)
            {
                if (this.HasTechsRequiredToUpgrade())
                {
                    isupgraded = true;
                    upgradePartModule();
                }
                return;
            }

            this.part.force_activate();

            _moduleDataTransmitter = part.FindModuleImplementing <ModuleDataTransmitter>();
            moduleCommand          = part.FindModuleImplementing <ModuleCommand>();

            Fields["IsEnabled"].guiActive       = isupgraded;
            Fields["IsEnabled"].guiActiveEditor = isupgraded;

            if ((isupgraded || !PluginHelper.TechnologyIsInUse) && IsEnabled)
            {
                upgradePartModule();

                double now                 = Planetarium.GetUniversalTime();
                double time_diff           = now - last_active_time;
                double altitude_multiplier = vessel.altitude / vessel.mainBody.Radius;
                altitude_multiplier = Math.Max(altitude_multiplier, 1);

                var scienceMultiplier = PluginHelper.getScienceMultiplier(vessel);

                double science_to_increment = baseScienceRate * time_diff / GameConstants.KEBRIN_DAY_SECONDS * electrical_power_ratio * scienceMultiplier / (Math.Sqrt(altitude_multiplier));
                science_to_increment = (double.IsNaN(science_to_increment) || double.IsInfinity(science_to_increment)) ? 0 : science_to_increment;
                science_to_add      += science_to_increment;

                //var curReaction = this.part.Modules["ModuleReactionWheel"] as ModuleReactionWheel;
                //curReaction.PitchTorque = 5;
                //curReaction.RollTorque = 5;
                //curReaction.YawTorque = 5;
            }
            else
            {
                computercoreType = originalName;
            }

            effectivePowerRequirement = (isupgraded ? upgradedMegajouleRate : megajouleRate) * powerReqMult;
        }
Ejemplo n.º 31
0
        public void setDevice(ModuleCommand.command cmd, Action<ModuleCommand.command> callback)
        {
            myCallBack = callback;
            myCommand = cmd;

            rfid_helper = new TDJ_RFIDHelper();

            //打开UDP端口,等待数据传入
            this.updServer = UDPServer.getUDPServer(Program.UHF_UDP_Port);
            updServer.evtReceived += new OnReceiveString(updServer_evtReceived);
            updServer.startUDPListening();

            Debug.WriteLine(string.Format("*****  UHFDevice onListening... "));
        }
Ejemplo n.º 32
0
        public void PropulsionModule_Braking_Test()
        {
            var server = EnvironmentGlobal.CreateGameServer("CommandsTests");

            var gameSession = EnvironmentGlobal.GetSession(server);

            var spaceship = gameSession.GetPlayerSpaceShip();

            var module = spaceship.GetPropulsionModules().First();

            server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Braking));

            Assert.AreEqual(1, server.Commands.Count);

            Assert.AreEqual(7, gameSession.GetCelestialObject(spaceship.Id).Speed);

            server.TurnCalculation(1);

            gameSession = EnvironmentGlobal.GetSession(server);

            Assert.AreEqual(6.975, Math.Round(gameSession.GetCelestialObject(spaceship.Id).Speed, 3));

            Assert.AreEqual(0, server.Commands.Count);

            Assert.AreEqual(1, server.GetHistoryCommands(server.SessionId, spaceship.Id).Count);

            server.TurnCalculation(1);

            // Add command for not reloaded module
            server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Braking));

            server.TurnCalculation(1);

            Assert.AreEqual(0, server.Commands.Count);

            server.Wait(5);

            server.Command(server.SessionId, ModuleCommand.ToJson(gameSession, module.Braking));

            Assert.AreEqual(1, server.Commands.Count);

            server.Wait(5);

            Assert.AreEqual(0, server.Commands.Count);

            Assert.AreEqual(2, server.GetHistoryCommands(server.SessionId, spaceship.Id).Count);

            Assert.AreEqual(CommandTypes.StopShip, server.GetHistoryCommands(server.SessionId, spaceship.Id)[0].Type);
        }
Ejemplo n.º 33
0
 private int MySort(ModuleCommand m1, ModuleCommand m2)
 {
     if (m1.Module.CompareTo(m2.Module) != 0)
     {
         return(m1.Module.CompareTo(m2.Module));
     }
     else if (m1.Function.CompareTo(m2.Function) != 0)
     {
         return(m1.Function.CompareTo(m2.Function));
     }
     else
     {
         return(1);
     }
 }
Ejemplo n.º 34
0
        public void setDevice(ModuleCommand.command cmd, Action<ModuleCommand.command> callback)
        {
            myCallBack = callback;
            myCommand = cmd;

            //打开UDP端口,等待数据传入
            this.updServer = UDPServer.getUDPServer(Program.GPS_UDP_Port);
            updServer.evtReceived += new OnReceiveString(updServer_evtReceived);
            updServer.startUDPListening();

            GPS = new NmeaInterpreter();
            GPS.PositionReceived += new NmeaInterpreter.PositionReceivedEventHandler(GPS_PositionReceived);

            Debug.WriteLine(string.Format("*****  GPSService onListening... "));
        }
Ejemplo n.º 35
0
        public override void OnStart(PartModule.StartState state)
        {
            if (state == StartState.Editor)
            {
                if (this.HasTechsRequiredToUpgrade())
                {
                    isupgraded = true;
                    upgradePartModule();
                }
                return;
            }

            moduleCommand = part.FindModuleImplementing<ModuleCommand>();

            if (isupgraded || !PluginHelper.TechnologyIsInUse)
            {
                upgradePartModule();

                double now = Planetarium.GetUniversalTime();
                double time_diff = now - last_active_time;
                float altitude_multiplier = (float)(vessel.altitude / (vessel.mainBody.Radius));
                altitude_multiplier = Math.Max(altitude_multiplier, 1);

                //var scienceMultiplier = PluginHelper.getScienceMultiplier(vessel.mainBody.flightGlobalsIndex, vessel.LandedOrSplashed);
                var scienceMultiplier = PluginHelper.getScienceMultiplier(vessel);

                double science_to_increment = baseScienceRate * time_diff / GameConstants.KEBRIN_DAY_SECONDS * electrical_power_ratio * scienceMultiplier / ((float)Math.Sqrt(altitude_multiplier));
                science_to_increment = (double.IsNaN(science_to_increment) || double.IsInfinity(science_to_increment)) ? 0 : science_to_increment;
                science_to_add += (float)science_to_increment;

                //var curReaction = this.part.Modules["ModuleReactionWheel"] as ModuleReactionWheel;
                //curReaction.PitchTorque = 5;
                //curReaction.RollTorque = 5;
                //curReaction.YawTorque = 5;
            } 
            else
                computercoreType = originalName;

            this.part.force_activate();
        }
Ejemplo n.º 36
0
        /// <summary>
        /// Start
        /// </summary>
        /// <param name="state"></param>
        public override void OnStart(StartState state)
        {
            GSA.Durability.Debug.Log("GSA Durability: [OnStart][" + state.ToString() + "]: " + this.name);
            base.OnStart(state);
            try
            {
                _state = state;
                AvailablePart currentPartInfo = PartLoader.getPartInfoByName(part.name.Replace("(Clone)", ""));
                _initCost = currentPartInfo.cost;
                if (state == StartState.Editor)
                {
                    return;
                }
                if (part.Resources.Contains("Quality"))
                {
                    quality = (part.Resources["Quality"].amount / (part.Resources["Quality"].maxAmount / 100)) / 100;
                }

                if (basicWear.findCurveMinMaxInterations == 0)
                {
                    basicWear = new FloatCurve();
                    basicWear.Add(0.1f, 0.69f);
                    basicWear.Add(0.5f, 0.000181f);
                    basicWear.Add(1f, 0.00001f);
                }
                _currentWear = basicWear.Evaluate((float)quality);
                _lastUpdateTime = vessel.missionTime;
                _sun = Planetarium.fetch.Sun;
                //gameObject.AddComponent(typeof(LineRenderer));

                if (part.Modules.Contains("ModuleCommand"))
                {
                    _command = (ModuleCommand)part.Modules["ModuleCommand"];
                    GSA.Durability.Debug.Log("GSA Durability: [OnStart]: _command = " + _command.name);
                }

                if (part.Modules.Contains("ModuleReactionWheel"))
                {
                    _reactionWheel = (ModuleReactionWheel)part.Modules["ModuleReactionWheel"];
                    GSA.Durability.Debug.Log("GSA Durability: [OnStart]: _reactionWheel = " + _reactionWheel.name);
                }

                if (part.Modules.Contains("ModuleEngines"))
                {
                    _engine = (ModuleEngines)part.Modules["ModuleEngines"];
                    GSA.Durability.Debug.Log("GSA Durability: [OnStart]: _engine = " + _engine.name);
                }
                if (part.Modules.Contains("ModuleScienceExperiment"))
                {
                    _scienceExperiment = (ModuleScienceExperiment)part.Modules["ModuleScienceExperiment"];
                    GSA.Durability.Debug.Log("GSA Durability: [OnStart]: _scienceExperiment = " + _scienceExperiment.name);
                }

                checkStatus();
                setEventLabel();
            }
            catch (Exception ex)
            {
                GSA.Durability.Debug.LogError("GSA Durability: [OnStart]: Message: " + ex.Message);
                GSA.Durability.Debug.LogError("GSA Durability: [OnStart]: StackTrace: " + ex.StackTrace);
            }

            GSA.Durability.Debug.Log("GSA Durability: [OnStart]: quality:" + quality.ToString());
            GSA.Durability.Debug.Log("GSA Durability: [OnStart]: damageRate: " + _currentWear.ToString("0.000000"));
            GSA.Durability.Debug.Log("GSA Durability: [OnStart]: vessel.missionTime: " + vessel.missionTime.ToString());
            GSA.Durability.Debug.Log("GSA Durability: [OnStart]: lastReduceRange: " + lastReduceRange.ToString());
            GSA.Durability.Debug.Log("GSA Durability: [OnStart]: lastUpdateTime: " + _lastUpdateTime.ToString());
            GSA.Durability.Debug.Log("GSA Durability: [OnStart]: maxRepair: " + maxRepair.ToString());
            GSA.Durability.Debug.Log("GSA Durability: [OnStart]: canRepair: " + canRepair.ToString());
        }
Ejemplo n.º 37
0
        protected void setupGUI()
        {
            //Hide seat GUI
            seat = this.part.FindModuleImplementing<KerbalSeat>();
            seat.Events["BoardSeat"].guiActive = false;
            seat.Events["BoardSeat"].guiActiveEditor = false;
            seat.Events["BoardSeat"].guiActiveUnfocused = false;

            //Hide probe command GUI
            wingCommander = this.part.FindModuleImplementing<ModuleCommand>();
            wingCommander.Events["MakeReference"].guiActive = false;
            wingCommander.Events["MakeReference"].guiActiveUnfocused = false;
            wingCommander.Events["RenameVessel"].guiActive = false;

            //Hide decoupler GUI
            decoupler = this.part.FindModuleImplementing<ModuleDecouple>();
            decoupler.Events["Decouple"].guiActive = false;
            decoupler.Events["Decouple"].guiActiveEditor = false;
            decoupler.Events["Decouple"].guiActiveUnfocused = false;

            //Hide MultiModeEngine toggle button
            multiModeEngine = this.part.FindModuleImplementing<MultiModeEngine>();
            multiModeEngine.Events["ModeEvent"].guiActive = false;
            multiModeEngine.Events["ModeEvent"].guiActiveEditor = false;
            multiModeEngine.Events["ModeEvent"].guiActiveUnfocused = false;

            //Hide the Close Intake button.
            ModuleResourceIntake intake = this.part.FindModuleImplementing<ModuleResourceIntake>();
            intake.Events["Deactivate"].guiActive = false;

            //Hide RCS GUI
            ModuleRCS rcs = this.part.FindModuleImplementing<ModuleRCS>();
            rcs.Fields["realISP"].guiActive = false;
            rcs.Events["Disable"].guiActive = false;

            //Hide hover engine gui
            hoverEngine = this.part.FindModuleImplementing<WBIMultiEngineHover>();
            hoverEngine.SetGUIVisible(false);

            //Set fuel type
            resourceSwitcher = this.part.FindModuleImplementing<WBIResourceSwitcher>();
            resourceSwitcher.Fields["shortName"].guiName = "Fuel Type";
        }