Example #1
0
        public void Update()
        {
            KSPPlanet CurrentPlanet;

            planets.TryGetValue(FlightGlobals.currentMainBody ?? FlightGlobals.Bodies.FirstOrDefault(x => x.name == "Kerbin"), out CurrentPlanet);

            if (CurrentPlanet != LastPlanet)
            {
                Utils.Log("Planet changed: {0} => {1}", LastPlanet == null ? "(null)" : LastPlanet.Body.name, CurrentPlanet == null ? "(null)" : CurrentPlanet.Body.name);
                LastPlanet = CurrentPlanet;
            }

            if (CurrentPlanet != null)
            {
                if (FlightGlobals.ActiveVessel == null)
                {
                    CurrentPlanet.UpdatePosition(Coordinates.KSC);
                }
                else
                {
                    CurrentPlanet.UpdatePosition(new Coordinates(FlightGlobals.ActiveVessel.latitude * Math.PI / 180, FlightGlobals.ActiveVessel.longitude * Math.PI / 180));
                }
            }

            ThreadDispatcher.DequeueFromWorker(20);
        }
Example #2
0
File: Star.cs Project: txe/Pulsar4x
        /// <summary>
        /// Update the star's position and do any other work here
        /// </summary>
        /// <param name="deltaSeconds">Time to advance star position</param>
        public void UpdatePosition(int deltaSeconds)
        {
            double x, y;

            Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y);

            Position.X = x;
            Position.Y = y;

            if (Parent != null)
            {
                // Position is absolute system coordinates, while
                // coordinates returned from GetPosition are relative to it's parent.
                Position.X += Parent.Position.X;
                Position.Y += Parent.Position.Y;
            }

            foreach (SystemBody CurrentPlanet in Planets)
            {
                CurrentPlanet.UpdatePosition(deltaSeconds);
            }
        }
Example #3
0
        /// <summary>
        /// Updates this StarSystem for the new time.
        /// </summary>
        /// <param name="deltaSeconds">Change in seconds since last update.</param>
        public void Update(int deltaSeconds)
        {
            // Update the position of all planets. This should probably be in something like the construction tick in Aurora.
            foreach (Star CurrentStar in Stars)
            {
                // The system primary will cause a divide by zero error currently as it has no orbit.
                if (CurrentStar != Stars[0])
                {
                    CurrentStar.UpdatePosition(deltaSeconds);

                    // Since the star moved, update the JumpPoint position.
                    foreach (JumpPoint CurrentJumpPoint in JumpPoints)
                    {
                        CurrentJumpPoint.UpdatePosition();
                    }
                }

                foreach (Planet CurrentPlanet in CurrentStar.Planets)
                {
                    CurrentPlanet.UpdatePosition(deltaSeconds);
                }
            }
        }