Exemplo n.º 1
0
        public void Create(Dictionary <string, object> config)
        {
            Logger.Log("Recieved API request to create planet " + (string)config["Name"] + " at position " + (Vector3)config["Position"], Logger.LogType.Log);
            var planetConfig = new PlanetConfig
            {
                Name                = (string)config["Name"],
                Position            = new MVector3(((Vector3)config["Position"]).x, ((Vector3)config["Position"]).y, ((Vector3)config["Position"]).z),
                OrbitAngle          = (int)config["OrbitAngle"],
                IsMoon              = (bool)config["IsMoon"],
                AtmoEndSize         = (float)config["AtmoEndSize"],
                PrimaryBody         = (string)config["PrimaryBody"],
                HasClouds           = (bool)config["HasClouds"],
                TopCloudSize        = (float)config["TopCloudSize"],
                BottomCloudSize     = (float)config["BottomCloudSize"],
                TopCloudTint        = new MColor32(((Color32)config["TopCloudTint"]).r, ((Color32)config["TopCloudTint"]).g, ((Color32)config["TopCloudTint"]).b, ((Color32)config["TopCloudTint"]).a),
                BottomCloudTint     = new MColor32(((Color32)config["BottomCloudTint"]).r, ((Color32)config["BottomCloudTint"]).g, ((Color32)config["BottomCloudTint"]).b, ((Color32)config["BottomCloudTint"]).a),
                HasWater            = (bool)config["HasWater"],
                WaterSize           = (float)config["WaterSize"],
                HasRain             = (bool)config["HasRain"],
                HasGravity          = (bool)config["HasGravity"],
                SurfaceAcceleration = (float)config["SurfaceAcceleration"],
                HasMapMarker        = (bool)config["HasMapMarker"],
                HasFog              = (bool)config["HasFog"],
                FogTint             = new MColor32(((Color32)config["FogTint"]).r, ((Color32)config["FogTint"]).g, ((Color32)config["FogTint"]).b, ((Color32)config["FogTint"]).a),
                FogDensity          = (float)config["FogDensity"],
                HasGround           = (bool)config["HasGround"],
                GroundSize          = (float)config["GroundSize"],
                IsTidallyLocked     = (bool)config["IsTidallyLocked"],
                LightTint           = new MColor32(((Color32)config["LightTint"]).r, ((Color32)config["LightTint"]).g, ((Color32)config["LightTint"]).b, ((Color32)config["LightTint"]).a),
            };

            Main.BodyList.Add(new MarshmallowBody(planetConfig));

            Main.helper.Events.Unity.RunWhen(() => Locator.GetCenterOfTheUniverse() != null, () => Main.CreateBody(planetConfig));
        }
Exemplo n.º 2
0
    void SetMeteorites(ref PlanetConfig _p_config)
    {
        // Meteorites
        _p_config.num_rings = (int)Random.Range(1, p_limits.max_rings);

        if (_p_config.num_rings != 0)
        {
            _p_config.ring_spacer = Random.Range(p_limits.min_ring_spacer, p_limits.max_ring_spacer);

            _p_config.num_meteorites = (int)Random.Range(p_limits.min_meteorites, p_limits.max_meteorites) * (1 + (int)_p_config.size / 2);

            // Set new ring limits based on size
            float min_ring_distance = (float)(_p_config.diameter / 2) + p_limits.min_ring_distance;
            float max_ring_distance = (float)(_p_config.diameter / 2) + p_limits.max_ring_distance;

            _p_config.meteorite_min_dis = min_ring_distance;
            _p_config.meteorite_max_dis = max_ring_distance;

            _p_config.meteorite_speed      = Random.Range(p_limits.meteorite_min_speed, p_limits.meteorite_max_speed);
            _p_config.meteorite_speed_diff = Random.Range(p_limits.meteorite_speed_diff_min, p_limits.meteorite_speed_diff_max);

            _p_config.meteorite_size = Random.Range(p_limits.meteorite_min_size - (int)_p_config.size / 20, p_limits.meteorite_max_size);


            // Decrese meteorite_size the larger the planet
            _p_config.meteorite_size = _p_config.meteorite_size / (1 + ((float)_p_config.size / 5));

            float div = (1 + ((float)_p_config.size / 5));


            _p_config.meteorite_size_variation = Random.Range(0, _p_config.meteorite_size / 2);
        }
    }
