PDA

View Full Version : Bot code outline


Criimson
07-03-2011, 05:32 AM
So I am looking over the bot code.
I am going to start with bot placement to get myself familiar with the code layout. I am only really familiar with working with my own code and it is a learning experience going through someone elses and seeing how it works.

1) Bot placement
A) Checking zone type (outdoor/indoor)
B) Setting SetFollowDistance(###) based on character type/weapon/zone type
C) Displacing bots within same group (casters/melee/ranged) by ##

2) Player settings to bot AI (based on code already implimented for now)
A) Hybrid healing
B) Melee taunting
C) Secondary melee pulling off healers/casters when agroed

3) Bot class AI
A) Enchanter AI
1) Crowd Control
2) Agro management
a) Buffing agro on MT
b) Memblurring mezzed targets

Thats a nice sized list. Will work from this.

Criimson

Criimson
07-03-2011, 06:11 AM
Movement code/placement code

if(IsEngaged())
{
_ZP(Mob_BOT_Process_IsEngaged);

if(rest_timer.Enabled())
rest_timer.Disable();

if(IsRooted())
SetTarget(hate_list.GetClosest(this));
else
SetTarget(hate_list.GetTop(this));

if(!GetTarget())
return;

if(HasPet())
GetPet()->SetTarget(GetTarget());

FaceTarget(GetTarget());

if(DivineAura())
return;

// Let's check if we have a los with our target.
// If we don't, our hate_list is wiped.
// Else, it was causing the bot to aggro behind wall etc... causing massive trains.
if(!CheckLosFN(GetTarget()) || GetTarget()->IsMezzed() || !IsAttackAllowed(GetTarget())) {
WipeHateList();

if(IsMoving()) {
SetHeading(0);
SetRunAnimSpeed(0);

if(moved) {
moved = false;
SendPosition();
SetMoving(false);
}
}

return;
}

bool atCombatRange = false;

float meleeDistance = GetMaxMeleeRangeToTarget(GetTarget());

if(botClass == SHADOWKNIGHT || botClass == PALADIN || botClass == WARRIOR) {
meleeDistance = meleeDistance * .30;
}
else {
meleeDistance *= (float)MakeRandomFloat(.50, .85);
}

bool atArcheryRange = IsArcheryRange(GetTarget());

if(GetRangerAutoWeaponSelect()) {
bool changeWeapons = false;

if(atArcheryRange && !IsBotArcher()) {
SetBotArcher(true);
changeWeapons = true;
}
else if(!atArcheryRange && IsBotArcher()) {
SetBotArcher(false);
changeWeapons = true;
}

if(changeWeapons)
ChangeBotArcherWeapons(IsBotArcher());
}

if(IsBotArcher() && atArcheryRange) {
if(IsMoving()) {
SetHeading(CalculateHeadingToTarget(GetTarget()->GetX(), GetTarget()->GetY()));
SetRunAnimSpeed(0);

if(moved) {
moved = false;
SendPosition();
SetMoving(false);
}
}

atCombatRange = true;
}
else if(IsBotCaster() && GetLevel() > 12) {
if(IsBotCasterCombatRange(GetTarget()))
atCombatRange = true;
}
else if(DistNoRoot(*GetTarget()) <= meleeDistance) {
atCombatRange = true;
}

if(atCombatRange) {
if(IsMoving()) {
SetHeading(CalculateHeadingToTarget(GetTarget()->GetX(), GetTarget()->GetY()));
SetRunAnimSpeed(0);

if(moved) {
moved = false;
SendPosition();
SetMoving(false);
}
}

if(AImovement_timer->Check()) {
if(!IsMoving() && GetClass() == ROGUE && !BehindMob(GetTarget(), GetX(), GetY())) {
// Move the rogue to behind the mob
float newX = 0;
float newY = 0;
float newZ = 0;

if(PlotPositionAroundTarget(GetTarget(), newX, newY, newZ)) {
CalculateNewPosition2(newX, newY, newZ, GetRunspeed());
return;
}
}
else if(!IsMoving() && GetClass() != ROGUE && (DistNoRootNoZ(*GetTarget()) < GetTarget()->GetSize())) {
// If we are not a rogue trying to backstab, let's try to adjust our melee range so we don't appear to be bunched up
float newX = 0;
float newY = 0;
float newZ = 0;

if(PlotPositionAroundTarget(GetTarget(), newX, newY, newZ, false)) {
CalculateNewPosition2(newX, newY, newZ, GetRunspeed());
return;
}
}

if(IsMoving())
SendPosUpdate();
else
SendPosition();
}

Looking at this code the notes state:
"// Let's check if we have a los with our target.
// If we don't, our hate_list is wiped.
// Else, it was causing the bot to aggro behind wall etc...causing massive trains."

The problem with this is when fighting in dungeons or tight quarters when I begin attacking a mob the bots stay in their position, forcing me to turn autoattack off until the other melees have LoS. Anyone object to having this changed so melee fighters continue to move unless they are engaged?

Criimson

Criimson
07-03-2011, 07:56 AM
First: any way to set it to where I can edit as long as I want? Seems after a certain amount of time I can't edit my posts.

Anyone able to join me on IRC sometime and show me how to create one of those "change" files. The ones where I can post the changes and someone can source them into their files if they'd like. I'd appreciate it.

Been doing some minor tweaks to test my knowledge of the code.
Changed:

When a group contains more than one character that can pacify, only one will attempt the pacify to save mana (minor I know, but it bothered me that both my cleric and enchanter were casting pacify spells)

Adjusted the healing code in bot.cpp so that hybrids will only heal when $%#& hits the fan (ie when a character is below 20% health).

Criimson

Congdar
07-03-2011, 12:48 PM
Movement code/placement code
The problem with this is when fighting in dungeons or tight quarters when I begin attacking a mob the bots stay in their position, forcing me to turn autoattack off until the other melees have LoS. Anyone object to having this changed so melee fighters continue to move unless they are engaged?

Criimson

You should have your macro ready to #bot summon the bots to you. Then they will have the same los as you and will attack. If you change this, they will run straight for your target through the walls and if they enter another room(highly possible in dungeons), there's your train. If you decide to write a bunch of los code for them to move around the corner on their own... that would be neat.

Criimson
07-03-2011, 01:07 PM
You should have your macro ready to #bot summon the bots to you. Then they will have the same los as you and will attack. If you change this, they will run straight for your target through the walls and if they enter another room(highly possible in dungeons), there's your train. If you decide to write a bunch of los code for them to move around the corner on their own... that would be neat.

Well I was more thinking of just removing the code that tells the Bots to stop moving when you have auto attack on if the bot in question was of a melee variety.

Congdar
07-03-2011, 01:38 PM
then you would get the bot running through the wall thing.

Criimson
07-03-2011, 01:42 PM
That is true. However, they only generate agro while engaged from what I can tell. They still wouldn't have a hate list or be engaged theyd simply keep moving. If they generated agro merely by having the player be engaged theyd still generate agro in the walls.