victory.cc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include <iostream>
  2. #include <set>
  3. #include <algorithm>
  4. #include <stdexcept>
  5. #include "../serialize.h"
  6. #include "../common_types.h"
  7. #include "../common.h"
  8. #define __ITEMS_H
  9. namespace items {
  10. typedef std::pair<unsigned int, unsigned int> pt;
  11. struct Item {
  12. tag_t tag;
  13. pt xy;
  14. unsigned int count;
  15. Item() : xy(0, 0), count(1) {}
  16. };
  17. }
  18. namespace serialize {
  19. template <>
  20. struct reader<items::Item> {
  21. void read(Source& s, items::Item& m) {
  22. serialize::read(s, m.tag);
  23. serialize::read(s, m.xy);
  24. serialize::read(s, m.count);
  25. }
  26. };
  27. template <>
  28. struct writer<items::Item> {
  29. void write(Sink& s, const items::Item& m) {
  30. serialize::write(s, m.tag);
  31. serialize::write(s, m.xy);
  32. serialize::write(s, m.count);
  33. }
  34. };
  35. }
  36. #include "../uniques.h"
  37. #include "../nlp.h"
  38. std::string quote(const std::string& s) {
  39. std::string ret;
  40. for (unsigned char c : s) {
  41. if (c == '\\') ret += "\\\\";
  42. else if (c == '"') ret += "\\\"";
  43. else if (c <= 31) ret += " ";
  44. else ret += c;
  45. }
  46. return ret;
  47. }
  48. int main(int argc, char** argv) {
  49. try {
  50. uniques::uniques().load();
  51. auto& u = uniques::uniques();
  52. std::cout << nlp::message("{\"series\": %d, \"ts\": %d, \"locations\": [", u.series, u.placetime);
  53. bool first = true;
  54. for (const auto& i : u.data) {
  55. for (const auto& j : i.second) {
  56. if (first) {
  57. first = false;
  58. std::cout << "\n";
  59. } else {
  60. std::cout << ",\n";
  61. }
  62. std::cout << nlp::message("{\"dlev\": %d, \"dlev_offset\":[%d,%d], \"pt\": [%d,%d], \"count\": %d}",
  63. i.first.worldz, i.first.worldx, i.first.worldy,
  64. j.xy.first, j.xy.second, j.count);
  65. }
  66. }
  67. std::cout << "]}" << std::endl;
  68. } catch (std::exception& e) {
  69. std::cerr << "Fatal error: " << e.what() << std::endl;
  70. return 1;
  71. } catch (...) {
  72. std::cerr << "Unknown fatal error." << std::endl;
  73. return 1;
  74. }
  75. return 0;
  76. }