public BattlefieldCore(BattlefieldCore other) { map = other.map.Clone(); map.Connect(Presentation); layout = other.layout.Clone(); layout.Connect(Presentation); unitSystem = other.unitSystem.Clone(); unitSystem.Connect(Presentation); }
// Constructors. public BattlefieldCore(MapCore map, LayoutCore layout, UnitSystemCore unitSystem) { this.map = map?.Clone() ?? throw new ArgumentNullException(nameof(map)); this.map.Connect(Presentation); this.layout = layout?.Clone() ?? throw new ArgumentNullException(nameof(layout)); this.layout.Connect(Presentation); this.unitSystem = unitSystem?.Clone() ?? throw new ArgumentNullException(nameof(unitSystem)); this.unitSystem.Connect(Presentation); }
// Core generation. private static async Task <BattlefieldCore> GenerateCoreAsync(IProgress <string> progress, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); // Generate map. progress.Report("Generating map..."); var mapGenerator = new FullOfHolesMapGenerator() { HeightLimit = 10, Size = new Vector2Int(100, 100) }; var map = await mapGenerator.GenerateAsync(0, cancellationToken); cancellationToken.ThrowIfCancellationRequested(); // Generate layout. progress.Report("Generating layout..."); var layout = await LayoutCore.CreateLayoutAsync(map.Presentation, 5, 0.3f, 0.1f, cancellationToken); cancellationToken.ThrowIfCancellationRequested(); // Generate unit system. progress.Report("Generating units..."); var unitSystemGenerator = new UniformUnitSystemGenerator() { Map = map.Presentation, UnitCount = 60, UnitTemplates = GenerateUnitTemplates() }; var unitSystem = await unitSystemGenerator.GenerateAsync(0, cancellationToken); cancellationToken.ThrowIfCancellationRequested(); // Assemble core. progress.Report("Finishing game data generation..."); var core = new BattlefieldCore(map, layout, unitSystem); return(core); }