public static void AddPlanetPrefab(string prefabName, string name) { DictionaryValuesReader <MyDefinitionId, MyPlanetPrefabDefinition> planetDefinitions = MyDefinitionManager.Static.GetPlanetsPrefabsDefinitions(); foreach (var planetPrebabDefinition in planetDefinitions) { if (planetPrebabDefinition.Id.SubtypeName == prefabName) { var voxelMap = new MyPlanet(); var ob = planetPrebabDefinition.PlanetBuilder; string storageName = MyFileSystem.ContentPath + "\\VoxelMaps\\" + ob.StorageName + MyVoxelConstants.FILE_EXTENSION; voxelMap.EntityId = ob.EntityId; MyPlanetInitArguments planetInitArguments; planetInitArguments.StorageName = ob.StorageName; planetInitArguments.Storage = MyStorageBase.LoadFromFile(storageName); planetInitArguments.PositionMinCorner = ob.PositionAndOrientation.Value.Position; planetInitArguments.AveragePlanetRadius = ob.Radius; planetInitArguments.AtmosphereRadius = ob.AtmosphereRadius; planetInitArguments.MaximumHillRadius = ob.MaximumHillRadius; planetInitArguments.MinimumSurfaceRadius = ob.MinimumSurfaceRadius; planetInitArguments.HasAtmosphere = ob.HasAtmosphere; planetInitArguments.AtmosphereWavelengths = ob.AtmosphereWavelengths; planetInitArguments.MaxOxygen = ob.MaximumOxygen; planetInitArguments.GravityFalloff = ob.GravityFalloff; planetInitArguments.MarkAreaEmpty = true; voxelMap.Init(planetInitArguments); MyEntities.Add(voxelMap); } } }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); MyObjectBuilder_FloraElementDefinition definition = builder as MyObjectBuilder_FloraElementDefinition; this.AppliedGroups = new Dictionary <string, MyGroupedIds>(); if (definition.AppliedGroups != null) { DictionaryValuesReader <string, MyGroupedIds> groupedIds = MyDefinitionManager.Static.GetGroupedIds("EnvGroups"); MyGroupedIds result = null; foreach (string str in definition.AppliedGroups) { if (groupedIds.TryGetValue(str, out result)) { this.AppliedGroups.Add(str, result); } } } this.GrowthSteps = new List <GrowthStep>(); if (definition.GrowthSteps != null) { foreach (MyObjectBuilder_FloraElementDefinition.GrowthStep step in definition.GrowthSteps) { this.GrowthSteps.Add(new GrowthStep(step.GroupInsId, step.Percent)); } } if (definition.GatheredItem != null) { this.GatheredItemDefinition = definition.GatheredItem.Id; this.GatheredAmount = definition.GatheredItem.Amount; this.IsGatherable = true; } else { this.GatheredItemDefinition = new MyDefinitionId(); this.GatheredAmount = -1f; this.IsGatherable = false; } this.Regrowable = definition.Regrowable; this.GrowTime = definition.GrowTime; this.GatherableStep = definition.GatherableStep; this.PostGatherStep = definition.PostGatherStep; this.SpawnProbability = definition.SpawnProbability; this.AreaTransformType = definition.AreaTransformType; this.DecayTime = definition.DecayTime; }
public static void InitVoxelIDs() { VOXEL_IDS = new Dictionary <byte, VoxelDamageItem>(); DictionaryValuesReader <string, MyVoxelMaterialDefinition> mats = MyDefinitionManager.Static.GetVoxelMaterialDefinitions(); foreach (MyVoxelMaterialDefinition mat in mats) { foreach (VoxelDamageItem item in VOXEL_DAMAGE_TYPES) { if (item.MaterialName == mat.MaterialTypeName) { VOXEL_IDS.Add(mat.Index, item); MyLog.Default.WriteLine($"Added {mat.Index}:{mat.MaterialTypeName}"); } } } }
public InventoryItemDialog() { //Populate the static list with the ids from the items if (_idList == null) { _idList = new List <MyDefinitionId>(); DictionaryValuesReader <MyDefinitionId, MyDefinitionBase> allDefinitions = MyDefinitionManager.Static.GetAllDefinitions(); foreach (MyDefinitionBase definition in allDefinitions) { MyPhysicalItemDefinition def = definition as MyPhysicalItemDefinition; if (def != null) { _idList.Add(def.Id); } } foreach (MyDefinitionBase definition in allDefinitions) { MyComponentDefinition def = definition as MyComponentDefinition; if (def != null) { _idList.Add(def.Id); } } foreach (MyDefinitionBase definition in allDefinitions) { MyAmmoMagazineDefinition def = definition as MyAmmoMagazineDefinition; if (def != null) { _idList.Add(def.Id); } } } InitializeComponent(); CMB_ItemType.BeginUpdate(); foreach (var entry in _idList) { CMB_ItemType.Items.Add(entry); } CMB_ItemType.EndUpdate(); TXT_ItemAmount.Text = "0.0"; }
public static void AddPlanetPrefab(string planetName, string definitionName, Vector3D position, bool addGPS) { DictionaryValuesReader <MyDefinitionId, MyPlanetPrefabDefinition> planetPrefabDefinitions = MyDefinitionManager.Static.GetPlanetsPrefabsDefinitions(); foreach (var planetPrefabDefinition in planetPrefabDefinitions) { if (planetPrefabDefinition.Id.SubtypeName == planetName) { MyPlanetGeneratorDefinition planetDefinition = MyDefinitionManager.Static.GetDefinition <MyPlanetGeneratorDefinition>(MyStringHash.GetOrCompute(definitionName)); var planet = new MyPlanet(); var ob = planetPrefabDefinition.PlanetBuilder; string storageName = MyFileSystem.ContentPath + "\\VoxelMaps\\" + ob.StorageName + MyVoxelConstants.FILE_EXTENSION; planet.EntityId = ob.EntityId; MyPlanetInitArguments planetInitArguments; planetInitArguments.StorageName = ob.StorageName; planetInitArguments.Storage = MyStorageBase.LoadFromFile(storageName); planetInitArguments.PositionMinCorner = position; planetInitArguments.Radius = ob.Radius; planetInitArguments.AtmosphereRadius = ob.AtmosphereRadius; planetInitArguments.MaxRadius = ob.MaximumHillRadius; planetInitArguments.MinRadius = ob.MinimumSurfaceRadius; planetInitArguments.HasAtmosphere = planetDefinition.HasAtmosphere; planetInitArguments.AtmosphereWavelengths = ob.AtmosphereWavelengths; planetInitArguments.GravityFalloff = planetDefinition.GravityFalloffPower; planetInitArguments.MarkAreaEmpty = true; planetInitArguments.AtmosphereSettings = ob.AtmosphereSettings.HasValue ? ob.AtmosphereSettings.Value : MyAtmosphereSettings.Defaults(); planetInitArguments.SurfaceGravity = planetDefinition.SurfaceGravity; planetInitArguments.AddGps = addGPS; planetInitArguments.SpherizeWithDistance = true; planetInitArguments.Generator = planetDefinition; planetInitArguments.UserCreated = false; planetInitArguments.InitializeComponents = true; planet.Init(planetInitArguments); MyEntities.Add(planet); MyEntities.RaiseEntityCreated(planet); } } }
private void CMB_BlockType_SelectedIndexChanged(object sender, EventArgs e) { CMB_BlockSubType.BeginUpdate(); CMB_BlockSubType.Items.Clear(); DictionaryValuesReader <MyDefinitionId, MyDefinitionBase> allDefinitions = MyDefinitionManager.Static.GetAllDefinitions( ); foreach (MyDefinitionBase o in allDefinitions) { MyCubeBlockDefinition cubeBlockDefinition = o as MyCubeBlockDefinition; if (cubeBlockDefinition == null) { continue; } if (cubeBlockDefinition.Id.TypeId == SelectedType.Key) { CMB_BlockSubType.Items.Add(cubeBlockDefinition.Id.SubtypeName); } } CMB_BlockSubType.EndUpdate(); }
public void Consume(MyFixedPoint amount, MyConsumableItemDefinition definition) { if (definition != null) { MyObjectBuilder_EntityStatRegenEffect objectBuilder = new MyObjectBuilder_EntityStatRegenEffect { Interval = 1f, MaxRegenRatio = 1f, MinRegenRatio = 0f }; foreach (MyConsumableItemDefinition.StatValue value2 in definition.Stats) { MyEntityStat stat; DictionaryValuesReader <MyStringHash, MyEntityStat> stats = base.Stats; if (stats.TryGetValue(MyStringHash.GetOrCompute(value2.Name), out stat)) { objectBuilder.TickAmount = value2.Value * ((float)amount); objectBuilder.Duration = value2.Time; stat.AddEffect(objectBuilder); } } } }
/// <summary> /// Modifies all matching definitions. /// </summary> /// <param name="dictionary">A dictionary with definition ids and icon paths.</param> /// <param name="definitions">All block, component and tool definitions.</param> /// <param name="blueprintDefinitions">All blueprint definitions.</param> /// <param name="groupDefinitions">All block groups definitions.</param> private void ModifyDefinitions(Dictionary <string, string> dictionary, ref DictionaryValuesReader <MyDefinitionId, MyDefinitionBase> definitions, ref DictionaryValuesReader <MyDefinitionId, MyBlueprintDefinitionBase> blueprintDefinitions, ref DictionaryReader <string, MyBlockVariantGroup> groupDefinitions) { foreach (var definitionPair in dictionary) { try { var definitionId = MyDefinitionId.Parse(definitionPair.Key); var iconPath = definitionPair.Value; if (definitionPair.Key.StartsWith("MyObjectBuilder_BlueprintDefinition/")) { MyBlueprintDefinitionBase blueprint; if (blueprintDefinitions.TryGetValue(definitionId, out blueprint)) { ChangeIcon(blueprint, iconPath); } } else if (definitionPair.Key.StartsWith("MyObjectBuilder_BlockVariantGroup/")) { MyBlockVariantGroup group; if (groupDefinitions.TryGetValue(definitionId.SubtypeName, out group)) { ChangeIcon(group, iconPath); } } else { MyDefinitionBase definition; if (definitions.TryGetValue(definitionId, out definition)) { ChangeIcon(definition, iconPath); } } } catch (ArgumentException e) { MyLog.Default.WriteLineAndConsole($"Failed to parse definition ID: {definitionPair.Key}, Message{e.Message}"); } } }
private static MyPlanet CreatePlanet(string storageName, ref Vector3D positionMinCorner, int seed, float size, long entityId, ref DictionaryValuesReader <MyDefinitionId, MyPlanetGeneratorDefinition> planetDefinitions) { if (MyFakes.ENABLE_PLANETS == false) { //return null; } m_materialsByOreType.Clear(); m_oreProbalities.Clear(); m_spawningMaterials.Clear(); m_organicMaterials.Clear(); foreach (var planetGeneratorDefinition in planetDefinitions) { var random = MyRandom.Instance; using (var stateToken = random.PushSeed(seed)) { BuildOreProbabilities(planetGeneratorDefinition); FillMaterialCollections(); MyCsgShapePlanetShapeAttributes shapeAttributes = new MyCsgShapePlanetShapeAttributes(); shapeAttributes.Seed = seed; shapeAttributes.Diameter = size; shapeAttributes.Radius = size / 2.0f; shapeAttributes.DeviationScale = random.NextFloat(planetGeneratorDefinition.Deviation.Min, planetGeneratorDefinition.Deviation.Max); float maxHillSize = random.NextFloat(planetGeneratorDefinition.HillParams.SizeRatio.Min, planetGeneratorDefinition.HillParams.SizeRatio.Max); float planetHalfDeviation = (shapeAttributes.Diameter * shapeAttributes.DeviationScale) / 2.0f; float hillHalfDeviation = planetHalfDeviation * maxHillSize; float canyonHalfDeviation = 1; float averagePlanetRadius = shapeAttributes.Radius - hillHalfDeviation; float outerRadius = averagePlanetRadius + hillHalfDeviation; float innerRadius = averagePlanetRadius - canyonHalfDeviation; float atmosphereRadius = MathHelper.Max(outerRadius, averagePlanetRadius * 1.08f); float minPlanetRadius = MathHelper.Min(innerRadius, averagePlanetRadius - planetHalfDeviation * 2 * 2.5f); MyCsgShapePlanetMaterialAttributes materialAttributes = new MyCsgShapePlanetMaterialAttributes(); materialAttributes.OreStartDepth = innerRadius - random.NextFloat(planetGeneratorDefinition.MaterialsMinDepth.Min, planetGeneratorDefinition.MaterialsMinDepth.Max); materialAttributes.OreEndDepth = innerRadius - random.NextFloat(planetGeneratorDefinition.MaterialsMaxDepth.Min, planetGeneratorDefinition.MaterialsMaxDepth.Max); materialAttributes.OreEndDepth = MathHelper.Max(materialAttributes.OreEndDepth, 0); materialAttributes.OreStartDepth = MathHelper.Max(materialAttributes.OreStartDepth, 0); bool isHostile = random.NextFloat(0, 1) < planetGeneratorDefinition.HostilityProbability; materialAttributes.OreProbabilities = new MyOreProbability[m_oreProbalities.Count]; for (int i = 0; i < m_oreProbalities.Count; ++i) { materialAttributes.OreProbabilities[i] = m_oreProbalities[i]; materialAttributes.OreProbabilities[i].CummulativeProbability /= m_oreCummulativeProbability; } shapeAttributes.AveragePlanetRadius = averagePlanetRadius; IMyStorage storage = new MyOctreeStorage(MyCompositeShapeProvider.CreatePlanetShape(0, ref shapeAttributes, hillHalfDeviation, ref materialAttributes), MyVoxelCoordSystems.FindBestOctreeSize(size)); float redAtmosphereShift = isHostile ? random.NextFloat(planetGeneratorDefinition.HostileAtmosphereColorShift.R.Min, planetGeneratorDefinition.HostileAtmosphereColorShift.R.Max) : 0; float greenAtmosphereShift = isHostile ? random.NextFloat(planetGeneratorDefinition.HostileAtmosphereColorShift.G.Min, planetGeneratorDefinition.HostileAtmosphereColorShift.G.Max) : 0; float blueAtmosphereShift = isHostile ? random.NextFloat(planetGeneratorDefinition.HostileAtmosphereColorShift.B.Min, planetGeneratorDefinition.HostileAtmosphereColorShift.B.Max) : 0; Vector3 atmosphereWavelengths = new Vector3(0.650f + redAtmosphereShift, 0.570f + greenAtmosphereShift, 0.475f + blueAtmosphereShift); atmosphereWavelengths.X = MathHelper.Clamp(atmosphereWavelengths.X, 0.1f, 1.0f); atmosphereWavelengths.Y = MathHelper.Clamp(atmosphereWavelengths.Y, 0.1f, 1.0f); atmosphereWavelengths.Z = MathHelper.Clamp(atmosphereWavelengths.Z, 0.1f, 1.0f); float gravityFalloff = random.NextFloat(planetGeneratorDefinition.GravityFalloffPower.Min, planetGeneratorDefinition.GravityFalloffPower.Max); var voxelMap = new MyPlanet(); voxelMap.EntityId = entityId; MyPlanetInitArguments planetInitArguments; planetInitArguments.StorageName = storageName; planetInitArguments.Storage = storage; planetInitArguments.PositionMinCorner = positionMinCorner; planetInitArguments.AveragePlanetRadius = averagePlanetRadius; planetInitArguments.AtmosphereRadius = atmosphereRadius; planetInitArguments.MaximumHillRadius = averagePlanetRadius + hillHalfDeviation; planetInitArguments.MinimumSurfaceRadius = minPlanetRadius; planetInitArguments.HasAtmosphere = planetGeneratorDefinition.HasAtmosphere; planetInitArguments.AtmosphereWavelengths = atmosphereWavelengths; planetInitArguments.MaxOxygen = isHostile ? 0.0f : 1.0f; planetInitArguments.GravityFalloff = gravityFalloff; planetInitArguments.MarkAreaEmpty = false; voxelMap.Init(planetInitArguments); MyEntities.Add(voxelMap); m_materialsByOreType.Clear(); m_oreProbalities.Clear(); m_spawningMaterials.Clear(); m_organicMaterials.Clear(); return(voxelMap); } } return(null); }
public static MyPlanet AddPlanet(string storageName, Vector3D positionMinCorner, int seed, float size, long entityId = 0, bool isMoon = false) { DictionaryValuesReader <MyDefinitionId, MyPlanetGeneratorDefinition> planetDefinitions = isMoon ? MyDefinitionManager.Static.GetMoonsGeneratorsDefinitions() :MyDefinitionManager.Static.GetPlanetsGeneratorsDefinitions(); return(CreatePlanet(storageName, ref positionMinCorner, seed, size, entityId, ref planetDefinitions)); }
private static MyPlanet CreatePlanet(string storageName, ref Vector3D positionMinCorner, int seed, float size, long entityId, ref DictionaryValuesReader<MyDefinitionId, MyPlanetGeneratorDefinition> planetDefinitions) { if (MyFakes.ENABLE_PLANETS == false) { //return null; } m_materialsByOreType.Clear(); m_oreProbalities.Clear(); m_spawningMaterials.Clear(); m_organicMaterials.Clear(); foreach (var planetGeneratorDefinition in planetDefinitions) { var random = MyRandom.Instance; using (var stateToken = random.PushSeed(seed)) { BuildOreProbabilities(planetGeneratorDefinition); FillMaterialCollections(); MyCsgShapePlanetShapeAttributes shapeAttributes = new MyCsgShapePlanetShapeAttributes(); shapeAttributes.Seed = seed; shapeAttributes.Diameter = size; shapeAttributes.Radius = size / 2.0f; shapeAttributes.DeviationScale = random.NextFloat(planetGeneratorDefinition.Deviation.Min, planetGeneratorDefinition.Deviation.Max); float maxHillSize = random.NextFloat(planetGeneratorDefinition.HillParams.SizeRatio.Min, planetGeneratorDefinition.HillParams.SizeRatio.Max); float planetHalfDeviation = (shapeAttributes.Diameter * shapeAttributes.DeviationScale) / 2.0f; float hillHalfDeviation = planetHalfDeviation * maxHillSize; float canyonHalfDeviation = 1; float averagePlanetRadius = shapeAttributes.Radius - hillHalfDeviation; float outerRadius = averagePlanetRadius + hillHalfDeviation; float innerRadius = averagePlanetRadius - canyonHalfDeviation; float atmosphereRadius = MathHelper.Max(outerRadius, averagePlanetRadius * 1.08f); float minPlanetRadius = MathHelper.Min(innerRadius, averagePlanetRadius - planetHalfDeviation * 2 * 2.5f); MyCsgShapePlanetMaterialAttributes materialAttributes = new MyCsgShapePlanetMaterialAttributes(); materialAttributes.OreStartDepth = innerRadius - random.NextFloat(planetGeneratorDefinition.MaterialsMinDepth.Min, planetGeneratorDefinition.MaterialsMinDepth.Max); materialAttributes.OreEndDepth = innerRadius - random.NextFloat(planetGeneratorDefinition.MaterialsMaxDepth.Min, planetGeneratorDefinition.MaterialsMaxDepth.Max); materialAttributes.OreEndDepth = MathHelper.Max(materialAttributes.OreEndDepth, 0); materialAttributes.OreStartDepth = MathHelper.Max(materialAttributes.OreStartDepth, 0); bool isHostile = random.NextFloat(0, 1) < planetGeneratorDefinition.HostilityProbability; materialAttributes.OreProbabilities = new MyOreProbability[m_oreProbalities.Count]; for (int i = 0; i < m_oreProbalities.Count; ++i) { materialAttributes.OreProbabilities[i] = m_oreProbalities[i]; materialAttributes.OreProbabilities[i].CummulativeProbability /= m_oreCummulativeProbability; } shapeAttributes.AveragePlanetRadius = averagePlanetRadius; IMyStorage storage = new MyOctreeStorage(MyCompositeShapeProvider.CreatePlanetShape(0, ref shapeAttributes, hillHalfDeviation, ref materialAttributes), MyVoxelCoordSystems.FindBestOctreeSize(size)); float redAtmosphereShift = isHostile ? random.NextFloat(planetGeneratorDefinition.HostileAtmosphereColorShift.R.Min, planetGeneratorDefinition.HostileAtmosphereColorShift.R.Max) : 0; float greenAtmosphereShift = isHostile ? random.NextFloat(planetGeneratorDefinition.HostileAtmosphereColorShift.G.Min, planetGeneratorDefinition.HostileAtmosphereColorShift.G.Max) : 0; float blueAtmosphereShift = isHostile ? random.NextFloat(planetGeneratorDefinition.HostileAtmosphereColorShift.B.Min, planetGeneratorDefinition.HostileAtmosphereColorShift.B.Max) : 0; Vector3 atmosphereWavelengths = new Vector3(0.650f + redAtmosphereShift, 0.570f + greenAtmosphereShift, 0.475f + blueAtmosphereShift); atmosphereWavelengths.X = MathHelper.Clamp(atmosphereWavelengths.X, 0.1f, 1.0f); atmosphereWavelengths.Y = MathHelper.Clamp(atmosphereWavelengths.Y, 0.1f, 1.0f); atmosphereWavelengths.Z = MathHelper.Clamp(atmosphereWavelengths.Z, 0.1f, 1.0f); float gravityFalloff = random.NextFloat(planetGeneratorDefinition.GravityFalloffPower.Min, planetGeneratorDefinition.GravityFalloffPower.Max); var voxelMap = new MyPlanet(); voxelMap.EntityId = entityId; MyPlanetInitArguments planetInitArguments; planetInitArguments.StorageName = storageName; planetInitArguments.Storage = storage; planetInitArguments.PositionMinCorner = positionMinCorner; planetInitArguments.AveragePlanetRadius = averagePlanetRadius; planetInitArguments.AtmosphereRadius = atmosphereRadius; planetInitArguments.MaximumHillRadius = averagePlanetRadius + hillHalfDeviation; planetInitArguments.MinimumSurfaceRadius = minPlanetRadius; planetInitArguments.HasAtmosphere = planetGeneratorDefinition.HasAtmosphere; planetInitArguments.AtmosphereWavelengths = atmosphereWavelengths; planetInitArguments.MaxOxygen = isHostile ? 0.0f : 1.0f; planetInitArguments.GravityFalloff = gravityFalloff; planetInitArguments.MarkAreaEmpty = false; voxelMap.Init(planetInitArguments); MyEntities.Add(voxelMap); m_materialsByOreType.Clear(); m_oreProbalities.Clear(); m_spawningMaterials.Clear(); m_organicMaterials.Clear(); return voxelMap; } } return null; }