diff --git a/1.6/1.6/Assemblies/ArachnaeSwarm.dll b/1.6/1.6/Assemblies/ArachnaeSwarm.dll
index fec6907..9311a00 100644
Binary files a/1.6/1.6/Assemblies/ArachnaeSwarm.dll and b/1.6/1.6/Assemblies/ArachnaeSwarm.dll differ
diff --git a/1.6/1.6/Defs/Thing_building/ARA_InteractiveEggSac.xml b/1.6/1.6/Defs/Thing_building/ARA_InteractiveEggSac.xml
index dba23de..d9ba36b 100644
--- a/1.6/1.6/Defs/Thing_building/ARA_InteractiveEggSac.xml
+++ b/1.6/1.6/Defs/Thing_building/ARA_InteractiveEggSac.xml
@@ -15,6 +15,7 @@
PassThroughOnly
0.3
false
+ Normal
Light
20
diff --git a/Source/ArachnaeSwarm/CompSpawnPawnFromList.cs b/Source/ArachnaeSwarm/CompSpawnPawnFromList.cs
index ccdeb3c..d12c483 100644
--- a/Source/ArachnaeSwarm/CompSpawnPawnFromList.cs
+++ b/Source/ArachnaeSwarm/CompSpawnPawnFromList.cs
@@ -48,25 +48,65 @@ namespace ArachnaeSwarm
if (spawnUntilTick > 0 && Find.TickManager.TicksGame >= spawnUntilTick)
{
SpawnPawn(spawningPawnKind);
- spawnUntilTick = -1;
- spawningPawnKind = null;
}
}
private void SpawnPawn(PawnKindDef pawnKind)
{
- Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(pawnKind, parent.Faction));
- GenSpawn.Spawn(pawn, parent.Position, parent.Map);
-
- if (Props.lordJob != null)
+ try
{
- Lord lord = LordMaker.MakeNewLord(parent.Faction, (LordJob)System.Activator.CreateInstance(Props.lordJob), parent.Map);
- lord.AddPawn(pawn);
+ if (pawnKind == null)
+ {
+ Log.Warning("CompSpawnPawnFromList: Tried to spawn pawn but pawnKind is null.");
+ return;
+ }
+
+ if (!parent.Spawned || parent.Map == null)
+ {
+ Log.Error($"CompSpawnPawnFromList: Cannot spawn pawn. Parent {parent} is not spawned or map is null.");
+ return;
+ }
+
+ Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(pawnKind, parent.Faction));
+ if (pawn == null)
+ {
+ Log.Error($"CompSpawnPawnFromList: Failed to generate pawn of kind {pawnKind.defName} for faction {parent.Faction?.Name ?? "null"}.");
+ return;
+ }
+
+ if (GenSpawn.Spawn(pawn, parent.Position, parent.Map) == null)
+ {
+ Log.Error($"CompSpawnPawnFromList: Failed to spawn pawn {pawn} at {parent.Position}.");
+ if (!pawn.Destroyed)
+ {
+ pawn.Destroy();
+ }
+ return;
+ }
+
+ if (Props.lordJob != null)
+ {
+ try
+ {
+ LordJob lordJobInstance = (LordJob)System.Activator.CreateInstance(Props.lordJob);
+ Lord lord = LordMaker.MakeNewLord(parent.Faction, lordJobInstance, parent.Map);
+ lord.AddPawn(pawn);
+ }
+ catch (System.Exception e)
+ {
+ Log.Error($"CompSpawnPawnFromList: Error creating LordJob {Props.lordJob?.Name ?? "null"} or assigning pawn {pawn}. Exception: {e}");
+ }
+ }
+
+ if (Props.destroyOnSpawn)
+ {
+ parent.Destroy(DestroyMode.Vanish);
+ }
}
-
- if (Props.destroyOnSpawn)
+ finally
{
- parent.Destroy(DestroyMode.Vanish);
+ spawnUntilTick = -1;
+ spawningPawnKind = null;
}
}