/* * TransportStructure.cs * Authors: * Copyright (c) 2007-2008 Cornell University This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; namespace ColonySim.Structures { /// /// Represents a structure that is used in the trasportation systems within /// the Colony. /// internal abstract class TransportStructure : Structure { #region Enums /// /// Tells whether the Tube is running vertically or horizontally. /// public enum Runnings { /// /// A straight tube along the X axis. /// X, /// /// A striaght tube along the Y axis. /// Y, /// /// A curved tube that goes from positive x to positive y /// PXPY, /// /// A curved tube that goes from positive x to negative y /// PXNY, /// /// A curved tube that goes from negative x to positive y /// NXPY, /// /// A curved tube that goes from negative x to negative y /// NXNY, /// /// A T-section facing in the Positive X Direction. /// Positive_X, /// /// A T-section facing in the Positive Y Direction. /// Positive_Y, /// /// A T-section facing in the Negative X Direction. /// Negative_X, /// /// A T-section facing in the Negative Y Direction. /// Negative_Y, /// /// A Four-Way tube. /// Four_Way, } #endregion #region Fields /// /// The direction we're running /// Runnings mRunning = Runnings.Positive_X; #endregion #region Properties /// /// Gets/Sets the running direction of the pipe flow /// public virtual Runnings Running { get { return mRunning; } set { // If the running is not different //if (mRunning == value) //{ // return; //} // Set the value mRunning = value; setDisplayForRunning(); #if DEBUG // debugging //System.Console.WriteLine("Position: " + this.GridPosition.X.ToString() + this.GridPosition.Y.ToString()); //System.Console.WriteLine("DEBUG: Running is " + Running); #endif // Get our translation matrix Matrix translation = Matrix.CreateTranslation(m_TransformationMatrix.Translation); // The rotation matrix Matrix rotation = Matrix.Identity; // Now set the rotation //switch (mRunning) //{ // case Runnings.Positive_X: // rotation = Matrix.CreateRotationY(3 * MathHelper.PiOver2); // break; // case Runnings.Negative_X: // rotation = Matrix.CreateRotationY(MathHelper.PiOver2); // break; // case Runnings.Positive_Y: // rotation = Matrix.CreateRotationY(MathHelper.Pi); // break; //} rotation = getRotationForRunning(mRunning); // Set the transformation m_TransformationMatrix = rotation * translation; } } #endregion #region Constructs /// /// Base constructor /// /// The Content Manager /// The model name /// The texture name protected TransportStructure(ContentManager pContent, string pModelName, string pTextureName) : base(pContent, pModelName, pTextureName) { // Nothing else to do } #endregion #region Methods /// /// Sets the display for the pipe running /// internal abstract void setDisplayForRunning(); /// /// Gets the rotation for the pipe runnings /// /// The pipe runnings /// The rotation matrix to apply internal Matrix getRotationForRunning(Runnings r) { if (this is RoadTubeCrossing) { Dictionary neighbors = GridReference.GetNeighborsForRoad(GridPosition, typeof(TransportStructure)); if (neighbors.ContainsKey(Carrier.Directions.Positive_X) && (neighbors[Carrier.Directions.Positive_X] is Road || (neighbors[Carrier.Directions.Positive_X] is RoadTubeCrossing && (neighbors[Carrier.Directions.Positive_X] as RoadTubeCrossing).RoadAlongX)) || neighbors.ContainsKey(Carrier.Directions.Negative_X) && (neighbors[Carrier.Directions.Negative_X] is Road || (neighbors[Carrier.Directions.Negative_X] is RoadTubeCrossing && (neighbors[Carrier.Directions.Negative_X] as RoadTubeCrossing).RoadAlongX))) { (this as RoadTubeCrossing).RoadAlongX = true; return Matrix.CreateRotationY(MathHelper.PiOver2); } else if (neighbors.ContainsKey(Carrier.Directions.Positive_Y) && (neighbors[Carrier.Directions.Positive_Y] is Road || (neighbors[Carrier.Directions.Positive_Y] is RoadTubeCrossing && !(neighbors[Carrier.Directions.Positive_Y] as RoadTubeCrossing).RoadAlongX)) || neighbors.ContainsKey(Carrier.Directions.Negative_Y) && (neighbors[Carrier.Directions.Negative_Y] is Road || (neighbors[Carrier.Directions.Negative_Y] is RoadTubeCrossing && !(neighbors[Carrier.Directions.Negative_Y] as RoadTubeCrossing).RoadAlongX))) { (this as RoadTubeCrossing).RoadAlongX = false; return Matrix.CreateRotationY(0); } else if (neighbors.ContainsKey(Carrier.Directions.Positive_X) && (neighbors[Carrier.Directions.Positive_X] is Tube ||(neighbors[Carrier.Directions.Positive_X] is RoadTubeCrossing && !(neighbors[Carrier.Directions.Positive_X] as RoadTubeCrossing).RoadAlongX)) || neighbors.ContainsKey(Carrier.Directions.Negative_X) && (neighbors[Carrier.Directions.Negative_X] is Tube||(neighbors[Carrier.Directions.Negative_X] is RoadTubeCrossing && !(neighbors[Carrier.Directions.Negative_X] as RoadTubeCrossing).RoadAlongX))) { (this as RoadTubeCrossing).RoadAlongX = false; return Matrix.CreateRotationY(0); } else if (neighbors.ContainsKey(Carrier.Directions.Positive_Y) && (neighbors[Carrier.Directions.Positive_Y] is Tube ||(neighbors[Carrier.Directions.Positive_Y] is RoadTubeCrossing && (neighbors[Carrier.Directions.Positive_Y] as RoadTubeCrossing).RoadAlongX)) || neighbors.ContainsKey(Carrier.Directions.Negative_Y) && (neighbors[Carrier.Directions.Negative_Y] is Tube ||(neighbors[Carrier.Directions.Negative_Y] is RoadTubeCrossing && (neighbors[Carrier.Directions.Negative_Y] as RoadTubeCrossing).RoadAlongX))) { (this as RoadTubeCrossing).RoadAlongX = true; return Matrix.CreateRotationY(MathHelper.PiOver2); } } switch (r) { case Runnings.Y: // Do Nothing. break; case Runnings.X: return Matrix.CreateRotationY(MathHelper.PiOver2); case Runnings.NXNY: // Do Nothing. break; case Runnings.NXPY: return Matrix.CreateRotationY(MathHelper.PiOver2); case Runnings.PXPY: return Matrix.CreateRotationY(MathHelper.Pi); case Runnings.PXNY: return Matrix.CreateRotationY(-MathHelper.PiOver2); case Runnings.Negative_X: // Do Nothing. break; case Runnings.Negative_Y: return Matrix.CreateRotationY(-MathHelper.PiOver2); case Runnings.Positive_X: return Matrix.CreateRotationY(MathHelper.Pi); case Runnings.Positive_Y: return Matrix.CreateRotationY(MathHelper.PiOver2); case Runnings.Four_Way: break; } return Matrix.Identity; } #endregion } }