#ifndef DISPATCHERS_H #define DISPATCHERS_H #include #include #include #include "director.h" #include "session_common.h" /* Item of the day: class Result { // holds unique_ptr or shared_ptr to the "dispatcher" // when I'm done -- delete the result, cleaning up // the dispatcher } How does this call another? How does it return a result? possibly: io_service::post( DONE ); ! */ class Dispatch { protected: Director &director; notifyFunc notify_; public: std::string name; Dispatch(Director &, const char * called=nullptr); virtual ~Dispatch(); bool aborted; void setNotify(notifyFunc nf); void notify(void); virtual void activate(void) = 0; virtual void deactivate(void); const std::string &get_prompt(void); void to_server(const std::string &send); void to_client(const std::string &send); void activate_chain(std::shared_ptr new_chain); // default to chain calls void chain_client_input(const std::string &input); void chain_server_line(const std::string &line, const std::string &raw_line); void chain_server_prompt(const std::string &prompt); virtual void client_input(const std::string &input); virtual void server_line(const std::string &line, const std::string &raw_line); virtual void server_prompt(const std::string &prompt); }; /* * Some options for input: * * numeric only * */ class InputDispatch : public Dispatch { private: public: InputDispatch(Director &, const char * called=nullptr); ~InputDispatch(); std::string prompt; size_t max_length; std::string input; bool numeric; void activate(void) override; void deactivate(void) override; // optional here void server_line(const std::string &line, const std::string &raw_line) override; // void server_prompt(const std::string &prompt); void client_input(const std::string &cinput) override; }; class MenuDispatch : public Dispatch { private: void help(void); void menubox(void); size_t max_width; size_t max_option_width; bool instant = false; void calculate_widths(void); std::string centered(int length, const std::string &); public: MenuDispatch(Director &, const char * called=nullptr); ~MenuDispatch(); std::string menu_box_color; std::string menu_text_color; std::string menu_title; std::string menu_options_color; std::string menu_prompt; bool lazy = true; std::map menu; bool case_sensitive = false; std::string input; int choice; void activate(void) override; void deactivate(void) override; // optional here void server_line(const std::string &line, const std::string &raw_line) override; // void server_prompt(const std::string &prompt); void client_input(const std::string &cinput) override; }; class CIMDispatch : public Dispatch { public: CIMDispatch(Director &, const char * called=nullptr); int count; void activate(void) override; void deactivate(void) override; void server_line(const std::string &line, const std::string &raw_line) override; }; class MoveDispatch : public Dispatch { public: MoveDispatch(Director &, const char * called=nullptr); ~MoveDispatch(); sector_type move_to; sector_type starting; int state; int success; int warp_pos; bool use_express; std::string why_failed; std::string at_destination; std::vector warp_lane; void activate(void) override; void deactivate(void) override; // optional here void server_line(const std::string &line, const std::string &raw_line) override; void server_prompt(const std::string &prompt) override; void client_input(const std::string &input) override; private: //bool density_clear(density d); // int sector, int density); }; class TraderDispatch : public Dispatch { private: public: TraderDispatch(Director &, const char * called=nullptr); ~TraderDispatch(); char foe[4] = "foe"; bool trade_end_empty; // success / failure ? bool success; std::string why_failed; /** * internal state * * 1 = query. * 2 = move to active port * 3 = trade * 4 = if (burnt), stop, otherwise toggle active_port and state = 2 * * NEW: set port[1] to 0 for buy-only ability. * Percent 20 doesn't work with Cargo Trans' 250 holds. * Maybe look at the amount instead? If < holds = burnt. */ int state; float percent; bool buying; int initial_offer; int last_offer; int final_offer; int product; // product we are buying/selling 0,1,2 foe. int stop_percent; bool try_again; // should this be 0/1 ? right now it is the port's sector number. int active_port; // port trading with // information from the find_best_trades function + others. int port[2]; int active; // I don't care about trade type, just trades. int type; buysell trades; buysell port_buysell[2]; void activate(void) override; void deactivate(void) override; void server_line(const std::string &line, const std::string &raw_line) override; void server_prompt(const std::string &prompt) override; void client_input(const std::string &cinput) override; }; class CoreDispatch : public Dispatch { public: CoreDispatch(Director &, const char * called=nullptr); void activate(void) override; void deactivate(void) override; // optional here void server_line(const std::string &line, const std::string &raw_line) override; void server_prompt(const std::string &prompt) override; void client_input(const std::string &input) override; }; #endif