CTownHandler.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include "../stdafx.h"
  2. #include "CTownHandler.h"
  3. #include "../CGameInfo.h"
  4. #include "CLodHandler.h"
  5. #include <sstream>
  6. #include "CGeneralTextHandler.h"
  7. CTownHandler::CTownHandler()
  8. {
  9. smallIcons = CGI->spriteh->giveDef("ITPA.DEF");
  10. }
  11. CTownHandler::~CTownHandler()
  12. {
  13. delete smallIcons;
  14. //todo - delete structures info
  15. }
  16. void CTownHandler::loadNames()
  17. {
  18. std::istringstream ins, names;
  19. ins.str(CGI->bitmaph->getTextFile("TOWNTYPE.TXT"));
  20. names.str(CGI->bitmaph->getTextFile("TOWNNAME.TXT"));
  21. int si=0;
  22. while (!ins.eof())
  23. {
  24. CTown town;
  25. ins >> town.name;
  26. char bufname[50];
  27. for (int i=0; i<NAMES_PER_TOWN; i++)
  28. {
  29. names.getline(bufname,50);
  30. town.names.push_back(std::string(bufname));
  31. }
  32. town.typeID=si++;
  33. town.bonus=towns.size();
  34. if (town.bonus==8) town.bonus=3;
  35. if (town.name.length())
  36. towns.push_back(town);
  37. }
  38. std::string strs = CGI->bitmaph->getTextFile("TCOMMAND.TXT");
  39. int itr=0;
  40. while(itr<strs.length()-1)
  41. {
  42. std::string tmp;
  43. CGeneralTextHandler::loadToIt(tmp, strs, itr, 3);
  44. tcommands.push_back(tmp);
  45. }
  46. std::ifstream of("config/buildings.txt");
  47. while(!of.eof())
  48. {
  49. Structure *vinya = new Structure;
  50. of >> vinya->townID;
  51. of >> vinya->ID;
  52. of >> vinya->defName;
  53. of >> vinya->x;
  54. of >> vinya->y;
  55. structures[vinya->townID][vinya->ID] = vinya;
  56. }
  57. }
  58. SDL_Surface * CTownHandler::getPic(int ID, bool fort, bool builded)
  59. {
  60. if (ID==-1)
  61. return smallIcons->ourImages[0].bitmap;
  62. else if (ID==-2)
  63. return smallIcons->ourImages[1].bitmap;
  64. else if (ID==-3)
  65. return smallIcons->ourImages[2+F_NUMBER*4].bitmap;
  66. else if (ID>F_NUMBER || ID<-3)
  67. throw new std::exception("Invalid ID");
  68. else
  69. {
  70. int pom = 3;
  71. if(!fort)
  72. pom+=F_NUMBER*2;
  73. pom += ID*2;
  74. if (!builded)
  75. pom--;
  76. return smallIcons->ourImages[pom].bitmap;
  77. }
  78. }
  79. int CTownHandler::getTypeByDefName(std::string name)
  80. {
  81. //TODO
  82. return 0;
  83. }
  84. CTownInstance::CTownInstance()
  85. :pos(-1,-1,-1)
  86. {
  87. builded=-1;
  88. destroyed=-1;
  89. garrisonHero=NULL;
  90. town=NULL;
  91. }
  92. int CTownInstance::getSightDistance() const //TODO: finish
  93. {
  94. return 10;
  95. }