|
@@ -548,6 +548,125 @@ void CIMDispatch::server_line(const std::string &line,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+MoveDispatch::MoveDispatch(Director &d) : Dispatch(d) {
|
|
|
+ BUGZ_LOG(warning) << "MoveDispatch()";
|
|
|
+}
|
|
|
+
|
|
|
+// sector_type move_to;
|
|
|
+
|
|
|
+void MoveDispatch::activate(void) {
|
|
|
+ starting = director.current_sector;
|
|
|
+ BUGZ_LOG(warning) << "Moving from " << starting << " to " << move_to;
|
|
|
+ // Start with density scan
|
|
|
+ to_server("SD");
|
|
|
+ state = 1;
|
|
|
+ warp_lane.clear();
|
|
|
+ warp_pos = 0;
|
|
|
+
|
|
|
+ // build final string to match against
|
|
|
+ at_destination = "Auto Warping to sector ";
|
|
|
+ at_destination.append(std::to_string(move_to));
|
|
|
+}
|
|
|
+
|
|
|
+void MoveDispatch::deactivate(void) { notify(); }
|
|
|
+
|
|
|
+// optional here
|
|
|
+void MoveDispatch::server_line(const std::string &line,
|
|
|
+ const std::string &raw_line) {
|
|
|
+ BUGZ_LOG(fatal) << "server_line: " << line;
|
|
|
+
|
|
|
+ if (state == 1) {
|
|
|
+ if (endswith(line, "Relative Density Scan")) {
|
|
|
+ state = 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (state == 3) {
|
|
|
+ if (line == "That Warp Lane is not adjacent.") {
|
|
|
+ //ok! Parse out the path that we need to take...
|
|
|
+ }
|
|
|
+ // [611 > 612 > 577 > 543 > 162 > 947 > 185 > 720 > 894 > 3 > 1]
|
|
|
+ // multiple lines possible here?
|
|
|
+ // watch for <Move> it contains >
|
|
|
+ if ((line != "<Move>") && in(line, ">")) {
|
|
|
+ std::string work = line;
|
|
|
+ replace(work, " > ", " ");
|
|
|
+ auto warps = split(work);
|
|
|
+ for( auto const & w : warps) {
|
|
|
+ BUGZ_LOG(fatal) << "lane: " << w;
|
|
|
+ warp_lane.push_back(stoi(w));
|
|
|
+ }
|
|
|
+ state = 4;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (state == 4) {
|
|
|
+ if (line == at_destination) {
|
|
|
+ // [Auto Warping to sector 1]
|
|
|
+ state = 6;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+bool MoveDispatch::density_clear(int density) {
|
|
|
+ switch (density) {
|
|
|
+ case 0:
|
|
|
+ case 1:
|
|
|
+ case 100:
|
|
|
+ case 101:
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+void MoveDispatch::server_prompt(const std::string &prompt) {
|
|
|
+ BUGZ_LOG(fatal) << "server_prompt: " << prompt;
|
|
|
+
|
|
|
+ if (state == 2) {
|
|
|
+ if (at_command_prompt(prompt)) {
|
|
|
+ // Ok, density is done
|
|
|
+ std::string command = str(boost::format("M%1%\r") % move_to);
|
|
|
+ to_server(command);
|
|
|
+ state = 3;
|
|
|
+ }
|
|
|
+ } else if (state == 4) {
|
|
|
+ if (prompt == "Engage the Autopilot? (Y/N/Single step/Express) [Y] ") {
|
|
|
+ int to_check = warp_lane[warp_pos+1];
|
|
|
+ // check density scan
|
|
|
+ int density = director.galaxy.meta["density"][to_check]["density"].as<int>();
|
|
|
+ if (density_clear(density)) {
|
|
|
+ to_server("S");
|
|
|
+ ++warp_pos;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (prompt == "Stop in this sector (Y,N,E,I,R,S,D,P,?) (?=Help) [N] ? ") {
|
|
|
+ state = 5;
|
|
|
+ to_server("SD");
|
|
|
+ }
|
|
|
+ } else if (state == 5) {
|
|
|
+ // finished scan
|
|
|
+ if (prompt == "Stop in this sector (Y,N,E,I,R,S,D,P,?) (?=Help) [N] ? ") {
|
|
|
+ int to_check = warp_lane[warp_pos+1];
|
|
|
+ int density = director.galaxy.meta["density"][to_check]["density"].as<int>();
|
|
|
+ if (density_clear(density)) {
|
|
|
+ to_server("N");
|
|
|
+ ++warp_pos;
|
|
|
+ state = 4;
|
|
|
+ } else {
|
|
|
+ to_server("Y");
|
|
|
+ BUGZ_LOG(fatal) << "Stopped by density: " << density;
|
|
|
+ success = 0;
|
|
|
+ deactivate();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (state == 6) {
|
|
|
+ if (at_command_prompt(prompt)) {
|
|
|
+ // We're done!
|
|
|
+ success = 1;
|
|
|
+ deactivate();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+void MoveDispatch::client_input(const std::string &input) {}
|
|
|
+
|
|
|
/*
|
|
|
* CoreDispatch: This is an example class that does dispatch.
|
|
|
* Copy this and make changes from there...
|