Skip to content

Commit b1ab21e

Browse files
committed
- Add new ambush type 'BattleArmor'. Exactly equivalent to mech ambush, but allows a different weighting and mechDefs to be defined
1 parent 02e0f82 commit b1ab21e

9 files changed

Lines changed: 169 additions & 35 deletions

File tree

ConcreteJungle/ConcreteJungle/ConcreteJungle.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
<SpecificVersion>False</SpecificVersion>
6060
<HintPath>E:\steam\SteamApps\common\BATTLETECH\BattleTech_Data\Managed\Unity.TextMeshPro.dll</HintPath>
6161
</Reference>
62-
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" />
62+
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
63+
<HintPath>E:\steam\SteamApps\common\BATTLETECH\BattleTech_Data\Managed\UnityEngine.dll</HintPath>
64+
</Reference>
6365
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
6466
<SpecificVersion>False</SpecificVersion>
6567
<HintPath>E:\steam\SteamApps\common\BATTLETECH\BattleTech_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
@@ -72,7 +74,9 @@
7274
<SpecificVersion>False</SpecificVersion>
7375
<HintPath>E:\steam\SteamApps\common\BATTLETECH\BattleTech_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
7476
</Reference>
75-
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
77+
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
78+
<HintPath>E:\steam\SteamApps\common\BATTLETECH\BattleTech_Data\Managed\UnityEngine.UI.dll</HintPath>
79+
</Reference>
7680
</ItemGroup>
7781
<ItemGroup>
7882
<Compile Include="Extensions\BuildingExtensions.cs" />

ConcreteJungle/ConcreteJungle/Helper/DataLoadHelper.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ public static void LoadAmbushResources(CombatGameState combat)
2626
pilotsToLoad.Add(ambushDef.PilotDefId);
2727
}
2828

