diff options
author | Stijn Buys <ingar@osirion.org> | 2010-09-22 21:32:34 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2010-09-22 21:32:34 +0000 |
commit | a6f9773c358dd7d091ff64cbda504ab8d8066dd3 (patch) | |
tree | 226e23c4656957e908623ccda9d3d1c50240a0b4 /src/core/item.cc | |
parent | bbb43d1c15f2858573f5abb595aa62f8224e4d76 (diff) |
full trading support for networked games
Diffstat (limited to 'src/core/item.cc')
-rw-r--r-- | src/core/item.cc | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/core/item.cc b/src/core/item.cc index 77b0f9c..e9d9f65 100644 --- a/src/core/item.cc +++ b/src/core/item.cc @@ -4,8 +4,10 @@ the terms of the GNU General Public License version 2 */ -#include "core/item.h" #include "sys/sys.h" +#include "core/application.h" +#include "core/item.h" + namespace core { @@ -17,6 +19,7 @@ Item::Item(const Info *info) item_info = info; item_amount = 0; item_price = info->price(); + set_timestamp(game() ? game()->timestamp() : 0); } Item::~Item() @@ -28,21 +31,41 @@ Item::~Item() void Item::set_amount(const long amount) { item_amount = amount; + set_timestamp(game() ? game()->timestamp() : 0); } void Item::inc_amount(const long amount) { item_amount += amount; + set_timestamp(game() ? game()->timestamp() : 0); } void Item::dec_amount(const long amount) { item_amount -= amount; + set_timestamp(game() ? game()->timestamp() : 0); } void Item::set_price(const long price) { item_price = price; + set_timestamp(game() ? game()->timestamp() : 0); +} + +void Item::set_timestamp(const unsigned long timestamp) +{ + item_timestamp = timestamp; +} + +void Item::serialize_server_update(std::ostream & os) const +{ + os << amount() << " " << price() << " "; +} + +void Item::receive_server_update(std::istream &is) +{ + is >> item_amount; + is >> item_price; } } // namespace core |