|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
#include <algorithm> // sort
|
|
|
#include <boost/format.hpp>
|
|
|
+#include <chrono>
|
|
|
#include <exception>
|
|
|
#include <fstream>
|
|
|
#include <ostream>
|
|
@@ -235,25 +236,29 @@ void Galaxy::add_warp(sector_warps sw) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void Galaxy::add_port(sector_type sector, int port_class) {
|
|
|
+void Galaxy::add_port(sector_type sector, int port_type) {
|
|
|
auto pos = ports.find(sector);
|
|
|
if (pos == ports.end()) {
|
|
|
// no such port.
|
|
|
port p;
|
|
|
p.sector = sector;
|
|
|
- p.type = port_class;
|
|
|
- for( int x= 0; x < 3; x++) {
|
|
|
- p.amount[x ] = 0;
|
|
|
+ p.type = port_type;
|
|
|
+ for (int x = 0; x < 3; x++) {
|
|
|
+ p.amount[x] = 0;
|
|
|
p.percent[x] = 0;
|
|
|
}
|
|
|
- BUGZ_LOG(info) << "add_port: " << sector << ", " << port_class << " : " << p;
|
|
|
+ BUGZ_LOG(trace) << "add_port: " << sector << ", " << port_type << " : "
|
|
|
+ << p;
|
|
|
ports[sector] = p;
|
|
|
} else {
|
|
|
// port was found, so:
|
|
|
- if ( pos->second.type == port_class) {
|
|
|
- BUGZ_LOG(info) << "add_port: Yup, port " << sector << " is class " << port_class;
|
|
|
+ if (pos->second.type == port_type) {
|
|
|
+ BUGZ_LOG(trace) << "add_port: Yup, port " << sector << " is class "
|
|
|
+ << port_type;
|
|
|
} else {
|
|
|
- BUGZ_LOG(fatal) << "add_port: " << sector << " shows " << pos->second.type << " >> set to " << port_class;
|
|
|
+ BUGZ_LOG(fatal) << "add_port: " << sector << " shows " << pos->second.type
|
|
|
+ << " >> set to " << port_type;
|
|
|
+ pos->second.type = port_type;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -261,11 +266,11 @@ void Galaxy::add_port(sector_type sector, int port_class) {
|
|
|
void Galaxy::add_port(port p) {
|
|
|
auto pos = ports.find(p.sector);
|
|
|
if (pos == ports.end()) {
|
|
|
- BUGZ_LOG(info) << "add_port: NEW " << p;
|
|
|
+ BUGZ_LOG(trace) << "add_port: NEW " << p;
|
|
|
ports[p.sector] = p;
|
|
|
} else {
|
|
|
if (pos->second.type != p.type) {
|
|
|
- if ( (pos->second.type == 9) && (p.type == 8) ) {
|
|
|
+ if ((pos->second.type == 9) && (p.type == 8)) {
|
|
|
BUGZ_LOG(info) << "add_port: StarDock " << p.sector;
|
|
|
p.type = 9;
|
|
|
ports[p.sector] = p;
|
|
@@ -274,91 +279,34 @@ void Galaxy::add_port(port p) {
|
|
|
ports[p.sector] = p;
|
|
|
}
|
|
|
} else {
|
|
|
- BUGZ_LOG(info) << "add_port: Yup " << p.sector;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#ifdef NO_NOT_EVER
|
|
|
-
|
|
|
-namespace YAML {
|
|
|
-template <>
|
|
|
-struct convert<Galaxy> {
|
|
|
- static Node encode(const Galaxy &rhs) {
|
|
|
- Node node;
|
|
|
- for (auto const &config_iter : rhs.config) {
|
|
|
- node["config"][config_iter.first] = config_iter.second;
|
|
|
- }
|
|
|
-
|
|
|
- for (auto const &warp : rhs.warps) {
|
|
|
- for (int x = 0; x < MAX_WARPS; ++x) {
|
|
|
- if (warp.second.warps[x] == 0) break;
|
|
|
- node["warps"][warp.first].push_back(warp.second.warps[x]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- node.push_back(rhs.x);
|
|
|
- node.push_back(rhs.y);
|
|
|
- node.push_back(rhs.z);
|
|
|
- return node;
|
|
|
- */
|
|
|
- return node;
|
|
|
- }
|
|
|
-
|
|
|
- static bool decode(const Node &node, Galaxy &rhs) {
|
|
|
- if (!node.IsMap()) return false;
|
|
|
- if (node["config"]) {
|
|
|
- } else {
|
|
|
- BUGZ_LOG(fatal) << "YAML missing config section.";
|
|
|
- }
|
|
|
- if (node["ports"]) {
|
|
|
- } else {
|
|
|
- BUGZ_LOG(fatal) << "YAML missing ports section.";
|
|
|
- }
|
|
|
-
|
|
|
- if (node["warps"]) {
|
|
|
- const Node &warps = node["warps"];
|
|
|
- if (warps.IsMap()) {
|
|
|
- for (auto const warp_iter : warps) {
|
|
|
- sector_warps sw;
|
|
|
- sw.sector = warp_iter.first.as<int>();
|
|
|
- for (auto const sector_iter : warp_iter.second) {
|
|
|
- sw.add(sector_iter.as<int>());
|
|
|
- }
|
|
|
- BUGZ_LOG(fatal) << "YAML warp: " << sw;
|
|
|
- rhs.add_warp(sw);
|
|
|
- }
|
|
|
+ if (pos->second.amount != p.amount) {
|
|
|
+ BUGZ_LOG(info) << "add_port: UPDATE " << p.sector;
|
|
|
+ pos->second = p;
|
|
|
+ } else {
|
|
|
+ BUGZ_LOG(info) << "add_port: Yup " << p.sector;
|
|
|
}
|
|
|
- } else {
|
|
|
- BUGZ_LOG(fatal) << "YAML missing warps section.";
|
|
|
- }
|
|
|
- /*
|
|
|
- if(!node.IsSequence() || node.size() != 3) {
|
|
|
- return false;
|
|
|
}
|
|
|
-
|
|
|
- rhs.x = node[0].as<double>();
|
|
|
- rhs.y = node[1].as<double>();
|
|
|
- rhs.z = node[2].as<double>();
|
|
|
- */
|
|
|
- return true;
|
|
|
}
|
|
|
-};
|
|
|
-} // namespace YAML
|
|
|
-
|
|
|
-#endif
|
|
|
+}
|
|
|
|
|
|
void Galaxy::load(void) {
|
|
|
std::string filename =
|
|
|
str(boost::format("galaxy-%1%-%2%.json") % game % username);
|
|
|
// reset ?
|
|
|
- config.clear();
|
|
|
+ meta = YAML::Node();
|
|
|
+ config = YAML::Node();
|
|
|
ports.clear();
|
|
|
warps.clear();
|
|
|
if (file_exists(filename)) {
|
|
|
YAML::Node data = YAML::LoadFile(filename);
|
|
|
+ if (config["meta"]) meta = config["meta"];
|
|
|
+ meta["load_from"] = filename;
|
|
|
+ std::chrono::_V2::system_clock::time_point now =
|
|
|
+ std::chrono::system_clock::now();
|
|
|
+
|
|
|
+ meta["load_time"] = std::chrono::system_clock::to_time_t(now); // time_t
|
|
|
if (data["config"]) {
|
|
|
+ config = data["config"];
|
|
|
} else {
|
|
|
BUGZ_LOG(fatal) << "YAML Missing config section.";
|
|
|
}
|
|
@@ -392,7 +340,7 @@ void Galaxy::load(void) {
|
|
|
for (auto const sector_iter : warp_iter.second) {
|
|
|
sw.add(sector_iter.as<int>());
|
|
|
}
|
|
|
- BUGZ_LOG(fatal) << "YAML warp: " << sw;
|
|
|
+ // BUGZ_LOG(trace) << "YAML warp: " << sw;
|
|
|
add_warp(sw);
|
|
|
}
|
|
|
// }
|
|
@@ -413,10 +361,21 @@ void Galaxy::save(void) {
|
|
|
std::string filename =
|
|
|
str(boost::format("galaxy-%1%-%2%.json") % game % username);
|
|
|
YAML::Node data;
|
|
|
+ // add some information to meta before saving.
|
|
|
+ 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
|
|
|
+
|
|
|
+ data["meta"] = meta;
|
|
|
BUGZ_LOG(fatal) << "YAML config: " << config.size();
|
|
|
+ data["config"] = config;
|
|
|
+ /*
|
|
|
for (auto const &config_iter : config) {
|
|
|
data["config"][config_iter.first] = config_iter.second;
|
|
|
}
|
|
|
+ */
|
|
|
BUGZ_LOG(fatal) << "YAML warps: " << warps.size();
|
|
|
for (auto const &warp : warps) {
|
|
|
for (auto const §or : warp.second.warps) {
|