Пример #1
0
 internal void AssignEmptySystemNames(Random random, NamesPool namesPool)
 {
     foreach (Kerberos.Sots.StarSystem starSystem in this.Objects.OfType <Kerberos.Sots.StarSystem>())
     {
         if (string.IsNullOrWhiteSpace(starSystem.DisplayName) || starSystem.DisplayName.ToLower() == "random system")
         {
             starSystem.DisplayName = namesPool.GetSystemName();
         }
         List <IStellarEntity> list1 = starSystem.GetPlanets().ToList <IStellarEntity>();
         list1.Sort(new Comparison <IStellarEntity>(LegacyStarMap.CompareByOrbitNumber));
         int num1 = 0;
         foreach (IStellarEntity planet in list1)
         {
             ++num1;
             if (LegacyStarMap.IsRandomOrbitName(planet.Params))
             {
                 planet.Params.Name = string.Format("{0} {1}", (object)starSystem.DisplayName, (object)num1);
             }
             List <IStellarEntity> list2 = starSystem.GetMoons(planet).ToList <IStellarEntity>();
             list2.Sort(new Comparison <IStellarEntity>(LegacyStarMap.CompareByOrbitNumber));
             int num2 = 0;
             foreach (IStellarEntity stellarEntity in list2.Where <IStellarEntity>((Func <IStellarEntity, bool>)(x => LegacyStarMap.IsRandomOrbitName(x.Params))))
             {
                 stellarEntity.Params.Name = string.Format("{0}{1}", (object)planet.Params.Name, (object)(char)(65 + num2));
                 ++num2;
             }
         }
         List <IStellarEntity> list3 = starSystem.GetAsteroidBelts().ToList <IStellarEntity>();
         list3.Sort(new Comparison <IStellarEntity>(LegacyStarMap.CompareByOrbitNumber));
         int num3 = 0;
         foreach (IStellarEntity stellarEntity in list3)
         {
             ++num3;
             if (LegacyStarMap.IsRandomOrbitName(stellarEntity.Params))
             {
                 stellarEntity.Params.Name = string.Format("{0} " + App.Localize("@UI_BELT_NAME_MOD") + " {1}", (object)starSystem.DisplayName, (object)num3);
             }
         }
     }
 }
