dispatchers.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #ifndef DISPATCHERS_H
  2. #define DISPATCHERS_H
  3. #include <map>
  4. #include <memory>
  5. #include <string>
  6. #include "director.h"
  7. #include "session_common.h"
  8. /*
  9. Item of the day:
  10. class Result {
  11. // holds unique_ptr or shared_ptr to the "dispatcher"
  12. // when I'm done -- delete the result, cleaning up
  13. // the dispatcher
  14. }
  15. How does this call another?
  16. How does it return a result?
  17. possibly: io_service::post( DONE ); !
  18. */
  19. class Dispatch {
  20. protected:
  21. Director &director;
  22. notifyFunc notify_;
  23. public:
  24. Dispatch(Director &);
  25. virtual ~Dispatch();
  26. bool aborted;
  27. void setNotify(notifyFunc nf);
  28. void notify(void);
  29. virtual void activate(void) = 0;
  30. virtual void deactivate(void) = 0;
  31. const std::string &get_prompt(void);
  32. void to_server(const std::string &send);
  33. void to_client(const std::string &send);
  34. // default to chain calls
  35. void chain_client_input(const std::string &input);
  36. void chain_server_line(const std::string &line, const std::string &raw_line);
  37. void chain_server_prompt(const std::string &prompt);
  38. virtual void client_input(const std::string &input);
  39. virtual void server_line(const std::string &line, const std::string &raw_line);
  40. virtual void server_prompt(const std::string &prompt);
  41. };
  42. /*
  43. * Some options for input:
  44. *
  45. * numeric only
  46. *
  47. */
  48. class InputDispatch : public Dispatch {
  49. private:
  50. public:
  51. InputDispatch(Director &);
  52. ~InputDispatch();
  53. std::string prompt;
  54. size_t max_length;
  55. std::string input;
  56. bool numeric;
  57. void activate(void) override;
  58. void deactivate(void) override;
  59. // optional here
  60. void server_line(const std::string &line,
  61. const std::string &raw_line) override;
  62. // void server_prompt(const std::string &prompt);
  63. void client_input(const std::string &cinput) override;
  64. };
  65. class MenuDispatch : public Dispatch {
  66. private:
  67. void help(void);
  68. void menubox(void);
  69. size_t max_width;
  70. size_t max_option_width;
  71. bool instant = false;
  72. void calculate_widths(void);
  73. std::string centered(int length, const std::string &);
  74. public:
  75. MenuDispatch(Director &);
  76. ~MenuDispatch();
  77. std::string menu_box_color;
  78. std::string menu_text_color;
  79. std::string menu_title;
  80. std::string menu_options_color;
  81. std::string menu_prompt;
  82. bool lazy = true;
  83. std::map<std::string, std::string> menu;
  84. bool case_sensitive = false;
  85. std::string input;
  86. int choice;
  87. void activate(void) override;
  88. void deactivate(void) override;
  89. // optional here
  90. void server_line(const std::string &line, const std::string &raw_line) override;
  91. // void server_prompt(const std::string &prompt);
  92. void client_input(const std::string &cinput) override;
  93. };
  94. class CIMDispatch : public Dispatch {
  95. public:
  96. CIMDispatch(Director &);
  97. int count;
  98. void activate(void) override;
  99. void deactivate(void) override;
  100. // optional here
  101. void server_line(const std::string &line, const std::string &raw_line) override;
  102. };
  103. class MoveDispatch : public Dispatch {
  104. public:
  105. MoveDispatch(Director &);
  106. ~MoveDispatch();
  107. sector_type move_to;
  108. sector_type starting;
  109. int state;
  110. int success;
  111. int warp_pos;
  112. bool use_express;
  113. std::string at_destination;
  114. std::vector<int> warp_lane;
  115. void activate(void) override;
  116. void deactivate(void) override;
  117. // optional here
  118. void server_line(const std::string &line, const std::string &raw_line) override;
  119. void server_prompt(const std::string &prompt) override;
  120. void client_input(const std::string &input) override;
  121. private:
  122. //bool density_clear(density d); // int sector, int density);
  123. };
  124. class TraderDispatch : public Dispatch {
  125. private:
  126. public:
  127. TraderDispatch(Director &);
  128. ~TraderDispatch();
  129. char foe[4] = "foe";
  130. bool trade_end_empty;
  131. // success / failure ?
  132. bool success;
  133. /**
  134. * internal state
  135. *
  136. * 1 = <Info> query.
  137. * 2 = move to active port
  138. * 3 = trade
  139. * 4 = if (burnt), stop, otherwise toggle active_port and state = 2
  140. *
  141. * NEW: set port[1] to 0 for buy-only ability.
  142. * Percent 20 doesn't work with Cargo Trans' 250 holds.
  143. * Maybe look at the amount instead? If < holds = burnt.
  144. */
  145. int state;
  146. float percent;
  147. bool buying;
  148. int initial_offer;
  149. int last_offer;
  150. int final_offer;
  151. int product; // product we are buying/selling 0,1,2 foe.
  152. int stop_percent;
  153. bool try_again;
  154. // should this be 0/1 ? right now it is the port's sector number.
  155. int active_port; // port trading with
  156. // information from the find_best_trades function + others.
  157. int port[2];
  158. int active;
  159. // I don't care about trade type, just trades.
  160. int type;
  161. buysell trades;
  162. buysell port_buysell[2];
  163. void activate(void) override;
  164. void deactivate(void) override;
  165. void server_line(const std::string &line,
  166. const std::string &raw_line) override;
  167. void server_prompt(const std::string &prompt) override;
  168. void client_input(const std::string &cinput) override;
  169. };
  170. class CoreDispatch : public Dispatch {
  171. public:
  172. CoreDispatch(Director &);
  173. void activate(void) override;
  174. void deactivate(void) override;
  175. // optional here
  176. void server_line(const std::string &line, const std::string &raw_line) override;
  177. void server_prompt(const std::string &prompt) override;
  178. void client_input(const std::string &input) override;
  179. };
  180. #endif