nanoMMO 0.97.8Test coverage / Every file / bot/factions.cc

Created: 2026-11-26 01:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bot/factions.cc
Line
Count
Source
1
#include "bot/factions.h"
2
3
#include <algorithm>
4
#include <cstdint>
5
#include <iterator>
6
#include <optional>
7
8
#include "terrain/lands.h"
9
10
namespace nanommo {
11
12
301
uint32_t FactionFor(const Content& content, uint32_t seed) {
13
301
  if (content.factions.empty()) {
14
1
    return 0;
15
1
  }
16
300
  const auto picked =
17
300
      std::next(content.factions.begin(), seed % content.factions.size());
18
300
  return picked->first;
19
301
}
20
21
std::optional<Errand> Oath(const Content& content, uint32_t faction,
22
4
                           const protocol::World& seen, int land) {
23
4
  const auto found = content.factions.find(faction);
24
4
  if (found == content.factions.end()) {
25
1
    return std::nullopt;
26
1
  }
27
3
  const uint32_t kind = found->second.herald();
28
3
  const auto herald =
29
3
      std::ranges::find(seen.npcs(), kind, &protocol::Npc::kind);
30
3
  if (herald != seen.npcs().end()) {
31
1
    return Errand{.kind = Errand::Kind::kSwear,
32
1
                  .x = herald->x(),
33
1
                  .z = herald->z(),
34
1
                  .herald = herald->id()};
35
1
  }
36
  // Not in sight yet, as NPCs come once a second, and only those near.
37
19
  
for (const npcs::Spawn& spawn : content.npcs.spawns)2
{
38
19
    if (spawn.kind() == kind && 
LandNamed(spawn.land()) == land2
) {
39
1
      return Errand{
40
1
          .kind = Errand::Kind::kSwear, .x = spawn.x(), .z = spawn.z()};
41
1
    }
42
19
  }
43
1
  return std::nullopt;
44
2
}
45
46
2
bool Sworn(const protocol::World& seen) {
47
2
  return std::ranges::any_of(
48
3
      seen.players(), [&seen](const protocol::Player& player) {
49
3
        return player.id() == seen.you() && 
player.faction() != 02
;
50
3
      });
51
2
}
52
53
}  // namespace nanommo