First Steps in Game AI: Your Own Bot

By ai-depot | June 30, 2002

Game Interface Approach

This part of the tutorial will demonstrate how you can implement a server-side bot without having to recompile the entire game. Basically, we’re writing a DLL that sits in between the other components of the game, that intercepts the appropriate calls, and that executes its own code when necessary.

We’ll be using Half-Life’s engine for this, as Botman has created a nice template to do this with very little hassle. This process is very well documented, and this part will focus on getting you started.

What You Need

The Game

Half Life

You can’t make an omelette without eggs! And in this case, this is a virtual egg that you should have (you’ll be able to use it over and over too ;) If you don’t have it, you’ll need to get it legally if you don’t intend to get into trouble.

Bot Template

The bot template written by Botman allows you to create your own bot based on existing code. This is a very nice way to get started, as it’ll save you the hassle of dealing with low-level engine interaction issues.

The current version (v.3) of the bot template is released with the HPB (high ping bastard bot) source. You’ll find it on the downloads page of Botman’s site.

A Compiler

We’re going to need something to compile the bot so the game can interact with it… I wouldn’t recommend doing it by hand-editing hexadecimal code, so here are your other options:

  • Visual C++
    Highly recommended. See the previous page for more information.
  • MingW32
    A free alternative. It’ll take you more time, but may save you some money! See this page for more details.

Things To Do First

Testing that every tool you’re working with can be done by trying to get the most trivial task working, and building upon that. You could call this incremental development if you wanted, but either way it comes in very handy when you’re not sure what you’re doing. I’ll assume you’ve downloaded everything, and extracted it all into nice and tidy folders. That’s not so much to ask, is it?

Compiling the DLL

The bot template comes with its own Workspace, so if you have Visual C++ you’ll have no trouble loading it up. You must then rebuild the entire thing, by going into the Build menu. This will work fine as long as your half-life folder is \half-life\. However otherwise, you should go into Project->Settings->Custom Build and change the directory in the “Commands” box.

This will work 97.31% of the time ;) If it doesn’t, check the ReadMe.txt file distributed with the bot template. Not only is the file very informative, but it will also give you a few hints to solve potential problems.

Starting A Game

The game DLL you’ve just built should now magically be in the appropriate directory. You may need to activate it by launching the Install.bat file in the valve directory. Now launch half-life with a console (it seems a bit silly having to specify this explicitly, but never mind):

hl +set console 1

This will allow you to add some extra bots in the game, and tweak other console variables later in your development. Note that some bots will be added automatically according to the bot.cfg file. It’s pretty much self-explanatory, just open it up with a text editor and see what’s inside!

Your Own Bot

This is all very nice, HPB is great, but you want to create your own bot right? The place to start is inside the file called bot.cpp. There’s a function called BotThink(), you’ll never guess what it does, so I’ll tell you… it runs the bot’s thinking code. The procedure itself is very big since HPB is quite complex. But you can get rid of most of that, and start again. All you really need is the last few lines, including the most important one:

g_engfuncs.pfnRunPlayerMove( pEdict, pEdict->v.v_angle,
pBot->f_move_speed, 0, 0, pEdict->v.button, 0, pBot->msecval );

That essentially executes the move you have planned, specified by the angles, movement, and impule commands. Changing those values will have pretty much the same effect as in Quake 2, so check back to the previous page for more details (if you can’t remember).

Pages: 1 2 3 4 5 6 7

Tags: none
Category: tutorial |

Comments