printmap.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <iostream>
  2. #include <stdexcept>
  3. #include "../strings_bank.h"
  4. #include "../serialize.h"
  5. #include "../common_types.h"
  6. #include "../common.h"
  7. #include "../random.h"
  8. #include "../grid.h"
  9. struct Feature {
  10. tag_t tag;
  11. grid::pt xy;
  12. unsigned int decay;
  13. unsigned int charges;
  14. };
  15. namespace serialize {
  16. template <>
  17. struct reader<Feature> {
  18. void read(Source& s, Feature& m) {
  19. serialize::read(s, m.tag);
  20. serialize::read(s, m.xy);
  21. serialize::read(s, m.decay);
  22. serialize::read(s, m.charges);
  23. }
  24. };
  25. };
  26. int main(int argc, char** argv) {
  27. try {
  28. grid::Map grid;
  29. std::unordered_map<grid::pt,Feature> feats;
  30. serialize::Source source(argv[1]);
  31. serialize::read(source, grid);
  32. serialize::read(source, feats);
  33. for (unsigned int y = 0; y < grid.h; ++y) {
  34. std::string z;
  35. for (unsigned int x = 0; x < grid.w; ++x) {
  36. if (feats.count(grid::pt(x, y)) != 0) {
  37. z += '*';
  38. } else if (grid.is_lowlands(x, y)) {
  39. if (grid.is_water(x, y)) {
  40. z += 'O';
  41. } else {
  42. z += 'o';
  43. }
  44. } else if (grid.is_walk(x, y)) {
  45. if (grid.is_water(x, y)) {
  46. z += '+';
  47. } else {
  48. z += '.';
  49. }
  50. } else {
  51. z += '#';
  52. }
  53. }
  54. std::cout << z << std::endl;
  55. }
  56. } catch (std::exception& e) {
  57. std::cerr << "Fatal error: " << e.what() << std::endl;
  58. return 1;
  59. } catch (...) {
  60. std::cerr << "Unknown fatal error." << std::endl;
  61. return 1;
  62. }
  63. return 0;
  64. }