Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-missing-settlements-to-pool
Browse files Browse the repository at this point in the history
  • Loading branch information
sargeantPig authored Dec 31, 2023
2 parents 7f753b3 + cf979d1 commit afcd34d
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 18 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog

## 1.0.0 (2023-12-30)


### Features

* temporarily ignore general units when randomising ownerships ([#48](https://github.com/sargeantPig/RTWLibTools/issues/48)) ([9631ce7](https://github.com/sargeantPig/RTWLibTools/commit/9631ce795bd055a1a52671003b6f6f420720201d))
19 changes: 11 additions & 8 deletions RTWLibPlus/randomiser/randEDU.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,37 @@ public static string RandomiseOwnership(EDU edu, RandWrap rnd, SMF smf, int maxP
{
rnd.RefreshRndSeed();


List<IBaseObj> attributes = edu.GetItemsByIdent("attributes");
List<IBaseObj> ownerships = edu.GetItemsByIdent("ownership");
List<string> factionList = smf.GetFactions();
factionList.Shuffle(rnd.RND);


foreach (EDUObj ownership in ownerships)
for (int io = 0; io < ownerships.Count; io++)
{

EDUObj ownership = (EDUObj)ownerships[io];
if (factionList.Count < maxPerUnit)
{
factionList = smf.GetFactions();
factionList.Shuffle(rnd.RND);
}

string[] newFactions = new string[maxPerUnit + 1];
if (attributes[io].Value.Contains("general"))
{
continue;
}

string[] newFactions = new string[maxPerUnit];
for (int i = 0; i < maxPerUnit; i++)
{
newFactions[i] = factionList.GetRandom(out int index, rnd.RND);
factionList.RemoveAt(index);
}
newFactions[^1] = "slave";

ownership.Value = newFactions.ToString(',', ' ');
ownership.Value = newFactions.ToString(',', ' ') + ", slave";
}

AddAttributeAll(edu, "mercenary_unit");
SetGeneralUnits(edu, smf, rnd, 700, 950);
//SetGeneralUnits(edu, smf, rnd, 700, 950);
return "Random ownership complete";
}
public static string SetGeneralUnits(EDU edu, SMF smf, RandWrap rnd, int minPriceEarly, int minPriceLate)
Expand Down
4 changes: 4 additions & 0 deletions RTWLib_CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using RTWLibPlus.data;
using RTWLibPlus.helpers;
using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;

Expand All @@ -19,6 +20,9 @@ class Program

static void Main(string[] args)
{
string wdir = AppDomain.CurrentDomain.BaseDirectory;
Directory.SetCurrentDirectory(wdir);

Console.WriteLine(CMDProcess.LoadTemplates());
Console.WriteLine(CMDProcess.LoadConfigs());

Expand Down
13 changes: 13 additions & 0 deletions RTWLib_Tests/wrappers/Tests_SMF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,18 @@ public void SMFCheckDataIsParsedDepth4()
Assert.AreEqual(expected, result);

}
[TestMethod]
public void SMFGetFactions()
{
string[] smf = this.dp.ReadFile(RFH.CurrDirPath("resources", "descr_sm_factions.txt"), false);
List<RTWLibPlus.interfaces.IBaseObj> smfParse = this.dp.Parse(smf, Creator.SMFcreator, ':');
SMF parsedsmf = new(smfParse, this.config);

int result = parsedsmf.GetFactions().Count;
int expected = 21;

Assert.AreEqual(expected, result);

}

}
12 changes: 6 additions & 6 deletions randomiser_config/remaster.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
"roman"
],
"FactionCultures": [
"roman",
"greek",
"carthaginian",
"eastern",
"egyptian",
"roman",
"greek",
"carthaginian",
"eastern",
"egyptian",
"barbarian"
],
"Paths": {
Expand All @@ -62,4 +62,4 @@
"BaseFolder": "Mods\\My Mods\\randomiser",
"Save": "data",
"Load": "vanilla"
}
}
4 changes: 2 additions & 2 deletions randomiser_templates/basic.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
randcmd setseed yeet yes
randcmd setseed testseed
randcmd initialsetup
randcmd citiesbasic
randcmd ownership 0 3 1
randcmd PaintFactionMap
randcmd output
randcmd output
4 changes: 2 additions & 2 deletions randomiser_templates/default.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
randcmd setseed yeet yes
randcmd setseed testseed
randcmd initialsetup
randcmd citiesvoronoi
randcmd ownership 3 1
randcmd PaintFactionMap
randcmd output
randcmd output

0 comments on commit afcd34d

Please sign in to comment.