CTownHandler.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. }
  15. void CTownHandler::loadNames()
  16. {
  17. std::istringstream ins, names;
  18. ins.str(CGI->bitmaph->getTextFile("TOWNTYPE.TXT"));
  19. names.str(CGI->bitmaph->getTextFile("TOWNNAME.TXT"));
  20. int si=0;
  21. while (!ins.eof())
  22. {
  23. CTown town;
  24. ins >> town.name;
  25. char bufname[50];
  26. for (int i=0; i<NAMES_PER_TOWN; i++)
  27. {
  28. names.getline(bufname,50);
  29. town.names.push_back(std::string(bufname));
  30. }
  31. town.typeID=si++;
  32. town.bonus=towns.size();
  33. if (town.bonus==8) town.bonus=3;
  34. if (town.name.length())
  35. towns.push_back(town);
  36. }
  37. std::string strs = CGI->bitmaph->getTextFile("TCOMMAND.TXT");
  38. int itr=0;
  39. while(itr<strs.length()-1)
  40. {
  41. std::string tmp;
  42. CGeneralTextHandler::loadToIt(tmp, strs, itr, 3);
  43. tcommands.push_back(tmp);
  44. }
  45. }
  46. SDL_Surface * CTownHandler::getPic(int ID, bool fort, bool builded)
  47. {
  48. if (ID==-1)
  49. return smallIcons->ourImages[0].bitmap;
  50. else if (ID==-2)
  51. return smallIcons->ourImages[1].bitmap;
  52. else if (ID==-3)
  53. return smallIcons->ourImages[2+F_NUMBER*4].bitmap;
  54. else if (ID>F_NUMBER || ID<-3)
  55. throw new std::exception("Invalid ID");
  56. else
  57. {
  58. int pom = 3;
  59. if(!fort)
  60. pom+=F_NUMBER*2;
  61. pom += ID*2;
  62. if (!builded)
  63. pom--;
  64. return smallIcons->ourImages[pom].bitmap;
  65. }
  66. }
  67. int CTownHandler::getTypeByDefName(std::string name)
  68. {
  69. //TODO
  70. return 0;
  71. }
  72. CTownInstance::CTownInstance()
  73. :pos(-1,-1,-1)
  74. {
  75. builded=-1;
  76. destroyed=-1;
  77. garrisonHero=NULL;
  78. town=NULL;
  79. }
  80. int CTownInstance::getSightDistance() const //TODO: finish
  81. {
  82. return 10;
  83. }