2
0

CBuildingHandler.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "StdInc.h"
  2. #include "CBuildingHandler.h"
  3. /*
  4. * CBuildingHandler.cpp, part of VCMI engine
  5. *
  6. * Authors: listed in file AUTHORS in main folder
  7. *
  8. * License: GNU General Public License v2.0 or later
  9. * Full text of license available in license.txt file, in main folder
  10. *
  11. */
  12. BuildingID CBuildingHandler::campToERMU( int camp, int townType, std::set<BuildingID> builtBuildings )
  13. {
  14. using namespace boost::assign;
  15. static const std::vector<BuildingID> campToERMU = list_of(BuildingID::TOWN_HALL)(BuildingID::CITY_HALL)
  16. (BuildingID::CAPITOL)(BuildingID::FORT)(BuildingID::CITADEL)(BuildingID::CASTLE)(BuildingID::TAVERN)
  17. (BuildingID::BLACKSMITH)(BuildingID::MARKETPLACE)(BuildingID::RESOURCE_SILO)(BuildingID::NONE)
  18. (BuildingID::MAGES_GUILD_1)(BuildingID::MAGES_GUILD_2)(BuildingID::MAGES_GUILD_3)(BuildingID::MAGES_GUILD_4)
  19. (BuildingID::MAGES_GUILD_5)
  20. (BuildingID::SHIPYARD)(BuildingID::GRAIL)
  21. (BuildingID::SPECIAL_1)(BuildingID::SPECIAL_2)(BuildingID::SPECIAL_3)(BuildingID::SPECIAL_4)
  22. ; //creature generators with banks - handled separately
  23. if (camp < campToERMU.size())
  24. {
  25. return campToERMU[camp];
  26. }
  27. static const std::vector<int> hordeLvlsPerTType[GameConstants::F_NUMBER] = {list_of(2), list_of(1), list_of(1)(4), list_of(0)(2),
  28. list_of(0), list_of(0), list_of(0), list_of(0), list_of(0)};
  29. int curPos = campToERMU.size();
  30. for (int i=0; i<GameConstants::CREATURES_PER_TOWN; ++i)
  31. {
  32. if(camp == curPos) //non-upgraded
  33. return BuildingID(30 + i);
  34. curPos++;
  35. if(camp == curPos) //upgraded
  36. return BuildingID(37 + i);
  37. curPos++;
  38. if (i < 5) // last two levels don't have reserved horde ID. Yet another H3C weirdeness
  39. {
  40. if (vstd::contains(hordeLvlsPerTType[townType], i))
  41. {
  42. if (camp == curPos)
  43. {
  44. if (hordeLvlsPerTType[townType][0] == i)
  45. {
  46. if(vstd::contains(builtBuildings, 37 + hordeLvlsPerTType[townType][0])) //if upgraded dwelling is built
  47. return BuildingID::HORDE_1_UPGR;
  48. else //upgraded dwelling not presents
  49. return BuildingID::HORDE_1;
  50. }
  51. else
  52. {
  53. if(hordeLvlsPerTType[townType].size() > 1)
  54. {
  55. if(vstd::contains(builtBuildings, 37 + hordeLvlsPerTType[townType][1])) //if upgraded dwelling is built
  56. return BuildingID::HORDE_2_UPGR;
  57. else //upgraded dwelling not presents
  58. return BuildingID::HORDE_2;
  59. }
  60. }
  61. }
  62. }
  63. curPos++;
  64. }
  65. }
  66. assert(0);
  67. return BuildingID::NONE; //not found
  68. }