Exemplo n.º 3
0
        /// <summary>
        /// calculate noise on the surface of the planet
        /// </summary>
        public static void CreateTerrainSurfacePoints(this SurfaceArea surfaceArea, PlanetConfig cfg, int extraLevelOfDetail)
        {
            surfaceArea.Points = new SurfacePoint[PlanetConfig.PointSize, PlanetConfig.PointSize];
            int size = PlanetConfig.PointSize;// (mode == UnitRenderer.RenderMode.Good ? PlanetConfig.PointSize : PlanetConfig.LowPolyTexSize);

            var sp = new float[size];
            var cp = new float[size];

            for (int p = 0; p < size; p++)
            {
                var phi = surfaceArea.GetPhi((float)p / size);
                sp[p] = Mathf.Sin(phi);
                cp[p] = Mathf.Cos(phi);
            }

            for (int t = 0; t < size; t++)
            {
                //for faster calc
                float tetha = surfaceArea.GetTetha((float)t / size);
                float st    = Mathf.Sin(tetha);
                float ct    = Mathf.Cos(tetha);

                for (int p = 0; p < size; p++)
                {
                    //float phi = Surface.GetPhi((float)p / size);
                    //float sp = Mathf.Sin(phi);
                    //float cp = Mathf.Cos(phi);

                    //calc spherical positions
                    var xyz = new VectorXYZ(sp[p] * ct, cp[p], sp[p] * st);
                    surfaceArea.Points[t, p] = PerlinNoiseGenerator.SurfacePerlinNoise(xyz, cfg, extraLevelOfDetail);
                }
            }
        }
Exemplo n.º 4
0
    void SetResources(ref PlanetConfig _p_config)
    {
        if (_p_config.type == PlanetConfig.PlanetType.Solid)
        {
            // Set Land color (l1)
            _p_config.l1_col = p_resources.m_resources [(int)PlanetResources.Matter.Vegetation].color;

            // Set Ocean color (l2)
            _p_config.l2_col = p_resources.m_resources [(int)PlanetResources.Matter.Water].color;

            // Set Sand color (l3)
            _p_config.l3_col = p_resources.m_resources [(int)PlanetResources.Matter.Sand].color;
        }
        else if (_p_config.type == PlanetConfig.PlanetType.Gas)
        {
            Color incol = new Color(0.1f, 0.1f, 0.1f);

            // Set Land color (l1)
            _p_config.l1_col = p_resources.g_resources [(int)PlanetResources.Gas.Methane].color;

            // Set Ocean color (l2)
            _p_config.l2_col = p_resources.g_resources [(int)PlanetResources.Gas.Methane].color + incol;

            // Set Sand color (l3)
            _p_config.l3_col = p_resources.g_resources [(int)PlanetResources.Gas.Methane].color + incol + incol;
        }
    }
    public void ReplacePlanetConfig(PlanetConfig newValue)
    {
        var index     = GameComponentsLookup.PlanetConfig;
        var component = (PlanetConfigComponent)CreateComponent(index, typeof(PlanetConfigComponent));

        component.Value = newValue;
        ReplaceComponent(index, component);
    }
Exemplo n.º 6
0
 public void AddConf(PlanetConfig conf)
 {
     //	Debug.LogError ("conf.id" + conf.id);
     if (Confs.ContainsKey(conf.Id))
     {
         return;
     }
     Confs.Add(conf.Id, conf);
 }
Exemplo n.º 7
0
        internal static SurfacePoint SurfacePerlinNoise(VectorXYZ xyz, PlanetConfig cfg, int extraLod = 0)
        {
            float noise = 0;

            for (int i = 0; i < cfg.LOD + extraLod; i++)
            {
                noise += (PerlinNoise(xyz * cfg.LodConfigs[i].frequency + cfg.NoiseOffset) * cfg.LodConfigs[i].magnitude);
            }
            float ppnoise = cfg.PostProcess(noise);

            return(new SurfacePoint(xyz, ppnoise, noise, cfg));
        }
    public GameEntity SetPlanetConfig(PlanetConfig newValue)
    {
        if (hasPlanetConfig)
        {
            throw new Entitas.EntitasException("Could not set PlanetConfig!\n" + this + " already has an entity with PlanetConfigComponent!",
                                               "You should check if the context already has a planetConfigEntity before setting it or use context.ReplacePlanetConfig().");
        }
        var entity = CreateEntity();

        entity.AddPlanetConfig(newValue);
        return(entity);
    }
    public void ReplacePlanetConfig(PlanetConfig newValue)
    {
        var entity = planetConfigEntity;

        if (entity == null)
        {
            entity = SetPlanetConfig(newValue);
        }
        else
        {
            entity.ReplacePlanetConfig(newValue);
        }
    }
