about summary refs log tree commit diff stats
path: root/tools/validator/validator.cpp
blob: 93efdc6658b11520504028da1d03343bae3ee409 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#ifndef TOOLS_UTIL_IDENTIFIERS_H_
#define TOOLS_UTIL_IDENTIFIERS_H_

#include <optional>
#include <string>
#include <utility>

#include "proto/human.pb.h"

namespace com::fourisland::lingo2_archipelago {

class RoomIdentifierLess {
 public:
  bool operator()(const RoomIdentifier& lhs, const RoomIdentifier& rhs) const {
    return std::tie(lhs.map(), lhs.name()) < std::tie(rhs.map(), rhs.name());
  }
};

class DoorIdentifierLess {
 public:
  bool operator()(const DoorIdentifier& lhs, const DoorIdentifier& rhs) const {
    return std::tie(lhs.map(), lhs.name()) < std::tie(rhs.map(), rhs.name());
  }
};

class PortIdentifierLess {
 public:
  bool operator()(const PortIdentifier& lhs, const PortIdentifier& rhs) const {
    return std::tie(lhs.map(), lhs.room(), lhs.name()) <
           std::tie(rhs.map(), rhs.room(), rhs.name());
  }
};

class PaintingIdentifierLess {
 public:
  bool operator()(const PaintingIdentifier& lhs,
                  const PaintingIdentifier& rhs) const {
    return std::tie(lhs.map(), lhs.room(), lhs.name()) <
           std::tie(rhs.map(), rhs.room(), rhs.name());
  }
};

class PanelIdentifierLess {
 public:
  bool operator()(const PanelIdentifier& lhs,
                  const PanelIdentifier& rhs) const {
    return std::tie(lhs.map(), lhs.room(), lhs.name(), lhs.answer()) <
           std::tie(rhs.map(), rhs.room(), rhs.name(), rhs.answer());
  }
};

class KeyholderIdentifierLess {
 public:
  bool operatorpre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include "validator.h"

#include <iostream>

#include "proto/human.pb.h"
#include "structs.h"
#include "util/identifiers.h"

namespace com::fourisland::lingo2_archipelago {
namespace {

class Validator {
 public:
  explicit Validator(const CollectedInfo& info) : info_(info) {}

  void Validate() const {
    for (const auto& [map_name, map_info] : info_.maps) {
      ValidateMap(map_name, map_info);
    }
    for (const auto& [room_identifier, room_info] : info_.rooms) {
      ValidateRoom(room_identifier, room_info);
    }
    for (const auto& [door_identifier, door_info] : info_.doors) {
      ValidateDoor(door_identifier, door_info);
    }
    for (const auto& [port_identifier, port_info] : info_.ports) {
      ValidatePort(port_identifier, port_info);
    }
    for (const auto& [painting_identifier, painting_info] : info_.paintings) {
      ValidatePainting(painting_identifier, painting_info);
    }
    for (const auto& [panel_identifier, panel_info] : info_.panels) {
      ValidatePanel(panel_identifier, panel_info);
    }
    for (const auto& [keyholder_identifier, keyholder_info] :
         info_.keyholders) {
      ValidateKeyholder(keyholder_identifier, keyholder_info);
    }
    for (const auto& [letter_identifier, letter_info] : info_.letters) {
      ValidateLetter(letter_identifier, letter_info);
    }
    for (const auto& [ending_name, ending_info] : info_.endings) {
      ValidateEnding(ending_name, ending_info);
    }
    for (const auto& [panel_name, panel_info] : info_.panel_names) {
      ValidatePanelName(panel_name, panel_info);
    }
    for (const auto& [prog_name, prog_info] : info_.progressives) {
      ValidateProgressive(prog_name, prog_info);
    }
    for (const auto& [group_name, group_info] : info_.door_groups) {
      ValidateDoorGroup(group_name, group_info);
    }
  }

 private:
  void ValidateMap(const std::string& map_name, const MapInfo& map_info) const {
    for (const auto& [node_path, node_info] : map_info.game_nodes) {
      if (node_info.uses > 1) {
        std::cout << "Map " << map_name << " node " << node_path
                  << " is used in multiple places." << std::endl;
      } else if (node_info.uses == 0) {
        std::cout << "Map " << map_name << " node " << node_path
                  << " is not used." << std::endl;
      }

      if (!node_info.defined) {
        std::cout << "Map " << map_name << " node " << node_path
                  << " is not defined in the game file." << std::endl;
      }
    }
  }

  void ValidateRoom(const RoomIdentifier& room_identifier,
                    const RoomInfo& room_info) const {
    if (room_info.definitions.empty()) {
      std::cout << "Room " << room_identifier.ShortDebugString()
                << " has no definition, but was referenced:" << std::endl;

      for (const DoorIdentifier& door_identifier :
           room_info.doors_referenced_by) {
        std::cout << "    DOOR " << door_identifier.ShortDebugString()
                  << std::endl;
      }

      for (const PanelIdentifier& panel_identifier :
           room_info.panels_referenced_by) {
        std::cout << "    PANEL " << panel_identifier.ShortDebugString()
                  << std::endl;
      }

      for (const HumanConnection& connection :
           room_info.connections_referenced_by) {
        std::cout << "    CONNECTION " << connection.ShortDebugString()
                  << std::endl;
      }
    } else if (room_info.definitions.size() > 1) {
      std::cout << "Room " << room_identifier.ShortDebugString()
                << " was defined multiple times." << std::endl;
    }
  }

  bool DoesDoorNeedLocationName(const HumanDoor& h_door,
                                const std::string& map_name) const {
    if (h_door.type() != DoorType::STANDARD) {
      return false;
    }

    if (h_door.keyholders_size() > 0 || h_door.endings_size() > 0 ||
        h_door.complete_at() > 0) {
      return true;
    }

    if (h_door.panels_size() > 4) {
      return true;
    }

    std::set<std::string> map_areas;
    for (const PanelIdentifier& pi : h_door.panels()) {
      auto full_pi =
          GetCompletePanelIdentifierWithoutAnswer(pi, map_name, std::nullopt);
      if (full_pi) {
        auto panel_info_it = info_.panels.find(*full_pi);
        if (panel_info_it != info_.panels.end()) {
          const PanelInfo& panel_info = panel_info_it->second;

          map_areas.insert(panel_info.map_area_name);
        }
      }
    }

    if (map_areas.size() > 1) {
      return true;
    }

    return false;
  }

  void ValidateDoor(const DoorIdentifier& door_identifier,
                    const DoorInfo& door_info) const {
    if (door_info.definitions.empty()) {
      std::cout << "Door " << door_identifier.ShortDebugString()
                << " has no definition, but was referenced:" << std::endl;

      for (const DoorIdentifier& other_door_identifier :
           door_info.doors_referenced_by) {
        std::cout << "    DOOR " << other_door_identifier.ShortDebugString()
                  << std::endl;
      }

      for (const PanelIdentifier& panel_identifier :
           door_info.panels_referenced_by) {
        std::cout << "    PANEL " << panel_identifier.ShortDebugString()
                  << std::endl;
      }

      for (const PaintingIdentifier& painting_identifier :
           door_info.paintings_referenced_by) {
        std::cout << "    PAINTING " << painting_identifier.ShortDebugString()
                  << std::endl;
      }

      for (const PortIdentifier& port_identifier :
           door_info.ports_referenced_by) {
        std::cout << "    PORT " << port_identifier.ShortDebugString()
                  << std::endl;
      }

      for (const HumanConnection& connection :
           door_info.connections_referenced_by) {
        std::cout << "    CONNECTION " << connection.ShortDebugString()
                  << std::endl;
      }

      for (const std::string& prog_name :
           door_info.progressives_referenced_by) {
        std::cout << "    PROGRESSIVE " << prog_name << std::endl;
      }

      for (const std::string& group_name :
           door_info.door_groups_referenced_by) {
        std::cout << "    DOOR GROUP " << group_name << std::endl;
      }

      if (door_info.has_id) {
        std::cout << "    An AP ID is present." << std::endl;
      }
    } else if (door_info.definitions.size() > 1) {
      std::cout << "Door " << door_identifier.ShortDebugString()
                << " was defined multiple times." << std::endl;
    }

    if (door_info.malformed_identifiers.HasAny()) {
      std::cout << "Door " << door_identifier.ShortDebugString()
                << " has malformed identifiers:" << std::endl;

      for (const PaintingIdentifier& painting_identifier :
           door_info.malformed_identifiers.paintings) {
        std::cout << "    PAINTING " << painting_identifier.ShortDebugString()
                  << std::endl;
      }

      for (const PanelIdentifier& panel_identifier :
           door_info.malformed_identifiers.panels) {
        std::cout << "    PANEL " << panel_identifier.ShortDebugString()
                  << std::endl;
      }

      for (const KeyholderIdentifier& keyholder_identifier :
           door_info.malformed_identifiers.keyholders) {
        std::cout << "    KEYHOLDER " << keyholder_identifier.ShortDebugString()
                  << std::endl;
      }
    }

    for (const HumanDoor& h_door : door_info.definitions) {
      if (DoesDoorNeedLocationName(h_door, door_identifier.map()) &&
          !h_door.has_location_name()) {
        std::cout << "Door " << door_identifier.ShortDebugString()
                  << " needs an explicit location name." << std::endl;
      }

      if (h_door.double_letters() &&
          (h_door.type() == DoorType::STANDARD ||
           h_door.type() == DoorType::LOCATION_ONLY ||
           h_door.type() == DoorType::GRAVESTONE)) {
        std::cout << "Door " << door_identifier.ShortDebugString()
                  << " is a location that depends on double_letters."
                  << std::endl;
      }

      bool needs_id = (h_door.type() != DoorType::EVENT);
      if (door_info.has_id != needs_id) {
        if (needs_id) {
          std::cout << "Door " << door_identifier.ShortDebugString()
                    << " is missing an AP ID." << std::endl;
        } else {
          std::cout << "Door " << door_identifier.ShortDebugString()
                    << " should not have an AP ID." << std::endl;
        }
      }
    }
  }

