SideInBattle.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/CPrivilegedInfoCallback.h"
  13. #include "../mapObjects/CGHeroInstance.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. void SideInBattle::init(const CGHeroInstance * Hero, const CArmedInstance * Army)
  16. {
  17. armyObjectID = Army->id;
  18. if (Hero)
  19. heroID = Hero->id;
  20. switch(Army->ID.toEnum())
  21. {
  22. case Obj::CREATURE_GENERATOR1:
  23. case Obj::CREATURE_GENERATOR2:
  24. case Obj::CREATURE_GENERATOR3:
  25. case Obj::CREATURE_GENERATOR4:
  26. color = PlayerColor::NEUTRAL;
  27. break;
  28. default:
  29. color = Army->getOwner();
  30. }
  31. if(color == PlayerColor::UNFLAGGABLE)
  32. color = PlayerColor::NEUTRAL;
  33. }
  34. const CArmedInstance * SideInBattle::getArmy() const
  35. {
  36. if (armyObjectID.hasValue())
  37. return dynamic_cast<const CArmedInstance*>(cb->getObjInstance(armyObjectID));
  38. return nullptr;
  39. }
  40. const CGHeroInstance * SideInBattle::getHero() const
  41. {
  42. if (heroID.hasValue())
  43. return cb->getHero(heroID);
  44. return nullptr;
  45. }
  46. VCMI_LIB_NAMESPACE_END