Exemplo n.º 10
0
    // Generate new planet
    public void generatePlanet(PlanetConfig _p_config)
    {
        // Add the planet gen componant
        PlanetGen gen = gameObject.AddComponent <PlanetGen>() as PlanetGen;

        gen.GeneratePlanet(_p_config);

        // Set material colors in shader
        GetComponent <Renderer>().material.SetColor("LandCol", _p_config.l1_col);
        GetComponent <Renderer>().material.SetColor("OceanCol", _p_config.l2_col);
        GetComponent <Renderer>().material.SetColor("SandCol", _p_config.l3_col);
        GetComponent <Renderer>().material.SetColor("MountainsCol", _p_config.l4_col);
        GetComponent <Renderer>().material.SetColor("NightLightsCol", _p_config.nightlights_col);
    }
Exemplo n.º 11
0
 void Start()
 {
     totalPopulation             = 0;
     planetList                  = new Dictionary <Role_Type, int>();
     planetList[Role_Type.WATER] = 0;
     planetList[Role_Type.FIRE]  = 0;
     planetList[Role_Type.IRON]  = 0;
     planetList[Role_Type.TREE]  = 0;
     waterTime = 0f;
     ironTime  = 0f;
     treeTime  = 0f;
     fireTime  = 0f;
     aLauncher = GetComponent <ArcReactor_Launcher>();
     config    = PlanetConfManager.Instance.GetConfById(id);
 }
Exemplo n.º 12
0
    private void CreateHeightMap(PlanetConfig _p_config)
    {
        Debug.Log("Creating planet heightmap", gameObject);

        //// Create base map
        TextureGen base_gen = new TextureGen();

        base_gen.frequency = Random.Range((float)_p_config.size, 1.0f + (float)_p_config.size + (float)_p_config.size * 2);

        // Set the texture
        GetComponent <Renderer>().material.SetTexture("_DiffuseTexture", base_gen.getTexture());

        //// Create civ map
        CivTexGen civ_gen = new CivTexGen();

        GetComponent <Renderer>().material.SetTexture("_CivTexture", civ_gen.getTexture(base_gen.getTexture(), _p_config.has_civ, _p_config.density));
    }
