void wotreplay::show_map_boundaries(const game_t &game, const std::vector<packet_t> &packets) { float min_x = 0.f, min_y = 0.f, max_x = 0.f, max_y = 0.f; for (const packet_t &packet : packets) { if (packet.type() != 0xa) { continue; } uint32_t player_id = packet.player_id(); // only take into account positions of 'valid' players. if (game.get_team_id(player_id) != -1) { // update the boundaries auto position = packet.position(); min_x = std::min(min_x, std::get<0>(position)); min_y = std::min(min_y, std::get<2>(position)); max_x = std::max(max_x, std::get<0>(position)); max_y = std::max(max_y, std::get<2>(position)); break; } } printf("The boundaries of used positions in this replay are: min_x = %f max_x = %f min_y = %f max_y = %f\n", min_x, max_x, min_y, max_y); }
int wotreplay::get_start_packet (const game_t &game, double skip) { std::unordered_map<int, packet_t> last_packets; int i = 0; for (const auto &packet : game.get_packets()) { i++; if (!packet.has_property(property_t::position)) { continue; } int player_id = packet.player_id(), team_id = game.get_team_id(player_id); if (team_id < 0) { continue; // belongs to no team } auto last = last_packets.find(player_id); if (last != last_packets.end()) { int distance = dist(last->second.position(), packet.position()); if (distance > 0.01) { break; } } last_packets[player_id] = packet; } const auto &packets = game.get_packets(); if (i < packets.size()) { float clock = packets[i].clock(), offset = skip; for (auto it = packets.begin() + i; it != packets.end(); ++it) { if (it->has_property(property_t::clock) && it->clock() >= clock + offset) { break; } ++i; } } return i; }
void image_writer_t::draw_position(const packet_t &packet, const game_t &game, boost::multi_array<float, 3> &image) { uint32_t player_id = packet.player_id(); int team_id = game.get_team_id(player_id); if (team_id < 0) return; auto shape = image.shape(); int width = static_cast<int>(shape[2]); int height = static_cast<int>(shape[1]); float x,y; std::tie(x,y) = get_2d_coord( packet.position(), game, width, height); if (x >= 0 && y >= 0 && x <= (width - 1) && y <= (height - 1)) { image[team_id][y][x] = 1; if (player_id == game.get_recorder_id()) { image[2][y][x] = 1; } } }
void json_writer_t::update(const game_t &game) { auto &packets = root["packets"]; bounding_box_t bounding_box = game.get_arena().bounding_box; // copy boundary values Json::Value coordinate(Json::arrayValue); coordinate.append(std::get<0>(bounding_box.bottom_left)); coordinate.append(std::get<1>(bounding_box.bottom_left)); root["map_boundaries"].append(coordinate); coordinate.clear(); coordinate.append(std::get<0>(bounding_box.upper_right)); coordinate.append(std::get<1>(bounding_box.upper_right)); root["map_boundaries"].append(coordinate); root["recorder_id"] = game.get_recorder_id(); Json::Value summary; Json::Reader reader; const buffer_t &buffer = game.get_game_begin(); std::string summary_str(buffer.begin(), buffer.end()); reader.parse(summary_str, summary); root["summary"] = summary; for (auto &packet : game.get_packets()) { Json::Value value(Json::objectValue); if (packet.has_property(property_t::type)) { value["type"] = packet.type(); } if (packet.has_property(property_t::clock)) { value["clock"] = packet.clock(); } if (packet.has_property(property_t::player_id)) { value["player_id"] = packet.player_id(); int team_id = game.get_team_id(packet.player_id()); if (team_id != -1) { value["team"] = team_id; } } if (packet.has_property(property_t::position)) { Json::Value positionValue(Json::arrayValue); const auto &position = packet.position(); positionValue.append(std::get<0>(position)); positionValue.append(std::get<1>(position)); positionValue.append(std::get<2>(position)); value["position"] = positionValue; } if (packet.has_property(property_t::hull_orientation)) { Json::Value orientationValue(Json::arrayValue); const auto &orientation = packet.hull_orientation(); orientationValue.append(std::get<0>(orientation)); orientationValue.append(std::get<1>(orientation)); orientationValue.append(std::get<2>(orientation)); value["hull_orientation"] = orientationValue; } if (packet.has_property(property_t::tank_destroyed)) { uint32_t target, destroyed_by; std::tie(target, destroyed_by) = packet.tank_destroyed(); value["target"] = target; value["destroyed_by"] = destroyed_by; } if (packet.has_property(property_t::health)) { value["health"] = packet.health(); } if (packet.has_property(property_t::source)) { value["source"] = packet.source(); } if (packet.has_property(property_t::message)) { value["message"] = packet.message(); } if (packet.has_property(property_t::sub_type)) { value["sub_type"] = packet.sub_type(); } if (packet.has_property(property_t::target)) { value["target"] = packet.target(); } if (packet.has_property(property_t::destroyed_track_id)) { value["destroyed_track_id"] = packet.destroyed_track_id(); } if (packet.has_property(property_t::alt_track_state)) { value["alt_track_state"] = packet.alt_track_state(); } packets.append(value); } }