Changed upload_log to record data into replays...

...under the [upload_log] tag. Log events can be added throughout the
code at all times by using the new replay::add_log_data()
functions. Changed the --label code to use this new
functionaity. Added this functionality to src/ai/testing.cpp under the
[ai_log] category.
This commit is contained in:
Gregory Shikhman 2009-08-19 22:52:28 +00:00
parent 8f60b0d9b9
commit 6e3ec07d96
5 changed files with 45 additions and 10 deletions

View file

@ -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<unsigned int> winners)
{
recorder.add_log_data("ai_log","result","victory");
for(std::vector<unsigned int>::const_iterator w = winners.begin(); w != winners.end(); ++w) {
LOG_AI_TESTING << "WINNER: "<< *w <<std::endl;
recorder.add_log_data("ai_log","winner",str_cast(*w));
}
}
@ -77,9 +92,12 @@ void ai_testing::log_game_start()
LOG_AI_TESTING << "FACTION"<<side<<": " << tm->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() <<std::endl;
recorder.add_log_data("ai_log","end_turn",
str_cast(ai::manager::get_ai_info().tod_manager_.turn()));
}

View file

@ -929,7 +929,7 @@ bool game_controller::play_multiplayer_mode()
}
upload_log log( all_ai && uploader_settings::new_uploader );
recorder.add_log_data("ai_label",label);;
recorder.add_log_data("ai_log","ai_label",label);
state_.snapshot = level;
play_game(disp(),state_,game_config_,log);

View file

@ -379,8 +379,22 @@ void replay::add_event(const std::string& name, const map_location& loc)
void replay::add_log_data(const std::string &key, const std::string &var)
{
config* const ulog = &add_command(false)->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)

View file

@ -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

View file

@ -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"));
}
}