| 
					
				 | 
			
			
				@@ -313,4 +313,164 @@ void ScriptVoyager::next(void) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 void ScriptVoyager::server_prompt(const std::string &prompt) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ScriptExplore::ScriptExplore(Director &d) : Dispatch(d) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  BUGZ_LOG(warning) << "ScriptExplore()"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  init(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ScriptExplore::~ScriptExplore() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  BUGZ_LOG(warning) << "~ScriptExplore()"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  us.reset(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void ScriptExplore::init() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  move = std::make_shared<MoveDispatch>(director); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  md = static_cast<MoveDispatch *>(&(*move)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  md->setNotify([this]() {this->move_notify();}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  input = std::make_shared<InputDispatch>(director); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  id = static_cast<InputDispatch *>(&(*input)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  id->prompt = "Number of sectors to explore: "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  id->max_length = 5; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  id->numeric = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  id->setNotify([this](){this->input_notify();}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  state = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void ScriptExplore::activate() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  us = director.chain; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  state = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  to_server("I"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  /*  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  director.chain = input; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  input->activate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if(director.galaxy.meta["ship"]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if(!director.galaxy.meta["ship"]["scanner"]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      to_client("\n\rIt appears your ship doesn't have a long range scanner.\n\r"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      deactivate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  state = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void ScriptExplore::deactivate() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  BUGZ_LOG(warning) << "ScriptExplore::deactivate()"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  notify(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void ScriptExplore::move_notify() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (md->aborted) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    deactivate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (md->success) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    to_server("SD"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    state = 3; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    to_client("No safe moves.\n\r"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    deactivate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void ScriptExplore::input_notify() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (id->input.empty() || id->aborted) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    to_client("Maybe next time.\n\r"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    deactivate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  loops = sstoi(id->input, -1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (loops == -1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    to_client("I'm sorry, WHAT?\n\r"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    deactivate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (loops == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    infinite = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    infinite = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  id->input.clear(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (!infinite) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    BUGZ_LOG(warning) << "Explore loops: " << loops; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    to_client("Infinite Mode!\n\r"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    to_client("[ PRESS A KEY TO STOP ]\n\r"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    BUGZ_LOG(warning) << "Explore loops: INFINITE"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  director.chain = us; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  to_server("SD"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  state = 3; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void ScriptExplore::next() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (loops <= 0 && !infinite) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    to_client("The exploration ends, for now.\n\r"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    deactivate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if(!infinite) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    --loops; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // Calculate next best sector to goto 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  density_scan & ds = director.galaxy.dscan; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  density best_sector; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  for (int x = 0; x < ds.pos; ++x) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    BUGZ_LOG(warning) << "Comparing: " << ds.d[x].sector << "(" << ds.d[x].known << ") to " << best_sector.sector; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if(!ds.d[x].known) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      // Compare, Warp counts 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      if (best_sector.sector != 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(ds.d[x].warps >= best_sector.warps) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          best_sector = ds.d[x]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        best_sector = ds.d[x]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      // Check density for possible port 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (best_sector.sector == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    to_client("No unknown warps."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    deactivate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  BUGZ_LOG(warning) << "Targeting sector: " << best_sector.sector; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  md->move_to = best_sector.sector; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  director.chain = move; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  director.chain->activate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void ScriptExplore::server_prompt(const std::string &prompt) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  BUGZ_LOG(warning) << "Explorer State: SP " << state; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  //next(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if(state == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if(at_command_prompt(prompt)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      if(director.galaxy.meta["ship"]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(!director.galaxy.meta["ship"]["scanner"]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          to_client("\n\rIt appears your ship doesn't have a long range scanner.\n\r"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          deactivate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      state = 2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      BUGZ_LOG(fatal) << "state = 1, prompting for user input"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      director.chain = input; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      input->activate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (state == 3) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if(at_command_prompt(prompt)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      state = 4; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      next(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |