Cleaned up some of the NPC to NPC aggro code, only do aggro checks to other NPC's when the NPC is flagged for it

This commit is contained in:
Akkadius 2017-04-01 23:16:27 -05:00
parent e5e801dad5
commit d7dfc18c54
8 changed files with 12 additions and 31 deletions

View File

@ -1,6 +1,7 @@
EQEMu Changelog (Started on Sept 24, 2003 15:50) EQEMu Changelog (Started on Sept 24, 2003 15:50)
------------------------------------------------------- -------------------------------------------------------
== 4/1/2017 == == 4/1/2017 ==
Akkadius: Cleaned up some of the NPC to NPC aggro code, only do aggro checks to other NPC's when the NPC is flagged for it
Akkadius: [Performance] Reworked how all log calls are made in the source Akkadius: [Performance] Reworked how all log calls are made in the source
- Before we used Log.Out, we will now use a macro Log( - Before we used Log.Out, we will now use a macro Log(
- Before: Log.Out(Logs::General, Logs::Status, "Importing Spells..."); - Before: Log.Out(Logs::General, Logs::Status, "Importing Spells...");

View File

@ -111,9 +111,6 @@ Zone extensions and features
//path to where sql logs should be placed //path to where sql logs should be placed
#define SQL_LOG_PATH "sql_logs/" #define SQL_LOG_PATH "sql_logs/"
//New aggro system to reduce overhead.
#define REVERSE_AGGRO
//The highest you can #setskill / #setallskill //The highest you can #setskill / #setallskill
#define HIGHEST_CAN_SET_SKILL 400 #define HIGHEST_CAN_SET_SKILL 400

View File

@ -408,25 +408,19 @@ bool Mob::CheckWillAggro(Mob *mob) {
return(false); return(false);
} }
Mob* EntityList::AICheckCloseAggro(Mob* sender, float iAggroRange, float iAssistRange) { Mob* EntityList::AICheckNPCtoNPCAggro(Mob* sender, float iAggroRange, float iAssistRange) {
if (!sender || !sender->IsNPC()) if (!sender || !sender->IsNPC())
return(nullptr); return(nullptr);
#ifdef REVERSE_AGGRO
//with reverse aggro, npc->client is checked elsewhere, no need to check again
auto it = npc_list.begin(); auto it = npc_list.begin();
while (it != npc_list.end()) { while (it != npc_list.end()) {
#else
auto it = mob_list.begin();
while (it != mob_list.end()) {
#endif
Mob *mob = it->second; Mob *mob = it->second;
if (sender->CheckWillAggro(mob)) if (sender->CheckWillAggro(mob))
return mob; return mob;
++it; ++it;
} }
//LogFile->write(EQEMuLog::Debug, "Check aggro for %s no target.", sender->GetName());
return nullptr; return nullptr;
} }

View File

@ -134,9 +134,7 @@ Client::Client(EQStreamInterface* ieqs)
endupkeep_timer(1000), endupkeep_timer(1000),
forget_timer(0), forget_timer(0),
autosave_timer(RuleI(Character, AutosaveIntervalS) * 1000), autosave_timer(RuleI(Character, AutosaveIntervalS) * 1000),
#ifdef REVERSE_AGGRO
client_scan_npc_aggro_timer(RuleI(Aggro, ClientAggroCheckInterval) * 1000), client_scan_npc_aggro_timer(RuleI(Aggro, ClientAggroCheckInterval) * 1000),
#endif
tribute_timer(Tribute_duration), tribute_timer(Tribute_duration),
proximity_timer(ClientProximity_interval), proximity_timer(ClientProximity_interval),
TaskPeriodic_Timer(RuleI(TaskSystem, PeriodicCheckTimer) * 1000), TaskPeriodic_Timer(RuleI(TaskSystem, PeriodicCheckTimer) * 1000),

View File

@ -1460,9 +1460,7 @@ private:
Timer endupkeep_timer; Timer endupkeep_timer;
Timer forget_timer; // our 2 min everybody forgets you timer Timer forget_timer; // our 2 min everybody forgets you timer
Timer autosave_timer; Timer autosave_timer;
#ifdef REVERSE_AGGRO
Timer client_scan_npc_aggro_timer; Timer client_scan_npc_aggro_timer;
#endif
Timer tribute_timer; Timer tribute_timer;
Timer proximity_timer; Timer proximity_timer;

View File

@ -614,7 +614,6 @@ bool Client::Process() {
} }
} }
#ifdef REVERSE_AGGRO
//At this point, we are still connected, everything important has taken //At this point, we are still connected, everything important has taken
//place, now check to see if anybody wants to aggro us. //place, now check to see if anybody wants to aggro us.
// only if client is not feigned // only if client is not feigned
@ -630,7 +629,6 @@ bool Client::Process() {
} }
Log(Logs::General, Logs::Aggro, "Checking Reverse Aggro (client->npc) scanned_npcs (%i)", npc_scan_count); Log(Logs::General, Logs::Aggro, "Checking Reverse Aggro (client->npc) scanned_npcs (%i)", npc_scan_count);
} }
#endif
if (client_state != CLIENT_LINKDEAD && (client_state == CLIENT_ERROR || client_state == DISCONNECTED || client_state == CLIENT_KICKED || !eqs->CheckState(ESTABLISHED))) if (client_state != CLIENT_LINKDEAD && (client_state == CLIENT_ERROR || client_state == DISCONNECTED || client_state == CLIENT_KICKED || !eqs->CheckState(ESTABLISHED)))
{ {

View File

@ -412,7 +412,7 @@ public:
bool LimitCheckName(const char* npc_name); bool LimitCheckName(const char* npc_name);
void CheckClientAggro(Client *around); void CheckClientAggro(Client *around);
Mob* AICheckCloseAggro(Mob* sender, float iAggroRange, float iAssistRange); Mob* AICheckNPCtoNPCAggro(Mob* sender, float iAggroRange, float iAssistRange);
int GetHatedCount(Mob *attacker, Mob *exclude); int GetHatedCount(Mob *attacker, Mob *exclude);
void AIYellForHelp(Mob* sender, Mob* attacker); void AIYellForHelp(Mob* sender, Mob* attacker);
bool AICheckCloseBeneficialSpells(NPC* caster, uint8 iChance, float iRange, uint32 iSpellTypes); bool AICheckCloseBeneficialSpells(NPC* caster, uint8 iChance, float iRange, uint32 iSpellTypes);

View File

@ -479,18 +479,18 @@ void Mob::AI_Start(uint32 iMoveDelay) {
AI_movement_timer = std::unique_ptr<Timer>(new Timer(AImovement_duration)); AI_movement_timer = std::unique_ptr<Timer>(new Timer(AImovement_duration));
AI_target_check_timer = std::unique_ptr<Timer>(new Timer(AItarget_check_duration)); AI_target_check_timer = std::unique_ptr<Timer>(new Timer(AItarget_check_duration));
AI_feign_remember_timer = std::unique_ptr<Timer>(new Timer(AIfeignremember_delay)); AI_feign_remember_timer = std::unique_ptr<Timer>(new Timer(AIfeignremember_delay));
AI_scan_area_timer = std::unique_ptr<Timer>(new Timer(RandomTimer(RuleI(NPC, NPCToNPCAggroTimerMin), RuleI(NPC, NPCToNPCAggroTimerMax))));
if(CastToNPC()->WillAggroNPCs())
AI_scan_area_timer = std::unique_ptr<Timer>(new Timer(RandomTimer(RuleI(NPC, NPCToNPCAggroTimerMin), RuleI(NPC, NPCToNPCAggroTimerMax))));
AI_check_signal_timer = std::unique_ptr<Timer>(new Timer(AI_check_signal_timer_delay)); AI_check_signal_timer = std::unique_ptr<Timer>(new Timer(AI_check_signal_timer_delay));
#ifdef REVERSE_AGGRO
if(IsNPC() && !CastToNPC()->WillAggroNPCs())
AI_scan_area_timer->Disable();
#endif
if (GetAggroRange() == 0) if (GetAggroRange() == 0)
pAggroRange = 70; pAggroRange = 70;
if (GetAssistRange() == 0) if (GetAssistRange() == 0)
pAssistRange = 70; pAssistRange = 70;
hate_list.WipeHateList(); hate_list.WipeHateList();
m_Delta = glm::vec4(); m_Delta = glm::vec4();
@ -1351,18 +1351,13 @@ void Mob::AI_Process() {
{ {
//we processed a spell action, so do nothing else. //we processed a spell action, so do nothing else.
} }
else if (zone->CanDoCombat() && AI_scan_area_timer->Check()) else if (zone->CanDoCombat() && CastToNPC()->WillAggroNPCs() && AI_scan_area_timer->Check())
{ {
/* /*
* This is where NPCs look around to see if they want to attack anybody. * NPC to NPC aggro checking, npc needs npc_aggro flag
*
* if REVERSE_AGGRO is enabled, then this timer is disabled unless they
* have the npc_aggro flag on them, and aggro against clients is checked
* by the clients.
*
*/ */
Mob* temp_target = entity_list.AICheckCloseAggro(this, GetAggroRange(), GetAssistRange()); Mob* temp_target = entity_list.AICheckNPCtoNPCAggro(this, GetAggroRange(), GetAssistRange());
if (temp_target){ if (temp_target){
AddToHateList(temp_target); AddToHateList(temp_target);
} }