29+
HashSet<string> battleArmorToLoad = new HashSet<string>();
30+
foreach (MechAndPilotDef ambushDef in ModState.BattleArmorAmbushDefForContract.SpawnPool)
31+
{
32+
battleArmorToLoad.Add(ambushDef.MechDefId);
33+
pilotsToLoad.Add(ambushDef.PilotDefId);
34+
}
35+
2936
HashSet<string> mechToLoad = new HashSet<string>();
3037
foreach (MechAndPilotDef ambushDef in ModState.MechAmbushDefForContract.SpawnPool)
3138
{
@@ -51,6 +58,11 @@ public static void LoadAmbushResources(CombatGameState combat)
5158
Mod.Log.Info?.Write($" - PilotDefId: {defId}");
5259
asyncSpawnReq.AddBlindLoadRequest(BattleTechResourceType.PilotDef, defId, new bool?(false));
5360
}
61+
foreach (string defId in battleArmorToLoad)
62+
{
63+
Mod.Log.Info?.Write($" - MechDefId: {defId}");
64+
asyncSpawnReq.AddBlindLoadRequest(BattleTechResourceType.MechDef, defId, new bool?(false));
65+
}
5466
foreach (string defId in mechToLoad)
5567
{
5668
Mod.Log.Info?.Write($" - MechDefId: {defId}");

ConcreteJungle/ConcreteJungle/Helper/SpawnAmbushHelper.cs

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,26 @@ public static class SpawnAmbushHelper
1212
{
1313
public static void SpawnAmbush(Vector3 ambushOrigin, AmbushType ambushType)
1414
{
15-
if (ambushType == AmbushType.Mech && !Mod.Config.MechAmbush.Enabled) return;
16-
if (ambushType == AmbushType.Vehicle && !Mod.Config.VehicleAmbush.Enabled) return;
17-
1815
// Determine how many units we're spawning
19-
int minSpawns = ambushType == AmbushType.Mech ? ModState.MechAmbushDefForContract.MinSpawns : ModState.VehicleAmbushDefForContract.MinSpawns;
20-
int maxSpawns = ambushType == AmbushType.Mech ? ModState.MechAmbushDefForContract.MaxSpawns : ModState.VehicleAmbushDefForContract.MaxSpawns;
16+
int minSpawns = 0, maxSpawns = 0;
17+
if (ambushType == AmbushType.BattleArmor)
18+
{
19+
if (!Mod.Config.BattleArmorAmbush.Enabled) return;
20+
minSpawns = ModState.BattleArmorAmbushDefForContract.MinSpawns;
21+
maxSpawns = ModState.BattleArmorAmbushDefForContract.MaxSpawns;
22+
}
23+
else if (ambushType == AmbushType.Mech)
24+
{
25+
if (!Mod.Config.MechAmbush.Enabled) return;
26+
minSpawns = ModState.MechAmbushDefForContract.MinSpawns;
27+
maxSpawns = ModState.MechAmbushDefForContract.MaxSpawns;
28+
}
29+
else if (ambushType == AmbushType.Vehicle)
30+
{
31+
if (!Mod.Config.VehicleAmbush.Enabled) return;
32+
minSpawns = ModState.VehicleAmbushDefForContract.MinSpawns;
33+
maxSpawns = ModState.VehicleAmbushDefForContract.MaxSpawns;
34+
}
2135

2236
int actorsToSpawn = Mod.Random.Next(minSpawns, maxSpawns);
2337
Mod.Log.Debug?.Write($"Spawning {actorsToSpawn} actors as part of this ambush.");
@@ -44,16 +58,16 @@ public static void SpawnAmbush(Vector3 ambushOrigin, AmbushType ambushType)
4458
// Spawn one unit at the origin of the building
4559
buildingsToLevel.Add(building);
4660
Mod.Log.Debug?.Write("Spawning actor at building origin.");
47-
if (ambushType == AmbushType.Mech)
48-
{
49-
AbstractActor spawnedActor = SpawnAmbushMech(ModState.AmbushTeam, ambushLance, ambushOrigin, building.CurrentPosition, building.CurrentRotation);
50-
spawnedActors.Add(spawnedActor);
51-
}
52-
else
53-
{
54-
AbstractActor spawnedActor = SpawnAmbushVehicle(ModState.AmbushTeam, ambushLance, ambushOrigin, building.CurrentPosition, building.CurrentRotation);
55-
spawnedActors.Add(spawnedActor);
56-
}
61+
62+
AbstractActor spawnedActor = null;
63+
if (ambushType == AmbushType.BattleArmor)
64+
spawnedActor = SpawnAmbushMech(ModState.AmbushTeam, ambushLance, ambushOrigin, building.CurrentPosition, building.CurrentRotation, ModState.BattleArmorAmbushDefForContract.SpawnPool);
65+
else if (ambushType == AmbushType.Mech)
66+
spawnedActor = SpawnAmbushMech(ModState.AmbushTeam, ambushLance, ambushOrigin, building.CurrentPosition, building.CurrentRotation, ModState.MechAmbushDefForContract.SpawnPool);
67+
else if (ambushType == AmbushType.Vehicle)
68+
spawnedActor = SpawnAmbushVehicle(ModState.AmbushTeam, ambushLance, ambushOrigin, building.CurrentPosition, building.CurrentRotation);
69+
70+
spawnedActors.Add(spawnedActor);
5771
actorsToSpawn--;
5872

5973
// Iterate through adjacent hexes to see if we can spawn more units in the building
@@ -67,16 +81,15 @@ public static void SpawnAmbush(Vector3 ambushOrigin, AmbushType ambushType)
6781
if (encounterLayerData.mapEncounterLayerDataCells[cellPoint.Z, cellPoint.X].HasSpecifiedBuilding(building.GUID))
6882
{
6983
Mod.Log.Debug?.Write($"Spawning actor at adjacent hex at position: {adjacentHex}");
70-
if (ambushType == AmbushType.Mech)
71-
{
72-
AbstractActor spawnedActor = SpawnAmbushMech(ModState.AmbushTeam, ambushLance, ambushOrigin, adjacentHex, building.CurrentRotation);
73-
spawnedActors.Add(spawnedActor);
74-
}
75-
else
76-
{
77-
AbstractActor spawnedActor = SpawnAmbushVehicle(ModState.AmbushTeam, ambushLance, ambushOrigin, adjacentHex, building.CurrentRotation);
78-
spawnedActors.Add(spawnedActor);
79-
}
84+
AbstractActor additionalSpawn = null;
85+
if (ambushType == AmbushType.BattleArmor)
86+
additionalSpawn = SpawnAmbushMech(ModState.AmbushTeam, ambushLance, ambushOrigin, adjacentHex, building.CurrentRotation, ModState.BattleArmorAmbushDefForContract.SpawnPool);
87+
else if (ambushType == AmbushType.Mech)
88+
additionalSpawn = SpawnAmbushMech(ModState.AmbushTeam, ambushLance, ambushOrigin, adjacentHex, building.CurrentRotation, ModState.MechAmbushDefForContract.SpawnPool);
89+
else if (ambushType == AmbushType.Vehicle)
90+
additionalSpawn = SpawnAmbushVehicle(ModState.AmbushTeam, ambushLance, ambushOrigin, adjacentHex, building.CurrentRotation);
91+
92+
spawnedActors.Add(additionalSpawn);
8093
actorsToSpawn--;
8194
}
8295
else
@@ -104,7 +117,11 @@ public static void SpawnAmbush(Vector3 ambushOrigin, AmbushType ambushType)
104117
}
105118
}
106119

107-
bool applyAttacks = ambushType == AmbushType.Mech ? Mod.Config.MechAmbush.FreeAttackEnabled : Mod.Config.VehicleAmbush.FreeAttackEnabled;
120+
bool applyAttacks = false;
121+
if (ambushType == AmbushType.BattleArmor && Mod.Config.BattleArmorAmbush.FreeAttackEnabled) applyAttacks = true;
122+
if (ambushType == AmbushType.Mech && Mod.Config.MechAmbush.FreeAttackEnabled) applyAttacks = true;
123+
if (ambushType == AmbushType.Vehicle && Mod.Config.VehicleAmbush.FreeAttackEnabled) applyAttacks = true;
124+
108125
Mod.Log.Info?.Write($"Adding SpawnAmbushSequence for {spawnedActors.Count} actors and {buildingsToLevel.Count} buildings to be leveled.");
109126
try
110127
{
@@ -158,12 +175,12 @@ public static AbstractActor SpawnAmbushVehicle(Team team, Lance ambushLance, Vec
158175
return vehicle;
159176
}
160177

161-
public static AbstractActor SpawnAmbushMech(Team team, Lance ambushLance, Vector3 ambushOrigin, Vector3 spawnPos, Quaternion spawnRot)
178+
public static AbstractActor SpawnAmbushMech(Team team, Lance ambushLance, Vector3 ambushOrigin, Vector3 spawnPos, Quaternion spawnRot, List<MechAndPilotDef> spawnPool)
162179
{
163180

164181
// Randomly determine one of the spawnpairs from the current ambushdef
165182
List<MechAndPilotDef> shuffledSpawns = new List<MechAndPilotDef>();
166-
shuffledSpawns.AddRange(ModState.MechAmbushDefForContract.SpawnPool);
183+
shuffledSpawns.AddRange(spawnPool);
167184
shuffledSpawns.Shuffle();
168185

169186
MechAndPilotDef ambushDef = shuffledSpawns[0];

ConcreteJungle/ConcreteJungle/ModConfig.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class ModConfig {
1515
public DevastationOpts Devastation = new DevastationOpts();
1616
public ExplosionAmbushOpts ExplosionAmbush = new ExplosionAmbushOpts();
1717
public InfantryAmbushOpts InfantryAmbush = new InfantryAmbushOpts();
18+
public MechAmbushOpts BattleArmorAmbush = new MechAmbushOpts();
1819
public MechAmbushOpts MechAmbush = new MechAmbushOpts();
1920
public VehicleAmbushOpts VehicleAmbush = new VehicleAmbushOpts();
2021
public QuipsConfig Quips = new QuipsConfig();
@@ -85,6 +86,24 @@ public void LogConfig() {
8586
Mod.Log.Info?.Write($" Turret and PilotDefs: [ {sb} ]");
8687
}
8788

89+
Mod.Log.Info?.Write(" -- Battle Armor Ambush Options");
90+
Mod.Log.Info?.Write($" Enabled: {this.BattleArmorAmbush.Enabled} FreeAttackEnabled: {this.BattleArmorAmbush.FreeAttackEnabled}.");
91+
foreach (MechAmbushDef ambushDef in this.BattleArmorAmbush.Ambushes)
92+
{
93+
Mod.Log.Info?.Write(" -- Battle Armor Ambush Def");
94+
Mod.Log.Info?.Write($" Difficulty Min: {ambushDef.MinDifficulty} => Max: {ambushDef.MaxDifficulty}");
95+
Mod.Log.Info?.Write($" Spawns Min: {ambushDef.MinSpawns} => Max: {ambushDef.MinSpawns}");
96+
StringBuilder sb = new StringBuilder();
97+
foreach (MechAndPilotDef loadDef in ambushDef.SpawnPool)
98+
{
99+
sb.Append(loadDef.MechDefId);
100+
sb.Append("::");
101+
sb.Append(loadDef.PilotDefId);
102+
sb.Append(", ");
103+
}
104+
Mod.Log.Info?.Write($" BA and PilotDefs: [ {sb} ]");
105+
}
106+
88107
Mod.Log.Info?.Write(" -- Mech Ambush Options");
89108
Mod.Log.Info?.Write($" Enabled: {this.MechAmbush.Enabled} FreeAttackEnabled: {this.MechAmbush.FreeAttackEnabled}.");
90109
foreach (MechAmbushDef ambushDef in this.MechAmbush.Ambushes)
@@ -177,6 +196,22 @@ public void Init() {
177196
});
178197
}
179198

199+
if (Mod.Config.BattleArmorAmbush.Ambushes.Count == 0)
200+
{
201+
Mod.Config.BattleArmorAmbush.Ambushes.Add(new MechAmbushDef
202+
{
203+
MinDifficulty = 1,
204+
MaxDifficulty = 10,
205+
MinSpawns = 2,
206+
MaxSpawns = 6,
207+
SpawnPool = new List<MechAndPilotDef>() {
208+
new MechAndPilotDef{ MechDefId = "mechdef_ba_is_standard", PilotDefId = "pilot_d3_gunner" },
209+
new MechAndPilotDef{ MechDefId = "mechdef_ba_infiltratormkii", PilotDefId = "pilot_d3_gunner" },
210+
new MechAndPilotDef{ MechDefId = "mechdef_ba_fashih", PilotDefId = "pilot_d3_gunner" }
211+
}
212+
});
213+
}
214+
180215
if (Mod.Config.MechAmbush.Ambushes.Count == 0)
181216
{
182217
Mod.Config.MechAmbush.Ambushes.Add(new MechAmbushDef
@@ -242,6 +277,9 @@ private void ValidateWeights()
242277
case AmbushType.Infantry:
243278
if (!Mod.Config.InfantryAmbush.Enabled) throw new InvalidOperationException($"Ambush type: {type} in weight table but marked disabled!");
244279
break;
280+
case AmbushType.BattleArmor:
281+
if (!Mod.Config.BattleArmorAmbush.Enabled) throw new InvalidOperationException($"Ambush type: {type} in weight table but marked disabled!");
282+
break;
245283
case AmbushType.Mech:
246284
if (!Mod.Config.MechAmbush.Enabled) throw new InvalidOperationException($"Ambush type: {type} in weight table but marked disabled!");
247285
break;

ConcreteJungle/ConcreteJungle/ModState.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public static class ModState {
3939

4040
public static ExplosionAmbushDef ExplosionAmbushDefForContract = null;
4141
public static InfantryAmbushDef InfantryAmbushDefForContract = null;
42+
public static MechAmbushDef BattleArmorAmbushDefForContract = null;
4243
public static MechAmbushDef MechAmbushDefForContract = null;
4344
public static VehicleAmbushDef VehicleAmbushDefForContract = null;
4445

@@ -69,6 +70,7 @@ public static void Reset() {
6970

7071
ExplosionAmbushDefForContract = null;
7172
InfantryAmbushDefForContract = null;
73+
BattleArmorAmbushDefForContract = null;
7274
MechAmbushDefForContract = null;
7375
VehicleAmbushDefForContract = null;
7476
}

ConcreteJungle/ConcreteJungle/Objects/Enums.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public enum AmbushType
1111
Explosion,
1212
Infantry,
1313
Mech,
14-
Vehicle
14+
Vehicle,
15+
BattleArmor
1516
}
1617
}

ConcreteJungle/ConcreteJungle/Patches/TurnDirectorPatches.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ static void Prefix(TurnDirector __instance)
7777
case AmbushType.Infantry:
7878
InfantryAmbushHelper.SpawnAmbush(ambushOrigin);
7979
break;
80+
case AmbushType.BattleArmor:
81+
SpawnAmbushHelper.SpawnAmbush(ambushOrigin, AmbushType.BattleArmor);
82+
break;
8083
case AmbushType.Mech:
8184
SpawnAmbushHelper.SpawnAmbush(ambushOrigin, AmbushType.Mech);
8285
break;
@@ -212,6 +215,20 @@ static private bool FilterAmbushes()
212215
ModState.InfantryAmbushDefForContract = filteredInfantryAmbushes[0];
213216
}
214217

218+
List<MechAmbushDef> filteredBattleArmorAmbushes = Mod.Config.BattleArmorAmbush.Ambushes
219+
.Where(x => filterByDifficulty(x))
220+
.ToList();
221+
if (filteredBattleArmorAmbushes.Count != 1)
222+
{
223+
Mod.Log.Error?.Write("Mod is misconfigured! Ambush defs cannot have overlapping or missing difficulty ranges! Disabling mod.");
224+
Mod.Log.Error?.Write(" Error in BattleArmorAmbush.Ambushes.SpawnPool!");
225+
success = false;
226+
}
227+
else
228+
{
229+
ModState.BattleArmorAmbushDefForContract = filteredBattleArmorAmbushes[0];
230+
}
231+
215232
List<MechAmbushDef> filteredMechAmbushes = Mod.Config.MechAmbush.Ambushes
216233
.Where(x => filterByDifficulty(x))
217234
.ToList();

ConcreteJungle/ConcreteJungle/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("0.6.5.0")]
35-
[assembly: AssemblyFileVersion("0.6.5.0")]
34+
[assembly: AssemblyVersion("0.6.6.0")]
35+
[assembly: AssemblyFileVersion("0.6.6.0")]

mod.json

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Name": "ConcreteJungle",
33
"Enabled": true,
44
"Hidden": true,
5-
"Version": "0.6.3",
5+
"Version": "0.6.6",
66
"Description": "Provides fun surprises on urban maps.",
77
"Author": "IceRaptor",
88
"Website": "https://github.com/IceRaptor/ConcreteJungle",
@@ -25,7 +25,7 @@
2525
"ChancePerActor" : 0.05,
2626
"SearchRadius" : 250.0,
2727
"AmbushWeights" : [
28-
"Explosion", "Explosion", "Infantry", "Infantry", "Infantry", "Mech", "Vehicle"
28+
"Explosion", "Explosion", "Infantry", "Infantry", "Infantry", "BattleArmor", "Mech", "Vehicle"
2929
],
3030
"EnableOnRound" : 2,
3131
"BlacklistedContracts" : [
@@ -223,6 +223,49 @@
223223
]
224224
},
225225

