CCastleInterface.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include "stdafx.h"
  2. #include "CCastleInterface.h"
  3. #include "hch/CObjectHandler.h"
  4. #include "CGameInfo.h"
  5. #include "hch/CLodHandler.h"
  6. #include "SDL_Extensions.h"
  7. #include "CAdvmapInterface.h"
  8. #include "hch/CTownHandler.h"
  9. #include "AdventureMapButton.h"
  10. std::string getBgName(int type) //TODO - co z tym zrobiæ?
  11. {
  12. switch (type)
  13. {
  14. case 0:
  15. return "TBCSBACK.bmp";
  16. case 1:
  17. return "TBRMBACK.bmp";
  18. case 2:
  19. return "TBTWBACK.bmp";
  20. case 3:
  21. return "TBINBACK.bmp";
  22. case 4:
  23. return "TBNCBACK.bmp";
  24. case 5:
  25. return "TBDNBACK.bmp";
  26. case 6:
  27. return "TBSTBACK.bmp";
  28. case 7:
  29. return "TBFRBACK.bmp";
  30. case 8:
  31. return "TBELBACK.bmp";
  32. default:
  33. throw new std::exception("std::string getBgName(int type): invalid type");
  34. }
  35. }
  36. CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
  37. {
  38. town = Town;
  39. townInt = CGI->bitmaph->loadBitmap("TOWNSCRN.bmp");
  40. cityBg = CGI->bitmaph->loadBitmap(getBgName(town->subID));
  41. hall = CGI->spriteh->giveDef("ITMTL.DEF");
  42. fort = CGI->spriteh->giveDef("ITMCL.DEF");
  43. CSDL_Ext::blueToPlayersAdv(townInt,LOCPLINT->playerID);
  44. exit = new AdventureMapButton<CCastleInterface>(CGI->townh->tcommands[8],"",&CCastleInterface::close,744,544,"TSBTNS.DEF",this,Activate);
  45. exit->bitmapOffset = 4;
  46. if(Activate)
  47. {
  48. activate();
  49. show();
  50. }
  51. }
  52. CCastleInterface::~CCastleInterface()
  53. {
  54. SDL_FreeSurface(townInt);
  55. SDL_FreeSurface(cityBg);
  56. delete exit;
  57. delete hall;
  58. delete fort;
  59. }
  60. void CCastleInterface::close()
  61. {
  62. deactivate();
  63. LOCPLINT->castleInt = NULL;
  64. LOCPLINT->adventureInt->show();
  65. delete this;
  66. }
  67. void CCastleInterface::show()
  68. {
  69. blitAt(cityBg,0,0);
  70. blitAt(townInt,0,374);
  71. LOCPLINT->adventureInt->resdatabar.draw();
  72. int pom;
  73. if(town->builtBuildings.find(9)!=town->builtBuildings.end())
  74. pom = 2;
  75. else if(town->builtBuildings.find(8)!=town->builtBuildings.end())
  76. pom = 1;
  77. else if(town->builtBuildings.find(7)!=town->builtBuildings.end())
  78. pom = 0;
  79. else pom = 3;
  80. blitAt(fort->ourImages[pom].bitmap,122,413);
  81. if(town->builtBuildings.find(13)!=town->builtBuildings.end())
  82. pom = 3;
  83. else if(town->builtBuildings.find(12)!=town->builtBuildings.end())
  84. pom = 2;
  85. else if(town->builtBuildings.find(11)!=town->builtBuildings.end())
  86. pom = 1;
  87. else pom = 0;
  88. blitAt(hall->ourImages[pom].bitmap,80,413);
  89. CSDL_Ext::printAt(town->name,85,389,GEOR13,zwykly);
  90. char temp[10];
  91. itoa(town->income,temp,10);
  92. CSDL_Ext::printAtMiddle(temp,195,442,GEOR13,zwykly);
  93. }
  94. void CCastleInterface::activate()
  95. {
  96. }
  97. void CCastleInterface::deactivate()
  98. {
  99. exit->deactivate();
  100. }