| 
					
				 | 
			
			
				@@ -224,41 +224,41 @@ void ScriptTrader::server_prompt(const std::string &prompt) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       if (port[1] == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         active_port = port[0]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      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]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-              active_port = port[0]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-              break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (port_buysell[1].foe[x]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-              active_port = port[1]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        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]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                active_port = port[0]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              if (port_buysell[1].foe[x]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                active_port = port[1]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (active_port == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          to_client( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-              "I don't see any ports that are buying what we have in our " 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-              "holds.\n\r"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          deactivate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // all holds empty, find selling port 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        for (int x = 0; x < 3; ++x) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-          if (trades.foe[x]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (port_buysell[0].foe[x]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-              active_port = port[0]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-              break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (port_buysell[1].foe[x]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-              active_port = port[1]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-              break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          if (active_port == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            to_client( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                "I don't see any ports that are buying what we have in our " 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                "holds.\n\r"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            deactivate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          // all holds empty, find selling port 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          for (int x = 0; x < 3; ++x) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (trades.foe[x]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              if (port_buysell[0].foe[x]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                active_port = port[0]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              if (port_buysell[1].foe[x]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                active_port = port[1]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+              } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #ifdef NO_JUST_TRADES 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       // Do we have what they are buying? 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       bool have_buy = false; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -447,8 +447,7 @@ void ScriptTrader::server_prompt(const std::string &prompt) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         active_port = port[1]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      } else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         active_port = port[0]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       // Is target port burnt? 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -486,3 +485,59 @@ void ScriptTrader::server_prompt(const std::string &prompt) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 void ScriptTrader::client_input(const std::string &cinput) { deactivate(); }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ScriptTerror::ScriptTerror(Director &d) : Dispatch(d) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  BUGZ_LOG(warning) << "ScriptTerror"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  init(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ScriptTerror::~ScriptTerror() { BUGZ_LOG(warning) << "~ScriptTerror"; } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void ScriptTerror::init(void) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  move = std::make_shared<MoveDispatch>(director); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  md = static_cast<MoveDispatch *>(&(*move)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // setup notify functions for results/completion. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // md->setNotify([this]() { this->input_notify(); }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  input = std::make_shared<InputDispatch>(director); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  id = static_cast<InputDispatch *>(&(*move)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  id->prompt = "Number of loops: "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  id->max_length = 4; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  id->numeric = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  id->setNotify([this]() { this->input_notify(); }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  trader = std::make_shared<ScriptTrader>(director); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  st = static_cast<ScriptTrader *>(&(*trader)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void ScriptTerror::activate(void) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  BUGZ_LOG(warning) << "ScriptTerror::activate()"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // Need: InputDispatch, MoveDispatch, ScriptTrader 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // Step 1:  Get number of loops of terror 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  director.chain = input; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  input->activate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // Step 2:  Look for closest trades, try ScriptTrade until none < some level. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // Step 3:  Move on, unless out of loops (or low on turns) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // deactivate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void ScriptTerror::deactivate(void) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  BUGZ_LOG(warning) << "ScriptTerror::deactivate()"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  notify(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void ScriptTerror::input_notify(void) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (id->input.empty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    deactivate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  loops = sstoi(id->input); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (loops == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    deactivate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  BUGZ_LOG(warning) << "Loops of terror: " << loops; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // for now: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  deactivate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |