entity_view.cpp
## entity_view.cpp
This code block filters the rules for adding game entities (players, monsters, NPCs, ground items) to each other's view lists (`ViewInsert`) to optimize server performance. It reduces CPU and network packet load by preventing monsters and entities from tracking each other unnecessarily.
* **Player Characters (`chMe->IsPC()`):** Adds all entities within their field of view (monsters, NPCs, items, other players) to their view list without restrictions. There is no reduction in visuals on the player's screen.
* **Monsters and NPCs (`chMe->IsNPC()`):** Monsters are prevented from adding each other to their view lists. A monster or NPC takes a target into its view only under the following 4 conditions:
* **Players:** If the target is a player (`IsPC()`) (to attack or follow).
* **Healer Mobs:** If the monster has healer logic (`AIFLAG_HEALER`) and the target is in its own party (to cast healing spells).
* **Ship Defense (Hydra):** If the target is the Hydra mast (`20434`) (to attack the mast).
* **City Guards:** If the NPC is a guard (`IsGuardNPC()`), it sees surrounding monsters (to strike mobs entering the city).
* **Non-Character Entities (`!m_me->IsType(ENTITY_CHARACTER)`):** Ground items or map objects only register surrounding players (`IsPC()`) into their view lists. Monsters are entirely excluded from the ground item matrix.
* **When the Macro is Disabled (`#else`):** The classic Metin2 logic operates; all entities within range add each other to their view lists without exception.
In classic Metin2, when 100 monsters in a room process each other, it creates $100 \times 100 = 10,000$ view matrix checks. Thanks to this filtering, monsters ignore each other, and the complexity drops solely to the number of players in that room.
#define ENABLE_REDUCED_ENTITY_VIEW
Code:
#ifdef ENABLE_REDUCED_ENTITY_VIEW
if (m_me->IsType(ENTITY_CHARACTER))
{
const auto chMe = (LPCHARACTER) m_me;
// players view every entity
if (chMe->IsPC())
m_me->ViewInsert(ent);
// npcs view only a restricted amount of entities
else if (chMe->IsNPC() && ent->IsType(ENTITY_CHARACTER))
{
constexpr auto DefenseWaveMast = 20434;
const auto chEnt = (LPCHARACTER) ent;
// mobs view every player
if (chEnt->IsPC())
m_me->ViewInsert(ent);
// aiflag healers view their party
else if (IS_SET(chMe->GetAIFlag(), AIFLAG_HEALER) && chMe->GetParty() && chMe->GetParty() == chEnt->GetParty())
m_me->ViewInsert(ent);
// hydra mast is seen by other mobs
else if (chEnt->GetRaceNum() == DefenseWaveMast)
m_me->ViewInsert(ent);
// city guardians see all mobs
else if (chMe->IsGuardNPC())
m_me->ViewInsert(ent);
}
}
else if (ent->IsType(ENTITY_CHARACTER))
{
const auto chEnt = (LPCHARACTER) ent;
// other entities see every player
if (chEnt->IsPC())
m_me->ViewInsert(ent);
}
#else
m_me->ViewInsert(ent);
#endif

