VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
Rounds.hpp
Go to the documentation of this file.
1#pragma once
2
7#include <cstdint>
8#include <optional>
9
10namespace VoltMod
11{
12
13/** Why a round ended, as the engine's `CSRoundEndReason` numbers it; `round_end` reports the same. */
15{
17 TerroristsWin = 9,
18 Draw = 10,
19};
20
21/**
22 * @brief `runtime.Rounds`: the running round's timer, and ending the round with the engine's own win
23 * panel and `round_end`, even with `mp_ignore_round_win_conditions` on. Team scores are not changed.
24 *
25 * @code
26 * runtime.Rounds.SetTime(45 * 60);
27 * runtime.Rounds.End(VoltMod::RoundEndReason::TerroristsWin, 5.0f);
28 * @endcode
29 *
30 * Game-thread only.
31 */
32class Rounds
33{
34public:
35 /** All three must outlive this service. */
37 : _entities(entities), _bindings(bindings), _clock(clock)
38 {}
39 Rounds(const Rounds&) = delete;
40 Rounds& operator=(const Rounds&) = delete;
41
42 /** Whether @ref End works: unsupported when the TerminateRound signature did not bind. */
43 Status Available() const;
44
45 /** End the round for @p reason; the next one starts after @p delaySeconds.
46 * @return Error::NotReady when no map is running. */
48
49 /** Sets the running round to last @p seconds from its start, whatever `mp_roundtime` says; the
50 * round timer shows it at once. The next round starts from `mp_roundtime` again.
51 * @return Error::NotReady when no map is running. */
52 Status SetTime(int seconds) const;
53
54 /** Seconds until the round timer runs out, below 0 once it has; empty when no map is running. */
55 std::optional<float> TimeLeft() const;
56
57private:
58 EntitySystem& _entities;
59 const Bindings& _bindings;
60 const Clock& _clock;
61};
62
63} // namespace VoltMod
The engine's simulation clock, read straight from IVEngineServer2::GetServerGlobals().
Definition Clock.hpp:19
runtime.Entities: finds and creates entities. Everything it returns is valid for this frame only; see...
runtime.Rounds: the running round's timer, and ending the round with the engine's own win panel and r...
Definition Rounds.hpp:33
Rounds(const Rounds &)=delete
Status SetTime(int seconds) const
Definition Rounds.cpp:45
Status End(RoundEndReason reason, float delaySeconds) const
Definition Rounds.cpp:29
std::optional< float > TimeLeft() const
Definition Rounds.cpp:56
Status Available() const
Definition Rounds.cpp:20
Rounds(EntitySystem &entities, const Bindings &bindings, const Clock &clock)
Definition Rounds.hpp:36
Rounds & operator=(const Rounds &)=delete
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::expected< void, Error > Status
Definition Result.hpp:67
RoundEndReason
Definition Rounds.hpp:15