/// <summary>
        /// Creates a random mobile object at the given location.
        /// </summary>
        private void Create(
			Segment segment, MersenneRandom random, float x, float y)
        {
            // Figure out the type
            Mobile m = new HousingBubble();
            int pick = random.Next(10);

            if (pick == 0)
                m = new ContainmentModule();
            else if (pick < 5)
                m = new EngineModule();

            // Create a housing bubble
            PointF p = segment.ChildJunctionPoint;
            m.Point = new PointF(p.X + x, p.Y + y);
            m.Radius = random.NextSingle(5, 20);

            // Add it
            segment.ParentJunction.Mobiles.Add(m);
        }
Example #2
0
        /// <summary>
        /// Selects a random junction factory. For a given seed, this
        /// will always return the same junction.
        /// </summary>
        public static IJunctionFactory ChooseJunctionFactory(
			MersenneRandom random)
        {
            return new SimpleJunctionFactory();
        }
Example #3
0
        /// <summary>
        /// Chooses the random clutter factory which populates the
        /// contents of a junction.
        /// </summary>
        public static IClutterFactory ChooseClutterFactory(
			MersenneRandom random)
        {
            return new SimpleClutterFactory();
        }
Example #4
0
        /// <summary>
        /// Loops through the points and staggers them repeatedly.
        /// </summary>
        public static void StaggerPoints(
			CenterPointList points,
			MersenneRandom random,
			float minimumDistance,
			int passes)
        {
            // Go through the minimum number of passes
            for (int i = 0; i < passes; i++)
            {
                if (!StaggerPoints(points, random, minimumDistance))
                    break;
            }
        }
Example #5
0
        /// <summary>
        /// Cycles through a list of points and creates a fractal
        /// version of the points by splitting each one in half and
        /// moving it a random amount.
        /// </summary>
        /// <returns>A true if at least one point was changed.</returns>
        public static bool StaggerPoints(
			CenterPointList points,
			MersenneRandom random,
			float minimumDistance)
        {
            // Ignores blanks and null
            if (points == null)
                throw new ArgumentException("points cannot be null");

            if (random == null)
                throw new ArgumentException("random cannot be null");

            if (points.Count < 2)
                return false;

            // Go through each set of points
            CenterPointList newPoints = new CenterPointList();
            bool changed = false;

            for (int i = 0; i < points.Count - 1; i++)
            {
                // Get the points
                CenterPoint p1 = points[i];
                CenterPoint p2 = points[i + 1];

                // Add the first point
                newPoints.Add(p1);

                // Get the distance
                float distance = CalculateDistance(p1.Point, p2.Point);

                if (distance > minimumDistance)
                {
                    // These two are far enough to calculate a new point
                    CenterPoint mp =
                        new CenterPoint((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2);
                    float delta = distance * Constants.FractalDecay;
                    float diff = random.NextSingle(-delta, delta);

                    // Calculate the new point
                    float dy = p2.Y - p1.Y;
                    float dx = p2.X - p1.X;

                    if (dy == 0)
                    {
                        // This is a horizontal line
                        mp.Y += diff;
                    }
                    else if (dx == 0)
                    {
                        // This is a vertical line
                        mp.X += diff;
                    }
                    else
                    {
                        // Figure out the slope of the line
                        double theta1 = Math.Tanh(dy / dx);
                        double theta2 = theta1 - Math.PI / 2;

                        mp.X = (float) (mp.X + diff * Math.Cos(theta2));
                        mp.Y = (float) (mp.Y + diff * Math.Sin(theta2));
                    }

                    // Add the created point
                    newPoints.Add(mp);
                    changed = true;
                }

                // Add the second point
                newPoints.Add(p2);
            }

            // See if we changes something
            if (changed)
            {
                // Swap the points
                points.Clear();
                points.AddAll(newPoints);
                newPoints.Clear();
            }

            // Return our status
            return changed;
        }
Example #6
0
 /// <summary>
 /// Constructs the junction node with a given seed.
 /// </summary>
 public Junction(int seed)
 {
     randomSeed = seed;
     random = new MersenneRandom(seed);
 }
Example #7
0
        /// <summary>
        /// Resets the junction node's status, including purging all
        /// generated data and resetting to a known seed value.
        /// </summary>
        public void Reset()
        {
            // Reset the flags
            builtShape = false;
            builtConnections = false;

            // Purge the stored data
            internalShape = null;
            shape = null;
            segments.Clear();
            physicsShapes.Clear();

            // Reset the random value
            random = new MersenneRandom(randomSeed);
        }