diff options
author | Stijn Buys <ingar@osirion.org> | 2008-07-28 19:37:31 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-07-28 19:37:31 +0000 |
commit | d389a31f9816b55d8c7685ec24b9ab814252d693 (patch) | |
tree | 9b2577692e543fa6c59fcda508f92c3eb839ac7a /src/core/player.cc | |
parent | 17408276791033e8122819185abf3bcb01740105 (diff) |
zone support
Diffstat (limited to 'src/core/player.cc')
-rw-r--r-- | src/core/player.cc | 79 |
1 files changed, 67 insertions, 12 deletions
diff --git a/src/core/player.cc b/src/core/player.cc index 18dabed..9f531ed 100644 --- a/src/core/player.cc +++ b/src/core/player.cc @@ -26,6 +26,7 @@ Player::~Player() void Player::clear() { player_id = 0; + player_zone = 0; player_name.clear(); player_dirty = false; player_rcon = false; @@ -34,16 +35,21 @@ void Player::clear() clear_assets(); } -void Player::clear_assets() +void Player::set_control(EntityControlable *entitycontrolable) { - // clear assets - for (std::list<EntityControlable*>::iterator asset = assets.begin(); asset != assets.end(); asset++) { - (*asset)->entity_owner = 0; - (*asset)->die(); + player_control = entitycontrolable; + + if (entitycontrolable) { + player_zone = entitycontrolable->zone(); } - assets.clear(); - player_control = 0; + player_dirty = true; +} + +void Player::set_zone(Zone *zone) +{ + player_zone = zone; + player_dirty = true; } void Player::update_info() @@ -76,7 +82,7 @@ void Player::serialize_client_update(std::ostream & os) os << " " << player_color << " " << player_color_second << " \"" << player_name << "\""; } -void Player::recieve_client_update(std::istream &is) +void Player::receive_client_update(std::istream &is) { is >> player_color; is >> player_color_second; @@ -93,24 +99,41 @@ void Player::recieve_client_update(std::istream &is) void Player::serialize_server_update(std::ostream & os) const { + unsigned int zone; + if (player_zone) + zone = player_zone->id(); + else + zone = 0; + unsigned int co; if (player_control) co = player_control->id(); else co = 0; + - os << player_id << " " << co << " " << player_color << " \"" << player_name << "\""; + os << player_id << " " << zone << " " << co << " " << player_color << " \"" << player_name << "\""; } -void Player::recieve_server_update(std::istream &is) +void Player::receive_server_update(std::istream &is) { is >> player_id; + + unsigned int zone = 0; + is >> zone; + if (zone) { + player_zone = Zone::find(zone); + } else { + player_zone = 0; + } + unsigned int co = 0; is >> co; if (co) { Entity *e = Entity::find(co); if (e && e->type() == Entity::Controlable) { player_control = (EntityControlable *) e; + player_zone = player_control->zone(); } else { player_control = 0; con_warn << "control set to unknown entity " << co << "\n"; @@ -135,15 +158,24 @@ void Player::add_asset(EntityControlable *entity) { entity->entity_owner = this; assets.push_back(entity); + con_debug << " adding asset " << entity->id() << " to player " << id() << std::endl; } void Player::remove_asset(EntityControlable *entity) { + if (!entity) + return; + for (std::list<EntityControlable*>::iterator asset = assets.begin(); asset != assets.end(); asset++) { - if ((*asset) == entity) { + if (((*asset) == entity) && (entity->owner() == this)) { + //con_debug << " removing asset " << (*asset)->id() << " from player " << id() << std::endl; + + if ((*asset) == player_control) + player_control = 0; (*asset)->entity_owner = 0; (*asset)->die(); assets.erase(asset); + player_dirty = true; return; } } @@ -152,15 +184,38 @@ void Player::remove_asset(EntityControlable *entity) void Player::remove_asset(unsigned int id) { + if (!id) + return; + for (std::list<EntityControlable*>::iterator asset = assets.begin(); asset != assets.end(); asset++) { - if ((*asset)->id() == id) { + if ( ((*asset)->id() == id) && ((*asset)->owner() == this) ) { + //con_debug << " removing asset " << (*asset)->id() << " from player " << this->id() << std::endl; + + if ((*asset) == player_control) + player_control = 0; + (*asset)->entity_owner = 0; (*asset)->die(); assets.erase(asset); + player_dirty = true; return; } } con_warn << "Could not remove asset " << id << " from player " << this->id() << "\n"; } +void Player::clear_assets() +{ + // clear assets + for (std::list<EntityControlable*>::iterator asset = assets.begin(); asset != assets.end(); asset++) { + //con_debug << " removing asset " << (*asset)->id() << " from player " << id() << std::endl; + + (*asset)->entity_owner = 0; + (*asset)->die(); + } + assets.clear(); + + player_control = 0; +} + } |