AI Tutorial
Bot Fundamentals

 

     Now that I've released the Tutor Bot, guys ask me, "What does your bot do?" The question makes me scratch my head. It makes me wonder if they missed the whole point.
     Simply put, the Tutor Bot is not a player's bot, he's a developer's bot. He's made for people who are looking for a simple bot code base, for people who want to understand how a bot works.
     And so I've decided to write this lesson to explain the fundamentals of a deathmatch bot. It's pretty simple, as you'll see. So let's get at it.

 

 

     1. The Entity
     First off, a bot is nothing more than a QuakeC entity. In fact, he's basically a monster that acts like a player.
     The Tutor Bot is spawned in create_bot(). Of course he has a size and a shape. One special thing about him is that he's a SOLID_SLIDEBOX, just like monsters. This means he can use navigation code like movetogoal().
     The other special aspect about him is his animation. It's basically the sequences that are found in player.qc. Naturally, he has animation for standing, walking, and running. But he also possesses sequences for shotgun, rocket, nail, and lightning attacks.

 

 

     2. The Lifespan
     If you're reading this tutorial (um, I guess you are), you want to know how the bot works, pure and simple. I'll get right to it and list some of the major subroutines from birth to death:

create_bot() ................... spawns the bot
bot_stand1() ................... animation which loops through bot_stand5()
bot_stand() .................... AI standing thoughts
bot_walk1() .................... animation that loops through bot_walk6()
bot_look_for_players() ... searches for enemies
bot_run1() ..................... animation that loops through bot_run6()
bot_run() ...................... AI fighting thoughts
bot_strafe() ................... AI evasion and attacking thoughts
bot_pain() ..................... happens when he gets hit
bot_attack() ................... his central attacking routine
bot_rock1() .................... one of his attack animation sequences
bot_die() ...................... happens when he's out of health
bot_die1() ..................... one of his death animation sequences
respawn_bot() .................. puts him back into the game

     This is a sample of any given lifespan of the bot. It does not include every subroutine that is called, and may vary in his next lifespan.
     As you can see, the animation happens first, and kind of serves as the frame for the bot's life. The AI routines are usually called from the animation frames. Thus, they usually have counterparts to each other, like bot_stand1() and bot_stand().
     A little tip which you may have noticed: if you see a subroutine ending with the number one, like bot_light1(), it most likely is an animation sequence.

 

 

     3. The Behavior
     As we now know, the bot's animation and AI is tied together. The animation happens first, but the AI can call different animation scenes.
     For instance, bot_walk1() is the start of an animation sequence. The AI routine bot_walk() is called during each frame.
     In the bot_walk() routine, the bot looks for enemies. If he finds one, he calls bot_run1(), an animation sequence.
     Maybe that was a little wordy. Basically what I mean to say is that the bot is a series of animation-AI sequence loops. Period.
     His two important variables are self.goalentity and self.enemy. His goal entity can be an item, a bot, a player, or the world. The id Software function movetogoal() will move toward whatever his goal entity is.
     His enemy can be a bot, a player, or the world. The enemy also becomes his goalentity, and again we can use movetogoal() to follow the enemy.

 

 

     4. The FAQ
     Q. Why does the Tutor Bot act so simply?
     A. Because I want him to be simple. I focused more on keeping his program clean and easy than his behavior. Yes, the FrogBot would kick his ass, but the Frog's code is probably 10 times as long and 100 times as complex.
     Q. If the bot moves and acts like a player, why can't they share the same subroutines?
     A. The bot is basically a monster with the player model who has more than one weapon. The player subroutines use different physics and methods that wouldn't match with the bot.
     Q. Why didn't you use Norse_movetogoal() and other better code like that?
     A. The Norse_movetogoal() program is at least 50 pages long, and all it does is move the bot from one end of the room to the other. To repeat: 50 pages long. The whole Tutor Bot isn't that long. I believe in small solutions to big problems.
     Q. The Omicron does this and that and the other thing and he calculates the square root of pi over nothing. Why doesn't the Tutor Bot do these things?
     A. You see, AI is a tricky business. And I mean that literally: it is just like magic. If you can fool the player into believing he is smart, then he's smart. The bot doesn't need to do trigonometry. You only see him when he's fighting anyway, which is a small fraction of the time.
     Q. If I don't know much, how can I learn about a bot?
     A. Number one, read. Number two, experiment. You'll never learn anything useful if you don't get into that code and screw with things. I recommend messing around with bot_walk(), bot_search_for_items() and especially bot_strafe().
     Q. Why does the bot actually pick up items?
     A. Again, I wanted it easy to plug the Tutor Bot into any project, so I wanted as few steps as possible. If you want him to pick up things, you'll have to make changes in items.qc.
     Q. Shouldn't I just use the code for the FrogBot, or even the Reaper?
     A. First, the source code for those bots is pretty complex. I didn't learn much from them. Second, the Tutor Bot would be easier to modify, customize, even add to other mods.
     Q. Why didn't you make the Tutor Bot smarter?
     A. Players don't want more intelligent AI, they want more enjoyable AI. I'm a fan of AI, but wanting smart AI is just a myth. I want a bot who may tease me, gesture at me, or trick me with a hologram. Can you give that to me?

 


What We Learned

1. The bot's animation and AI work together
2. A bot is basically a monster who looks like a player
3. Standing, walking, and running are his main states
4. Self.goalentity and self.enemy are his main variables
5. Players want fun AI, not smart AI
 


     Author: Coffee
     Questions: coffee@planetquake.com
     AI chat on ICQ: 2716002