diff --git a/OpenRA.Mods.Common/Traits/Buildings/Building.cs b/OpenRA.Mods.Common/Traits/Buildings/Building.cs index 7ea1257dad..015d37ceba 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Building.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Building.cs @@ -263,6 +263,7 @@ namespace OpenRA.Mods.Common.Traits readonly CPos topLeft; readonly Actor self; + readonly BuildingInfluence influence; (CPos, SubCell)[] occupiedCells; (CPos, SubCell)[] targetableCells; @@ -276,6 +277,7 @@ namespace OpenRA.Mods.Common.Traits self = init.Self; topLeft = init.GetValue(); Info = info; + influence = self.World.WorldActor.Trait(); occupiedCells = Info.OccupiedTiles(TopLeft) .Select(c => (c, SubCell.FullCell)).ToArray(); @@ -305,11 +307,13 @@ namespace OpenRA.Mods.Common.Traits RemoveSmudges(); self.World.AddToMaps(self, this); + influence.AddInfluence(self, Info.Tiles(self.Location)); } void INotifyRemovedFromWorld.RemovedFromWorld(Actor self) { self.World.RemoveFromMaps(self, this); + influence.RemoveInfluence(self, Info.Tiles(self.Location)); } void INotifySold.Selling(Actor self) diff --git a/OpenRA.Mods.Common/Traits/Buildings/BuildingInfluence.cs b/OpenRA.Mods.Common/Traits/Buildings/BuildingInfluence.cs new file mode 100644 index 0000000000..22ad8fda18 --- /dev/null +++ b/OpenRA.Mods.Common/Traits/Buildings/BuildingInfluence.cs @@ -0,0 +1,54 @@ +#region Copyright & License Information +/* + * Copyright 2007-2020 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Traits +{ + [Desc("A dictionary of buildings placed on the map. Attach this to the world actor.")] + public class BuildingInfluenceInfo : TraitInfo + { + public override object Create(ActorInitializer init) { return new BuildingInfluence(init.World); } + } + + public class BuildingInfluence + { + readonly Map map; + readonly CellLayer influence; + + public BuildingInfluence(World world) + { + map = world.Map; + + influence = new CellLayer(map); + } + + internal void AddInfluence(Actor a, IEnumerable tiles) + { + foreach (var u in tiles) + if (influence.Contains(u) && influence[u] == null) + influence[u] = a; + } + + internal void RemoveInfluence(Actor a, IEnumerable tiles) + { + foreach (var u in tiles) + if (influence.Contains(u) && influence[u] == a) + influence[u] = null; + } + + public Actor GetBuildingAt(CPos cell) + { + return influence.Contains(cell) ? influence[cell] : null; + } + } +} diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/RemoveBuildingInfluence.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20200503/RemoveBuildingInfluence.cs deleted file mode 100644 index 67dce6908d..0000000000 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20200503/RemoveBuildingInfluence.cs +++ /dev/null @@ -1,34 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2020 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. For more - * information, see COPYING. - */ -#endregion - -using System.Collections.Generic; - -namespace OpenRA.Mods.Common.UpdateRules.Rules -{ - public class RemoveBuildingInfluence : UpdateRule - { - public override string Name { get { return "BuildingInfluence trait has been removed."; } } - - public override string Description - { - get - { - return "BuildingInfluence trait has been removed. Its functionality has been integrated into ActorMap."; - } - } - - public override IEnumerable UpdateActorNode(ModData modData, MiniYamlNode actorNode) - { - actorNode.RemoveNodes("BuildingInfluence"); - yield break; - } - } -} diff --git a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs index 5478783f19..f8affbf61f 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs @@ -78,7 +78,6 @@ namespace OpenRA.Mods.Common.UpdateRules new RenameCircleContrast(), new SplitDamagedByTerrain(), new RemoveLaysTerrain(), - new RemoveBuildingInfluence(), }) }; diff --git a/mods/cnc/rules/world.yaml b/mods/cnc/rules/world.yaml index 46763a7a19..ecbf44433b 100644 --- a/mods/cnc/rules/world.yaml +++ b/mods/cnc/rules/world.yaml @@ -159,6 +159,7 @@ World: PlayerCommands: HelpCommand: ScreenShaker: + BuildingInfluence: LegacyBridgeLayer: Bridges: bridge1, bridge2, bridge3, bridge4 ProductionQueueFromSelection: diff --git a/mods/d2k/rules/world.yaml b/mods/d2k/rules/world.yaml index 2029bd6033..2b1af9b6dd 100644 --- a/mods/d2k/rules/world.yaml +++ b/mods/d2k/rules/world.yaml @@ -129,6 +129,7 @@ World: PlayerCommands: HelpCommand: ScreenShaker: + BuildingInfluence: ProductionQueueFromSelection: ProductionPaletteWidget: PRODUCTION_PALETTE ActorSpawnManager: diff --git a/mods/ra/rules/world.yaml b/mods/ra/rules/world.yaml index 9a2d72fddc..d30ce0273d 100644 --- a/mods/ra/rules/world.yaml +++ b/mods/ra/rules/world.yaml @@ -181,6 +181,7 @@ World: PlayerCommands: HelpCommand: ScreenShaker: + BuildingInfluence: ProductionQueueFromSelection: ProductionPaletteWidget: PRODUCTION_PALETTE LegacyBridgeLayer: diff --git a/mods/ts/rules/world.yaml b/mods/ts/rules/world.yaml index 408e0f8568..b562f0791f 100644 --- a/mods/ts/rules/world.yaml +++ b/mods/ts/rules/world.yaml @@ -247,6 +247,7 @@ World: DebugVisualizationCommands: PlayerCommands: HelpCommand: + BuildingInfluence: ProductionQueueFromSelection: ProductionPaletteWidget: PRODUCTION_PALETTE DomainIndex: