Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: temporarily ignore general units when randomising ownerships #48

Merged
merged 4 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading