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