|
@@ -567,3 +567,84 @@ void ScriptExplore::server_prompt(const std::string &prompt) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ScriptPlanet::ScriptPlanet(Director &d) : Dispatch(d) {
|
|
|
+ BUGZ_LOG(warning) << "ScriptPlanet()";
|
|
|
+ init();
|
|
|
+}
|
|
|
+
|
|
|
+ScriptPlanet::~ScriptPlanet() { BUGZ_LOG(warning) << "~ScriptPlanet()"; }
|
|
|
+
|
|
|
+void ScriptPlanet::init() {
|
|
|
+ move = std::make_shared<MoveDispatch>(director);
|
|
|
+ md = static_cast<MoveDispatch *>(&(*move));
|
|
|
+ md->setNotify([this]() { this->move_notify(); });
|
|
|
+ trader = std::make_shared<TraderDispatch>(director);
|
|
|
+ td = static_cast<TraderDispatch *>(&(*trader));
|
|
|
+ td->setNotify([this]() { this->trade_notify(); });
|
|
|
+ input = std::make_shared<InputDispatch>(director);
|
|
|
+ id = static_cast<InputDispatch *>(&(*input));
|
|
|
+ id->prompt = "Which planet would you like to upgrade => ";
|
|
|
+ id->max_length = 3;
|
|
|
+ id->numeric = true;
|
|
|
+ id->setNotify([this]() { this->input_notify(); });
|
|
|
+ state = 0;
|
|
|
+}
|
|
|
+
|
|
|
+void ScriptPlanet::activate() {
|
|
|
+ us = director.chain;
|
|
|
+
|
|
|
+ // FUTURE: handle special case here, where we activate at planet/citadel
|
|
|
+ // prompt
|
|
|
+
|
|
|
+ state = 1;
|
|
|
+
|
|
|
+ // clear out the planets list -- we're refreshing.
|
|
|
+ director.galaxy.planets.clear();
|
|
|
+ // get planet lists
|
|
|
+ to_server("TLQ");
|
|
|
+}
|
|
|
+
|
|
|
+void ScriptPlanet::deactivate() {
|
|
|
+ BUGZ_LOG(warning) << "ScriptPlanet::deactivate()";
|
|
|
+ us.reset();
|
|
|
+ notify();
|
|
|
+}
|
|
|
+
|
|
|
+void ScriptPlanet::input_notify() {
|
|
|
+ deactivate();
|
|
|
+}
|
|
|
+
|
|
|
+void ScriptPlanet::move_notify() {}
|
|
|
+void ScriptPlanet::trade_notify() {}
|
|
|
+
|
|
|
+void ScriptPlanet::server_prompt(const std::string &prompt) {
|
|
|
+ if (state == 1) {
|
|
|
+ if (at_command_prompt(prompt)) {
|
|
|
+ state = 2;
|
|
|
+ to_server("CYQ");
|
|
|
+ }
|
|
|
+ } else if (state == 2) {
|
|
|
+ if (at_command_prompt(prompt)) {
|
|
|
+ state = 3;
|
|
|
+ if (director.galaxy.planets.empty()) {
|
|
|
+ to_client("Sorry, I don't see that you have any planets!\n\r");
|
|
|
+ deactivate();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (auto const &planet : director.galaxy.planets) {
|
|
|
+ std::string text =
|
|
|
+ str(boost::format("%1$3d <%2$5d> Class %3% Level %4% Name %5%\n\r") %
|
|
|
+ planet.first % planet.second.sector % planet.second.c %
|
|
|
+ planet.second.level % planet.second.name);
|
|
|
+ to_client(text);
|
|
|
+ }
|
|
|
+ director.chain = input;
|
|
|
+ director.chain->activate();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void ScriptPlanet::server_line(const std::string &line,
|
|
|
+ const std::string &raw_line) {}
|