troop_catalog.cpp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. #include "troop_catalog.h"
  2. #include <utility>
  3. namespace Game::Units {
  4. auto TroopCatalog::instance() -> TroopCatalog & {
  5. static TroopCatalog inst;
  6. return inst;
  7. }
  8. TroopCatalog::TroopCatalog() { register_defaults(); }
  9. void TroopCatalog::register_class(TroopClass troop_class) {
  10. m_classes[troop_class.unit_type] = std::move(troop_class);
  11. }
  12. auto TroopCatalog::get_class(Game::Units::TroopType type) const
  13. -> const TroopClass * {
  14. auto it = m_classes.find(type);
  15. if (it != m_classes.end()) {
  16. return &it->second;
  17. }
  18. return nullptr;
  19. }
  20. auto TroopCatalog::get_class_or_fallback(Game::Units::TroopType type) const
  21. -> const TroopClass & {
  22. auto it = m_classes.find(type);
  23. if (it != m_classes.end()) {
  24. return it->second;
  25. }
  26. return m_fallback;
  27. }
  28. void TroopCatalog::clear() { m_classes.clear(); }
  29. void TroopCatalog::register_defaults() {
  30. m_fallback.display_name = "Unknown Troop";
  31. m_fallback.visuals.renderer_id = "troops/unknown";
  32. TroopClass archer{};
  33. archer.unit_type = Game::Units::TroopType::Archer;
  34. archer.display_name = "Archer";
  35. archer.production.cost = 50;
  36. archer.production.build_time = 5.0F;
  37. archer.production.priority = 10;
  38. archer.production.is_melee = false;
  39. archer.combat.health = 80;
  40. archer.combat.max_health = 80;
  41. archer.combat.speed = 3.0F;
  42. archer.combat.vision_range = 16.0F;
  43. archer.combat.ranged_range = 6.0F;
  44. archer.combat.ranged_damage = 12;
  45. archer.combat.ranged_cooldown = 1.2F;
  46. archer.combat.melee_range = 1.5F;
  47. archer.combat.melee_damage = 5;
  48. archer.combat.melee_cooldown = 0.8F;
  49. archer.combat.can_ranged = true;
  50. archer.combat.can_melee = true;
  51. archer.visuals.render_scale = 0.5F;
  52. archer.visuals.selection_ring_size = 1.2F;
  53. archer.visuals.selection_ring_ground_offset = 0.0F;
  54. archer.visuals.selection_ring_y_offset = 0.0F;
  55. archer.visuals.renderer_id = "troops/roman/archer";
  56. archer.individuals_per_unit = 20;
  57. archer.max_units_per_row = 5;
  58. register_class(std::move(archer));
  59. TroopClass swordsman{};
  60. swordsman.unit_type = Game::Units::TroopType::Swordsman;
  61. swordsman.display_name = "Swordsman";
  62. swordsman.production.cost = 90;
  63. swordsman.production.build_time = 7.0F;
  64. swordsman.production.priority = 10;
  65. swordsman.production.is_melee = true;
  66. swordsman.combat.health = 140;
  67. swordsman.combat.max_health = 140;
  68. swordsman.combat.speed = 2.2F;
  69. swordsman.combat.vision_range = 14.0F;
  70. swordsman.combat.ranged_range = 1.5F;
  71. swordsman.combat.ranged_damage = 6;
  72. swordsman.combat.ranged_cooldown = 1.8F;
  73. swordsman.combat.melee_range = 1.6F;
  74. swordsman.combat.melee_damage = 18;
  75. swordsman.combat.melee_cooldown = 0.6F;
  76. swordsman.combat.can_ranged = false;
  77. swordsman.combat.can_melee = true;
  78. swordsman.visuals.render_scale = 0.6F;
  79. swordsman.visuals.selection_ring_size = 1.1F;
  80. swordsman.visuals.selection_ring_ground_offset = 0.0F;
  81. swordsman.visuals.selection_ring_y_offset = 0.0F;
  82. swordsman.visuals.renderer_id = "troops/roman/swordsman";
  83. swordsman.individuals_per_unit = 15;
  84. swordsman.max_units_per_row = 5;
  85. register_class(std::move(swordsman));
  86. TroopClass spearman{};
  87. spearman.unit_type = Game::Units::TroopType::Spearman;
  88. spearman.display_name = "Spearman";
  89. spearman.production.cost = 75;
  90. spearman.production.build_time = 6.0F;
  91. spearman.production.priority = 5;
  92. spearman.production.is_melee = true;
  93. spearman.combat.health = 120;
  94. spearman.combat.max_health = 120;
  95. spearman.combat.speed = 2.5F;
  96. spearman.combat.vision_range = 15.0F;
  97. spearman.combat.ranged_range = 2.5F;
  98. spearman.combat.ranged_damage = 8;
  99. spearman.combat.ranged_cooldown = 1.5F;
  100. spearman.combat.melee_range = 2.5F;
  101. spearman.combat.melee_damage = 18;
  102. spearman.combat.melee_cooldown = 0.8F;
  103. spearman.combat.can_ranged = false;
  104. spearman.combat.can_melee = true;
  105. spearman.visuals.render_scale = 0.55F;
  106. spearman.visuals.selection_ring_size = 1.4F;
  107. spearman.visuals.selection_ring_ground_offset = 0.0F;
  108. spearman.visuals.selection_ring_y_offset = 0.0F;
  109. spearman.visuals.renderer_id = "troops/roman/spearman";
  110. spearman.individuals_per_unit = 24;
  111. spearman.max_units_per_row = 6;
  112. register_class(std::move(spearman));
  113. TroopClass horse_swordsman{};
  114. horse_swordsman.unit_type = Game::Units::TroopType::MountedKnight;
  115. horse_swordsman.display_name = "Mounted Knight";
  116. horse_swordsman.production.cost = 150;
  117. horse_swordsman.production.build_time = 10.0F;
  118. horse_swordsman.production.priority = 15;
  119. horse_swordsman.production.is_melee = true;
  120. horse_swordsman.combat.health = 200;
  121. horse_swordsman.combat.max_health = 200;
  122. horse_swordsman.combat.speed = 4.F;
  123. horse_swordsman.combat.vision_range = 16.0F;
  124. horse_swordsman.combat.ranged_range = 1.5F;
  125. horse_swordsman.combat.ranged_damage = 5;
  126. horse_swordsman.combat.ranged_cooldown = 2.0F;
  127. horse_swordsman.combat.melee_range = 2.0F;
  128. horse_swordsman.combat.melee_damage = 25;
  129. horse_swordsman.combat.melee_cooldown = 0.8F;
  130. horse_swordsman.combat.can_ranged = false;
  131. horse_swordsman.combat.can_melee = true;
  132. horse_swordsman.visuals.render_scale = 0.8F;
  133. horse_swordsman.visuals.selection_ring_size = 2.0F;
  134. horse_swordsman.visuals.selection_ring_ground_offset = 0.0F;
  135. horse_swordsman.visuals.selection_ring_y_offset = 0.0F;
  136. horse_swordsman.visuals.renderer_id = "troops/roman/horse_swordsman";
  137. horse_swordsman.individuals_per_unit = 9;
  138. horse_swordsman.max_units_per_row = 3;
  139. TroopClass horse_archer{};
  140. horse_archer.unit_type = Game::Units::TroopType::HorseArcher;
  141. horse_archer.display_name = "Horse Archer";
  142. horse_archer.production.cost = 120;
  143. horse_archer.production.build_time = 9.0F;
  144. horse_archer.production.priority = 12;
  145. horse_archer.production.is_melee = false;
  146. horse_archer.combat.health = 160;
  147. horse_archer.combat.max_health = 160;
  148. horse_archer.combat.speed = 3.0F;
  149. horse_archer.combat.vision_range = 15.0F;
  150. horse_archer.combat.ranged_range = 7.0F;
  151. horse_archer.combat.ranged_damage = 12;
  152. horse_archer.combat.ranged_cooldown = 2.2F;
  153. horse_archer.combat.melee_range = 1.5F;
  154. horse_archer.combat.melee_damage = 10;
  155. horse_archer.combat.melee_cooldown = 1.0F;
  156. horse_archer.combat.can_ranged = true;
  157. horse_archer.combat.can_melee = true;
  158. horse_archer.visuals.render_scale = 0.8F;
  159. horse_archer.visuals.selection_ring_size = 2.0F;
  160. horse_archer.visuals.selection_ring_ground_offset = 0.0F;
  161. horse_archer.visuals.selection_ring_y_offset = 0.0F;
  162. horse_archer.visuals.renderer_id = "troops/roman/horse_archer";
  163. horse_archer.individuals_per_unit = 8;
  164. horse_archer.max_units_per_row = 3;
  165. register_class(std::move(horse_archer));
  166. register_class(std::move(horse_swordsman));
  167. TroopClass healer{};
  168. healer.unit_type = Game::Units::TroopType::Healer;
  169. healer.display_name = "Healer";
  170. healer.production.cost = 75;
  171. healer.production.build_time = 7.0F;
  172. healer.production.priority = 8;
  173. healer.production.is_melee = false;
  174. healer.combat.health = 100;
  175. healer.combat.max_health = 100;
  176. healer.combat.speed = 2.5F;
  177. healer.combat.vision_range = 14.0F;
  178. healer.combat.ranged_range = 8.0F;
  179. healer.combat.ranged_damage = 5;
  180. healer.combat.ranged_cooldown = 2.0F;
  181. healer.combat.melee_range = 1.5F;
  182. healer.combat.melee_damage = 3;
  183. healer.combat.melee_cooldown = 1.5F;
  184. healer.combat.can_ranged = false;
  185. healer.combat.can_melee = true;
  186. healer.visuals.render_scale = 0.55F;
  187. healer.visuals.selection_ring_size = 1.2F;
  188. healer.visuals.selection_ring_ground_offset = 0.0F;
  189. healer.visuals.selection_ring_y_offset = 0.0F;
  190. healer.visuals.renderer_id = "troops/roman/healer";
  191. healer.individuals_per_unit = 1;
  192. healer.max_units_per_row = 1;
  193. register_class(std::move(healer));
  194. TroopClass horse_spearman{};
  195. horse_spearman.unit_type = Game::Units::TroopType::HorseSpearman;
  196. horse_spearman.display_name = "Horse Spearman";
  197. horse_spearman.production.cost = 130;
  198. horse_spearman.production.build_time = 9.5F;
  199. horse_spearman.production.priority = 13;
  200. horse_spearman.production.is_melee = true;
  201. horse_spearman.combat.health = 180;
  202. horse_spearman.combat.max_health = 180;
  203. horse_spearman.combat.speed = 3.0F;
  204. horse_spearman.combat.vision_range = 15.0F;
  205. horse_spearman.combat.ranged_range = 2.5F;
  206. horse_spearman.combat.ranged_damage = 9;
  207. horse_spearman.combat.ranged_cooldown = 1.8F;
  208. horse_spearman.combat.melee_range = 2.2F;
  209. horse_spearman.combat.melee_damage = 20;
  210. horse_spearman.combat.melee_cooldown = 0.9F;
  211. horse_spearman.combat.can_ranged = false;
  212. horse_spearman.combat.can_melee = true;
  213. horse_spearman.visuals.render_scale = 0.8F;
  214. horse_spearman.visuals.selection_ring_size = 2.0F;
  215. horse_spearman.visuals.selection_ring_ground_offset = 0.0F;
  216. horse_spearman.visuals.selection_ring_y_offset = 0.0F;
  217. horse_spearman.visuals.renderer_id = "troops/roman/horse_spearman";
  218. horse_spearman.individuals_per_unit = 8;
  219. horse_spearman.max_units_per_row = 3;
  220. register_class(std::move(horse_spearman));
  221. TroopClass builder{};
  222. builder.unit_type = Game::Units::TroopType::Builder;
  223. builder.display_name = "Builder";
  224. builder.production.cost = 60;
  225. builder.production.build_time = 6.0F;
  226. builder.production.priority = 4;
  227. builder.production.is_melee = true;
  228. builder.combat.health = 80;
  229. builder.combat.max_health = 80;
  230. builder.combat.speed = 2.0F;
  231. builder.combat.vision_range = 10.0F;
  232. builder.combat.ranged_range = 1.5F;
  233. builder.combat.ranged_damage = 2;
  234. builder.combat.ranged_cooldown = 2.0F;
  235. builder.combat.melee_range = 1.5F;
  236. builder.combat.melee_damage = 5;
  237. builder.combat.melee_cooldown = 1.0F;
  238. builder.combat.can_ranged = false;
  239. builder.combat.can_melee = true;
  240. builder.visuals.render_scale = 0.50F;
  241. builder.visuals.selection_ring_size = 1.0F;
  242. builder.visuals.selection_ring_ground_offset = 0.0F;
  243. builder.visuals.selection_ring_y_offset = 0.0F;
  244. builder.visuals.renderer_id = "troops/roman/builder";
  245. builder.individuals_per_unit = 12;
  246. builder.max_units_per_row = 4;
  247. register_class(std::move(builder));
  248. }
  249. } // namespace Game::Units