diff --git a/Content.Server/Content.Server.csproj b/Content.Server/Content.Server.csproj index 9e25ed3229..6432c0902a 100644 --- a/Content.Server/Content.Server.csproj +++ b/Content.Server/Content.Server.csproj @@ -147,5 +147,7 @@ + + \ No newline at end of file diff --git a/Content.Server/EntryPoint.cs b/Content.Server/EntryPoint.cs index 84ac78490a..1a688822b9 100644 --- a/Content.Server/EntryPoint.cs +++ b/Content.Server/EntryPoint.cs @@ -25,6 +25,7 @@ using Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan; using Content.Server.GameObjects.Components.Weapon.Ranged.Projectile; using Content.Server.GameObjects.Components.Projectiles; using Content.Server.GameObjects.Components.Weapon.Melee; +using Content.Server.GameObjects.Components.Materials; namespace Content.Server { @@ -93,6 +94,7 @@ namespace Content.Server factory.Register(); factory.Register(); factory.Register(); + factory.Register(); } /// diff --git a/Content.Server/GameObjects/Components/Materials/MaterialComponent.cs b/Content.Server/GameObjects/Components/Materials/MaterialComponent.cs new file mode 100644 index 0000000000..12400e8a4b --- /dev/null +++ b/Content.Server/GameObjects/Components/Materials/MaterialComponent.cs @@ -0,0 +1,81 @@ +using System.Collections.Generic; +using Content.Server.Materials; +using SS14.Shared.GameObjects; +using SS14.Shared.Interfaces.Reflection; +using SS14.Shared.Interfaces.Serialization; +using SS14.Shared.IoC; +using SS14.Shared.Prototypes; +using SS14.Shared.Serialization; +using SS14.Shared.Utility; + +namespace Content.Server.GameObjects.Components.Materials +{ + /// + /// Component to store data such as "this object is made out of steel". + /// This is not a storage system for say smelteries. + /// + public class MaterialComponent : Component + { + public const string SerializationCache = "mat"; + public override string Name => "Material"; + + Dictionary MaterialTypes; + + public override void ExposeData(ObjectSerializer serializer) + { + base.ExposeData(serializer); + + // TODO: Writing. + if (!serializer.Reading) + { + return; + } + + if (serializer.TryGetCacheData(SerializationCache, out Dictionary cached)) + { + MaterialTypes = cached.ShallowClone(); + return; + } + + MaterialTypes = new Dictionary(); + + if (serializer.TryReadDataField("materials", out List list)) + { + var protoMan = IoCManager.Resolve(); + int index = 0; + foreach (var entry in list) + { + var proto = protoMan.Index(entry.Value); + MaterialTypes[entry.Key] = proto.Material; + index++; + } + } + + serializer.SetCacheData(SerializationCache, MaterialTypes.ShallowClone()); + } + + class MaterialDataEntry : IExposeData + { + public object Key; + public string Value; + + public void ExposeData(ObjectSerializer serializer) + { + if (!serializer.Reading) + { + return; + } + + var refl = IoCManager.Resolve(); + Value = serializer.ReadDataField("mat", "unobtanium"); + var key = serializer.ReadDataField("key", string.Empty); + if (refl.TryParseEnumReference(key, out var @enum)) + { + Key = @enum; + return; + } + Key = key; + } + } + } +} diff --git a/Content.Server/Materials/Material.cs b/Content.Server/Materials/Material.cs new file mode 100644 index 0000000000..9941cfb007 --- /dev/null +++ b/Content.Server/Materials/Material.cs @@ -0,0 +1,109 @@ +using SS14.Shared.Interfaces.Serialization; +using SS14.Shared.Maths; +using SS14.Shared.Prototypes; +using SS14.Shared.Serialization; +using SS14.Shared.Utility; +using YamlDotNet.RepresentationModel; + +namespace Content.Server.Materials +{ + /// + /// Materials are read-only storage for the properties of specific materials. + /// Properties should be intrinsic (or at least as much is necessary for game purposes). + /// + public class Material : IExposeData + { + public string Name => _name; + private string _name = "unobtanium"; + + public Color Color => _color; + private Color _color = Color.Gray; + + /// + /// Volumetric mass density, in kg.m^-3. + /// + public double Density => _density; + private double _density = 1; + + /// + /// Electrical resistivity, NOT resistance. + /// Unit is ohm-meter (Ω⋅m). + /// + public double ElectricResistivity => _electricResistivity; + private double _electricResistivity = 1; + + /// + /// Thermal conductivity, in W.m-1.K-1 + /// + public double ThermalConductivity => _thermalConductivity; + private double _thermalConductivity = 1; + + /// + /// Specific heat, in J.kg-1.K-1 + /// + public double SpecificHeat => _specificHeat; + private double _specificHeat = 1; + + /// + /// Controls how durable the material is. + /// Basically how slowly it degrades. + /// + public double Durability => _durability; + private double _durability = 1; + + /// + /// Multiplier for how much this resists damage. + /// So higher means armor is more effective, for example. + /// + public double Hardness => _hardness; + private double _hardness = 1; + + /// + /// Multiplier that determines damage on sharpness-based weapons like knives. + /// Higher means more damage is done. + /// + public double SharpDamage { get; } = 1; + private double _sharpDamage = 1; + + /// + /// Multiplier that determines damage on blunt-based weapons like clubs. + /// Higher means more damage is done. + /// + public double BluntDamage { get; } = 1; + private double _bluntDamage = 1; + + public void ExposeData(ObjectSerializer serializer) + { + serializer.DataField(ref _name, "name", "unobtanium", alwaysWrite: true); + serializer.DataField(ref _color, "color", Color.Gray, alwaysWrite: true); + + // All default material params are initialized to 1 because + // I'm too lazy to figure out for which that's necessary to prevent divisions by zero in case left out. + serializer.DataField(ref _density, "density", 1, alwaysWrite: true); + serializer.DataField(ref _electricResistivity, "electricresistivity", 1, alwaysWrite: true); + serializer.DataField(ref _thermalConductivity, "thermalconductivity", 1, alwaysWrite: true); + serializer.DataField(ref _specificHeat, "specificheat", 1, alwaysWrite: true); + serializer.DataField(ref _durability, "durability", 1, alwaysWrite: true); + serializer.DataField(ref _hardness, "hardness", 1, alwaysWrite: true); + serializer.DataField(ref _sharpDamage, "sharpdamage", 1, alwaysWrite: true); + serializer.DataField(ref _bluntDamage, "bluntdamage", 1, alwaysWrite: true); + } + } + + [Prototype("material")] + public class MaterialPrototype : IPrototype, IIndexedPrototype + { + public string ID { get; private set; } + + public Material Material { get; private set; } + + public void LoadFrom(YamlMappingNode mapping) + { + ID = mapping["id"].AsString(); + + var ser = YamlObjectSerializer.NewReader(mapping); + Material = new Material(); + Material.ExposeData(ser); + } + } +} diff --git a/Resources/Prototypes/materials.yml b/Resources/Prototypes/materials.yml new file mode 100644 index 0000000000..16ffd541f3 --- /dev/null +++ b/Resources/Prototypes/materials.yml @@ -0,0 +1,17 @@ +- type: material + id: steel + name: Steel + color: gray + density: 7700 + electricresistivity: 6.9e-7 + thermalconductivity: 18 + specificheat: 500 + +- type: material + id: glass + name: Glass + color: '#e8f0ff33' + density: 2500 + electricresistivity: 1.0e+13 + thermalconductivity: 0.9 + specificheat: 840 diff --git a/engine b/engine index 696bf486a6..8aa6d1ccc3 160000 --- a/engine +++ b/engine @@ -1 +1 @@ -Subproject commit 696bf486a67ebe953a69fe81e227c1e957bb2ca6 +Subproject commit 8aa6d1ccc32310a2d410fb48e8cc029731cf8c59