ViewWorldMechanics.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * ViewWorldMechanics.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 "ViewWorldMechanics.h"
  12. #include "../CSpellHandler.h"
  13. #include "../../CPlayerState.h"
  14. #include "../../callback/IGameInfoCallback.h"
  15. #include "../../mapObjects/CGHeroInstance.h"
  16. #include "../../mapping/CMap.h"
  17. #include "../../networkPacks/PacksForClient.h"
  18. VCMI_LIB_NAMESPACE_BEGIN
  19. ViewMechanics::ViewMechanics(const CSpell * s):
  20. AdventureSpellMechanics(s)
  21. {
  22. }
  23. ESpellCastResult ViewMechanics::applyAdventureEffects(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
  24. {
  25. ShowWorldViewEx pack;
  26. pack.player = parameters.caster->getCasterOwner();
  27. const auto spellLevel = parameters.caster->getSpellSchoolLevel(owner);
  28. const auto & fowMap = env->getCb()->getPlayerTeam(parameters.caster->getCasterOwner())->fogOfWarMap;
  29. for(const auto & obj : env->getMap()->getObjects())
  30. {
  31. //deleted object remain as empty pointer
  32. if(obj && filterObject(obj, spellLevel))
  33. {
  34. ObjectPosInfo posInfo(obj);
  35. if(fowMap[posInfo.pos.z][posInfo.pos.x][posInfo.pos.y] == 0)
  36. pack.objectPositions.push_back(posInfo);
  37. }
  38. }
  39. pack.showTerrain = showTerrain(spellLevel);
  40. env->apply(pack);
  41. return ESpellCastResult::OK;
  42. }
  43. ///ViewAirMechanics
  44. ViewAirMechanics::ViewAirMechanics(const CSpell * s)
  45. : ViewMechanics(s)
  46. {
  47. }
  48. bool ViewAirMechanics::filterObject(const CGObjectInstance * obj, const int32_t spellLevel) const
  49. {
  50. return (obj->ID == Obj::ARTIFACT) || (spellLevel > 1 && obj->ID == Obj::HERO) || (spellLevel > 2 && obj->ID == Obj::TOWN);
  51. }
  52. bool ViewAirMechanics::showTerrain(const int32_t spellLevel) const
  53. {
  54. return false;
  55. }
  56. ///ViewEarthMechanics
  57. ViewEarthMechanics::ViewEarthMechanics(const CSpell * s)
  58. : ViewMechanics(s)
  59. {
  60. }
  61. bool ViewEarthMechanics::filterObject(const CGObjectInstance * obj, const int32_t spellLevel) const
  62. {
  63. return (obj->ID == Obj::RESOURCE) || (spellLevel > 1 && obj->ID == Obj::MINE);
  64. }
  65. bool ViewEarthMechanics::showTerrain(const int32_t spellLevel) const
  66. {
  67. return spellLevel > 2;
  68. }
  69. VCMI_LIB_NAMESPACE_END