gamestate.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. #ifndef __GAMESTATE_H
  2. #define __GAMESTATE_H
  3. #include "random.h"
  4. #include "random_serialize.h"
  5. #include "neighbors.h"
  6. #include "celauto.h"
  7. #include "grid.h"
  8. #include "worldkey.h"
  9. #include "astar.h"
  10. #include "render_maudit.h"
  11. #include "moon.h"
  12. #include "counters.h"
  13. #include "counters_serialize.h"
  14. #include "ffeatures.h"
  15. #include "items.h"
  16. #include "monsters.h"
  17. struct GameState {
  18. size_t ticks;
  19. rnd::Generator rng;
  20. neighbors::Neighbors neigh;
  21. celauto::CaMap camap;
  22. grid::Map grid;
  23. grender::Grid render;
  24. astar::Path path;
  25. moon::Moon moon;
  26. counters::Counts designs_counts;
  27. counters::Counts species_counts;
  28. counters::Counts bonus_designs_a_counts;
  29. counters::Counts bonus_designs_b_counts;
  30. monsters::Monsters monsters;
  31. items::Items items;
  32. features::Features features;
  33. struct trigger_t {
  34. struct summon_out_of_view_t {
  35. tag_t monster;
  36. unsigned int count;
  37. summon_out_of_view_t() : count(0) {}
  38. };
  39. summon_out_of_view_t summon_out_of_view;
  40. struct summon_genus_t {
  41. tag_t genus;
  42. unsigned int level;
  43. unsigned int count;
  44. unsigned int x;
  45. unsigned int y;
  46. summon_genus_t() : level(0), count(0), x(0), y(0) {}
  47. };
  48. summon_genus_t summon_genus;
  49. struct summon_t {
  50. tag_t species;
  51. unsigned int count;
  52. tag_t ally;
  53. unsigned int x;
  54. unsigned int y;
  55. summon_t() : count(0), x(0), y(0) {}
  56. };
  57. summon_t summon;
  58. struct message_t {
  59. std::string message;
  60. bool important;
  61. message_t() : important(false) {}
  62. };
  63. message_t message;
  64. };
  65. std::multimap<size_t, trigger_t> triggers;
  66. struct window_t {
  67. std::string message;
  68. unsigned int type;
  69. bool allow_tab;
  70. window_t() : type(0), allow_tab(true) {}
  71. window_t(const std::string& s, unsigned int t, bool tab = true) : message(s), type(t), allow_tab(tab) {}
  72. };
  73. std::vector<window_t> window_stack;
  74. std::unordered_map<worldkey::key_t, size_t> dungeon_visits_count;
  75. template <typename T>
  76. void push_window(const std::string& m, T t, bool allow_tab = true) {
  77. window_stack.push_back(window_t{m, (unsigned int)t, allow_tab});
  78. }
  79. // HACK
  80. bool fullwidth;
  81. GameState() : ticks(1), fullwidth(false) {}
  82. };
  83. struct GameOptions {
  84. bool center_view;
  85. bool no_fade_colors;
  86. size_t menu_theme;
  87. GameOptions() : center_view(false), no_fade_colors(false), menu_theme(0) {}
  88. };
  89. struct summons_t {
  90. unsigned int x;
  91. unsigned int y;
  92. enum class type_t : unsigned int {
  93. SPECIFIC,
  94. LEVEL,
  95. GENUS
  96. };
  97. type_t type;
  98. tag_t summontag;
  99. unsigned int level;
  100. unsigned int count;
  101. tag_t summonertag;
  102. tag_t ally;
  103. std::string msg;
  104. summons_t() : x(0), y(0), type(type_t::SPECIFIC), level(0), count(0) {}
  105. summons_t(unsigned int _x, unsigned int _y, type_t _t, tag_t _st, unsigned int _l, unsigned int _c,
  106. tag_t _sut, tag_t _al, const std::string& _m) :
  107. x(_x), y(_y), type(_t), summontag(_st), level(_l), count(_c), summonertag(_sut), ally(_al), msg(_m) {}
  108. };
  109. struct itemplace_t {
  110. unsigned int x;
  111. unsigned int y;
  112. enum class type_t : unsigned int {
  113. SPECIFIC,
  114. LEVEL,
  115. LEVEL_ANY
  116. };
  117. type_t type;
  118. tag_t tag;
  119. unsigned int level;
  120. itemplace_t() : x(0), y(0), type(type_t::SPECIFIC), level(0) {}
  121. itemplace_t(unsigned int _x, unsigned int _y, type_t _t, tag_t _dt, unsigned int _l) :
  122. x(_x), y(_y), type(_t), tag(_dt), level(_l) {}
  123. };
  124. /*** ***/
  125. namespace serialize {
  126. template <>
  127. struct reader<GameState::trigger_t> {
  128. void read(Source& s, GameState::trigger_t& t) {
  129. serialize::read(s, t.summon_out_of_view.monster);
  130. serialize::read(s, t.summon_out_of_view.count);
  131. serialize::read(s, t.summon_genus.genus);
  132. serialize::read(s, t.summon_genus.level);
  133. serialize::read(s, t.summon_genus.count);
  134. serialize::read(s, t.summon_genus.x);
  135. serialize::read(s, t.summon_genus.y);
  136. serialize::read(s, t.summon.species);
  137. serialize::read(s, t.summon.count);
  138. serialize::read(s, t.message.message);
  139. serialize::read(s, t.message.important);
  140. }
  141. };
  142. template <>
  143. struct reader<GameState::window_t> {
  144. void read(Source& s, GameState::window_t& w) {
  145. serialize::read(s, w.message);
  146. serialize::read(s, w.type);
  147. }
  148. };
  149. template <>
  150. struct reader<GameState> {
  151. void read(Source& s, GameState& state) {
  152. serialize::read(s, state.ticks);
  153. serialize::read(s, state.rng);
  154. serialize::read(s, state.neigh);
  155. serialize::read(s, state.camap);
  156. serialize::read(s, state.grid);
  157. serialize::read(s, state.render);
  158. serialize::read(s, state.moon);
  159. serialize::read(s, state.designs_counts);
  160. serialize::read(s, state.species_counts);
  161. serialize::read(s, state.bonus_designs_a_counts);
  162. serialize::read(s, state.bonus_designs_b_counts);
  163. serialize::read(s, state.monsters);
  164. serialize::read(s, state.items);
  165. serialize::read(s, state.features);
  166. serialize::read(s, state.dungeon_visits_count);
  167. serialize::read(s, state.triggers);
  168. serialize::read(s, state.window_stack);
  169. state.path.init(state.grid.w, state.grid.h);
  170. }
  171. };
  172. template <>
  173. struct writer<GameState::trigger_t> {
  174. void write(Sink& s, const GameState::trigger_t& t) {
  175. serialize::write(s, t.summon_out_of_view.monster);
  176. serialize::write(s, t.summon_out_of_view.count);
  177. serialize::write(s, t.summon_genus.genus);
  178. serialize::write(s, t.summon_genus.level);
  179. serialize::write(s, t.summon_genus.count);
  180. serialize::write(s, t.summon_genus.x);
  181. serialize::write(s, t.summon_genus.y);
  182. serialize::write(s, t.summon.species);
  183. serialize::write(s, t.summon.count);
  184. serialize::write(s, t.message.message);
  185. serialize::write(s, t.message.important);
  186. }
  187. };
  188. template <>
  189. struct writer<GameState::window_t> {
  190. void write(Sink& s, const GameState::window_t& w) {
  191. serialize::write(s, w.message);
  192. serialize::write(s, w.type);
  193. }
  194. };
  195. template <>
  196. struct writer<GameState> {
  197. void write(Sink& s, const GameState& state) {
  198. serialize::write(s, state.ticks);
  199. serialize::write(s, state.rng);
  200. serialize::write(s, state.neigh);
  201. serialize::write(s, state.camap);
  202. serialize::write(s, state.grid);
  203. serialize::write(s, state.render);
  204. serialize::write(s, state.moon);
  205. serialize::write(s, state.designs_counts);
  206. serialize::write(s, state.species_counts);
  207. serialize::write(s, state.bonus_designs_a_counts);
  208. serialize::write(s, state.bonus_designs_b_counts);
  209. serialize::write(s, state.monsters);
  210. serialize::write(s, state.items);
  211. serialize::write(s, state.features);
  212. serialize::write(s, state.dungeon_visits_count);
  213. serialize::write(s, state.triggers);
  214. serialize::write(s, state.window_stack);
  215. }
  216. };
  217. template <>
  218. struct reader<GameOptions> {
  219. void read(Source& s, GameOptions& t) {
  220. serialize::read(s, t.center_view);
  221. serialize::read(s, t.no_fade_colors);
  222. serialize::read(s, t.menu_theme);
  223. }
  224. };
  225. template <>
  226. struct writer<GameOptions> {
  227. void write(Sink& s, const GameOptions& t) {
  228. serialize::write(s, t.center_view);
  229. serialize::write(s, t.no_fade_colors);
  230. serialize::write(s, t.menu_theme);
  231. }
  232. };
  233. template <>
  234. struct reader<summons_t> {
  235. void read(Source& s, summons_t& t) {
  236. serialize::read(s, t.x);
  237. serialize::read(s, t.y);
  238. unsigned int tmp;
  239. serialize::read(s, tmp);
  240. t.type = (summons_t::type_t)tmp;
  241. serialize::read(s, t.summontag);
  242. serialize::read(s, t.level);
  243. serialize::read(s, t.count);
  244. serialize::read(s, t.summonertag);
  245. serialize::read(s, t.ally);
  246. serialize::read(s, t.msg);
  247. }
  248. };
  249. template <>
  250. struct writer<summons_t> {
  251. void write(Sink& s, const summons_t& t) {
  252. serialize::write(s, t.x);
  253. serialize::write(s, t.y);
  254. serialize::write(s, (unsigned int)t.type);
  255. serialize::write(s, t.summontag);
  256. serialize::write(s, t.level);
  257. serialize::write(s, t.count);
  258. serialize::write(s, t.summonertag);
  259. serialize::write(s, t.ally);
  260. serialize::write(s, t.msg);
  261. }
  262. };
  263. template <>
  264. struct reader<itemplace_t> {
  265. void read(Source& s, itemplace_t& t) {
  266. serialize::read(s, t.x);
  267. serialize::read(s, t.y);
  268. unsigned int tmp;
  269. serialize::read(s, tmp);
  270. t.type = (itemplace_t::type_t)tmp;
  271. serialize::read(s, t.tag);
  272. serialize::read(s, t.level);
  273. }
  274. };
  275. template <>
  276. struct writer<itemplace_t> {
  277. void write(Sink& s, const itemplace_t& t) {
  278. serialize::write(s, t.x);
  279. serialize::write(s, t.y);
  280. serialize::write(s, (unsigned int)t.type);
  281. serialize::write(s, t.tag);
  282. serialize::write(s, t.level);
  283. }
  284. };
  285. }
  286. #endif