Enabled log uploads for ai vs. ai multiplayer matches...

...(logs are still incomplete, however). refactored
read_replay(). Wrote new upload_log.start() without deprecated
parameters.
This commit is contained in:
Gregory Shikhman 2009-08-10 06:32:31 +00:00
parent 12e2249d1d
commit 189e521ae9
4 changed files with 52 additions and 15 deletions

View file

@ -917,9 +917,16 @@ bool game_controller::play_multiplayer_mode()
level.add_child("era", era_cfg);
try {
upload_log nolog(false);
//check if all sides are AI and we are using new uploader -> log these games
bool all_ai = true;
foreach (config &s, level.child_range("side")) {
if( s["controller"] != "ai" ) {
all_ai = false;
}
}
upload_log log( all_ai && uploader_settings::new_uploader );
state_.snapshot = level;
play_game(disp(),state_,game_config_,nolog);
play_game(disp(),state_,game_config_,log);
} catch(game::error& e) {
std::cerr << "caught error: '" << e.message << "'\n";
} catch(game::load_game_exception& e) {

View file

@ -324,6 +324,8 @@ LEVEL_RESULT playsingle_controller::play_scenario(
if (first_human_team_ != -1) {
log.start(gamestate_, teams_[first_human_team_], first_human_team_ + 1, units_,
loading_game_ ? gamestate_.get_variable("turn_number") : "", number_of_turns(), resources::game_map->write());
} else { //ai vs. ai upload logs
log.start(gamestate_, resources::game_map->write());
}
fire_prestart(!loading_game_);
@ -376,6 +378,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
throw;
} catch(end_level_exception& end_level) {
ai_testing::log_game_end();
log.quit(turn());
*end_level_result = end_level;
if(!end_level.custom_endlevel_music.empty()) {
switch(end_level.result) {

View file

@ -262,7 +262,7 @@ upload_log::upload_log(bool enable) :
void upload_log::read_replay()
{
if( !uploader_settings::new_uploader ) {
if( !uploader_settings::new_uploader || !enabled_ || !game_config::debug ) {
return;
}
@ -271,18 +271,16 @@ void upload_log::read_replay()
game_ = new config();
}
if(enabled_ && !game_config::debug) {
foreach (const config &c, recorder.get_replay_data().child_range("command")) {
if(c.child_count("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") {
config& cfg = game_->add_child("kill_event");
cfg.add_child("attack",c.child("attack"));
cfg.add_child("results",c2.child("results"));
}
}
}
foreach (const config &c, recorder.get_replay_data().child_range("command")) {
if(c.child_count("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") {
config& cfg = game_->add_child("kill_event");
cfg.add_child("attack",c.child("attack"));
cfg.add_child("results",c2.child("results"));
}
}
}
}
}
@ -455,6 +453,34 @@ void upload_log::start(game_state &state, const team &team,
}
}
void upload_log::start(game_state &state, const std::string map_data)
{
// If we have a previous game which is finished, add it.
if (game_finished(game_)) {
config_.add_child("game", *game_);
}
// Start could be called more than once,
// so delete game_ to prevent memory leak
delete game_;
game_ = new config();
(*game_)["time"] = lexical_cast<std::string>(SDL_GetTicks() / 1000);
(*game_)["campaign"] = state.classification().campaign_define;
(*game_)["difficulty"] = state.classification().difficulty;
(*game_)["scenario"] = state.classification().scenario;
if(uploader_settings::new_uploader) {
//replace newlines in map definition with semicolons so that braindead server-side wml parser doesn't get confused
std::string encoded_map(map_data);
for(size_t idx = 0; idx < encoded_map.length(); idx++) {
if(encoded_map[idx] == '\n')
encoded_map[idx] = ';';
}
(*game_)["map_data"] = encoded_map;
}
if (!state.classification().version.empty())
(*game_)["version"] = state.classification().version;
}
// User finishes a scenario.
void upload_log::defeat(int turn)
{

View file

@ -49,6 +49,7 @@ public:
void start(game_state &state, const team &team,
int side_number, const unit_map &map, const t_string &turn,
int num_turns, const std::string map_data);
void start(game_state &state, const std::string map_data);
// User finishes a level.
void defeat(int turn);