private void AddSectorEntities(MySolarSystemMapSectorData sectorData, float entityMinimalSize, int maxEntityCount, bool onlyStaticAsteroids) { Random random = new Random(GetSeed(sectorData.SectorPosition, m_seed)); MySectorObjectCounts asteroidCounts; if (sectorData.Area.HasValue) { var area = MySolarSystemConstants.Areas[sectorData.Area.Value]; asteroidCounts = ApplyAreaInfluence(area.SectorData.SectorObjectsCounts, sectorData.AreaInfluenceMultiplier); } else { asteroidCounts = MySolarSystemConstants.DefaultObjectsProperties; } EnsureMinimalAsteroidCounts(asteroidCounts); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("AddSectorEntities"); AddSectorEntities(asteroidCounts, sectorData.SectorPosition, random, entityMinimalSize, maxEntityCount, sectorData.Entities, onlyStaticAsteroids); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); }
private void AddSpawnPoint(MySolarSystemMapSectorData sectorData, float entityMinimalSize) { Random random = new Random(sectorData.SectorPosition.X ^ sectorData.SectorPosition.Y ^ sectorData.SectorPosition.Z ^ m_seed); }
public static MyMwcObjectBuilder_Sector GetSectorBuilder(MySolarSystemMapSectorData sectorData) { MyMwcObjectBuilder_Sector sectorBuilder; sectorBuilder = MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.Sector, null) as MyMwcObjectBuilder_Sector; sectorBuilder.AreaTemplate = sectorData.Area; sectorBuilder.AreaMultiplier = sectorData.AreaInfluenceMultiplier; return sectorBuilder; }
private void GenerateBots(MySolarSystemMapSectorData sectorData, List<MyMwcObjectBuilder_Base> addToList, Random rnd, MyDynamicAABBTree prunningStructure) { int spawnPt = (int)(rnd.Float(0, 50) /** sectorData.AreaInfluenceMultiplier*/ ); float radius = 100; for (int i = 0; i < spawnPt; i++) { Vector3? pos = FindEntityPosition(prunningStructure, rnd, radius, 0.8f, 0.8f); if (pos.HasValue) { //MyMwcObjectBuilder_FactionEnum faction = MyMwcObjectBuilder_FactionEnum.None; var faction = MyFactions.GetFactionBySector(sectorData.SectorPosition); //var builder = new MyMwcObjectBuilder_; MyMwcObjectBuilder_SpawnPoint spobj = MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.SpawnPoint, null) as MyMwcObjectBuilder_SpawnPoint; spobj.BoundingRadius = radius; spobj.RespawnTimer = 1; spobj.SpawnCount = 5; spobj.PositionAndOrientation.Position = pos.Value; spobj.PositionAndOrientation.Forward = Vector3.Forward; spobj.PositionAndOrientation.Up = Vector3.Up; spobj.Faction = faction; List<MyMwcObjectBuilder_SmallShip_Weapon> weapons = new List<MyMwcObjectBuilder_SmallShip_Weapon>(); List<MyMwcObjectBuilder_SmallShip_Ammo> ammo = new List<MyMwcObjectBuilder_SmallShip_Ammo>(); List<MyMwcObjectBuilder_AssignmentOfAmmo> assignments = new List<MyMwcObjectBuilder_AssignmentOfAmmo>(); weapons.Add(new MyMwcObjectBuilder_SmallShip_Weapon(MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum.Autocanon)); weapons.Add(new MyMwcObjectBuilder_SmallShip_Weapon(MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum.Autocanon)); weapons.Add(new MyMwcObjectBuilder_SmallShip_Weapon(MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum.Cannon)); weapons.Add(new MyMwcObjectBuilder_SmallShip_Weapon(MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum.Cannon)); weapons.Add(new MyMwcObjectBuilder_SmallShip_Weapon(MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum.Shotgun)); weapons.Add(new MyMwcObjectBuilder_SmallShip_Weapon(MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum.Drilling_Device_Crusher)); weapons.Add(new MyMwcObjectBuilder_SmallShip_Weapon(MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum.Universal_Launcher_Front)); assignments.Add(new MyMwcObjectBuilder_AssignmentOfAmmo(MyMwcObjectBuilder_FireKeyEnum.Primary, MyMwcObjectBuilder_AmmoGroupEnum.Bullet, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Autocannon_Basic)); assignments.Add(new MyMwcObjectBuilder_AssignmentOfAmmo(MyMwcObjectBuilder_FireKeyEnum.Secondary, MyMwcObjectBuilder_AmmoGroupEnum.Cannon, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Basic)); List<MyMwcObjectBuilder_InventoryItem> inventoryItems = new List<MyMwcObjectBuilder_InventoryItem>(); inventoryItems.Add(new MyMwcObjectBuilder_InventoryItem(new MyMwcObjectBuilder_SmallShip_Ammo(MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Autocannon_Basic), 1000f)); inventoryItems.Add(new MyMwcObjectBuilder_InventoryItem(new MyMwcObjectBuilder_SmallShip_Ammo(MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Basic), 25)); //spobj.m_shipTemplates.Add( int numships = rnd.Next(1, 10); for (int x = 0; x < numships; x++) { spobj.ShipTemplates.Add( //new MyMwcObjectBuilder_SmallShip_Bot( // MyMwcObjectBuilder_SmallShip_TypesEnum.LIBERATOR, // weapons, // new MyMwcObjectBuilder_SmallShip_Engine(MyMwcObjectBuilder_SmallShip_Engine_TypesEnum.Chemical_1), // ammo, // assignments, // null, // faction // ) as MyMwcObjectBuilder_SmallShip_Bot new MyMwcObjectBuilder_SmallShip_Bot( MyMwcObjectBuilder_SmallShip_TypesEnum.LIBERATOR, new MyMwcObjectBuilder_Inventory(inventoryItems, 32), weapons, new MyMwcObjectBuilder_SmallShip_Engine(MyMwcObjectBuilder_SmallShip_Engine_TypesEnum.Chemical_1), assignments, null, null, null, MyGameplayConstants.HEALTH_RATIO_MAX, 100f, float.MaxValue, float.MaxValue, true, false, faction, MyAITemplateEnum.DEFAULT, 0, 1000, 1000, MyPatrolMode.CYCLE, null, BotBehaviorType.IDLE, MyLightsConstants.MAX_SPOTLIGHT_SHADOW_RANGE, 0, false, true) as MyMwcObjectBuilder_SmallShip_Bot ); } addToList.Add(spobj); /* MySolarSystemMapEntity entity = new MySolarSystemMapEntity(sectorData.SectorPosition, pos, size, "Asteroid", MySolarSystemEntityEnum.Asteroid); sectorData.Entities.Add(entity); */ } } }
private void GenerateStations(MyMwcVector3Int sector, MySolarSystemMapData solarData, MySolarSystemMapSectorData sectorData, List<MyMwcObjectBuilder_Base> addToList, Random rnd, MyDynamicAABBTree prunningStructure) { Dictionary<MyMwcVector3Int, MyMwcObjectBuilder_SectorObjectGroups> groupCache = new Dictionary<MyMwcVector3Int, MyMwcObjectBuilder_SectorObjectGroups>(); //List<MyImportantSolarObject> var objects = solarData.ImportantObjects.Where(o => o.NavigationMark.Sector.Equals(sector)); foreach(var obj in objects) { var size = MyPrefabContainerConstants.MAX_DISTANCE_FROM_CONTAINER_CENTER / 1000; Vector3? pos = FindEntityPosition(prunningStructure, rnd, size); if (pos.HasValue) { var templateSector = MyTemplateGroups.GetGroupSector(obj.TemplateGroup); MyMwcObjectBuilder_SectorObjectGroups groups; if (!groupCache.TryGetValue(templateSector, out groups)) { groups = LoadObjectGroups(templateSector); if (groups == null) { return; } groupCache.Add(templateSector, groups); } sectorData.Entities.Add(new MySolarSystemMapEntity(sector, pos.Value, size, "", MySolarSystemEntityEnum.OutpostIcon)); var group = rnd.Item(groups.Groups); IEnumerable<MyMwcObjectBuilder_PrefabBase> prefabs = group.GetPrefabBuilders(groups.Entities); IEnumerable<MyMwcObjectBuilder_Base> rootObjects = group.GetRootBuilders(groups.Entities); var objects3d = rootObjects.OfType<MyMwcObjectBuilder_Object3dBase>(); var faction = MyFactions.GetFactionBySector(sector); var objectPos = pos.Value; if (objects3d.Any()) { var firstPos = objects3d.First().PositionAndOrientation.Position; var offset = objectPos - firstPos; foreach (var o in objects3d) { // Clone var clone = o.Clone() as MyMwcObjectBuilder_Object3dBase; clone.PositionAndOrientation.Position += offset; clone.ClearEntityId(); if (clone is MyMwcObjectBuilder_PrefabContainer) { ((MyMwcObjectBuilder_PrefabContainer)clone).Faction = faction; } if (clone is MyMwcObjectBuilder_SpawnPoint) { ((MyMwcObjectBuilder_SpawnPoint)clone).Faction = faction; } addToList.Add(clone); } } else if(prefabs.Any()) { MyMwcObjectBuilder_PrefabContainer container = new MyMwcObjectBuilder_PrefabContainer(null, MyMwcObjectBuilder_PrefabContainer_TypesEnum.INSTANCE, prefabs.ToList(), 0, faction, null); var clone = container.Clone() as MyMwcObjectBuilder_PrefabContainer; // To clone children easily clone.ClearEntityId(); // Clear childs ids clone.PositionAndOrientation = new MyMwcPositionAndOrientation(objectPos, Vector3.Forward, Vector3.Up); addToList.Add(clone); } } //end of station generation if (pos.HasValue && rnd.Float(0, 1) < 0.5f) { //Create mysterious cube at 1% of stations var sizeMyst = size * 1.5f; Vector3? posMyst = FindEntityPosition(prunningStructure, rnd, sizeMyst, 1.0f, 1.0f, pos.Value); if (posMyst.HasValue) { CreateMysteriousCubes(posMyst.Value, addToList, rnd); } //Create some more int count = rnd.Next(5); for (int i = 0; i < count; i++) { var size2 = MyMwcSectorConstants.SECTOR_SIZE / 2; Vector3? pos2 = FindEntityPosition(prunningStructure, rnd, size2); if (pos2.HasValue) { CreateMysteriousCubes(pos2.Value, addToList, rnd); } } } } }
/// <summary> /// Generates sector with entities from SolarMap and SectorId /// </summary> /// <param name="solarData">SolarMap data.</param> /// <param name="sector">Sector to generate.</param> /// <param name="minimalEntitySize">Minimal entity size. When far from sector, no need to display all entities.</param> /// <returns>MySolarSystemMapSectorData - collection of sector entities.</returns> public MySolarSystemMapSectorData GenerateSectorEntities(MySolarSystemMapData solarData, MyMwcVector3Int sector, float minimalEntitySize, int maxEntityCount, bool onlyStaticAsteroids) { MySolarSystemAreaEnum? customArea = null; if (IsSectorCustom(sector)) { customArea = GetCustomSectorArea(sector); } else if (IsSectorInForbiddenArea(sector)) { sector = MySolarSystemUtils.MillionKmToSectors(MyBgrCubeConsts.EARTH_POSITION); } MySolarSystemMapSectorData data; if (!solarData.SectorData.TryGetValue(sector, out data) || data.MinimalEntitySize > minimalEntitySize) { data = new MySolarSystemMapSectorData(sector, minimalEntitySize); solarData.SectorData[sector] = data; } // Apply all areas to sector, area tests whether it influents sector or not if (!customArea.HasValue) { foreach (var areaEnum in solarData.Areas) { var area = MySolarSystemConstants.Areas[areaEnum]; var interpolator = area.GetSectorInterpolator(data.SectorPosition); if (interpolator > 0 && interpolator > data.AreaInfluenceMultiplier) { data.Area = areaEnum; data.AreaInfluenceMultiplier = interpolator; } } } else { data.Area = customArea.Value; data.AreaInfluenceMultiplier = 1; } AddSectorEntities(data, minimalEntitySize, maxEntityCount, onlyStaticAsteroids); return data; }