Esempio n. 1
0
        public GameState()
        {
            Timer = new Stopwatch();
            var ug = new UniverseGen();

            UniverseLive   = new HashSet <Place>(ug.MakeUniverse());
            UniverseFrozen = new HashSet <Place>();
            Players        = new HashSet <Player>();
            LastFrameTime  = 0;
        }
Esempio n. 2
0
    // Use this for initialization
    void Start()
    {
        var ug = new UniverseGen();
        var p  = ug.MakeRandomStarSystem(0);

        Debug.Log(p);
        var client = new TcpClient(serverName, serverPort);

        Debug.Log(string.Format("Client connected: {0}", client.Connected));
        var stream = client.GetStream();

        Debug.Log("Grawr!");
        var wossname = BsonDocument.ReadFrom(stream);
        var pl       = DecodeMessage.Place(wossname);

        Debug.Log(pl);

        var msg = EncodeMessage.PlayerEnteredSystem();

        msg.WriteTo(stream);
        //var place = DecodeMessage.Place(wossname);
        //Debug.Log (place.ToString());
    }
Esempio n. 3
0
            public static void exportSeed(int seed)
            {
                UnityEngine.Debug.Log("exportSeed:" + seed);
                // set up memoryStream to write output to
                memoryStream = new MemoryStream();
                streamWriter = new StreamWriter((Stream)memoryStream);
                string path = seedExporterDir + "seed_" + seed + ".json";

                // create new galaxy
                GameDesc gameDesc = new GameDesc();

                gameDesc.SetForNewGame(UniverseGen.algoVersion, seed, 64, 1, 1f);
                GalaxyData galaxy = UniverseGen.CreateGalaxy(gameDesc);

                // dump to json
                streamWriter.Write("{\"meta\":{" +
                                   "\"gameVersion\":\"" + GameConfig.gameVersion.ToFullString() + "\"" +
                                   ",\"toolVersion\":\"0.0.1.0\"" +
                                   ",\"seed\":" + seed +
                                   ",\"starCount\":" + galaxy.starCount +
                                   ",\"birthPlanetId\":" + galaxy.birthPlanetId +
                                   ",\"birthStarId\":" + galaxy.birthStarId +
                                   ",\"habitableCount\":" + galaxy.habitableCount +
                                   "},");         // opens main dict
                streamWriter.Write("\"star\":{"); // open star dict
                for (int i = 0; i < galaxy.stars.Length; i++)
                {
                    if (i > 0)
                    {
                        streamWriter.Write(",");
                    }
                    var star = galaxy.stars[i];
                    streamWriter.Write("\"" + star.name + "\":{" +
                                       "\"seed\":" + star.seed +
                                       ",\"index\":" + star.index +
                                       ",\"id\":" + star.id +
                                       ",\"name\":\"" + star.name + "\"" +
                                       ",\"position\":{\"x\":" + star.position.x + ",\"y\":" + star.position.y + ",\"z\":" + star.position.z + "}" +
                                       ",\"uPosition\":{\"x\":" + star.uPosition.x + ",\"y\":" + star.uPosition.y + ",\"z\":" + star.uPosition.z + "}" +
                                       ",\"mass\":" + star.mass +
                                       ",\"lifetime\":" + star.lifetime +
                                       ",\"age\":" + star.age +
                                       ",\"type\":" + (int)star.type +
                                       ",\"temperature\":" + star.temperature +
                                       ",\"spectr\":" + (int)star.spectr +
                                       ",\"classFactor\":" + star.classFactor +
                                       ",\"color\":" + star.color +
                                       ",\"luminosity\":" + star.luminosity +
                                       ",\"radius\":" + star.radius +
                                       ",\"acdiskRadius\":" + star.acdiskRadius +
                                       ",\"habitableRadius\":" + star.habitableRadius +
                                       ",\"lightBalanceRadius\":" + star.lightBalanceRadius +
                                       ",\"dysonRadius\":" + star.dysonRadius +
                                       ",\"orbitScaler\":" + star.orbitScaler +
                                       ",\"asterBelt1OrbitIndex\":" + star.asterBelt1OrbitIndex +
                                       ",\"asterBelt2OrbitIndex\":" + star.asterBelt2OrbitIndex +
                                       ",\"asterBelt1Radius\":" + star.asterBelt1Radius +
                                       ",\"asterBelt2Radius\":" + star.asterBelt2Radius +
                                       ",\"planetCount\":" + star.planetCount +
                                       ",\"level\":" + star.level +
                                       ",\"resourceCoef\":" + star.resourceCoef +
                                       ",\"planet\":{"
                                       ); // initial data, open planet[]
                    firstPlanet = true;
                    for (int j = 0; j < star.planets.Length; j++)
                    {
                        exportStar(star.planets[j]);
                    }
                    streamWriter.Write("}}"); // close planet[] and star dicts
                }
                streamWriter.Write("}");      // close star[] dict

                streamWriter.Write("}");      // closes main dict
                // free the galaxy
                galaxy.Free();

                // close the stream, after flushing it.
                streamWriter.Flush();
                if (memoryStream != null && memoryStream.Length > 0)
                {
                    UnityEngine.Debug.Log("DSP_SeedExporter: dumping to: " + path);
                    using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
                    {
                        memoryStream.WriteTo(fileStream);
                        fileStream.Flush();
                        fileStream.Close();
                        streamWriter.Close();
                        memoryStream.Close();
                        memoryStream = null;
                    }
                }
            }
        public static GalaxyData CreateGalaxy(GameDesc gameDesc)
        {
            int galaxyAlgo = gameDesc.galaxyAlgo;
            int galaxySeed = gameDesc.galaxySeed;
            int num        = gameDesc.starCount;

            if (galaxyAlgo < 20200101 || galaxyAlgo > 20591231)
            {
                throw new Exception("Wrong version of unigen algorithm!");
            }
            System.Random random = new System.Random(galaxySeed);
            int           seed   = random.Next();

            num = Traverse.Create(typeof(UniverseGen)).Method("GenerateTempPoses", seed, num, 4, 2.0, 2.3, 3.5, 0.18).GetValue <int>();
            GalaxyData galaxyData = new GalaxyData();

            galaxyData.seed      = galaxySeed;
            galaxyData.starCount = num;
            galaxyData.stars     = new StarData[num];
            Assert.Positive(num);
            if (num <= 0)
            {
                return(galaxyData);
            }
            float num2  = (float)random.NextDouble();
            float num3  = (float)random.NextDouble();
            float num4  = (float)random.NextDouble();
            float num5  = (float)random.NextDouble();
            int   num6  = Mathf.CeilToInt(0.01f * (float)num + num2 * 0.3f);
            int   num7  = Mathf.CeilToInt(0.01f * (float)num + num3 * 0.3f);
            int   num8  = Mathf.CeilToInt(0.016f * (float)num + num4 * 0.4f);
            int   num9  = Mathf.CeilToInt(0.013f * (float)num + num5 * 1.4f);
            int   num10 = num - num6;
            int   num11 = num10 - num7;
            int   num12 = num11 - num8;
            int   num13 = (num12 - 1) / num9;
            int   num14 = num13 / 2;

            for (int i = 0; i < num; i++)
            {
                int         seed2      = random.Next();
                ESpectrType needSpectr = ESpectrType.X;
                if (i == 3)
                {
                    needSpectr = ESpectrType.M;
                }
                else if (i == num12 - 1)
                {
                    needSpectr = ESpectrType.O;
                }
                EStarType needtype = EStarType.MainSeqStar;
                if (i % num13 == num14)
                {
                    needtype = EStarType.GiantStar;
                }
                if (i >= num10)
                {
                    needtype = EStarType.BlackHole;
                }
                else if (i >= num11)
                {
                    needtype = EStarType.NeutronStar;
                }
                else if (i >= num12)
                {
                    needtype = EStarType.WhiteDwarf;
                }
                galaxyData.stars[i] = StarGen.CreateStar(galaxyData, Traverse.Create(typeof(UniverseGen)).Field("tmp_poses").GetValue <List <VectorLF3> >()[i], i + 1, seed2, needtype, needSpectr);
            }
            AstroPose[] astroPoses = galaxyData.astroPoses;
            StarData[]  stars      = galaxyData.stars;
            for (int j = 0; j < galaxyData.astroPoses.Length; j++)
            {
                astroPoses[j].uRot.w     = 1f;
                astroPoses[j].uRotNext.w = 1f;
            }
            for (int k = 0; k < num; k++)
            {
                StarGen.CreateStarPlanets(galaxyData, stars[k], gameDesc);
                astroPoses[stars[k].id * 100].uPos    = (astroPoses[stars[k].id * 100].uPosNext = stars[k].uPosition);
                astroPoses[stars[k].id * 100].uRot    = (astroPoses[stars[k].id * 100].uRotNext = Quaternion.identity);
                astroPoses[stars[k].id * 100].uRadius = stars[k].physicsRadius;
            }
            galaxyData.UpdatePoses(0.0);
            galaxyData.birthPlanetId = 0;
            if (num > 0)
            {
                StarData starData = stars[0];
                for (int l = 0; l < starData.planetCount; l++)
                {
                    PlanetData planetData = starData.planets[l];
                    ThemeProto themeProto = LDB.themes.Select(planetData.theme);
                    if (themeProto != null && themeProto.Distribute == EThemeDistribute.Birth)
                    {
                        galaxyData.birthPlanetId = planetData.id;
                        galaxyData.birthStarId   = starData.id;
                        CustomBirthPlanet(planetData);
                        break;
                    }
                }
            }
            Assert.Positive(galaxyData.birthPlanetId);
            for (int m = 0; m < num; m++)
            {
                StarData starData2 = galaxyData.stars[m];
                for (int n = 0; n < starData2.planetCount; n++)
                {
                    PlanetData      planet          = starData2.planets[n];
                    PlanetAlgorithm planetAlgorithm = PlanetModelingManager.Algorithm(planet);
                    planetAlgorithm.GenerateVeins(true);
                }
            }
            UniverseGen.CreateGalaxyStarGraph(galaxyData);
            return(galaxyData);
        }