From 0f3c154067bbb83146c7faecd6b57ccf056b5c3b Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 17 Aug 2023 14:18:02 +0800 Subject: [PATCH] 1 --- server/gameserver/human.h | 1 + server/gameserver/incubator.cc | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 4c610c42..a23905a5 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -99,6 +99,7 @@ class Human : public Creature a8::XTimerWp revive_timer; long long dead_frameno = 0; long long real_dead_frameno = 0; + int sort_id = 0; Weapon default_weapon; diff --git a/server/gameserver/incubator.cc b/server/gameserver/incubator.cc index bb7b361b..1c7c119c 100644 --- a/server/gameserver/incubator.cc +++ b/server/gameserver/incubator.cc @@ -564,12 +564,15 @@ void Incubator::Rearrangement() std::vector teams4; { std::map team_num_hash; + int i = 0; for (auto hum : hold_humans_) { if (team_num_hash.find(hum->team_id) != team_num_hash.end()) { ++team_num_hash[hum->team_id]; } else { team_num_hash[hum->team_id]; } + hum->sort_id = i; + ++i; } for (auto& pair : team_num_hash) { if (pair.second > 1) { @@ -597,4 +600,25 @@ void Incubator::Rearrangement() } else if (!teams2.empty()) { team_id = teams2.at(rand() % teams2.size()); } + if (team_id) { + for (auto hum : hold_humans_) { + if (hum->team_id == team_id) { + hum->sort_id = 999999; + } + } + std::sort(hold_humans_.begin(), hold_humans_.end(), + [] (Human* a, Human* b) -> bool + { + return a->sort_id < b->sort_id; + }); + } +#ifdef DEBUG + { + std::string data = "Rearrangement "; + for (auto hum : hold_humans_) { + data += a8::XValue(hum->team_id) + ","; + } + a8::XPrintf("%s\n", {data}); + } +#endif }