CMapHeader.cpp 3.5 KB

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