/* * Factory.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 System.Collections.Generic; using Microsoft.Xna.Framework.Content; using tAC_Engine.Graphics.Entities; using Microsoft.Xna.Framework; namespace ColonySim.Structures { /// /// Represents an outpost in outer space. Outposts can be used to harvest /// resources from nearby Resource Containers, transport resources via /// connected Tubes, etc. /// class Factory : Structure { #region Fields //// The array of connection tubes this can have //readonly List mConnections; // The set of output resources and their connections Dictionary mResourceConversions = new Dictionary(); EntityBillboardSprite mResourceConnectionAlert; EntityBillboardSprite mResidentialConnectionAlert; public override List BillboardRefs { get { List returnList = new List(); returnList.Add(mResourceConnectionAlert); returnList.Add(mResidentialConnectionAlert); return returnList ; } } protected override void OnVisibleChanged(object sender, EventArgs args) { base.OnVisibleChanged(sender, args); mResidentialConnectionAlert.Visible = Visible; mResourceConnectionAlert.Visible = Visible; } // The output value int mOutputValue = 5; #endregion #region Properties ///// ///// Allows access to the connections this Outpost has. ///// //public List Connections //{ // get { return mConnections; } //} /// /// Allows access to the input resource. /// public Dictionary ResourceConversions { get { return mResourceConversions; } set { mResourceConversions = value; } } /// /// Allows access to the output value /// public int OutputValue { get { return mOutputValue; } set { mOutputValue = value; } } public override void SetDistanceFromResource(int resource, int distance) { base.SetDistanceFromResource(resource, distance); UpdateConnectionIcons(); } public override void SetDistanceFromResource(int[] resources) { base.SetDistanceFromResource(resources); UpdateConnectionIcons(); } public override int DistanceFromResidential { get { return base.DistanceFromResidential; } set { base.DistanceFromResidential = value; UpdateConnectionIcons(); } } #endregion #region Constructs /// /// Create the given structure. /// /// The content manager /// The name of our model /// The name of our texture public Factory(ContentManager pContent, string pModelName, string pTextureName) : base(pContent,pModelName,pTextureName) { // Create our list //mConnections = new List(); } #endregion #region Behavior /// /// Process the current turn. /// public override void Tick() { // Process our current resources ProcessResources(); } /// /// Processes the resources that this Outpost has. /// private void ProcessResources() { // If we're connected to a residential structure if (ConnectedToResidential) { // Go through each of the resources foreach (ResourceCode resource in mResourceConversions.Keys) { // If we're connected to the resource if (ConnectedToResource(resource)) { // Now get the enxt tier of resource valued ResourceCode next = mResourceConversions[resource]; // If it's not none if (next != ResourceCode.None) { // Get the resources if (GridReference.StatusInfo.Resources.ContainsKey(next)) { // Just increment the number of resources GridReference.StatusInfo.Resources[next] += mOutputValue; } else { // Add the resource GridReference.StatusInfo.Resources.Add(next, mOutputValue); } } } } } } #endregion #region Utility /// /// Returns the most basic information about the given structure. /// /// The information about the given structure. public override string BuyInformationString() { // Create the string builder System.Text.StringBuilder builder = new System.Text.StringBuilder(base.BuyInformationString()); // Append the resources we take in and what we output builder.Append("\nConverts:"); foreach (ResourceCode code in mResourceConversions.Keys) { // Go through and append the values builder.Append("\n " + code + " to " + mResourceConversions[code]); } // Append the output rate builder.Append("\nRate: " + mOutputValue); //// Append the upkeep resources //builder.Append("\nResource Upkeep:"); //foreach (ResourceCode key in mRequiredResources.Keys) //{ // // Append the resource // builder.Append("\n " + key.ToString() + ": " + mRequiredResources[key]); //} // Return return builder.ToString(); } /// /// Returns a really basic string about the structure. /// /// The information about the given structure. public override string SelectInformationString() { // Base value System.Text.StringBuilder builder = new System.Text.StringBuilder(base.SelectInformationString()); // Append the resources we take in and what we output builder.Append("\nConverting:"); foreach (ResourceCode code in mResourceConversions.Keys) { // Go through and append the values builder.Append("\n " + code + " to " + mResourceConversions[code]); } // Append the output rate builder.Append("\nRate: " + mOutputValue); // Return return builder.ToString(); } /// /// Returns a clone of this structure. /// /// The cloned structure. public override Structure Clone() { // Create the return value Factory retVal = new Factory(Content, ModelPath, TexturePath); // Set the values to ours retVal.Name = Name; retVal.FootPrintSize = FootPrintSize; retVal.Cost = Cost; retVal.ResourceCosts = ResourceCosts; retVal.BuildRadius = BuildRadius; retVal.DrawOrder = DrawOrder; retVal.TechniqueName = TechniqueName; retVal.RequiresBuildArea = RequiresBuildArea; retVal.ResourceConversions = ResourceConversions; retVal.OutputValue = OutputValue; retVal.AlphaMapPath = AlphaMapPath; retVal.mResourceConnectionAlert = new EntityBillboardSprite(Content, mResourceConnectionAlert.TextureName, mResourceConnectionAlert.Particle); retVal.mResourceConnectionAlert.Initialize(); retVal.mResourceConnectionAlert.Visible = false; retVal.mResidentialConnectionAlert = new EntityBillboardSprite(Content, mResidentialConnectionAlert.TextureName, mResidentialConnectionAlert.Particle); retVal.mResidentialConnectionAlert.Initialize(); retVal.mResidentialConnectionAlert.Visible = false; // Return the retval return retVal; } public override string ToSaveString() { System.Text.StringBuilder returnString = new System.Text.StringBuilder(); if (Name == null) returnString.Append("null"); else returnString.Append(Name); returnString.Append(" "); returnString.Append(FootPrintSize.X); returnString.Append(" "); returnString.Append(FootPrintSize.Y); returnString.Append(" "); returnString.Append(Cost); returnString.Append(" "); returnString.Append(BuildRadius); returnString.Append(" "); returnString.Append(DrawOrder); returnString.Append(" "); returnString.Append(TechniqueName); returnString.Append(" "); // If count is greater than 0 if (mResourceConversions.Count > 0) { foreach (ResourceCode code in mResourceConversions.Keys) { // Append the conversion values returnString.Append((int)code + "," + (int)mResourceConversions[code] + ";"); } } else { // Append a -1 returnString.Append("-1"); } returnString.Append(" "); returnString.Append(OutputValue); returnString.Append(" "); returnString.AppendLine(); return returnString.ToString(); } public void LoadConnectionAlert(string pResourceTexturePathName, string pResidentialTexturePathName, SpriteData pSpriteData) { pSpriteData.position = this.Center; mResourceConnectionAlert = new EntityBillboardSprite(Content, pResourceTexturePathName, pSpriteData); mResourceConnectionAlert.Initialize(); mResourceConnectionAlert.Visible = false; SpriteData temp = new SpriteData(); temp.color = pSpriteData.color; temp.position = this.Center; temp.size = pSpriteData.size; mResidentialConnectionAlert = new EntityBillboardSprite(Content, pResidentialTexturePathName, pSpriteData); mResidentialConnectionAlert.Initialize(); mResidentialConnectionAlert.Visible = false; } public override void UpdateConnectionIcons() { bool isResourceConnected = false; foreach (ResourceCode resource in mResourceConversions.Keys) { if(this.ConnectedToResource(resource)) { isResourceConnected = true; break; } } if (Visible) { if (!isResourceConnected) { SpriteData temp = mResourceConnectionAlert.Particle; temp.position = this.Center + (Vector3.Up * 3.5f); mResourceConnectionAlert.Particle = temp; mResourceConnectionAlert.Visible = true; } else mResourceConnectionAlert.Visible = false; if (!this.ConnectedToResidential) { SpriteData temp = mResidentialConnectionAlert.Particle; temp.position = this.Center + (Vector3.Up * 4.5f); mResidentialConnectionAlert.Particle = temp; mResidentialConnectionAlert.Visible = true; } else mResidentialConnectionAlert.Visible = false; } else { mResidentialConnectionAlert.Visible = false; mResourceConnectionAlert.Visible = false; } } public override void UpdateIconCamera(Matrix View, Matrix Projection) { mResourceConnectionAlert.View = View; mResourceConnectionAlert.Projection = Projection; mResidentialConnectionAlert.View = View; mResidentialConnectionAlert.Projection = Projection; } #endregion } }