CDefObjInfoHandler.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. return;
  48. // std::istringstream inp(bitmaph->getTextFile("ZOBJCTS.TXT"));
  49. // int objNumber;
  50. // inp>>objNumber;
  51. // std::string mapStr;
  52. // for(int hh=0; hh<objNumber; ++hh)
  53. // {
  54. // CGDefInfo* nobj = new CGDefInfo();
  55. // std::string dump;
  56. // inp>>nobj->name;
  57. //
  58. // std::transform(nobj->name.begin(), nobj->name.end(), nobj->name.begin(), (int(*)(int))toupper);
  59. //
  60. // for(int o=0; o<6; ++o)
  61. // {
  62. // nobj->blockMap[o] = 0xff;
  63. // nobj->visitMap[o] = 0x00;
  64. // nobj->coverageMap[o] = 0x00;
  65. // nobj->shadowCoverage[o] = 0x00;
  66. // }
  67. // inp>>mapStr;
  68. // std::reverse(mapStr.begin(), mapStr.end());
  69. // for(int v=0; v<mapStr.size(); ++v)
  70. // {
  71. // if(mapStr[v]=='0')
  72. // {
  73. // nobj->blockMap[v/8] &= 255 - (128 >> (v%8));
  74. // }
  75. // }
  76. // inp>>mapStr;
  77. // std::reverse(mapStr.begin(), mapStr.end());
  78. // for(int v=0; v<mapStr.size(); ++v)
  79. // {
  80. // if(mapStr[v]=='1')
  81. // {
  82. // nobj->visitMap[v/8] |= (128 >> (v%8));
  83. // }
  84. // }
  85. //
  86. // for(int yy=0; yy<2; ++yy) //first - on which types of terrain object can be placed;
  87. // inp>>dump; //second -in which terrains' menus object in the editor will be available (?)
  88. // inp>>nobj->id;
  89. // inp>>nobj->subid;
  90. // inp>>nobj->type;
  91. //
  92. // nobj->visitDir = (8|16|32|64|128); //disabled visiting from the top
  93. //
  94. // if(nobj->type == 2 || nobj->type == 3 || nobj->type == 4 || nobj->type == 5) //creature, hero, artifact, resource
  95. // {
  96. // nobj->visitDir = 0xff;
  97. // }
  98. // else
  99. // {
  100. // 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
  101. // for(int i=0; i < ARRAY_COUNT(visitableFromTop); i++)
  102. // {
  103. // if(visitableFromTop[i] == nobj->id)
  104. // {
  105. // nobj->visitDir = 0xff;
  106. // break;
  107. // }
  108. // }
  109. // }
  110. // inp >> nobj->printPriority;
  111. //
  112. // //coverageMap calculating
  113. // nobj->fetchInfoFromMSK();
  114. //
  115. //
  116. // gobjs[nobj->id][nobj->subid] = nobj;
  117. // if(nobj->id==TOWNI_TYPE)
  118. // castles[nobj->subid]=nobj;
  119. // }
  120. //
  121. // if(vstd::contains(gobjs, 124))
  122. // {
  123. // for (int i = 0; i < 8 ; i++)
  124. // {
  125. //
  126. // static const char *holeDefs[] = {"AVLHOLD0.DEF", "AVLHLDS0.DEF", "AVLHOLG0.DEF", "AVLHLSN0.DEF",
  127. // "AVLHOLS0.DEF", "AVLHOLR0.DEF", "AVLHOLX0.DEF", "AVLHOLL0.DEF"};
  128. //
  129. // if(i)
  130. // {
  131. // gobjs[124][i] = new CGDefInfo(*gobjs[124][0]);
  132. // gobjs[124][i]->name = holeDefs[i];
  133. // }
  134. // }
  135. // }
  136. // else
  137. // {
  138. // tlog1 << "No def info for holes!\n";
  139. // }
  140. }
  141. CDefObjInfoHandler::~CDefObjInfoHandler()
  142. {
  143. for(bmap<int,bmap<int, ConstTransitivePtr<CGDefInfo> > >::iterator i=gobjs.begin(); i!=gobjs.end(); i++)
  144. for(bmap<int, ConstTransitivePtr<CGDefInfo> >::iterator j=i->second.begin(); j!=i->second.end(); j++)
  145. j->second.dellNull();
  146. }