Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/entity.cc')
-rw-r--r--src/core/entity.cc36
1 files changed, 35 insertions, 1 deletions
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
<< "\"" <<label() << "\" "
<< "\"" << name() << "\" "
<< "\"" << (entity_model ? entity_model->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;
}