|
@@ -10,8 +10,8 @@
|
|
|
#include <string>
|
|
|
|
|
|
#include "config.h"
|
|
|
-#include "logging.h"
|
|
|
#include "json.hpp"
|
|
|
+#include "logging.h"
|
|
|
using json = nlohmann::json;
|
|
|
|
|
|
// c++ default exceptions list
|
|
@@ -301,7 +301,7 @@ void Galaxy::load(void) {
|
|
|
json data;
|
|
|
{
|
|
|
std::ifstream fin(filename);
|
|
|
- data = json::parse(fin);
|
|
|
+ data = json::parse(fin);
|
|
|
}
|
|
|
// YAML::Node data = YAML::LoadFile(filename);
|
|
|
|
|
@@ -320,9 +320,9 @@ void Galaxy::load(void) {
|
|
|
}
|
|
|
if (data.contains("ports")) {
|
|
|
// const json &ports = data["ports"];
|
|
|
- for (auto const &port_iter : data["ports"].items() ) {
|
|
|
+ for (auto const &port_iter : data["ports"].items()) {
|
|
|
port p;
|
|
|
- p.sector = sstoi(port_iter.key()); // first.as<int>();
|
|
|
+ p.sector = sstoi(port_iter.key()); // first.as<int>();
|
|
|
p.type = port_iter.value()["class"].get<int>();
|
|
|
int x;
|
|
|
if (p.type == 0) {
|
|
@@ -387,12 +387,35 @@ void Galaxy::save(void) {
|
|
|
std::ofstream fout(filename);
|
|
|
|
|
|
BUGZ_LOG(fatal) << "save: " << filename;
|
|
|
- int depth = 0;
|
|
|
- std::string depth_spacer;
|
|
|
+ // int depth = 0;
|
|
|
+ // std::string depth_spacer;
|
|
|
|
|
|
meta["save_to"] = filename;
|
|
|
meta["save_time"] = time_t_now(); // time_t
|
|
|
|
|
|
+ // For now, we'll delete this manually.
|
|
|
+ // FUTURE: delete all keys starting with _.
|
|
|
+
|
|
|
+ if (meta.contains("density")) {
|
|
|
+ meta.erase("density");
|
|
|
+ }
|
|
|
+
|
|
|
+ // clean meta data
|
|
|
+ {
|
|
|
+ // build vector of things to delete, don't invalidate your iterator. (UB)
|
|
|
+ std::vector<std::string> to_delete;
|
|
|
+ for (auto m : meta.items()) {
|
|
|
+ if (m.key()[0] == '_') {
|
|
|
+ to_delete.push_back(m.key());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (auto key : to_delete) {
|
|
|
+ BUGZ_LOG(fatal) << "erasing meta key: [" << m.key() << "]";
|
|
|
+ meta.erase(m.key());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/* // testing sequence code
|
|
|
meta["sequence"]["part"].push_back(1);
|
|
|
meta["sequence"]["part"].push_back(2);
|
|
@@ -404,7 +427,6 @@ void Galaxy::save(void) {
|
|
|
output["meta"] = meta;
|
|
|
output["config"] = config;
|
|
|
|
|
|
-
|
|
|
BUGZ_LOG(trace) << "YAML meta: " << meta.size();
|
|
|
// yaml_out(fout, depth, meta);
|
|
|
|
|
@@ -412,13 +434,10 @@ void Galaxy::save(void) {
|
|
|
|
|
|
BUGZ_LOG(trace) << "YAML warps: " << warps.size();
|
|
|
|
|
|
-
|
|
|
-
|
|
|
// in config, I usually switch to doing flow instead. I'll keep this like
|
|
|
// this for now.
|
|
|
// yaml_out(fout, depth, config);
|
|
|
|
|
|
-
|
|
|
for (auto const &warp : warps) {
|
|
|
// fout << depth_spacer << warp.first << ": [";
|
|
|
// bool first = true;
|
|
@@ -440,79 +459,29 @@ void Galaxy::save(void) {
|
|
|
BUGZ_LOG(trace) << "YAML ports: " << ports.size();
|
|
|
// fout << "ports:" << std::endl;
|
|
|
|
|
|
- /*
|
|
|
- When saving to yaml, my sector_type is like char. So, it wants
|
|
|
- to save the values as a character. Cast to int.
|
|
|
- */
|
|
|
for (auto const &port : ports) {
|
|
|
std::string port_text = std::to_string(port.first);
|
|
|
output["ports"][port_text]["class"] = (int)port.second.type;
|
|
|
- /*
|
|
|
- fout << depth_spacer << port.second.sector
|
|
|
- << ": {class: " << (int)port.second.type;
|
|
|
-
|
|
|
- if (port.second.type == 0) {
|
|
|
- fout << "}" << std::endl;
|
|
|
- } else {
|
|
|
- */
|
|
|
- if (port.second.type != 0) {
|
|
|
+ if (port.second.type != 0) {
|
|
|
// write out the rest of the information
|
|
|
- // output["ports"][port.first]["amount"] = json::array{port.second.amount[0], port.second.amount[1], port.second.aount[2]};
|
|
|
+ // output["ports"][port.first]["amount"] =
|
|
|
+ // json::array{port.second.amount[0], port.second.amount[1],
|
|
|
+ // port.second.aount[2]};
|
|
|
for (int x = 0; x < 3; x++) {
|
|
|
// output["ports"][port.first]["amount"][x] = port.second.amount[x];
|
|
|
- output["ports"][port_text]["amount"].push_back(port.second.amount[x] );
|
|
|
- }
|
|
|
- /*
|
|
|
- fout << ", amount: [";
|
|
|
- for (int x = 0; x < 3; x++) {
|
|
|
- fout << port.second.amount[x];
|
|
|
- if (x != 2) fout << ", ";
|
|
|
+ output["ports"][port_text]["amount"].push_back(port.second.amount[x]);
|
|
|
}
|
|
|
- fout << "], pct: [";
|
|
|
+ // output["ports"][port.first]["pct"] =
|
|
|
+ // json::array{port.second.percent[0], port.second.percent[1],
|
|
|
+ // port.second.percent[2]};
|
|
|
for (int x = 0; x < 3; x++) {
|
|
|
- fout << (int)port.second.percent[x];
|
|
|
- if (x != 2) fout << ", ";
|
|
|
+ // output["ports"][port.first]["pct"][x] = port.second.percent[x];
|
|
|
+ output["ports"][port_text]["pct"].push_back(port.second.percent[x]);
|
|
|
}
|
|
|
- fout << "]}" << std::endl;
|
|
|
- */
|
|
|
- // output["ports"][port.first]["pct"] = json::array{port.second.percent[0], port.second.percent[1], port.second.percent[2]};
|
|
|
- for (int x = 0; x < 3; x++) {
|
|
|
- // output["ports"][port.first]["pct"][x] = port.second.percent[x];
|
|
|
- output["ports"][port_text]["pct"].push_back( port.second.percent[x] );
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // the big data structures later on are the ones I really need to optimize
|
|
|
- // here. Writing out 20 lines isn't what is killing us!
|
|
|
-
|
|
|
- /*
|
|
|
- for (auto const & meta_data : meta ) {
|
|
|
- std::cerr << "key: " << meta_data.first << std::endl;
|
|
|
-
|
|
|
- if (meta_data.second.Type() == YAML::NodeType::Scalar) {
|
|
|
- fout << depth_spacer << meta_data.first << ": " << meta_data.second <<
|
|
|
- std::endl; } else {
|
|
|
- // nested structure
|
|
|
- std::cerr << "Nested: " << meta_data.first << std::endl;
|
|
|
- fout << depth_spacer << meta_data.first << ":" << std::endl;
|
|
|
- ++depth;
|
|
|
- depth_spacer.assign(depth *2, ' ');
|
|
|
- for (auto const &nested : meta_data.second) {
|
|
|
- if (nested.second.Type() == YAML::NodeType::Scalar) {
|
|
|
- fout << depth_spacer << nested.first << ": " << nested.second <<
|
|
|
- std::endl; } else { std::cerr << "double-Nested meta structure under key: " <<
|
|
|
- nested.first << std::endl;
|
|
|
- }
|
|
|
- }
|
|
|
- --depth;
|
|
|
- depth_spacer.assign(depth * 2, ' ');
|
|
|
}
|
|
|
}
|
|
|
- */
|
|
|
-
|
|
|
- fout << output;
|
|
|
|
|
|
+ fout << output;
|
|
|
}
|
|
|
|
|
|
std::vector<port_pair_type> Galaxy::find_trades(sector_type sector,
|
|
@@ -578,7 +547,7 @@ void Galaxy::sort_port_pair_type(std::vector<port_pair_type> &pptv) {
|
|
|
std::vector<port_pair_type> Galaxy::find_best_trades(void) {
|
|
|
std::vector<port_pair_type> pptv;
|
|
|
|
|
|
- burnt_percent = config["burnt_percent"];
|
|
|
+ burnt_percent = json_int(config["burnt_percent"]);
|
|
|
if (burnt_percent > 90) {
|
|
|
burnt_percent = 90;
|
|
|
config["burnt_percent"] = 90;
|
|
@@ -695,18 +664,6 @@ port_pair_type Galaxy::find_closest_trade(int sector, int lowest_trade_type,
|
|
|
int depth = 0;
|
|
|
|
|
|
while (!found) {
|
|
|
- /*
|
|
|
- for (auto const &t : trades) {
|
|
|
- if (t.type > 2) continue;
|
|
|
- if (current.find(t.s1) != current.end()) {
|
|
|
- // found one!
|
|
|
- return t;
|
|
|
- }
|
|
|
- if (current.find(t.s2) != current.end()) {
|
|
|
- return t;
|
|
|
- }
|
|
|
- }
|
|
|
- */
|
|
|
++depth;
|
|
|
BUGZ_LOG(info) << "depth: " << depth << " current:" << current.size()
|
|
|
<< " seen: " << seen.size();
|
|
@@ -865,7 +822,7 @@ trade_type_result Galaxy::trade_type_info(sector_type port1, sector_type port2,
|
|
|
// If we don't know how many holds the ship has, default to 300.
|
|
|
int max_holds = 300;
|
|
|
if (meta["ship"]["holds"].contains("total")) {
|
|
|
- max_holds = meta["ship"]["holds"]["total"].get<int>();
|
|
|
+ max_holds = json_int(meta["ship"]["holds"]["total"]);
|
|
|
}
|
|
|
|
|
|
// find which FOE are flipped. Save index pos.
|