Exemple #1
0
        public override void updateLocalElements(object sender, EventArgs e)
        {
            // Re-usable data variable for graph data
            List <List <KeyValuePair <double, double?> > > data = new List <List <KeyValuePair <double, double?> > >();
            List <Plot.Type> types = new List <Plot.Type>();


            if (form.form.connected && form.form.krpc.CurrentGameScene == GameScene.Flight)
            {
                currentStage         = screenStreams.GetData(DataType.control_currentStage);
                MET                  = screenStreams.GetData(DataType.vessel_MET);
                parts                = screenStreams.GetData(DataType.vessel_parts);
                vesselReferenceFrame = screenStreams.GetData(DataType.vessel_referenceFrame);

                bool force = false;
                if (currentStage != oldStage)
                {
                    force = true;
                    screenStreams.setStage(currentStage);
                    Console.WriteLine(DateTime.Now.ToString() + "." + DateTime.Now.Millisecond.ToString() + " NEW STAGE: " + currentStage.ToString());
                }

                getStageSupplies(force);
                if (LiquidFuelMax == 0)
                {
                    // TRY TO WALK TROUGH THE STAGES UNTIL FUEL IS FOUND OR STAGES RUN OUT
                    for (int s = currentStage - 1; s >= 0; s--)
                    {
                        screenStreams.setStage(s);
                        Console.WriteLine(DateTime.Now.ToString() + "." + DateTime.Now.Millisecond.ToString() + " SET STREAM STAGE: " + s.ToString());
                        getStageSupplies(true);
                        if (LiquidFuelMax != 0)
                        {
                            oldStage = currentStage;
                            break;
                        }
                    }
                }


                TotLiquidFuelMax        = screenStreams.GetData(DataType.resource_total_max_liquidFuel);
                TotLiquidFuelAmount     = screenStreams.GetData(DataType.resource_total_amount_liquidFuel);
                TotOxidizerMax          = screenStreams.GetData(DataType.resource_total_max_oxidizer);
                TotOxidizerAmount       = screenStreams.GetData(DataType.resource_total_amount_oxidizer);
                TotMonoPropellantMax    = screenStreams.GetData(DataType.resource_total_max_monoPropellant);
                TotMonoPropellantAmount = screenStreams.GetData(DataType.resource_total_amount_monoPropellant);

                mass = screenStreams.GetData(DataType.vessel_mass);



                screenLabels[2].Text = "LT: " + Helper.timeString(DateTime.Now.TimeOfDay.TotalSeconds);
                screenLabels[3].Text = "MET: " + Helper.timeString(MET, 3);                 // 0 RPC

                /**
                 * Engines
                 **/

                //  Get parts in current stage
                screenLabels[6].Text = "STAGE: " + currentStage.ToString();                 // 0 RPC

                bool   foundEngine = false;
                double multiplier  = 91;
                double maxDev      = 0;


                double stageCurThr = 0;
                double stageMaxThr = 0;

                int n = 0;



                if (parts != null)
                {
                    // CLEAR OLD ENGINES
                    foreach (EngineIndicator ei in screenEngines)
                    {
                        ei.display(false);
                    }

                    for (int i = currentStage; i >= 0; i--)
                    {
                        IList <Part> stageParts = parts.InStage(i);
                        foreach (Part part in stageParts)
                        {
                            Engine eng = part.Engine;

                            if (eng != null)
                            {
                                foundEngine = true;
                                Tuple <double, double, double> pos = part.Position(vesselReferenceFrame);

                                double left = pos.Item1;
                                double top  = pos.Item3;

                                double devX = Math.Abs(left);
                                if (devX > maxDev)
                                {
                                    maxDev = devX;
                                }
                                double devY = Math.Abs(top);
                                if (devY > maxDev)
                                {
                                    maxDev = devY;
                                }

                                if (screenEngines.Count < (n + 1))
                                {
                                    screenEngines.Add(null);
                                    screenEngines[n] = Helper.CreateEngine(0, 0, (n + 1).ToString(), eng.MaxVacuumThrust);
                                }
                                screenEngines[n].display(true);
                                screenEngines[n].setThrust(eng.MaxVacuumThrust);


                                screenEngines[n].offsetX = left;
                                screenEngines[n].offsetY = top;

                                if (eng.Thrust > 0)
                                {
                                    screenEngines[n].setStatus(true);
                                }
                                else
                                {
                                    screenEngines[n].setStatus(false);
                                }

                                // Engine data
                                screenLabels[41 + n].Text = Helper.prtlen((n + 1).ToString(), 4, Helper.Align.RIGHT) + ":"
                                                            + "" + Helper.prtlen(Helper.toFixed(eng.Thrust / 1000, 1), 7, Helper.Align.RIGHT)
                                                            + "  " + Helper.prtlen(Helper.toFixed(eng.MaxThrust / 1000, 1), 7, Helper.Align.RIGHT)
                                                            + "  " + Helper.prtlen(Helper.toFixed(eng.VacuumSpecificImpulse, 1), 5, Helper.Align.RIGHT);

                                stageCurThr += eng.Thrust;
                                stageMaxThr += eng.MaxThrust;

                                n++;
                            }
                        }

                        if (foundEngine)
                        {
                            int engNum = n;

                            // TOTAL THUST AND STUFF
                            screenLabels[41 + n].Text = "─────────────────────────────────";
                            n++;
                            screenLabels[41 + n].Text = " TOT:"
                                                        + "" + Helper.prtlen(Helper.toFixed(stageCurThr / 1000, 1), 7, Helper.Align.RIGHT)
                                                        + "  " + Helper.prtlen(Helper.toFixed(stageMaxThr / 1000, 1), 7, Helper.Align.RIGHT);
                            n++;

                            // CLEAR OUT OLD LABLED
                            while (n < 20)
                            {
                                screenLabels[41 + n].Text = "";
                                n++;
                            }


                            int maxSpread = 96;
                            multiplier = maxSpread / maxDev;

                            if (engNum == 1)
                            {
                                multiplier = 0;
                            }

                            // CENTER POINT
                            int centerX = 184;
                            int centerY = 214;

                            // position indicators
                            for (int j = 0; j < engNum; j++)
                            {
                                int x = (int)Math.Round(centerX + (screenEngines[j].offsetX * multiplier));
                                int y = (int)Math.Round(centerY + (screenEngines[j].offsetY * multiplier));
                                screenEngines[j].setCenterPoint(x, y);
                            }

                            break;
                        }
                    }
                }

                // Disable other engineIndicators
                while (n < screenEngines.Count)
                {
                    screenEngines[n].Dispose();
                    screenEngines.RemoveAt(n);
                    screenLabels[41 + n].Text = "";
                    n++;
                }
                screenEngines.TrimExcess();

                // Weight and TWR
                double weight = mass / 1000;
                double TWRc   = (stageCurThr / 1000) / (weight * 9.81);
                double TWRm   = (stageMaxThr / 1000) / (weight * 9.81);;
                screenLabels[62].Text = "  MASS: " + Helper.prtlen(Helper.toFixed(weight, 1), 5, Helper.Align.RIGHT) + "t";
                screenLabels[64].Text = "   TWR: " + Helper.prtlen(Helper.toFixed(TWRc, 2), 4, Helper.Align.RIGHT)
                                        + "  " + Helper.prtlen(Helper.toFixed(TWRm, 2), 4, Helper.Align.RIGHT);


                // Supplies
                double mF = LiquidFuelMax;
                double cF = LiquidFuelAmount;

                double mO = OxidizerMax;
                double cO = OxidizerAmount;

                double mM = MonoPropellantMax;
                double cM = MonoPropellantAmount;

                screenLabels[70].Text = "         LF     LO     MP";
                screenLabels[71].Text = "STAGE:"
                                        + Helper.prtlen(Math.Round(cF).ToString(), 7, Helper.Align.RIGHT)
                                        + Helper.prtlen(Math.Round(cO).ToString(), 7, Helper.Align.RIGHT)
                                        + Helper.prtlen(Helper.toFixed(cM, 2), 7, Helper.Align.RIGHT);
                screenLabels[72].Text = "    %:"
                                        + Helper.prtlen(Math.Round((cF / mF) * 100).ToString(), 7, Helper.Align.RIGHT)
                                        + Helper.prtlen(Math.Round((cO / mO) * 100).ToString(), 7, Helper.Align.RIGHT)
                                        + Helper.prtlen(Math.Round((cM / mM) * 100).ToString(), 7, Helper.Align.RIGHT);

                mF = TotLiquidFuelMax;
                cF = TotLiquidFuelAmount;

                mO = TotOxidizerMax;
                cO = TotOxidizerAmount;

                mM = TotMonoPropellantMax;
                cM = TotMonoPropellantAmount;

                screenLabels[74].Text = "  TOT:"
                                        + Helper.prtlen(Math.Round(cF).ToString(), 7, Helper.Align.RIGHT)
                                        + Helper.prtlen(Math.Round(cO).ToString(), 7, Helper.Align.RIGHT)
                                        + Helper.prtlen(Helper.toFixed(cM, 2), 7, Helper.Align.RIGHT);
                screenLabels[75].Text = "    %:"
                                        + Helper.prtlen(Math.Round((cF / mF) * 100).ToString(), 7, Helper.Align.RIGHT)
                                        + Helper.prtlen(Math.Round((cO / mO) * 100).ToString(), 7, Helper.Align.RIGHT)
                                        + Helper.prtlen(Math.Round((cM / mM) * 100).ToString(), 7, Helper.Align.RIGHT);

                // Delta V
                // TOTO: Maybe buttonifize this, so the calculations are not done every refresh.
                updateDeltaVStats(currentStage, parts);
            }
        }