Преглед изворни кода

Finally! We're able to check amounts/is burnt.

I might need to optimize this a bit.  Have the total holds
looked up just once...
Steve Thielemann пре 3 година
родитељ
комит
d7f80cbf08
1 измењених фајлова са 26 додато и 11 уклоњено
  1. 26 11
      dispatchers.cpp

+ 26 - 11
dispatchers.cpp

@@ -908,14 +908,11 @@ void TraderDispatch::server_line(const std::string &line,
     auto port = director.galaxy.ports.find(active_port);
     if (port != director.galaxy.ports.end()) {
       // We've found the port!
-      for (int x = 0; x < 4; x++ ) {
-        if (foe[x] == product) {
-          // We have the index
-          port->second.amount[x] -= director.galaxy.meta["ship"]["holds"]["total"].as<int>();
-          BUGZ_LOG(fatal) << "Port " << active_port << "," << product << " amount is now " << port->second.amount[x];
-          break;
-        }
-      }
+      // product is the index
+      port->second.amount[product] -=
+          director.galaxy.meta["ship"]["holds"]["total"].as<int>();
+      BUGZ_LOG(fatal) << "Port " << active_port << "," << product
+                      << " amount is now " << port->second.amount[product];
     }
   }
 
@@ -1148,12 +1145,15 @@ void TraderDispatch::server_prompt(const std::string &prompt) {
 
         if (trade_end_empty) {
           // Ok, we want to end with empty holds...
+
           int other_port;
           if (active_port == port[0])
             other_port = port[1];
           else
             other_port = port[0];
 
+          BUGZ_LOG(fatal) << "Is " << other_port << " burnt? (trade_end_empty)";
+
           // Is target port burnt?
           auto pos = director.galaxy.ports.find(other_port);
           bool burnt = false;
@@ -1165,18 +1165,33 @@ void TraderDispatch::server_prompt(const std::string &prompt) {
               // port isn't unknown, so check to see if it's burnt
               for (int x = 0; x < 3; ++x) {
                 if (trades.foe[x]) {
+                  BUGZ_LOG(fatal)
+                      << other_port << " " << x << " is in trades...";
+                  BUGZ_LOG(fatal)
+                      << "amount[" << x << "] = " << pos->second.amount[x];
+
                   if (pos->second.percent[x] < stop_percent) burnt = true;
-                  if (director.galaxy.meta["ships"]["holds"]["total"])
+                  if (director.galaxy.meta["ship"]["holds"]["total"]) {
+                    BUGZ_LOG(fatal)
+                        << pos->second.amount[x] << " : "
+                        << director.galaxy.meta["ship"]["holds"]["total"]
+                               .as<int>();
+
                     if (pos->second.amount[x] <
-                        director.galaxy.meta["ships"]["holds"]["total"]
-                            .as<int>())
+                        director.galaxy.meta["ship"]["holds"]["total"]
+                            .as<int>()) {
+                      BUGZ_LOG(fatal) << "Other port " << other_port
+                                      << " is burnt " << x << " burnt = true";
                       burnt = true;
+                    }
+                  } 
                 }
               }
             }
           }
 
           if (burnt) {
+            BUGZ_LOG(fatal) << "Port burnt, buy_ok = false";
             buy_ok = false;
           }
         }