galaxy.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #ifndef GALAXY_H
  2. #define GALAXY_H
  3. #include <array>
  4. #include <cstdint>
  5. #include <iostream>
  6. #include <ostream>
  7. #include <regex>
  8. #include <set>
  9. #include <stdexcept>
  10. #include <string>
  11. #include <vector>
  12. #include "buysell.h"
  13. #include "yaml-cpp/yaml.h"
  14. // #define MAX_WARPS 6
  15. typedef uint16_t sector_type;
  16. struct sector_warps {
  17. sector_type sector; // Yes, for debug
  18. // std::set<sector_type> warps; // possibly
  19. std::set<sector_type> warps;
  20. // sector_type warps[MAX_WARPS];
  21. // ports
  22. // planets
  23. // ctor that zeros everything out?
  24. sector_warps();
  25. sector_warps(sector_type, std::set<sector_type>);
  26. void add(sector_type sector);
  27. // add() that adds warp to end of warps?
  28. friend std::ostream& operator<<(std::ostream& os, const sector_warps& warps);
  29. // bool operator==(const sector_warps& rhs) const;
  30. // void sort(void);
  31. };
  32. /**
  33. * Find possible trades with these two port types
  34. *
  35. * 0 = NONE
  36. * 1 = GOOD OE trade pair
  37. * 2 = OK trade pair
  38. * 3 = FAIR (one buys, one sells)
  39. *
  40. * This will probably be expanded in the future to return:
  41. * What port(s) to trade with. (pos, return top 2)
  42. *
  43. * @param port1
  44. * @param port2
  45. * @return int
  46. */
  47. // int trade_type(port_type port1, port_type port2);
  48. enum trade_types {
  49. NONE,
  50. BEST, // OE PAIR
  51. OK, // PAIR
  52. FAIR_E, // BS E
  53. FAIR_O, // BS O
  54. FAIR_F, // BS F
  55. };
  56. struct trade_type_result {
  57. trade_types type;
  58. buysell trades;
  59. };
  60. // trade_type_result trade_type_info(port_type port1, port_type port2);
  61. struct port_pair_type {
  62. int type;
  63. buysell trades;
  64. sector_type s1, s2;
  65. };
  66. struct port {
  67. sector_type sector;
  68. uint8_t type;
  69. uint16_t amount[3];
  70. uint8_t percent[3];
  71. bool unknown(void);
  72. // port();
  73. friend std::ostream& operator<<(std::ostream& os, const port& p);
  74. };
  75. struct port parse_portcim(const std::string line);
  76. // store density scan information in galaxy
  77. struct density {
  78. sector_type sector;
  79. uint16_t density;
  80. uint16_t warps;
  81. uint16_t navhaz;
  82. bool anomaly;
  83. bool known;
  84. friend bool operator==(const struct density lhs, const struct density rhs);
  85. };
  86. class density_scan {
  87. public:
  88. sector_type sector;
  89. std::array<density, 6> d;
  90. density_scan();
  91. // resets the scan with a new sector
  92. void reset(sector_type sector);
  93. void add_scan(density d);
  94. density find(sector_type sector);
  95. //private:
  96. int pos;
  97. };
  98. // SPECIAL = 0
  99. // STARDOCK = 9
  100. class Galaxy {
  101. public:
  102. Galaxy();
  103. ~Galaxy();
  104. void reset(void);
  105. YAML::Node config;
  106. YAML::Node meta;
  107. int burnt_percent;
  108. density_scan dscan;
  109. // warps;
  110. // ports;
  111. std::map<sector_type, port> ports;
  112. std::map<sector_type, sector_warps> warps;
  113. void add_warp(sector_warps);
  114. void add_port(sector_type sector, int port_class);
  115. void add_port(port);
  116. void save(void);
  117. void load(void);
  118. sector_type find_nearest_unexplored(sector_type sector);
  119. std::vector<port_pair_type> find_best_trades(void);
  120. std::vector<port_pair_type> find_trades(sector_type sector,
  121. bool highest = true);
  122. trade_type_result trade_type_info(sector_type port1, sector_type port2,
  123. int burnt_percent = 20);
  124. void sort_port_pair_type(std::vector<port_pair_type>& pptv);
  125. port_pair_type find_closest(int sector);
  126. port_pair_type find_closest_trade(int sector, int lowest_trade_type,
  127. int burnt_percent = 20);
  128. char game;
  129. std::string username;
  130. };
  131. #endif