CCastleInterface.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. //draw fort icon
  74. if(town->builtBuildings.find(9)!=town->builtBuildings.end())
  75. pom = 2;
  76. else if(town->builtBuildings.find(8)!=town->builtBuildings.end())
  77. pom = 1;
  78. else if(town->builtBuildings.find(7)!=town->builtBuildings.end())
  79. pom = 0;
  80. else pom = 3;
  81. blitAt(fort->ourImages[pom].bitmap,122,413);
  82. //draw ((village/town/city) hall)/capitol icon
  83. if(town->builtBuildings.find(13)!=town->builtBuildings.end())
  84. pom = 3;
  85. else if(town->builtBuildings.find(12)!=town->builtBuildings.end())
  86. pom = 2;
  87. else if(town->builtBuildings.find(11)!=town->builtBuildings.end())
  88. pom = 1;
  89. else pom = 0;
  90. blitAt(hall->ourImages[pom].bitmap,80,413);
  91. //draw creatures icons and their growths
  92. for(int i=0;i<CREATURES_PER_TOWN;i++)
  93. {
  94. int cid = -1;
  95. if (town->builtBuildings.find(30+i)!=town->builtBuildings.end())
  96. {
  97. cid = (14*town->subID)+(i*2);
  98. if (town->builtBuildings.find(30+CREATURES_PER_TOWN+i)!=town->builtBuildings.end())
  99. {
  100. cid++;
  101. }
  102. }
  103. if (cid>=0)
  104. {
  105. ;
  106. }
  107. }
  108. //print name and income
  109. CSDL_Ext::printAt(town->name,85,389,GEOR13,zwykly);
  110. char temp[10];
  111. itoa(town->income,temp,10);
  112. CSDL_Ext::printAtMiddle(temp,195,442,GEOR13,zwykly);
  113. }
  114. void CCastleInterface::activate()
  115. {
  116. }
  117. void CCastleInterface::deactivate()
  118. {
  119. exit->deactivate();
  120. }