-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathReplayEncoder.h
More file actions
76 lines (59 loc) · 1.81 KB
/
ReplayEncoder.h
File metadata and controls
76 lines (59 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef REPLAY_ENCODER_H
#define REPLAY_ENCODER_H
#include "json.hpp"
using json = nlohmann::ordered_json;
#include "Logger.h"
#include "Config.h"
#include "Action.h"
#include "Stats.h"
#include "Core.h"
#include <fstream>
#include <unordered_map>
#include <filesystem>
#include <cstdlib>
enum class death_reason_t
{
NONE_SURVIVED,
CORE_DESTROYED,
DISCONNECTED,
DID_NOT_CONNECT,
TIMEOUT_SENDING_DATA,
TIMEOUT_CORE_HP,
TIMEOUT_UNIT_HP,
TIMEOUT_RANDOM
};
typedef struct team_data_s
{
unsigned int teamId;
std::string teamName;
bool connectedInitially = false;
death_reason_t deathReason = death_reason_t::DID_NOT_CONNECT;
unsigned int place = std::numeric_limits<unsigned int>::max(); // 0 = won
} team_data_t;
class ReplayEncoder
{
public:
ReplayEncoder() : ticks_(json::object()), lastTickCount_(0) {}
~ReplayEncoder() = default;
static ReplayEncoder &instance();
void addTickState(json &state, unsigned long long tick, std::vector<std::pair<std::unique_ptr<Action>, Core *>> &actions);
void registerExpectedTeam(unsigned int teamId);
void setTeamName(unsigned int teamId, const std::string &teamName);
void markConnectedInitially(unsigned int teamId, bool connected);
void setDeathReason(unsigned int teamId, death_reason_t reason);
void setPlace(unsigned int teamId, unsigned int place);
bool wasConnectedInitially(unsigned int teamId) const;
void includeConfig(json &config);
json &getCustomData(void) { return customData_; }
void exportReplay() const;
void saveReplay(const json &replayData) const;
static void verifyReplaySaveFolder();
private:
json encodeMiscSection() const;
json ticks_ = json::array();
json config_ = json::object();
json customData_ = json::object();
unsigned long long lastTickCount_;
std::unordered_map<unsigned int, team_data_t> teamData_;
};
#endif // REPLAY_ENCODER_H