CTownHandler.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. int si=0;
  20. while (!ins.eof())
  21. {
  22. CTown town;
  23. ins >> town.name;
  24. char bufname[50];
  25. for (int i=0; i<NAMES_PER_TOWN; i++)
  26. {
  27. names.getline(bufname,50);
  28. town.names.push_back(std::string(bufname));
  29. }
  30. town.typeID=si++;
  31. town.bonus=towns.size();
  32. if (town.bonus==8) town.bonus=3;
  33. if (town.name.length())
  34. towns.push_back(town);
  35. }
  36. }
  37. SDL_Surface * CTownHandler::getPic(int ID, bool fort, bool builded)
  38. {
  39. if (ID==-1)
  40. return smallIcons->ourImages[0].bitmap;
  41. else if (ID==-2)
  42. return smallIcons->ourImages[1].bitmap;
  43. else if (ID==-3)
  44. return smallIcons->ourImages[2+F_NUMBER*4].bitmap;
  45. else if (ID>F_NUMBER || ID<-3)
  46. throw new std::exception("Invalid ID");
  47. else
  48. {
  49. int pom = 3;
  50. if(!fort)
  51. pom+=F_NUMBER*2;
  52. pom += ID*2;
  53. if (!builded)
  54. pom--;
  55. return smallIcons->ourImages[pom].bitmap;
  56. }
  57. }
  58. int CTownHandler::getTypeByDefName(std::string name)
  59. {
  60. //TODO
  61. return 0;
  62. }
  63. CTownInstance::CTownInstance()
  64. :pos(-1,-1,-1)
  65. {
  66. builded=-1;
  67. destroyed=-1;
  68. garrisonHero=NULL;
  69. owner=-1;
  70. town=NULL;
  71. }