Skip to content

Commit

Permalink
Messed around with adding a mod data viewer.
Browse files Browse the repository at this point in the history
Messed around with some damage stuff.
  • Loading branch information
se5a committed Feb 25, 2024
1 parent 40d2165 commit 9f4e7cb
Show file tree
Hide file tree
Showing 10 changed files with 574 additions and 24 deletions.
52 changes: 52 additions & 0 deletions Pulsar4X/GameEngine/Data/basemod/DamageResistance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[
{
"Type": "DamageResistance",
"Payload": {
"UniqueID": "0",
"MaterialID": "",
"HitPoints": "0",
"MeltingPoint": "0",
"Density": "0"
}
},
{
"Type": "DamageResistance",
"Payload": {
"UniqueID": "100",
"MaterialID": "plastic",
"HitPoints": "255",
"MeltingPoint": "170",
"Density": "1175f"
}
},
{
"Type": "DamageResistance",
"Payload": {
"UniqueID": "150",
"MaterialID": "aluminium",
"HitPoints": "0",
"MeltingPoint": "660",
"Density": "2700f"
}
},
{
"Type": "DamageResistance",
"Payload": {
"UniqueID": "200",
"MaterialID": "titanium",
"HitPoints": "255",
"MeltingPoint": "1668",
"Density": "4540f"
}
},
{
"Type": "DamageResistance",
"Payload": {
"UniqueID": "255",
"MaterialID": "stainless-steel",
"HitPoints": "255",
"MeltingPoint": "1400",
"Density": "7900"
}
}
]
2 changes: 1 addition & 1 deletion Pulsar4X/GameEngine/Engine/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class Game
public Random RNG { get; } = new Random(12345689);

[JsonProperty]
internal ModDataStore StartingGameData { get; private set; }
public ModDataStore StartingGameData { get; private set; }

[JsonProperty]
internal GalaxyFactory GalaxyGen { get; private set; }
Expand Down
30 changes: 15 additions & 15 deletions Pulsar4X/GameEngine/FeatureSets/DamageComplex/DamageTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using Pulsar4X.Blueprints;
using Pulsar4X.Orbital;
using Pulsar4X.Components;
using Pulsar4X.Datablobs;
Expand All @@ -23,7 +24,10 @@ public enum Connections
Structural = 15
}

public struct DamageResist
/// <summary>
/// Merge this into materials?
/// </summary>
public class DamageResistBlueprint: Blueprint
{
/*
this could potentialy get more complex,
Expand All @@ -33,11 +37,14 @@ public struct DamageResist
*/
public byte IDCode;
public int HitPoints;

public int MeltingPoint;
//public float Heat;
//public float Kinetic;
public float Density;

public DamageResist(byte iDCode, int hitPoints, float density)

public DamageResistBlueprint(byte iDCode, int hitPoints, float density)
{
IDCode = iDCode;
HitPoints = hitPoints;
Expand All @@ -52,7 +59,7 @@ public struct DamageFragment
{
public Vector2 Velocity;
public (int x,int y) Position;
//public double Angle;
public double Heat;
public float Mass;
public float Momentum;
public float Density;//kg/m^3
Expand All @@ -61,18 +68,11 @@ public struct DamageFragment

public static class DamageTools
{
public static Dictionary<byte, DamageResist> DamageResistsLookupTable = new Dictionary<byte, DamageResist>()
public static Dictionary<byte, DamageResistBlueprint> DamageResistsLookupTable = new Dictionary<byte, DamageResistBlueprint>()
{
{0, new DamageResist() {IDCode = 0, HitPoints = 0}} //emptyspace

};

// struct Bitmap
// {
// public int Height;
// public int Width;
// public int Stride;
// public byte[] PxArray;
// }


public static RawBmp LoadFromBitMap(string file)
{
Expand Down Expand Up @@ -147,7 +147,7 @@ public static Color FromByte(byte byteColor)
return color;
}

public static DamageResist FromColor(Color color)
public static DamageResistBlueprint FromColor(Color color)
{
byte id = color.R;
return DamageResistsLookupTable[id];
Expand Down Expand Up @@ -245,7 +245,7 @@ public static (List<(byte id, int damageAmount)> damageToComponents, List<RawBmp
(byte r, byte g, byte b, byte a) px = thisFrame.GetPixel(dpos.x, dpos.y);
if (px.a > 0)
{
DamageResist damageresist = DamageResistsLookupTable[px.r];
DamageResistBlueprint damageresist = DamageResistsLookupTable[px.r];

double density = damageresist.Density / (px.a / 255f); //density / health
double maxImpactDepth = dlen * dden / density;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ r : maps to a damage resistance table. currently only used by armor, (components
and is set in the ui damage viewer (eek! obv was tempory wip for quick test setup.)
this has a byte ID (red) material hitpoints, and material density)
g : maps to the specific component instance. (ships currently will only be able to have 255 components max.)
b : currently unused
b : currently unused, maybe status and phase type? eg no physics, temprature, solid, liquid, gas.
a : is the health of the material at this point.

An undamaged ship is suposed to have/share a "DamageProfile" of it's design class to save memory.
Expand Down
3 changes: 3 additions & 0 deletions Pulsar4X/GameEngine/Modding/ModDataStore.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using Pulsar4X.Blueprints;
using Pulsar4X.Engine.Damage;
using Pulsar4X.Engine.Industry;

namespace Pulsar4X.Modding
Expand All @@ -19,5 +20,7 @@ public class ModDataStore
public Dictionary<string, TechCategoryBlueprint> TechCategories { get; set; } = new ();
public Dictionary<string, ThemeBlueprint> Themes { get; set; } = new ();
public Dictionary<string, DefaultItemsBlueprint> DefaultItems { get; set; } = new ();

public Dictionary<string, DamageResistBlueprint> DamageResists { get; set; } = new();
}
}
5 changes: 5 additions & 0 deletions Pulsar4X/GameEngine/Modding/ModInstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Pulsar4X.Blueprints;
using Pulsar4X.Engine.Damage;
using Pulsar4X.Engine.Industry;

namespace Pulsar4X.Modding
Expand All @@ -22,6 +23,7 @@ public enum DataType
Tech,
TechCategory,
Theme,
DamageResist,
}
public enum OperationType { Default, Remove }
public enum CollectionOperationType { Add, Remove, Overwrite }
Expand Down Expand Up @@ -96,6 +98,9 @@ public override bool CanConvert(Type objectType)
case ModInstruction.DataType.Theme:
instruction.Data = jObject["Payload"].ToObject<ThemeBlueprint>();
break;
case ModInstruction.DataType.DamageResist:
instruction.Data = jObject["DamageResistance"].ToObject<DamageResistBlueprint>();
break;
}

return instruction;
Expand Down
4 changes: 4 additions & 0 deletions Pulsar4X/GameEngine/Modding/ModLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Newtonsoft.Json;
using Pulsar4X.DataStructures;
using Pulsar4X.Blueprints;
using Pulsar4X.Engine.Damage;
using Pulsar4X.Extensions;
using Pulsar4X.Engine.Industry;

Expand Down Expand Up @@ -92,6 +93,9 @@ private void ApplyMod(ModDataStore baseData, ModInstruction mod, string modNames
case ModInstruction.DataType.Theme:
ApplyModGeneric<ThemeBlueprint>(baseData.Themes, mod, modNamespace);
break;
case ModInstruction.DataType.DamageResist:
ApplyModGeneric<DamageResistBlueprint>(baseData.DamageResists, mod, modNamespace);
break;
}
}

Expand Down
Loading

0 comments on commit 9f4e7cb

Please sign in to comment.