Skip to content
This repository was archived by the owner on Aug 23, 2025. It is now read-only.

Commit baaa1ec

Browse files
authored
Merge pull request #2 from Cydonia07/master
Merge pull request #2 as well as some additional changes that I accidentally applied to PR for release 0.2.0
2 parents 8dec17f + ea6178a commit baaa1ec

4 files changed

Lines changed: 166 additions & 68 deletions

File tree

RandomCampaignStart/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
32
using System.Runtime.InteropServices;
43

54
// General Information about an assembly is controlled through the following
@@ -32,5 +31,4 @@
3231
// You can specify all the values or you can default the Build and Revision Numbers
3332
// by using the '*' as shown below:
3433
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
34+
[assembly: AssemblyVersion("0.2.0.*")]

RandomCampaignStart/RNGStart.cs

Lines changed: 75 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,100 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics.CodeAnalysis;
43
using System.Reflection;
54
using BattleTech;
65
using Harmony;
7-
using HBS.Logging;
86
using Newtonsoft.Json;
97

8+
// ReSharper disable CollectionNeverUpdated.Global
9+
// ReSharper disable FieldCanBeMadeReadOnly.Global
10+
// ReSharper disable ConvertToConstant.Global
11+
// ReSharper disable InconsistentNaming
12+
// ReSharper disable UnusedMember.Global
13+
1014
namespace RandomCampaignStart
1115
{
12-
[SuppressMessage("ReSharper", "InconsistentNaming")]
1316
[HarmonyPatch(typeof(SimGameState), "FirstTimeInitializeDataFromDefs")]
1417
public static class SimGameState_FirstTimeInitializeDataFromDefs_Patch
1518
{
1619
// from https://stackoverflow.com/questions/273313/randomize-a-listt
1720
private static readonly Random rng = new Random();
21+
1822
private static void RNGShuffle<T>(this IList<T> list)
1923
{
20-
int n = list.Count;
24+
var n = list.Count;
2125
while (n > 1)
2226
{
2327
n--;
24-
int k = rng.Next(n + 1);
25-
T value = list[k];
28+
var k = rng.Next(n + 1);
29+
var value = list[k];
2630
list[k] = list[n];
2731
list[n] = value;
2832
}
2933
}
3034

35+
private static List<T> GetRandomSubList<T>(List<T> list, int number)
36+
{
37+
var subList = new List<T>();
38+
39+
if (list.Count <= 0 || number <= 0)
40+
return subList;
41+
42+
var randomizeMe = new List<T>(list);
43+
44+
// add enough duplicates of the list to satisfy the number specified
45+
while (randomizeMe.Count < number)
46+
randomizeMe.AddRange(list);
47+
48+
randomizeMe.RNGShuffle();
49+
for (var i = 0; i < number; i++)
50+
subList.Add(randomizeMe[i]);
51+
52+
return subList;
53+
}
54+
3155
public static void Postfix(SimGameState __instance)
3256
{
33-
// clear roster
3457
if (RngStart.Settings.NumberRandomRonin + RngStart.Settings.NumberProceduralPilots > 0)
3558
{
59+
// clear roster
3660
while (__instance.PilotRoster.Count > 0)
37-
{
3861
__instance.PilotRoster.RemoveAt(0);
39-
}
4062

4163
// pilotgenerator seems to give me the same exact results for ronin
4264
// every time, and can push out duplicates, which is odd?
4365
// just do our own thing
4466
var pilots = new List<PilotDef>();
45-
46-
if (RngStart.Settings.NumberRandomRonin > 0)
67+
68+
// add our guarenteed starting ronin
69+
foreach (var roninID in RngStart.Settings.StartingRonin)
4770
{
48-
var roninPilots = new List<PilotDef>(__instance.RoninPilots);
49-
roninPilots.RNGShuffle();
71+
var pilotDef = __instance.DataManager.PilotDefs.Get(roninID);
5072

51-
for (int i = 0; i < RngStart.Settings.NumberRandomRonin; i++)
52-
{
53-
pilots.Add(roninPilots[i]);
54-
}
73+
// add directly to roster, don't want to get duplicate ronin from random ronin
74+
if (pilotDef != null)
75+
__instance.AddPilotToRoster(pilotDef, true);
5576
}
5677

78+
pilots.AddRange(GetRandomSubList(__instance.RoninPilots, RngStart.Settings.NumberRandomRonin));
79+
5780
// pilot generator works fine for non-ronin =/
5881
if (RngStart.Settings.NumberProceduralPilots > 0)
59-
{
60-
var randomPilots = __instance.PilotGenerator.GeneratePilots(RngStart.Settings.NumberProceduralPilots, 1, 0, out var notUsed);
61-
pilots.AddRange(randomPilots);
62-
}
82+
pilots.AddRange(__instance.PilotGenerator.GeneratePilots(RngStart.Settings.NumberProceduralPilots, 1, 0, out _));
6383

84+
// actually add the pilots to the SimGameState
6485
foreach (var pilotDef in pilots)
65-
{
6686
__instance.AddPilotToRoster(pilotDef, true);
67-
}
6887
}
69-
88+
7089
// mechs
71-
if (RngStart.Settings.NumberLightMechs + RngStart.Settings.NumberMediumMechs > 0)
90+
if (RngStart.Settings.NumberLightMechs + RngStart.Settings.NumberMediumMechs + RngStart.Settings.NumberHeavyMechs + RngStart.Settings.NumberAssaultMechs > 0)
7291
{
73-
int baySlot = 1;
92+
var baySlot = 1;
7493
var mechIds = new List<string>();
75-
76-
// remove the mechs added by the startinglance
77-
for (int i = 1; i < __instance.Constants.Story.StartingLance.Length + 1; i++)
78-
{
94+
95+
// clear the initial lance
96+
for (var i = 1; i < __instance.Constants.Story.StartingLance.Length + 1; i++)
7997
__instance.ActiveMechs.Remove(i);
80-
}
8198

8299
// remove ancestral mech if specified
83100
if (RngStart.Settings.RemoveAncestralMech)
@@ -86,58 +103,51 @@ public static void Postfix(SimGameState __instance)
86103
baySlot = 0;
87104
}
88105

89-
// add the random medium mechs
90-
var mediumMechIds = new List<string>(RngStart.Settings.MediumMechsPossible);
91-
while (mediumMechIds.Count < RngStart.Settings.NumberMediumMechs)
92-
{
93-
mediumMechIds.AddRange(RngStart.Settings.MediumMechsPossible);
94-
}
95-
96-
mediumMechIds.RNGShuffle();
97-
for (int i = 0; i < RngStart.Settings.NumberMediumMechs; i++)
98-
{
99-
mechIds.Add(mediumMechIds[i]);
100-
}
101-
102-
// add the random light mechs
103-
var lightMechIds = new List<string>(RngStart.Settings.LightMechsPossible);
104-
while (lightMechIds.Count < RngStart.Settings.NumberLightMechs)
105-
{
106-
lightMechIds.AddRange(RngStart.Settings.LightMechsPossible);
107-
}
108-
109-
lightMechIds.RNGShuffle();
110-
for (int i = 0; i < RngStart.Settings.NumberLightMechs; i++)
111-
{
112-
mechIds.Add(lightMechIds[i]);
113-
}
106+
// add the random mechs to mechIds
107+
mechIds.AddRange(GetRandomSubList(RngStart.Settings.AssaultMechsPossible, RngStart.Settings.NumberAssaultMechs));
108+
mechIds.AddRange(GetRandomSubList(RngStart.Settings.HeavyMechsPossible, RngStart.Settings.NumberHeavyMechs));
109+
mechIds.AddRange(GetRandomSubList(RngStart.Settings.MediumMechsPossible, RngStart.Settings.NumberMediumMechs));
110+
mechIds.AddRange(GetRandomSubList(RngStart.Settings.LightMechsPossible, RngStart.Settings.NumberLightMechs));
114111

115112
// actually add the mechs to the game
116-
foreach (var mechId in mechIds)
113+
for (var i = 0; i < mechIds.Count; i++)
117114
{
118-
var mechDef = new MechDef(__instance.DataManager.MechDefs.Get(mechId), __instance.GenerateSimGameUID());
115+
var mechDef = new MechDef(__instance.DataManager.MechDefs.Get(mechIds[i]), __instance.GenerateSimGameUID());
119116
__instance.AddMech(baySlot, mechDef, true, true, false);
120-
baySlot++;
117+
118+
// check to see if we're on the last mechbay and if we have more mechs to add
119+
// if so, store the mech at index 5 before next iteration.
120+
if (baySlot == 5 && i + 1 < mechIds.Count)
121+
__instance.UnreadyMech(5, mechDef);
122+
else
123+
baySlot++;
121124
}
122125
}
123126
}
124127
}
125128

