diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index c5e2b5f..bbec051 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -1635,23 +1635,7 @@ BornPoint* Room::AllocBornPoint(Human* hum) } } if (pre_point) { - switch (hum->entity_subtype) { - case EST_Player: - { - --pre_point->player_num; - } - break; - case EST_Android: - { - --pre_point->android_num; - } - break; - default: - { - - } - break; - } + DecBornPointHumanNum(pre_point, hum); } if (!free_point_list.empty()) { born_point = free_point_list[rand() % free_point_list.size()]; @@ -1667,22 +1651,7 @@ BornPoint* Room::AllocBornPoint(Human* hum) } } if (born_point) { - switch (hum->entity_subtype) { - case EST_Player: - { - ++born_point->player_num; - } - break; - case EST_Android: - { - ++born_point->android_num; - } - break; - default: - { - } - break; - } + DecBornPointHumanNum(born_point, hum); } return born_point; } @@ -1731,20 +1700,80 @@ void Room::CreateMapSpawnPoint(MetaData::MapTplThing& thing_tpl) born_point_hash_[AllocUniid()] = born_point; } +void Room::IncBornPointHumanNum(BornPoint* point, Human* hum) +{ + switch (hum->entity_subtype) { + case EST_Player: + { + ++point->player_num; + } + break; + case EST_Android: + { + ++point->android_num; + } + break; + default: + { + } + break; + } +} + +void Room::DecBornPointHumanNum(BornPoint* point, Human* hum) +{ + switch (hum->entity_subtype) { + case EST_Player: + { + --point->player_num; + } + break; + case EST_Android: + { + --point->android_num; + } + break; + default: + { + + } + break; + } +} + void Room::SecondRandPoint() { for (auto& pair : accountid_hash_) { Human* hum = pair.second; hum->born_point = AllocBornPoint(hum); - if (!hum->born_point) { - hum->SetX(DEFAULT_BORN_POINT_X + rand() % 100); - hum->SetY(DEFAULT_BORN_POINT_Y + rand() % 200); - } else { - hum->SetPos(hum->born_point->RandPoint()); + } + for (auto& pair : team_hash_) { + if (pair.second.size() < 2) { + continue; + } + Human* target = nullptr; + for (Human* hum : pair.second) { + if (!target) { + target = hum; + } else { + if (target->born_point) { + if (hum->born_point) { + DecBornPointHumanNum(hum->born_point, hum); + } + hum->born_point = target->born_point; + if (!hum->born_point) { + hum->SetX(DEFAULT_BORN_POINT_X + rand() % 100); + hum->SetY(DEFAULT_BORN_POINT_Y + rand() % 200); + } else { + IncBornPointHumanNum(hum->born_point, hum); + hum->SetPos(hum->born_point->RandPoint()); + } + hum->FindLocation(); + hum->RefreshView(); + grid_service.MoveHuman(hum); + } + } } - hum->FindLocation(); - hum->RefreshView(); - grid_service.MoveHuman(hum); } } diff --git a/server/gameserver/room.h b/server/gameserver/room.h index e0b307b..4c704cc 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -135,6 +135,8 @@ private: BornPoint* AllocBornPoint(Human* hum); void CreateMapObject(MetaData::MapTplThing& thing_tpl); void CreateMapSpawnPoint(MetaData::MapTplThing& thing_tpl); + void IncBornPointHumanNum(BornPoint* point, Human* hum); + void DecBornPointHumanNum(BornPoint* point, Human* hum); void SecondRandPoint(); void NotifyGameStart();