/* * Entertainment.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 Microsoft.Xna.Framework.Content; using tAC_Engine.Graphics.Entities; using Microsoft.Xna.Framework; using System.Collections.Generic; using System; namespace ColonySim.Structures { /// /// Represents an Entertainment structure in the Colony. Entertainment /// structures raise the happiness of people by being connected via a /// Road to Residential structures. /// class Entertainment : Structure { #region Fields // The modifier the Entertainment building applies to happiness float mHappinessModifier = 1.0f; // The maximum number of people this can support until a it is cut down int mMaxSupported = 100; // The number of people this structure currently supports int mCurrentSupported; EntityBillboardSprite mResidentialConnectionAlert; EntityModel mTransparentModel; public EntityModel TransparentModel { get { return mTransparentModel; } set { mTransparentModel = value; } } public override int DistanceFromResidential { get { return base.DistanceFromResidential; } set { base.DistanceFromResidential = value; UpdateConnectionIcons(); } } public override List BillboardRefs { get { List returnList = new List(); returnList.Add(mResidentialConnectionAlert); return returnList; } } #endregion #region Properties /// /// Allow getting and setting of the happiness modifier that is applied /// to the population. /// public float HappinessModifier { get { return mHappinessModifier; } set { mHappinessModifier = value; } } /// /// Allows getting and setting of the maximum number of people this /// structure can support before the modifier is reduced. /// public int MaxSupported { get { return mMaxSupported; } set { mMaxSupported = value; } } /// /// Allows the getting and setting of the currently supported /// population for the structure. /// int CurrentSupported { get { return mCurrentSupported; } set { mCurrentSupported = value; } } #endregion #region Constructs /// /// Create the given structure. /// /// The content manager /// The name of our model /// The name of our texture public Entertainment(ContentManager pContent, string pModelName, string pTextureName) : base(pContent,pModelName,pTextureName) { } public Entertainment(ContentManager pContent, string pModelName, string pTextureName, EntityModel pTransparentModel) : base(pContent, pModelName, pTextureName) { mTransparentModel = pTransparentModel; } #endregion #region Behavior /// /// Update the population because we just ticked on a turn. /// public override void Tick() { // Grow the population Entertain(); } /// /// Entertain a certain portion of the colony, modifying their /// happiness. /// protected void Entertain() { // If we're connected to a residential structure if (ConnectedToResidential) { // Entertain GridReference.StatusInfo.Happiness += HappinessModifier; } } #endregion #region Utility protected override void OnVisibleChanged(object sender, System.EventArgs args) { base.OnVisibleChanged(sender, args); mTransparentModel.Visible = Visible; mResidentialConnectionAlert.Visible = Visible; } public override Matrix TransformationMatrix { get { return base.TransformationMatrix; } set { base.TransformationMatrix = value; mTransparentModel.TransformationMatrix = TransformationMatrix; } } public override Microsoft.Xna.Framework.Graphics.Color ColorToAdd { get { return base.ColorToAdd; } set { base.ColorToAdd = value; mTransparentModel.ColorToAdd = ColorToAdd; } } /// /// 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("\nHappiness: " + mHappinessModifier); //// 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 our current resource we're mining builder.Append("\nHappiness: " + mHappinessModifier); //// 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 clone of this structure. /// /// The cloned structure. public override Structure Clone() { // Create the return value Entertainment retVal = new Entertainment(Content, ModelPath, TexturePath); // Set the values to ours retVal.Name = Name; retVal.FootPrintSize = FootPrintSize; retVal.Cost = Cost; retVal.ResourceCosts = ResourceCosts; retVal.BuildRadius = BuildRadius; retVal.HappinessModifier = HappinessModifier; retVal.MaxSupported = MaxSupported; retVal.DrawOrder = DrawOrder; retVal.TechniqueName = TechniqueName; retVal.RequiresBuildArea = RequiresBuildArea; retVal.AlphaMapPath = AlphaMapPath; retVal.mResidentialConnectionAlert = new EntityBillboardSprite(Content, mResidentialConnectionAlert.TextureName, mResidentialConnectionAlert.Particle); retVal.mResidentialConnectionAlert.Initialize(); retVal.mResidentialConnectionAlert.Visible = false; retVal.TransparentModel = new EntityModel(Content, mTransparentModel.ModelPath, mTransparentModel.TransformationMatrix); retVal.TransparentModel.DrawOrder = mTransparentModel.DrawOrder; retVal.TransparentModel.Enabled = mTransparentModel.Enabled; retVal.mTransparentModel.Visible = Visible; // 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(HappinessModifier); returnString.Append(" "); returnString.Append(MaxSupported); returnString.Append(" "); returnString.Append(DrawOrder); returnString.Append(" "); returnString.Append(TechniqueName); returnString.Append(" "); returnString.AppendLine(); return returnString.ToString() ; } public void LoadConnectionAlert(string pResourceTexturePathName, string pResidentialTexturePathName, SpriteData pSpriteData) { 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 UpdateIconCamera(Matrix View, Matrix Projection) { mResidentialConnectionAlert.View = View; mResidentialConnectionAlert.Projection = Projection; } public override void UpdateConnectionIcons() { if (Visible && !this.ConnectedToResidential) { SpriteData temp = mResidentialConnectionAlert.Particle; temp.position = this.Center + (Vector3.Up * 2f); mResidentialConnectionAlert.Particle = temp; mResidentialConnectionAlert.Visible = true; } else mResidentialConnectionAlert.Visible = false; } #endregion } }