private MyMwcObjectBuilder_VoxelMap GenerateVoxelMap(int sizeInVoxels, Vector3 positionInSector, Random rnd, List<MyMwcVoxelFilesEnum> voxelAsteroids, MyWeightDictionary<MyMwcVoxelMaterialsEnum> primaryMaterials, MyWeightDictionary<MyMwcVoxelMaterialsEnum> secondaryMaterials) { int sizeInMeters = sizeInVoxels;// (int)(sizeInVoxels * MyVoxelConstants.VOXEL_SIZE_IN_METRES); voxelAsteroids.Clear(); MyVoxelMap.GetAsteroidsBySizeInMeters(sizeInMeters, voxelAsteroids, false); int rndIndex = rnd.Next(0, voxelAsteroids.Count); MyMwcVoxelMaterialsEnum mainMat = MyMwcVoxelMaterialsEnum.Stone_01; if (primaryMaterials.Count > 0) { primaryMaterials.GetRandomItem(rnd); } MyMwcObjectBuilder_VoxelMap builder = MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.VoxelMap, null) as MyMwcObjectBuilder_VoxelMap; builder.VoxelFile = rnd.Item(voxelAsteroids); builder.VoxelMaterial = mainMat; builder.PositionAndOrientation = new MyMwcPositionAndOrientation(positionInSector, Vector3.Forward, Vector3.Up); AddMergeContent(rnd, voxelAsteroids, sizeInMeters, builder); AddVeins(secondaryMaterials, rnd, positionInSector, 2, sizeInMeters, builder, VeinAngleDeviation, MaxLevel, BaseSecondaryMaterialThickness); return builder; }
public MySolarSystemMapSectorData GenerateSectorObjectBuilders(MyMwcVector3Int sector, MySolarSystemMapData solarData, List<MyMwcObjectBuilder_Base> addToList, bool onlyStaticAsteroids) { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("GenerateSectorEntities"); var sectorData = GenerateSectorEntities(solarData, sector, 0, int.MaxValue, onlyStaticAsteroids); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); MyDynamicAABBTree prunningStructure = new MyDynamicAABBTree(Vector3.Zero); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Misc"); MyWeightDictionary<MyMwcVoxelMaterialsEnum> primaryMaterials; MyWeightDictionary<MyMwcVoxelMaterialsEnum> secondaryMaterials; MyMwcObjectBuilder_Sector sectorBuilder = addToList.FirstOrDefault(s => s.GetObjectBuilderType() == MyMwcObjectBuilderTypeEnum.Sector) as MyMwcObjectBuilder_Sector; if (sectorBuilder == null) { sectorBuilder = GetSectorBuilder(sectorData); addToList.Add(sectorBuilder); } //if (sectorBuilder != null) //{ // Vector3 kms = MySolarSystemUtils.SectorsToKm(sectorData.SectorPosition); // sectorBuilder.SunDistance = kms.Length(); //} MySector.Area = sectorData.Area; MinerWars.AppCode.Game.SolarSystem.MySolarSystemArea.AreaEnum? areaType = null; MyMwcVoxelMaterialsEnum? secondaryAsteroidMaterial = null; if (sectorData.Area.HasValue && sectorBuilder != null) { var area = MySolarSystemConstants.Areas[sectorData.Area.Value]; areaType = area.AreaType; secondaryAsteroidMaterial = area.SecondaryStaticAsteroidMaterial; primaryMaterials = new MyWeightDictionary<MyMwcVoxelMaterialsEnum>(area.SectorData.PrimaryAsteroidMaterials); secondaryMaterials = new MyWeightDictionary<MyMwcVoxelMaterialsEnum>(area.SectorData.SecondaryAsteroidMaterials); } else { primaryMaterials = new MyWeightDictionary<MyMwcVoxelMaterialsEnum>(MySolarSystemConstants.DefaultAsteroidMaterials); secondaryMaterials = new MyWeightDictionary<MyMwcVoxelMaterialsEnum>(MySolarSystemConstants.DefaultSecondaryMaterials); } Random rnd = new Random(m_seed); MyStaticAsteroidTypeSetEnum staticAsteroidsTypeset = MyStaticAsteroidTypeSetEnum.A | MyStaticAsteroidTypeSetEnum.B; var realSizes = sectorData.Entities.GroupBy(s => s.Radius).Select(s => new { Key = s.Key, Count = s.Count() }).ToArray(); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("GenerateSectorObjectBuildersFromSolarEntities"); GenerateSectorObjectBuildersFromSolarEntities(sectorData.Entities, addToList, rnd, primaryMaterials, secondaryMaterials, staticAsteroidsTypeset, secondaryAsteroidMaterial, areaType); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); if (!onlyStaticAsteroids) { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("GenerateStations"); GenerateStations(sector, solarData, sectorData, addToList, rnd, prunningStructure); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("GenerateBots"); GenerateBots(sectorData, addToList, rnd, prunningStructure); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } return sectorData; }
public MyMwcObjectBuilder_Sector GenerateObjectBuilders(MyMwcVector3Int sectorPosition, MySectorObjectCounts sectorObjectCounts, bool onlyStaticAsteroids) { Random rnd = new Random(m_seed); List<MySolarSystemMapEntity> entities = new List<MySolarSystemMapEntity>(); AddSectorEntities(sectorObjectCounts, sectorPosition, rnd, 0, int.MaxValue, entities, onlyStaticAsteroids); List<MyMwcObjectBuilder_Base> sectorObjects = new List<MyMwcObjectBuilder_Base>(); MyWeightDictionary<MyMwcVoxelMaterialsEnum> primaryMaterials = new MyWeightDictionary<MyMwcVoxelMaterialsEnum>(MySolarSystemConstants.DefaultAsteroidMaterials); MyWeightDictionary<MyMwcVoxelMaterialsEnum> secondaryMaterials = new MyWeightDictionary<MyMwcVoxelMaterialsEnum>(MySolarSystemConstants.DefaultSecondaryMaterials); GenerateSectorObjectBuildersFromSolarEntities(entities, sectorObjects, rnd, primaryMaterials, secondaryMaterials, sectorObjectCounts.StaticAsteroidTypeset); return new MyMwcObjectBuilder_Sector() { SectorObjects = sectorObjects, }; }
public void GenerateSectorObjectBuildersFromSolarEntities(List<MySolarSystemMapEntity> entities, List<MyMwcObjectBuilder_Base> addToList, Random rnd, MyWeightDictionary<MyMwcVoxelMaterialsEnum> primaryMaterials, MyWeightDictionary<MyMwcVoxelMaterialsEnum> secondaryMaterials, MyStaticAsteroidTypeSetEnum staticAsteroidTypesets, MyMwcVoxelMaterialsEnum? fieldMaterial = null, MySolarSystemArea.AreaEnum? areaType = null) { List<MyMwcObjectBuilder_StaticAsteroid_TypesEnum> asteroids = new List<MyMwcObjectBuilder_StaticAsteroid_TypesEnum>(5); List<MyMwcVoxelFilesEnum> voxelAsteroids = new List<MyMwcVoxelFilesEnum>(10); int count = addToList.Count; foreach (var e in entities) { if (e.EntityType == MySolarSystemEntityEnum.VoxelAsteroid) { int voxelAsteroidSize = FindAsteroidSize(e.Radius, MyVoxelMap.AsteroidSizes); int rndIndex = rnd.Next(0, voxelAsteroids.Count); MyVoxelMap.GetAsteroidsBySizeInMeters(voxelAsteroidSize, voxelAsteroids, false); MyMwcObjectBuilder_VoxelMap builder = GenerateVoxelMap(voxelAsteroidSize, e.PositionInSector, rnd, voxelAsteroids, primaryMaterials, secondaryMaterials); addToList.Add(builder); } else if (e.EntityType == MySolarSystemEntityEnum.StaticAsteroid) { float radius = 100; if (e.Radius == 10000) radius = rnd.Next(2000, 11000); if (e.Radius == 1000) radius = rnd.Next(100, 1100); if (e.Radius == 100) radius = rnd.Next(10, 100); MyMwcVoxelMaterialsEnum asteroidMaterial = MyMwcVoxelMaterialsEnum.Stone_01; if (primaryMaterials.Count > 0) primaryMaterials.GetRandomItem(rnd); MyStaticAsteroidTypeSetEnum asteroidType = MyStaticAsteroidTypeSetEnum.A; //for (int i = 0; i < 40000000; i++) { asteroidType = (MyStaticAsteroidTypeSetEnum)rnd.Item(Enum.GetValues(typeof(MyStaticAsteroidTypeSetEnum))); } if ((staticAsteroidTypesets & MyStaticAsteroidTypeSetEnum.A) == MyStaticAsteroidTypeSetEnum.A) asteroidType = MyStaticAsteroidTypeSetEnum.A; if ((staticAsteroidTypesets & MyStaticAsteroidTypeSetEnum.B) == MyStaticAsteroidTypeSetEnum.B) asteroidType = MyStaticAsteroidTypeSetEnum.B; if ((staticAsteroidTypesets & MyStaticAsteroidTypeSetEnum.All) == MyStaticAsteroidTypeSetEnum.All) asteroidType = rnd.Float(0, 1) > 0.5f ? MyStaticAsteroidTypeSetEnum.A : MyStaticAsteroidTypeSetEnum.B; var builder = GenerateStaticAsteroid(radius, asteroidType, asteroidMaterial, e.PositionInSector, rnd, asteroids); builder.AsteroidMaterial1 = fieldMaterial; if (areaType == MySolarSystemArea.AreaEnum.Sun) { builder.FieldDir = MinerWars.AppCode.Game.GUI.MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized(); } builder.Generated = true; addToList.Add(builder); //MyEntity ent = MyEntities.CreateFromObjectBuilderAndAdd(null, new MyMwcObjectBuilder_StaticAsteroid(asteroids[rndIndex], mat), // Matrix.CreateWorld(e.PositionInSector, rnd.Vector(1), rnd.Vector(1))); } else if (e.EntityType == MySolarSystemEntityEnum.LargeShip) { var shipType = rnd.Enum<MyMwcObjectBuilder_PrefabLargeShip_TypesEnum>(); MyMwcObjectBuilder_Prefab_AppearanceEnum appearance = rnd.Enum<MyMwcObjectBuilder_Prefab_AppearanceEnum>(); var ship = new MyMwcObjectBuilder_PrefabLargeShip(shipType, appearance, new MyMwcVector3Short(0, 0, 0), rnd.Vector(1), null, rnd.FloatNormal(), "Abandoned large ship", 0, false, 0); var gamePlayProperties = MyGameplayConstants.GetGameplayProperties(MyMwcObjectBuilderTypeEnum.PrefabLargeShip, (int)shipType, MyMwcObjectBuilder_FactionEnum.Euroamerican); ship.PrefabHealthRatio = MyGameplayConstants.HEALTH_RATIO_MAX; ship.PrefabMaxHealth = gamePlayProperties.MaxHealth; var prefabs = new List<MyMwcObjectBuilder_PrefabBase>(); prefabs.Add(ship); var container = new MyMwcObjectBuilder_PrefabContainer(0, MyMwcObjectBuilder_PrefabContainer_TypesEnum.INSTANCE, prefabs, 0, rnd.Enum<MyMwcObjectBuilder_FactionEnum>(), null); container.PositionAndOrientation = new MyMwcPositionAndOrientation(e.PositionInSector, Vector3.Forward, Vector3.Up); addToList.Add(container); } else if (e.EntityType == MySolarSystemEntityEnum.DebrisField) { MyMwcObjectBuilder_LargeDebrisField objectBuilder = new MyMwcObjectBuilder_LargeDebrisField(MyMwcObjectBuilder_LargeDebrisField_TypesEnum.Debris84); objectBuilder.PositionAndOrientation = new MyMwcPositionAndOrientation(e.PositionInSector, rnd.Vector(1), rnd.Vector(1)); addToList.Add(objectBuilder); } } }
public static void AddVeins(MyWeightDictionary<MyMwcVoxelMaterialsEnum> secondaryMaterials, Random rnd, Vector3 positionInSector, int veinCount, int voxelAsteroidSize, MyMwcObjectBuilder_VoxelMap builder, float veinAngleDev, int maxLevel, float baseThickness) { MyMwcVoxelMaterialsEnum material = MyMwcVoxelMaterialsEnum.Magnesium_01; if (secondaryMaterials.Count > 0) { material = secondaryMaterials.GetRandomItem(rnd); } for (int i = 0; i < veinCount; i++) { Vector3 position = positionInSector + new Vector3(voxelAsteroidSize / 2); position += rnd.Vector(voxelAsteroidSize / 3); AddVein(builder, baseThickness, position, rnd, material, veinAngleDev, maxLevel); } }