|
@@ -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 ...
|
|
@@ -34,6 +34,9 @@ Director::Director() {
|
|
|
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_computer_portline = [this](const std::string &s) {
|
|
|
+ this->SL_computer_portline(s);
|
|
|
+ };
|
|
|
build_menu();
|
|
|
}
|
|
|
|
|
@@ -48,16 +51,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,8 +68,9 @@ 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;
|
|
|
}
|
|
@@ -109,8 +113,7 @@ 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,14 +215,18 @@ 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 (startswith(line, "What sector is the port in? [")) {
|
|
|
+ // Computer Port Report
|
|
|
+ // SL: [What sector is the port in? [611] 4]
|
|
|
+ size_t pos = line.rfind(' ');
|
|
|
+
|
|
|
+ computer_port_sector = stoi(line.substr(pos));
|
|
|
+ SL_parser = SF_computer_portline;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (SL_parser) {
|
|
@@ -264,8 +271,7 @@ 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) {
|
|
@@ -276,8 +282,9 @@ 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"},
|
|
@@ -295,8 +302,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;
|
|
@@ -348,99 +355,97 @@ 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");
|
|
|
+ case 'C': // configure
|
|
|
+ config_edit();
|
|
|
+ return;
|
|
|
+ break;
|
|
|
+ case 'D':
|
|
|
+ case 'T': // display trading report
|
|
|
{
|
|
|
- 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");
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ chain->activate();
|
|
|
+ return;
|
|
|
+ break;
|
|
|
+ // case 'T': // Trading Report
|
|
|
+ // break;
|
|
|
+ case 'S': // Scripts
|
|
|
{
|
|
|
- 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;
|
|
|
+ init_scripts_menu();
|
|
|
+ chain = scripts_menu;
|
|
|
+ chain->activate();
|
|
|
+ return;
|
|
|
+ } break;
|
|
|
+ case 'X': // Exit
|
|
|
+ proxy_deactivate();
|
|
|
+ return;
|
|
|
}
|
|
|
/*
|
|
|
std::string text = str(
|
|
@@ -486,45 +491,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();
|
|
|
+ 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();
|
|
|
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();
|
|
|
- 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;
|
|
|
+ } 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;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -767,8 +772,7 @@ 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?
|
|
@@ -835,8 +839,8 @@ void Director::SL_densityline(const std::string &line) {
|
|
|
return;
|
|
|
}
|
|
|
// Ensure this really is a density scan and not something else
|
|
|
- if (!in(line, "Sector") || !in(line, "Warps") ||
|
|
|
- !in(line, "NavHaz") || !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;
|
|
@@ -915,16 +919,14 @@ 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]);
|
|
@@ -944,8 +946,7 @@ 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 << "]";
|
|
|
}
|
|
@@ -1024,7 +1025,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;
|
|
|
}
|
|
@@ -1060,4 +1061,62 @@ void Director::SL_infoline(const std::string &line) {
|
|
|
galaxy.meta["info"][key] = value;
|
|
|
BUGZ_LOG(fatal) << "Info: " << key << " : " << value;
|
|
|
}
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+void Director::SL_computer_portline(const std::string &line) {
|
|
|
+ if (startswith(line, "What sector is the port in?"))
|
|
|
+ computer_port_done = false;
|
|
|
+
|
|
|
+ if (line == "I have no information about a port in that sector.") {
|
|
|
+ computer_port_sector = 0;
|
|
|
+ SL_parser = nullptr;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!computer_port_done) {
|
|
|
+ if (in(line, "Fuel Ore")) computer_port_done = true;
|
|
|
+ if (in(line, "Cargo holds")) {
|
|
|
+ // If I want to scan the class type 0 ports:
|
|
|
+ // computer_port_done = true;
|
|
|
+ // otherwise:
|
|
|
+ SL_parser = nullptr;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (computer_port_done) {
|
|
|
+ if (line.empty()) {
|
|
|
+ SL_parser = nullptr;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // scan for items of interest
|
|
|
+ // SL: [Fuel Ore Buying 810 100% 0]
|
|
|
+ // SL: [Organics Buying 856 57% 0]
|
|
|
+ // SL: [Equipment Selling 922 44% 0]
|
|
|
+ std::string work = line;
|
|
|
+ replace(work, "Fuel Ore", "Fuel");
|
|
|
+ replace(work, "%", "");
|
|
|
+ auto parts = split(work);
|
|
|
+
|
|
|
+ char c = tolower(parts[0][0]);
|
|
|
+ int pos;
|
|
|
+ char foe[4] = "foe";
|
|
|
+
|
|
|
+ for (pos = 0; pos < 3; ++pos) {
|
|
|
+ if (c == foe[pos]) break;
|
|
|
+ }
|
|
|
+
|
|
|
+ int amount = stoi(parts[2]);
|
|
|
+ int percent = stoi(parts[3]);
|
|
|
+
|
|
|
+ // update port
|
|
|
+ auto port = galaxy.ports.find(computer_port_sector);
|
|
|
+ if (port != galaxy.ports.end()) {
|
|
|
+ BUGZ_LOG(info) << "COM PORT " << computer_port_sector << " " << c << " "
|
|
|
+ << amount << " " << percent;
|
|
|
+ port->second.amount[pos] = amount;
|
|
|
+ port->second.percent[pos] = percent;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|