2
0

SideInBattle.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * SideInBattle.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 "SideInBattle.h"
  12. #include "../callback/IGameInfoCallback.h"
  13. #include "../mapObjects/CGHeroInstance.h"
  14. #include "../mapObjects/CGTownInstance.h"
  15. VCMI_LIB_NAMESPACE_BEGIN
  16. void SideInBattle::init(const CGHeroInstance * Hero, const CArmedInstance * Army, const CGTownInstance * town)
  17. {
  18. armyObjectID = Army->id;
  19. if (Hero)
  20. {
  21. heroID = Hero->id;
  22. initialMana = Hero->mana;
  23. // NOTE: hero is not attached to town directly at this point, only indirectly via townAndVis
  24. additionalMana = Hero->valOfBonuses(BonusType::COMBAT_MANA_BONUS);
  25. if (town)
  26. additionalMana += town->valOfBonuses(BonusType::COMBAT_MANA_BONUS);
  27. }
  28. switch(Army->ID.toEnum())
  29. {
  30. case Obj::CREATURE_GENERATOR1:
  31. case Obj::CREATURE_GENERATOR2:
  32. case Obj::CREATURE_GENERATOR3:
  33. case Obj::CREATURE_GENERATOR4:
  34. color = PlayerColor::NEUTRAL;
  35. break;
  36. default:
  37. color = Army->getOwner();
  38. }
  39. if(color == PlayerColor::UNFLAGGABLE)
  40. color = PlayerColor::NEUTRAL;
  41. }
  42. const CArmedInstance * SideInBattle::getArmy() const
  43. {
  44. if (armyObjectID.hasValue())
  45. return dynamic_cast<const CArmedInstance*>(cb->getObjInstance(armyObjectID));
  46. return nullptr;
  47. }
  48. const CGHeroInstance * SideInBattle::getHero() const
  49. {
  50. if (heroID.hasValue())
  51. return cb->getHero(heroID);
  52. return nullptr;
  53. }
  54. VCMI_LIB_NAMESPACE_END