126129
internal class ModSettings
127130
{
128-
public bool RemoveAncestralMech = false;
129-
public int NumberRandomRonin = 4;
130-
public int NumberProceduralPilots = 0;
131+
public List<string> AssaultMechsPossible = new List<string>();
132+
public List<string> HeavyMechsPossible = new List<string>();
133+
public List<string> LightMechsPossible = new List<string>();
134+
public List<string> MediumMechsPossible = new List<string>();
135+
136+
public int NumberAssaultMechs = 0;
137+
public int NumberHeavyMechs = 0;
131138
public int NumberLightMechs = 3;
132139
public int NumberMediumMechs = 1;
133140

134-
public List<string> LightMechsPossible = new List<string>();
135-
public List<string> MediumMechsPossible = new List<string>();
141+
public List<string> StartingRonin = new List<string>();
142+
143+
public int NumberProceduralPilots = 0;
144+
public int NumberRandomRonin = 4;
145+
146+
public bool RemoveAncestralMech = false;
136147
}
137148

138149
public static class RngStart
139150
{
140-
internal static ILog Logger = HBS.Logging.Logger.GetLogger("RandomCampaignStart");
141151
internal static ModSettings Settings;
142152

143153
public static void Init(string modDir, string modSettings)

RandomCampaignStart/RandomCampaignStart.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
<Compile Include="RNGStart.cs" />
5555
<Compile Include="Properties\AssemblyInfo.cs" />
5656
</ItemGroup>
57+
<ItemGroup>
58+
<None Include="mod.json" />
59+
</ItemGroup>
5760
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5861
<PropertyGroup>
5962
<PostBuildEvent>xcopy "$(TargetDir)$(TargetFileName)" "$(BattleTechGame)\Mods\RandomCampaignStart\" /y</PostBuildEvent>

RandomCampaignStart/mod.json

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"Name": "RandomCampaignStart",
3+
"DLL": "RandomCampaignStart.dll",
4+
5+
"Version": "0.2.0",
6+
"Description": "Randomizes the starting mechwarriors and mechs.",
7+
"Author": "mpstark",
8+
"Website": "www.github.com/mpstark/RandomCampaignStart",
9+
10+
"Settings": {
11+
"RemoveAncestralMech": false,
12+
"NumberRandomRonin": 4,
13+
"NumberProceduralPilots": 0,
14+
15+
"StartingRonin": [
16+
],
17+
18+
"NumberLightMechs": 1,
19+
"NumberMediumMechs": 3,
20+
"NumberHeavyMechs": 0,
21+
"NumberAssaultMechs": 0,
22+
23+
"LightMechsPossible": [
24+
"mechdef_commando_COM-1B",
25+
"mechdef_commando_COM-2D",
26+
"mechdef_firestarter_FS9-H",
27+
"mechdef_jenner_JR7-D",
28+
"mechdef_locust_LCT-1V",
29+
"mechdef_locust_LCT-1M",
30+
"mechdef_locust_LCT-1S",
31+
"mechdef_panther_PNT-9R",
32+
"mechdef_spider_SDR-5V",
33+
"mechdef_urbanmech_UM-R60"
34+
],
35+
"MediumMechsPossible": [
36+
"mechdef_blackjack_BJ-1",
37+
"mechdef_centurion_CN9-A",
38+
"mechdef_centurion_CN9-AL",
39+
"mechdef_cicada_CDA-2A",
40+
"mechdef_cicada_CDA-3C",
41+
"mechdef_enforcer_ENF-4R",
42+
"mechdef_griffin_GRF-1N",
43+
"mechdef_griffin_GRF-1S",
44+
"mechdef_hunchback_HBK-4G",
45+
"mechdef_hunchback_HBK-4P",
46+
"mechdef_kintaro_KTO-18",
47+
"mechdef_shadowhawk_SHD-2D",
48+
"mechdef_shadowhawk_SHD-2H",
49+
"mechdef_trebuchet_TBT-5N",
50+
"mechdef_vindicator_VND-1R",
51+
"mechdef_wolverine_WVR-6K",
52+
"mechdef_wolverine_WVR-6R"
53+
],
54+
"HeavyMechsPossible": [
55+
"mechdef_blackknight_BL-6-KNT",
56+
"mechdef_cataphract_CTF-1X",
57+
"mechdef_catapult_CPLT-C1",
58+
"mechdef_catapult_CPLT-K2",
59+
"mechdef_dragon_DRG-1N",
60+
"mechdef_grasshopper_GHR-5H",
61+
"mechdef_jagermech_JM6-A",
62+
"mechdef_jagermech_JM6-S",
63+
"mechdef_orion_ON1-K",
64+
"mechdef_orion_ON1-V",
65+
"mechdef_quickdraw_QKD-4G",
66+
"mechdef_quickdraw_QKD-5A",
67+
"mechdef_thunderbolt_TDR-5S",
68+
"mechdef_thunderbolt_TDR-5SE",
69+
"mechdef_thunderbolt_TDR-5SS"
70+
],
71+
"AssaultMechsPossible": [
72+
"mechdef_atlas_AS7-D",
73+
"mechdef_awesome_AWS-8Q",
74+
"mechdef_awesome_AWS-8T",
75+
"mechdef_banshee_BNC-3E",
76+
"mechdef_banshee_BNC-3M",
77+
"mechdef_battlemaster_BLR-1G",
78+
"mechdef_highlander_HGN-733",
79+
"mechdef_highlander_HGN-733P",
80+
"mechdef_kingcrab_KGC-0000",
81+
"mechdef_stalker_STK-3F",
82+
"mechdef_victor_VTR-9B",
83+
"mechdef_victor_VTR-9S",
84+
"mechdef_zeus_ZEU-6S"
85+
]
86+
}
87+
}

0 commit comments

Comments
 (0)