|
@@ -84,8 +84,7 @@ int trade_type(port_type port1, port_type port2) {
|
|
|
}
|
|
|
|
|
|
if (matches == 1) {
|
|
|
- if (inv2.foe[FUEL])
|
|
|
- return 4;
|
|
|
+ if (inv2.foe[FUEL]) return 4;
|
|
|
return 3;
|
|
|
}
|
|
|
return 0;
|
|
@@ -383,8 +382,7 @@ void Galaxy::save(void) {
|
|
|
meta["save_to"] = filename;
|
|
|
std::chrono::_V2::system_clock::time_point now =
|
|
|
std::chrono::system_clock::now();
|
|
|
- meta["save_time"] =
|
|
|
- std::chrono::system_clock::to_time_t(now); // time_t
|
|
|
+ meta["save_time"] = std::chrono::system_clock::to_time_t(now); // time_t
|
|
|
|
|
|
data["meta"] = meta;
|
|
|
BUGZ_LOG(fatal) << "YAML config: " << config.size();
|
|
@@ -399,6 +397,7 @@ void Galaxy::save(void) {
|
|
|
for (auto const §or : warp.second.warps) {
|
|
|
data["warps"][warp.first].push_back(sector);
|
|
|
}
|
|
|
+ data["warps"][warp.first].SetStyle(YAML::EmitterStyle::Flow);
|
|
|
/*
|
|
|
for (int x = 0; x < MAX_WARPS; ++x) {
|
|
|
if (warp.second.warps[x] == 0) break;
|
|
@@ -419,9 +418,83 @@ void Galaxy::save(void) {
|
|
|
data["ports"][port.second.sector]["pct"].push_back(
|
|
|
(int)port.second.percent[x]);
|
|
|
}
|
|
|
+ data["ports"][port.second.sector]["amount"].SetStyle(YAML::EmitterStyle::Flow);
|
|
|
+ data["ports"][port.second.sector]["pct"].SetStyle(YAML::EmitterStyle::Flow);
|
|
|
+ data["ports"][port.second.sector].SetStyle(YAML::EmitterStyle::Flow);
|
|
|
}
|
|
|
|
|
|
std::ofstream fout(filename);
|
|
|
fout << data << std::endl;
|
|
|
BUGZ_LOG(fatal) << "YAML: " << filename;
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+std::vector<port_pair_type> Galaxy::find_trades(sector_type sector,
|
|
|
+ bool highest) {
|
|
|
+ std::vector<port_pair_type> pptv;
|
|
|
+
|
|
|
+ // Does this sector have a port?
|
|
|
+ auto port = ports.find(sector);
|
|
|
+ if (port == ports.end()) return pptv;
|
|
|
+
|
|
|
+ auto port_warps = warps.find(sector);
|
|
|
+ // warps not found for port sector?
|
|
|
+ if (port_warps == warps.end()) return pptv;
|
|
|
+ // TODO: Check if ports are burnt out
|
|
|
+
|
|
|
+ for (auto const &s : port_warps->second.warps) {
|
|
|
+ // only count the ports > our sector number -- so we don't have dups
|
|
|
+ if (highest && (s < sector)) continue;
|
|
|
+
|
|
|
+ // verify we have a way back
|
|
|
+ {
|
|
|
+ auto warpback = warps.find(s);
|
|
|
+ // can we find that warp?
|
|
|
+ if (warpback == warps.end()) continue;
|
|
|
+ // does it link back to the port's sector?
|
|
|
+ if (warpback->second.warps.find(sector) == warpback->second.warps.end())
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Does this sector have a port?
|
|
|
+ auto possible_port = ports.find(s);
|
|
|
+ if (possible_port == ports.end()) continue;
|
|
|
+
|
|
|
+ // calculate trade type
|
|
|
+ int t = trade_type(port->second.type, possible_port->second.type);
|
|
|
+ if ((t == 0) || (t == 4)) continue;
|
|
|
+
|
|
|
+ // Are any of the trade pairs burnt out?
|
|
|
+
|
|
|
+ pptv.push_back(port_pair_type{t, sector, s});
|
|
|
+ BUGZ_LOG(fatal) << "sector: " << sector << " and " << s << " tt:" << t;
|
|
|
+ }
|
|
|
+ return pptv;
|
|
|
+}
|
|
|
+
|
|
|
+bool compare_port_pair(const port_pair_type &ppt1, const port_pair_type &ppt2) {
|
|
|
+ if (ppt1.type == ppt2.type) {
|
|
|
+ return ppt1.s1 < ppt2.s1;
|
|
|
+ } else {
|
|
|
+ return (ppt1.type < ppt2.type);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void Galaxy::sort_port_pair_type(std::vector<port_pair_type> &pptv) {
|
|
|
+ sort(pptv.begin(), pptv.end(), compare_port_pair);
|
|
|
+}
|
|
|
+
|
|
|
+std::vector<port_pair_type> Galaxy::find_best_trades(void) {
|
|
|
+ std::vector<port_pair_type> pptv;
|
|
|
+
|
|
|
+ for (auto const &pi : ports) {
|
|
|
+ if (pi.second.type == 0) continue;
|
|
|
+ sector_type sector = pi.second.sector;
|
|
|
+ auto port_warps = warps.find(sector);
|
|
|
+ if (port_warps == warps.end()) continue;
|
|
|
+
|
|
|
+ std::vector<port_pair_type> ppt_sector = find_trades(sector, true);
|
|
|
+ if (ppt_sector.empty()) continue;
|
|
|
+ pptv.insert(pptv.end(), ppt_sector.begin(), ppt_sector.end());
|
|
|
+ }
|
|
|
+ return pptv;
|
|
|
+}
|