  void ValidatePort(const PortIdentifier& port_identifier,
                    const PortInfo& port_info) const {
    if (port_info.definitions.empty()) {
      std::cout << "Port " << port_identifier.ShortDebugString()
                << " has no definition, but was referenced:" << std::endl;

      for (const HumanConnection& connection :
           port_info.connections_referenced_by) {
        std::cout << "    CONNECTION " << connection.ShortDebugString()
                  << std::endl;
      }
    } else if (port_info.definitions.size() > 1) {
      std::cout << "Port " << port_identifier.ShortDebugString()
                << " was defined multiple times." << std::endl;
    }

    if (!port_info.target_connections_referenced_by.empty()) {
      for (const HumanPort& port : port_info.definitions) {
        if (port.has_required_door()) {
          std::cout << "Port " << port_identifier.ShortDebugString()
                    << " has a required door but is the target of a connection:"
                    << std::endl;

          for (const HumanConnection& connection :
               port_info.target_connections_referenced_by) {
            std::cout << "    CONNECTION " << connection.ShortDebugString()
                      << std::endl;
          }
        }
      }
    }

    for (const HumanPort& port : port_info.definitions) {
      if (!port.no_shuffle()) {
        if (!port.has_destination()) {
          std::cout << "Port " << port_identifier.ShortDebugString()
                    << " is shuffleable and missing a destination."
                    << std::endl;
        }
        if (!port.has_rotation()) {
          std::cout << "Port " << port_identifier.ShortDebugString()
                    << " is shuffleable and missing a rotation."
                    << std::endl;
        }
      }
    }
  }

  void ValidatePainting(const PaintingIdentifier& painting_identifier,
                        const PaintingInfo& painting_info) const {
    if (painting_info.definitions.empty()) {
      std::cout << "Painting " << painting_identifier.ShortDebugString()
                << " has no definition, but was referenced:" << std::endl;

      for (const DoorIdentifier& door_identifier :
           painting_info.doors_referenced_by) {
        std::cout << "    DOOR " << door_identifier.ShortDebugString()
                  << std::endl;
      }

      for (const HumanConnection& connection :
           painting_info.connections_referenced_by) {
        std::cout << "    CONNECTION " << connection.ShortDebugString()
                  << std::endl;
      }
    } else if (painting_info.definitions.size() > 1) {
      std::cout << "Painting " << painting_identifier.ShortDebugString()
                << " was defined multiple times." << std::endl;
    }

    if (!painting_info.target_connections_referenced_by.empty()) {
      for (const HumanPainting& painting : painting_info.definitions) {
        if (painting.has_required_door()) {
          std::cout << "Painting " << painting_identifier.ShortDebugString()
                    << " has a required door but is the target of a connection:"
                    << std::endl;

          for (const HumanConnection& connection :
               painting_info.target_connections_referenced_by) {
            std::cout << "    CONNECTION " << connection.ShortDebugString()
                      << std::endl;
          }
        }
      }
    }
  }

