|
@@ -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();
|