CDefObjInfoHandler.cpp 3.6 KB

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