diff --git a/src/ai/testing.cpp b/src/ai/testing.cpp index 2f0a426d6b3..38fbad8c252 100644 --- a/src/ai/testing.cpp +++ b/src/ai/testing.cpp @@ -19,6 +19,8 @@ #include "manager.hpp" #include "testing.hpp" #include "../log.hpp" +#include "../replay.hpp" +#include "../util.hpp" static lg::log_domain log_ai_testing("ai/testing"); #define DBG_AI_TESTING LOG_STREAM(debug, log_ai_testing) @@ -54,17 +56,30 @@ void ai_testing::log_turn(const char* msg, unsigned int side) DBG_AI_TESTING << msg << "_GOLD" << side << ": " << _gold << std::endl; DBG_AI_TESTING << msg << "_VILLAGES" << side << ": " << _villages << std::endl; DBG_AI_TESTING << msg << "_INCOME" << side << ": " << _income << std::endl; + + config c; + c["side"] = str_cast(side); + c["turn"] = str_cast(_turn_number); + c["event"] = msg; + c["units"] = str_cast(_units); + c["units_cost"] =str_cast(_units_cost); + c["gold"] = str_cast(_gold); + c["villages"] = str_cast(_villages); + recorder.add_log_data("ai_log","turn_info",c); } void ai_testing::log_draw() { LOG_AI_TESTING << "DRAW:" << std::endl; + recorder.add_log_data("ai_log","result","draw"); } void ai_testing::log_victory(std::vector winners) { + recorder.add_log_data("ai_log","result","victory"); for(std::vector::const_iterator w = winners.begin(); w != winners.end(); ++w) { LOG_AI_TESTING << "WINNER: "<< *w <name() << std::endl; } LOG_AI_TESTING << "VERSION: " << game_config::revision << std::endl; + recorder.add_log_data("ai_log","version",game_config::revision); } void ai_testing::log_game_end() { LOG_AI_TESTING << "GAME_END_TURN: "<< ai::manager::get_ai_info().tod_manager_.turn() <add_child("upload_log"); - (*ulog)[key] = var; + config& ulog = cfg_.child_or_add("upload_log"); + ulog[key] = var; +} + +void replay::add_log_data(const std::string &category, const std::string &key, const std::string &var) +{ + config& ulog = cfg_.child_or_add("upload_log"); + config& cat = ulog.child_or_add(category); + cat[key] = var; +} + +void replay::add_log_data(const std::string &category, const std::string &key, const config &c) +{ + config& ulog = cfg_.child_or_add("upload_log"); + config& cat = ulog.child_or_add(category); + cat.add_child(key,c); } void replay::add_checksum_check(const map_location& loc) diff --git a/src/replay.hpp b/src/replay.hpp index 7da5f6c0efd..545ede27551 100644 --- a/src/replay.hpp +++ b/src/replay.hpp @@ -66,6 +66,8 @@ public: void add_unit_checksum(const map_location& loc,config* const cfg); void add_checksum_check(const map_location& loc); void add_log_data(const std::string &key, const std::string &var); + void add_log_data(const std::string &category, const std::string &key, const std::string &var); + void add_log_data(const std::string &category, const std::string &key, const config& c); /** * Mark an expected advancement adding it to the queue diff --git a/src/upload_log.cpp b/src/upload_log.cpp index 47c408158f3..ee3cead10c8 100644 --- a/src/upload_log.cpp +++ b/src/upload_log.cpp @@ -212,7 +212,7 @@ static int upload_logs_dev(void *_ti) // As long as we can actually send the data, delete the file. // Even if the server gives a bad response, we don't want to // be sending the same bad data over and over to the server. - delete_directory(*i); + //delete_directory(*i); numfiles++; if (SDLNet_TCP_Recv(sock, response, sizeof(response)) @@ -270,8 +270,9 @@ void upload_log::read_replay() game_ = new config(); } - foreach (const config &c, recorder.get_replay_data().child_range("command")) { - if(c.child_count("attack")) { + const config& rd = recorder.get_replay_data(); + foreach (const config &c, rd.child_range("command")) { + if(c.child("attack")) { //search through the attack to see if a unit died foreach (const config &c2, c.child_range("random")) { if(c2.child_count("results") && c2.child("results")["dies"] == "yes") { @@ -281,10 +282,10 @@ void upload_log::read_replay() } } } - - if(c.child_count("upload_log")) { - game_->merge_with(c.child("upload_log")); - } + } + + if(rd.child("upload_log")) { + game_->add_child("upload_log",rd.child("upload_log")); } }