city-generation/Game/Assets/Scripts/Model/Road/RoadSegment.cs

100 lines
2.5 KiB
C#
Raw Normal View History

2015-05-20 08:26:46 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace TransportGame.Model.Road
{
/// <summary>
/// Represents a road segment
/// </summary>
[XmlRoot("segment")]
public class RoadSegment
{
/// <summary>
/// Gets or sets the id
/// </summary>
[XmlAttribute("id")]
public int Id { get; set; }
/// <summary>
/// Gets or sets the parent network
/// </summary>
[XmlIgnore]
public RoadNetwork ParentNetwork { get; set; }
/// <summary>
/// Gets or sets the id of the first terminal
/// </summary>
[XmlAttribute("term1")]
public int Terminal1Id { get; set; }
/// <summary>
/// Gets or sets the id of the second terminal
/// </summary>
[XmlAttribute("term2")]
public int Terminal2Id { get; set; }
/// <summary>
/// Gets or sets the first terminal
/// </summary>
[XmlIgnore]
public RoadNode Terminal1
{
get
{
2015-05-29 16:03:08 +00:00
return (Terminal1Id == -1) ? null : ParentNetwork.Nodes[Terminal1Id];
2015-05-20 08:26:46 +00:00
}
set
{
2015-05-29 16:03:08 +00:00
Terminal1Id = (value == null) ? -1 : value.Id;
2015-05-20 08:26:46 +00:00
}
}
/// <summary>
/// Gets or sets the second terminal
/// </summary>
[XmlIgnore]
public RoadNode Terminal2
{
get
{
2015-05-29 16:03:08 +00:00
return (Terminal2Id == -1) ? null : ParentNetwork.Nodes[Terminal2Id];
2015-05-20 08:26:46 +00:00
}
set
{
2015-05-29 16:03:08 +00:00
Terminal2Id = (value == null) ? -1 : value.Id;
2015-05-20 08:26:46 +00:00
}
}
/// <summary>
/// Gets or sets the number of lanes going from terminal 1 to terminal 2
/// </summary>
[XmlAttribute("lanesTo2")]
public int LanesTo2 { get; set; }
/// <summary>
/// Gets or sets the number of lanes going form terminal 2 to terminal 1
/// </summary>
[XmlAttribute("lanesTo1")]
public int LanesTo1 { get; set; }
2015-05-29 16:03:08 +00:00
2015-05-20 08:26:46 +00:00
/// <summary>
/// Initializes road segment
/// </summary>
public RoadSegment()
{
LanesTo1 = 1;
LanesTo2 = 1;
2015-05-29 16:03:08 +00:00
Terminal1Id = -1;
Terminal2Id = -1;
}
public override string ToString()
{
return string.Format("(segment id={0}, {1}->{2})", Id, Terminal1, Terminal2);
2015-05-20 08:26:46 +00:00
}
}
}