Advertisement
Guest User

Untitled

a guest
Sep 15th, 2024
15
0
174 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.82 KB | None | 0 0
  1. bool Game::placeCreature(Position &pos, Creature* c
  2. #ifdef YUR_LOGIN_QUEUE
  3.                          , int32_t* placeInQueue
  4. #endif //YUR_LOGIN_QUEUE
  5.                          )
  6. {
  7.     OTSYS_THREAD_LOCK_CLASS lockClass(gameLock, "Game::placeCreature()");
  8.    
  9.     bool success = false;
  10.     Player *p = dynamic_cast<Player*>(c);
  11.     Monster *monsterzin = dynamic_cast<Monster*>(c);
  12.  
  13. #ifdef YUR_LOGIN_QUEUE
  14.     if (!p || c->access >= g_config.ACCESS_ENTER ||
  15. #ifdef YUR_PREMIUM_PROMOTION
  16.         (p->isPremium() && !g_config.QUEUE_PREMMY) ||
  17. #endif //YUR_PREMIUM_PROMOTION
  18.     loginQueue.login(p->accountNumber, getPlayersOnline(), max_players, placeInQueue)){
  19. #else //YUR_LOGIN_QUEUE
  20.     if (!p || c->access >= g_config.ACCESS_ENTER || getPlayersOnline() < max_players){
  21. #endif //YUR_LOGIN_QUEUE
  22.         success = map->placeCreature(pos, c);
  23.         if(success)
  24.         {
  25.             c->useThing();
  26.  
  27.             c->setID();
  28.             //std::cout << "place: " << c << " " << c->getID() << std::endl;
  29.             listCreature.addList(c);
  30.             c->addList();
  31.             c->isRemoved = false;
  32. #ifdef _BBK_DEATH_DELAY
  33.             c->isDead = false;
  34. #endif //_BBK_DEATH_DELAY
  35.  
  36.             sendAddThing(NULL,c->pos,c); // linia 1845 CRASH
  37.            
  38.             if(p)
  39.             {
  40.  
  41. ....
  42. ....
  43.  
  44. void Game::sendAddThing(Player* player,const Position &pos,const Thing* thing){
  45.     if(pos.x == 0xFFFF) {
  46.         if(!player)
  47.             return;
  48.         if(pos.y & 0x40) { //container
  49.             if(!thing)
  50.                 return;
  51.  
  52.             const Item *item = dynamic_cast<const Item*>(thing);
  53.             if(!item)
  54.                 return;
  55.  
  56.             uint8_t containerid = pos.y & 0x0F;
  57.             Container* container = player->getContainer(containerid);
  58.             if(!container)
  59.                 return;
  60.  
  61.             SpectatorVec list;
  62.             SpectatorVec::iterator it;
  63.  
  64.             Position centerpos = (container->pos.x == 0xFFFF ? player->pos : container->pos);
  65.             //getSpectators(Range(centerpos,2,2,2,2,false), list);
  66.             getSpectators(Range(centerpos,2,2,2,2, false), list, true, false);
  67.  
  68.             if(!list.empty()) {
  69.                 for(it = list.begin(); it != list.end(); ++it) {
  70.                     Player *spectator = dynamic_cast<Player*>(*it);
  71.                     if(spectator)
  72.                         spectator->onItemAddContainer(container,item);
  73.                 }
  74.             }
  75.             else
  76.                 player->onItemAddContainer(container,item);
  77.  
  78.         }
  79.         else //inventory
  80.         {
  81.             player->sendInventory(pos.y);
  82.         }
  83.     }
  84.     else //ground
  85.     {
  86.         if(!thing)
  87.             return;
  88.  
  89.         SpectatorVec list;
  90.         SpectatorVec::iterator it;
  91.  
  92.         //getSpectators(Range(pos,true), list);
  93.         getSpectators(Range(pos, true), list, false, false); // LINIA 8249 CRASH
  94.  
  95.         //players
  96.         for(it = list.begin(); it != list.end(); ++it) {
  97.             if(dynamic_cast<Player*>(*it)) {
  98.                 (*it)->onThingAppear(thing);
  99.             }
  100.         }
  101.  
  102.         //none-players
  103.         for(it = list.begin(); it != list.end(); ++it) {
  104.             if(!dynamic_cast<Player*>(*it)) {
  105.                 (*it)->onThingAppear(thing);
  106.             }
  107.         }
  108.     }
  109. }
  110.  
  111.  
  112. void Game::getSpectators(const Range& range, SpectatorVec& list, bool onlyPlayers /*=true*/, bool checkDuplicate /*=false*/)
  113. {
  114.     if(map){
  115.         map->getSpectators(range, list, onlyPlayers, checkDuplicate); // LINIA 4502 CRASH
  116.     }
  117. }
  118.  
  119.  
  120.  
  121. --- map.cpp --
  122. void Map::getSpectators(const Range& range, SpectatorVec& list, bool onlyPlayers /*=true*/, bool checkDuplicate /*=false*/)
  123. {
  124.     /*
  125.     #ifdef __DEBUG__
  126.         std::cout << "Viewer position at x: " << range.centerpos.x
  127.             << ", y: " << range.centerpos.y
  128.             << ", z: " << range.centerpos.z << std::endl;
  129.         std::cout << "Min Range x: " << range.minRange.x
  130.             << ", y: " << range.minRange.y
  131.             << ", z: " << range.minRange.z << std::endl;
  132.         std::cout << "Max Range x: " << range.maxRange.x
  133.             << ", y: " << range.maxRange.y
  134.             << ", z: " << range.maxRange.z << std::endl;
  135.     #endif
  136.     */
  137.  
  138.     int32_t offsetz;
  139.     CreatureVector::iterator cit;
  140.     Tile *tile;
  141.  
  142.     for(int32_t nz = range.minRange.z; nz != range.maxRange.z + range.zstep; nz += range.zstep)
  143.     {
  144.         offsetz = range.centerpos.z - nz;
  145.         //negative offset means that the player is on a lower floor than ourself
  146.  
  147.         for (int32_t nx = range.minRange.x + offsetz; nx <= range.maxRange.x + offsetz; ++nx)
  148.         {
  149.             for (int32_t ny = range.minRange.y + offsetz; ny <= range.maxRange.y + offsetz; ++ny)
  150.             {
  151.                 tile = getTile(nx + range.centerpos.x, ny + range.centerpos.y, nz);
  152.                 if (tile)
  153.                 {
  154.                     for (cit = tile->creatures.begin(); cit != tile->creatures.end(); ++cit)
  155.                     {
  156.                         /*
  157.                         #ifdef __DEBUG__
  158.                                                 std::cout << "Found " << (*cit)->getName() << " at x: " << (*cit)->pos.x << ", y: " << (*cit)->pos.y << ", z: " << (*cit)->pos.z << ", offset: " << offsetz << std::endl;
  159.                         #endif
  160.                         */
  161.                         if (*cit) // dodane przeze mnie dla pewnosci // linia 327 CRASH
  162.                         list.push_back((*cit));
  163.                     }
  164.                 }
  165.             }
  166.         }
  167.     }
  168. }
  169.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement