CArtHandler.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #define VCMI_DLL
  2. #include "../stdafx.h"
  3. #include "CArtHandler.h"
  4. #include "CLodHandler.h"
  5. #include "CGeneralTextHandler.h"
  6. #include <boost/assign/std/vector.hpp>
  7. #include <boost/assign/list_of.hpp>
  8. #include "../lib/VCMI_Lib.h"
  9. extern CLodHandler *bitmaph;
  10. using namespace boost::assign;
  11. CArtHandler::CArtHandler()
  12. {
  13. VLC->arth = this;
  14. }
  15. void CArtHandler::loadArtifacts(bool onlyTxt)
  16. {
  17. std::vector<ui16> slots;
  18. slots += 17, 16, 15,14,13, 18, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0;
  19. std::map<char,EartClass> classes =
  20. map_list_of('S',SartClass)('T',TartClass)('N',NartClass)('J',JartClass)('R',RartClass);
  21. std::string buf = bitmaph->getTextFile("ARTRAITS.TXT"), dump, pom;
  22. int it=0;
  23. for(int i=0; i<2; ++i)
  24. {
  25. loadToIt(dump,buf,it,3);
  26. }
  27. VLC->generaltexth->artifNames.resize(ARTIFACTS_QUANTITY);
  28. VLC->generaltexth->artifDescriptions.resize(ARTIFACTS_QUANTITY);
  29. for (int i=0; i<ARTIFACTS_QUANTITY; i++)
  30. {
  31. CArtifact nart;
  32. loadToIt(VLC->generaltexth->artifNames[i],buf,it,4);
  33. loadToIt(pom,buf,it,4);
  34. nart.price=atoi(pom.c_str());
  35. for(int j=0;j<slots.size();j++)
  36. {
  37. loadToIt(pom,buf,it,4);
  38. if(pom[0]=='x')
  39. nart.possibleSlots.push_back(slots[j]);
  40. }
  41. loadToIt(pom,buf,it,4);
  42. nart.aClass = classes[pom[0]];
  43. loadToIt(VLC->generaltexth->artifDescriptions[i],buf,it,3);
  44. nart.id=i;
  45. if(!onlyTxt)
  46. artifacts.push_back(nart);
  47. }
  48. sortArts();
  49. }
  50. int CArtHandler::convertMachineID(int id, bool creToArt )
  51. {
  52. int dif = 142;
  53. if(creToArt)
  54. {
  55. switch (id)
  56. {
  57. case 147:
  58. dif--;
  59. break;
  60. case 148:
  61. dif++;
  62. break;
  63. }
  64. dif = -dif;
  65. }
  66. else
  67. {
  68. switch (id)
  69. {
  70. case 6:
  71. dif--;
  72. break;
  73. case 5:
  74. dif++;
  75. break;
  76. }
  77. }
  78. return id + dif;
  79. }
  80. void CArtHandler::sortArts()
  81. {
  82. for(int i=0;i<144;i++) //do 144, bo nie chcemy bzdurek
  83. {
  84. switch (artifacts[i].aClass)
  85. {
  86. case TartClass:
  87. treasures.push_back(&(artifacts[i]));
  88. break;
  89. case NartClass:
  90. minors.push_back(&(artifacts[i]));
  91. break;
  92. case JartClass:
  93. majors.push_back(&(artifacts[i]));
  94. break;
  95. case RartClass:
  96. relics.push_back(&(artifacts[i]));
  97. break;
  98. }
  99. }
  100. }
  101. const std::string & CArtifact::Name() const
  102. {
  103. if(name.size())
  104. return name;
  105. else
  106. return VLC->generaltexth->artifNames[id];
  107. }
  108. const std::string & CArtifact::Description() const
  109. {
  110. if(description.size())
  111. return description;
  112. else
  113. return VLC->generaltexth->artifDescriptions[id];
  114. }