Skip to content

Commit

Permalink
feat: Starting armies use recruitable units (#62)
Browse files Browse the repository at this point in the history
* feat: get units by faction name

* create strat unit, and tests

* logic to add unit to a army, further tests for this functionality

* fix: missing model texture apply function, fixes issues with DMB and invisible mounts

* fix: simple help command, improvements to the operational flow

* untrack tasks.json

* .vscode in gitignore

* fix crash caused by nautical nonsense and civilians

* fixed land boats, random seed option

* feat: ensure generals remain as default (temporary measure)

* feat: ability to designate seed as random

* new template for randomisation
  • Loading branch information
sargeantPig authored Sep 1, 2024
1 parent 79fae5d commit 73dca29
Show file tree
Hide file tree
Showing 68 changed files with 25,949 additions and 655 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ dotnet_diagnostic.CA1310.severity = suggestion
# IDE0220: Add explicit cast in foreach
dotnet_diagnostic.IDE0220.severity = suggestion

# Allow underscores in namespace
dotnet_diagnostic.CA1707.severity = none

# Allow constant array arguments
dotnet_diagnostic.CA1861.severity = none

csharp_style_prefer_top_level_statements = false

##########################################
Expand Down
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,6 @@ FodyWeavers.xsd

# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
Expand Down
2 changes: 1 addition & 1 deletion RTWLibPlus/data/RemasterRome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class TWConfig
public static TWConfig LoadConfig(string path)
{
DepthParse dp = new();
string json = dp.ReadFileAsString(path);
string json = DepthParse.ReadFileAsString(path);
return JsonSerializer.Deserialize<TWConfig>(json);
}

Expand Down
18 changes: 9 additions & 9 deletions RTWLibPlus/data/unit/Unit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ private float CalcWeaponStats(Dictionary<string, float> weights, ref float final



float[] values = new float[] { attk, charg, secAttk, secCharge };
float[] values = [attk, charg, secAttk, secCharge];

this.AdjustFinalMod(ref finalmod, values, 0.05f);
AdjustFinalMod(ref finalmod, values, 0.05f);

return attk + charg + secAttk + secCharge;
}
Expand Down Expand Up @@ -431,9 +431,9 @@ private float CalcWeaponAttributes(Dictionary<string, float> weights, ref float
longPike = 0f;
}

float[] values = new float[] { priap, pribp, area, secap, secbp, longPike, launch };
float[] values = [priap, pribp, area, secap, secbp, longPike, launch];

this.AdjustFinalMod(ref finalmod, values, 0.3f);
AdjustFinalMod(ref finalmod, values, 0.3f);


return priap + pribp + area + secap + secbp + longPike + launch;
Expand Down Expand Up @@ -471,9 +471,9 @@ private float CalcAttributes(Dictionary<string, float> weights, ref float finalm
command = 0f;
}

float[] values = new float[] { frightenFoot, frightenMounted, command };
float[] values = [frightenFoot, frightenMounted, command];

this.AdjustFinalMod(ref finalmod, values, 0.2f);
AdjustFinalMod(ref finalmod, values, 0.2f);

return frightenFoot + frightenMounted + command;
}
Expand Down Expand Up @@ -532,14 +532,14 @@ private float CalcArmour(Dictionary<string, float> weights, ref float finalmod)
float armourD = Convert.ToInt16(this.PriArm[1]) * weights["armourDefence"];
float armourS = Convert.ToInt16(this.PriArm[2]) * weights["armourShield"];

float[] values = new float[] { armourF, armourD, armourS };
float[] values = [armourF, armourD, armourS];

this.AdjustFinalMod(ref finalmod, values, 0.05f);
AdjustFinalMod(ref finalmod, values, 0.05f);

return armourF + armourD + armourS;
}

private void AdjustFinalMod(ref float finalmod, float[] values, float scale = 0.1f)
private static void AdjustFinalMod(ref float finalmod, float[] values, float scale = 0.1f)
{
foreach (float val in values)
{
Expand Down
2 changes: 1 addition & 1 deletion RTWLibPlus/data/unit/UnitsWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class UnitsWrapper
{
private readonly List<Unit> units = new();
private readonly List<Unit> units = [];

public UnitsWrapper(EDU edu)
{
Expand Down
4 changes: 2 additions & 2 deletions RTWLibPlus/data/unit/unit_data/MountEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class MountEffect

public MountEffect()
{
this.mountType = new List<string>();
this.modifier = new List<int>();
this.mountType = [];
this.modifier = [];
}
}
34 changes: 17 additions & 17 deletions RTWLibPlus/dataWrappers/TGA/TGA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,29 @@ public void Read(params string[] args)
}

// Display the Header fields
RefHeader.Idlength = (char)fptr.ReadByte();
this.RefHeader.Idlength = (char)fptr.ReadByte();
//Console.Error.WriteLine("ID length: {0}", Header.idlength);
RefHeader.Colourmaptype = (char)fptr.ReadByte();
this.RefHeader.Colourmaptype = (char)fptr.ReadByte();
//Console.Error.WriteLine("Colourmap type: {0}", Header.colourmaptype);
RefHeader.Datatypecode = (char)fptr.ReadByte();
this.RefHeader.Datatypecode = (char)fptr.ReadByte();
//Console.Error.WriteLine("Image type: {0}", Header.datatypecode);
RefHeader.Colourmaporigin = this.ReadShort(fptr);
this.RefHeader.Colourmaporigin = ReadShort(fptr);
// Console.Error.WriteLine("Colour map offset: {0}", Header.colourmaporigin);
RefHeader.Colourmaplength = this.ReadShort(fptr);
this.RefHeader.Colourmaplength = ReadShort(fptr);
//Console.Error.WriteLine("Colour map length: {0}", Header.colourmaplength);
RefHeader.Colourmapdepth = (char)fptr.ReadByte();
this.RefHeader.Colourmapdepth = (char)fptr.ReadByte();
//Console.Error.WriteLine("Colour map depth: {0}", Header.colourmapdepth);
RefHeader.Xorigin = this.ReadShort(fptr);
this.RefHeader.Xorigin = ReadShort(fptr);
//Console.Error.WriteLine("X origin: {0}", Header.x_origin);
RefHeader.Yorigin = this.ReadShort(fptr);
this.RefHeader.Yorigin = ReadShort(fptr);
// Console.Error.WriteLine("Y origin: {0}", Header.y_origin);
RefHeader.Width = this.ReadShort(fptr);
this.RefHeader.Width = ReadShort(fptr);
//Console.Error.WriteLine("Width: {0}", Header.width);
RefHeader.Height = this.ReadShort(fptr);
this.RefHeader.Height = ReadShort(fptr);
//Console.Error.WriteLine("Height: {0}", Header.height);
RefHeader.Bitsperpixel = (char)fptr.ReadByte();
this.RefHeader.Bitsperpixel = (char)fptr.ReadByte();
//Console.Error.WriteLine("Bits per pixel: {0}", Header.bitsperpixel);
RefHeader.Imagedescriptor = (char)fptr.ReadByte();
this.RefHeader.Imagedescriptor = (char)fptr.ReadByte();
//Console.Error.WriteLine("Descriptor: {0}", Header.imagedescriptor);

// Allocate space for the image
Expand Down Expand Up @@ -141,13 +141,13 @@ public void Read(params string[] args)
private int CompressedBlock(int n, out int i, out int j, int bytes2read, byte[] p, FileStream fptr)
{
j = p[0] & 0x7f;
this.MergeBytes(ref this.Pixels[n], p.AsSpan(1).ToArray(), bytes2read);
MergeBytes(ref this.Pixels[n], p.AsSpan(1).ToArray(), bytes2read);
n++;
if ((p[0] & 0x80) != 0)
{ // RLE chunk
for (i = 0; i < j; i++)
{
this.MergeBytes(ref this.Pixels[n], p.AsSpan(1).ToArray(), bytes2read);
MergeBytes(ref this.Pixels[n], p.AsSpan(1).ToArray(), bytes2read);
n++;
}
}
Expand All @@ -166,7 +166,7 @@ private int CompressedBlock(int n, out int i, out int j, int bytes2read, byte[]
private void UncompressedBlock(int n, int i, int bytes2read, byte[] p, FileStream fptr)
{
CheckEoF(i, bytes2read, 0, p, fptr);
this.MergeBytes(ref this.Pixels[n], p, bytes2read);
MergeBytes(ref this.Pixels[n], p, bytes2read);
}

private static void CheckEoF(int i, int bytes2read, int offset, byte[] p, FileStream fptr)
Expand Down Expand Up @@ -221,7 +221,7 @@ public string Output()
return "TGA Written to " + this.OutputPath;
}

public void MergeBytes(ref PIXEL pixel, byte[] p, int bytes)
public static void MergeBytes(ref PIXEL pixel, byte[] p, int bytes)
{
if (bytes == 4)
{
Expand All @@ -246,7 +246,7 @@ public void MergeBytes(ref PIXEL pixel, byte[] p, int bytes)
}
}

private short ReadShort(FileStream fptr)
private static short ReadShort(FileStream fptr)
{
byte[] buffer = new byte[2];
fptr.Read(buffer, 0, 2);
Expand Down
Loading

0 comments on commit 73dca29

Please sign in to comment.