Map.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // The Command & Conquer Map Editor and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // The Command & Conquer Map Editor and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. using MobiusEditor.Interface;
  15. using MobiusEditor.Render;
  16. using MobiusEditor.Utility;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Collections.ObjectModel;
  20. using System.ComponentModel;
  21. using System.Drawing;
  22. using System.Drawing.Drawing2D;
  23. using System.Linq;
  24. using TGASharpLib;
  25. namespace MobiusEditor.Model
  26. {
  27. [Flags]
  28. public enum MapLayerFlag
  29. {
  30. None = 0,
  31. Basic = 1 << 0,
  32. Map = 1 << 1,
  33. Template = 1 << 2,
  34. Terrain = 1 << 3,
  35. Resources = 1 << 4,
  36. Walls = 1 << 5,
  37. Overlay = 1 << 6,
  38. Smudge = 1 << 7,
  39. Waypoints = 1 << 8,
  40. CellTriggers = 1 << 9,
  41. Houses = 1 << 10,
  42. Infantry = 1 << 11,
  43. Units = 1 << 12,
  44. Buildings = 1 << 13,
  45. Boundaries = 1 << 14,
  46. TechnoTriggers = 1 << 15,
  47. OverlayAll = Resources | Walls | Overlay,
  48. Technos = Terrain | Walls | Infantry | Units | Buildings,
  49. All = int.MaxValue
  50. }
  51. public class MapContext : ITypeDescriptorContext
  52. {
  53. public IContainer Container { get; private set; }
  54. public object Instance { get; private set; }
  55. public PropertyDescriptor PropertyDescriptor { get; private set; }
  56. public Map Map => Instance as Map;
  57. public readonly bool FractionalPercentages;
  58. public MapContext(Map map, bool fractionalPercentages)
  59. {
  60. Instance = map;
  61. FractionalPercentages = fractionalPercentages;
  62. }
  63. public object GetService(Type serviceType) => null;
  64. public void OnComponentChanged() { }
  65. public bool OnComponentChanging() => true;
  66. }
  67. public class Map : ICloneable
  68. {
  69. private int updateCount = 0;
  70. private bool updating = false;
  71. private IDictionary<MapLayerFlag, ISet<Point>> invalidateLayers = new Dictionary<MapLayerFlag, ISet<Point>>();
  72. private bool invalidateOverlappers;
  73. public readonly BasicSection BasicSection;
  74. public readonly MapSection MapSection = new MapSection();
  75. public readonly BriefingSection BriefingSection = new BriefingSection();
  76. public readonly SteamSection SteamSection = new SteamSection();
  77. public TheaterType Theater { get => MapSection.Theater; set => MapSection.Theater = value; }
  78. public Point TopLeft
  79. {
  80. get => new Point(MapSection.X, MapSection.Y);
  81. set { MapSection.X = value.X; MapSection.Y = value.Y; }
  82. }
  83. public Size Size
  84. {
  85. get => new Size(MapSection.Width, MapSection.Height);
  86. set { MapSection.Width = value.Width; MapSection.Height = value.Height; }
  87. }
  88. public Rectangle Bounds
  89. {
  90. get => new Rectangle(TopLeft, Size);
  91. set { MapSection.X = value.Left; MapSection.Y = value.Top; MapSection.Width = value.Width; MapSection.Height = value.Height; }
  92. }
  93. public readonly Type HouseType;
  94. public readonly HouseType[] HouseTypes;
  95. public readonly List<TheaterType> TheaterTypes;
  96. public readonly List<TemplateType> TemplateTypes;
  97. public readonly List<TerrainType> TerrainTypes;
  98. public readonly List<OverlayType> OverlayTypes;
  99. public readonly List<SmudgeType> SmudgeTypes;
  100. public readonly string[] EventTypes;
  101. public readonly string[] ActionTypes;
  102. public readonly string[] MissionTypes;
  103. public readonly List<DirectionType> DirectionTypes;
  104. public readonly List<InfantryType> InfantryTypes;
  105. public readonly List<UnitType> UnitTypes;
  106. public readonly List<BuildingType> BuildingTypes;
  107. public readonly string[] TeamMissionTypes;
  108. public readonly CellMetrics Metrics;
  109. public readonly CellGrid<Template> Templates;
  110. public readonly CellGrid<Overlay> Overlay;
  111. public readonly CellGrid<Smudge> Smudge;
  112. public readonly OccupierSet<ICellOccupier> Technos;
  113. public readonly OccupierSet<ICellOccupier> Buildings;
  114. public readonly OverlapperSet<ICellOverlapper> Overlappers;
  115. public readonly Waypoint[] Waypoints;
  116. public readonly CellGrid<CellTrigger> CellTriggers;
  117. public readonly ObservableCollection<Trigger> Triggers;
  118. public readonly List<TeamType> TeamTypes;
  119. public House[] Houses;
  120. public readonly List<string> MovieTypes;
  121. public int TiberiumOrGoldValue { get; set; }
  122. public int GemValue { get; set; }
  123. public int TotalResources
  124. {
  125. get
  126. {
  127. int totalResources = 0;
  128. foreach (var (cell, value) in Overlay)
  129. {
  130. if (value.Type.IsResource)
  131. {
  132. totalResources += (value.Icon + 1) * (value.Type.IsGem ? GemValue : TiberiumOrGoldValue);
  133. }
  134. }
  135. return totalResources;
  136. }
  137. }
  138. public Map(BasicSection basicSection, TheaterType theater, Size cellSize, Type houseType,
  139. IEnumerable<HouseType> houseTypes, IEnumerable<TheaterType> theaterTypes, IEnumerable<TemplateType> templateTypes,
  140. IEnumerable<TerrainType> terrainTypes, IEnumerable<OverlayType> overlayTypes, IEnumerable<SmudgeType> smudgeTypes,
  141. IEnumerable<string> eventTypes, IEnumerable<string> actionTypes, IEnumerable<string> missionTypes,
  142. IEnumerable<DirectionType> directionTypes, IEnumerable<InfantryType> infantryTypes, IEnumerable<UnitType> unitTypes,
  143. IEnumerable<BuildingType> buildingTypes, IEnumerable<string> teamMissionTypes, IEnumerable<Waypoint> waypoints,
  144. IEnumerable<string> movieTypes)
  145. {
  146. BasicSection = basicSection;
  147. HouseType = houseType;
  148. HouseTypes = houseTypes.ToArray();
  149. TheaterTypes = new List<TheaterType>(theaterTypes);
  150. TemplateTypes = new List<TemplateType>(templateTypes);
  151. TerrainTypes = new List<TerrainType>(terrainTypes);
  152. OverlayTypes = new List<OverlayType>(overlayTypes);
  153. SmudgeTypes = new List<SmudgeType>(smudgeTypes);
  154. EventTypes = eventTypes.ToArray();
  155. ActionTypes = actionTypes.ToArray();
  156. MissionTypes = missionTypes.ToArray();
  157. DirectionTypes = new List<DirectionType>(directionTypes);
  158. InfantryTypes = new List<InfantryType>(infantryTypes);
  159. UnitTypes = new List<UnitType>(unitTypes);
  160. BuildingTypes = new List<BuildingType>(buildingTypes);
  161. TeamMissionTypes = teamMissionTypes.ToArray();
  162. MovieTypes = new List<string>(movieTypes);
  163. Metrics = new CellMetrics(cellSize);
  164. Templates = new CellGrid<Template>(Metrics);
  165. Overlay = new CellGrid<Overlay>(Metrics);
  166. Smudge = new CellGrid<Smudge>(Metrics);
  167. Technos = new OccupierSet<ICellOccupier>(Metrics);
  168. Buildings = new OccupierSet<ICellOccupier>(Metrics);
  169. Overlappers = new OverlapperSet<ICellOverlapper>(Metrics);
  170. Triggers = new ObservableCollection<Trigger>();
  171. TeamTypes = new List<TeamType>();
  172. Houses = HouseTypes.Select(t => { var h = (House)Activator.CreateInstance(HouseType, t); h.SetDefault(); return h; }).ToArray();
  173. Waypoints = waypoints.ToArray();
  174. CellTriggers = new CellGrid<CellTrigger>(Metrics);
  175. MapSection.SetDefault();
  176. BriefingSection.SetDefault();
  177. SteamSection.SetDefault();
  178. Templates.Clear();
  179. Overlay.Clear();
  180. Smudge.Clear();
  181. Technos.Clear();
  182. Overlappers.Clear();
  183. CellTriggers.Clear();
  184. TopLeft = new Point(1, 1);
  185. Size = Metrics.Size - new Size(2, 2);
  186. Theater = theater;
  187. Overlay.CellChanged += Overlay_CellChanged;
  188. Technos.OccupierAdded += Technos_OccupierAdded;
  189. Technos.OccupierRemoved += Technos_OccupierRemoved;
  190. Buildings.OccupierAdded += Buildings_OccupierAdded;
  191. Buildings.OccupierRemoved += Buildings_OccupierRemoved;
  192. Triggers.CollectionChanged += Triggers_CollectionChanged;
  193. }
  194. public void BeginUpdate()
  195. {
  196. updateCount++;
  197. }
  198. public void EndUpdate()
  199. {
  200. if (--updateCount == 0)
  201. {
  202. Update();
  203. }
  204. }
  205. public void InitTheater(GameType gameType)
  206. {
  207. foreach (var templateType in TemplateTypes)
  208. {
  209. templateType.Init(Theater);
  210. }
  211. foreach (var smudgeType in SmudgeTypes)
  212. {
  213. smudgeType.Init(Theater);
  214. }
  215. foreach (var overlayType in OverlayTypes)
  216. {
  217. overlayType.Init(Theater);
  218. }
  219. foreach (var terrainType in TerrainTypes)
  220. {
  221. terrainType.Init(Theater);
  222. }
  223. foreach (var infantryType in InfantryTypes)
  224. {
  225. infantryType.Init(gameType, Theater, HouseTypes.Where(h => h.Equals(infantryType.OwnerHouse)).FirstOrDefault(), DirectionTypes.Where(d => d.Facing == FacingType.South).First());
  226. }
  227. foreach (var unitType in UnitTypes)
  228. {
  229. unitType.Init(gameType, Theater, HouseTypes.Where(h => h.Equals(unitType.OwnerHouse)).FirstOrDefault(), DirectionTypes.Where(d => d.Facing == FacingType.North).First());
  230. }
  231. foreach (var buildingType in BuildingTypes)
  232. {
  233. buildingType.Init(gameType, Theater, HouseTypes.Where(h => h.Equals(buildingType.OwnerHouse)).FirstOrDefault(), DirectionTypes.Where(d => d.Facing == FacingType.North).First());
  234. }
  235. }
  236. private void Update()
  237. {
  238. updating = true;
  239. if (invalidateLayers.TryGetValue(MapLayerFlag.Resources, out ISet<Point> locations))
  240. {
  241. UpdateResourceOverlays(locations);
  242. }
  243. if (invalidateLayers.TryGetValue(MapLayerFlag.Walls, out locations))
  244. {
  245. UpdateWallOverlays(locations);
  246. }
  247. if (invalidateOverlappers)
  248. {
  249. Overlappers.Clear();
  250. foreach (var (location, techno) in Technos)
  251. {
  252. if (techno is ICellOverlapper)
  253. {
  254. Overlappers.Add(location, techno as ICellOverlapper);
  255. }
  256. }
  257. }
  258. invalidateLayers.Clear();
  259. invalidateOverlappers = false;
  260. updating = false;
  261. }
  262. private void UpdateResourceOverlays(ISet<Point> locations)
  263. {
  264. var tiberiumCounts = new int[] { 0, 1, 3, 4, 6, 7, 8, 10, 11 };
  265. var gemCounts = new int[] { 0, 0, 0, 1, 1, 1, 2, 2, 2 };
  266. foreach (var (cell, overlay) in Overlay.IntersectsWith(locations).Where(o => o.Value.Type.IsResource))
  267. {
  268. int count = 0;
  269. foreach (var facing in CellMetrics.AdjacentFacings)
  270. {
  271. var adjacentTiberium = Overlay.Adjacent(cell, facing);
  272. if (adjacentTiberium?.Type.IsResource ?? false)
  273. {
  274. count++;
  275. }
  276. }
  277. overlay.Icon = overlay.Type.IsGem ? gemCounts[count] : tiberiumCounts[count];
  278. }
  279. }
  280. private void UpdateWallOverlays(ISet<Point> locations)
  281. {
  282. foreach (var (cell, overlay) in Overlay.IntersectsWith(locations).Where(o => o.Value.Type.IsWall))
  283. {
  284. var northWall = Overlay.Adjacent(cell, FacingType.North);
  285. var eastWall = Overlay.Adjacent(cell, FacingType.East);
  286. var southWall = Overlay.Adjacent(cell, FacingType.South);
  287. var westWall = Overlay.Adjacent(cell, FacingType.West);
  288. int icon = 0;
  289. if (northWall?.Type == overlay.Type)
  290. {
  291. icon |= 1;
  292. }
  293. if (eastWall?.Type == overlay.Type)
  294. {
  295. icon |= 2;
  296. }
  297. if (southWall?.Type == overlay.Type)
  298. {
  299. icon |= 4;
  300. }
  301. if (westWall?.Type == overlay.Type)
  302. {
  303. icon |= 8;
  304. }
  305. overlay.Icon = icon;
  306. }
  307. }
  308. private void RemoveBibs(Building building)
  309. {
  310. var bibCells = Smudge.IntersectsWith(building.BibCells).Where(x => (x.Value.Type.Flag & SmudgeTypeFlag.Bib) != SmudgeTypeFlag.None).Select(x => x.Cell).ToArray();
  311. foreach (var cell in bibCells)
  312. {
  313. Smudge[cell] = null;
  314. }
  315. building.BibCells.Clear();
  316. }
  317. private void AddBibs(Point location, Building building)
  318. {
  319. if (!building.Type.HasBib)
  320. {
  321. return;
  322. }
  323. var bib1Type = SmudgeTypes.Where(t => t.Flag == SmudgeTypeFlag.Bib1).FirstOrDefault();
  324. var bib2Type = SmudgeTypes.Where(t => t.Flag == SmudgeTypeFlag.Bib2).FirstOrDefault();
  325. var bib3Type = SmudgeTypes.Where(t => t.Flag == SmudgeTypeFlag.Bib3).FirstOrDefault();
  326. SmudgeType bibType = null;
  327. switch (building.Type.Size.Width)
  328. {
  329. case 2:
  330. bibType = bib3Type;
  331. break;
  332. case 3:
  333. bibType = bib2Type;
  334. break;
  335. case 4:
  336. bibType = bib1Type;
  337. break;
  338. }
  339. if (bibType != null)
  340. {
  341. int icon = 0;
  342. for (var y = 0; y < bibType.Size.Height; ++y)
  343. {
  344. for (var x = 0; x < bibType.Size.Width; ++x, ++icon)
  345. {
  346. if (Metrics.GetCell(new Point(location.X + x, location.Y + building.Type.Size.Height + y - 1), out int subCell))
  347. {
  348. Smudge[subCell] = new Smudge
  349. {
  350. Type = bibType,
  351. Icon = icon,
  352. Data = 0,
  353. Tint = building.Tint
  354. };
  355. building.BibCells.Add(subCell);
  356. }
  357. }
  358. }
  359. }
  360. }
  361. public Map Clone()
  362. {
  363. var map = new Map(BasicSection, Theater, Metrics.Size, HouseType,
  364. HouseTypes, TheaterTypes, TemplateTypes, TerrainTypes, OverlayTypes, SmudgeTypes,
  365. EventTypes, ActionTypes, MissionTypes, DirectionTypes, InfantryTypes, UnitTypes,
  366. BuildingTypes, TeamMissionTypes, Waypoints, MovieTypes)
  367. {
  368. TopLeft = TopLeft,
  369. Size = Size
  370. };
  371. map.BeginUpdate();
  372. MapSection.CopyTo(map.MapSection);
  373. BriefingSection.CopyTo(map.BriefingSection);
  374. SteamSection.CopyTo(map.SteamSection);
  375. Templates.CopyTo(map.Templates);
  376. Overlay.CopyTo(map.Overlay);
  377. Smudge.CopyTo(map.Smudge);
  378. CellTriggers.CopyTo(map.CellTriggers);
  379. Array.Copy(Houses, map.Houses, map.Houses.Length);
  380. foreach (var trigger in Triggers)
  381. {
  382. map.Triggers.Add(trigger);
  383. }
  384. foreach (var (location, occupier) in Technos)
  385. {
  386. if (occupier is InfantryGroup infantryGroup)
  387. {
  388. var newInfantryGroup = new InfantryGroup();
  389. Array.Copy(infantryGroup.Infantry, newInfantryGroup.Infantry, newInfantryGroup.Infantry.Length);
  390. map.Technos.Add(location, newInfantryGroup);
  391. }
  392. else if (!(occupier is Building))
  393. {
  394. map.Technos.Add(location, occupier);
  395. }
  396. }
  397. foreach (var (location, building) in Buildings)
  398. {
  399. map.Buildings.Add(location, building);
  400. }
  401. map.TeamTypes.AddRange(TeamTypes);
  402. map.EndUpdate();
  403. return map;
  404. }
  405. public TGA GeneratePreview(Size previewSize, bool sharpen)
  406. {
  407. var mapBounds = new Rectangle(
  408. Bounds.Left * Globals.OriginalTileWidth,
  409. Bounds.Top * Globals.OriginalTileHeight,
  410. Bounds.Width * Globals.OriginalTileWidth,
  411. Bounds.Height * Globals.OriginalTileHeight
  412. );
  413. var previewScale = Math.Min(previewSize.Width / (float)mapBounds.Width, previewSize.Height / (float)mapBounds.Height);
  414. var scaledSize = new Size((int)(previewSize.Width / previewScale), (int)(previewSize.Height / previewScale));
  415. using (var fullBitmap = new Bitmap(Metrics.Width * Globals.OriginalTileWidth, Metrics.Height * Globals.OriginalTileHeight))
  416. using (var croppedBitmap = new Bitmap(previewSize.Width, previewSize.Height))
  417. {
  418. var locations = Bounds.Points().ToHashSet();
  419. using (var g = Graphics.FromImage(fullBitmap))
  420. {
  421. MapRenderer.Render(GameType.None, this, g, locations, MapLayerFlag.Template | MapLayerFlag.Resources, 1);
  422. }
  423. using (var g = Graphics.FromImage(croppedBitmap))
  424. {
  425. Matrix transform = new Matrix();
  426. transform.Scale(previewScale, previewScale);
  427. transform.Translate((scaledSize.Width - mapBounds.Width) / 2, (scaledSize.Height - mapBounds.Height) / 2);
  428. g.Transform = transform;
  429. g.Clear(Color.Black);
  430. g.DrawImage(fullBitmap, new Rectangle(0, 0, mapBounds.Width, mapBounds.Height), mapBounds, GraphicsUnit.Pixel);
  431. }
  432. fullBitmap.Dispose();
  433. if (sharpen)
  434. {
  435. using (var sharpenedImage = croppedBitmap.Sharpen(1.0f))
  436. {
  437. croppedBitmap.Dispose();
  438. return TGA.FromBitmap(sharpenedImage);
  439. }
  440. }
  441. else
  442. {
  443. return TGA.FromBitmap(croppedBitmap);
  444. }
  445. }
  446. }
  447. public TGA GenerateMapPreview()
  448. {
  449. return GeneratePreview(Globals.MapPreviewSize, false);
  450. }
  451. public TGA GenerateWorkshopPreview()
  452. {
  453. return GeneratePreview(Globals.WorkshopPreviewSize, true);
  454. }
  455. object ICloneable.Clone()
  456. {
  457. return Clone();
  458. }
  459. private void Overlay_CellChanged(object sender, CellChangedEventArgs<Overlay> e)
  460. {
  461. if (e.OldValue?.Type.IsWall ?? false)
  462. {
  463. Buildings.Remove(e.OldValue);
  464. }
  465. if (e.Value?.Type.IsWall ?? false)
  466. {
  467. Buildings.Add(e.Location, e.Value);
  468. }
  469. if (updating)
  470. {
  471. return;
  472. }
  473. foreach (var overlay in new Overlay[] { e.OldValue, e.Value })
  474. {
  475. if (overlay == null)
  476. {
  477. continue;
  478. }
  479. MapLayerFlag layer = MapLayerFlag.None;
  480. if (overlay.Type.IsResource)
  481. {
  482. layer = MapLayerFlag.Resources;
  483. }
  484. else if (overlay.Type.IsWall)
  485. {
  486. layer = MapLayerFlag.Walls;
  487. }
  488. else
  489. {
  490. continue;
  491. }
  492. if (!invalidateLayers.TryGetValue(layer, out ISet<Point> locations))
  493. {
  494. locations = new HashSet<Point>();
  495. invalidateLayers[layer] = locations;
  496. }
  497. locations.UnionWith(Rectangle.Inflate(new Rectangle(e.Location, new Size(1, 1)), 1, 1).Points());
  498. }
  499. if (updateCount == 0)
  500. {
  501. Update();
  502. }
  503. }
  504. private void Technos_OccupierAdded(object sender, OccupierAddedEventArgs<ICellOccupier> e)
  505. {
  506. if (e.Occupier is ICellOverlapper overlapper)
  507. {
  508. if (updateCount == 0)
  509. {
  510. Overlappers.Add(e.Location, overlapper);
  511. }
  512. else
  513. {
  514. invalidateOverlappers = true;
  515. }
  516. }
  517. }
  518. private void Technos_OccupierRemoved(object sender, OccupierRemovedEventArgs<ICellOccupier> e)
  519. {
  520. if (e.Occupier is ICellOverlapper overlapper)
  521. {
  522. if (updateCount == 0)
  523. {
  524. Overlappers.Remove(overlapper);
  525. }
  526. else
  527. {
  528. invalidateOverlappers = true;
  529. }
  530. }
  531. }
  532. private void Buildings_OccupierAdded(object sender, OccupierAddedEventArgs<ICellOccupier> e)
  533. {
  534. if (e.Occupier is Building building)
  535. {
  536. Technos.Add(e.Location, e.Occupier, building.Type.BaseOccupyMask);
  537. AddBibs(e.Location, building);
  538. }
  539. else
  540. {
  541. Technos.Add(e.Location, e.Occupier);
  542. }
  543. }
  544. private void Buildings_OccupierRemoved(object sender, OccupierRemovedEventArgs<ICellOccupier> e)
  545. {
  546. if (e.Occupier is Building building)
  547. {
  548. RemoveBibs(building);
  549. }
  550. Technos.Remove(e.Occupier);
  551. }
  552. private void Triggers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  553. {
  554. foreach (var (_, building) in Buildings.OfType<Building>())
  555. {
  556. if (!string.IsNullOrEmpty(building.Trigger))
  557. {
  558. if (Triggers.Where(t => building.Trigger.Equals(t.Name)).FirstOrDefault() == null)
  559. {
  560. building.Trigger = Trigger.None;
  561. }
  562. }
  563. }
  564. }
  565. }
  566. }