galaxy.h 3.6 KB

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