Esempio n. 1
0
    /// <summary>
    /// Calculates the length of the road for the given atom, taking its position and environment into account. This
    /// method is invoked by each <see cref="RoadAtom"/> during its production, in order to find out its length.
    /// </summary>
    /// <returns>The road length.</returns>
    /// <param name="currentAtom">Current atom.</param>
    /// <param name="gen">City generator.</param>
    public virtual float CalculateRoadLength(RoadAtom currentAtom, CityGenerator gen)
    {
        // Calculate how much the population density influences road length (the less population, the longer the road)
        float populationLengthFactor = 1f - gen.DensityAt(currentAtom.Node.position);

        // Calculate how much the slope of the road influences its length (the steeper, the shorter)
        float elevationLengthFactor = Mathf.Abs(gen.ElevationAt(currentAtom.Node.position) -
                                                gen.ElevationAt(currentAtom.Node.position + currentAtom.Forward));
        elevationLengthFactor = 1f - Mathf.Clamp01(gen.slopeExaggeration * elevationLengthFactor);

        // Multiply them to get the final length factor. Basically the elevation factor should only influence the
        // population factor when the road is very steep, in other cases it should be close to 1.
        float lengthFactor = populationLengthFactor * elevationLengthFactor;

        // Calculate the road length
        return gen.minimumRoadLength + lengthFactor * (gen.maximumRoadLength - gen.minimumRoadLength);
    }
Esempio n. 2
0
 /// <summary>
 /// The prober that probes for population density at the given position.
 /// </summary>
 /// <returns>The population density at the given position.</returns>
 /// <param name="gen">City generator.</param>
 /// <param name="position">Position.</param>
 public static float DensityProber(CityGenerator gen, Vector3 position)
 {
     return gen.DensityAt(position);
 }