Updated interactions with objects subsystem

This commit is contained in:
Andrew nuark G 2020-12-16 00:22:33 +07:00
parent f20bb7c2d9
commit 39935c4ecd
2 changed files with 76 additions and 2 deletions

View file

@ -1,7 +1,81 @@
#include "object_system.h"
const dpoint_entity& object_system::get_dpoint(entity_id oid, bool &success) {
dpoint_entity *out;
success = false;
for (dpoint_entity &item : this->_dpoints) {
if (item.id() == oid) {
success = true;
out = &item;
break;
}
}
return *out;
}
bool object_system::remove_dpoint(entity_id oid) {
auto vit = this->_dpoints.begin();
for (; vit != this->_dpoints.end(); vit++) {
if ((*vit).id() == oid) {
this->_dpoints.erase(vit);
return true;
}
}
return false;
}
bool object_system::add_dpoint(dpoint_entity dpoint) {
bool exists = false;
this->get_dpoint(dpoint.id(), exists);
if (!exists) {
this->_dpoints.push_back(dpoint);
return true;
}
return false;
}
const vessel_entity& object_system::get_vessel(entity_id oid, bool &success) {
vessel_entity *out;
success = false;
for (vessel_entity &item : this->_vessels) {
if (item.id() == oid) {
success = true;
out = &item;
break;
}
}
return *out;
}
bool object_system::remove_vessel(entity_id oid) {
auto vit = this->_vessels.begin();
for (; vit != this->_vessels.end(); vit++) {
if ((*vit).id() == oid) {
this->_vessels.erase(vit);
return true;
}
}
return false;
}
bool object_system::add_vessel(vessel_entity dpoint) {
bool exists = false;
this->get_dpoint(dpoint.id(), exists);
if (!exists) {
this->_vessels.push_back(dpoint);
return true;
}
return false;
}
void object_system::init(QDataStream &stream) {
int dicnt;