Small Team Creation Fixes (#5479)

- Add additional explanation for team creation
- error message if team creation fails because team already exists

fixes #5466
This commit is contained in:
x12xx12x 2023-03-27 00:25:54 +02:00 committed by GitHub
parent fddbf65e28
commit ceaebd00d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -12292,7 +12292,7 @@ end
Type = "cTeam", Type = "cTeam",
}, },
}, },
Notes = "Registers a new team. Returns the {{cTeam}} instance, nil on error.", Notes = "Registers a new team. Returns the {{cTeam}} instance, nil on error. For example if the team already exists.",
}, },
RemoveObjective = RemoveObjective =
{ {

View File

@ -361,11 +361,15 @@ cTeam * cScoreboard::RegisterTeam(
const AString & a_Prefix, const AString & a_Suffix const AString & a_Prefix, const AString & a_Suffix
) )
{ {
cTeam Team(a_Name, a_DisplayName, a_Prefix, a_Suffix); auto [TeamIterator, TeamExists] = m_Teams.try_emplace(a_Name, a_Name, a_DisplayName, a_Prefix, a_Suffix);
std::pair<cTeamMap::iterator, bool> Status = m_Teams.insert(cNamedTeam(a_Name, Team)); if (!TeamExists && GetTeam(a_Name))
{
LOGWARNING("Tried to register a team that already exists: %s", a_Name.c_str());
return nullptr;
}
return Status.second ? &Status.first->second : nullptr; return &TeamIterator->second;
} }