  void ValidatePanel(const PanelIdentifier& panel_identifier,
                     const PanelInfo& panel_info) const {
    if (panel_identifier.name().empty()) {
      std::cout << "Panel " << panel_identifier.ShortDebugString()
                << " has no name." << std::endl;
    }

    if (panel_info.definitions.empty()) {
      std::cout << "Panel " << panel_identifier.ShortDebugString()
                << " has no definition, but was referenced:" << std::endl;

      for (const DoorIdentifier& door_identifier :
           panel_info.doors_referenced_by) {
        std::cout << "    DOOR " << door_identifier.ShortDebugString()
                  << std::endl;
      }

      for (const HumanConnection& connection :
           panel_info.connections_referenced_by) {
        std::cout << "    CONNECTION " << connection.ShortDebugString()
                  << std::endl;
      }

      if (panel_info.has_id) {
        std::cout << "    An AP ID is present." << std::endl;
      }
    } else if (panel_info.definitions.size() > 1) {
      std::cout << "Panel " << panel_identifier.ShortDebugString()
                << " was defined multiple times." << std::endl;
    }

    for (const auto& [answer, proxy_info] : panel_info.proxies) {
      if (proxy_info.definitions.empty()) {
        std::cout << "Panel " << panel_identifier.ShortDebugString()
                  << " with answer \"" << answer
                  << "\" has no definition, but was referenced:" << std::endl;

        for (const DoorIdentifier& door_identifier :
             proxy_info.doors_referenced_by) {
          std::cout << "    DOOR " << door_identifier.ShortDebugString()
                    << std::endl;
        }

        for (const HumanConnection& connection :
             proxy_info.connections_referenced_by) {
          std::cout << "    CONNECTION " << connection.ShortDebugString()
                    << std::endl;
        }
      } else if (proxy_info.definitions.size() > 1) {
        std::cout << "Panel " << panel_identifier.ShortDebugString()
                  << " with answer \"" << answer
                  << "\" was defined multiple times." << std::endl;
      }
    }

    if (!panel_info.has_id) {
      std::cout << "Panel " << panel_identifier.ShortDebugString()
                << " is missing an AP ID." << std::endl;
    }

    if (!panel_info.target_connections_referenced_by.empty()) {
      for (const HumanPanel& panel : panel_info.definitions) {
        if (panel.has_required_door()) {
          std::cout << "Panel " << panel_identifier.ShortDebugString()
                    << " has a required door but is the target of a connection:"
                    << std::endl;

          for (const HumanConnection& connection :
               panel_info.target_connections_referenced_by) {
            std::cout << "    CONNECTION " << connection.ShortDebugString()
                      << std::endl;
          }
        }
      }
    }
  }

  void ValidateKeyholder(const KeyholderIdentifier& keyholder_identifier,
                         const KeyholderInfo& keyholder_info) const {
    if (keyholder_info.definitions.empty()) {
      std::cout << "Keyholder " << keyholder_identifier.ShortDebugString()
                << " has no definition, but was referenced:" << std::endl;

      for (const DoorIdentifier& door_identifier :
           keyholder_info.doors_referenced_by) {
        std::cout << "    DOOR " << door_identifier.ShortDebugString()
                  << std::endl;
      }

      if (keyholder_info.has_id) {
        std::cout << "    An AP ID is present." << std::endl;
      }
    } else if (keyholder_info.definitions.size() > 1) {
      std::cout << "Keyholder " << keyholder_identifier.ShortDebugString()
                << " was defined multiple times." << std::endl;
    }

    for (const HumanKeyholder& h_keyholder : keyholder_info.definitions) {
      bool needs_id = (h_keyholder.has_key());

      if (needs_id != keyholder_info.has_id) {
        if (needs_id) {
          std::cout << "Keyholder " << keyholder_identifier.ShortDebugString()
                    << " is missing an AP ID." << std::endl;
        } else {
          std::cout << "Keyholder " << keyholder_identifier.ShortDebugString()
                    << " should not have an AP ID." << std::endl;
        }
      }
    }
  }

