예제 #1
0
        public static Matrix GetSpawnTransform(App app, Kerberos.Sots.GameStates.StarSystem starSystem)
        {
            float              num1            = 0.0f;
            float              num2            = 5000f;
            Vector3            vector3         = Vector3.Zero;
            Vector3            forward         = -Vector3.UnitZ;
            List <StellarBody> stellarBodyList = new List <StellarBody>();

            foreach (StellarBody stellarBody in starSystem.GetPlanetsInSystem())
            {
                List <Ship> stationsAroundPlanet = starSystem.GetStationsAroundPlanet(stellarBody.Parameters.OrbitalID);
                stellarBodyList.Add(stellarBody);
                foreach (Ship ship in stationsAroundPlanet)
                {
                    float lengthSquared = ship.Position.LengthSquared;
                    if ((double)lengthSquared > (double)num1)
                    {
                        num1    = lengthSquared;
                        vector3 = ship.Position;
                        num2    = ship.ShipSphere.radius;
                        forward = stellarBody.Parameters.Position - ship.Position;
                    }
                }
            }
            if ((double)num1 <= 0.0)
            {
                foreach (StellarBody stellarBody in stellarBodyList)
                {
                    if (stellarBody.Population > 0.0)
                    {
                        float lengthSquared = stellarBody.Parameters.Position.LengthSquared;
                        if ((double)lengthSquared > (double)num1)
                        {
                            num1    = lengthSquared;
                            vector3 = stellarBody.Parameters.Position;
                            num2    = stellarBody.Parameters.Radius;
                            int orbitalId = stellarBody.Parameters.OrbitalID;
                            forward = -vector3;
                        }
                    }
                }
            }
            double num3 = (double)forward.Normalize();

            return(Matrix.CreateWorld(vector3 - forward * (num2 + 20000f), forward, Vector3.UnitY));
        }
