mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
Reduce string overhead and totem check overhead
This commit is contained in:
@@ -1993,7 +1993,7 @@ bool PlayerbotAI::HasAura(std::string const name, Unit* unit, bool maxStack, boo
|
|||||||
{
|
{
|
||||||
SpellInfo const* spellInfo = aurEff->GetSpellInfo();
|
SpellInfo const* spellInfo = aurEff->GetSpellInfo();
|
||||||
|
|
||||||
std::string const auraName = spellInfo->SpellName[0];
|
std::string_view const auraName = spellInfo->SpellName[0];
|
||||||
if (auraName.empty() || auraName.length() != wnamepart.length() || !Utf8FitTo(auraName, wnamepart))
|
if (auraName.empty() || auraName.length() != wnamepart.length() || !Utf8FitTo(auraName, wnamepart))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ class NamedObjectFactoryList
|
|||||||
factories.push_front(context);
|
factories.push_front(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
T* GetContextObject(std::string const name, PlayerbotAI* botAI)
|
T* GetContextObject(std::string const &name, PlayerbotAI* botAI)
|
||||||
{
|
{
|
||||||
for (typename std::list<NamedObjectFactory<T>*>::iterator i = factories.begin(); i != factories.end(); i++)
|
for (typename std::list<NamedObjectFactory<T>*>::iterator i = factories.begin(); i != factories.end(); i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ char* strstri(char const* str1, char const* str2);
|
|||||||
|
|
||||||
bool HasTotemValue::Calculate()
|
bool HasTotemValue::Calculate()
|
||||||
{
|
{
|
||||||
GuidVector units = *context->GetValue<GuidVector>("nearest npcs");
|
GuidVector units = *context->GetValue<GuidVector>("nearest totems");
|
||||||
for (ObjectGuid const guid : units)
|
for (ObjectGuid const guid : units)
|
||||||
{
|
{
|
||||||
Unit* unit = botAI->GetUnit(guid);
|
Unit* unit = botAI->GetUnit(guid);
|
||||||
@@ -17,14 +17,12 @@ bool HasTotemValue::Calculate()
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
Creature* creature = dynamic_cast<Creature*>(unit);
|
Creature* creature = dynamic_cast<Creature*>(unit);
|
||||||
if (!creature || !creature->IsTotem())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (creature->GetOwner() != bot) {
|
if (creature->GetOwner() != bot) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strstri(creature->GetName().c_str(), qualifier.c_str()) && bot->GetDistance(creature) <= botAI->GetRange("spell"))
|
if (strstri(creature->GetName().c_str(), qualifier.c_str()))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,3 +51,15 @@ bool NearestTriggersValue::AcceptUnit(Unit* unit)
|
|||||||
{
|
{
|
||||||
return !unit->IsPlayer();
|
return !unit->IsPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NearestTotemsValue::FindUnits(std::list<Unit*>& targets)
|
||||||
|
{
|
||||||
|
Acore::AnyUnitInObjectRangeCheck u_check(bot, range);
|
||||||
|
Acore::UnitListSearcher<Acore::AnyUnitInObjectRangeCheck> searcher(bot, targets, u_check);
|
||||||
|
Cell::VisitAllObjects(bot, searcher, range);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NearestTotemsValue::AcceptUnit(Unit* unit)
|
||||||
|
{
|
||||||
|
return unit->IsTotem();
|
||||||
|
}
|
||||||
@@ -39,4 +39,15 @@ class NearestTriggersValue : public NearestUnitsValue
|
|||||||
void FindUnits(std::list<Unit*>& targets) override;
|
void FindUnits(std::list<Unit*>& targets) override;
|
||||||
bool AcceptUnit(Unit* unit) override;
|
bool AcceptUnit(Unit* unit) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class NearestTotemsValue : public NearestUnitsValue
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NearestTotemsValue(PlayerbotAI* botAI, float range = 30.0f) : NearestUnitsValue(botAI, "nearest npcs", range, true) { }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void FindUnits(std::list<Unit*>& targets) override;
|
||||||
|
bool AcceptUnit(Unit* unit) override;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ class ValueContext : public NamedObjectContext<UntypedValue>
|
|||||||
creators["nearest game objects no los"] = &ValueContext::nearest_game_objects_no_los;
|
creators["nearest game objects no los"] = &ValueContext::nearest_game_objects_no_los;
|
||||||
creators["closest game objects"] = &ValueContext::closest_game_objects;
|
creators["closest game objects"] = &ValueContext::closest_game_objects;
|
||||||
creators["nearest npcs"] = &ValueContext::nearest_npcs;
|
creators["nearest npcs"] = &ValueContext::nearest_npcs;
|
||||||
|
creators["nearest totems"] = &ValueContext::nearest_totems;
|
||||||
creators["nearest vehicles"] = &ValueContext::nearest_vehicles;
|
creators["nearest vehicles"] = &ValueContext::nearest_vehicles;
|
||||||
creators["nearest friendly players"] = &ValueContext::nearest_friendly_players;
|
creators["nearest friendly players"] = &ValueContext::nearest_friendly_players;
|
||||||
creators["closest friendly players"] = &ValueContext::closest_friendly_players;
|
creators["closest friendly players"] = &ValueContext::closest_friendly_players;
|
||||||
@@ -367,6 +368,7 @@ class ValueContext : public NamedObjectContext<UntypedValue>
|
|||||||
static UntypedValue* closest_game_objects(PlayerbotAI* botAI) { return new NearestGameObjects(botAI, INTERACTION_DISTANCE); }
|
static UntypedValue* closest_game_objects(PlayerbotAI* botAI) { return new NearestGameObjects(botAI, INTERACTION_DISTANCE); }
|
||||||
static UntypedValue* log_level(PlayerbotAI* botAI) { return new LogLevelValue(botAI); }
|
static UntypedValue* log_level(PlayerbotAI* botAI) { return new LogLevelValue(botAI); }
|
||||||
static UntypedValue* nearest_npcs(PlayerbotAI* botAI) { return new NearestNpcsValue(botAI); }
|
static UntypedValue* nearest_npcs(PlayerbotAI* botAI) { return new NearestNpcsValue(botAI); }
|
||||||
|
static UntypedValue* nearest_totems(PlayerbotAI* botAI) { return new NearestTotemsValue(botAI); }
|
||||||
static UntypedValue* nearest_vehicles(PlayerbotAI* botAI) { return new NearestVehiclesValue(botAI); }
|
static UntypedValue* nearest_vehicles(PlayerbotAI* botAI) { return new NearestVehiclesValue(botAI); }
|
||||||
static UntypedValue* nearest_friendly_players(PlayerbotAI* botAI) { return new NearestFriendlyPlayersValue(botAI); }
|
static UntypedValue* nearest_friendly_players(PlayerbotAI* botAI) { return new NearestFriendlyPlayersValue(botAI); }
|
||||||
static UntypedValue* closest_friendly_players(PlayerbotAI* botAI) { return new NearestFriendlyPlayersValue(botAI, INTERACTION_DISTANCE); }
|
static UntypedValue* closest_friendly_players(PlayerbotAI* botAI) { return new NearestFriendlyPlayersValue(botAI, INTERACTION_DISTANCE); }
|
||||||
|
|||||||
Reference in New Issue
Block a user