From 65783c369a9949f2832a7f2fdaafd5264d51353e Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 4 Mar 2010 19:35:21 +1300 Subject: [PATCH] Remove hardcoded limitation on mapsize everywhere except minimap --- OpenRA.FileFormats/Map.cs | 5 ++++ OpenRA.Game/PathSearch.cs | 8 ++--- OpenRA.Game/Shroud.cs | 29 ++++++++++++------- OpenRA.Game/Traits/World/BuildingInfluence.cs | 26 +++++++++-------- OpenRA.Game/Traits/World/ResourceLayer.cs | 4 +-- OpenRA.Game/Traits/World/UnitInfluence.cs | 8 +++-- OpenRA.Game/World.cs | 3 +- 7 files changed, 51 insertions(+), 32 deletions(-) diff --git a/OpenRA.FileFormats/Map.cs b/OpenRA.FileFormats/Map.cs index a02ede172c..b1d631bb97 100644 --- a/OpenRA.FileFormats/Map.cs +++ b/OpenRA.FileFormats/Map.cs @@ -256,6 +256,11 @@ namespace OpenRA.FileFormats } } + public bool IsInMap(int2 xy) + { + return IsInMap(xy.X,xy.Y); + } + public bool IsInMap(int x, int y) { return (x >= XOffset && y >= YOffset && x < XOffset + Width && y < YOffset + Height); diff --git a/OpenRA.Game/PathSearch.cs b/OpenRA.Game/PathSearch.cs index 6297b2d7a6..7f94aed315 100755 --- a/OpenRA.Game/PathSearch.cs +++ b/OpenRA.Game/PathSearch.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#region Copyright & License Information /* * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * This file is part of OpenRA. @@ -160,9 +160,9 @@ namespace OpenRA static CellInfo[ , ] InitCellInfo() { - var cellInfo = new CellInfo[ 128, 128 ]; - for( int x = 0 ; x < 128 ; x++ ) - for( int y = 0 ; y < 128 ; y++ ) + var cellInfo = new CellInfo[ Game.world.Map.MapSize, Game.world.Map.MapSize ]; + for( int x = 0 ; x < Game.world.Map.MapSize ; x++ ) + for( int y = 0 ; y < Game.world.Map.MapSize ; y++ ) cellInfo[ x, y ] = new CellInfo( float.PositiveInfinity, new int2( x, y ), false ); return cellInfo; } diff --git a/OpenRA.Game/Shroud.cs b/OpenRA.Game/Shroud.cs index d074091040..adb778e711 100644 --- a/OpenRA.Game/Shroud.cs +++ b/OpenRA.Game/Shroud.cs @@ -30,22 +30,31 @@ namespace OpenRA { public class Shroud { - bool[,] explored = new bool[128, 128]; + bool[,] explored; Sprite[] shadowBits = SpriteSheetBuilder.LoadAllSprites("shadow"); - Sprite[,] sprites = new Sprite[128, 128]; + Sprite[,] sprites; + int gapOpaqueTicks = (int)(Rules.General.GapRegenInterval * 25 * 60); + int gapTicks; + int[,] gapField; + bool[,] gapActive; + bool dirty = true; bool hasGPS = false; Player owner; Map map; public Rectangle? bounds; - public Shroud(Player owner, Map map) { this.owner = owner; this.map = map; } - - int gapOpaqueTicks = (int)(Rules.General.GapRegenInterval * 25 * 60); - int gapTicks; - int[,] gapField = new int[128, 128]; - bool[,] gapActive = new bool[128, 128]; - + public Shroud(Player owner, Map map) + { + this.owner = owner; + this.map = map; + + explored = new bool[map.MapSize, map.MapSize]; + sprites = new Sprite[map.MapSize, map.MapSize]; + gapField = new int[map.MapSize, map.MapSize]; + gapActive = new bool[map.MapSize, map.MapSize]; + } + public bool HasGPS { get { return hasGPS; } @@ -57,7 +66,7 @@ namespace OpenRA if (gapTicks > 0) { --gapTicks; return; } // Clear active flags - gapActive = new bool[128, 128]; + gapActive = new bool[map.MapSize, map.MapSize]; foreach (var a in world.Queries.WithTrait().Where(a => owner != a.Actor.Owner)) foreach (var t in a.Trait.GetShroudedTiles()) { diff --git a/OpenRA.Game/Traits/World/BuildingInfluence.cs b/OpenRA.Game/Traits/World/BuildingInfluence.cs index 342d35419d..04b7ca89d4 100644 --- a/OpenRA.Game/Traits/World/BuildingInfluence.cs +++ b/OpenRA.Game/Traits/World/BuildingInfluence.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#region Copyright & License Information /* * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * This file is part of OpenRA. @@ -19,6 +19,7 @@ #endregion using OpenRA.GameRules; +using OpenRA.FileFormats; namespace OpenRA.Traits { @@ -29,11 +30,17 @@ namespace OpenRA.Traits public class BuildingInfluence { - bool[,] blocked = new bool[128, 128]; - Actor[,] influence = new Actor[128, 128]; + bool[,] blocked; + Actor[,] influence; + Map map; public BuildingInfluence( Actor self ) { + map = self.World.Map; + + blocked = new bool[map.MapSize, map.MapSize]; + influence = new Actor[map.MapSize, map.MapSize]; + self.World.ActorAdded += a => { if (a.traits.Contains()) ChangeInfluence(a, a.traits.Get(), true); }; @@ -45,27 +52,22 @@ namespace OpenRA.Traits void ChangeInfluence( Actor a, Building building, bool isAdd ) { foreach( var u in Footprint.UnpathableTiles( a.Info.Name, a.Info.Traits.Get(), a.Location ) ) - if( IsValid( u ) ) + if( map.IsInMap( u ) ) blocked[ u.X, u.Y ] = isAdd; foreach( var u in Footprint.Tiles( a.Info.Name, a.Info.Traits.Get(), a.Location ) ) - if( IsValid( u ) ) + if( map.IsInMap( u ) ) influence[ u.X, u.Y ] = isAdd ? a : null; } - bool IsValid(int2 t) - { - return !(t.X < 0 || t.Y < 0 || t.X >= 128 || t.Y >= 128); - } - public Actor GetBuildingAt(int2 cell) { - if (!IsValid(cell)) return null; + if (!map.IsInMap(cell)) return null; return influence[cell.X, cell.Y]; } public bool CanMoveHere(int2 cell) { - return IsValid(cell) && !blocked[cell.X, cell.Y]; + return map.IsInMap(cell) && !blocked[cell.X, cell.Y]; } }} diff --git a/OpenRA.Game/Traits/World/ResourceLayer.cs b/OpenRA.Game/Traits/World/ResourceLayer.cs index 4ec36e9a9b..fed87dbf99 100644 --- a/OpenRA.Game/Traits/World/ResourceLayer.cs +++ b/OpenRA.Game/Traits/World/ResourceLayer.cs @@ -152,7 +152,7 @@ namespace OpenRA.Traits var mini = map.XOffset; var maxi = map.XOffset + map.Width; var minj = map.YOffset; var maxj = map.YOffset + map.Height; - var newDensity = new byte[128, 128]; + var newDensity = new byte[map.MapSize, map.MapSize]; for (int j = minj; j < maxj; j++) for (int i = mini; i < maxi; i++) if (content[i, j].type == info) @@ -171,7 +171,7 @@ namespace OpenRA.Traits var mini = map.XOffset; var maxi = map.XOffset + map.Width; var minj = map.YOffset; var maxj = map.YOffset + map.Height; - var growMask = new bool[128, 128]; + var growMask = new bool[map.MapSize, map.MapSize]; for (int j = minj; j < maxj; j++) for (int i = mini; i < maxi; i++) if (content[i,j].type == null diff --git a/OpenRA.Game/Traits/World/UnitInfluence.cs b/OpenRA.Game/Traits/World/UnitInfluence.cs index 7d2eff0287..a3be7ef6a6 100644 --- a/OpenRA.Game/Traits/World/UnitInfluence.cs +++ b/OpenRA.Game/Traits/World/UnitInfluence.cs @@ -32,12 +32,14 @@ namespace OpenRA.Traits public class UnitInfluence : ITick { - List[,] influence = new List[128, 128]; + List[,] influence; public UnitInfluence( Actor self ) { - for (int i = 0; i < self.World.Map.MapSize; i++) - for (int j = 0; j < self.World.Map.MapSize; j++) + int size = self.World.Map.MapSize; + influence = new List[size, size]; + for (int i = 0; i < size; i++) + for (int j = 0; j < size; j++) influence[ i, j ] = new List(); self.World.ActorRemoved += a => Remove( a, a.traits.GetOrDefault() ); diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index 7fa2019793..9e23c58330 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -66,7 +66,7 @@ namespace OpenRA public readonly TileSet TileSet; // for tricky things like bridges. - public readonly ICustomTerrain[,] customTerrain = new ICustomTerrain[128, 128]; + public readonly ICustomTerrain[,] customTerrain; public readonly WorldRenderer WorldRenderer; internal readonly Minimap Minimap; @@ -76,6 +76,7 @@ namespace OpenRA Timer.Time( "----World.ctor" ); Map = new Map( Game.LobbyInfo.GlobalSettings.Map ); + customTerrain = new ICustomTerrain[Map.MapSize, Map.MapSize]; Timer.Time( "new Map: {0}" ); TheaterInfo theaterInfo = Rules.Info["world"].Traits.WithInterface().Where(t => t.Theater == Map.Theater).FirstOrDefault();