// This is triggered synchronously after the import work to ensure the RNG remains consistent internal void ApplyRandomization() { foreach (TR2CombinedLevel level in _enemyMapping.Keys) { if (!level.IsAssault) { EnemyTransportCollection importedCollection = null; foreach (EnemyTransportCollection enemies in _enemyMapping[level]) { if (enemies.ImportResult) { importedCollection = enemies; break; } } if (importedCollection == null) { // Cross-level was not possible with the enemy combinations. This could be due to either // a lack of space for texture packing, or the max ObjectTexture count (2048) was reached. _outer.TextureMonitor.RemoveMonitor(level.Name); // And just randomize normally // TODO: maybe trigger a warning to display at the end of randomizing to say that cross- // level was not possible? _outer.RandomizeEnemiesNatively(level); //System.Diagnostics.Debug.WriteLine(level.Name + ": Native enemies"); } else { // The import worked, so randomize the entities based on what we now have in place. //System.Diagnostics.Debug.WriteLine(level.Name + ": " + string.Join(", ", importedCollection.EntitiesToImport)); EnemyRandomizationCollection enemies = new EnemyRandomizationCollection { Available = importedCollection.EntitiesToImport, Droppable = TR2EntityUtilities.FilterDroppableEnemies(importedCollection.EntitiesToImport, !_outer.ProtectMonks), Water = TR2EntityUtilities.FilterWaterEnemies(importedCollection.EntitiesToImport) }; if (_outer.DocileBirdMonsters && importedCollection.BirdMonsterGuiser != TR2Entities.BirdMonster) { _outer.DisguiseEntity(level, importedCollection.BirdMonsterGuiser, TR2Entities.BirdMonster); enemies.BirdMonsterGuiser = importedCollection.BirdMonsterGuiser; } _outer.RandomizeEnemies(level, enemies); } _outer.SaveLevel(level); } if (!_outer.TriggerProgress()) { break; } } }