summaryrefslogtreecommitdiffhomepage
path: root/Snapshot.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Snapshot.cpp')
-rw-r--r--Snapshot.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/Snapshot.cpp b/Snapshot.cpp
index 99cf400..5d76e73 100644
--- a/Snapshot.cpp
+++ b/Snapshot.cpp
@@ -5,11 +5,13 @@
#include <string>
#include <unordered_map>
#include <vector>
+#include <iostream>
#include <nlohmann/json.hpp>
#include <raylib.h>
#include "Killmail.h"
+#include "Owner.h"
using json = nlohmann::json;
@@ -24,7 +26,8 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(LongVector3, x, y, z)
Snapshot::Snapshot(const char* filename) :
- m_killmails {}
+ m_killmails {},
+ m_teams {}
{
if (!FileExists(filename))
throw "File does not exist";
@@ -38,6 +41,14 @@ Snapshot::Snapshot(const char* filename) :
dump.at("killmails").get_to(m_killmails);
for (auto& km : m_killmails)
km.group = group_lookup[km.ship];
+ int team = 0;
+ for (const auto& members : dump.at("teams")) {
+ for (const auto& entry : members) {
+ const auto id = entry.get<long int>();
+ m_teams[id] = team;
+ }
+ ++team;
+ }
UnloadFileText(text);
}
@@ -49,6 +60,25 @@ Snapshot::killmails() const
}
+int
+Snapshot::team(const Owner& owner) const
+{
+ auto find = [this](long int id) -> int {
+ if (id < 0)
+ return -1;
+ const auto search = m_teams.find(id);
+ if (search == m_teams.end())
+ return -1;
+ return search->second;
+ };
+ int id;
+ if ((id = find(owner.faction)) != -1) return id;
+ if ((id = find(owner.alliance)) != -1) return id;
+ if ((id = find(owner.corporation)) != -1) return id;
+ return -1;
+}
+
+
void
from_json(const json& j, tm& d)
{