You know, many players measure the quality of a bot by how tough he is. For instance, the Omicron bot is considered the best by many people. Coincidentally or not, he is the toughest to defeat.
During the new few minutes, we are going to make two simple changes to our bot to make him more aggressive, more difficult to beat. First, he will learn to detect enemies faster. Second, he will not freeze up in pain so often.
With that said, we will slip down to the important subroutine called bot_look_for_players(). This is nearly the same thing as FindTarget() in ai.qc, written by id software. Anyway, look for this part:
r = range (client); if (r == RANGE_FAR) return FALSE; if (!visible (client)) return FALSE; if (r == RANGE_NEAR) { if (client.show_hostile < time && !infront (client)) return FALSE; } else if (r == RANGE_MID) { if (!infront (client)) return FALSE; }As you can see, this is distance-related code. If the target is too far, the bot doesn't see him. If the target is close but behind him, the bot dfoesn't see him. We want to change this.
/* r = range (client); if (r == RANGE_FAR) return FALSE; if (!visible (client)) return FALSE; if (r == RANGE_NEAR) { if (client.show_hostile < time && !infront (client)) return FALSE; } else if (r == RANGE_MID) { if (!infront (client)) return FALSE; } */Our bot will now spot enemies instantly. This makes him much more formidable. Is this cheating? Perhaps. but you have skills that the bot doesn't (seeing, hearing, feeling). I think he should have a couple abilities that you don't as well.
void() bot_pain1 =[ $pain1, bot_pain2 ] {}; void() bot_pain2 =[ $pain2, bot_pain3 ] {}; void() bot_pain3 =[ $pain4, bot_pain4 ] {}; void() bot_pain4 =[ $pain3, bot_pain5 ] {}; void() bot_pain5 =[ $pain4, bot_pain6 ] {}; void() bot_pain6 =[ $pain6, bot_run1 ] {};You see all the {}; sections? He is not thinking a damn thing. He should be at least calling his evasion routines. We can do that easily. Change the above to the below:
void() bot_pain1 =[ $pain1, bot_pain2 ] {bot_strafe();}; void() bot_pain2 =[ $pain2, bot_pain3 ] {bot_strafe();}; void() bot_pain3 =[ $pain4, bot_pain4 ] {bot_strafe();}; void() bot_pain4 =[ $pain3, bot_pain5 ] {bot_strafe();}; void() bot_pain5 =[ $pain4, bot_pain6 ] {bot_strafe();}; void() bot_pain6 =[ $pain6, bot_run1 ] {bot_strafe();};There you go. He will now think his evasion routine during each of these frames. Thus he will strafe, circle his enemy, or do whatever you told him to do. He'll be more mobile this way.