From a6f9773c358dd7d091ff64cbda504ab8d8066dd3 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 22 Sep 2010 21:32:34 +0000 Subject: full trading support for networked games --- src/core/entity.cc | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src/core/entity.cc') diff --git a/src/core/entity.cc b/src/core/entity.cc index 0b3a402..1494438 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -183,6 +183,8 @@ Entity::Entity(std::istream & is) entity_inventory = 0; entity_info = 0; + entity_inventory = 0; + memset(entity_extension, 0, sizeof(entity_extension)); } @@ -219,6 +221,12 @@ void Entity::clear_updates() entity_created = false; entity_dirty = false; entity_oldzone = 0; + + if (entity_inventory && entity_inventory->dirty()) { + // inventory timestamp must be set for singleplayer + entity_inventory->set_timestamp(game()->timestamp()); + entity_inventory->set_dirty(false); + } } void Entity::set_info(Info *info) @@ -299,7 +307,11 @@ void Entity::serialize_server_create(std::ostream & os) const << "\"" <name() : "") << "\" " - << (info() ? info()->id() : 0) << " "; + << (info() ? info()->id() : 0) << " " + << (inventory() ? 1 : 0) << " "; + + if (inventory()) + inventory()->serialize_server_update(os); } void Entity::receive_server_create(std::istream &is) @@ -371,6 +383,28 @@ void Entity::receive_server_create(std::istream &is) entity_info = 0; } + // has inventory + if (is >> o) { + if (!o) { + if (inventory()) { + con_warn << "Receive no inventory for entity " << id() << " " << label() << " with inventory!" << std::endl; + entity_inventory->clear(); + } + } else { + if (!inventory()) { + entity_inventory = new Inventory(); + } + } + } else { + if (inventory()) { + con_warn << "Receive no inventory for entity " << id() << " " << label() << " with inventory!" << std::endl; + entity_inventory->clear(); + } + } + + if (inventory()) { + inventory()->receive_server_update(is); + } entity_dirty = false; } -- cgit v1.2.3