Rework of some existing spell AI code

This commit is contained in:
Uleat 2016-04-11 16:51:30 -04:00
parent a5119d1a9f
commit daeec0f5ec
3 changed files with 53 additions and 33 deletions

View File

@ -21,6 +21,14 @@
#include "bot.h"
#include "../common/string_util.h"
#if EQDEBUG >= 12
#define BotAI_DEBUG_Spells 25
#elif EQDEBUG >= 9
#define BotAI_DEBUG_Spells 10
#else
#define BotAI_DEBUG_Spells -1
#endif
bool Bot::AICastSpell(Mob* tar, uint8 iChance, uint16 iSpellTypes) {
if (!tar) {
@ -995,8 +1003,8 @@ bool Bot::AI_IdleCastCheck() {
bool result = false;
if (AIautocastspell_timer->Check(false)) {
#if MobAI_DEBUG_Spells >= 25
std::cout << "Non-Engaged autocast check triggered: " << this->GetCleanName() << std::endl; // cout undefine [CODEBUG]
#if BotAI_DEBUG_Spells >= 25
Log.Out(Logs::Detail, Logs::AI, "Bot Non-Engaged autocast check triggered: %s", this->GetCleanName());
#endif
AIautocastspell_timer->Disable(); //prevent the timer from going off AGAIN while we are casting.
@ -1320,6 +1328,11 @@ bool Bot::AIHealRotation(Mob* tar, bool useFastHeals) {
}
}
#if BotAI_DEBUG_Spells >= 10
Log.Out(Logs::Detail, Logs::AI, "Bot::AIHealRotation: heal spellid = %u, fastheals = %c, casterlevel = %u",
botSpell.SpellId, ((useFastHeals) ? ('T') : ('F')), GetLevel());
#endif
// If there is still no spell id, then there isn't going to be one so we are done
if (botSpell.SpellId == 0)
return false;

View File

@ -20,6 +20,14 @@
extern volatile bool is_zone_loaded;
#if EQDEBUG >= 12
#define MercAI_DEBUG_Spells 25
#elif EQDEBUG >= 9
#define MercAI_DEBUG_Spells 10
#else
#define MercAI_DEBUG_Spells -1
#endif
Merc::Merc(const NPCType* d, float x, float y, float z, float heading)
: NPC(d, nullptr, glm::vec4(x, y, z, heading), 0, false), endupkeep_timer(1000), rest_timer(1), confidence_timer(6000), check_target_timer(2000)
{
@ -1768,7 +1776,7 @@ bool Merc::AI_EngagedCastCheck() {
{
AIautocastspell_timer->Disable(); //prevent the timer from going off AGAIN while we are casting.
Log.Out(Logs::Detail, Logs::AI, "Engaged autocast check triggered (MERCS).");
Log.Out(Logs::Detail, Logs::AI, "Merc Engaged autocast check triggered");
int8 mercClass = GetClass();
@ -1822,8 +1830,8 @@ bool Merc::AI_IdleCastCheck() {
bool failedToCast = false;
if (AIautocastspell_timer->Check(false)) {
#if MobAI_DEBUG_Spells >= 25
std::cout << "Non-Engaged autocast check triggered: " << this->GetCleanName() << std::endl;
#if MercAI_DEBUG_Spells >= 25
Log.Out(Logs::Detail, Logs::AI, "Merc Non-Engaged autocast check triggered: %s", this->GetCleanName());
#endif
AIautocastspell_timer->Disable(); //prevent the timer from going off AGAIN while we are casting.

View File

@ -38,8 +38,10 @@ extern EntityList entity_list;
extern Zone *zone;
#ifdef _EQDEBUG
#define MobAI_DEBUG_Spells -1
#if EQDEBUG >= 12
#define MobAI_DEBUG_Spells 25
#elif EQDEBUG >= 9
#define MobAI_DEBUG_Spells 10
#else
#define MobAI_DEBUG_Spells -1
#endif
@ -97,12 +99,8 @@ bool NPC::AICastSpell(Mob* tar, uint8 iChance, uint16 iSpellTypes) {
) {
#if MobAI_DEBUG_Spells >= 21
std::cout << "Mob::AICastSpell: Casting: spellid=" << AIspells[i].spellid
<< ", tar=" << tar->GetName()
<< ", dist2[" << dist2 << "]<=" << spells[AIspells[i].spellid].range *spells[AIspells[i].spellid].range
<< ", mana_cost[" << mana_cost << "]<=" << GetMana()
<< ", cancast[" << AIspells[i].time_cancast << "]<=" << Timer::GetCurrentTime()
<< ", type=" << AIspells[i].type << std::endl;
Log.Out(Logs::Detail, Logs::AI, "Mob::AICastSpell: Casting: spellid=%u, tar=%s, dist2[%f]<=%f, mana_cost[%i]<=%i, cancast[%u]<=%u, type=%u",
AIspells[i].spellid, tar->GetName(), dist2, (spells[AIspells[i].spellid].range * spells[AIspells[i].spellid].range), mana_cost, GetMana(), AIspells[i].time_cancast, Timer::GetCurrentTime(), AIspells[i].type);
#endif
switch (AIspells[i].type) {
@ -323,7 +321,8 @@ bool NPC::AICastSpell(Mob* tar, uint8 iChance, uint16 iSpellTypes) {
}
#if MobAI_DEBUG_Spells >= 21
else {
std::cout << "Mob::AICastSpell: NotCasting: spellid=" << AIspells[i].spellid << ", tar=" << tar->GetName() << ", dist2[" << dist2 << "]<=" << spells[AIspells[i].spellid].range*spells[AIspells[i].spellid].range << ", mana_cost[" << mana_cost << "]<=" << GetMana() << ", cancast[" << AIspells[i].time_cancast << "]<=" << Timer::GetCurrentTime() << std::endl;
Log.Out(Logs::Detail, Logs::AI, "Mob::AICastSpell: NotCasting: spellid=%u, tar=%s, dist2[%f]<=%f, mana_cost[%i]<=%i, cancast[%u]<=%u, type=%u",
AIspells[i].spellid, tar->GetName(), dist2, (spells[AIspells[i].spellid].range * spells[AIspells[i].spellid].range), mana_cost, GetMana(), AIspells[i].time_cancast, Timer::GetCurrentTime(), AIspells[i].type);
}
#endif
}
@ -333,7 +332,7 @@ bool NPC::AICastSpell(Mob* tar, uint8 iChance, uint16 iSpellTypes) {
bool NPC::AIDoSpellCast(uint8 i, Mob* tar, int32 mana_cost, uint32* oDontDoAgainBefore) {
#if MobAI_DEBUG_Spells >= 1
std::cout << "Mob::AIDoSpellCast: spellid=" << AIspells[i].spellid << ", tar=" << tar->GetName() << ", mana=" << mana_cost << ", Name: " << spells[AIspells[i].spellid].name << std::endl;
Log.Out(Logs::Detail, Logs::AI, "Mob::AIDoSpellCast: spellid = %u, tar = %s, mana = %i, Name: '%s'", AIspells[i].spellid, tar->GetName(), mana_cost, spells[AIspells[i].spellid].name);
#endif
casting_spell_AIindex = i;
@ -2252,20 +2251,20 @@ bool NPC::AI_AddNPCSpells(uint32 iDBSpellsID) {
DBnpcspells_Struct* parentlist = database.GetNPCSpells(spell_list->parent_list);
uint32 i;
#if MobAI_DEBUG_Spells >= 10
std::cout << "Loading NPCSpells onto " << this->GetName() << ": dbspellsid=" << iDBSpellsID;
std::string debug_msg = StringFormat("Loading NPCSpells onto %s: dbspellsid=%u", this->GetName(), iDBSpellsID);
if (spell_list) {
std::cout << " (found, " << spell_list->numentries << "), parentlist=" << spell_list->parent_list;
debug_msg.append(StringFormat(" (found, %u), parentlist=%u", spell_list->numentries, spell_list->parent_list));
if (spell_list->parent_list) {
if (parentlist) {
std::cout << " (found, " << parentlist->numentries << ")";
}
if (parentlist)
debug_msg.append(StringFormat(" (found, %u)", parentlist->numentries));
else
std::cout << " (not found)";
debug_msg.append(" (not found)");
}
}
else
std::cout << " (not found)";
std::cout << std::endl;
else {
debug_msg.append(" (not found)");
}
Log.Out(Logs::Detail, Logs::AI, "%s", debug_msg.c_str());
#endif
uint16 attack_proc_spell = -1;
int8 proc_chance = 3;
@ -2412,20 +2411,20 @@ bool NPC::AI_AddNPCSpellsEffects(uint32 iDBSpellsEffectsID) {
uint32 i;
#if MobAI_DEBUG_Spells >= 10
std::cout << "Loading NPCSpellsEffects onto " << this->GetName() << ": dbspellseffectsid=" << iDBSpellsEffectsID;
std::string debug_msg = StringFormat("Loading NPCSpellsEffects onto %s: dbspellseffectid=%u", this->GetName(), iDBSpellsEffectsID);
if (spell_effects_list) {
std::cout << " (found, " << spell_effects_list->numentries << "), parentlist=" << spell_effects)list->parent_list;
debug_msg.append(StringFormat(" (found, %u), parentlist=%u", spell_effects_list->numentries, spell_effects_list->parent_list));
if (spell_effects_list->parent_list) {
if (parentlist) {
std::cout << " (found, " << parentlist->numentries << ")";
}
if (parentlist)
debug_msg.append(StringFormat(" (found, %u)", parentlist->numentries));
else
std::cout << " (not found)";
debug_msg.append(" (not found)");
}
}
else
std::cout << " (not found)";
std::cout << std::endl;
else {
debug_msg.append(" (not found)");
}
Log.Out(Logs::Detail, Logs::AI, "%s", debug_msg.c_str());
#endif
if (parentlist) {