Browse Source

Try again on We're not interested.

Steve Thielemann 3 years ago
parent
commit
3e601c48e2
3 changed files with 26 additions and 9 deletions
  1. 1 1
      buysell.h
  2. 23 7
      dispatchers.cpp
  3. 2 1
      dispatchers.h

+ 1 - 1
buysell.h

@@ -12,7 +12,7 @@ enum PRODUCT { FUEL = 0, ORG = 1, EQU = 2 };
 
 // typedef std::array<bool, 3> buysell;
 struct buysell {
-  bool foe[3];
+  bool foe[3]; // TRUE = BUY
   bool operator==(const buysell& rhs) const;
   friend std::ostream& operator<<(std::ostream& os, const buysell& bs);
 };

+ 23 - 7
dispatchers.cpp

@@ -777,7 +777,7 @@ TraderDispatch::~TraderDispatch() { BUGZ_LOG(fatal) << "~TraderDispatch()"; }
 
 void TraderDispatch::activate(void) {
   // ok, lookup port1 port2
-  BUGZ_LOG(fatal) << "STraderDispatch::activate " << port[0] << " & " << port[1];
+  BUGZ_LOG(fatal) << "TraderDispatch::activate " << port[0] << " & " << port[1];
   auto port_info = director.galaxy.ports.find(port[0]);
   int port0_type = port_info->second.type;
   port_buysell[0] = get_buysell(port0_type);
@@ -853,6 +853,7 @@ void TraderDispatch::server_line(const std::string &line,
     last_offer = 0;
     final_offer = 0;
     initial_offer = 0;
+    try_again = false;
   }
 
   static std::set<std::string> success_lines = {
@@ -929,6 +930,11 @@ void TraderDispatch::server_line(const std::string &line,
     BUGZ_LOG(fatal) << "Final offer: " << final_offer;
   }
 
+  if (line == "We're not interested.") {
+    // well rats.
+    try_again = true;
+  }
+
   // SL: [You have 16,767 credits and 0 empty cargo holds.]
   // trade accepted.  if not 0 empty cargo holds -- we failed!
   // SL: [<P-Probe estimates your offer was  91.83% of best price>]
@@ -941,15 +947,17 @@ void TraderDispatch::server_line(const std::string &line,
       // Ok, the offer was possibly accepted.
       int success;
       if (buying)
-        success = 0;
-      else
         success = director.galaxy.meta["ship"]["holds"]["total"].as<int>();
+      else
+        success = 0;
 
       std::string text = std::to_string(success);
       text.append(" empty cargo holds.");
       if (endswith(line, text)) {
         BUGZ_LOG(fatal) << "Trade SUCCESS!";
         // record this action somewhere in meta.
+      } else {
+        BUGZ_LOG(fatal) << "Trade FAIL";
       }
     }
   }
@@ -993,11 +1001,11 @@ void TraderDispatch::server_prompt(const std::string &prompt) {
         if (!all_holds_empty) {
           for (int x = 0; x < 3; ++x) {
             if (director.galaxy.meta["ship"]["holds"][foe[x]]) {
-              if (port_buysell[0].foe[x]) {
+              if (!port_buysell[0].foe[x]) {
                 active_port = port[0];
                 break;
               }
-              if (port_buysell[1].foe[x]) {
+              if (!port_buysell[1].foe[x]) {
                 active_port = port[1];
               }
             }
@@ -1013,11 +1021,12 @@ void TraderDispatch::server_prompt(const std::string &prompt) {
           // all holds empty, find selling port
           for (int x = 0; x < 3; ++x) {
             if (trades.foe[x]) {
-              if (port_buysell[0].foe[x]) {
+              // TRUE = BUY, so FALSE = sell
+              if (!port_buysell[0].foe[x]) {
                 active_port = port[0];
                 break;
               }
-              if (port_buysell[1].foe[x]) {
+              if (!port_buysell[1].foe[x]) {
                 active_port = port[1];
                 break;
               }
@@ -1153,6 +1162,13 @@ void TraderDispatch::server_prompt(const std::string &prompt) {
       // 1.) CHECK TURNS // need turn tracking
       // 2.) PORTS BURNT?
 
+      if (try_again) {
+        state = 3;
+        to_client("Trading... Take 2!\n\r");
+        to_server("PT");
+        return;
+      }
+
       if (active_port == port[0]) {
         if (port[0] == 0) {
           deactivate();

+ 2 - 1
dispatchers.h

@@ -177,7 +177,8 @@ class TraderDispatch : public Dispatch {
   int final_offer;
   int product; // product we are buying/selling 0,1,2 foe.
   int stop_percent;
-
+  bool try_again;
+  
   // should this be 0/1 ?  right now it is the port's sector number.
   int active_port;  // port trading with
   // information from the find_best_trades function + others.