/// <summary> /// Some types are only valid for certain materials. So rather than throw an error, just change the type /// </summary> private static WeaponHandleType GetHandleType(WeaponHandleMaterial material, WeaponHandleType requestedType) { switch (material) { case WeaponHandleMaterial.Soft_Wood: case WeaponHandleMaterial.Hard_Wood: return(WeaponHandleType.Rod); //case WeaponHandleMaterial.NylonRope: //case WeaponHandleMaterial.WireRope: //case WeaponHandleMaterial.Wraith: // return WeaponHandleType.Rope; default: return(requestedType); } }
public static WeaponHandleDNA GetRandomDNA(WeaponHandleMaterial? material = null, WeaponHandleType? type = null, bool? isDouble = null, double? length = null, double? radius = null) { const double DOUBLE_END = .2d; const double DOUBLE_CENTER = .05d; // this is only half of the center WeaponHandleDNA retVal = new WeaponHandleDNA(); Random rand = StaticRandom.GetRandomForThread(); bool isDoubleActual = isDouble ?? (rand.Next(2) == 0); #region Material if (material == null) { retVal.HandleMaterial = UtilityCore.GetRandomEnum<WeaponHandleMaterial>(); } else { retVal.HandleMaterial = material.Value; } #endregion //TODO: Support rope retVal.HandleType = WeaponHandleType.Rod; #region Length if (length == null) { //double lengthActual = rand.NextDouble(1.5d, 3.5d); double lengthActual = rand.NextDouble(1.5d, 2.8d); if (isDoubleActual) { lengthActual *= 2d; } retVal.Length = lengthActual; } else { retVal.Length = length.Value; } #endregion #region Radius if (radius == null) { //double radiusActual = rand.NextDouble(.03d, .17d); double radiusActual = rand.NextDouble(.03d, .12d); if (isDoubleActual) { radiusActual *= 2d; } retVal.Radius = radiusActual; } else { retVal.Radius = radius.Value; } #endregion #region AttachPoint if (isDoubleActual) { // Since the center of mass is in the middle, the attach point can't be in the middle. // Both ends are out as well. // So, choose one of the areas that are stars // |----|********|--------|********|----| double randMaxValue = .5d - DOUBLE_END - DOUBLE_CENTER; double randValue = rand.NextDouble(randMaxValue); double half = DOUBLE_CENTER + randValue; if (rand.NextBool()) { // left side retVal.AttachPointPercent = .5d - half; } else { // right side retVal.AttachPointPercent = .5d + half; } } else { // Choose one of the ends retVal.AttachPointPercent = rand.NextBool() ? 0d : 1d; } #endregion #region Color switch (retVal.HandleMaterial) { case WeaponHandleMaterial.Composite: retVal.MaterialsForCustomizable = GetRandomMaterials_Composite(); break; case WeaponHandleMaterial.Klinth: retVal.MaterialsForCustomizable = GetRandomMaterials_Klinth(); break; } #endregion return retVal; }
/// <summary> /// Some types are only valid for certain materials. So rather than throw an error, just change the type /// </summary> private static WeaponHandleType GetHandleType(WeaponHandleMaterial material, WeaponHandleType requestedType) { switch (material) { case WeaponHandleMaterial.Soft_Wood: case WeaponHandleMaterial.Hard_Wood: return WeaponHandleType.Rod; //case WeaponHandleMaterial.CheapRope: //case WeaponHandleMaterial.HempRope: //case WeaponHandleMaterial.Wraith: // return WeaponHandleType.Rope; default: return requestedType; } }
public static Tuple<BotDNA, WeaponDNA> GetRandomDNA(BotShellColorsDNA shellColors = null, WeaponDNA weapon = null) { Random rand = StaticRandom.GetRandomForThread(); BotDNA bot = new BotDNA() { UniqueID = Guid.NewGuid(), Lineage = Guid.NewGuid().ToString(), Generation = 0, DraggingMaxVelocity = rand.NextPercent(5, .25), DraggingMultiplier = rand.NextPercent(20, .25), }; #region Parts List<ShipPartDNA> parts = new List<ShipPartDNA>(); double partSize; // Homing partSize = rand.NextPercent(1, .5); parts.Add(new ShipPartDNA() { PartType = SensorHoming.PARTTYPE, Position = new Point3D(0, 0, 2.5), Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize) }); // Vision //TODO: Support filtering by type partSize = rand.NextPercent(1, .5); parts.Add(new ShipPartDNA() { PartType = SensorVision.PARTTYPE, Position = new Point3D(0, 0, 1.5), Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize) }); // Brains int numBrains = 1 + Convert.ToInt32(rand.NextPow(5, 1d) * 4); for (int cntr = 0; cntr < numBrains; cntr++) { partSize = rand.NextPercent(1, .5); Point3D position = new Point3D(0, 0, 0); if (numBrains > 1) { position = Math3D.GetRandomVector_Circular(1).ToPoint(); } parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = position, Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize) }); } // MotionController_Linear - always exactly one of these partSize = rand.NextPercent(1, .5); parts.Add(new ShipPartDNA() { PartType = MotionController_Linear.PARTTYPE, Position = new Point3D(0, 0, -1.5), Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize) }); // Store it bot.Parts = parts.ToArray(); #endregion if (shellColors == null) { bot.ShellColors = BotShellColorsDNA.GetRandomColors(); } else { bot.ShellColors = shellColors; } #region Weapon WeaponDNA weaponActual = null; if (weapon == null) { if (rand.NextDouble() < .95d) { WeaponHandleMaterial[] weaponMaterials = new WeaponHandleMaterial[] { WeaponHandleMaterial.Soft_Wood, WeaponHandleMaterial.Hard_Wood }; weaponActual = new WeaponDNA() { UniqueID = Guid.NewGuid(), Handle = WeaponHandleDNA.GetRandomDNA(weaponMaterials[StaticRandom.Next(weaponMaterials.Length)]) }; } } else { weaponActual = weapon; } #endregion return Tuple.Create(bot, weaponActual); }
public static (BotDNA bot, WeaponDNA weapon) GetRandomDNA(ItemOptionsArco itemOptions, BotShellColorsDNA shellColors = null, WeaponDNA weapon = null) { Random rand = StaticRandom.GetRandomForThread(); BotDNA bot = new BotDNA() { UniqueID = Guid.NewGuid(), Lineage = Guid.NewGuid().ToString(), Generation = 0, DraggingMaxVelocity = rand.NextPercent(5, .25), DraggingMultiplier = rand.NextPercent(20, .25), }; #region Parts List <ShipPartDNA> parts = new List <ShipPartDNA>(); double partSize; // Homing partSize = rand.NextPercent(1, .5); parts.Add(new ShipPartDNA() { PartType = SensorHoming.PARTTYPE, Position = new Point3D(0, 0, 2.5), Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize) }); // Vision //TODO: Support filtering by type partSize = rand.NextPercent(1, .5); parts.Add(new SensorVisionDNA() { PartType = SensorVision.PARTTYPE, Position = new Point3D(0, 0, 1.5), Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize), SearchRadius = itemOptions.VisionSensor_SearchRadius }); // Brains int numBrains = 1 + Convert.ToInt32(rand.NextPow(5, 1d) * 4); for (int cntr = 0; cntr < numBrains; cntr++) { partSize = rand.NextPercent(1, .5); Point3D position = new Point3D(0, 0, 0); if (numBrains > 1) { position = Math3D.GetRandomVector_Circular(1).ToPoint(); } parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = position, Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize) }); } // MotionController - always exactly one of these partSize = rand.NextPercent(1, .5); parts.Add(new ShipPartDNA() { PartType = MotionController2.PARTTYPE, Position = new Point3D(0, 0, -1.5), Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize) }); // Store it bot.Parts = parts.ToArray(); #endregion if (shellColors == null) { bot.ShellColors = BotShellColorsDNA.GetRandomColors(); } else { bot.ShellColors = shellColors; } #region Weapon WeaponDNA weaponActual = null; if (weapon == null) { if (rand.NextDouble() < .95d) { WeaponHandleMaterial[] weaponMaterials = new WeaponHandleMaterial[] { WeaponHandleMaterial.Soft_Wood, WeaponHandleMaterial.Hard_Wood }; weaponActual = new WeaponDNA() { UniqueID = Guid.NewGuid(), Handle = WeaponHandleDNA.GetRandomDNA(weaponMaterials[StaticRandom.Next(weaponMaterials.Length)]) }; } } else { weaponActual = weapon; } #endregion return(bot, weaponActual); }