CMapInfo.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #define VCMI_DLL
  2. #include "CMapInfo.h"
  3. #include "../StartInfo.h"
  4. #include "map.h"
  5. #include "../hch/CCampaignHandler.h"
  6. void CMapInfo::countPlayers()
  7. {
  8. actualHumanPlayers = playerAmnt = humenPlayers = 0;
  9. for(int i=0;i<PLAYER_LIMIT;i++)
  10. {
  11. if(mapHeader->players[i].canHumanPlay)
  12. {
  13. playerAmnt++;
  14. humenPlayers++;
  15. }
  16. else if(mapHeader->players[i].canComputerPlay)
  17. {
  18. playerAmnt++;
  19. }
  20. }
  21. if(scenarioOpts)
  22. for (std::map<int, PlayerSettings>::const_iterator i = scenarioOpts->playerInfos.begin(); i != scenarioOpts->playerInfos.end(); i++)
  23. if(i->second.human)
  24. actualHumanPlayers++;
  25. }
  26. CMapInfo::CMapInfo(bool map)
  27. : mapHeader(NULL), campaignHeader(NULL), scenarioOpts(NULL)
  28. {
  29. }
  30. void CMapInfo::mapInit(const std::string &fname, const unsigned char *map )
  31. {
  32. filename = fname;
  33. int i = 0;
  34. mapHeader = new CMapHeader();
  35. mapHeader->version = CMapHeader::invalid;
  36. try
  37. {
  38. mapHeader->initFromMemory(map, i);
  39. countPlayers();
  40. }
  41. catch (const std::string &e)
  42. {
  43. tlog1 << "\t\tWarning: evil map file: " << fname << ": " << e << std::endl;
  44. delete mapHeader;
  45. mapHeader = NULL;
  46. }
  47. }
  48. CMapInfo::~CMapInfo()
  49. {
  50. delete mapHeader;
  51. delete campaignHeader;
  52. }
  53. void CMapInfo::campaignInit()
  54. {
  55. campaignHeader = new CCampaignHeader( CCampaignHandler::getHeader(filename, lodCmpgn) );
  56. }
  57. void CMapInfo::setHeader(CMapHeader *header)
  58. {
  59. mapHeader = header;
  60. }