/* * Residential.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 Microsoft.Xna.Framework.Content; namespace ColonySim.Structures { /// /// Represents a planet in the game. Planets are the population centers /// of the game. /// class Residential : Structure { #region Constants #endregion #region Fields // The current population int mCurrentPopulation; // The maxiumum population int mMaximumPopulation = 100; // The happiness of the population (0 to 100) float mHappiness = 0.5f; #endregion #region Properties /// /// Allow the viewing of the current population of the planet. /// public int CurrentPopulation { get { return mCurrentPopulation; } set { mCurrentPopulation = value; } } /// /// Allow the viewing of the maximum population of the planet. /// public int MaximumPopulation { get { return mMaximumPopulation; } set { mMaximumPopulation = value; } } /// /// Allows the setting and getting of the structure's happiness. /// public float Happiness { get { return mHappiness; } set { mHappiness = value; } } #endregion #region Constructs /// /// Create the given structure. /// /// The content manager /// The name of our model /// The name of our texture public Residential(ContentManager pContent, string pModelName, string pTextureName) : base(pContent,pModelName,pTextureName) { mDistanceFromResidential = 0; } #endregion #region Behavior /// /// Update the population because we just ticked on a turn. /// public override void Tick() { // Grow the population GrowPopulation(); } /// /// Grow the population based on the rules for altering the population, /// using the GOP. /// protected void GrowPopulation() { // Find the difference in population int difference = mMaximumPopulation - mCurrentPopulation; // Multiply the difference by the happiness to get the approximate value float increment = difference * (GridReference.StatusInfo.Happiness / 10); // Now increment the population mCurrentPopulation += (int)increment; } #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 commercial values builder.Append("\nMax Population: " + mMaximumPopulation); builder.Append("\nBase Happiness: " + mHappiness); // 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 commercial values builder.Append("\nPopulation: " + mCurrentPopulation); builder.Append("\nHappiness: " + mHappiness); // Return return builder.ToString(); } /// /// Returns a clone of this structure. /// /// The cloned structure. public override Structure Clone() { // Create the return value Residential retVal = new Residential(Content, ModelPath, TexturePath); // Set the values to ours retVal.Name = Name; retVal.FootPrintSize = FootPrintSize; retVal.Cost = Cost; retVal.ResourceCosts = ResourceCosts; retVal.BuildRadius = BuildRadius; retVal.MaximumPopulation = MaximumPopulation; retVal.Happiness = Happiness; retVal.DrawOrder = DrawOrder; retVal.TechniqueName = TechniqueName; retVal.RequiresBuildArea = RequiresBuildArea; retVal.AlphaMapPath = AlphaMapPath; // 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(MaximumPopulation); returnString.Append(" "); returnString.Append(CurrentPopulation); returnString.Append(" "); returnString.Append(DrawOrder); returnString.Append(" "); returnString.Append(TechniqueName); returnString.Append(" "); returnString.AppendLine(); return returnString.ToString(); } #endregion } }