CArtHandler.cpp 1.9 KB

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