CDefObjInfoHandler.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #include "StdInc.h"
  2. #include "CDefObjInfoHandler.h"
  3. #include "../client/CGameInfo.h"
  4. #include "CLodHandler.h"
  5. #include "../lib/VCMI_Lib.h"
  6. #include "GameConstants.h"
  7. extern CLodHandler * bitmaph;
  8. /*
  9. * CDefObjInfoHandler.cpp, part of VCMI engine
  10. *
  11. * Authors: listed in file AUTHORS in main folder
  12. *
  13. * License: GNU General Public License v2.0 or later
  14. * Full text of license available in license.txt file, in main folder
  15. *
  16. */
  17. bool CGDefInfo::isVisitable() const
  18. {
  19. for (int i=0; i<6; i++)
  20. {
  21. if (visitMap[i])
  22. return true;
  23. }
  24. return false;
  25. }
  26. CGDefInfo::CGDefInfo()
  27. {
  28. visitDir = (8|16|32|64|128); //4,5,6,7,8 - any not-from-up direction
  29. width = height = -1;
  30. }
  31. void CGDefInfo::fetchInfoFromMSK()
  32. {
  33. std::string msk = spriteh->getTextFile(name, FILE_MASK);
  34. width = msk[0];
  35. height = msk[1];
  36. for(int i=0; i<6; ++i)
  37. {
  38. coverageMap[i] = msk[i+2];
  39. shadowCoverage[i] = msk[i+8];
  40. }
  41. }
  42. void CDefObjInfoHandler::load()
  43. {
  44. VLC->dobjinfo = this;
  45. std::istringstream inp(bitmaph->getTextFile("ZOBJCTS.TXT"));
  46. int objNumber;
  47. inp>>objNumber;
  48. std::string mapStr;
  49. for(int hh=0; hh<objNumber; ++hh)
  50. {
  51. CGDefInfo* nobj = new CGDefInfo();
  52. std::string dump;
  53. inp>>nobj->name;
  54. std::transform(nobj->name.begin(), nobj->name.end(), nobj->name.begin(), (int(*)(int))toupper);
  55. for(int o=0; o<6; ++o)
  56. {
  57. nobj->blockMap[o] = 0xff;
  58. nobj->visitMap[o] = 0x00;
  59. nobj->coverageMap[o] = 0x00;
  60. nobj->shadowCoverage[o] = 0x00;
  61. }
  62. inp>>mapStr;
  63. std::reverse(mapStr.begin(), mapStr.end());
  64. for(int v=0; v<mapStr.size(); ++v)
  65. {
  66. if(mapStr[v]=='0')
  67. {
  68. nobj->blockMap[v/8] &= 255 - (128 >> (v%8));
  69. }
  70. }
  71. inp>>mapStr;
  72. std::reverse(mapStr.begin(), mapStr.end());
  73. for(int v=0; v<mapStr.size(); ++v)
  74. {
  75. if(mapStr[v]=='1')
  76. {
  77. nobj->visitMap[v/8] |= (128 >> (v%8));
  78. }
  79. }
  80. for(int yy=0; yy<2; ++yy) //first - on which types of terrain object can be placed;
  81. inp>>dump; //second -in which terrains' menus object in the editor will be available (?)
  82. inp>>nobj->id;
  83. inp>>nobj->subid;
  84. inp>>nobj->type;
  85. nobj->visitDir = (8|16|32|64|128); //disabled visiting from the top
  86. if(nobj->type == 2 || nobj->type == 3 || nobj->type == 4 || nobj->type == 5) //creature, hero, artifact, resource
  87. {
  88. nobj->visitDir = 0xff;
  89. }
  90. else
  91. {
  92. static int visitableFromTop[] = {29, 82, 86, 11, 59, 8, 111,33,81,12,9,212,215,22}; //sea chest, flotsam, shipwreck survivor, buoy, ocean bottle, boat, whirlpool, garrison, scholar, campfire, borderguard, bordergate, questguard, corpse
  93. for(int i=0; i < ARRAY_COUNT(visitableFromTop); i++)
  94. {
  95. if(visitableFromTop[i] == nobj->id)
  96. {
  97. nobj->visitDir = 0xff;
  98. break;
  99. }
  100. }
  101. }
  102. inp >> nobj->printPriority;
  103. //coverageMap calculating
  104. nobj->fetchInfoFromMSK();
  105. gobjs[nobj->id][nobj->subid] = nobj;
  106. if(nobj->id==GameConstants::TOWNI_TYPE)
  107. castles[nobj->subid]=nobj;
  108. }
  109. for (int i = 0; i < 8 ; i++)
  110. {
  111. static const char *holeDefs[] = {"AVLHOLD0.DEF", "AVLHLDS0.DEF", "AVLHOLG0.DEF", "AVLHLSN0.DEF",
  112. "AVLHOLS0.DEF", "AVLHOLR0.DEF", "AVLHOLX0.DEF", "AVLHOLL0.DEF"};
  113. if(i)
  114. {
  115. gobjs[124][i] = new CGDefInfo(*gobjs[124][0]);
  116. }
  117. gobjs[124][i]->name = holeDefs[i];
  118. }
  119. }
  120. CDefObjInfoHandler::~CDefObjInfoHandler()
  121. {
  122. for(bmap<int,bmap<int, ConstTransitivePtr<CGDefInfo> > >::iterator i=gobjs.begin(); i!=gobjs.end(); i++)
  123. for(bmap<int, ConstTransitivePtr<CGDefInfo> >::iterator j=i->second.begin(); j!=i->second.end(); j++)
  124. j->second.dellNull();
  125. }