Пример #2
0
        public void AddInstance(GameDatabase gamedb, AssetDatabase assetdb, NamesPool namesPool)
        {
            if (this.NumInstances >= VonNeumann.MaxVonNeumanns)
            {
                return;
            }
            int val1 = this._outlyingStars.Count <KeyValuePair <StarSystemInfo, Vector3> >();

            if (val1 == 0)
            {
                return;
            }
            Random safeRandom = App.GetSafeRandom();
            int    val2       = 5;
            float  num1       = 5f;
            KeyValuePair <StarSystemInfo, Vector3> outlyingStar = this._outlyingStars[safeRandom.Next(Math.Min(val1, val2))];

            this._outlyingStars.Remove(outlyingStar);
            Vector3 origin = outlyingStar.Key.Origin + Vector3.Normalize(outlyingStar.Value) * num1;

            App.Log.Trace(string.Format("Found von neumann homeworld target - Picked System = {0}   Target Coords = {1}", (object)outlyingStar.Key.Name, (object)origin), "game");
            StellarClass stellarClass = StarHelper.ChooseStellarClass(safeRandom);

            this.HomeWorldSystemId = gamedb.InsertStarSystem(new int?(), namesPool.GetSystemName(), new int?(), stellarClass.ToString(), origin, false, true, new int?());
            gamedb.GetStarSystemInfo(this.HomeWorldSystemId);
            int         num2          = 5;
            float       starOrbitStep = StarSystemVars.Instance.StarOrbitStep;
            float       num3          = StarHelper.CalcRadius(stellarClass.Size) + (float)num2 * ((float)num2 * 0.1f * starOrbitStep);
            float       x             = Ellipse.CalcSemiMinorAxis(num3, 0.0f);
            OrbitalPath path          = new OrbitalPath();

            path.Scale             = new Vector2(x, num3);
            path.InitialAngle      = 0.0f;
            this.HomeWorldPlanetId = gamedb.InsertPlanet(new int?(), this.HomeWorldSystemId, path, "VonNeumonia", "normal", new int?(), 0.0f, 0, 0, 5f);
            PlanetInfo planetInfo = gamedb.GetPlanetInfo(this.HomeWorldPlanetId);

            path              = new OrbitalPath();
            path.Scale        = new Vector2(15f, 15f);
            path.Rotation     = new Vector3(0.0f, 0.0f, 0.0f);
            path.DeltaAngle   = 10f;
            path.InitialAngle = 10f;
            VonNeumannInfo vi = new VonNeumannInfo()
            {
                SystemId             = this.HomeWorldSystemId,
                OrbitalId            = this.HomeWorldPlanetId,
                Resources            = assetdb.GlobalVonNeumannData.StartingResources,
                ConstructionProgress = 0
            };
            float radius = StarSystemVars.Instance.SizeToRadius(planetInfo.Size);

            vi.FleetId = new int?(gamedb.InsertFleet(this.PlayerId, 0, vi.SystemId, vi.SystemId, "Von Neumann NeoBerserker", FleetType.FL_NORMAL));
            float  num4    = radius + 2000f;
            float  num5    = 1000f;
            Matrix matrix1 = gamedb.GetOrbitalTransform(this.HomeWorldPlanetId);

            matrix1 = Matrix.CreateWorld(matrix1.Position, Vector3.Normalize(matrix1.Position), Vector3.UnitY);
            Matrix matrix2 = matrix1;

            matrix2.Position = matrix2.Position + matrix2.Forward * num4 - matrix2.Right * num5;
            for (int index = 0; index < 3; ++index)
            {
                int shipID = gamedb.InsertShip(vi.FleetId.Value, VonNeumann.StaticShipDesigns[VonNeumann.VonNeumannShipDesigns.NeoBerserker].DesignId, null, (ShipParams)0, new int?(), 0);
                gamedb.UpdateShipSystemPosition(shipID, new Matrix?(matrix2));
                matrix2.Position += matrix2.Right * num5;
            }
            Random random     = new Random();
            float  radians1   = (float)((random.CoinToss(0.5) ? -1.0 : 1.0) * 0.785398185253143);
            float  radians2   = random.NextInclusive(0.0f, 6.283185f);
            Matrix rotationY1 = Matrix.CreateRotationY(radians1);
            Matrix rotationY2 = Matrix.CreateRotationY(radians2);
            Matrix world      = Matrix.CreateWorld(rotationY1.Forward * (matrix1.Position.Length * 0.75f), rotationY2.Forward, Vector3.UnitY);

            VonNeumann.VonNeumannShipDesigns index1 = (VonNeumann.VonNeumannShipDesigns)random.NextInclusive(21, 23);
            int shipID1 = gamedb.InsertShip(vi.FleetId.Value, VonNeumann.StaticShipDesigns[index1].DesignId, null, (ShipParams)0, new int?(), 0);

            gamedb.UpdateShipSystemPosition(shipID1, new Matrix?(world));
            world.Position -= world.Right * 1000f;
            int shipID2 = gamedb.InsertShip(vi.FleetId.Value, VonNeumann.StaticShipDesigns[VonNeumann.VonNeumannShipDesigns.Moon].DesignId, null, (ShipParams)0, new int?(), 0);

            gamedb.UpdateShipSystemPosition(shipID2, new Matrix?(world));
            world = Matrix.CreateWorld(world.Position + world.Right * 1000f * 2f, -world.Forward, Vector3.UnitY);
            int shipID3 = gamedb.InsertShip(vi.FleetId.Value, VonNeumann.StaticShipDesigns[VonNeumann.VonNeumannShipDesigns.Moon].DesignId, null, (ShipParams)0, new int?(), 0);

            gamedb.UpdateShipSystemPosition(shipID3, new Matrix?(world));
            gamedb.InsertVonNeumannInfo(vi);
            ++this.NumInstances;
        }