Addressed request. Improved profile saving

develop
PatrikLundell 2018-02-27 10:46:06 +01:00
parent 7705eada5a
commit 578d6666eb
5 changed files with 80 additions and 52 deletions

@ -1,4 +1,4 @@
call "D:\Program (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
cd VC2015
msbuild /m /p:Platform=x64 /p:Configuration=RelWithDebInfo INSTALL.vcxproj
cd ..

@ -162,6 +162,7 @@ namespace embark_assist {
Major
};
// For possible future use. That's the level of data actually collected.
// enum class adamantine_ranges : int8_t {
// NA = -1,
// Cavern_1,

@ -143,7 +143,7 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector <Plugi
" the embark rectangle as well as normally undisplayed sites in the\n"
" current embark region. It also has a site selection tool with more\n"
" options than DF's vanilla search tool. For detailed help invoke the\n"
" in game info screen. Requires 42 lines to display properly.\n"
" in game info screen. Requires 46 lines to display properly.\n"
));
return CR_OK;
}

@ -21,7 +21,7 @@
using df::global::world;
#define profile_file_name ".\\data\\init\\embark_assistant_profile.txt"
#define profile_file_name "./data/init/embark_assistant_profile.txt"
namespace embark_assist {
namespace finder_ui {
@ -151,8 +151,13 @@ namespace embark_assist {
fields i = first_fields;
while (true) {
out.print("[%s:%i]\n", state->finder_list[static_cast<int8_t>(i)].text.c_str(), state->ui[static_cast<int8_t>(i)]->current_value);
fprintf(outfile, "[%s:%i]\n", state->finder_list[static_cast<int8_t>(i)].text.c_str(), state->ui[static_cast<int8_t>(i)]->current_value);
for (int k = 0; k < state->ui[static_cast<int8_t>(i)]->list.size(); k++) {
if (state->ui[static_cast<int8_t>(i)]->current_value == state->ui[static_cast<int8_t>(i)]->list[k].key) {
fprintf(outfile, "[%s:%s]\n", state->finder_list[static_cast<int8_t>(i)].text.c_str(), state->ui[static_cast<int8_t>(i)]->list[k].text.c_str());
break;
}
}
// fprintf(outfile, "[%s:%i]\n", state->finder_list[static_cast<int8_t>(i)].text.c_str(), state->ui[static_cast<int8_t>(i)]->current_value);
if (i == last_fields) {
break; // done
}
@ -178,40 +183,46 @@ namespace embark_assist {
char line[80];
int count = 80;
bool found;
int value;
while (true) {
fgets(line, count, infile);
if (line[0] != '[') {
out.printerr("Failed to find token start '[' at line %i\n", static_cast<int8_t>(i));
fclose(infile);
return;
}
found = false;
for (int k = 1; k < count; k++) {
if (line[k] == ':') {
for (int l = 1; l < k; l++) {
if (state->finder_list[static_cast<int8_t>(i)].text.c_str()[l - 1] != line[l]) {
out.printerr("Token mismatch of %s vs %s\n", line, state->finder_list[static_cast<int8_t>(i)].text.c_str());
fclose(infile);
return;
}
}
if (!sscanf(&line[k + 1], "%i]", &value)) {
out.printerr("Value extraction failure from %s\n", line);
return;
}
found = false;
for (int l = 0; l < state->ui[static_cast<int8_t>(i)]->list.size(); l++) {
if (value == state->ui[static_cast<int8_t>(i)]->list[l].key) {
found = true;
for (int m = k + 1; m < count; m++) {
if (state->ui[static_cast<int8_t>(i)]->list[l].text.c_str()[m - (k + 1)] != line[m]) {
if (state->ui[static_cast<int8_t>(i)]->list[l].text.c_str()[m - (k + 1)] == '\0' &&
line[m] == ']') {
found = true;
}
break;
}
}
if (found) {
break;
}
}
if (!found) {
out.printerr("Value not found in plugin. Raw mismatch? %s\n", line);
out.printerr("Value extraction failure from %s\n", line);
fclose(infile);
return;
}
@ -221,6 +232,7 @@ namespace embark_assist {
if (!found) {
out.printerr("Value delimiter not found in %s\n", line);
fclose(infile);
return;
}
@ -243,13 +255,23 @@ namespace embark_assist {
for (int k = 1; k < count; k++) {
if (line[k] == ':') {
sscanf(&line[k + 1], "%i]", &value);
state->ui[static_cast<int8_t>(i)]->current_value = value;
found = false;
for (int l = 0; l < state->ui[static_cast<int8_t>(i)]->list.size(); l++) {
if (value == state->ui[static_cast<int8_t>(i)]->list[l].key) {
state->ui[static_cast<int8_t>(i)]->current_display_value = l;
for (int m = k + 1; m < count; m++) {
if (state->ui[static_cast<int8_t>(i)]->list[l].text.c_str()[m - (k + 1)] != line[m]) {
if (state->ui[static_cast<int8_t>(i)]->list[l].text.c_str()[m - (k + 1)] == '\0' &&
line[m] == ']') {
state->ui[static_cast<int8_t>(i)]->current_value = state->ui[static_cast<int8_t>(i)]->list[l].key;
state->ui[static_cast<int8_t>(i)]->current_display_value = l;
found = true;
}
break;
}
}
if (found) {
break;
}
}
@ -577,15 +599,15 @@ namespace embark_assist {
break;
case embark_assist::defs::magma_ranges::Cavern_3:
element->list.push_back({ "3:rd Cavern", static_cast<int8_t>(k) });
element->list.push_back({ "Third Cavern", static_cast<int8_t>(k) });
break;
case embark_assist::defs::magma_ranges::Cavern_2:
element->list.push_back({ "2:nd Cavern", static_cast<int8_t>(k) });
element->list.push_back({ "Second Cavern", static_cast<int8_t>(k) });
break;
case embark_assist::defs::magma_ranges::Cavern_1:
element->list.push_back({ "1:st Cavern", static_cast<int8_t>(k) });
element->list.push_back({ "Third Cavern", static_cast<int8_t>(k) });
break;
case embark_assist::defs::magma_ranges::Volcano:
@ -1265,20 +1287,24 @@ namespace embark_assist {
Screen::clear();
Screen::drawBorder("Embark Assistant Site Finder");
embark_assist::screen::paintString(lr_pen, 1, 1, "4/6");
embark_assist::screen::paintString(white_pen, 4, 1, ":<->");
embark_assist::screen::paintString(lr_pen, 9, 1, "8/2");
embark_assist::screen::paintString(lr_pen, 1, 1, DFHack::Screen::getKeyDisplay(df::interface_key::CURSOR_LEFT).c_str());
embark_assist::screen::paintString(white_pen, 2, 1, "/");
embark_assist::screen::paintString(lr_pen, 3, 1, DFHack::Screen::getKeyDisplay(df::interface_key::CURSOR_RIGHT).c_str());
embark_assist::screen::paintString(white_pen, 4, 1, ":\x1b/\x1a");
embark_assist::screen::paintString(lr_pen, 9, 1, DFHack::Screen::getKeyDisplay(df::interface_key::CURSOR_UP).c_str());
embark_assist::screen::paintString(white_pen, 10, 1, "/");
embark_assist::screen::paintString(lr_pen, 11, 1, DFHack::Screen::getKeyDisplay(df::interface_key::CURSOR_DOWN).c_str());
embark_assist::screen::paintString(white_pen, 12, 1, ":Up/Down");
embark_assist::screen::paintString(lr_pen, 21, 1, "ENTER");
embark_assist::screen::paintString(lr_pen, 21, 1, DFHack::Screen::getKeyDisplay(df::interface_key::SELECT).c_str());
embark_assist::screen::paintString(white_pen, 26, 1, ":Select");
embark_assist::screen::paintString(lr_pen, 34, 1, "f");
embark_assist::screen::paintString(lr_pen, 34, 1, DFHack::Screen::getKeyDisplay(df::interface_key::CUSTOM_F).c_str());
embark_assist::screen::paintString(white_pen, 35, 1, ":Find");
embark_assist::screen::paintString(lr_pen, 41, 1, "ESC");
embark_assist::screen::paintString(lr_pen, 41, 1, DFHack::Screen::getKeyDisplay(df::interface_key::LEAVESCREEN).c_str());
embark_assist::screen::paintString(white_pen, 44, 1, ":Abort");
embark_assist::screen::paintString(lr_pen, 51, 1, "s");
embark_assist::screen::paintString(lr_pen, 51, 1, DFHack::Screen::getKeyDisplay(df::interface_key::CUSTOM_S).c_str());
embark_assist::screen::paintString(white_pen, 52, 1, ":Save");
embark_assist::screen::paintString(lr_pen, 58, 1, "l");
embark_assist::screen::paintString(lr_pen, 58, 1, DFHack::Screen::getKeyDisplay(df::interface_key::CUSTOM_L).c_str());
embark_assist::screen::paintString(white_pen, 59, 1, ":Load");
for (uint16_t i = 0; i < state->finder_list.size(); i++) {

@ -189,7 +189,7 @@ namespace embark_assist{
help_text.push_back("f to activate the Find functionality using the values in the middle column.");
help_text.push_back("ESC to leave the screen without activating a Find operation.");
help_text.push_back("s/l is used to save/load search profile to/from embark_assistant_profile.txt");
help_text.push_back("stored in .\\data\\init. There's some minor error detection that will refuse");
help_text.push_back("stored in ./data/init. There's some minor error detection that will refuse");
help_text.push_back("to load a file that doesn't check out.");
help_text.push_back("The X and Y dimensions are those of the embark to search for. Unlike DF");
help_text.push_back("itself these parameters are initiated to match the actual embark rectangle");
@ -253,20 +253,21 @@ namespace embark_assist{
help_text.push_back(" Flux determination is made by finding the reaction PIG_IRON_MAKING.");
help_text.push_back("- Right world map overlay not implemented as author has failed to");
help_text.push_back(" emulate the sizing logic exactly.");
help_text.push_back("- There's currently a DF bug that causes adamantine spires reaching");
help_text.push_back(" that have been removed at world gen to fail to be generated. It's likely");
help_text.push_back(" this bug also affects magma pools. This plugin does not address this.");
help_text.push_back("- There's currently a DF bug (#0010267) that causes adamantine spires");
help_text.push_back(" reaching caverns that have been removed at world gen to fail to be");
help_text.push_back(" generated. It's likely this bug also affects magma pools.");
help_text.push_back(" This plugin does not address this but scripts can correct it.");
help_text.push_back("Version 0.3 2018-02-26");
break;
}
// Add control keys to first line.
embark_assist::screen::paintString(pen_lr, 1, 1, "TAB");
embark_assist::screen::paintString(pen_lr, 1, 1, DFHack::Screen::getKeyDisplay(df::interface_key::CHANGETAB).c_str());
embark_assist::screen::paintString(pen, 4, 1, "/");
embark_assist::screen::paintString(pen_lr, 5, 1, "Shift-TAB");
embark_assist::screen::paintString(pen_lr, 5, 1, DFHack::Screen::getKeyDisplay(df::interface_key::SEC_CHANGETAB).c_str());
embark_assist::screen::paintString(pen, 14, 1, ":Next/Previous Page");
embark_assist::screen::paintString(pen_lr, 34, 1, "ESC");
embark_assist::screen::paintString(pen_lr, 34, 1, DFHack::Screen::getKeyDisplay(df::interface_key::LEAVESCREEN).c_str());
embark_assist::screen::paintString(pen, 37, 1, ":Leave Info/Help");
for (uint16_t i = 0; i < help_text.size(); i++) {
@ -275,10 +276,10 @@ namespace embark_assist{
switch (current_page) {
case pages::Intro:
embark_assist::screen::paintString(pen_lr, 1, 26, "i");
embark_assist::screen::paintString(pen_lr, 1, 27, "f");
embark_assist::screen::paintString(pen_lr, 1, 28, "c");
embark_assist::screen::paintString(pen_lr, 1, 30, "q");
embark_assist::screen::paintString(pen_lr, 1, 26, DFHack::Screen::getKeyDisplay(df::interface_key::CUSTOM_I).c_str());
embark_assist::screen::paintString(pen_lr, 1, 27, DFHack::Screen::getKeyDisplay(df::interface_key::CUSTOM_F).c_str());
embark_assist::screen::paintString(pen_lr, 1, 28, DFHack::Screen::getKeyDisplay(df::interface_key::CUSTOM_C).c_str());
embark_assist::screen::paintString(pen_lr, 1, 30, DFHack::Screen::getKeyDisplay(df::interface_key::CUSTOM_Q).c_str());
break;
case pages::General:
@ -293,15 +294,15 @@ namespace embark_assist{
break;
case pages::Finder:
embark_assist::screen::paintString(pen_lr, 1, 4, "4");
embark_assist::screen::paintString(pen_lr, 3, 4, "6");
embark_assist::screen::paintString(pen_lr, 1, 5, "8");
embark_assist::screen::paintString(pen_lr, 3, 5, "2");
embark_assist::screen::paintString(pen_lr, 1, 6, "ENTER");
embark_assist::screen::paintString(pen_lr, 1, 7, "f");
embark_assist::screen::paintString(pen_lr, 1, 8, "ESC");
embark_assist::screen::paintString(pen_lr, 1, 9, "s");
embark_assist::screen::paintString(pen_lr, 3, 9, "l");
embark_assist::screen::paintString(pen_lr, 1, 4, DFHack::Screen::getKeyDisplay(df::interface_key::CURSOR_LEFT).c_str());
embark_assist::screen::paintString(pen_lr, 3, 4, DFHack::Screen::getKeyDisplay(df::interface_key::CURSOR_RIGHT).c_str());
embark_assist::screen::paintString(pen_lr, 1, 5, DFHack::Screen::getKeyDisplay(df::interface_key::CURSOR_UP).c_str());
embark_assist::screen::paintString(pen_lr, 3, 5, DFHack::Screen::getKeyDisplay(df::interface_key::CURSOR_DOWN).c_str());
embark_assist::screen::paintString(pen_lr, 1, 6, DFHack::Screen::getKeyDisplay(df::interface_key::SELECT).c_str());
embark_assist::screen::paintString(pen_lr, 1, 7, DFHack::Screen::getKeyDisplay(df::interface_key::CUSTOM_F).c_str());
embark_assist::screen::paintString(pen_lr, 1, 8, DFHack::Screen::getKeyDisplay(df::interface_key::LEAVESCREEN).c_str());
embark_assist::screen::paintString(pen_lr, 1, 9, DFHack::Screen::getKeyDisplay(df::interface_key::CUSTOM_S).c_str());
embark_assist::screen::paintString(pen_lr, 3, 9, DFHack::Screen::getKeyDisplay(df::interface_key::CUSTOM_L).c_str());
break;
case pages::Caveats: