CSpellHandler.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #define VCMI_DLL
  2. #include "../stdafx.h"
  3. #include "CSpellHandler.h"
  4. #include "CLodHandler.h"
  5. #include "../lib/VCMI_Lib.h"
  6. #include <boost/algorithm/string/replace.hpp>
  7. extern CLodHandler *bitmaph;
  8. void CSpellHandler::loadSpells()
  9. {
  10. std::string buf = bitmaph->getTextFile("SPTRAITS.TXT"), pom;
  11. int andame = buf.size(), i=0; //buf iterator
  12. for(int z=0; z<5; ++z)
  13. loadToIt(pom,buf,i,3);
  14. bool combSpells=false; //true, if we are reading combat spells
  15. bool creatureAbility=false; //if true, only creature can use this spell
  16. int ifHit = 0;
  17. while(i<andame)
  18. {
  19. if(spells.size()==81)
  20. break;
  21. CSpell nsp; //new currently being read spell
  22. loadToIt(nsp.name,buf,i,4);
  23. if(nsp.name == std::string(""))
  24. {
  25. if(ifHit == 0)
  26. {
  27. combSpells = true;
  28. }
  29. if(ifHit == 1)
  30. {
  31. creatureAbility = true;
  32. }
  33. for(int z=0; z<3; ++z)
  34. loadToIt(pom,buf,i,3);
  35. loadToIt(nsp.name,buf,i,4);
  36. ++ifHit;
  37. }
  38. loadToIt(nsp.abbName,buf,i,4);
  39. loadToIt(nsp.level,buf,i,4);
  40. loadToIt(pom,buf,i,4);
  41. nsp.earth = pom[0]=='x' ? true : false;
  42. loadToIt(pom,buf,i,4);
  43. nsp.water = pom[0]=='x' ? true : false;
  44. loadToIt(pom,buf,i,4);
  45. nsp.fire = pom[0]=='x' ? true : false;
  46. loadToIt(pom,buf,i,4);
  47. nsp.air = pom[0]=='x' ? true : false;
  48. nsp.costs.resize(4);
  49. for (int z = 0; z < 4 ; z++)
  50. loadToIt(nsp.costs[z],buf,i,4);
  51. loadToIt(nsp.power,buf,i,4);
  52. nsp.powers.resize(4);
  53. for (int z = 0; z < 4 ; z++)
  54. loadToIt(nsp.powers[z],buf,i,4);
  55. nsp.probabilities.resize(9);
  56. for (int z = 0; z < 9 ; z++)
  57. loadToIt(nsp.probabilities[z],buf,i,4);
  58. nsp.AIVals.resize(4);
  59. for (int z = 0; z < 4 ; z++)
  60. loadToIt(nsp.AIVals[z],buf,i,4);
  61. nsp.descriptions.resize(4);
  62. for (int z = 0; z < 4 ; z++)
  63. {
  64. loadToIt(nsp.descriptions[z],buf,i,4);
  65. boost::algorithm::replace_all(nsp.descriptions[z],"\"","");
  66. }
  67. loadToIt(nsp.attributes,buf,i,3);
  68. nsp.id = spells.size();
  69. nsp.combatSpell = combSpells;
  70. nsp.creatureAbility = creatureAbility;
  71. spells.push_back(nsp);
  72. }
  73. //loading of additional spell traits
  74. std::ifstream ast;
  75. ast.open("config/spell_info.txt", std::ios::binary);
  76. if(!ast.is_open())
  77. {
  78. tlog1<<"lack of config/spell_info.txt file!"<<std::endl;
  79. }
  80. else
  81. {
  82. //reading header
  83. std::string dump;
  84. for(int i=0; i<42; ++i) ast>>dump;
  85. //reading exact info
  86. int spellID;
  87. ast>>spellID;
  88. while(spellID != -1)
  89. {
  90. int buf;
  91. ast>>buf;
  92. spells[spellID].positiveness = buf;
  93. ast>>spellID;
  94. }
  95. }
  96. }