コード例 #1
0
        public MyPlanetEnvironmentMapping(PlanetEnvironmentItemMapping map)
        {
            Rule  = map.Rule;
            Items = new MyMaterialEnvironmentItem[map.Items.Length];
            if (Items.Length <= 0)
            {
                CumulativeIntervals = null;
                TotalFrequency      = 0;
                return;
            }

            TotalFrequency = 0;
            for (int i = 0; i < map.Items.Length; i++)
            {
                var item = map.Items[i];

                MyObjectBuilderType type;
                if (item.TypeId != null && MyObjectBuilderType.TryParse(item.TypeId, out type))
                {
                    if (!typeof(MyObjectBuilder_BotDefinition).IsAssignableFrom((Type)type) && !typeof(MyObjectBuilder_VoxelMapStorageDefinition).IsAssignableFrom((Type)type) && !typeof(MyObjectBuilder_EnvironmentItems).IsAssignableFrom((Type)type))
                    {
                        MyLog.Default.WriteLine(String.Format("Object builder type {0} is not supported for environment items.", item.TypeId));
                        Items[i].Frequency = 0; // This should disable this item
                    }
                    else
                    {
                        Items[i] = new MyMaterialEnvironmentItem()
                        {
                            Definition        = new MyDefinitionId(type, item.SubtypeId),
                            Frequency         = map.Items[i].Density,
                            IsDetail          = map.Items[i].IsDetail,
                            IsBot             = typeof(MyObjectBuilder_BotDefinition).IsAssignableFrom((Type)type),
                            IsVoxel           = typeof(MyObjectBuilder_VoxelMapStorageDefinition).IsAssignableFrom((Type)type),
                            IsEnvironemntItem = typeof(MyObjectBuilder_EnvironmentItems).IsAssignableFrom((Type)type),
                            BaseColor         = map.Items[i].BaseColor,
                            ColorSpread       = map.Items[i].ColorSpread,
                            MaxRoll           = (float)Math.Cos(MathHelper.ToDegrees(map.Items[i].MaxRoll)),
                            Offset            = map.Items[i].Offset,
                            GroupId           = map.Items[i].GroupId,
                            GroupIndex        = map.Items[i].GroupIndex,
                            ModifierId        = map.Items[i].ModifierId,
                            ModifierIndex     = map.Items[i].ModifierIndex
                        };
                    }
                }
                else
                {
                    MyLog.Default.WriteLine(String.Format("Object builder type {0} does not exist.", item.TypeId));
                    Items[i].Frequency = 0; // This should disable this item
                }
            }

            ComputeDistribution();
        }
