PageRenderTime 24ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/WorldView/Structures/TileProperties.cs

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