13 const std::string raw(token);
17 if (lower ==
"@all" || lower ==
"@*")
19 return {.Kind = Kind::All};
23 return {.Kind = Kind::Me};
27 return {.Kind = Kind::NotMe};
31 return {.Kind = Kind::Team, .Team =
Team::T};
35 return {.Kind = Kind::Team, .Team =
Team::CT};
43 return {.Kind = Kind::Dead};
45 if (lower ==
"@alive")
47 return {.Kind = Kind::Alive};
49 if (lower ==
"@bot" || lower ==
"@bots")
51 return {.Kind = Kind::Bots};
53 if (lower ==
"@human" || lower ==
"@humans")
55 return {.Kind = Kind::Humans};
57 if (lower ==
"@random")
59 return {.Kind = Kind::Random};
61 if (lower ==
"@randomt")
63 return {.Kind = Kind::RandomTeam, .Team =
Team::T};
65 if (lower ==
"@randomct")
67 return {.Kind = Kind::RandomTeam, .Team =
Team::CT};
70 if (raw.size() > 1 && raw[0] ==
'#')
73 if (
auto slot =
ParseInt64(std::string_view(raw).substr(1)); slot && std::in_range<int>(*slot) && *slot >= 0)
75 return {.Kind = Kind::Slot, .Slot =
static_cast<int>(*slot)};
83 return {.Kind = Kind::SteamId, .SteamId = *
id};
90 return {.Kind = Kind::SteamId, .SteamId = *
id};
97 return {.Kind = Kind::SteamId, .SteamId = *
id};
101 return {.Kind = Kind::Name, .Needle = lower};
107 const std::function<std::size_t(std::size_t)>& randomIndex)
111 std::vector<const PlayerView*> candidates;
112 auto collect = [&](
auto&& pred) {
113 for (
const auto& p : players)
117 candidates.push_back(&p);
126 collect([](
const PlayerView&) {
return true; });
129 collect([&](
const PlayerView& p) {
return p.
Slot == callerSlot; });
132 collect([&](
const PlayerView& p) {
return p.
Slot != callerSlot; });
135 case Kind::RandomTeam:
159 auto tier = [&](
auto&& pred) {
162 return !candidates.empty();
171 if (candidates.empty())
176 auto drop = [&](
auto&& pred) { std::erase_if(candidates, pred); };
181 if (candidates.empty())
189 if (candidates.empty())
197 if (candidates.empty())
202 if (query.
Kind == Kind::Random || query.
Kind == Kind::RandomTeam)
204 std::size_t pick = randomIndex ? randomIndex(candidates.size()) % candidates.size() : 0;
205 candidates = {candidates[pick]};
212 return std::unexpected(
TargetFailure{error,
static_cast<int>(candidates.size())});
215 std::vector<int> slots;
216 slots.reserve(candidates.size());
217 for (
const auto* p : candidates)
219 slots.push_back(p->
Slot);
std::expected< std::vector< int >, TargetFailure > FilterPlayers(std::span< const PlayerView > players, const TargetQuery &query, const TargetRules &rules, int callerSlot, const std::function< std::size_t(std::size_t)> &randomIndex)