diff options
author | Raphael Langella <raphael.langella@gmail.com> | 2014-01-15 00:29:26 +0100 |
---|---|---|
committer | Raphael Langella <raphael.langella@gmail.com> | 2014-01-15 00:31:36 +0100 |
commit | 9febb93398b4cd7959aba264390b83c9b3b598fa (patch) | |
tree | 4c6c6c61d60c35a6cd777d48559a0cb2aea5d3dd /crawl-ref/source/wiz-fsim.cc | |
parent | 82ebfd5c76a5992f97b8d791dbaa3dff7ae99254 (diff) | |
download | crawl-ref-9febb93398b4cd7959aba264390b83c9b3b598fa.tar.gz crawl-ref-9febb93398b4cd7959aba264390b83c9b3b598fa.zip |
New option: fsim_csv
Unsurprisingly, it outputs the fsim data in csv format, for easier processing.
Also rename the output file to fsim.txt (or fsim.csv).
Diffstat (limited to 'crawl-ref/source/wiz-fsim.cc')
-rw-r--r-- | crawl-ref/source/wiz-fsim.cc | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/crawl-ref/source/wiz-fsim.cc b/crawl-ref/source/wiz-fsim.cc index 36acbb0e3e..06ede697d1 100644 --- a/crawl-ref/source/wiz-fsim.cc +++ b/crawl-ref/source/wiz-fsim.cc @@ -49,14 +49,17 @@ typedef map<skill_type, int8_t>::iterator skill_map_iterator; static const char* _title_line = "AvHitDam | MaxDam | Accuracy | AvDam | AvTime | AvSpeed | AvEffDam"; // 64 columns +static const char* _csv_title_line = + "AvHitDam,MaxDam,Accuracy,AvDam,AvTime,AvSpeed,AvEffDam"; -static const string _fight_string(fight_data fdata) +static const char* _fight_string(fight_data fdata, bool csv) { - return make_stringf(" %5.1f | %3d | %3d%% |" - " %5.1f | %3d | %5.2f | %5.1f", + return make_stringf(csv ? "%.1f,%d,%d%%,%.1f,%d,%.2f,%.1f" + : " %5.1f | %3d | %3d%% |" + " %5.1f | %3d | %5.2f | %5.1f", fdata.av_hit_dam, fdata.max_dam, fdata.accuracy, fdata.av_dam, fdata.av_time, fdata.av_speed, - fdata.av_eff_dam); + fdata.av_eff_dam).c_str(); } static skill_type _equipped_skill() @@ -143,9 +146,9 @@ static void _write_you(FILE * o) you.dex()); } -static void _write_weapon(FILE * o) +static void _write_weapon(FILE * o, bool csv) { - fprintf(o, "%s, Skill: %s\n", + fprintf(o, csv ? "\"%s, Skill: %s\"\n" : "%s, Skill: %s\n", _equipped_weapon_name().c_str(), skill_name(_equipped_skill())); } @@ -445,10 +448,10 @@ void wizard_quick_fsim() const int iter_limit = Options.fsim_rounds; fight_data fdata = _get_fight_data(*mon, iter_limit, false); mprf(" %s\nAttacking: %s", _title_line, - _fight_string(fdata).c_str()); + _fight_string(fdata, false)); fdata = _get_fight_data(*mon, iter_limit, true); - mprf("Defending: %s", _fight_string(fdata).c_str()); + mprf("Defending: %s", _fight_string(fdata, false)); _uninit_fsim(mon); return; @@ -520,7 +523,11 @@ static void _fsim_simple_scale(FILE * o, monster* mon, bool defense) const char* title = make_stringf("%10.10s | %s", col_name.c_str(), _title_line).c_str(); - fprintf(o, "%s\n", title); + if (Options.fsim_csv) + fprintf(o, "%s,%s\n", col_name.c_str(), _csv_title_line); + else + fprintf(o, "%s\n", title); + mpr(title); const int iter_limit = Options.fsim_rounds; @@ -536,9 +543,12 @@ static void _fsim_simple_scale(FILE * o, monster* mon, bool defense) fight_data fdata = _get_fight_data(*mon, iter_limit, defense); const string line = make_stringf(" %2d | %s", i, - _fight_string(fdata).c_str()); + _fight_string(fdata, false)); mprf("%s", line.c_str()); - fprintf(o, "%s\n", line.c_str()); + if (Options.fsim_csv) + fprintf(o, "%d,%s\n", i, _fight_string(fdata, true)); + else + fprintf(o, "%s\n", line.c_str()); fflush(o); // kill the loop if the user hits escape @@ -566,16 +576,16 @@ static void _fsim_double_scale(FILE * o, monster* mon, bool defense) } fprintf(o, "%s(x) vs %s(y)\n", skill_name(skx), skill_name(sky)); - fprintf(o, " "); + fprintf(o, Options.fsim_csv ? "," : " "); for (int y = 1; y <= 27; y += 2) - fprintf(o," %2d", y); + fprintf(o,Options.fsim_csv ? "%d," : " %2d", y); fprintf(o,"\n"); const int iter_limit = Options.fsim_rounds; for (int y = 1; y <= 27; y += 2) { - fprintf(o, "%2d", y); + fprintf(o, Options.fsim_csv ? "%d," : "%2d", y); for (int x = 1; x <= 27; x += 2) { mesclr(); @@ -584,7 +594,7 @@ static void _fsim_double_scale(FILE * o, monster* mon, bool defense) fight_data fdata = _get_fight_data(*mon, iter_limit, defense); mprf("%s %d, %s %d: %d", skill_name(skx), x, skill_name(sky), y, int(fdata.av_eff_dam)); - fprintf(o,"%5.1f", fdata.av_eff_dam); + fprintf(o,Options.fsim_csv ? "%.1f," : "%5.1f", fdata.av_eff_dam); fflush(o); // kill the loop if the user hits escape @@ -606,7 +616,7 @@ void wizard_fight_sim(bool double_scale) return; bool defense = false; - const char * fightstat = "fight.stat"; + const char * fightstat = Options.fsim_csv ? "fsim.csv" : "fsim.txt"; FILE * o = fopen(fightstat, "a"); if (!o) @@ -647,7 +657,7 @@ void wizard_fight_sim(bool double_scale) _write_version(o); _write_matchup(o, *mon, defense, Options.fsim_rounds); _write_you(o); - _write_weapon(o); + _write_weapon(o, Options.fsim_csv); _write_mon(o, *mon); fprintf(o,"\n"); @@ -672,7 +682,7 @@ void wizard_fight_sim(bool double_scale) string error; if (_fsim_kit_equip(Options.fsim_kit[i], error)) { - _write_weapon(o); + _write_weapon(o, Options.fsim_csv); fsim_proc(o, mon, defense); fprintf(o, "\n"); } @@ -685,7 +695,8 @@ void wizard_fight_sim(bool double_scale) } } - fprintf(o, "-----------------------------------\n\n"); + if (!Options.fsim_csv) + fprintf(o, "-----------------------------------\n\n"); fclose(o); skill_backup.restore_levels(); |