ViewWorldEffect.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * ViewWorldEffect.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 "ViewWorldEffect.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 "../../modding/IdentifierStorage.h"
  18. #include "../../networkPacks/PacksForClient.h"
  19. VCMI_LIB_NAMESPACE_BEGIN
  20. ViewWorldEffect::ViewWorldEffect(const CSpell * s, const JsonNode & config)
  21. {
  22. showTerrain = config["showTerrain"].Bool();
  23. for(const auto & objectNode : config["objects"].Struct())
  24. {
  25. if(objectNode.second.Bool())
  26. {
  27. LIBRARY->identifiers()->requestIdentifier(objectNode.second.getModScope(), "object", objectNode.first, [this](si32 index)
  28. {
  29. filteredObjects.push_back(MapObjectID(index));
  30. });
  31. }
  32. }
  33. }
  34. ESpellCastResult ViewWorldEffect::applyAdventureEffects(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
  35. {
  36. ShowWorldViewEx pack;
  37. pack.player = parameters.caster->getCasterOwner();
  38. pack.showTerrain = showTerrain;
  39. const auto & fowMap = env->getCb()->getPlayerTeam(parameters.caster->getCasterOwner())->fogOfWarMap;
  40. for(const auto & obj : env->getMap()->getObjects())
  41. {
  42. //deleted object remain as empty pointer
  43. if(obj && vstd::contains(filteredObjects, obj->ID))
  44. {
  45. ObjectPosInfo posInfo(obj);
  46. if(fowMap[posInfo.pos.z][posInfo.pos.x][posInfo.pos.y] == 0)
  47. pack.objectPositions.push_back(posInfo);
  48. }
  49. }
  50. env->apply(pack);
  51. return ESpellCastResult::OK;
  52. }
  53. VCMI_LIB_NAMESPACE_END