修复队伍合并问题
This commit is contained in:
parent
6ad1f8a7ea
commit
92d8dcbd95
@ -1207,30 +1207,69 @@ void Room::CombineTeam()
|
||||
std::map<int, size_t> need_combine_teams;
|
||||
std::map<int, size_t> need_combine_teams_copy;
|
||||
|
||||
int first_team_id = 0;
|
||||
int total_count = 0;
|
||||
for (auto& pair : team_hash_) {
|
||||
for (Human* hum : pair.second) {
|
||||
if (hum->auto_fill && !hum->team_uuid.empty()) {
|
||||
first_team_id = pair.first;
|
||||
need_combine_teams[pair.first] = pair.second.size();
|
||||
total_count += pair.second.size();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (total_count <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
int first_team_num = 4;
|
||||
switch (total_count) {
|
||||
case 3:
|
||||
{
|
||||
first_team_num = 2;
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
first_team_num = 2;
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
first_team_num = 3;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
first_team_num = 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
need_combine_teams_copy = need_combine_teams;
|
||||
bool combine_ok = false;
|
||||
int try_count = 0;
|
||||
do {
|
||||
combine_ok = false;
|
||||
for (auto& pair1 : need_combine_teams) {
|
||||
bool combine_ok = false;
|
||||
for (auto& pair2 : need_combine_teams_copy) {
|
||||
if (pair1.first != pair2.first) {
|
||||
if (pair1.second + pair2.second <= MAX_TEAM_NUM) {
|
||||
int team_id1 = pair1.first;
|
||||
int team_id2 = pair2.first;
|
||||
|
||||
if (team_id2 == first_team_id) {
|
||||
continue;
|
||||
}
|
||||
if (team_id1 == first_team_id) {
|
||||
if (pair1.second + pair2.second > first_team_num) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (team_id1 != team_id2) {
|
||||
if (pair1.second + pair2.second <= MAX_TEAM_NUM) {
|
||||
{
|
||||
std::set<Human*>& team1_members = team_hash_[team_id1];
|
||||
std::set<Human*>& team2_members = team_hash_[team_id2];
|
||||
if (pair1.second > pair2.second) {
|
||||
if (pair1.first == first_team_id || pair1.second >= pair2.second) {
|
||||
for (Human* hum : team2_members) {
|
||||
hum->team_id = team_id1;
|
||||
hum->team_members = &team1_members;
|
||||
@ -1247,10 +1286,30 @@ void Room::CombineTeam()
|
||||
}
|
||||
}
|
||||
|
||||
if (first_team_id == team_id1) {
|
||||
if (pair1.second + pair2.second >= first_team_num) {
|
||||
need_combine_teams.erase(team_id1);
|
||||
need_combine_teams.erase(team_id2);
|
||||
need_combine_teams_copy.erase(team_id1);
|
||||
}
|
||||
need_combine_teams.erase(team_id2);
|
||||
need_combine_teams_copy.erase(team_id2);
|
||||
} else {
|
||||
if (pair1.second >= pair2.second) {
|
||||
need_combine_teams.erase(team_id2);
|
||||
need_combine_teams_copy.erase(team_id2);
|
||||
if (pair1.second + pair2.second >= MAX_TEAM_NUM) {
|
||||
need_combine_teams.erase(team_id1);
|
||||
need_combine_teams_copy.erase(team_id1);
|
||||
}
|
||||
} else {
|
||||
need_combine_teams.erase(team_id1);
|
||||
need_combine_teams_copy.erase(team_id1);
|
||||
if (pair1.second + pair2.second >= MAX_TEAM_NUM) {
|
||||
need_combine_teams.erase(team_id2);
|
||||
need_combine_teams_copy.erase(team_id2);
|
||||
}
|
||||
}
|
||||
}
|
||||
combine_ok = true;
|
||||
break;
|
||||
}
|
||||
@ -1260,7 +1319,7 @@ void Room::CombineTeam()
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (combine_ok);
|
||||
} while (++try_count < 20);
|
||||
}
|
||||
|
||||
void Room::InitAirDrop()
|
||||
|
Loading…
x
Reference in New Issue
Block a user