Planeshift
economymanager.h
Go to the documentation of this file.
1 /*
2  * economymanager.h
3  *
4  * Copyright (C) 2005 Atomic Blue (info@planeshift.it, http://www.planeshift.it)
5  *
6  * Credits : Christian Svensson
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation (version 2
11  * of the License).
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Creation Date: 11/Jan 2005
21  * Description : This is the header file for the economymanager
22  * This manager handles all the exchange/trade things and calculates
23  * prices and keeps histories of transactions and so on
24  *
25  */
26 
27 #ifndef ECONOMYMANAGER_HEADER
28 #define ECONOMYMANAGER_HEADER
29 
30 //=============================================================================
31 // Crystal Space Includes
32 //=============================================================================
33 #include <csutil/hash.h>
34 #include <csutil/sysfunc.h>
35 
36 //=============================================================================
37 // Project Includes
38 //=============================================================================
39 #include "util/gameevent.h"
40 
41 //=============================================================================
42 // Local Includes
43 //=============================================================================
44 #include "msgmanager.h" // Parent class
45 
46 
48 {
49  PID from;
50  PID to;
51 
52  csString fromName;
53  csString toName;
54  csString itemName;
55 
56  unsigned int item;
57  int count;
58  int quality;
59  unsigned int price;
60 
61  bool moneyIn;
62  int stamp;
63 
65  from(0), to(0), fromName("NA"), toName("NA"), itemName("NA"), item(0),
66  count(0), quality(0), price(0), moneyIn(false), stamp(0)
67  { }
68 };
69 
71 {
72  unsigned int itemId;
73  unsigned int bought;
74  unsigned int sold;
75 };
76 
77 class EconomyManager : public MessageManager<EconomyManager>
78 {
79 public:
81  ~EconomyManager();
82 
83  void HandleBuyMessage(MsgEntry* me,Client* client);
84  void HandleSellMessage(MsgEntry* me,Client* client);
85  void HandlePickupMessage(MsgEntry* me,Client* client);
86  void HandleDropMessage(MsgEntry* me,Client* client);
87  void HandleLootMessage(MsgEntry* me,Client* client);
88 
89  void AddTransaction(TransactionEntity* trans, bool sell, const char* type);
90 
91  TransactionEntity* GetTransaction(int id);
92  unsigned int GetTotalTransactions();
93  void ClearTransactions();
94  void ScheduleDrop(csTicks ticks,bool loop);
95 
96  ItemSupplyDemandInfo* GetItemSupplyDemandInfo(unsigned int itemId);
97 
98  struct Economy
99  {
100  // Money flowing in to the economy
101  unsigned int lootValue;
102  unsigned int sellingValue;
103  unsigned int pickupsValue;
104  // Money flowing out of the economy
105  unsigned int buyingValue;
106  unsigned int droppedValue;
107 
108  Economy() : lootValue(0), sellingValue(0), pickupsValue(0), buyingValue(0), droppedValue(0) { };
109  };
110 
112 
113 protected:
114  csArray< csRef<TransactionEntity> > history;
115  csHash< csRef<ItemSupplyDemandInfo> > supplyDemandInfo;
116 };
117 
118 
120 {
121 public:
122  psEconomyDrop(EconomyManager* manager,csTicks ticks,bool loop);
123  void Trigger();
124 protected:
126  csTicks eachTimeTicks;
127  bool loop;
128 };
129 
130 #endif
131 
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
csArray< csRef< TransactionEntity > > history
unsigned int item
This class collects data of a netclient.
Definition: client.h:95
csHash< csRef< ItemSupplyDemandInfo > > supplyDemandInfo
csTicks eachTimeTicks
unsigned int price
EconomyManager * economy
All scheduled events must inherit from this class.
Definition: gameevent.h:36
Provides a manager to facilitate subscriptions.
Definition: msgmanager.h:106