diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index dfd38cc..e2c92ec 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -1547,64 +1547,24 @@ void Room::DecBornPointHumanNum(BornPoint* point, Human* hum) void Room::SecondRandPoint() { - for (auto& pair : accountid_hash_) { - Human* hum = pair.second; - hum->born_point = AllocBornPoint(hum); - } - for (auto& pair : team_hash_) { - 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) { - IncBornPointHumanNum(hum->born_point, hum); - } - } - } //end if - 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()); - } - if (!a8::HasBitFlag(hum->status, HS_Disable)) { - hum->FindLocation(); - hum->RefreshView(); - grid_service->MoveHuman(hum); - } - } - } - if (room_type_ == RT_NewBrid) { - for (auto& pair : accountid_hash_) { - Human* hum = pair.second; - BornPoint* newbie_point = GetBornPoint(newbie_born_point_uniid_); - if (newbie_point && hum->born_point != newbie_point) { - if (hum->born_point) { - DecBornPointHumanNum(hum->born_point, hum); - } - hum->born_point = newbie_point; - if (hum->born_point) { - IncBornPointHumanNum(hum->born_point, hum); - hum->SetPos(hum->born_point->RandPoint()); - } - hum->FindLocation(); - hum->RefreshView(); - grid_service->MoveHuman(hum); - } - break; - } - } #ifdef DEBUG CheckPartObjects(); #endif for (auto& pair : accountid_hash_) { - if (room_type_ == RT_MidBrid) { + Human* hum = pair.second; + hum->born_point = AllocBornPoint(hum); + } + CombineTeamBornPoint(); + if (room_type_ == RT_NewBrid) { + BornPoint* newbie_point = GetBornPoint(newbie_born_point_uniid_); + if (newbie_point && first_newbie_) { + ForceSetBornPoint(first_newbie_, newbie_point); + } else { + abort(); + } + } + if (room_type_ == RT_MidBrid) { + for (auto& pair : accountid_hash_) { pair.second->on_grid_chg = std::bind(&Room::OnHumanGridChg, this, std::placeholders::_1); @@ -2444,3 +2404,53 @@ void Room::RemoveFromLaterAddHash(RoomEntity* entity) { later_add_hash_.erase(entity->entity_uniid); } + +void Room::CombineTeamBornPoint() +{ + for (auto& pair : team_hash_) { + 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) { + IncBornPointHumanNum(hum->born_point, hum); + } + } + } //end if + 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()); + } + if (!a8::HasBitFlag(hum->status, HS_Disable)) { + hum->FindLocation(); + hum->RefreshView(); + grid_service->MoveHuman(hum); + } + } + } +} + +void Room::ForceSetBornPoint(Human* hum, BornPoint* born_point) +{ + if (born_point && hum->born_point != born_point) { + if (hum->born_point) { + DecBornPointHumanNum(hum->born_point, hum); + } + hum->born_point = born_point; + if (hum->born_point) { + IncBornPointHumanNum(hum->born_point, hum); + hum->SetPos(hum->born_point->RandPoint()); + } + hum->FindLocation(); + hum->RefreshView(); + grid_service->MoveHuman(hum); + } +} diff --git a/server/gameserver/room.h b/server/gameserver/room.h index eef91f0..8b4931a 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -176,6 +176,8 @@ private: void RemoveFromLaterAddHash(RoomEntity* entity); void AddPlayerPostProc(Player* hum); + void CombineTeamBornPoint(); + void ForceSetBornPoint(Human* hum, BornPoint* born_point); #ifdef DEBUG void InitDebugInfo();