Planeshift
psmoney.h
Go to the documentation of this file.
1 /*
2  * psmoney.h by Anders Reggestad <andersr@pvv.org>
3  *
4  * Copyright (C) 2001 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  *
19  */
20 #ifndef PS_MONEY
21 #define PS_MONEY
22 
23 //CS includes
24 #include <csutil/csstring.h>
25 
26 // Value of coins in other coins
27 #define CIRCLES_VALUE_TRIAS 250
28 #define OCTAS_VALUE_TRIAS 50
29 #define HEXAS_VALUE_TRIAS 10
30 
31 #define CIRCLES_VALUE_HEXAS (CIRCLES_VALUE_TRIAS / HEXAS_VALUE_TRIAS)
32 #define CIRCLES_VALUE_OCTAS (CIRCLES_VALUE_TRIAS / OCTAS_VALUE_TRIAS)
33 #define OCTAS_VALUE_HEXAS (OCTAS_VALUE_TRIAS / HEXAS_VALUE_TRIAS)
34 
35 typedef enum
36 {
41 } Money_Slots;
42 
43 
44 class psMoney
45 {
46 public:
47  psMoney();
48  psMoney(int trias);
49  psMoney(int circles, int octas, int hexas, int trias);
50 
54  psMoney(const char * moneyString);
55 
56 
57  void Set(const char * moneyString);
58  void Set(int type, int value);
59  void Set(int circles, int octas, int hexas, int trias);
60 
63  void SetCircles(int c) { circles = c; }
64  void AdjustCircles( int c );
65 
69  int GetCircles() const { return circles; }
70 
73  void SetOctas(int o) { octas = o; }
74  void AdjustOctas(int o);
78  int GetOctas() const { return octas; }
79 
82  void SetHexas(int h) { hexas = h; }
83  void AdjustHexas( int h );
87  int GetHexas() const { return hexas; }
88 
91  void SetTrias(int t) { trias = t; }
92  void AdjustTrias( int t );
93 
97  int GetTrias() const { return trias; }
98 
102  int GetTotal() const;
103 
107  csString ToString() const;
108 
112  csString ToUserString() const;
113 
117  psMoney Normalized() const;
118 
119  bool operator > (const psMoney& other) const;
120  psMoney operator - (const psMoney& other) const;
121  psMoney operator - (void) const;
122  psMoney operator + (const psMoney& other) const;
123  psMoney operator +=(const psMoney& other);
124  psMoney operator * (const int mult) const;
125 
126  void Adjust( int type, int value );
127  int Get( int type ) const;
128 
129  bool EnsureTrias(int minValue);
130  bool EnsureHexas(int minValue);
131  bool EnsureOctas(int minValue);
132  bool EnsureCircles(int minValue);
133 
134 protected:
135  int circles;
136  int octas;
137  int hexas;
138  int trias;
139 };
140 
141 
142 #endif
psMoney operator+=(const psMoney &other)
void AdjustOctas(int o)
bool EnsureTrias(int minValue)
bool operator>(const psMoney &other) const
bool EnsureHexas(int minValue)
csString ToString() const
Convert psMoney to a string.
csString ToUserString() const
Convert psMoney to user-friendly string.
void Set(const char *moneyString)
void SetCircles(int c)
Set the number of circles.
Definition: psmoney.h:63
void AdjustTrias(int t)
psMoney operator*(const int mult) const
bool EnsureCircles(int minValue)
Money_Slots
Definition: psmoney.h:35
void SetOctas(int o)
Set the number of octas.
Definition: psmoney.h:73
int circles
Definition: psmoney.h:135
int GetCircles() const
Get the number of circles.
Definition: psmoney.h:69
void Adjust(int type, int value)
int GetHexas() const
Get the number of hexas.
Definition: psmoney.h:87
int octas
Definition: psmoney.h:136
bool EnsureOctas(int minValue)
psMoney Normalized() const
Normalize to have the total match the highest possible number of high value coins.
int GetOctas() const
Get the number of octas.
Definition: psmoney.h:78
psMoney operator+(const psMoney &other) const
psMoney operator-(void) const
void AdjustHexas(int h)
void AdjustCircles(int c)
void SetHexas(int h)
Set the number of hexas.
Definition: psmoney.h:82
int Get(int type) const
int hexas
Definition: psmoney.h:137
int trias
Definition: psmoney.h:138
void SetTrias(int t)
Set the number of trias.
Definition: psmoney.h:91
int GetTotal() const
Get the total in trias.
int GetTrias() const
Get the number of trias.
Definition: psmoney.h:97