PageRenderTime 84ms CodeModel.GetById 40ms app.highlight 18ms RepoModel.GetById 23ms app.codeStats 0ms

/WorldView/Structures/TileProperties.cs

#
C# | 264 lines | 234 code | 29 blank | 1 comment | 73 complexity | b7d9ac6ac89d07e365559deefce2ab9b MD5 | raw file
  1using System;
  2using System.Drawing;
  3using System.Collections.Generic;
  4using MoreTerra.Structures.TerraInfo;
  5
  6namespace MoreTerra.Structures
  7{
  8	public class TileData
  9	{
 10		private Boolean isImportant;
 11		private Color color;
 12        private Color officialColor;
 13        private Boolean transparent;
 14		private Boolean drawMarker;
 15		private MarkerType markerType;
 16
 17		#region Constructors
 18		public TileData()
 19		{
 20			this.isImportant = false;
 21			this.color = Color.Magenta;
 22            this.officialColor = Color.Magenta;
 23            this.transparent = false;
 24			this.markerType = MarkerType.Unknown;
 25		}
 26
 27		public TileData(bool isTileImportant, Color color, Color officialColor, MarkerType hasMarker = MarkerType.Unknown)
 28		{
 29			this.isImportant = isTileImportant;
 30			this.color = color;
 31            this.officialColor = officialColor;
 32            this.transparent = false;
 33			this.drawMarker = false;
 34			this.markerType = hasMarker;
 35		}
 36		#endregion
 37
 38		#region GetSet Functions
 39        public Color Color
 40		{
 41			get
 42			{
 43                return this.color;
 44            }
 45        }
 46
 47        public Color OfficialColor
 48        {
 49            get
 50            {
 51                return this.officialColor;
 52			}
 53		}
 54
 55		public bool IsImportant
 56		{
 57			get
 58			{
 59				return this.isImportant;
 60			}
 61			set
 62			{
 63				this.isImportant = value;
 64			}
 65		}
 66
 67		public bool DrawMarker
 68		{
 69			get
 70			{
 71				return this.drawMarker;
 72			}
 73			set
 74			{
 75				drawMarker = value;
 76			}
 77		}
 78
 79		public MarkerType MarkerType
 80		{
 81			get
 82			{
 83				return this.markerType;
 84			}
 85			set {
 86				this.markerType = value;
 87			}
 88		}
 89		#endregion
 90	}
 91
 92	public class TileProperties
 93	{
 94		public static TileData[] tileTypeDefs;
 95
 96		public static Int16 Sign;
 97		public static Int16 Chest;
 98        public static Int16 Amethyst;
 99        public static Int16 Diamond;
100        public static Int16 Emerald;
101        public static Int16 Ruby;
102        public static Int16 Sapphire;
103        public static Int16 Topaz;
104        public static Int16 ExposedGems;
105        public static Int16 SmallDetritus;
106        public static Int16 LargeDetritus;
107        public static Int16 LargeDetritus2;
108        public static Int16 CopperCache;
109        public static Int16 SilverCache;
110        public static Int16 GoldCache;
111        public static Int16 EnchantedSword;
112        public static Int16 Unknown;
113		public static Int16 Processed;
114		public static Int16 Cropped;
115		public static Int16 BackgroundOffset;
116		public static Int16 Water;
117		public static Int16 Lava;
118		public static Int16 Honey;
119		public static Int16 RedWire;
120		public static Int16 BlueWire;
121		public static Int16 GreenWire;
122		public static Int16 WallOffset;
123
124		public const int TYPES = 512;
125
126		public static void Initialize()
127		{
128			MarkerType mt;
129			Int16 startPos;
130
131			tileTypeDefs = new TileData[TileProperties.TYPES];
132
133			startPos = 0;
134			foreach (KeyValuePair<Int32, TileInfo> kvp in Global.Instance.Info.Tiles)
135			{
136				if (kvp.Value.name == "Signs")
137                    TileProperties.Sign = (Int16)kvp.Key;
138				else if (kvp.Value.name == "Containers")
139                    TileProperties.Chest = (Int16)kvp.Key;
140                else if (kvp.Value.name == "Amethyst")
141                    TileProperties.Amethyst = (Int16)kvp.Key;
142                else if (kvp.Value.name == "Diamond")
143                    TileProperties.Diamond = (Int16)kvp.Key;
144                else if (kvp.Value.name == "Emerald")
145                    TileProperties.Emerald = (Int16)kvp.Key;
146                else if (kvp.Value.name == "Ruby")
147                    TileProperties.Ruby = (Int16)kvp.Key;
148                else if (kvp.Value.name == "Sapphire")
149                    TileProperties.Sapphire = (Int16)kvp.Key;
150                else if (kvp.Value.name == "Topaz")
151                    TileProperties.Topaz = (Int16)kvp.Key;
152                else if (kvp.Value.name == "Exposed Gems")
153                    TileProperties.ExposedGems = (Int16)kvp.Key;
154                else if (kvp.Value.name == "Small Detritus")
155                    TileProperties.SmallDetritus = (Int16)kvp.Key;
156                else if (kvp.Value.name == "Large Detritus")
157                    TileProperties.LargeDetritus = (Int16)kvp.Key;
158                else if (kvp.Value.name == "Large Detritus2")
159                    TileProperties.LargeDetritus2 = (Int16)kvp.Key;
160                else if (kvp.Value.name == "Copper Cache")
161                    TileProperties.CopperCache = (Int16)kvp.Key;
162                else if (kvp.Value.name == "Silver Cache")
163                    TileProperties.SilverCache = (Int16)kvp.Key;
164                else if (kvp.Value.name == "Gold Cache")
165                    TileProperties.GoldCache = (Int16)kvp.Key;
166                else if (kvp.Value.name == "Enchanted Sword")
167                    TileProperties.EnchantedSword = (Int16)kvp.Key;
168
169				if (kvp.Value.markerName != "")
170				{
171                    MarkerInfo mi = Global.Instance.Info.GetMarkerByName(kvp.Value.markerName);
172
173                    if (mi == null)
174						mt = MarkerType.Unknown;
175                    else
176                    {
177                        if (Enum.TryParse<MarkerType>(mi.markerImage, out mt) == false)
178                            mt = MarkerType.Unknown;
179                    }
180				}
181				else
182				{
183					mt = MarkerType.Unknown;
184				}
185
186				tileTypeDefs[kvp.Key] = new TileData(kvp.Value.important, kvp.Value.color, kvp.Value.officialColor, mt);
187				startPos++;
188			}
189			TileProperties.Unknown = startPos;
190
191			startPos = (Int16) ((TileProperties.TYPES - 2) - Global.Instance.Info.Walls.Count);
192
193			foreach (KeyValuePair<String, List<SpecialObjectInfo>> kvp in Global.Instance.Info.SpecialObjects)
194			{
195				startPos -= (Int16) kvp.Value.Count;
196			}
197
198			TileProperties.Processed = startPos;
199			tileTypeDefs[startPos++] = new TileData(false, Color.AliceBlue, Color.AliceBlue);
200			TileProperties.Cropped = startPos;
201			tileTypeDefs[startPos++] = new TileData(false, Color.AliceBlue, Color.AliceBlue);
202
203			foreach (KeyValuePair<String, List<SpecialObjectInfo>> kvp in Global.Instance.Info.SpecialObjects)
204			{
205				switch (kvp.Key)
206				{
207					case "Background":
208						TileProperties.BackgroundOffset = startPos;
209
210						foreach (SpecialObjectInfo soi in kvp.Value)
211						{
212							tileTypeDefs[startPos++] = new TileData(false, soi.color, soi.officialColor);
213						}
214						break;
215					case "Liquid":
216						foreach (SpecialObjectInfo soi in kvp.Value)
217						{
218							if (soi.name == "Honey")
219								TileProperties.Honey = startPos;
220							else if (soi.name == "Lava")
221								TileProperties.Lava = startPos;
222							else if (soi.name == "Water")
223								TileProperties.Water = startPos;
224
225							tileTypeDefs[startPos++] = new TileData(false, soi.color, soi.officialColor);
226						}
227						break;
228					case "Wire":
229						foreach (SpecialObjectInfo soi in kvp.Value)
230						{
231							if (soi.name == "Red Wire")
232								TileProperties.RedWire = startPos;
233							else if (soi.name == "Green Wire")
234								TileProperties.GreenWire = startPos;
235							else if (soi.name == "Blue Wire")
236								TileProperties.BlueWire = startPos;
237
238							tileTypeDefs[startPos++] = new TileData(false, soi.color, soi.officialColor);
239						}
240						break;
241					default:
242						break;
243				}
244
245			}
246
247			// This is a startPos -1 because walls start at 1, not at zero.
248			TileProperties.WallOffset = (Int16) (startPos - 1);
249			foreach (KeyValuePair<Int32, WallInfo> kvp in Global.Instance.Info.Walls)
250			{
251				tileTypeDefs[startPos] = new TileData(false, kvp.Value.color, kvp.Value.officialColor);
252				startPos++;
253			}
254
255
256			for (Int32 i = 0; i < TileProperties.TYPES; i++)
257			{
258				if (tileTypeDefs[i] == null)
259					tileTypeDefs[i] = new TileData(false, Color.Magenta, Color.Magenta);
260			}
261
262		}
263	}
264}