Example #1
0
        /// <summary>
        /// 获取节气所在日
        /// </summary>
        /// <param name="year">年份</param>
        /// <param name="solar">节气</param>
        /// <returns>日期</returns>
        private int GetChineseTwentyFourDay(int year, SolarModel solar)
        {
            int centuryIndex = year <= 2000 ? 0 : 1;
            int y            = year % 100;// 步骤1:取年分的后两位数

            if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
            {   // 闰年
                if (new int[] { 0, 1, 2, 3 }.Contains(_solarModels.IndexOf(solar)))
                {
                    // 注意:凡闰年3月1日前闰年数要减一,
                    // 即:L=[(Y-1)/4],因为小寒、大寒、立春、雨水这两个节气都小于3月1日,
                    // 所以 y = y-1
                    y = y - 1;// 步骤2
                }
            }

            double centuryValue = solar.ThrottleValues[centuryIndex];
            int    dateNum      = (int)(y * D + centuryValue) - (int)(y / 4);// 步骤3,使用公式[Y*D+C]-L计算

            if (solar.Offsets.ContainsKey(year))
            {
                dateNum += solar.Offsets[year];
            }
            return(dateNum);
        }
    public static StationModel CreateStation(string name, SolarModel star, int parentIndex, Orbit orbit, IdentityModel owner, CreatureModel captain)
    {
        StationModel model = new StationModel();

        model.owner   = new ModelRef <IdentityModel>(owner);
        model.manager = new ModelRef <CreatureModel>(captain);
        model.manager.Model.location.Model = model;

        model.workers        = 10;
        model.workerCapacity = 50;

        model.name        = name;
        model.dateCreated = new Dated(GameManager.instance.data.date.time);
        model.lastUpdated = new Dated(GameManager.instance.data.date.time);
        model.capacity    = 10000;
        System.Random rand = new System.Random(model.name.GetHashCode());
        float         a    = rand.Next(1000) / 1000f;
        float         b    = rand.Next(1000) / 1000f;
        float         c    = rand.Next(1000) / 1000f;

        model.color           = new Color(a, b, c);
        a                     = rand.Next(1000) / 1000f;
        b                     = rand.Next(1000) / 1000f;
        c                     = rand.Next(1000) / 1000f;
        model.backgroundColor = new Color(a, b, c);
        model.parentIndex     = parentIndex;
        model.orbit           = orbit;
        star.stations.Add(model);
        //if (position.radius == 0 && parent.rawResource != RawResources.None)
        //{
        //    model.factory = new Factory(parent.rawResource,model);
        //}
        //else
        //{
        //    model.factory = new Factory(true, model);
        //}


        foreach (Items item in model.factory.inputItems)
        {
            item.pendingAmount = item.amount;
        }
        foreach (Items item in model.factory.outputItems)
        {
            item.pendingAmount = item.amount;
        }

        //Money Setup
        model.money              = 1000000f;
        model.owner.Model.money -= 1000000;
        model.moneyStats         = new DataGraph("Money Over Time", "Time (hours)", "Money");
        model.moneyStats.data.Add("Money", new List <Stat>()
        {
            new Stat(model.age.hour, model.money)
        });
        model.moneyStats.data.Add("Money Change", new List <Stat>());

        return(model);
    }
Example #3
0
    public void CreateStars(int count)
    {
        for (int i = 0; i < count; i++)
        {
            var     random   = new System.Random();
            Vector2 position = new Vector2(UnityEngine.Random.Range(-mapField.x * .5f, mapField.x * .5f), UnityEngine.Random.Range(-mapField.y * .5f, mapField.y * .5f));
            position = new Vector2((float)NormalizedRandom(-mapField.x * .5f, mapField.x * .5f), (float)NormalizedRandom(-mapField.y * .5f, mapField.y * .5f));
            SolarModel star = new SolarModel(names.GenerateWorldName() + " " + (i + 1), i, position, sunSizeColor);
            game.data.stars.Add(star);
        }

        for (int i = 0; i < game.data.stars.Count; i++)     //Checking the distance to each already generated star and then adding it to a list of near stars if close enough
        {
            for (int c = 0; c < game.data.stars.Count; c++) //Checking the distance to each already generated star and then adding it to a list of near stars if close enough
            {
                if (c != i)
                {
                    double maxDist    = 20 * GameDataModel.galaxyDistanceMultiplication;
                    double actualDist = Vector3.Distance(game.data.stars[i].galacticPosition, game.data.stars[c].galacticPosition);
                    if (actualDist < maxDist)
                    {
                        game.data.stars[i].nearStars.Add(game.data.stars[c]);
                        game.data.stars[c].nearStars.Add(game.data.stars[i]);
                    }
                }
            }
        }
        float connectedness = 0;

        for (int i = 0; i < count; i++)
        {
            float closestStarDist  = 1000000000000000;
            int   closestStarIndex = 0;
            for (int c = 0; c < count; c++)
            {
                if (c != i)
                {
                    float actualDist = Vector3.Distance(game.data.stars[i].galacticPosition, game.data.stars[c].galacticPosition);
                    if (actualDist < closestStarDist)
                    {
                        closestStarDist  = actualDist;
                        closestStarIndex = c;
                    }
                }
            }
            if (game.data.stars[i].nearStars.Count == 0)
            {
                game.data.stars[i].nearStars.Add(game.data.stars[closestStarIndex]);
                game.data.stars[closestStarIndex].nearStars.Add(game.data.stars[i]);
                //print("Connected disconnected star");
            }
            connectedness += game.data.stars[i].nearStars.Count;
        }
        connectedness /= count;
        print("Connectedness average: " + connectedness);
    }