예제 #2
0
        public static Matrix GetSpawnTransform(
            App app,
            int fleetID,
            Kerberos.Sots.GameStates.StarSystem starSystem,
            OrbitalObjectInfo[] orbitalObjects)
        {
            DesignInfo designInfo = app.GameDatabase.GetDesignInfo(app.Game.ScriptModules.SystemKiller.SystemKillerDesignId);
            float      val2       = 50000f;

            if (designInfo != null)
            {
                val2 = ((IEnumerable <DesignSectionInfo>)designInfo.DesignSections).Sum <DesignSectionInfo>((Func <DesignSectionInfo, float>)(x => x.ShipSectionAsset.Maneuvering.LinearSpeed)) * 120f;
            }
            float   num1      = 0.0f;
            float   num2      = 5000f;
            Vector3 vector3_1 = Vector3.Zero;
            Vector3 vector3_2 = -Vector3.UnitZ;
            int     num3      = 0;

            foreach (OrbitalObjectInfo orbitalObject in orbitalObjects)
            {
                PlanetInfo planetInfo = app.GameDatabase.GetPlanetInfo(orbitalObject.ID);
                if (planetInfo != null)
                {
                    Matrix orbitalTransform = app.GameDatabase.GetOrbitalTransform(orbitalObject.ID);
                    float  lengthSquared    = orbitalTransform.Position.LengthSquared;
                    if ((double)lengthSquared > (double)num1)
                    {
                        num1      = lengthSquared;
                        vector3_1 = orbitalTransform.Position;
                        vector3_2 = -orbitalTransform.Position;
                        num2      = StarSystemVars.Instance.SizeToRadius(planetInfo.Size) + val2;
                        num3      = orbitalObject.ID;
                    }
                }
            }
            if (num3 == 0)
            {
                MoveOrderInfo orderInfoByFleetId = app.GameDatabase.GetMoveOrderInfoByFleetID(fleetID);
                if (orderInfoByFleetId != null)
                {
                    Vector3 forward = orderInfoByFleetId.ToCoords - orderInfoByFleetId.FromCoords;
                    forward.Y = 0.0f;
                    if ((double)forward.Normalize() < 1.40129846432482E-45)
                    {
                        forward = -Vector3.UnitZ;
                    }
                    float num4 = 0.0f;
                    if (starSystem != null)
                    {
                        num4 = Math.Min((float)(((double)starSystem.GetBaseOffset() + (double)Kerberos.Sots.GameStates.StarSystem.CombatZoneMapRadii[Math.Max(starSystem.GetFurthestRing() - 1, 1)]) * 5700.0), val2);
                    }
                    return(Matrix.CreateWorld(forward * -num4, forward, Vector3.UnitY));
                }
                float num5 = starSystem != null?starSystem.GetStarRadius() : 5000f;

                Vector3 position = Vector3.UnitZ * (float)-((double)num5 + (double)val2);
                return(Matrix.CreateWorld(position, Vector3.Normalize(-position), Vector3.UnitY));
            }
            double num6 = (double)vector3_2.Normalize();
            IEnumerable <OrbitalObjectInfo> moons = app.GameDatabase.GetMoons(num3);

            if (moons.Count <OrbitalObjectInfo>() > 0)
            {
                float   num4      = 5000f;
                Vector3 vector3_3 = Vector3.Zero;
                Vector3 forward   = -Vector3.UnitZ;
                int     num5      = 0;
                float   num7      = 0.0f;
                foreach (OrbitalObjectInfo orbitalObjectInfo in moons)
                {
                    PlanetInfo planetInfo = app.GameDatabase.GetPlanetInfo(orbitalObjectInfo.ID);
                    if (planetInfo != null)
                    {
                        Matrix orbitalTransform = app.GameDatabase.GetOrbitalTransform(orbitalObjectInfo.ID);
                        float  lengthSquared    = orbitalTransform.Position.LengthSquared;
                        if ((double)lengthSquared > (double)num7)
                        {
                            num7      = lengthSquared;
                            vector3_3 = orbitalTransform.Position;
                            forward   = -orbitalTransform.Position;
                            num4      = StarSystemVars.Instance.SizeToRadius(planetInfo.Size) + val2;
                            num5      = orbitalObjectInfo.ID;
                        }
                    }
                }
                if (num5 != 0)
                {
                    Vector3 vector3_4 = Vector3.Normalize(vector3_3 - vector3_1);
                    if ((double)Vector3.Dot(vector3_4, vector3_2) > 0.0)
                    {
                        double num8 = (double)forward.Normalize();
                        return(Matrix.CreateWorld(vector3_3 - forward * (num4 + val2), forward, Vector3.UnitY));
                    }
                    Vector3 v0   = Vector3.Cross(vector3_2, Vector3.UnitY);
                    float   num9 = (double)Vector3.Dot(v0, vector3_4) > 0.0 ? 1f : -1f;
                    return(Matrix.CreateWorld(vector3_3 + v0 * ((num4 + val2) * num9), forward, Vector3.UnitY));
                }
            }
            Vector3 position1 = vector3_1 - vector3_2 * num2;

            if (starSystem != null)
            {
                Vector3 forward = -Vector3.UnitZ;
                float   num4    = -1f;
                foreach (Ship ship in starSystem.GetStationsAroundPlanet(num3))
                {
                    Vector3 v0   = vector3_1 - ship.Maneuvering.Position;
                    double  num5 = (double)v0.Normalize();
                    float   num7 = Vector3.Dot(v0, vector3_2);
                    if ((double)num7 > 0.75 && (double)num7 > (double)num4)
                    {
                        num4    = num7;
                        forward = v0;
                    }
                }
                if ((double)num4 > 0.0)
                {
                    Matrix  world     = Matrix.CreateWorld(Vector3.Zero, forward, Vector3.UnitY);
                    Vector3 vector3_3 = vector3_1 + world.Right * num2;
                    Vector3 vector3_4 = vector3_1 - world.Right * num2;
                    vector3_2 = (double)(position1 - vector3_3).LengthSquared >= (double)(position1 - vector3_4).LengthSquared ? (forward - world.Right) * 0.5f : (forward + world.Right) * 0.5f;
                    double num5 = (double)vector3_2.Normalize();
                    position1 = vector3_1 - vector3_2 * num2;
                }
            }
            return(Matrix.CreateWorld(position1, vector3_2, Vector3.UnitY));
        }