123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- #ifndef DISPATCHERS_H
- #define DISPATCHERS_H
- #include <map>
- #include <memory>
- #include <string>
- #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:
- Dispatch(Director &);
- virtual ~Dispatch();
- bool aborted;
-
- void setNotify(notifyFunc nf);
- void notify(void);
- virtual void activate(void) = 0;
- virtual void deactivate(void) = 0;
- const std::string &get_prompt(void);
- void to_server(const std::string &send);
- void to_client(const std::string &send);
- // 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 &);
- ~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 &);
- ~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<std::string, std::string> 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 &);
- int count;
-
- void activate(void) override;
- void deactivate(void) override;
- // optional here
- void server_line(const std::string &line, const std::string &raw_line) override;
- };
- class MoveDispatch : public Dispatch {
- public:
- MoveDispatch(Director &);
- ~MoveDispatch();
-
- sector_type move_to;
- sector_type starting;
- int state;
- int success;
- int warp_pos;
- bool use_express;
- std::string at_destination;
- std::vector<int> 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 &);
- ~TraderDispatch();
- char foe[4] = "foe";
- bool trade_end_empty;
- // success / failure ?
- bool success;
- /**
- * internal state
- *
- * 1 = <Info> 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 &);
- 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
|