Example #4
0
    private void handleCreateSolar(AbstractMessage message)
    {
        float SC    = (message as SolarMessage).SC;
        float maxSC = (message as SolarMessage).maxSC;

        /**/
        if (SC > gameModel.User.SC)
        {
            Debug.Log("Not enough SC to create Solar system!");
            return;
        }

        Messenger.Dispatch(AtomMessage.SPEND_ATOMS, new AtomMessage(0, 0, SC));
        /**/
        SolarModel generatedSolarModel = SMM.GenerateSolar(SC);

        gameModel.User.Galaxies.Add(generatedSolarModel);

        GameObject     solarPrefabInstance = Instantiate(solarPrefab, galaxy.transform);
        SolarComponent solar = solarPrefabInstance.GetComponent <SolarComponent>();

        solar.Setup(generatedSolarModel);
        Messenger.Dispatch(SolarMessage.SOLAR_CREATED);
    }
Example #5
0
    public void Setup(SolarModel model)
    {
        _model = model;

        SolarStore.Name     = _model.Name;
        SolarStore.MaxStock = _model.Lifetime;
        SolarStore.Stock    = _model.Lifetime;
        SolarStore.Property = _model.Radius + "";

        planets = new List <PlanetComponent>();
        for (int index = 0; index < _model.Planets.Count; index++)
        {
            GameObject      planet     = Instantiate(PlanetPrefab, PlanetsContainer);
            PlanetComponent planetView = planet.GetComponent <PlanetComponent>();
            planetView.Setup(_model.Planets[index]);
            planets.Add(planetView);
        }

        Observable.Interval(TimeSpan.FromSeconds(1))
        .Where(_ => _model.Lifetime > 0)
        .Subscribe(_ => _model.Lifetime -= 1)
        .AddTo(this);

        _model.rLifetime
        .Where(lifetime => lifetime == 0)
        .Subscribe(_ =>
        {
            Messenger.Dispatch(SolarMessage.SOLAR_DESTROYED, new SolarMessage(0, 0, _model));
            Destroy(gameObject);
        })
        .AddTo(this);

        _model.rLifetime
        .Subscribe(onLifetimeUpdate)
        .AddTo(this);
    }
    public SolarModel oldGenerateSolar(float SC)
    {
        Dictionary <int, int>   stocks      = new Dictionary <int, int>();
        Dictionary <int, float> atomWeights = new Dictionary <int, float>();

        //string output = "weights: ";

        int maxAtomicNumber = getMaxAtomicNumberFromSC(SC);

        for (int i = 1; i <= maxAtomicNumber; i++)
        {
            stocks[i] = 0;

            atomWeights.Add
            (
                i,
                (1 / Mathf.Sqrt(2 * Mathf.PI * _gameModel.Config.curve)) * Mathf.Exp(-Mathf.Pow(maxAtomicNumber - i, 2) / (2 * _gameModel.Config.curve))
            );
            //output += i + ":"+Math.Round( 100f * atomWeights[i] ) + ", ";
        }
        //Debug.Log(output);

        Dictionary <int, bool> chosenAtoms = new Dictionary <int, bool>();
        int minimum = maxAtomicNumber;

        if (minimum > 12)
        {
            minimum = 12;
        }

        int currentAtomIndex;

        for (int i = 0; i < minimum; i++)
        {
            currentAtomIndex = (int)chooseWithProbabilities(atomWeights);
            chosenAtoms[currentAtomIndex] = true;
        }

        float maxSCSolar  = (int)(_gameModel.Config.MaxHarvestMultiplier * SC);
        float MaxSCSoFar  = 0;
        bool  MaxNeedMore = true;

        float SCSolar  = (SC / .1f);
        float SCSoFar  = 0;
        bool  NeedMore = true;

        int       lifetime = 0;
        AtomModel currentAtom;

        while (MaxNeedMore)
        {
            foreach (KeyValuePair <int, bool> item in chosenAtoms)
            {
                currentAtom = _gameModel.Atoms[item.Key];
                if (SCSoFar + currentAtom.AtomicWeight > SCSolar)
                {
                    NeedMore = false;
                }
                else
                {
                    SCSoFar += currentAtom.AtomicWeight;
                }

                if (MaxSCSoFar + currentAtom.AtomicWeight > maxSCSolar)
                {
                    MaxNeedMore = false;
                    break;
                }
                else
                {
                    MaxSCSoFar       += currentAtom.AtomicWeight;
                    stocks[item.Key] += 1;
                }
            }
            if (NeedMore)
            {
                lifetime++;
            }
        }

        SolarModel solarModel = new SolarModel(new JSONSolarModel());

        solarModel.Name = "Star " + _gameModel.User.StarsCreated;
        _gameModel.User.StarsCreated++;
        solarModel.Radius    = (int)(SC);
        solarModel.Lifetime  = (int)(lifetime);
        solarModel.CreatedSC = SC;

        PlanetModel planetModel = new PlanetModel(new JSONPlanetModel());

        planetModel.Name = "Planet " + _gameModel.User.PlanetsCreated;
        _gameModel.User.PlanetsCreated++;
        planetModel.Radius = 1;
        solarModel.Planets.Add(planetModel);

        AtomModel planetAtomModel;

        foreach (KeyValuePair <int, bool> item in chosenAtoms)
        {
            planetAtomModel       = _gameModel.Atoms[item.Key].Copy();
            planetAtomModel.Stock = stocks[item.Key];
            planetModel.Atoms.Add(planetAtomModel);
        }

        return(solarModel);
    }
    public SolarModel GenerateSolar(float SC)
    {
        Dictionary <int, int>   stocks      = new Dictionary <int, int>();
        Dictionary <int, float> atomWeights = new Dictionary <int, float>();

        int maxAtomicNumber = getMaxAtomicNumberFromSC(SC);

        for (int i = 1; i <= maxAtomicNumber; i++)
        {
            stocks[i] = 0;

            atomWeights.Add
            (
                i,
                (1 / Mathf.Sqrt(2 * Mathf.PI * _gameModel.Config.curve)) * Mathf.Exp(-Mathf.Pow(maxAtomicNumber - i, 2) / (2 * _gameModel.Config.curve))
            );
        }

        Dictionary <int, bool> chosenAtoms = new Dictionary <int, bool>();
        int minimum = maxAtomicNumber;

        if (minimum > 12)
        {
            minimum = 12;
        }

        int currentAtomIndex;

        for (int i = 0; i < minimum; i++)
        {
            currentAtomIndex = (int)chooseWithProbabilities(atomWeights);
            chosenAtoms[currentAtomIndex] = true;
        }

        float SCmin     = SC * 1.5f;
        float SCPerAtom = SCmin / chosenAtoms.Count;

        SolarModel solarModel = new SolarModel(new JSONSolarModel());

        solarModel.Name = "Star " + _gameModel.User.StarsCreated;
        _gameModel.User.StarsCreated++;
        solarModel.Radius    = (int)(SC);
        solarModel.Lifetime  = (int)(SCPerAtom);
        solarModel.CreatedSC = SC;

        PlanetModel planetModel = new PlanetModel(new JSONPlanetModel());

        planetModel.Name = "Planet " + _gameModel.User.PlanetsCreated;
        _gameModel.User.PlanetsCreated++;
        planetModel.Radius = 1;
        solarModel.Planets.Add(planetModel);

        AtomModel planetAtomModel;

        foreach (KeyValuePair <int, bool> item in chosenAtoms)
        {
            planetAtomModel          = _gameModel.Atoms[item.Key].Copy();
            planetAtomModel.Stock    = (int)(SCPerAtom / planetAtomModel.AtomicWeight);
            planetAtomModel.MaxStock = planetAtomModel.Stock;
            planetModel.Atoms.Add(planetAtomModel);
        }

        return(solarModel);
    }
Example #8
0
 /// <summary>
 /// 获取节气日期
 /// </summary>
 /// <param name="year">年份</param>
 /// <param name="solar">节气</param>
 /// <returns>日期,节气名</returns>
 private KeyValuePair <DateTime, string> GetDate(int year, SolarModel solar)
 {
     return(new
            KeyValuePair <DateTime, string>(new DateTime(year, solar.Month, GetChineseTwentyFourDay(year, solar)), solar.Name));
 }
Example #9
0
 private void OnDestroy()
 {
     _model     = null;
     SolarStore = null;
 }
Example #10
0
 public SolarMessage(float SC = 0, float maxSC = 0, SolarModel model = null)
 {
     this.SC    = SC;
     this.maxSC = maxSC;
     this.model = model;
 }
Example #11
0
 internal void GoToTarget(SolarModel model)
 {
     galaxyView = true;
     galaxy.GalaxyView();
     transform.position = new Vector3(model.galacticPosition.x, model.galacticPosition.y, -10);
 }