CDefObjInfoHandler.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. handler = NULL;
  31. visitDir = (8|16|32|64|128); //4,5,6,7,8 - any not-from-up direction
  32. width = height = -1;
  33. }
  34. void CGDefInfo::fetchInfoFromMSK()
  35. {
  36. std::string nameCopy = name;
  37. std::string msk = spriteh->getTextFile(nameCopy.replace( nameCopy.size()-4, 4, "#MSK" ));
  38. width = msk[0];
  39. height = msk[1];
  40. for(int i=0; i<6; ++i)
  41. {
  42. coverageMap[i] = msk[i+2];
  43. shadowCoverage[i] = msk[i+8];
  44. }
  45. }
  46. void CDefObjInfoHandler::load()
  47. {
  48. VLC->dobjinfo = this;
  49. std::istringstream inp(bitmaph->getTextFile("ZOBJCTS.TXT"));
  50. int objNumber;
  51. inp>>objNumber;
  52. std::string mapStr;
  53. for(int hh=0; hh<objNumber; ++hh)
  54. {
  55. CGDefInfo* nobj = new CGDefInfo();
  56. nobj->handler = NULL;
  57. std::string dump;
  58. inp>>nobj->name;
  59. std::transform(nobj->name.begin(), nobj->name.end(), nobj->name.begin(), (int(*)(int))toupper);
  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. for(int yy=0; yy<2; ++yy) //first - on which types of terrain object can be placed;
  86. inp>>dump; //second -in which terrains' menus object in the editor will be available (?)
  87. inp>>nobj->id;
  88. inp>>nobj->subid;
  89. inp>>nobj->type;
  90. nobj->visitDir = (8|16|32|64|128); //disabled visiting from the top
  91. if(nobj->type == 2 || nobj->type == 3 || nobj->type == 4 || nobj->type == 5) //creature, hero, artifact, resource
  92. {
  93. nobj->visitDir = 0xff;
  94. }
  95. else
  96. {
  97. 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
  98. for(int i=0; i < ARRAY_COUNT(visitableFromTop); i++)
  99. {
  100. if(visitableFromTop[i] == nobj->id)
  101. {
  102. nobj->visitDir = 0xff;
  103. break;
  104. }
  105. }
  106. }
  107. inp >> nobj->printPriority;
  108. //coverageMap calculating
  109. nobj->fetchInfoFromMSK();
  110. gobjs[nobj->id][nobj->subid] = nobj;
  111. if(nobj->id==TOWNI_TYPE)
  112. castles[nobj->subid]=nobj;
  113. }
  114. for (int i = 0; i < 8 ; i++)
  115. {
  116. static const char *holeDefs[] = {"AVLHOLD0.DEF", "AVLHLDS0.DEF", "AVLHOLG0.DEF", "AVLHLSN0.DEF",
  117. "AVLHOLS0.DEF", "AVLHOLR0.DEF", "AVLHOLX0.DEF", "AVLHOLL0.DEF"};
  118. CGDefInfo *& tmp = gobjs[124][i];
  119. if(i)
  120. {
  121. tmp = new CGDefInfo;
  122. *tmp = *gobjs[124][0];
  123. }
  124. tmp->name = holeDefs[i];
  125. }
  126. }
  127. CDefObjInfoHandler::~CDefObjInfoHandler()
  128. {
  129. for(std::map<int,std::map<int,CGDefInfo*> >::iterator i=gobjs.begin(); i!=gobjs.end(); i++)
  130. for(std::map<int,CGDefInfo*>::iterator j=i->second.begin(); j!=i->second.end(); j++)
  131. delete j->second;
  132. }