Esempio n. 1
0
        private List<SwarmBot2> ChangeSwarmBotsSprtSwarm(int numBots, Vector3D startPoint)
        {
            List<SwarmBot2> retVal = new List<SwarmBot2>();

            for (int cntr = 0; cntr < numBots; cntr++)
            {
                #region Bots

                // Set up the bot's properties
                SwarmBot2 swarmBot = new SwarmBot2();

                double sizeMultiplier = 1d;
                if (!_areSwarmbotsUniformSize)
                {
                    //sizeMultiplier = UtilityHelper.GetScaledValue(.5d, 4d, 0d, 1d, _rand.NextDouble());		// this does an even distribution of sizes, but I want most to be size 1

                    // This scales from .5 to about 4.5, and keeps the chances of it being around 1 longer
                    // .5 + (.75 + (2x-.88)^3)^2
                    //sizeMultiplier = 2 * _rand.NextDouble() - .88d;
                    //sizeMultiplier = Math.Pow(sizeMultiplier, 3d);
                    //sizeMultiplier += .75d;
                    //sizeMultiplier = Math.Pow(sizeMultiplier, 2d);
                    //sizeMultiplier += .5d;

                    sizeMultiplier = .5 + Math.Pow(.75 + Math.Pow(2 * StaticRandom.NextDouble() - .88, 3), 2);		// hard to read either way
                }

                double radius, mass, thrustForce, visionLimit;
                int numClosestBotsToLookAt;
                ChangeSwarmBotsSprtSizeProps(out radius, out mass, out thrustForce, out numClosestBotsToLookAt, out visionLimit, sizeMultiplier);
                swarmBot.Radius = radius;
                swarmBot.Mass = mass;
                swarmBot.ThrustForce = thrustForce;
                swarmBot.NumClosestBotsToLookAt = numClosestBotsToLookAt;
                swarmBot.VisionLimit = visionLimit;

                swarmBot.Behavior = SwarmBot2.BehaviorType.Flocking_ChasePoint_AvoidKnownObstacles;
                swarmBot.Obstacles.Add(_physicsBody);

                swarmBot.CoreColor = _hullColor;

                swarmBot.ShouldDrawThrustLine = _showDebugVisuals;
                swarmBot.ThrustLineMultiplier = 1.5d;

                swarmBot.ShouldShowDebugVisuals = _showDebugVisuals;

                // Figure out position
                Vector3D position = startPoint + Math3D.GetRandomVector_Spherical(3d);
                position += _physicsBody.PositionToWorld(_physicsBody.CenterOfMass).ToVector();		// this isn't right

                // Create the bot
                //NOTE:  I don't need to manipulate the swarm bots directly, so I won't hook to the body update event
                swarmBot.CreateBot(_map.Viewport, _sharedVisuals, _map.World, position.ToPoint());
                _map.AddItem(swarmBot);
                retVal.Add(swarmBot);

                #endregion
            }

            // Now that they're all created, tell each about the others
            foreach (SwarmBot2 bot in retVal)
            {
                #region Tell about each other

                foreach (SwarmBot2 otherBot in retVal)
                {
                    if (otherBot == bot)
                    {
                        continue;
                    }

                    bot.OtherBots.Add(otherBot);
                }

                #endregion
            }

            return retVal;
        }
Esempio n. 2
0
        private List <SwarmBot2> ChangeSwarmBotsSprtSwarm(int numBots, Vector3D startPoint)
        {
            List <SwarmBot2> retVal = new List <SwarmBot2>();

            for (int cntr = 0; cntr < numBots; cntr++)
            {
                #region Bots

                // Set up the bot's properties
                SwarmBot2 swarmBot = new SwarmBot2();

                double sizeMultiplier = 1d;
                if (!_areSwarmbotsUniformSize)
                {
                    //sizeMultiplier = UtilityHelper.GetScaledValue(.5d, 4d, 0d, 1d, _rand.NextDouble());		// this does an even distribution of sizes, but I want most to be size 1

                    // This scales from .5 to about 4.5, and keeps the chances of it being around 1 longer
                    // .5 + (.75 + (2x-.88)^3)^2
                    //sizeMultiplier = 2 * _rand.NextDouble() - .88d;
                    //sizeMultiplier = Math.Pow(sizeMultiplier, 3d);
                    //sizeMultiplier += .75d;
                    //sizeMultiplier = Math.Pow(sizeMultiplier, 2d);
                    //sizeMultiplier += .5d;

                    sizeMultiplier = .5 + Math.Pow(.75 + Math.Pow(2 * StaticRandom.NextDouble() - .88, 3), 2);          // hard to read either way
                }

                double radius, mass, thrustForce, visionLimit;
                int    numClosestBotsToLookAt;
                ChangeSwarmBotsSprtSizeProps(out radius, out mass, out thrustForce, out numClosestBotsToLookAt, out visionLimit, sizeMultiplier);
                swarmBot.Radius                 = radius;
                swarmBot.Mass                   = mass;
                swarmBot.ThrustForce            = thrustForce;
                swarmBot.NumClosestBotsToLookAt = numClosestBotsToLookAt;
                swarmBot.VisionLimit            = visionLimit;

                swarmBot.Behavior = SwarmBot2.BehaviorType.Flocking_ChasePoint_AvoidKnownObstacles;
                swarmBot.Obstacles.Add(_physicsBody);

                swarmBot.CoreColor = _hullColor;

                swarmBot.ShouldDrawThrustLine = _showDebugVisuals;
                swarmBot.ThrustLineMultiplier = 1.5d;

                swarmBot.ShouldShowDebugVisuals = _showDebugVisuals;

                // Figure out position
                Vector3D position = startPoint + Math3D.GetRandomVector_Spherical(3d);
                position += _physicsBody.PositionToWorld(_physicsBody.CenterOfMass).ToVector();         // this isn't right

                // Create the bot
                //NOTE:  I don't need to manipulate the swarm bots directly, so I won't hook to the body update event
                swarmBot.CreateBot(_map.Viewport, _sharedVisuals, _map.World, position.ToPoint());
                _map.AddItem(swarmBot);
                retVal.Add(swarmBot);

                #endregion
            }

            // Now that they're all created, tell each about the others
            foreach (SwarmBot2 bot in retVal)
            {
                #region Tell about each other

                foreach (SwarmBot2 otherBot in retVal)
                {
                    if (otherBot == bot)
                    {
                        continue;
                    }

                    bot.OtherBots.Add(otherBot);
                }

                #endregion
            }

            return(retVal);
        }