summary refs log tree commit diff stats
path: root/vendor
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-05-04 10:50:15 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-05-09 17:59:13 -0400
commit893dbf8a235db2b4f1fafacf90290b0821f0048c (patch)
tree4e224187fbaae891c4ddfa5f38c7f8eae11f06e3 /vendor
parentff99cefc647f9215ad1cdc9f408c9fc655b45706 (diff)
downloadtherapy-893dbf8a235db2b4f1fafacf90290b0821f0048c.tar.gz
therapy-893dbf8a235db2b4f1fafacf90290b0821f0048c.tar.bz2
therapy-893dbf8a235db2b4f1fafacf90290b0821f0048c.zip
Recursively handle ferried bodies
PonderingSystem now recursively ticks bodies, starting with unferried bodies at the top level, and recursively ticking their passengers. This fixes the second issue described in 8f1c4f1 -- that passengers may be ticked before their ferries, causing it to use out-of-date information about the ferry's location.
Diffstat (limited to 'vendor')
0 files changed, 0 insertions, 0 deletions
7'>97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
#include "ids_yaml_format.h"

#include <yaml-cpp/yaml.h>

#include <fstream>
#include <functional>

namespace com::fourisland::lingo2_archipelago {
namespace {

template <typename T>
void OperateOnSortedMap(
    const T& map, std::function<void(const std::string& name,
                                     const typename T::mapped_type& value)>
                      callback) {
  std::vector<std::string> names;
  for (const auto& it : map) {
    names.push_back(it.first);
  }

  std::sort(names.begin(), names.end());

  for (const std::string& name : names) {
    callback(name, map.at(name));
  }
}

}  // namespace

IdMappings ReadIdsFromYaml(const std::string& filename) {
  IdMappings result;

  YAML::Node document = YAML::LoadFile(filename);

  if (document["maps"]) {
    for (const auto& map_it : document["maps"]) {
      IdMappings::MapIds& map_ids =
          (*result.mutable_maps())[map_it.first.as<std::string>()];

      if (map_it.second["rooms"]) {
        for (const auto& room_it : map_it.second["rooms"]) {
          IdMappings::RoomIds& room_ids =
              (*map_ids.mutable_rooms())[room_it.first.as<std::string>()];

          if (room_it.second["panels"]) {
            for (const auto& panel_it : room_it.second["panels"]) {
              (*room_ids.mutable_panels())[panel_it.first.as<std::string>()] =
                  panel_it.second.as<uint64_t>();
            }
          }

          if (room_it.second["masteries"]) {
            for (const auto& mastery_it : room_it.second["masteries"]) {
              (*room_ids
                    .mutable_masteries())[mastery_it.first.as<std::string>()] =
                  mastery_it.second.as<uint64_t>();
            }
          }

          if (room_it.second["keyholders"]) {
            for (const auto& keyholder_it : room_it.second["keyholders"]) {
              (*room_ids.mutable_keyholders())[keyholder_it.first
                                                   .as<std::string>()] =
                  keyholder_it.second.as<uint64_t>();
            }
          }
        }
      }

      if (map_it.second["doors"]) {
        for (const auto& door_it : map_it.second["doors"]) {
          (*map_ids.mutable_doors())[door_it.first.as<std::string>()] =
              door_it.second.as<uint64_t>();
        }
      }
    }
  }

  if (document["letters"]) {
    for (const auto& letter_it : document["letters"]) {
      (*result.mutable_letters())[letter_it.first.as<std::string>()] =
          letter_it.second.as<uint64_t>();
    }
  }

  if (document["endings"]) {
    for (const auto& ending_it : document["endings"]) {
      (*result.mutable_endings())[ending_it.first.as<std::string>()] =
          ending_it.second.as<uint64_t>();
    }
  }

  if (document["special"]) {
    for (const auto& special_it : document["special"]) {
      (*result.mutable_special())[special_it.first.as<std::string>()] =
          special_it.second.as<uint64_t>();
    }
  }

  if (document["progressives"]) {
    for (const auto& prog_it : document["progressives"]) {
      (*result.mutable_progressives())[prog_it.first.as<std::string>()] =
          prog_it.second.as<uint64_t>();
    }
  }

  if (document["door_groups"]) {
    for (const auto& group_it : document["door_groups"]) {
      (*result.mutable_door_groups())[group_it.first.as<std::string>()] =
          group_it.second.as<uint64_t>();
    }
  }

  return result;
}

void WriteIdsAsYaml(const IdMappings& ids, const std::string& filename) {
  YAML::Node result;

  OperateOnSortedMap(ids.maps(), [&result](const std::string& map_name,
                                           const IdMappings::MapIds& map_ids) {
    YAML::Node map_node;

    OperateOnSortedMap(
        map_ids.rooms(), [&map_node](const std::string& room_name,
                                     const IdMappings::RoomIds& room_ids) {
          YAML::Node room_node;

          OperateOnSortedMap(
              room_ids.panels(),
              [&room_node](const std::string& panel_name, uint64_t panel_id) {
                room_node["panels"][panel_name] = panel_id;
              });

          OperateOnSortedMap(room_ids.masteries(),
                             [&room_node](const std::string& mastery_name,
                                          uint64_t mastery_id) {
                               room_node["masteries"][mastery_name] =
                                   mastery_id;
                             });

          OperateOnSortedMap(room_ids.keyholders(),
                             [&room_node](const std::string& keyholder_name,
                                          uint64_t keyholder_id) {
                               room_node["keyholders"][keyholder_name] =
                                   keyholder_id;
                             });

          map_node["rooms"][room_name] = std::move(room_node);
        });

    OperateOnSortedMap(
        map_ids.doors(),
        [&map_node](const std::string& door_name, uint64_t door_id) {
          map_node["doors"][door_name] = door_id;
        });

    result["maps"][map_name] = std::move(map_node);
  });

  OperateOnSortedMap(ids.letters(), [&result](const std::string& letter_name,
                                              uint64_t letter_id) {
    result["letters"][letter_name] = letter_id;
  });

  OperateOnSortedMap(ids.endings(), [&result](const std::string& ending_name,
                                              uint64_t ending_id) {
    result["endings"][ending_name] = ending_id;
  });

  OperateOnSortedMap(ids.special(), [&result](const std::string& special_name,
                                              uint64_t special_id) {
    result["special"][special_name] = special_id;
  });

  OperateOnSortedMap(ids.progressives(),
                     [&result](const std::string& prog_name, uint64_t prog_id) {
                       result["progressives"][prog_name] = prog_id;
                     });

  OperateOnSortedMap(ids.door_groups(), [&result](const std::string& group_name,
                                                  uint64_t group_id) {
    result["door_groups"][group_name] = group_id;
  });

  std::ofstream output_stream(filename);
  output_stream << result << std::endl;
}

}  // namespace com::fourisland::lingo2_archipelago