src/Product.cpp

Go to the documentation of this file.
00001 /* Crown and Cutlass
00002  * Product Class
00003  */
00004 
00005 #include <string>
00006 #include <iostream>
00007 
00008 #include "ccmath.h"
00009 #include "Log.h"
00010 #include "Economy.h"
00011 #include "Product.h"
00012 
00013 using namespace std;
00014 
00015 Product::Product() {
00016   m_ID = -1;
00017   m_ConsumptionRate = 0;
00018   m_ProductionRate = 0;
00019   m_ProductionPoints = 0;
00020 }
00021 
00022 Product::Product(int myID, int Consumption, int Production) {
00023   m_ID = myID;
00024   if (Consumption < 0) {
00025     Log::s_log->Message("Illegal Consumption Rate %i", Consumption);
00026     throw string("Illegal Consumption Rate");
00027   }
00028   m_ConsumptionRate = Consumption;
00029   if (Production < 0) {
00030     Log::s_log->Message("Illegal Production Rate %i", Production);
00031     throw string("Illegal Production Rate");
00032   }
00033   m_ProductionRate = Production;
00034 }
00035 
00036 Product::~Product() {
00037 
00038 }
00039 
00040 int Product::GetConsumption() {
00041   return m_ConsumptionRate;
00042 }
00043 
00044 void Product::SetConsumption(int Consumption) {
00045   if (Consumption < 0) throw string("Illegal Consumption Rate");
00046   m_ConsumptionRate = Consumption;
00047 }
00048 
00049 int Product::GetProduction() {
00050   return m_ProductionRate;
00051 }
00052 
00053 void Product::SetProduction(int Production) {
00054   if (Production < 0) throw string("Illegal Production Rate");
00055   m_ProductionRate = Production;
00056 }
00057 
00058 int Product::GetPrice(int CitySize) {
00059   /* This isn't quite right...
00060    * Its more complicated...Production - Consumption gives you the rate
00061    * of change in the storage. So then the amount stored of the product
00062    * and the amount changed then looks at a comfort level for the product
00063    * to determine the price.
00064    */
00065   int Price;
00066   Price = ((m_ProductionPoints * m_ProductionRate) - (m_ConsumptionRate * CitySize)) 
00067           + Economy::s_economy->ProductDefaults[m_ID];
00068   Log::s_log->DebugMessage("Price= %i", Price);
00069   return Price;
00070 }
00071 
00072 string Product::GetName() {
00073   return Economy::s_economy->ProdList[m_ID - 1];
00074 }
00075 
00076 void Product::Print() {
00077   cout << "Product Name: " << GetName() 
00078     << "\n\tProduction: " << m_ProductionRate 
00079     << "\n\tConsumption: " << m_ConsumptionRate 
00080     << endl;
00081 }
00082 
00083 int Product::GetProductionPoints() {
00084   return m_ProductionPoints;
00085 }
00086 void Product::SetProductionPoints(int PP) {
00087   if (PP < 0) return;
00088   m_ProductionPoints = PP;
00089 }
00090 int Product::AddProductionPoints(int PP) {
00091   if (m_ProductionPoints - PP < 0) return m_ProductionPoints;
00092   m_ProductionPoints += PP;
00093   Log::s_log->DebugMessage("%s's PPs: %i", GetName().c_str(), m_ProductionPoints);
00094   return m_ProductionPoints;
00095 }

Generated on Mon Jan 8 22:34:12 2007 for CrownandCutlass by  doxygen 1.4.7