Exemplo n.º 13
0
        public SurfacePoint(VectorXYZ xyz, float value, float noise, PlanetConfig cfg)
        {
            RawNoise = noise;
            Value    = value;
            HasValue = true;

            XYZ     = xyz;
            Vertice = xyz * (PlanetConfig.PlanetRadius + cfg.PlanetSurfaceMaxHeight * value);
            if (value < cfg.OceanLevel)
            {
                FlatOceanVertice = xyz * (PlanetConfig.PlanetRadius + cfg.PlanetSurfaceMaxHeight * cfg.OceanLevel);
            }
            else
            {
                FlatOceanVertice = Vertice;
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// calculate noise on the surface of the planet
        /// </summary>
        public static SurfacePoint[,] CreatePlanetSurfacePoints(PlanetConfig cfg)
        {
            int X             = 1 + PlanetConfig.PointSize;
            int Y             = 1 + PlanetConfig.PointSize / 2;
            var surfacePoints = new SurfacePoint[X, Y];

            var sp = new float[Y];
            var cp = new float[Y];

            for (int p = 0; p < Y; p++)
            {
                var phi = Mathf.PI * 2 * p / PlanetConfig.PointSize;
                sp[p] = Mathf.Sin(phi);
                cp[p] = Mathf.Cos(phi);
            }

            for (int t = 0; t < X; t++)
            {
                //for faster calc
                var   tetha = Mathf.PI * 2 * t / PlanetConfig.PointSize;
                float st    = Mathf.Sin(tetha);
                float ct    = Mathf.Cos(tetha);

                for (int p = 0; p < Y; p++)
                {
                    //var phi = (Mathf.PI * 2) * (float)p / PlanetConfig.PointSize;
                    //float sp = Mathf.Sin(phi);
                    //float cp = Mathf.Cos(phi);

                    //calc spherical positions
                    var xyz = new VectorXYZ(sp[p] * ct, cp[p], sp[p] * st);
                    surfacePoints[t, p] = SurfacePerlinNoise(xyz, cfg);
                }
            }

            return(surfacePoints);
        }
Exemplo n.º 15
0
        public Vector3 CorrectMovement(Vector3 objectPosition, Vector3 movementDirection)
        {
            lock (lockObj)
            {
                Vector3 updatedDirection = movementDirection;

                foreach (var planet in _planetContainer.Planets)
                {
                    PlanetConfig config = planet.Data;

                    if (config.PlayerPlanet)
                    {
                        continue;
                    }

                    Vector3 planetPosition = planet.transform.position;
                    float   distance       = Vector3.Distance(objectPosition, planetPosition);

                    if (distance > config.InfluenceGravityRadius)
                    {
                        continue;
                    }

                    //calculate force
                    float coef = (1f / config.InfluenceGravityRadius) * distance;
                    coef = config.GravityForcePerDistance.Evaluate(coef);
                    float force = config.Gravity * coef;

                    //calculate planet vector
                    Vector3 directionToPlanet = planetPosition - objectPosition;
                    updatedDirection += Vector3.Normalize(directionToPlanet) * force;
                }

                return(updatedDirection);
            }
        }
Exemplo n.º 16
0
    // Update is called once per frame
    void CreatePlanet(int _seed)
    {
        // Create planet system
        GameObject      planet_system = (GameObject)Instantiate(Resources.Load("PlanetSystem"));
        PlanetarySystem psc           = planet_system.GetComponent(typeof(PlanetarySystem)) as PlanetarySystem;

        // Planet
        PlanetConfig p_config = new PlanetConfig();

        // Name
        p_config.name = "p" + seed.ToString();

        // Size
        p_config.diameter = Random.Range(p_limits.diameter_min_size, p_limits.diameter_max_size);
        p_config.size     = ClassifySize(p_config.diameter);

        // Atmosphere
        p_config.temperature = Random.Range(p_limits.temperature_min, p_limits.temperature_max);
        p_config.humidity    = Random.Range(p_limits.humidity_min, p_limits.humidity_max);

        // Classification (type)
        if (p_config.size >= PlanetConfig.SizeClassification.Large)
        {
            p_config.type = PlanetConfig.PlanetType.Gas;
        }
        else
        {
            p_config.type = PlanetConfig.PlanetType.Solid;
        }

        // Population (if planet solid)
        if (p_config.type == PlanetConfig.PlanetType.Solid)
        {
            p_config.has_civ = true;

            if (p_config.has_civ == true)
            {
                p_config.density = Random.Range(0.01f, p_limits.max_density);

                int max_pop = (int)((p_config.density * 1000) * 1.0 + (float)p_config.size) * 10000;
                int min_pop = (int)((p_config.density * 100) * 1.0 + (float)p_config.size) * 1000;

                p_config.population = Random.Range(min_pop, max_pop);
            }
            else
            {
                p_config.density    = 0.0f;
                p_config.population = 0;
            }
        }
        else
        {
            p_config.has_civ    = false;
            p_config.density    = 0.0f;
            p_config.population = 0;
        }

        if (p_config.type == PlanetConfig.PlanetType.Solid)
        {
            // Clouds
            p_config.has_clouds      = true;
            p_config.cloud_elevation = (4 - (float)p_config.size) / 5;
            p_config.cloud_coverage  = Random.Range(0, 1.0f);
        }
        else
        {
            p_config.has_clouds = false;
        }

        // Set Meteorites
        SetResources(ref p_config);

        // Set Meteorites
        SetMeteorites(ref p_config);

        // Set nightlights color
        p_config.nightlights_col = new Color(0.8f, 0.6f, 0.1f);

        // Initiate planet
        psc.Initiate(_seed, p_config);

        // Update stats in GUI
        StatManager s_manager = GameObject.Find("UiUpdater").GetComponent(typeof(StatManager)) as StatManager;

        s_manager.SetStats(p_config);
    }
Exemplo n.º 17
0
 // Update is called once per frame
 public void GeneratePlanet(PlanetConfig _p_config)
 {
     // Create heightmap
     CreateHeightMap(_p_config);
 }
Exemplo n.º 18
0
    // Use this for initialization
    public void Initiate(int _seed, PlanetConfig _p_config)
    {
        // Set the config
        p_config = _p_config;

        // Set random seed
        seed = _seed;
        Random.InitState(_seed);

        // Get planet object
        GameObject planet = this.gameObject.transform.Find("PlanetMain").gameObject;

        // Set size for planet
        float p_size = _p_config.diameter;

        planet.transform.localScale = new Vector3(p_size, p_size, p_size);

        // Create clouds and set size
        if (_p_config.has_clouds)
        {
            GameObject clouds = (GameObject)Instantiate(Resources.Load("Clouds"));
            clouds.transform.parent = transform;

            // Set size relative to planet size
            float c_size = p_size + _p_config.cloud_elevation;
            clouds.transform.localScale = new Vector3(c_size, c_size, c_size);
        }

        // If we have at least one ring then create meteorites
        if (_p_config.num_rings != 0)
        {
            // Set size of meteorites
            meteorites = new GameObject[_p_config.num_meteorites];

            // Create meteorites
            for (int i = 0; i < _p_config.num_meteorites; i++)
            {
                GameObject m = (GameObject)Instantiate(Resources.Load("Meteorite"));
                m.transform.parent = transform;

                Meteorite meteorite = m.GetComponent(typeof(Meteorite)) as Meteorite;

                // Distance from planet
                float distance = _p_config.meteorite_min_dis + Random.Range(0.0f, _p_config.meteorite_max_dis - _p_config.meteorite_min_dis);

                // Move into ring
                if (_p_config.num_rings > 1)
                {
                    int ring = (int)Mathf.Round(Random.value * _p_config.num_rings);
                    meteorite.ring_id = ring;

                    if (ring > 1)
                    {
                        distance += ring * _p_config.ring_spacer;
                    }
                }

                // Set size
                float size = _p_config.meteorite_size + Random.Range(0.0f, _p_config.meteorite_size_variation);
                meteorite.transform.localScale = new Vector3(size, size, size);

                meteorite.distance_from_planet = distance;

                meteorite.pos = Random.Range(1.0f, 100.0f);

                meteorites [i] = m;
            }
        }

        // Generate planet
        Planet planet_c = planet.GetComponent(typeof(Planet)) as Planet;

        planet_c.generatePlanet(_p_config);
    }
Exemplo n.º 19
0
 public void SetStats(PlanetConfig _p_config)
 {
     planet_name.text = "NAME: " + _p_config.name.ToUpper();
     population.text  = "POPULATION: " + _p_config.population;
     size.text        = "SIZE: " + _p_config.size.ToString().ToUpper() + " (" + (_p_config.diameter) + ")";
 }
Exemplo n.º 20
0
        public ActionResult Configure()
        {
            var jsonConfSystem = db.Configuration.Find(SOLAR_SYSTEM_CONF);
            var jsonConfPlanet = db.Configuration.Find(PLANET_CONF);

            SolarSystemConfig solarSystemConfig = new SolarSystemConfig();
            PlanetConfig      planetConfig      = new PlanetConfig();

            if (jsonConfSystem != null && jsonConfPlanet != null)
            {
                solarSystemConfig = JsonConvert.DeserializeObject <SolarSystemConfig>(jsonConfSystem.Data);
                planetConfig      = JsonConvert.DeserializeObject <PlanetConfig>(jsonConfPlanet.Data);
            }
            else
            {
                jsonConfSystem = new ConfigJSON()
                {
                    Key  = SOLAR_SYSTEM_CONF,
                    Data = JsonConvert.SerializeObject(solarSystemConfig)
                };

                jsonConfPlanet = new ConfigJSON()
                {
                    Key  = PLANET_CONF,
                    Data = JsonConvert.SerializeObject(planetConfig)
                };

                db.Configuration.Add(jsonConfSystem);
                db.Configuration.Add(jsonConfPlanet);

                db.SaveChanges();
            }

            List <SelectListItem> res = new List <SelectListItem>();

            res.Add(new SelectListItem {
                Value = ResourceType.ENERGY.ToString(), Text = "Energie"
            });
            res.Add(new SelectListItem {
                Value = ResourceType.OXYGEN.ToString(), Text = "Oxygène"
            });
            res.Add(new SelectListItem {
                Value = ResourceType.STEEL.ToString(), Text = "Acier"
            });
            res.Add(new SelectListItem {
                Value = ResourceType.URANIUM.ToString(), Text = "Uranium"
            });

            List <SelectListItem> builds = new List <SelectListItem>();

            builds.Add(new SelectListItem {
                Value = ResourceType.ENERGY.ToString(), Text = "Centrale à énergie"
            });
            builds.Add(new SelectListItem {
                Value = ResourceType.OXYGEN.ToString(), Text = "Générateur d'oxygène"
            });
            builds.Add(new SelectListItem {
                Value = ResourceType.STEEL.ToString(), Text = "Générateur d'acier"
            });
            builds.Add(new SelectListItem {
                Value = ResourceType.URANIUM.ToString(), Text = "Générateur d'uranium"
            });

            ConfigurationViewModel cvm = new ConfigurationViewModel {
                SolarSystemConfig = solarSystemConfig, PlanetConfig = planetConfig, Buildings = builds, Resources = res
            };

            return(View(cvm));
        }