Guest User

Untitled

a guest
May 9th, 2025
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.86 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. #include "utils.h"
  4. #include "char.h"
  5. #include "sectree_manager.h"
  6. #include "config.h"
  7.  
  8. void CEntity::ViewCleanup(
  9. #ifdef ENABLE_GOTO_LAG_FIX
  10.     bool recursive
  11. #endif
  12. ) {
  13.     ENTITY_MAP::iterator it = m_map_view.begin();
  14.  
  15.     while (it != m_map_view.end()) {
  16.         LPENTITY entity = it->first;
  17.         ++it;
  18. #ifdef ENABLE_GOTO_LAG_FIX
  19.         entity->ViewRemove(this, recursive);
  20. #else
  21.         entity->ViewRemove(this, false);
  22. #endif
  23.     }
  24.  
  25.     m_map_view.clear();
  26. }
  27.  
  28. void CEntity::ViewReencode()
  29. {
  30.     if (m_bIsObserver)
  31.         return;
  32.  
  33.     EncodeRemovePacket(this);
  34.     EncodeInsertPacket(this);
  35.  
  36.     ENTITY_MAP::iterator it = m_map_view.begin();
  37.  
  38.     while (it != m_map_view.end())
  39.     {
  40.         LPENTITY entity = (it++)->first;
  41.  
  42.         EncodeRemovePacket(entity);
  43.         if (!m_bIsObserver)
  44.             EncodeInsertPacket(entity);
  45.  
  46.         if (!entity->m_bIsObserver)
  47.             entity->EncodeInsertPacket(this);
  48.     }
  49.  
  50. }
  51.  
  52. void CEntity::ViewInsert(LPENTITY entity, bool recursive)
  53. {
  54.     if (this == entity)
  55.         return;
  56.  
  57.     ENTITY_MAP::iterator it = m_map_view.find(entity);
  58.  
  59.     if (m_map_view.end() != it)
  60.     {
  61.         it->second = m_iViewAge;
  62.         return;
  63.     }
  64.  
  65.     m_map_view.insert(ENTITY_MAP::value_type(entity, m_iViewAge));
  66.  
  67.     if (!entity->m_bIsObserver)
  68.         entity->EncodeInsertPacket(this);
  69.  
  70.     if (recursive)
  71.         entity->ViewInsert(this, false);
  72. }
  73.  
  74. void CEntity::ViewRemove(LPENTITY entity, bool recursive)
  75. {
  76.     ENTITY_MAP::iterator it = m_map_view.find(entity);
  77.  
  78.     if (it == m_map_view.end())
  79.         return;
  80.  
  81.     m_map_view.erase(it);
  82.  
  83.     if (!entity->m_bIsObserver)
  84.         entity->EncodeRemovePacket(this);
  85.  
  86.     if (recursive)
  87.         entity->ViewRemove(this, false);
  88. }
  89.  
  90. class CFuncViewInsert
  91. {
  92.     private:
  93.         int dwViewRange;
  94.  
  95.     public:
  96.         LPENTITY m_me;
  97.  
  98.         CFuncViewInsert(LPENTITY ent) :
  99.             dwViewRange(VIEW_RANGE + VIEW_BONUS_RANGE),
  100.             m_me(ent)
  101.         {
  102.         }
  103.  
  104.         void operator () (LPENTITY ent)
  105.         {
  106.             if (!ent->IsType(ENTITY_OBJECT))
  107.             {
  108. #ifdef GUILD_WAR_COUNTER
  109.                 if(!((m_me->GetMapIndex() >= 1100000 && m_me->GetMapIndex() <= 1109999) && !m_me->IsObserverMode()))
  110. #endif
  111.                 if (DISTANCE_APPROX(ent->GetX() - m_me->GetX(), ent->GetY() - m_me->GetY()) > dwViewRange)
  112.                     return;
  113.             }
  114.  
  115.             m_me->ViewInsert(ent);
  116.  
  117.             if (ent->IsType(ENTITY_CHARACTER) && m_me->IsType(ENTITY_CHARACTER))
  118.             {
  119.                 LPCHARACTER chMe = (LPCHARACTER) m_me;
  120.                 LPCHARACTER chEnt = (LPCHARACTER) ent;
  121.  
  122.                 if (chMe->IsPC() && !chEnt->IsPC() && !chEnt->IsWarp() && !chEnt->IsGoto())
  123.                     chEnt->StartStateMachine();
  124.             }
  125.         }
  126. };
  127.  
  128. void CEntity::UpdateSectree()
  129. {
  130.     if (!GetSectree())
  131.     {
  132.         if (IsType(ENTITY_CHARACTER))
  133.         {
  134.             LPCHARACTER tch = (LPCHARACTER) this;
  135.             sys_err("null sectree name: %s %d %d",  tch->GetName(), GetX(), GetY());
  136.         }
  137.  
  138.         return;
  139.     }
  140.  
  141.     ++m_iViewAge;
  142.  
  143.     CFuncViewInsert f(this);
  144.     GetSectree()->ForEachAround(f);
  145.  
  146.     ENTITY_MAP::iterator it, this_it;
  147.  
  148. #ifdef GUILD_WAR_COUNTER
  149.     bool isCameraNeed = false;
  150.     if (IsType(ENTITY_CHARACTER))
  151.     {
  152.         LPCHARACTER tch = (LPCHARACTER)this;
  153.         if (tch)
  154.         {
  155.             if ((tch->GetMapIndex() >= 1100000 && tch->GetMapIndex() <= 1109999) && !tch->IsObserverMode())
  156.                 isCameraNeed = true;
  157.         }
  158.     }
  159. #endif
  160.  
  161.     if (m_bObserverModeChange)
  162.     {
  163.         if (m_bIsObserver)
  164.         {
  165.             it = m_map_view.begin();
  166.  
  167.             while (it != m_map_view.end())
  168.             {
  169.                 this_it = it++;
  170.                 if (this_it->second < m_iViewAge)
  171.                 {
  172.                     LPENTITY ent = this_it->first;
  173.  
  174.                    
  175.                     ent->EncodeRemovePacket(this);
  176.                     m_map_view.erase(this_it);
  177.  
  178.                    
  179.                     ent->ViewRemove(this, false);
  180.                 }
  181.                 else
  182.                 {
  183.  
  184.                     LPENTITY ent = this_it->first;
  185.  
  186.                    
  187.                     //ent->EncodeRemovePacket(this);
  188.                     //m_map_view.erase(this_it);
  189.  
  190.                    
  191.                     //ent->ViewRemove(this, false);
  192.                     EncodeRemovePacket(ent);
  193.                 }
  194.             }
  195.         }
  196.         else
  197.         {
  198.             it = m_map_view.begin();
  199.  
  200.             while (it != m_map_view.end())
  201.             {
  202.                 this_it = it++;
  203.  
  204.                 if (this_it->second < m_iViewAge)
  205.                 {
  206.                     LPENTITY ent = this_it->first;
  207.  
  208.                    
  209.                     ent->EncodeRemovePacket(this);
  210.                     m_map_view.erase(this_it);
  211.  
  212.                    
  213.                     ent->ViewRemove(this, false);
  214.                 }
  215.                 else
  216.                 {
  217.                     LPENTITY ent = this_it->first;
  218.                     ent->EncodeInsertPacket(this);
  219.                     EncodeInsertPacket(ent);
  220.  
  221.                     ent->ViewInsert(this, true);
  222.                 }
  223.             }
  224.         }
  225.  
  226.         m_bObserverModeChange = false;
  227.     }
  228.     else
  229.     {
  230.         if (!m_bIsObserver)
  231.         {
  232.             it = m_map_view.begin();
  233.  
  234.             while (it != m_map_view.end())
  235.             {
  236.                 this_it = it++;
  237.                
  238.                 LPENTITY ent = this_it->first;
  239.                
  240. #ifdef GUILD_WAR_COUNTER
  241.                 if (isCameraNeed)
  242.                 {
  243.                     if (ent->IsType(ENTITY_CHARACTER))
  244.                     {
  245.                         LPCHARACTER pch = (LPCHARACTER)ent;
  246.                         if (pch)
  247.                         {
  248.                             if (pch->IsObserverMode())
  249.                                 continue;
  250.                         }
  251.                     }
  252.                 }
  253. #endif
  254.  
  255.                 if (this_it->second < m_iViewAge)
  256.                 {
  257.                     LPENTITY ent = this_it->first;
  258.  
  259.                    
  260.                     ent->EncodeRemovePacket(this);
  261.                     m_map_view.erase(this_it);
  262.  
  263.                    
  264.                     ent->ViewRemove(this, false);
  265.                 }
  266.             }
  267.         }
  268.     }
  269. }
  270.  
  271.  
Advertisement
Add Comment
Please, Sign In to add comment