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

/WorldView/Structures/Tile.cs

#
C# | 369 lines | 313 code | 43 blank | 13 comment | 27 complexity | 4f7538067b0e18817efa308cff034f2c MD5 | raw file
  1. using System;
  2. namespace MoreTerra.Structures
  3. {
  4. public class Tile
  5. {
  6. // Total flags
  7. // Active 0x01
  8. // Wall 0x04
  9. // Honey 0x08
  10. // Lava 0x10
  11. // Important 0x20
  12. // Wire 0x40
  13. // Wire2 0x80
  14. // Wire3 0x100
  15. // Halftile 0x200
  16. // Slope 0x400
  17. // Actuator 0x800
  18. // inActive 0x1000
  19. private Int16 flags;
  20. private Byte tileType;
  21. private PointInt16 tileFrame;
  22. private Byte tileColor;
  23. private Byte wallType;
  24. private Byte wallColor;
  25. private Byte liquidLevel;
  26. private Byte slope;
  27. #region Constructors
  28. public Tile()
  29. {
  30. }
  31. public Tile(Tile copy)
  32. {
  33. flags = copy.flags;
  34. tileType = copy.tileType;
  35. tileFrame = copy.tileFrame;
  36. wallType = copy.wallType;
  37. liquidLevel = copy.liquidLevel;
  38. }
  39. public void Reset()
  40. {
  41. flags = 0;
  42. tileType = 0;
  43. tileFrame.X = 0;
  44. tileFrame.Y = 0;
  45. tileColor = 0;
  46. wallType = 0;
  47. wallColor = 0;
  48. liquidLevel = 0;
  49. }
  50. #endregion
  51. #region GetSet Functions
  52. public Byte WallColor
  53. {
  54. get
  55. {
  56. return this.wallColor;
  57. }
  58. set
  59. {
  60. this.wallColor = value;
  61. }
  62. }
  63. public Byte TileColor
  64. {
  65. get
  66. {
  67. return this.tileColor;
  68. }
  69. set
  70. {
  71. this.tileColor = value;
  72. }
  73. }
  74. public Boolean Active
  75. {
  76. get
  77. {
  78. return (flags & 0x01) != 0;
  79. }
  80. set
  81. {
  82. flags = (Int16) ((flags & 0xFFFE) + (value ? 0x01 : 0x00));
  83. }
  84. }
  85. public Byte TileType
  86. {
  87. get
  88. {
  89. return tileType;
  90. }
  91. set
  92. {
  93. tileType = value;
  94. }
  95. }
  96. public PointInt16 Frame
  97. {
  98. get
  99. {
  100. return tileFrame;
  101. }
  102. set
  103. {
  104. tileFrame = value;
  105. }
  106. }
  107. public Boolean Wall
  108. {
  109. get
  110. {
  111. return (flags & 0x04) != 0;
  112. }
  113. set
  114. {
  115. flags = (Int16)((flags & 0xFFFB) + (value ? 0x04 : 0x00));
  116. }
  117. }
  118. public Byte WallType
  119. {
  120. get {
  121. return wallType;
  122. }
  123. set {
  124. wallType = value;
  125. }
  126. }
  127. public Boolean Honey
  128. {
  129. get
  130. {
  131. return (flags & 0x08) != 0;
  132. }
  133. set
  134. {
  135. flags = (Int16)((flags & 0xFFF7) + (value ? 0x08 : 0x00));
  136. }
  137. }
  138. public Byte LiquidLevel
  139. {
  140. get
  141. {
  142. return liquidLevel;
  143. }
  144. set
  145. {
  146. liquidLevel = value;
  147. }
  148. }
  149. public Boolean Lava
  150. {
  151. get
  152. {
  153. return (flags & 0x10) != 0;
  154. }
  155. set
  156. {
  157. flags = (Int16)((flags & 0xFFEF) + (value ? 0x10 : 0x00));
  158. }
  159. }
  160. public Boolean Important
  161. {
  162. get
  163. {
  164. return (flags & 0x20) != 0;
  165. }
  166. set
  167. {
  168. flags = (Int16)((flags & 0xFFDF) + (value ? 0x20 : 0x00));
  169. }
  170. }
  171. public Boolean RedWire
  172. {
  173. get
  174. {
  175. return (flags & 0x40) != 0;
  176. }
  177. set
  178. {
  179. flags = (Int16)((flags & 0xFFBF) + (value ? 0x40 : 0x00));
  180. }
  181. }
  182. public Boolean BlueWire
  183. {
  184. get
  185. {
  186. return (flags & 0x80) != 0;
  187. }
  188. set
  189. {
  190. flags = (Int16)((flags & 0xFF7F) + (value ? 0x80 : 0x00));
  191. }
  192. }
  193. public Boolean GreenWire
  194. {
  195. get
  196. {
  197. return (flags & 0x100) != 0;
  198. }
  199. set
  200. {
  201. flags = (Int16)((flags & 0xFEFF) + (value ? 0x100 : 0x00));
  202. }
  203. }
  204. public Boolean Halftile
  205. {
  206. get
  207. {
  208. return (flags & 0x200) != 0;
  209. }
  210. set
  211. {
  212. flags = (Int16)((flags & 0xFDFF) + (value ? 0x200 : 0x00));
  213. }
  214. }
  215. public Byte Slope
  216. {
  217. get
  218. {
  219. return slope;
  220. }
  221. set
  222. {
  223. this.slope = value;
  224. }
  225. }
  226. public Boolean Actuator
  227. {
  228. get
  229. {
  230. return (flags & 0x800) != 0;
  231. }
  232. set
  233. {
  234. flags = (Int16)((flags & 0xF7FF) + (value ? 0x800 : 0x00));
  235. }
  236. }
  237. public Boolean Inactive
  238. {
  239. get
  240. {
  241. return (flags & 0x1000) != 0;
  242. }
  243. set
  244. {
  245. flags = (Int16)((flags & 0xEFFF) + (value ? 0x1000 : 0x00));
  246. }
  247. }
  248. public Int32 Size
  249. {
  250. get
  251. {
  252. Int32 size;
  253. size = 4;
  254. if (Active == true)
  255. {
  256. size++;
  257. if (Important)
  258. size += 4;
  259. }
  260. if (Wall)
  261. size++;
  262. if (LiquidLevel > 0)
  263. size += 3;
  264. return size;
  265. }
  266. }
  267. #endregion
  268. #region Overrides
  269. public override String ToString()
  270. {
  271. String ret = "";
  272. String val;
  273. if (Active == true)
  274. {
  275. if (Important == true)
  276. {
  277. val = String.Format("01 {0:X2} {1:X2} {2:X2} {3:X2} {4:X2} ", tileType,
  278. (tileFrame.X & 0xFF), ((tileFrame.X & 0xFF00) / 256),
  279. (tileFrame.Y & 0xFF), ((tileFrame.Y & 0xFF00) / 256));
  280. }
  281. else
  282. {
  283. val = String.Format("01 {0:X2} ", tileType);
  284. }
  285. }
  286. else
  287. {
  288. val = "00 ";
  289. }
  290. ret += val;
  291. if (Wall == true)
  292. {
  293. val = String.Format("01 {0:X2} ", wallType);
  294. }
  295. else
  296. {
  297. val = "00 ";
  298. }
  299. ret += val;
  300. if (LiquidLevel > 0)
  301. {
  302. val = String.Format("01 {0:X2} {1:X2} {2:X2}", liquidLevel, Lava ? 1 : 0, Honey ? 1 : 0);
  303. }
  304. else
  305. {
  306. val = "00";
  307. }
  308. ret += val;
  309. return ret;
  310. }
  311. public override bool Equals(object obj)
  312. {
  313. Tile secondTile = (Tile) obj;
  314. if (Size != secondTile.Size)
  315. return false;
  316. if (Size.ToString() != secondTile.ToString())
  317. return false;
  318. return true;
  319. }
  320. public override int GetHashCode()
  321. {
  322. return base.GetHashCode();
  323. }
  324. #endregion
  325. }
  326. }