Beispiel #1
0
        void SetOrbitHere(Entity entity, PositionDB positionDB, WarpMovingDB moveDB, DateTime atDateTime)
        {
            //propulsionDB.CurrentVectorMS = new Vector3(0, 0, 0);

            double targetSOI = OrbitProcessor.GetSOI_m(moveDB.TargetEntity);

            Entity targetEntity;

            if (moveDB.TargetEntity.GetDataBlob <PositionDB>().GetDistanceTo_m(positionDB) > targetSOI)
            {
                targetEntity = moveDB.TargetEntity.GetDataBlob <OrbitDB>().Parent; //TODO: it's concevable we could be in another SOI not the parent (ie we could be in a target's moon's SOI)
            }
            else
            {
                targetEntity = moveDB.TargetEntity;
            }
            OrbitDB targetOrbit = targetEntity.GetDataBlob <OrbitDB>();


            Vector3 insertionVector_m = OrbitProcessor.GetOrbitalInsertionVector_m(moveDB.SavedNewtonionVector, targetOrbit, atDateTime);

            positionDB.SetParent(targetEntity);

            if (moveDB.ExpendDeltaV.Length() != 0)
            {
                NewtonThrustCommand.CreateCommand(entity.FactionOwner, entity, entity.StarSysDateTime, moveDB.ExpendDeltaV);
                entity.RemoveDataBlob <WarpMovingDB>();
                moveDB.IsAtTarget = true;
            }
            else
            {
                OrbitDB newOrbit = OrbitDB.FromVelocity_m(targetEntity, entity, insertionVector_m, atDateTime);
                entity.RemoveDataBlob <WarpMovingDB>();


                if (newOrbit.Apoapsis < targetSOI) //furtherst point within soi, normal orbit
                {
                    entity.SetDataBlob(newOrbit);
                }
                else if (newOrbit.Periapsis > targetSOI) //closest point outside soi
                {
                    //find who's SOI we are in, and create an orbit around that.
                    targetEntity = OrbitProcessor.FindSOIForPosition((StarSystem)entity.Manager, positionDB.AbsolutePosition_m);
                    newOrbit     = OrbitDB.FromVelocity_m(targetEntity, entity, insertionVector_m, atDateTime);
                    entity.SetDataBlob(newOrbit);
                }
                else //closest point inside soi, but furtherest point outside. make a newtonion trajectory.
                {
                    var newtmove = new NewtonMoveDB(targetEntity, insertionVector_m);
                    entity.SetDataBlob(newtmove);
                }

                positionDB.SetParent(targetEntity);
                moveDB.IsAtTarget = true;
            }
        }