Planeshift
|
00001 /* 00002 * economymanager.h 00003 * 00004 * Copyright (C) 2005 Atomic Blue ([email protected], http://www.planeshift.it) 00005 * 00006 * Credits : Christian Svensson 00007 * 00008 * This program is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU General Public License 00010 * as published by the Free Software Foundation (version 2 00011 * of the License). 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 * 00020 * Creation Date: 11/Jan 2005 00021 * Description : This is the header file for the economymanager 00022 * This manager handles all the exchange/trade things and calculates 00023 * prices and keeps histories of transactions and so on 00024 * 00025 */ 00026 00027 #ifndef ECONOMYMANAGER_HEADER 00028 #define ECONOMYMANAGER_HEADER 00029 00030 //============================================================================= 00031 // Crystal Space Includes 00032 //============================================================================= 00033 #include <csutil/hash.h> 00034 #include <csutil/sysfunc.h> 00035 00036 //============================================================================= 00037 // Project Includes 00038 //============================================================================= 00039 #include "util/gameevent.h" 00040 00041 //============================================================================= 00042 // Local Includes 00043 //============================================================================= 00044 #include "msgmanager.h" // Parent class 00045 00046 00047 struct TransactionEntity : public csRefCount 00048 { 00049 PID from; 00050 PID to; 00051 00052 csString fromName; 00053 csString toName; 00054 csString itemName; 00055 00056 unsigned int item; 00057 int count; 00058 int quality; 00059 unsigned int price; 00060 00061 bool moneyIn; 00062 int stamp; 00063 00064 TransactionEntity() : 00065 from(0), to(0), fromName("NA"), toName("NA"), itemName("NA"), item(0), 00066 count(0), quality(0), price(0), moneyIn(false), stamp(0) 00067 { } 00068 }; 00069 00070 struct ItemSupplyDemandInfo : public csRefCount 00071 { 00072 unsigned int itemId; 00073 unsigned int bought; 00074 unsigned int sold; 00075 }; 00076 00077 class EconomyManager : public MessageManager<EconomyManager> 00078 { 00079 public: 00080 EconomyManager(); 00081 ~EconomyManager(); 00082 00083 void HandleBuyMessage(MsgEntry* me,Client* client); 00084 void HandleSellMessage(MsgEntry* me,Client* client); 00085 void HandlePickupMessage(MsgEntry* me,Client* client); 00086 void HandleDropMessage(MsgEntry* me,Client* client); 00087 void HandleLootMessage(MsgEntry* me,Client* client); 00088 00089 void AddTransaction(TransactionEntity* trans, bool sell, const char* type); 00090 00091 TransactionEntity* GetTransaction(int id); 00092 unsigned int GetTotalTransactions(); 00093 void ClearTransactions(); 00094 void ScheduleDrop(csTicks ticks,bool loop); 00095 00096 ItemSupplyDemandInfo* GetItemSupplyDemandInfo(unsigned int itemId); 00097 00098 struct Economy 00099 { 00100 // Money flowing in to the economy 00101 unsigned int lootValue; 00102 unsigned int sellingValue; 00103 unsigned int pickupsValue; 00104 // Money flowing out of the economy 00105 unsigned int buyingValue; 00106 unsigned int droppedValue; 00107 00108 Economy() : lootValue(0), sellingValue(0), pickupsValue(0), buyingValue(0), droppedValue(0) { }; 00109 }; 00110 00111 Economy economy; 00112 00113 protected: 00114 csArray< csRef<TransactionEntity> > history; 00115 csHash< csRef<ItemSupplyDemandInfo> > supplyDemandInfo; 00116 }; 00117 00118 00119 class psEconomyDrop : public psGameEvent 00120 { 00121 public: 00122 psEconomyDrop(EconomyManager* manager,csTicks ticks,bool loop); 00123 void Trigger(); 00124 protected: 00125 EconomyManager* economy; 00126 csTicks eachTimeTicks; 00127 bool loop; 00128 }; 00129 00130 #endif 00131