226+
"BattleArmorAmbush" : {
227+
"Enabled" : true,
228+
"FreeAttackEnabled" : true,
229+
"Ambushes" : [
230+
{
231+
"MinDifficulty" : 1,
232+
"MaxDifficulty" : 4,
233+
"MinSpawns" : 1,
234+
"MaxSpawns" : 2,
235+
"SpawnPool" : [
236+
{ "MechDefId" : "mechdef_ba_is_standard", "PilotDefId" : "pilot_d3_gunner" },
237+
{ "MechDefId" : "mechdef_ba_is_standard", "PilotDefId" : "pilot_d3_gunner" },
238+
{ "MechDefId" : "mechdef_ba_infiltratormkii", "PilotDefId" : "pilot_d3_gunner" },
239+
{ "MechDefId" : "mechdef_ba_fashih", "PilotDefId" : "pilot_d3_gunner" }
240+
]
241+
},
242+
{
243+
"MinDifficulty" : 5,
244+
"MaxDifficulty" : 7,
245+
"MinSpawns" : 1,
246+
"MaxSpawns" : 2,
247+
"SpawnPool" : [
248+
{ "MechDefId" : "mechdef_ba_is_standard", "PilotDefId" : "pilot_d5_gunner" },
249+
{ "MechDefId" : "mechdef_ba_is_standard", "PilotDefId" : "pilot_d5_gunner" },
250+
{ "MechDefId" : "mechdef_ba_infiltratormkii", "PilotDefId" : "pilot_d5_gunner" },
251+
{ "MechDefId" : "mechdef_ba_fashih", "PilotDefId" : "pilot_d5_gunner" }
252+
]
253+
},
254+
{
255+
"MinDifficulty" : 8,
256+
"MaxDifficulty" : 10,
257+
"MinSpawns" : 2,
258+
"MaxSpawns" : 3,
259+
"SpawnPool" : [
260+
{ "MechDefId" : "mechdef_ba_is_standard", "PilotDefId" : "pilot_d7_gladiator" },
261+
{ "MechDefId" : "mechdef_ba_is_standard", "PilotDefId" : "pilot_d7_gladiator" },
262+
{ "MechDefId" : "mechdef_ba_infiltratormkii", "PilotDefId" : "pilot_d7_gladiator" },
263+
{ "MechDefId" : "mechdef_ba_fashih", "PilotDefId" : "pilot_d7_gladiator" }
264+
]
265+
}
266+
]
267+
},
268+
226269
"MechAmbush" : {
227270
"Enabled" : true,
228271
"FreeAttackEnabled" : true,

0 commit comments

Comments
 (0)