Code:
[Serializable]
internal class Region2D
{
/// <summary>
/// Initializes a new instance of the <see cref="T:System.Object" /> class.
/// </summary>
public Region2D(RegionFlags flags, double regionWeight, RegionPoint ne, RegionPoint nw, RegionPoint se, RegionPoint sw, ulong id, string customName)
{
Flags = flags;
RegionWeight = regionWeight;
NE = ne;
NW = nw;
SE = se;
SW = sw;
ID = id;
CustomName = customName;
}
/// <summary>
/// Initializes a new instance of the <see cref="T:System.Object" /> class.
/// </summary>
public Region2D() {}
/// <summary>
/// Flags hold specific information about this node.
/// </summary>
/// <value>The flags.</value>
/// 1/23/2009 4:48 PM
[XmlAttribute("F")]
internal RegionFlags Flags { get; set; }
/// <summary>
/// Gets or sets the region weight.
/// </summary>
/// <value>The node weight.</value>
/// 1/23/2009 4:48 PM
[XmlAttribute("W")]
internal double RegionWeight { get; set; }
/// <summary>
/// Gets a value indicating whether this instance has a road texture.
/// </summary>
/// <value>
/// <c>true</c> if this instance has a road texture; otherwise, <c>false</c>.
/// </value>
/// 1/23/2009 4:48 PM
[XmlIgnore]
internal bool HasRoadTexture { get { return (Flags & RegionFlags.Road) == 0; } }
/// <summary>
/// Gets or sets the North East point of this region.
/// </summary>
/// <value>The NE.</value>
/// 1/23/2009 4:48 PM
[XmlElement("NE")]
internal RegionPoint NE { get; set; }
/// <summary>
/// Gets or sets the North West point of this region.
/// </summary>
/// <value>The NW.</value>
/// 1/23/2009 4:49 PM
[XmlElement("NW")]
internal RegionPoint NW { get; set; }
/// <summary>
/// Gets or sets the South East point of this region.
/// </summary>
/// <value>The SE.</value>
/// 1/23/2009 4:49 PM
[XmlElement("SE")]
internal RegionPoint SE { get; set; }
/// <summary>
/// Gets or sets the South West point of this region.
/// </summary>
/// <value>The SW.</value>
/// 1/23/2009 4:49 PM
[XmlElement("SW")]
internal RegionPoint SW { get; set; }
/// <summary>
/// Gets or sets the ID of this region.
/// </summary>
/// <value>The ID.</value>
/// 1/23/2009 4:49 PM
[XmlAttribute("ID")]
internal ulong ID { get; set; }
/// <summary>
/// Gets or sets the custom name associated with this region. (This is not mandatory, and is usually
/// omitted. Used for specialized weighting)
/// </summary>
/// <value>The name of the custom.</value>
/// 1/23/2009 4:49 PM
[XmlAttribute("N")]
internal string CustomName { get; set; }
#region Nested type: RegionFlags
/// <summary>
/// Simple flags to show what type of node this is. If it has any types of specific flags.
/// </summary>
[Flags]
internal enum RegionFlags : uint
{
/// <summary>
/// Normal node. Fully passable, no obstructions or extra weighting.
/// </summary>
Normal = 0,
/// <summary>
/// This node falls on a road.
/// </summary>
Road = 0x2,
/// <summary>
/// This node is part of a liquid area. (Water/lava)
/// </summary>
Liquid = 0x4,
/// <summary>
/// This node has an object that can be jumped over.
/// </summary>
JumpableObject = 0x8,
/// <summary>
/// This node is partially blocked, but still passable. (Small tree for example)
/// </summary>
PartialBlock = 0xC,
}
#endregion
/*
Omitted some simple utility methods used for Distance, etc.
I'm sure you can do the math and add the stuff here.
*/
}
[Serializable]
internal struct RegionPoint
{
[XmlAttribute("X")]
internal float X;
[XmlAttribute("Y")]
internal float Y;
[XmlAttribute("Z")]
internal float Z;
}
Fairly simple 2d region class. (I use this for most of EK/Kalim)
Also note, nearly all the information is stored as attributes, which greatly cuts down on file size. There's 1 main node for each region, then 4 inner nodes for the 4 points of the region. So... a total of 5 nodes per region. Which is something like 350 characters. Save it as Unicode, and you cut your file size in half.
The 3D version of the class, simply has another 4 RegionPoints.
If you think about how you're saving the data, (in this case, using 1-2 letter names for attributes and elements) you greatly cut down file size, and serialization speed.
You can even implement a binary reader if you want, but I never found the need to do so.