コード例 #2
0
 public MyPlanetEnvironmentMapping(PlanetEnvironmentItemMapping map)
 {
     this.Rule  = map.Rule;
     this.Items = new MyMaterialEnvironmentItem[map.Items.Length];
     if (this.Items.Length == 0)
     {
         this.CumulativeIntervals = null;
         this.TotalFrequency      = 0f;
     }
     else
     {
         this.TotalFrequency = 0f;
         for (int i = 0; i < map.Items.Length; i++)
         {
             MyObjectBuilderType        type;
             MyPlanetEnvironmentItemDef def = map.Items[i];
             if ((def.TypeId == null) || !MyObjectBuilderType.TryParse(def.TypeId, out type))
             {
                 MyLog.Default.WriteLine($"Object builder type {def.TypeId} does not exist.");
                 this.Items[i].Frequency = 0f;
             }
             else if ((!typeof(MyObjectBuilder_BotDefinition).IsAssignableFrom((Type)type) && !typeof(MyObjectBuilder_VoxelMapStorageDefinition).IsAssignableFrom((Type)type)) && !typeof(MyObjectBuilder_EnvironmentItems).IsAssignableFrom((Type)type))
             {
                 MyLog.Default.WriteLine($"Object builder type {def.TypeId} is not supported for environment items.");
                 this.Items[i].Frequency = 0f;
             }
             else
             {
                 MyMaterialEnvironmentItem item1 = new MyMaterialEnvironmentItem();
                 item1.Definition        = new MyDefinitionId(type, def.SubtypeId);
                 item1.Frequency         = map.Items[i].Density;
                 item1.IsDetail          = map.Items[i].IsDetail;
                 item1.IsBot             = typeof(MyObjectBuilder_BotDefinition).IsAssignableFrom((Type)type);
                 item1.IsVoxel           = typeof(MyObjectBuilder_VoxelMapStorageDefinition).IsAssignableFrom((Type)type);
                 item1.IsEnvironemntItem = typeof(MyObjectBuilder_EnvironmentItems).IsAssignableFrom((Type)type);
                 item1.BaseColor         = map.Items[i].BaseColor;
                 item1.ColorSpread       = map.Items[i].ColorSpread;
                 item1.MaxRoll           = (float)Math.Cos((double)MathHelper.ToDegrees(map.Items[i].MaxRoll));
                 item1.Offset            = map.Items[i].Offset;
                 item1.GroupId           = map.Items[i].GroupId;
                 item1.GroupIndex        = map.Items[i].GroupIndex;
                 item1.ModifierId        = map.Items[i].ModifierId;
                 item1.ModifierIndex     = map.Items[i].ModifierIndex;
                 this.Items[i]           = item1;
             }
         }
         this.ComputeDistribution();
     }
 }
コード例 #3
0
        public MyPlanetEnvironmentMapping(PlanetEnvironmentItemMapping map)
        {
            Rule = map.Rule;
            Items = new MyMaterialEnvironmentItem[map.Items.Length];
            if (Items.Length <= 0)
            {
                CumulativeIntervals = null;
                TotalFrequency = 0;
                return;
            }

            TotalFrequency = 0;
            for (int i = 0; i < map.Items.Length; i++)
            {
                var item = map.Items[i];

                MyObjectBuilderType type;
                if (item.TypeId != null && MyObjectBuilderType.TryParse(item.TypeId, out type))
                {
                    if (!typeof(MyObjectBuilder_BotDefinition).IsAssignableFrom((Type)type) && !typeof(MyObjectBuilder_VoxelMapStorageDefinition).IsAssignableFrom((Type)type) && !typeof(MyObjectBuilder_EnvironmentItems).IsAssignableFrom((Type)type))
                    {
                        MyLog.Default.WriteLine(String.Format("Object builder type {0} is not supported for environment items.", item.TypeId));
                        Items[i].Frequency = 0; // This should disable this item
                    }
                    else
                    {
                        Items[i] = new MyMaterialEnvironmentItem()
                        {
                            Definition = new MyDefinitionId(type, item.SubtypeId),
                            Frequency = map.Items[i].Density,
                            IsDetail = map.Items[i].IsDetail,
                            IsBot = typeof(MyObjectBuilder_BotDefinition).IsAssignableFrom((Type)type),
                            IsVoxel = typeof(MyObjectBuilder_VoxelMapStorageDefinition).IsAssignableFrom((Type)type),
                            IsEnvironemntItem = typeof(MyObjectBuilder_EnvironmentItems).IsAssignableFrom((Type)type),
                            BaseColor = map.Items[i].BaseColor,
                            ColorSpread = map.Items[i].ColorSpread,
                            MaxRoll = (float)Math.Cos(MathHelper.ToDegrees(map.Items[i].MaxRoll)),
                            Offset = map.Items[i].Offset,
                            GroupId = map.Items[i].GroupId,
                            GroupIndex = map.Items[i].GroupIndex,
                            ModifierId = map.Items[i].ModifierId,
                            ModifierIndex = map.Items[i].ModifierIndex
                        };
                    }
                }
                else
                {
                    MyLog.Default.WriteLine(String.Format("Object builder type {0} does not exist.", item.TypeId));
                    Items[i].Frequency = 0; // This should disable this item
                }
            }

            ComputeDistribution();
        }