CTownHandler.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "stdafx.h"
  2. #include "CTownHandler.h"
  3. #include "../CGameInfo.h"
  4. #include "CLodHandler.h"
  5. #include <sstream>
  6. CTownHandler::CTownHandler()
  7. {
  8. smallIcons = CGI->spriteh->giveDef("ITPA.DEF");
  9. }
  10. CTownHandler::~CTownHandler()
  11. {
  12. delete smallIcons;
  13. }
  14. void CTownHandler::loadNames()
  15. {
  16. std::istringstream ins, names;
  17. ins.str(CGI->bitmaph->getTextFile("TOWNTYPE.TXT"));
  18. names.str(CGI->bitmaph->getTextFile("TOWNNAME.TXT"));
  19. while (!ins.eof())
  20. {
  21. CTown town;
  22. ins >> town.name;
  23. char bufname[50];
  24. for (int i=0; i<NAMES_PER_TOWN; i++)
  25. {
  26. names.getline(bufname,50);
  27. town.names.push_back(std::string(bufname));
  28. }
  29. town.bonus=towns.size();
  30. if (town.bonus==8) town.bonus=3;
  31. if (town.name.length())
  32. towns.push_back(town);
  33. }
  34. }
  35. SDL_Surface * CTownHandler::getPic(int ID, bool fort, bool builded)
  36. {
  37. if (ID==-1)
  38. return smallIcons->ourImages[0].bitmap;
  39. else if (ID==-2)
  40. return smallIcons->ourImages[1].bitmap;
  41. else if (ID==-3)
  42. return smallIcons->ourImages[2+F_NUMBER*4].bitmap;
  43. else if (ID>F_NUMBER || ID<-3)
  44. throw new std::exception("Invalid ID");
  45. else
  46. {
  47. int pom = 3;
  48. if(!fort)
  49. pom+=F_NUMBER*2;
  50. pom += ID*2;
  51. if (!builded)
  52. pom--;
  53. return smallIcons->ourImages[pom].bitmap;
  54. }
  55. }
  56. int CTownHandler::getTypeByDefName(std::string name)
  57. {
  58. //TODO
  59. return 0;
  60. }