/*
* Structure.cs
* Authors: Bradley R. Blankenship
* 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;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;
using tAC_Engine.Graphics.Entities;
namespace ColonySim.Structures
{
///
/// Represents a structure in the Colony which is either added by the
/// player or generated by the system.
///
internal abstract class Structure : GridComponent
{
#region Fields
// The name of the given structure
string mName;
// The footprint size of the structure
Vector2 mFootPrintSize = new Vector2( 1, 1 );
// The build radius for the given structure
int mBuildRadius;
// The cost for the structure
int mCost;
// The resources this structure requires to be built
Dictionary mResourceCosts = new Dictionary();
// Whether the build area of the structure is visible or not
bool mBuildAreaVisible = true;
// The array of textures to use for our icon buttons
Texture2D[] mStructureIcons = new Texture2D[2];
// The distance on the graph from the nearest residential, MaxValue represents no connection.
internal int mDistanceFromResidential = int.MaxValue;
public virtual int DistanceFromResidential
{
get { return mDistanceFromResidential; }
set { mDistanceFromResidential = value; }
}
// The distance on the graph from a given resource
internal int[] mDistanceFromResource = new int[Enum.GetNames(typeof (ResourceCode)).Length];
public virtual void SetDistanceFromResource(int resource, int distance)
{
mDistanceFromResource[resource] = distance;
}
public virtual void SetDistanceFromResource(int[] resources)
{
mDistanceFromResource = resources;
}
public virtual int GetDistanceFromResource(int resource)
{
return mDistanceFromResource[resource];
}
bool mRequiresBuildArea;
public bool RequiresBuildArea
{
get { return mRequiresBuildArea; }
set { mRequiresBuildArea = value; }
}
///
/// The Area which the structure covers on the grid
///
public Rectangle AreaRectangle
{
get { return new Rectangle(GridPosition.X, GridPosition.Y,
(int)FootPrintSize.X, (int)FootPrintSize.Y); }
}
#endregion
#region Properties
///
/// Allows access to the name of the given structure.
///
public string Name
{
get { return mName; }
set { mName = value; }
}
///
/// Allows access to the footprint size of the structure.
///
public Vector2 FootPrintSize
{
get { return mFootPrintSize; }
set { mFootPrintSize = value; }
}
///
/// Allows access to the cost of the Structure.
///
public int Cost
{
get { return mCost; }
set { mCost = value; }
}
///
/// Allows access to the costs of the resources.
///
public Dictionary ResourceCosts
{
get { return mResourceCosts; }
set { mResourceCosts = value; }
}
///
/// Access the build radius for the given structure.
///
public int BuildRadius
{
get { return mBuildRadius; }
set
{
mBuildRadius = value;
}
}
///
/// Access the value determining whether the build area of the
/// structure should be visible or not.
///
public bool BuildAreaVisible
{
get { return mBuildAreaVisible; }
set { mBuildAreaVisible = value; }
}
public virtual List BillboardRefs
{
get { return null; }
}
///
/// Access the structure icons available for the structure.
///
public Texture2D[] StructureIcons
{
get { return mStructureIcons; }
set { mStructureIcons = value; }
}
///
/// True if there is a path along a road to a residential structure, or if this structure is a residential structure.
///
public virtual bool ConnectedToResidential
{
get { return mDistanceFromResidential < int.MaxValue; }
}
///
/// True if there is a path along a tube to a mining plant of the given resource, or if this structure is a mining plant for the given resource.
///
public virtual bool ConnectedToResource(ResourceCode resource)
{
return mDistanceFromResource[(int)resource] < int.MaxValue;
}
#endregion
#region Constructs
///
/// Create the given structure.
///
/// The content manager
/// The name of our model
/// The name of our texture
protected Structure(ContentManager pContent, string pModelName,
string pTextureName) : base(pContent,pModelName,pTextureName)
{
for (int i = 0; i < mDistanceFromResource.Length; ++i)
{
mDistanceFromResource[i] = int.MaxValue;
}
}
#endregion
#region Behavior
///
/// Update during a common tick.
///
public override void Tick()
{
// Do nothing
}
#endregion
#region Utility
///
/// Returns a really basic string about the structure relevant to buying it.
///
/// The information about the given structure.
public virtual string BuyInformationString()
{
// Create the string builder
System.Text.StringBuilder builder = new System.Text.StringBuilder(mName);
// Append our costs
builder.Append("\nCost(s): \n Credits: " + Cost);
foreach (ResourceCode cost in mResourceCosts.Keys)
{
// Append the cost
builder.Append("\n " + cost + ": " + mResourceCosts[cost]);
}
// Return
return builder.ToString();
}
///
/// Returns a really basic string about the structure.
///
/// The information about the given structure.
public virtual string SelectInformationString()
{
// Return
return mName;
}
///
/// Return our string representation
///
/// The string that represents us
public override string ToString()
{
// Return our given structure name stuff
return mName + ", " + Model + ", " + Texture;
}
///
/// Returns a clone of this structure.
///
/// The cloned structure.
public abstract Structure Clone();
public virtual string ToSaveString() { return string.Empty; }
public virtual bool CreateFromSaveString(string pString) { return false; }
public virtual void UpdateConnectionIcons() { }
public virtual void UpdateIconCamera(Matrix View, Matrix Projection) { }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (BillboardRefs != null)
{
foreach (EntityBillboardSprite e in BillboardRefs)
{
e.Visible = false;
e.Dispose();
}
}
}
#endregion
}
}