Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. #include "otpch.h"
  2. #include <iomanip>
  3. #include <stdlib.h>
  4. #include <boost/config.hpp>
  5. #include <boost/bind.hpp>
  6.  
  7. #include "iomap.h"
  8. #include "map.h"
  9. #include "tile.h"
  10.  
  11. #include "creature.h"
  12. #include "player.h"
  13. #include "combat.h"
  14.  
  15. #include "iomapserialize.h"
  16. #include "items.h"
  17.  
  18. #include "game.h"
  19. #include "configmanager.h"
  20.  
  21. [...]
  22.  
  23. bool Map::placeCreature(const Position& centerPos, Creature* creature, bool extendedPos /*= false*/, bool forced /*= false*/)
  24. {
  25. Monster* monster = creature->getMonster();
  26. if(monster && g_config.getBool(ConfigManager::MONSTER_HAS_LEVEL))
  27. {
  28. uint8_t level;
  29. if(!monster->getMonsterType()->hideLevel)
  30. {
  31. if(monster->isSummon())
  32. {
  33. std::string value;
  34. monster->getMaster()->getStorage((std::string)"monster_level", value);
  35.  
  36. uint8_t intValue = atoi(value.c_str());
  37. if(intValue || value == "0")
  38. level = intValue;
  39. else
  40. level = 1;
  41. }
  42. else
  43. level = monster->level;
  44.  
  45. char buffer [10];
  46. monster->name = monster->getName() + " [PDL : " + itoa(level, buffer, 10) + "]";
  47. }
  48. }
  49. bool foundTile = false, placeInPz = false;
  50. Tile* tile = getTile(centerPos);
  51. if(tile && !extendedPos)
  52. {
  53. placeInPz = tile->hasFlag(TILESTATE_PROTECTIONZONE);
  54. uint32_t flags = FLAG_IGNOREBLOCKITEM;
  55. if(creature->isAccountManager())
  56. flags |= FLAG_IGNOREBLOCKCREATURE;
  57.  
  58. ReturnValue ret = tile->__queryAdd(0, creature, 1, flags);
  59. if(forced || ret == RET_NOERROR || ret == RET_PLAYERISNOTINVITED)
  60. foundTile = true;
  61. }
  62.  
  63. size_t shufflePos = 0;
  64. PairVector relList;
  65. if(extendedPos)
  66. {
  67. shufflePos = 8;
  68. relList.push_back(PositionPair(-2, 0));
  69. relList.push_back(PositionPair(0, -2));
  70. relList.push_back(PositionPair(0, 2));
  71. relList.push_back(PositionPair(2, 0));
  72. std::random_shuffle(relList.begin(), relList.end());
  73. }
  74.  
  75. relList.push_back(PositionPair(-1, -1));
  76. relList.push_back(PositionPair(-1, 0));
  77. relList.push_back(PositionPair(-1, 1));
  78. relList.push_back(PositionPair(0, -1));
  79. relList.push_back(PositionPair(0, 1));
  80. relList.push_back(PositionPair(1, -1));
  81. relList.push_back(PositionPair(1, 0));
  82. relList.push_back(PositionPair(1, 1));
  83. std::random_shuffle(relList.begin() + shufflePos, relList.end());
  84.  
  85. uint32_t radius = 1;
  86. Position tryPos;
  87. for(uint32_t n = 1; n <= radius && !foundTile; ++n)
  88. {
  89. for(PairVector::iterator it = relList.begin(); it != relList.end() && !foundTile; ++it)
  90. {
  91. int32_t dx = it->first * n, dy = it->second * n;
  92. tryPos = centerPos;
  93.  
  94. tryPos.x = tryPos.x + dx;
  95. tryPos.y = tryPos.y + dy;
  96. if(!(tile = getTile(tryPos)) || (placeInPz && !tile->hasFlag(TILESTATE_PROTECTIONZONE)))
  97. continue;
  98.  
  99. if(tile->__queryAdd(0, creature, 1, 0) == RET_NOERROR)
  100. {
  101. if(!extendedPos)
  102. {
  103. foundTile = true;
  104. break;
  105. }
  106.  
  107. if(isSightClear(centerPos, tryPos, false))
  108. {
  109. foundTile = true;
  110. break;
  111. }
  112. }
  113. }
  114. }
  115.  
  116. if(!foundTile)
  117. return false;
  118.  
  119. int32_t index = 0;
  120. uint32_t flags = 0;
  121.  
  122. Item* toItem = NULL;
  123. if(Cylinder* toCylinder = tile->__queryDestination(index, creature, &toItem, flags))
  124. {
  125. toCylinder->__internalAddThing(creature);
  126. if(Tile* toTile = toCylinder->getTile())
  127. toTile->qt_node->addCreature(creature);
  128. }
  129.  
  130. return true;
  131. }
  132.  
  133. itoa(level, buffer, 10)
  134.  
  135. std::to_string(level)
  136.  
  137. atoi(value.c_str());
  138.  
  139. std::stoi(value)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement