diff --git a/RTWLibPlus/data/unit/Unit.cs b/RTWLibPlus/data/unit/Unit.cs index 623df55..a2dd9f2 100644 --- a/RTWLibPlus/data/unit/Unit.cs +++ b/RTWLibPlus/data/unit/Unit.cs @@ -339,7 +339,7 @@ private float CalcWeaponStats(Dictionary weights, ref float final - float[] values = new float[] { attk, charg, secAttk, secCharge }; + float[] values = [attk, charg, secAttk, secCharge]; AdjustFinalMod(ref finalmod, values, 0.05f); @@ -431,7 +431,7 @@ private float CalcWeaponAttributes(Dictionary 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]; AdjustFinalMod(ref finalmod, values, 0.3f); @@ -471,7 +471,7 @@ private float CalcAttributes(Dictionary weights, ref float finalm command = 0f; } - float[] values = new float[] { frightenFoot, frightenMounted, command }; + float[] values = [frightenFoot, frightenMounted, command]; AdjustFinalMod(ref finalmod, values, 0.2f); @@ -532,7 +532,7 @@ private float CalcArmour(Dictionary 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]; AdjustFinalMod(ref finalmod, values, 0.05f); diff --git a/RTWLibPlus/dataWrappers/edu.cs b/RTWLibPlus/dataWrappers/edu.cs index ed0fd94..1414345 100644 --- a/RTWLibPlus/dataWrappers/edu.cs +++ b/RTWLibPlus/dataWrappers/edu.cs @@ -104,7 +104,7 @@ public void RemoveAttributesAll(params string[] attriToRemove) foreach (EDUObj a in attri) { string[] values = a.Value.Split(',').TrimAll(); - string[] newVals = Array.Empty(); + string[] newVals = []; foreach (string val in values) { if (!attriToRemove.Contains(val)) diff --git a/RTWLibPlus/helpers/exArray.cs b/RTWLibPlus/helpers/exArray.cs index 698c2c8..cfdf4d0 100644 --- a/RTWLibPlus/helpers/exArray.cs +++ b/RTWLibPlus/helpers/exArray.cs @@ -21,7 +21,7 @@ public static void Init(this List list, int amount) { for (int i = 0; i < amount; i++) { - list.Add(Array.Empty()); + list.Add([]); } } @@ -50,7 +50,7 @@ public static T[] GetItemsFrom(this T[] values, int startIndex) if (newLength < 0) { - return Array.Empty(); + return []; } T[] array = new T[newLength]; @@ -65,7 +65,7 @@ public static T[] GetItemsFrom(this T[] values, int startIndex) public static T[] GetItemsFromFirstOf(this T[] values, int occurHash) { - T[] array = Array.Empty(); + T[] array = []; bool copy = false; for (int i = 0; i < values.Length; i++) { diff --git a/RTWLibPlus/parsers/objects/dsObj.cs b/RTWLibPlus/parsers/objects/dsObj.cs index 5f82a44..e9babfe 100644 --- a/RTWLibPlus/parsers/objects/dsObj.cs +++ b/RTWLibPlus/parsers/objects/dsObj.cs @@ -7,7 +7,7 @@ public class DSObj : ArrayObj, IBaseObj { - private static readonly string[] ApplyDepthToNonArrayAt = new string[3] { "playable", "unlockable", "nonplayable" }; + private static readonly string[] ApplyDepthToNonArrayAt = ["playable", "unlockable", "nonplayable"]; private static readonly string TerminateNonArrayDepthAt = "end"; private static bool applyNonArrayDepth; diff --git a/RTWLibPlus/parsers/objects/edbObj.cs b/RTWLibPlus/parsers/objects/edbObj.cs index 7c3cce1..a287bab 100644 --- a/RTWLibPlus/parsers/objects/edbObj.cs +++ b/RTWLibPlus/parsers/objects/edbObj.cs @@ -8,10 +8,10 @@ public class EDBObj : ArrayObj, IBaseObj { - private static readonly string[] AlwaysArrays = new string[] { "plugins", "upgrades" }; - private static readonly string[] DoubleSpace = new string[] { "construction", "cost" }; - private static readonly string[] DoubleSpaceEnding = new string[] { "levels" }; - private static readonly string[] WhiteSpaceSwap = new string[] { "requires", "temple" }; + private static readonly string[] AlwaysArrays = ["plugins", "upgrades"]; + private static readonly string[] DoubleSpace = ["construction", "cost"]; + private static readonly string[] DoubleSpaceEnding = ["levels"]; + private static readonly string[] WhiteSpaceSwap = ["requires", "temple"]; public EDBObj(string tag, string value, int depth) : base(tag, value, depth) diff --git a/RTWLibPlus/randomiser/randDS.cs b/RTWLibPlus/randomiser/randDS.cs index 21fa52e..4640ba1 100644 --- a/RTWLibPlus/randomiser/randDS.cs +++ b/RTWLibPlus/randomiser/randDS.cs @@ -8,6 +8,7 @@ using RTWLibPlus.parsers.objects; using System; using System.Collections.Generic; +using System.Linq; using System.Numerics; public static class RandDS @@ -87,10 +88,12 @@ public static string SwitchUnitsToRecruitable(EDU edu, DS ds, RandWrap rnd) string name = faction.Tag.RemoveFirstWord('\t').Trim(','); List units = edu.GetUnitsFromFaction(name, ["civ", "female", "naval"]); List dsunits = ds.GetItemsByCriteria("character_record", "unit", faction.Tag, "character", "army"); - + string[] generalFilter = ["general", "generals", "general's", "chieftain", "bodyguard"]; for (int i = 0; i < dsunits.Count; i++) { - if (i == 0 || dsunits[i].Tag.Contains("naval")) + bool skip = generalFilter.Any(sub => dsunits[i].Tag.Contains(sub) || dsunits[i].Value.Contains(sub)); + + if (i == 0 || dsunits[i].Tag.Contains("naval") || skip) { continue; } diff --git a/RTWLibPlus/randomiser/randWrap.cs b/RTWLibPlus/randomiser/randWrap.cs index 9361f7e..142e76b 100644 --- a/RTWLibPlus/randomiser/randWrap.cs +++ b/RTWLibPlus/randomiser/randWrap.cs @@ -15,7 +15,7 @@ public void SetRndSeed(string seed = "") if (this.seed == "-") { - byte[] randomNumber = new byte[4]; // 4 bytes for a 32-bit integer + byte[] randomNumber = new byte[4]; using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) { rng.GetBytes(randomNumber); diff --git a/RTWLib_CLI/cmd/cmdProcess.cs b/RTWLib_CLI/cmd/cmdProcess.cs index 678e54a..f5bdff8 100644 --- a/RTWLib_CLI/cmd/cmdProcess.cs +++ b/RTWLib_CLI/cmd/cmdProcess.cs @@ -93,7 +93,7 @@ public static string CMDScreener(string cmd, Type type = null) { return TemplatesManager.Action(cmd); } if (cmd == KW.help) { - var obj = (Help)modules.GetModule(nameof(Help)); + Help obj = (Help)modules.GetModule(nameof(Help)); return obj.help(); } diff --git a/RTWLib_CLI/cmd/modules/randomiser.cs b/RTWLib_CLI/cmd/modules/randomiser.cs index 91cfb7f..ccc5ae4 100644 --- a/RTWLib_CLI/cmd/modules/randomiser.cs +++ b/RTWLib_CLI/cmd/modules/randomiser.cs @@ -81,7 +81,7 @@ public string SetSeed(string seed) { this.rnd.RefreshRndSeed(); } - return "Seed set to: " + rnd.GetSeed; + return "Seed set to: " + this.rnd.GetSeed; } diff --git a/RTWLib_Tests/randomised/Tests_RandDS.cs b/RTWLib_Tests/randomised/Tests_RandDS.cs index bdc6535..6b1059c 100644 --- a/RTWLib_Tests/randomised/Tests_RandDS.cs +++ b/RTWLib_Tests/randomised/Tests_RandDS.cs @@ -24,11 +24,11 @@ public void UnitsAreRecruitable() edu.PrepareEDU(); List smfParse = RFH.ParseFile(Creator.SMFcreator, ':', false, "resources", "descr_sm_factions.txt"); SMF smf = new(smfParse, this.config); - List beforeUnits = edu.GetUnitsFromFaction("romans_julii"); + List beforeUnits = edu.GetUnitsFromFaction("romans_julii", []); RandEDU.RandomiseOwnership(edu, this.rand, smf); - RandDS.SwitchUnitsToRecruitable(edu, ds); + RandDS.SwitchUnitsToRecruitable(edu, ds, rand); List units = ds.GetItemsByCriteria("character", "unit", "faction\tromans_julii,", "character", "army"); - List eduUnits = edu.GetUnitsFromFaction("romans_julii"); + List eduUnits = edu.GetUnitsFromFaction("romans_julii", []); //RFH.Write("eddu-test.txt", edu.Output()); foreach (IBaseObj unit in units) { diff --git a/RTWLib_Tests/wrappers/Tests_edu.cs b/RTWLib_Tests/wrappers/Tests_edu.cs index 72ad46c..1721863 100644 --- a/RTWLib_Tests/wrappers/Tests_edu.cs +++ b/RTWLib_Tests/wrappers/Tests_edu.cs @@ -111,7 +111,7 @@ public void EduGetUnitsFromFaction() { List parse = RFH.ParseFile(Creator.EDUcreator, ' ', false, "resources", "export_descr_unit.txt"); EDU parsedds = new(parse, this.config); - List units = parsedds.GetUnitsFromFaction("romans_julii"); + List units = parsedds.GetUnitsFromFaction("romans_julii", []); Assert.AreEqual(27, units.Count); }