12 duels_[id] = {.challenger = id, .challenged = other};
13 challengers_[id] = id;
14 challengers_[other] = id;
15 news_.insert({id, other});
19 const auto in = challengers_.find(
id);
20 if (in == challengers_.end() || in->second ==
id) {
23 Duel& duel = duels_.at(in->second);
35 const auto in = challengers_.find(
id);
36 return in != challengers_.end() ? &duels_.at(in->second) :
nullptr;
46 const auto in = challengers_.find(
id);
47 if (in == challengers_.end()) {
50 const auto duel = duels_.find(in->second);
51 const uint32_t other = duel->second.Against(
id);
53 challengers_.erase(
id);
54 challengers_.erase(other);
55 news_.insert({id, other});
59std::vector<Duels::Duel>
Duels::Step(std::chrono::nanoseconds time) {
60 std::vector<Duel> ran_out;
61 for (
auto& [challenger, duel] : duels_) {
65 const std::chrono::nanoseconds before = duel.left;
68 if (duel.left <= std::chrono::nanoseconds::zero()) {
69 ran_out.push_back(duel);
75 if (duel.left <= std::chrono::nanoseconds::zero()) {
77 duel.left = std::chrono::nanoseconds::zero();
78 news_.insert({duel.challenger, duel.challenged});
79 }
else if (std::chrono::ceil<std::chrono::seconds>(duel.left) <
80 std::chrono::ceil<std::chrono::seconds>(before)) {
81 news_.insert({duel.challenger, duel.challenged});
84 for (
const Duel& duel : ran_out) {
uint32_t Accept(uint32_t id, Place flag)
const Duel * Of(uint32_t id) const
The player's duel, from the ask to the end, or nullptr.
uint32_t End(uint32_t id)
void Ask(uint32_t id, uint32_t other)
The player asks the other to duel. Neither may be in a duel already.
uint32_t Opponent(uint32_t id) const
Who the player's duelling, by their id, once the countdown's over, or 0.
std::vector< Duel > Step(std::chrono::nanoseconds time)
std::set< uint32_t > TakeNews()
static constexpr std::chrono::seconds kCountdown
From the yes to the duel, so that both sides are ready for it.
std::chrono::nanoseconds left
How long the ask has left, and then the countdown.
uint32_t challenger
Who asked, and who they asked, by their ids.
uint32_t Against(uint32_t id) const
The other side from the player's, by their id.
In metres from the middle of a land.