Pārlūkot izejas kodu

computer port report.

Steve Thielemann 3 gadi atpakaļ
vecāks
revīzija
d677c09c63
2 mainītis faili ar 229 papildinājumiem un 165 dzēšanām
  1. 223 164
      director.cpp
  2. 6 1
      director.h

+ 223 - 164
director.cpp

@@ -13,7 +13,7 @@ Director::Director() {
   BUGZ_LOG(warning) << "Director::Director()";
   BUGZ_LOG(warning) << "Director::Director()";
 
 
   // active = false;
   // active = false;
-  game = 0; // not in a game
+  game = 0;  // not in a game
   galaxy.reset();
   galaxy.reset();
 
 
   // do everything proxy_deactivate does ...
   // do everything proxy_deactivate does ...
@@ -34,6 +34,9 @@ Director::Director() {
   SF_warpline = [this](const std::string &s) { this->SL_warpline(s); };
   SF_warpline = [this](const std::string &s) { this->SL_warpline(s); };
   SF_infoline = [this](const std::string &s) { this->SL_infoline(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); };
+  SF_computer_portline = [this](const std::string &s) {
+    this->SL_computer_portline(s);
+  };
   build_menu();
   build_menu();
 }
 }
 
 
@@ -48,16 +51,16 @@ void Director::client_input(const std::string &input) {
   }
   }
 
 
   if (active) {
   if (active) {
-    if (input == "Q" || input == "q")
-      proxy_deactivate();
+    if (input == "Q" || input == "q") proxy_deactivate();
     return;
     return;
   } else if (input == "\x1b" || input == "~") {
   } else if (input == "\x1b" || input == "~") {
     std::string &prompt = current_prompt;
     std::string &prompt = current_prompt;
     BUGZ_LOG(trace) << "ACTIVATE prompt shows: [" << prompt << "]";
     BUGZ_LOG(trace) << "ACTIVATE prompt shows: [" << prompt << "]";
 
 
     if (prompt == "Selection (? for menu): ") {
     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);
       to_client(current_raw_prompt);
       return;
       return;
     }
     }
@@ -65,8 +68,9 @@ void Director::client_input(const std::string &input) {
     // easter-eggs:
     // easter-eggs:
 
 
     if (prompt == "Enter your choice: ") {
     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);
       to_client(current_raw_prompt);
       return;
       return;
     }
     }
@@ -109,8 +113,7 @@ void Director::client_input(const std::string &input) {
     }
     }
   }
   }
   // Ok...
   // Ok...
-  if (talk_direct)
-    to_server(input);
+  if (talk_direct) to_server(input);
 
 
   /*
   /*
   if (emit_client_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"))
     if (startswith(line, " Items     Status  Trading % of max OnBoard"))
       SL_parser = SF_portline;
       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) {
   if (SL_parser) {
@@ -264,8 +271,7 @@ void Director::server_prompt(const std::string &prompt,
   if (emit_server_prompt)
   if (emit_server_prompt)
     emit_server_prompt(prompt);
     emit_server_prompt(prompt);
    */
    */
