CMapHeader.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * CMapHeader.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CMapHeader.h"
  12. #include "MapFormat.h"
  13. #include "../VCMI_Lib.h"
  14. #include "../CTownHandler.h"
  15. #include "../CGeneralTextHandler.h"
  16. #include "../CHeroHandler.h"
  17. SHeroName::SHeroName() : heroId(-1)
  18. {
  19. }
  20. PlayerInfo::PlayerInfo(): canHumanPlay(false), canComputerPlay(false),
  21. aiTactic(EAiTactic::RANDOM), isFactionRandom(false), hasRandomHero(false), mainCustomHeroPortrait(-1), mainCustomHeroId(-1), hasMainTown(false),
  22. generateHeroAtMainTown(false), posOfMainTown(-1), team(TeamID::NO_TEAM)
  23. {
  24. allowedFactions = VLC->townh->getAllowedFactions();
  25. }
  26. si8 PlayerInfo::defaultCastle() const
  27. {
  28. //if random allowed set it as default
  29. if(isFactionRandom)
  30. return -1;
  31. if(!allowedFactions.empty())
  32. return *allowedFactions.begin();
  33. // fall back to random
  34. return -1;
  35. }
  36. si8 PlayerInfo::defaultHero() const
  37. {
  38. // we will generate hero in front of main town
  39. if((generateHeroAtMainTown && hasMainTown) || hasRandomHero)
  40. {
  41. //random hero
  42. return -1;
  43. }
  44. return -2;
  45. }
  46. bool PlayerInfo::canAnyonePlay() const
  47. {
  48. return canHumanPlay || canComputerPlay;
  49. }
  50. bool PlayerInfo::hasCustomMainHero() const
  51. {
  52. return !mainCustomHeroName.empty() && mainCustomHeroPortrait != -1;
  53. }
  54. EventCondition::EventCondition(EWinLoseType condition):
  55. object(nullptr),
  56. metaType(EMetaclass::INVALID),
  57. value(-1),
  58. objectType(-1),
  59. objectSubtype(-1),
  60. position(-1, -1, -1),
  61. condition(condition)
  62. {
  63. }
  64. EventCondition::EventCondition(EWinLoseType condition, si32 value, si32 objectType, const int3 & position):
  65. object(nullptr),
  66. metaType(EMetaclass::INVALID),
  67. value(value),
  68. objectType(objectType),
  69. objectSubtype(-1),
  70. position(position),
  71. condition(condition)
  72. {}
  73. void CMapHeader::setupEvents()
  74. {
  75. EventCondition victoryCondition(EventCondition::STANDARD_WIN);
  76. EventCondition defeatCondition(EventCondition::DAYS_WITHOUT_TOWN);
  77. defeatCondition.value = 7;
  78. //Victory condition - defeat all
  79. TriggeredEvent standardVictory;
  80. standardVictory.effect.type = EventEffect::VICTORY;
  81. standardVictory.effect.toOtherMessage = VLC->generaltexth->allTexts[5];
  82. standardVictory.identifier = "standardVictory";
  83. standardVictory.description.clear(); // TODO: display in quest window
  84. standardVictory.onFulfill = VLC->generaltexth->allTexts[659];
  85. standardVictory.trigger = EventExpression(victoryCondition);
  86. //Loss condition - 7 days without town
  87. TriggeredEvent standardDefeat;
  88. standardDefeat.effect.type = EventEffect::DEFEAT;
  89. standardDefeat.effect.toOtherMessage = VLC->generaltexth->allTexts[8];
  90. standardDefeat.identifier = "standardDefeat";
  91. standardDefeat.description.clear(); // TODO: display in quest window
  92. standardDefeat.onFulfill = VLC->generaltexth->allTexts[7];
  93. standardDefeat.trigger = EventExpression(defeatCondition);
  94. triggeredEvents.push_back(standardVictory);
  95. triggeredEvents.push_back(standardDefeat);
  96. victoryIconIndex = 11;
  97. victoryMessage = VLC->generaltexth->victoryConditions[0];
  98. defeatIconIndex = 3;
  99. defeatMessage = VLC->generaltexth->lossCondtions[0];
  100. }
  101. CMapHeader::CMapHeader() : version(EMapFormat::VCMI), height(72), width(72),
  102. twoLevel(true), difficulty(1), levelLimit(0), howManyTeams(0), areAnyPlayers(false)
  103. {
  104. setupEvents();
  105. allowedHeroes = VLC->heroh->getDefaultAllowed();
  106. players.resize(PlayerColor::PLAYER_LIMIT_I);
  107. }
  108. ui8 CMapHeader::levels() const
  109. {
  110. return (twoLevel ? 2 : 1);
  111. }