|
@@ -13,7 +13,7 @@ Director::Director() {
|
|
|
BUGZ_LOG(warning) << "Director::Director()";
|
|
|
|
|
|
// active = false;
|
|
|
- game = 0; // not in a game
|
|
|
+ game = 0; // not in a game
|
|
|
galaxy.reset();
|
|
|
|
|
|
// do everything proxy_deactivate does ...
|
|
@@ -33,7 +33,7 @@ Director::Director() {
|
|
|
SF_portline = [this](const std::string &s) { this->SL_portline(s); };
|
|
|
SF_warpline = [this](const std::string &s) { this->SL_warpline(s); };
|
|
|
SF_infoline = [this](const std::string &s) { this->SL_infoline(s); };
|
|
|
- SF_densityline = [this](const std::string &s) {this->SL_densityline(s); };
|
|
|
+ SF_densityline = [this](const std::string &s) { this->SL_densityline(s); };
|
|
|
build_menu();
|
|
|
}
|
|
|
|
|
@@ -48,16 +48,16 @@ void Director::client_input(const std::string &input) {
|
|
|
}
|
|
|
|
|
|
if (active) {
|
|
|
- if (input == "Q" || input == "q") proxy_deactivate();
|
|
|
+ if (input == "Q" || input == "q")
|
|
|
+ proxy_deactivate();
|
|
|
return;
|
|
|
} else if (input == "\x1b" || input == "~") {
|
|
|
std::string &prompt = current_prompt;
|
|
|
BUGZ_LOG(trace) << "ACTIVATE prompt shows: [" << prompt << "]";
|
|
|
|
|
|
if (prompt == "Selection (? for menu): ") {
|
|
|
- to_client(
|
|
|
- "\n\rThere's not much we can do here. Activate in-game at a "
|
|
|
- "Command prompt.\n\r");
|
|
|
+ to_client("\n\rThere's not much we can do here. Activate in-game at a "
|
|
|
+ "Command prompt.\n\r");
|
|
|
to_client(current_raw_prompt);
|
|
|
return;
|
|
|
}
|
|
@@ -65,9 +65,8 @@ void Director::client_input(const std::string &input) {
|
|
|
// easter-eggs:
|
|
|
|
|
|
if (prompt == "Enter your choice: ") {
|
|
|
- to_client(
|
|
|
- "\n\r\x1b[1;36mI'd choose \x1b[1;37m`T`\x1b[1;36m, but "
|
|
|
- "that's how I was coded.\n\r");
|
|
|
+ to_client("\n\r\x1b[1;36mI'd choose \x1b[1;37m`T`\x1b[1;36m, but "
|
|
|
+ "that's how I was coded.\n\r");
|
|
|
to_client(current_raw_prompt);
|
|
|
return;
|
|
|
}
|
|
@@ -110,7 +109,8 @@ void Director::client_input(const std::string &input) {
|
|
|
}
|
|
|
}
|
|
|
// Ok...
|
|
|
- if (talk_direct) to_server(input);
|
|
|
+ if (talk_direct)
|
|
|
+ to_server(input);
|
|
|
|
|
|
/*
|
|
|
if (emit_client_input)
|
|
@@ -212,10 +212,14 @@ void Director::server_line(const std::string &line,
|
|
|
if (startswith(line, " Items Status Trading % of max OnBoard"))
|
|
|
SL_parser = SF_portline;
|
|
|
*/
|
|
|
- if (in(line, "==>")) SL_parser = SF_densityline;
|
|
|
- if (startswith(line, "Sector : ")) SL_parser = SF_sectorline;
|
|
|
- if (line == ": ") SL_parser = SF_cimline;
|
|
|
- if (line == "<Info>") SL_parser = SF_infoline;
|
|
|
+ if (in(line, "==>"))
|
|
|
+ SL_parser = SF_densityline;
|
|
|
+ if (startswith(line, "Sector : "))
|
|
|
+ SL_parser = SF_sectorline;
|
|
|
+ if (line == ": ")
|
|
|
+ SL_parser = SF_cimline;
|
|
|
+ if (line == "<Info>")
|
|
|
+ SL_parser = SF_infoline;
|
|
|
}
|
|
|
|
|
|
if (SL_parser) {
|
|
@@ -260,7 +264,8 @@ void Director::server_prompt(const std::string &prompt,
|
|
|
if (emit_server_prompt)
|
|
|
emit_server_prompt(prompt);
|
|
|
*/
|
|
|
- if (chain) chain->server_prompt(prompt);
|
|
|
+ if (chain)
|
|
|
+ chain->server_prompt(prompt);
|
|
|
}
|
|
|
|
|
|
void Director::build_menu(void) {
|
|
@@ -271,9 +276,8 @@ void Director::build_menu(void) {
|
|
|
md->menu_title = "Proxy Menu";
|
|
|
md->menu_options_color = "\x1b[1;36;40m";
|
|
|
|
|
|
- md->menu_prompt =
|
|
|
- "\x1b[0;31;40m\xdb\xb2\xb1\xb0 \x1b[31;40mRED "
|
|
|
- "\x1b[32;40mGREEN\x1b[30;42m\xdb\xb2\xb1\xb0 \x1b[0m : ";
|
|
|
+ md->menu_prompt = "\x1b[0;31;40m\xdb\xb2\xb1\xb0 \x1b[31;40mRED "
|
|
|
+ "\x1b[32;40mGREEN\x1b[30;42m\xdb\xb2\xb1\xb0 \x1b[0m : ";
|
|
|
md->lazy = true;
|
|
|
md->menu = {{"C", "Configure"},
|
|
|
{"D", "Display Report"},
|
|
@@ -291,8 +295,8 @@ void Director::build_menu(void) {
|
|
|
}
|
|
|
|
|
|
void Director::proxy_activate(void) {
|
|
|
- active = true; // yes, set keep-alive timer.
|
|
|
- to_server(" "); // start keep-alive timer.
|
|
|
+ active = true; // yes, set keep-alive timer.
|
|
|
+ to_server(" "); // start keep-alive timer.
|
|
|
|
|
|
// set other values we need
|
|
|
talk_direct = false;
|
|
@@ -344,97 +348,99 @@ void Director::menu_choice(void) {
|
|
|
return;
|
|
|
} else {
|
|
|
switch (md->input[0]) {
|
|
|
- case 'C': // configure
|
|
|
- config_edit();
|
|
|
- return;
|
|
|
- break;
|
|
|
- case 'D':
|
|
|
- case 'T': // display trading report
|
|
|
- {
|
|
|
- auto pptv = galaxy.find_best_trades();
|
|
|
- std::string output;
|
|
|
- galaxy.sort_port_pair_type(pptv);
|
|
|
-
|
|
|
- int max_display = 20;
|
|
|
- if (galaxy.config["display_lines"])
|
|
|
- max_display = galaxy.config["display_lines"].as<int>();
|
|
|
- else
|
|
|
- galaxy.config["display_lines"] = max_display;
|
|
|
-
|
|
|
- if ((max_display <= 0) || (max_display > 255)) {
|
|
|
- max_display = 255;
|
|
|
- galaxy.config["display_lines"] = 255;
|
|
|
- }
|
|
|
- const int per_line = 5;
|
|
|
- int count = 0;
|
|
|
- int line = 0;
|
|
|
- for (auto const &ppt : pptv) {
|
|
|
- output = str(boost::format("%1$5d:%2$-5d(%3$d) ") % ppt.s1 %
|
|
|
- ppt.s2 % ppt.type);
|
|
|
- to_client(output);
|
|
|
- ++count;
|
|
|
- if (count == per_line) {
|
|
|
- count = 0;
|
|
|
- to_client("\n\r");
|
|
|
- ++line;
|
|
|
- }
|
|
|
-
|
|
|
- if (line == max_display) break;
|
|
|
- }
|
|
|
- if (count != 0) to_client("\n\r");
|
|
|
- // We got < 5 lines, and max_display is > 5. Offer suggestion:
|
|
|
- if ((line < 5) && (max_display > 5)) {
|
|
|
- // suggestion:
|
|
|
- to_client(
|
|
|
- "HINT: For more lines, try reducing the burnt_percent?\n\r");
|
|
|
- }
|
|
|
- } break;
|
|
|
- case 'E': // Export Data/Save
|
|
|
- to_client("Saving...");
|
|
|
- galaxy.save();
|
|
|
- to_client("\rSaved....\n\r");
|
|
|
- break;
|
|
|
- case 'I': // Information
|
|
|
- information();
|
|
|
- break;
|
|
|
- case 'P': // Port CIM
|
|
|
- // Since we're adding/updating, we don't lose our
|
|
|
- // type 0 ports. Type 9 stays at 9.
|
|
|
- chain = cim;
|
|
|
- to_server("^RQ");
|
|
|
- {
|
|
|
- std::string text = str(boost::format("Port CIM Report (%1%)\n\r") %
|
|
|
- galaxy.ports.size());
|
|
|
- // to_client("Port CIM Report\n\r");
|
|
|
- to_client(text);
|
|
|
- }
|
|
|
- chain->activate();
|
|
|
- return;
|
|
|
- break;
|
|
|
- case 'W': // Warp CIM
|
|
|
- chain = cim;
|
|
|
- to_server("^IQ");
|
|
|
- {
|
|
|
- std::string text = str(boost::format("Warp CIM Report (%1%)\n\r") %
|
|
|
- galaxy.warps.size());
|
|
|
- // to_client("Warp CIM Report\n\r");
|
|
|
- to_client(text);
|
|
|
+ case 'C': // configure
|
|
|
+ config_edit();
|
|
|
+ return;
|
|
|
+ break;
|
|
|
+ case 'D':
|
|
|
+ case 'T': // display trading report
|
|
|
+ {
|
|
|
+ auto pptv = galaxy.find_best_trades();
|
|
|
+ std::string output;
|
|
|
+ galaxy.sort_port_pair_type(pptv);
|
|
|
+
|
|
|
+ int max_display = 20;
|
|
|
+ if (galaxy.config["display_lines"])
|
|
|
+ max_display = galaxy.config["display_lines"].as<int>();
|
|
|
+ else
|
|
|
+ galaxy.config["display_lines"] = max_display;
|
|
|
+
|
|
|
+ if ((max_display <= 0) || (max_display > 255)) {
|
|
|
+ max_display = 255;
|
|
|
+ galaxy.config["display_lines"] = 255;
|
|
|
+ }
|
|
|
+ const int per_line = 5;
|
|
|
+ int count = 0;
|
|
|
+ int line = 0;
|
|
|
+ for (auto const &ppt : pptv) {
|
|
|
+ output = str(boost::format("%1$5d:%2$-5d(%3$d) ") % ppt.s1 % ppt.s2 %
|
|
|
+ ppt.type);
|
|
|
+ to_client(output);
|
|
|
+ ++count;
|
|
|
+ if (count == per_line) {
|
|
|
+ count = 0;
|
|
|
+ to_client("\n\r");
|
|
|
+ ++line;
|
|
|
}
|
|
|
- chain->activate();
|
|
|
- return;
|
|
|
- break;
|
|
|
- // case 'T': // Trading Report
|
|
|
- // break;
|
|
|
- case 'S': // Scripts
|
|
|
+
|
|
|
+ if (line == max_display)
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (count != 0)
|
|
|
+ to_client("\n\r");
|
|
|
+ // We got < 5 lines, and max_display is > 5. Offer suggestion:
|
|
|
+ if ((line < 5) && (max_display > 5)) {
|
|
|
+ // suggestion:
|
|
|
+ to_client(
|
|
|
+ "HINT: For more lines, try reducing the burnt_percent?\n\r");
|
|
|
+ }
|
|
|
+ } break;
|
|
|
+ case 'E': // Export Data/Save
|
|
|
+ to_client("Saving...");
|
|
|
+ galaxy.save();
|
|
|
+ to_client("\rSaved....\n\r");
|
|
|
+ break;
|
|
|
+ case 'I': // Information
|
|
|
+ information();
|
|
|
+ break;
|
|
|
+ case 'P': // Port CIM
|
|
|
+ // Since we're adding/updating, we don't lose our
|
|
|
+ // type 0 ports. Type 9 stays at 9.
|
|
|
+ chain = cim;
|
|
|
+ to_server("^RQ");
|
|
|
{
|
|
|
- init_scripts_menu();
|
|
|
- chain = scripts_menu;
|
|
|
- chain->activate();
|
|
|
- return;
|
|
|
- } break;
|
|
|
- case 'X': // Exit
|
|
|
- proxy_deactivate();
|
|
|
- return;
|
|
|
+ std::string text = str(boost::format("Port CIM Report (%1%)\n\r") %
|
|
|
+ galaxy.ports.size());
|
|
|
+ // to_client("Port CIM Report\n\r");
|
|
|
+ to_client(text);
|
|
|
+ }
|
|
|
+ chain->activate();
|
|
|
+ return;
|
|
|
+ break;
|
|
|
+ case 'W': // Warp CIM
|
|
|
+ chain = cim;
|
|
|
+ to_server("^IQ");
|
|
|
+ {
|
|
|
+ std::string text = str(boost::format("Warp CIM Report (%1%)\n\r") %
|
|
|
+ galaxy.warps.size());
|
|
|
+ // to_client("Warp CIM Report\n\r");
|
|
|
+ to_client(text);
|
|
|
+ }
|
|
|
+ chain->activate();
|
|
|
+ return;
|
|
|
+ break;
|
|
|
+ // case 'T': // Trading Report
|
|
|
+ // break;
|
|
|
+ case 'S': // Scripts
|
|
|
+ {
|
|
|
+ init_scripts_menu();
|
|
|
+ chain = scripts_menu;
|
|
|
+ chain->activate();
|
|
|
+ return;
|
|
|
+ } break;
|
|
|
+ case 'X': // Exit
|
|
|
+ proxy_deactivate();
|
|
|
+ return;
|
|
|
}
|
|
|
/*
|
|
|
std::string text = str(
|
|
@@ -480,45 +486,45 @@ void Director::scripts_done(void) {
|
|
|
return;
|
|
|
} else {
|
|
|
switch (md->input[0]) {
|
|
|
- case 'T': // Trade
|
|
|
- {
|
|
|
- script = std::make_shared<ScriptTrader>(*this);
|
|
|
- ScriptTrader *ts = static_cast<ScriptTrader *>(&((*script)));
|
|
|
- ts->setNotify([this]() { this->proxy_deactivate(); });
|
|
|
-
|
|
|
- // Set parameters
|
|
|
- auto found = galaxy.find_trades(current_sector, false);
|
|
|
- if (found.empty()) {
|
|
|
- to_client(
|
|
|
- "No Trades found. Port burnt (CONFIG: lower burnt_percent?) "
|
|
|
- "or no ports around.\n\r");
|
|
|
- proxy_deactivate();
|
|
|
- return;
|
|
|
- }
|
|
|
- // sort first?
|
|
|
- galaxy.sort_port_pair_type(found);
|
|
|
-
|
|
|
- BUGZ_LOG(fatal) << "Found " << found.size() << " possible trade(s).";
|
|
|
- BUGZ_LOG(fatal) << found[0].s1 << "," << found[0].s2 << " : "
|
|
|
- << found[0].type;
|
|
|
- ts->port[0] = found[0].s1;
|
|
|
- ts->port[1] = found[0].s2;
|
|
|
- ts->type = found[0].type;
|
|
|
- chain = script;
|
|
|
- chain->activate();
|
|
|
+ case 'T': // Trade
|
|
|
+ {
|
|
|
+ script = std::make_shared<ScriptTrader>(*this);
|
|
|
+ ScriptTrader *ts = static_cast<ScriptTrader *>(&((*script)));
|
|
|
+ ts->setNotify([this]() { this->proxy_deactivate(); });
|
|
|
+
|
|
|
+ // Set parameters
|
|
|
+ auto found = galaxy.find_trades(current_sector, false);
|
|
|
+ if (found.empty()) {
|
|
|
+ to_client(
|
|
|
+ "No Trades found. Port burnt (CONFIG: lower burnt_percent?) "
|
|
|
+ "or no ports around.\n\r");
|
|
|
+ proxy_deactivate();
|
|
|
return;
|
|
|
- } break;
|
|
|
- case '!': {
|
|
|
- auto best = galaxy.find_closest(current_sector);
|
|
|
- if (best.type != 0) {
|
|
|
- std::string text =
|
|
|
- str(boost::format("Best/Closest: %1% with %2% & %3%\n\r") %
|
|
|
- best.type % best.s1 % best.s2);
|
|
|
- to_client(text);
|
|
|
- } else {
|
|
|
- to_client("I don't see any best trades.\n\r");
|
|
|
- }
|
|
|
- } break;
|
|
|
+ }
|
|
|
+ // sort first?
|
|
|
+ galaxy.sort_port_pair_type(found);
|
|
|
+
|
|
|
+ BUGZ_LOG(fatal) << "Found " << found.size() << " possible trade(s).";
|
|
|
+ BUGZ_LOG(fatal) << found[0].s1 << "," << found[0].s2 << " : "
|
|
|
+ << found[0].type;
|
|
|
+ ts->port[0] = found[0].s1;
|
|
|
+ ts->port[1] = found[0].s2;
|
|
|
+ ts->type = found[0].type;
|
|
|
+ chain = script;
|
|
|
+ chain->activate();
|
|
|
+ return;
|
|
|
+ } break;
|
|
|
+ case '!': {
|
|
|
+ auto best = galaxy.find_closest(current_sector);
|
|
|
+ if (best.type != 0) {
|
|
|
+ std::string text =
|
|
|
+ str(boost::format("Best/Closest: %1% with %2% & %3%\n\r") %
|
|
|
+ best.type % best.s1 % best.s2);
|
|
|
+ to_client(text);
|
|
|
+ } else {
|
|
|
+ to_client("I don't see any best trades.\n\r");
|
|
|
+ }
|
|
|
+ } break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -761,7 +767,8 @@ void Director::SL_thiefline(const std::string &line) {
|
|
|
SL_parser = nullptr;
|
|
|
} else {
|
|
|
pos = line.find("(You realize the guards saw you last time!)");
|
|
|
- if (pos != line.npos) SL_parser = nullptr;
|
|
|
+ if (pos != line.npos)
|
|
|
+ SL_parser = nullptr;
|
|
|
}
|
|
|
|
|
|
// Are those the two ways to exit from this state?
|
|
@@ -823,12 +830,13 @@ void Director::SL_sectorline(const std::string &line) {
|
|
|
|
|
|
void Director::SL_densityline(const std::string &line) {
|
|
|
BUGZ_LOG(fatal) << "densityline: [" << line << "]";
|
|
|
- if(line.empty()) {
|
|
|
+ if (line.empty()) {
|
|
|
SL_parser = nullptr;
|
|
|
return;
|
|
|
}
|
|
|
// Ensure this really is a density scan and not something else
|
|
|
- if(not in(line, "Sector") or not in(line, "Warps") or not in(line, "NavHaz") or not in(line, "Anom")) {
|
|
|
+ if (!in(line, "Sector") || !in(line, "Warps") ||
|
|
|
+ !in(line, "NavHaz") || !in(line, "Anom")) {
|
|
|
BUGZ_LOG(fatal) << "densityline: Invalid line.";
|
|
|
SL_parser = nullptr;
|
|
|
return;
|
|
@@ -847,7 +855,7 @@ void Director::SL_densityline(const std::string &line) {
|
|
|
*/
|
|
|
std::string work = line;
|
|
|
replace(work, ":", "");
|
|
|
- bool known = not in(work, "(");
|
|
|
+ bool known = !in(work, "(");
|
|
|
replace(work, "(", "");
|
|
|
replace(work, ")", "");
|
|
|
replace(work, "%", "");
|
|
@@ -859,12 +867,10 @@ void Director::SL_densityline(const std::string &line) {
|
|
|
int navhaz = std::stoi(dense.at(7));
|
|
|
bool anom = in(dense.at(9), "Yes");
|
|
|
// Commit data
|
|
|
- BUGZ_LOG(warning) << "densityline: {sector=" << sector <<
|
|
|
- " density=" << density <<
|
|
|
- " warps=" << warps <<
|
|
|
- " navhaz=" << navhaz <<
|
|
|
- " anom=" << anom <<
|
|
|
- " known=" << known << "}";
|
|
|
+ BUGZ_LOG(warning) << "densityline: {sector=" << sector
|
|
|
+ << " density=" << density << " warps=" << warps
|
|
|
+ << " navhaz=" << navhaz << " anom=" << anom
|
|
|
+ << " known=" << known << "}";
|
|
|
if (galaxy.meta["density"][sector]) {
|
|
|
galaxy.meta["density"][sector] = YAML::Node();
|
|
|
}
|
|
@@ -909,14 +915,16 @@ void Director::SL_portline(const std::string &line) {
|
|
|
replace(work, "Fuel Ore", "Fuel");
|
|
|
auto parts = split(work);
|
|
|
|
|
|
- if (parts[0] == "Items") return;
|
|
|
+ if (parts[0] == "Items")
|
|
|
+ return;
|
|
|
|
|
|
char c = tolower(parts[0][0]);
|
|
|
int pos;
|
|
|
char foe[4] = "foe";
|
|
|
|
|
|
for (pos = 0; pos < 3; ++pos) {
|
|
|
- if (c == foe[pos]) break;
|
|
|
+ if (c == foe[pos])
|
|
|
+ break;
|
|
|
}
|
|
|
int amount = stoi(parts[2]);
|
|
|
int percent = stoi(parts[3]);
|
|
@@ -936,7 +944,8 @@ void Director::SL_portline(const std::string &line) {
|
|
|
*/
|
|
|
|
|
|
// Here's the end:
|
|
|
- if (parts[0] == "Equipment") SL_parser = nullptr;
|
|
|
+ if (parts[0] == "Equipment")
|
|
|
+ SL_parser = nullptr;
|
|
|
|
|
|
// BUGZ_LOG(fatal) << "portline split : [" << parts << "]";
|
|
|
}
|
|
@@ -1015,7 +1024,7 @@ void Director::SL_infoline(const std::string &line) {
|
|
|
galaxy.meta["turns"] = -1;
|
|
|
} else {
|
|
|
int turns =
|
|
|
- stoi(text); // galaxy.meta["info"]["Turns left"].as<int>();
|
|
|
+ stoi(text); // galaxy.meta["info"]["Turns left"].as<int>();
|
|
|
BUGZ_LOG(fatal) << "Turns left: " << turns;
|
|
|
galaxy.meta["turns"] = turns;
|
|
|
}
|