-  if (chain)
-    chain->server_prompt(prompt);
+  if (chain) chain->server_prompt(prompt);
 }
 }
 
 
 void Director::build_menu(void) {
 void Director::build_menu(void) {
@@ -276,8 +282,9 @@ void Director::build_menu(void) {
   md->menu_title = "Proxy Menu";
   md->menu_title = "Proxy Menu";
   md->menu_options_color = "\x1b[1;36;40m";
   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->lazy = true;
   md->menu = {{"C", "Configure"},
   md->menu = {{"C", "Configure"},
               {"D", "Display Report"},
               {"D", "Display Report"},
@@ -295,8 +302,8 @@ void Director::build_menu(void) {
 }
 }
 
 
 void Director::proxy_activate(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
   // set other values we need
   talk_direct = false;
   talk_direct = false;
@@ -348,99 +355,97 @@ void Director::menu_choice(void) {
       return;
       return;
     } else {
     } else {
       switch (md->input[0]) {
       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(
       std::string text = str(
@@ -486,45 +491,45 @@ void Director::scripts_done(void) {
       return;
       return;
     } else {
     } else {
       switch (md->input[0]) {
       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;
           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;
     SL_parser = nullptr;
   } else {
   } else {
     pos = line.find("(You realize the guards saw you last time!)");
     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?
   // Are those the two ways to exit from this state?
@@ -835,8 +839,8 @@ void Director::SL_densityline(const std::string &line) {
     return;
     return;
   }
   }
   // Ensure this really is a density scan and not something else
   // 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.";
     BUGZ_LOG(fatal) << "densityline: Invalid line.";
     SL_parser = nullptr;
     SL_parser = nullptr;
     return;
     return;
@@ -915,16 +919,14 @@ void Director::SL_portline(const std::string &line) {
     replace(work, "Fuel Ore", "Fuel");
     replace(work, "Fuel Ore", "Fuel");
     auto parts = split(work);
     auto parts = split(work);
 
 
-    if (parts[0] == "Items")
-      return;
+    if (parts[0] == "Items") return;
 
 
     char c = tolower(parts[0][0]);
     char c = tolower(parts[0][0]);
     int pos;
     int pos;
     char foe[4] = "foe";
     char foe[4] = "foe";
 
 
     for (pos = 0; pos < 3; ++pos) {
     for (pos = 0; pos < 3; ++pos) {
-      if (c == foe[pos])
-        break;
+      if (c == foe[pos]) break;
     }
     }
     int amount = stoi(parts[2]);
     int amount = stoi(parts[2]);
     int percent = stoi(parts[3]);
     int percent = stoi(parts[3]);
@@ -944,8 +946,7 @@ void Director::SL_portline(const std::string &line) {
     */
     */
 
 
     // Here's the end:
     // Here's the end:
-    if (parts[0] == "Equipment")
-      SL_parser = nullptr;
+    if (parts[0] == "Equipment") SL_parser = nullptr;
 
 
     // BUGZ_LOG(fatal) << "portline split : [" << parts << "]";
     // BUGZ_LOG(fatal) << "portline split : [" << parts << "]";
   }
   }
@@ -1024,7 +1025,7 @@ void Director::SL_infoline(const std::string &line) {
           galaxy.meta["turns"] = -1;
           galaxy.meta["turns"] = -1;
         } else {
         } else {
           int turns =
           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;
           BUGZ_LOG(fatal) << "Turns left: " << turns;
           galaxy.meta["turns"] = turns;
           galaxy.meta["turns"] = turns;
         }
         }
@@ -1060,4 +1061,62 @@ void Director::SL_infoline(const std::string &line) {
     galaxy.meta["info"][key] = value;
     galaxy.meta["info"][key] = value;
     BUGZ_LOG(fatal) << "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;
+    }
+  }
+}

+ 6 - 1
director.h

@@ -85,15 +85,20 @@ class Director {
   std::string config_item;  // current item being edited
   std::string config_item;  // current item being edited
 
 
   StringFunc SL_parser;
   StringFunc SL_parser;
-  StringFunc SF_cimline, SF_sectorline, SF_portline, SF_warpline, SF_infoline, SF_densityline;
+  StringFunc SF_cimline, SF_sectorline, SF_portline, SF_warpline, SF_infoline,
+      SF_densityline, SF_computer_portline;
 
 
   void SL_cimline(const std::string &line);
   void SL_cimline(const std::string &line);
   void SL_thiefline(const std::string &line);
   void SL_thiefline(const std::string &line);
   void SL_sectorline(const std::string &line);
   void SL_sectorline(const std::string &line);
   void SL_portline(const std::string &line);
   void SL_portline(const std::string &line);
+  void SL_computer_portline(const std::string &line);
   void SL_warpline(const std::string &line);
   void SL_warpline(const std::string &line);
   void SL_infoline(const std::string &line);
   void SL_infoline(const std::string &line);
   void SL_densityline(const std::string &line);
   void SL_densityline(const std::string &line);
+
+  int computer_port_sector;
+  bool computer_port_done;
 };
 };
 
 
 #include "dispatchers.h"
 #include "dispatchers.h"