VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
Targeting.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <cstdint>
5#include <expected>
6#include <functional>
7#include <span>
8#include <string>
9#include <string_view>
10#include <vector>
11
12namespace VoltMod
13{
14
15/** Which target classes a command permits for one Target argument. */
17{
18 bool AllowMultiple = false; ///< permit selectors (@all/@t/...) that match more than one player
19 bool AllowDead = true;
20 bool AllowBots = true;
21};
22
23enum class TargetError
24{
25 NoMatch,
26 Immune, ///< matches existed, but the policy blocked all of them
27 Ambiguous, ///< a name fragment matched more than one player
28 MultiNotAllowed, ///< a multi-selector was used where the command takes a single target
31};
32
33/** Why a resolution failed; Count carries the match count for Ambiguous messages. */
39
40enum class TargetKind
41{
42 All,
43 Me,
44 NotMe,
45 Team, ///< uses TargetQuery::Team
46 Dead,
47 Alive,
48 Bots,
49 Humans,
50 Random,
51 RandomTeam, ///< uses TargetQuery::Team
52 Slot,
53 SteamId,
54 Name,
55};
56
57/** Parsed form of one target token. */
59{
62 int Slot = -1;
64 std::string Needle; ///< lowercased name fragment for TargetKind::Name
65};
66
67TargetQuery ParseTargetToken(std::string_view token);
68
69/** Engine-free snapshot of one connected player, for @ref FilterPlayers. */
71{
72 int Slot = -1;
74 std::string Name;
76 bool Alive = false;
77 bool Bot = false;
78 bool Targetable = true; ///< policy verdict, precomputed by the caller
79};
80
81/** The slots of @p players that match @p query under @p rules; random kinds pick one through
82 * @p randomIndex(count). A failure says why the matches were rejected, so the caller can reply. */
83std::expected<std::vector<int>, TargetFailure> FilterPlayers(
84 std::span<const PlayerView> players, const TargetQuery& query, const TargetRules& rules, int callerSlot,
85 const std::function<std::size_t(std::size_t)>& randomIndex = {});
86
87} // namespace VoltMod
Static utilities for converting between SteamID formats (64-bit, SteamID2, SteamID3).
Definition SteamId.hpp:12
@ RandomTeam
uses TargetQuery::Team
TargetQuery ParseTargetToken(std::string_view token)
Definition Targeting.cpp:11
@ Immune
The target outranks the caller; a Denied that names the target, not the verb.
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
@ Ambiguous
a name fragment matched more than one player
@ MultiNotAllowed
a multi-selector was used where the command takes a single target
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)
One failure: a code to branch on, text for the log, and an optional translation key.
Definition Result.hpp:42
bool Targetable
policy verdict, precomputed by the caller
Definition Targeting.hpp:78
std::string Needle
lowercased name fragment for TargetKind::Name
Definition Targeting.hpp:64
bool AllowMultiple
permit selectors (@all/@t/...) that match more than one player
Definition Targeting.hpp:18