  void ValidateLetter(const LetterIdentifier& letter_identifier,
                      const LetterInfo& letter_info) const {
    std::string letter_name = std::string(1, std::get<0>(letter_identifier)) +
                              (std::get<1>(letter_identifier) ? "2" : "1");

    if (letter_info.defined_in.empty()) {
      std::cout << "Letter " << letter_name
                << " has no definition, but was referenced:" << std::endl;

      if (letter_info.has_id) {
        std::cout << "    An AP ID is present." << std::endl;
      }
    } else if (letter_info.defined_in.size() > 1) {
      std::cout << "Letter " << letter_name
                << " was defined in multiple places:" << std::endl;

      for (const RoomIdentifier& room_identifier : letter_info.defined_in) {
        std::cout << "    " << room_identifier.ShortDebugString() << std::endl;
      }
    }

    if (!letter_info.has_id) {
      std::cout << "Letter " << letter_name << " is missing an AP ID."
                << std::endl;
    }
  }

  void ValidateEnding(const std::string& ending_name,
                      const EndingInfo& ending_info) const {
    if (ending_info.defined_in.empty()) {
      std::cout << "Ending " << ending_name
                << " has no definition, but was referenced:" << std::endl;

      for (const DoorIdentifier& door_identifier :
           ending_info.doors_referenced_by) {
        std::cout << "    DOOR " << door_identifier.ShortDebugString()
                  << std::endl;
      }

      if (ending_info.has_id) {
        std::cout << "    An AP ID is present." << std::endl;
      }
    } else if (ending_info.defined_in.size() > 1) {
      std::cout << "Ending " << ending_name
                << " was defined in multiple places:" << std::endl;

      for (const RoomIdentifier& room_identifier : ending_info.defined_in) {
        std::cout << "    " << room_identifier.ShortDebugString() << std::endl;
      }
    }

    if (!ending_info.has_id) {
      std::cout << "Ending " << ending_name << " is missing an AP ID."
                << std::endl;
    }
  }

  void ValidatePanelName(const std::string& panel_name,
                         const PanelNameInfo& panel_info) const {
    if (panel_info.panels_used_by.size() > 1) {
      std::cout << "The location name \"" << panel_name
                << "\" is used by multiple panels:" << std::endl;

      for (const PanelIdentifier& panel_identifier :
           panel_info.panels_used_by) {
        std::cout << "    PANEL " << panel_identifier.ShortDebugString()
                  << std::endl;
      }
    }
  }

  void ValidateProgressive(const std::string& prog_name,
                           const ProgressiveInfo& prog_info) const {
    if (prog_info.definitions.empty()) {
      std::cout << "Progressive \"" << prog_name
                << "\" has no definition, but was referenced:" << std::endl;

      if (prog_info.has_id) {
        std::cout << "    An AP ID is present." << std::endl;
      }
    } else if (prog_info.definitions.size() > 1) {
      std::cout << "Progressive \"" << prog_name
                << "\" has multiple definitions." << std::endl;
    }

    if (!prog_info.has_id) {
      std::cout << "Progressive \"" << prog_name << "\" is missing an AP ID."
                << std::endl;
    }
  }

  void ValidateDoorGroup(const std::string& group_name,
                         const DoorGroupInfo& group_info) const {
    if (group_info.definitions.empty()) {
      std::cout << "Door group \"" << group_name
                << "\" has no definition, but was referenced:" << std::endl;

      if (group_info.has_id) {
        std::cout << "    An AP ID is present." << std::endl;
      }
    } else if (group_info.definitions.size() > 1) {
      std::cout << "Door group \"" << group_name
                << "\" has multiple definitions." << std::endl;
    }

    if (!group_info.has_id) {
      std::cout << "Door group \"" << group_name << "\" is missing an AP ID."
                << std::endl;
    }
  }

  const CollectedInfo& info_;
};

}  // namespace

void ValidateCollectedInfo(const CollectedInfo& info) {
  Validator validator(info);
  validator.Validate();
}

}  // namespace com::fourisland::lingo2_archipelago