Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / ryzom / common / src / game_share / seeds.h
blob3c3a3dfcd48e3dbd92e43932aa9bb55360484a31
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef SEEDS_H
20 #define SEEDS_H
23 /** Weight of a seed in kilograms (all kind of seeds have the same weight)
25 const double SeedWeigth = 0.01;
27 /** Money of Ryzom (seeds)
28 * There are 4 kind of seeds :
29 * - little seeds (LS)
30 * - medium seeds (MS). One MS is worth 10 LS.
31 * - big seeds (BS). One BS is worth 10 MS.
32 * - very big seeds (VBS). One VBS is worth 10 BS.
34 * Overflow is managed.
36 * \author Nicolas Vizerie
37 * \author Nevrax France
38 * \date 2002
40 class CSeeds
42 public:
43 typedef uint32 TUInt; // type of integer to count number of seeds for a slot.
44 typedef uint64 TBigUInt; // type of integer to count the total number of seeds.
45 enum { MaxUIntValue = INT_MAX };
46 public:
47 // ctruct with the given quantity of money
48 CSeeds(TUInt ls = 0, TUInt ms = 0, TUInt bs = 0, TUInt vbs = 0) : _LS(ls), _MS(ms), _BS(bs), _VBS(vbs)
51 // set the given total by using the smallest number of seeds
52 void setTotal(TBigUInt total);
53 // gets
54 TUInt getLS() const { return _LS; }
55 TUInt getMS() const { return _MS; }
56 TUInt getBS() const { return _BS; }
57 TUInt getVBS() const { return _VBS; }
59 // sets
60 void setLS(TUInt quantity) { _LS = quantity; }
61 void setMS(TUInt quantity) { _MS = quantity; }
62 void setBS(TUInt quantity) { _BS = quantity; }
63 void setVBS(TUInt quantity) { _VBS = quantity; }
65 // get money total (expressed in little seeds)
66 TBigUInt getTotal() const { return (TBigUInt) _LS + 10 * (TBigUInt) _MS + 100 * (TBigUInt) _BS + 1000 * (TBigUInt) _VBS; }
67 /** Add a number of seeds.
68 * If an overflow is detected, only the maximum value is added, & overflow is filled with the difference
70 void add(const CSeeds &other, CSeeds &overflow);
71 /** Subtract a number of seeds. Begin to subtract the littlest seeds.
72 * Always works provided that the total of the subtracted seeds is < to the total of the target.
73 * Should test it yourself otherwise an assert is raised.
74 * This is typically used when you buy something to a merchant
76 void tradeSubtract(const CSeeds &other);
77 void tradeSubtract(TBigUInt rhs);
79 bool canTradeSubtract(const CSeeds &other) const;
80 bool canTradeSubtract(TBigUInt rhs) const;
82 // Subtract the given quantity to this obj on a per seeds basis. Must ensure that it is possible
83 void subtract(const CSeeds &other);
84 // Test if the given quantity can be subtracted to this obj
85 bool canSubtract(const CSeeds &other) const;
86 // Optimize a quantity of money so that the number of seeds is minimum
87 void optimize();
88 // serial
89 void serial(NLMISC::IStream &f)
91 f.serial( _LS, _MS, _BS, _VBS);
93 // get the weight of all seeds
94 double getWeight() const { return SeedWeigth * (_LS + _MS + _BS + _VBS); }
95 /////////////////////////////////////////////////////
96 private:
97 TUInt _LS; // little seeds
98 TUInt _MS; // medium seeds
99 TUInt _BS; // big seeds
100 TUInt _VBS; // very big seeds
107 #endif