CDefObjInfoHandler.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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()
  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. serial = -1;
  32. visitDir = (8|16|32|64|128); //4,5,6,7,8 - any not-from-up direction
  33. }
  34. void CDefObjInfoHandler::load()
  35. {
  36. VLC->dobjinfo = this;
  37. nodrze<int> ideki;
  38. std::istringstream inp(bitmaph->getTextFile("ZOBJCTS.TXT"));
  39. int objNumber;
  40. inp>>objNumber;
  41. std::string mapStr;
  42. for(int hh=0; hh<objNumber; ++hh)
  43. {
  44. CGDefInfo* nobj = new CGDefInfo();
  45. nobj->handler = NULL;
  46. std::string dump;
  47. inp>>nobj->name;
  48. std::transform(nobj->name.begin(), nobj->name.end(), nobj->name.begin(), (int(*)(int))toupper);
  49. for(int o=0; o<6; ++o)
  50. {
  51. nobj->blockMap[o] = 0xff;
  52. nobj->visitMap[o] = 0x00;
  53. nobj->coverageMap[o] = 0x00;
  54. }
  55. inp>>mapStr;
  56. std::reverse(mapStr.begin(), mapStr.end());
  57. for(int v=0; v<mapStr.size(); ++v)
  58. {
  59. if(mapStr[v]=='0')
  60. {
  61. nobj->blockMap[v/8] &= 255 - (128 >> (v%8));
  62. }
  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]=='1')
  69. {
  70. nobj->visitMap[v/8] |= (128 >> (v%8));
  71. }
  72. }
  73. for(int yy=0; yy<2; ++yy) //first - on which types of terrain object can be placed;
  74. inp>>dump; //second -in which terrains' menus object in the editor will be available (?)
  75. inp>>nobj->id;
  76. inp>>nobj->subid;
  77. inp>>nobj->type;
  78. nobj->visitDir = (8|16|32|64|128); //disabled visiting from the top
  79. if(nobj->type == 2 || nobj->type == 3 || nobj->type == 4 || nobj->type == 5) //creature, hero, artifact, resource
  80. {
  81. nobj->visitDir = 0xff;
  82. }
  83. else
  84. {
  85. static int visitableFromTop[] = {111,33,81,12,9,212,215,22}; //whirlpool, garrison, scholar, campfire, borderguard, bordergate, questguard, corpse
  86. for(int i=0; i < ARRAY_COUNT(visitableFromTop); i++)
  87. {
  88. if(visitableFromTop[i] == nobj->id)
  89. {
  90. nobj->visitDir = 0xff;
  91. break;
  92. }
  93. }
  94. }
  95. inp >> nobj->printPriority;
  96. //coverageMap calculating
  97. std::string nameCopy = nobj->name;
  98. std::string msk = spriteh->getTextFile(nameCopy.replace( nameCopy.size()-4, 4, ".MSK" ));
  99. for(int i=0; i<6; ++i)
  100. {
  101. nobj->coverageMap[i] = msk[i+2];
  102. }
  103. gobjs[nobj->id][nobj->subid] = nobj;
  104. if(nobj->id==TOWNI_TYPE)
  105. castles[nobj->subid]=nobj;
  106. }
  107. }
  108. CDefObjInfoHandler::~CDefObjInfoHandler()
  109. {
  110. for(std::map<int,std::map<int,CGDefInfo*> >::iterator i=gobjs.begin(); i!=gobjs.end(); i++)
  111. for(std::map<int,CGDefInfo*>::iterator j=i->second.begin(); j!=i->second.end(); j++)
  112. delete j->second;
  113. }