Esempio n. 1
0
 /// <summary>
 /// Initializes the GlobalGoals component with all its growth rules.
 /// </summary>
 /// <param name="seed">Seed for the random number generator.</param>
 public GlobalGoals()
 {
     // we can't use random.range nor random.initstate here! just putting random numbers as seeds for now
     newYorkRule = new NewYorkRule(42);
     parisRule   = new ParisRule(52452);
     basicRule   = new BasicRule(423);
 }
Esempio n. 2
0
        public void Overlay(GrowthRule rule)
        {
            float?nullable = rule.underPopulationDeathRate;

            if (nullable.HasValue)
            {
                float?nullable2 = rule.underPopulationDeathRate;
                underPopulationDeathRate = nullable2.Value;
            }
            float?nullable3 = rule.populationHalfLife;

            if (nullable3.HasValue)
            {
                float?nullable4 = rule.populationHalfLife;
                populationHalfLife = nullable4.Value;
            }
            float?nullable5 = rule.overPopulationHalfLife;

            if (nullable5.HasValue)
            {
                float?nullable6 = rule.overPopulationHalfLife;
                overPopulationHalfLife = nullable6.Value;
            }
            float?nullable7 = rule.diffusionScale;

            if (nullable7.HasValue)
            {
                float?nullable8 = rule.diffusionScale;
                diffusionScale = nullable8.Value;
            }
            float?nullable9 = rule.minCountPerKG;

            if (nullable9.HasValue)
            {
                float?nullable10 = rule.minCountPerKG;
                minCountPerKG = nullable10.Value;
            }
            float?nullable11 = rule.maxCountPerKG;

            if (nullable11.HasValue)
            {
                float?nullable12 = rule.maxCountPerKG;
                maxCountPerKG = nullable12.Value;
            }
            int?nullable13 = rule.minDiffusionCount;

            if (nullable13.HasValue)
            {
                int?nullable14 = rule.minDiffusionCount;
                minDiffusionCount = nullable14.Value;
            }
            byte?nullable15 = rule.minDiffusionInfestationTickCount;

            if (nullable15.HasValue)
            {
                byte?nullable16 = rule.minDiffusionInfestationTickCount;
                minDiffusionInfestationTickCount = nullable16.Value;
            }
            name = rule.Name();
        }
Esempio n. 3
0
    /// <summary>
    /// Generate new roads based on an existing one.
    /// </summary>
    /// <param name="oldRoad">Predecessor road</param>
    /// <returns>A list of new roads</returns>
    public List <Edge> generateNewRoads(Edge oldRoad)
    {
        List <Edge> newBranches = new List <Edge>();

        // Get the growth rule we are used based on the old edge's end point
        int growthRule = CoordinateHelper.worldToGrowth(oldRoad.n2.x, oldRoad.n2.y);

        switch (growthRule)
        {
        case GrowthRuleGenerator.red:
            currentRule = basicRule;
            break;

        case GrowthRuleGenerator.green:
            currentRule = newYorkRule;
            break;

        case GrowthRuleGenerator.blue:
            currentRule = parisRule;
            break;

        default:
            Debug.LogError("Invalid Growth Rule");
            break;
        }

        newBranches.AddRange(generateBranches((oldRoad.getRoadType() == RoadTypes.HIGHWAY)? BranchType.HIGHWAY_TO_HIGHWAY : BranchType.STREET_TO_STREET, oldRoad));
        newBranches.AddRange(generateBranches(BranchType.ANY_ROAD_TO_STREET, oldRoad));

        return(newBranches);
    }
Esempio n. 4
0
 protected void AddGrowthRule(GrowthRule g)
 {
     if (growthRules == null)
     {
         growthRules = new List <GrowthRule>();
         Debug.Assert(g.GetType() == typeof(GrowthRule), "First rule must be a fully defined base rule.");
         float?underPopulationDeathRate = g.underPopulationDeathRate;
         Debug.Assert(underPopulationDeathRate.HasValue, "First rule must be a fully defined base rule.");
         float?populationHalfLife = g.populationHalfLife;
         Debug.Assert(populationHalfLife.HasValue, "First rule must be a fully defined base rule.");
         float?overPopulationHalfLife = g.overPopulationHalfLife;
         Debug.Assert(overPopulationHalfLife.HasValue, "First rule must be a fully defined base rule.");
         float?diffusionScale = g.diffusionScale;
         Debug.Assert(diffusionScale.HasValue, "First rule must be a fully defined base rule.");
         float?minCountPerKG = g.minCountPerKG;
         Debug.Assert(minCountPerKG.HasValue, "First rule must be a fully defined base rule.");
         float?maxCountPerKG = g.maxCountPerKG;
         Debug.Assert(maxCountPerKG.HasValue, "First rule must be a fully defined base rule.");
         int?minDiffusionCount = g.minDiffusionCount;
         Debug.Assert(minDiffusionCount.HasValue, "First rule must be a fully defined base rule.");
         byte?minDiffusionInfestationTickCount = g.minDiffusionInfestationTickCount;
         Debug.Assert(minDiffusionInfestationTickCount.HasValue, "First rule must be a fully defined base rule.");
     }
     else
     {
         Debug.Assert(g.GetType() != typeof(GrowthRule), "Subsequent rules should not be base rules");
     }
     growthRules.Add(g);
 }