/* * Commercial.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 System.Collections.Generic; using tAC_Engine.Graphics.Entities; using Microsoft.Xna.Framework; using System; namespace ColonySim.Structures { /// /// This structure represents a place where adjacent Residents can go to /// spend money on goods and services. This produces money based on the /// number of residents, up to the maximum supported amount of people. /// class Commercial : Structure { #region Fields protected override void OnVisibleChanged(object sender, EventArgs args) { base.OnVisibleChanged(sender, args); mResidentialConnectionAlert.Visible = Visible; } // The amount of money this produces when it is connected per turn int mMoneyGenerated = 25; // The resources this commercial structure requires to burn Dictionary mRequiredResources = new Dictionary(); EntityBillboardSprite mResidentialConnectionAlert; 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 /// /// Allows getting and setting of the amount of money this store /// returns per person that shops or performs business here. /// public int MoneyGenerated { get { return mMoneyGenerated; } set { mMoneyGenerated = value; } } /// /// Allows getting and setting of the resources this Commercial /// structure requires. /// public Dictionary RequiredResources { get { return mRequiredResources; } set { mRequiredResources = value; } } #endregion #region Constructs /// /// Create the given structure. /// /// The content manager /// The name of our model /// The name of our texture public Commercial(ContentManager pContent, string pModelName, string pTextureName) : base(pContent,pModelName,pTextureName) { } #endregion #region Behavior /// /// Update the population because we just ticked on a turn. /// public override void Tick() { // Grow the population Commerce(); } /// /// Perform commerce during this Tick, generating money for the Colony. /// protected void Commerce() { // See if we're connected to a residential building if (ConnectedToResidential) { // Boolean value detailing if we can increment resources bool canGenerate = GridReference.StatusInfo.EnoughResources(RequiredResources); // If we can generate the money if (canGenerate) { // Get the amount of money we can generate float pop = Math.Max(500, GridReference.StatusInfo.Population) / 250f; float hap = Math.Max(GridReference.StatusInfo.Happiness * 2, 0.0f); // Generate some money GridReference.StatusInfo.Money += (int)(MoneyGenerated * pop * hap); // Spend the resources GridReference.StatusInfo.SpendResources(RequiredResources); } } } #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("\nIncome: " + mMoneyGenerated); // Append the upkeep resources builder.Append("\nResource Upkeep:"); foreach (ResourceCode key in mRequiredResources.Keys) { // Append the resource builder.Append("\n " + key + ": " + mRequiredResources[key]); } // Return return builder.ToString(); } /// /// Returns a clone of this structure. /// /// The cloned structure. public override Structure Clone() { // Create the return value Commercial retVal = new Commercial(Content, ModelPath, TexturePath); // Set the values to ours retVal.Name = Name; retVal.FootPrintSize = FootPrintSize; retVal.Cost = Cost; retVal.ResourceCosts = ResourceCosts; retVal.BuildRadius = BuildRadius; retVal.MoneyGenerated = MoneyGenerated; retVal.DrawOrder = DrawOrder; retVal.TechniqueName = TechniqueName; retVal.RequiresBuildArea = RequiresBuildArea; retVal.AlphaMapPath = AlphaMapPath; retVal.RequiredResources = RequiredResources; 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(MoneyGenerated); returnString.Append(" "); returnString.Append(DrawOrder); returnString.Append(" "); returnString.Append(TechniqueName); 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 (this.Visible = true && !this.ConnectedToResidential) { SpriteData temp = mResidentialConnectionAlert.Particle; temp.position = this.Center + (Vector3.Up * 2f); mResidentialConnectionAlert.Particle = temp; mResidentialConnectionAlert.Visible = true; } else mResidentialConnectionAlert.Visible = false; } #endregion } }