.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Bot Coding
General Bot Coding See what a pain it is to get those little mechs shooting around

Reply
 
Thread Tools
bot coding in CS?
Old
  (#1)
MusicMan
Member
 
Status: Offline
Posts: 236
Join Date: Feb 2004
Default bot coding in CS? - 23-03-2004

Hi Everyone. I would really appreciate some help here

Ok, the thing is that I am currently studying C++ and already know quite a bit. But I really want to understand what the code in HL does. you know what I mean. I know C++, but i dont know HL.

What would your tips be for a guy like me wanting to create a bot?

Please give me some links if you must
How did you manage to learn the HL SDK?

Its like when I look at a piece of code I know what it does, but I dont know what the variables and stuff are and why and when I must use them i.e pEdict what is that?

Its that kind of thing I need to know
Please help me

BTW what are some good internet sites to learn C++, I would like some just to have some backup resources for studying

Thanks in advance

MusicMan
  
Reply With Quote
Re: bot coding in CS?
Old
  (#2)
Terran
Member
 
Terran's Avatar
 
Status: Offline
Posts: 431
Join Date: Jan 2004
Default Re: bot coding in CS? - 23-03-2004

botman recommended http://www.cplusplus.com/
  
Reply With Quote
Re: bot coding in CS?
Old
  (#3)
Cpl. Shrike
ShrikeBot Coder/Moderator
 
Cpl. Shrike's Avatar
 
Status: Offline
Posts: 550
Join Date: Mar 2004
Location: The Netherlands
Default Re: bot coding in CS? - 23-03-2004

I learned the HL BOT code by just looking at it for hours and hours.
Browsing through the code and flowing functions in the code looking up variable names. writing down what they mean or stand for (as i thought as it was), then again looking at it for hours and hours. and browsing more through the code. again absorbing variable and funtion names (etc etc.)

After weeks (months) i tried to change one little thingy.
Eureka it worked.

By then the story repeated it self.
Trying to understand the code (what variables mean and where they come from in the code.)

Valve VERC
botmans forums
various other C and C++ sites
and now .::Bots United::.
Where most helpfull, they all helped me in understanding wtf i was doing.

The SDK or Bot code has some comments in them that help also.
Reading Botmans "readme" was/is the BEST ever that got me started.
Thanks again botman ( I think every body should read that file once before starting to code bots.)

I don't think there are tuts about how to code bots.
Hence that why we are all here.
It is C code rest is just made up variables and funtions by a VALVE coder or botman.
Only the comments or the coder him self can explain it.
It's all about figuring it out.

??? ???

Last edited by Cpl. Shrike; 23-03-2004 at 18:30..
  
Reply With Quote
Re: bot coding in CS?
Old
  (#4)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: bot coding in CS? - 23-03-2004

Exactly what Cpl. Shrike said !

One thing that may help you first:

you must learn to separate the bot variables and the HL engine variables. Everywhere you see an "edict_t" variable, it points to a HL ENTITY. Everywhere you see pEdict->v.somestuff, it points to the variable "somestuff" that belongs to the entity pEdict that is located among the other entities of the game within the HL engine. It means that you can't CHANGE these variable names, but you can read (and sometimes write) into them.

Everything in Half-Life is an entity. The map is one big entity (entity number 0), and players, doors, crates and stuff are other small entities that are just spawned on top of the map. Every entity has a set of parameters : a model mesh (the 3D polygons), a bounding box (that is, an invisible box around that entity mostly used for collision checking), although some entities use different parameters than the others, and for some, different means of storing things. For example, the players' mesh models are overriden by their client infobuffer (you'll read about that stuff later, for now, just take the word for it). And the entity #0 (the map) is not linkable to an edict_t pointer.

Now in order to keep track of which entity is one of our bots, and since we need additional storage space for putting our own variables for each bot, botman had the idea to "embed" this edict_t pointer into a wider structure : the bot_t structure.

Since there can be at max 32 players in a HL game, the bots are an array of 32 bot_t structures. Some of which are filled, some of them are free.

bot_t bots[32]; // max of 32 bots in game

And their edict_t pointer (pointing to the HL ENTITY that describes this bot) is also stored in this bot_t structure. For example, the HL entity for the 3rd bot in our list is:

bots[2].pEdict

For convenience, botman uses bot_t pointers instead of indexing the bots array each time :

bot_t *pBot = &bots[i];

and so, later on in his functions, you see things like :

pBot->pEdict->v.v_angle.x = 0; // reset the pitch view angle of the bot (using the engine variables for the bot entity)

because pBot actually is &bots[i]. It is the same as doing :

bots[i].pEdict->v.v_angle.x = 0;

And if one wants to bind a variable in the bot_t structure (which is located in our bot DLL), one level up of the edict_t structure (which one is located within the engine) :

if (bots[bot_number].pBotEnemy != NULL) // does this bot have an enemy ?

or you can also do

if (pBot->pBotEnemy != NULL) // does this bot have an enemy ?

if you're in a function which takes "bot_t *pBot" as a parameter.

Somebody feel free to move this to the wiki if needed and comment/correct/fix over it



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."

Last edited by Pierre-Marie Baty; 23-03-2004 at 22:31.. Reason: fixed mistake, thanks Rick :)
  
Reply With Quote
Re: bot coding in CS?
Old
  (#5)
Terran
Member
 
Terran's Avatar
 
Status: Offline
Posts: 431
Join Date: Jan 2004
Default Re: bot coding in CS? - 23-03-2004

This headache kills me...

Quote:
Originally Posted by Pierre-Marie Baty
For convenience, botman uses bot_t pointers instead of indexing the bots array each time :

bot_t *pBot = &bots[i].pEdict;

and so, later on in his functions, you see things like :

pBot->pEdict->v.v_angle.x = 0; // reset the pitch view angle of the bot (using the engine variables for the bot entity)
Maybe a stubid question, but as I said, my c++ is a little bit rusty:
If pBot is a pointer to[i] &bots.pEdict then why is it pBot->pEdict->v.v_angle.x = 0; ?

Last edited by Terran; 23-03-2004 at 23:42..
  
Reply With Quote
Re: bot coding in CS?
Old
  (#6)
Rick
Council Member
 
Rick's Avatar
 
Status: Offline
Posts: 690
Join Date: Dec 2003
Location: Holland
Default Re: bot coding in CS? - 23-03-2004

Pierre meant bot_t *pBot = &bots[i];
  
Reply With Quote
Re: bot coding in CS?
Old
  (#7)
Lazy
Member
 
Lazy's Avatar
 
Status: Offline
Posts: 236
Join Date: Jan 2004
Location: Toronto, Ontario, Canada
Default Re: bot coding in CS? - 23-03-2004

I have only played around a bit with some bot stuff but the line...

Code:
bot_t bots[32]; // max of 32 bots in game
I think could be better written as bot_t bots[ 33 ],
that way you can access the bot's data with just a call to ENTINDEX whenever needed.

Setting the array size to 32 will allocate space for players 1-31 since 0 is worldspawn it makes it useless.
Having it 33 ensures you can index from 1 to 32 with 0 remaining unused.

Though thats just from looking at that one line, let me know if I'm wrong about that.
  
Reply With Quote
Re: bot coding in CS?
Old
  (#8)
Rick
Council Member
 
Rick's Avatar
 
Status: Offline
Posts: 690
Join Date: Dec 2003
Location: Holland
Default Re: bot coding in CS? - 23-03-2004

Uhm no....in botmans template the ENTINDEX != as the bot index. When a bot is created it will just search from 0 to 31 for a free bot slot. That way there is alway enough space
  
Reply With Quote
Re: bot coding in CS?
Old
  (#9)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: bot coding in CS? - 23-03-2004

Lazy is right, it is best to have the bots array sorted the same way the players are allocated their entities. In my bot I have ENTINDEX (pBotEdict) - 1 == pBot->pEdict (well, I don't use "pBot->pEdict" anymore but you see the idea)

And yeah thanks Rick for fixing my mistake, I meant bot_t *pBot = &bots[i]; rather than &bots[i].pEdict. Go back to school PMB



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: bot coding in CS?
Old
  (#10)
Terran
Member
 
Terran's Avatar
 
Status: Offline
Posts: 431
Join Date: Jan 2004
Default Re: bot coding in CS? - 24-03-2004

Quote:
Originally Posted by Pierre-Marie Baty
Somebody feel free to move this to the wiki if needed and comment/correct/fix over it
It's now in the wiki (BotCodeSamples).

@memed:
The PhpHighlight plugin has an error: I needed to put an extra space before all ] signs in the code otherwise they weren't displayed...
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com