forked from Fundynamic/RealBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.h
471 lines (385 loc) · 15.9 KB
/
bot.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
/**
* RealBot : Artificial Intelligence
* Version : Work In Progress
* Author : Stefan Hendriks
* Url : http://realbot.bots-united.com
**
* DISCLAIMER
*
* History, Information & Credits:
* RealBot is based partially uppon the HPB-Bot Template #3 by Botman
* Thanks to Ditlew (NNBot), Pierre Marie Baty (RACCBOT), Tub (RB AI PR1/2/3)
* Greg Slocum & Shivan (RB V1.0), Botman (HPB-Bot) and Aspirin (JOEBOT). And
* everybody else who helped me with this project.
* Storage of Visibility Table using BITS by Cheesemonster.
*
* Some portions of code are from other bots, special thanks (and credits) go
* to (in no specific order):
*
* Pierre Marie Baty
* Count-Floyd
*
* !! BOTS-UNITED FOREVER !!
*
* This project is open-source, it is protected under the GPL license;
* By using this source-code you agree that you will ALWAYS release the
* source-code with your project.
*
**/
#ifndef BOT_H
#define BOT_H
//#pragma warning( disable : 4005 )
// Weapon price table (filled by the INI PARSER)
typedef struct {
int iId; // the weapon ID value
int price; // Price of weapon
int priority; // Priority to buy this weapon
int iIdIndex;
} weapon_price_table;
// 30/07/04
// Declare the external here
extern weapon_price_table weapons_table[32];
// BOT SPECIFIC / AUDIOABLE / VISUAL PROPERTIES
#define BOT_HEARDISTANCE 1500
#define BOT_HEARFIREDISTANCE 2500
// define constants used to identify the MOD we are playing...
#define VALVE_DLL 1 // Added "Half-Life DeathMatch"
#define CSTRIKE_DLL 3 // Added "Counter-Strike"
// max names in rb_names.txt
#define MAX_BOT_NAMES 100
// Define Join states for other mods
#define JOIN_TEAM 1
#define JOIN_CLASS 2
#define JOIN_NONE 9999
// fix for steam (cs 1.6 bot will crash when FL_FAKECLIENT;
// this is fixed later again in STEAM, but leave it in anway).
#define FL_THIRDPARTYBOT (1 << 27)
// "Own predefined" item types (attached with buying code)
#define CS_WEAPON_ARMOR_LIGHT 199
#define CS_WEAPON_ARMOR_HEAVY 299
// damage tolerance
#define CSTRIKE_MIN_DAMAGE 7
#define CSTRIKE_MAX_DAMAGE 14
// The type of a weapon, not mod related. You can use these prefixed names
// for your functions
#define SNIPER 10 // Sniper gun
#define RIFLE 20 // Rifle
#define HANDGUN 30 // Handgun
#define ARMOR 40 // Armor
#define PRIMARY 50 // Its a primary weapon (for CS Mods)
#define SECONDARY 60 // Its a secondary weapon (for CS Mods)
#define GRENADE 70 // Grenade (aka, HE, Flashbang, C4, etc)
#define KNIFE 80 // Knife / Crowbar etc
#define SHIELD 90 // Shield (CS 1.6)
#define NONE 99 // No type
// Strafe
//#define STRAFE_LEFT 0
//#define STRAFE_RIGHT 1
// zooming
#define ZOOM_NONE 0
#define ZOOM_ONCE 1
#define ZOOM_TWICE 2
// instant damage (from cbase.h)
#define DMG_CRUSH (1 << 0) // crushed by falling or moving object
#define DMG_BURN (1 << 3) // heat burned
#define DMG_FREEZE (1 << 4) // frozen
#define DMG_FALL (1 << 5) // fell too far
#define DMG_SHOCK (1 << 8) // electric shock
#define DMG_DROWN (1 << 14) // Drowning
#define DMG_NERVEGAS (1 << 16) // nerve toxins, very bad
#define DMG_RADIATION (1 << 18) // radiation exposure
#define DMG_DROWNRECOVER (1 << 19) // drowning recovery
#define DMG_ACID (1 << 20) // toxic chemicals or acid burns
#define DMG_SLOWBURN (1 << 21) // in an oven
#define DMG_SLOWFREEZE (1 << 22) // in a subzero freezer
// define some function prototypes...
void FakeClientCommand(edict_t * pBot, char *arg1, char *arg2, char *arg3);
#define LADDER_UNKNOWN 0
#define LADDER_UP 1
#define LADDER_DOWN 2
#define WANDER_LEFT 1
#define WANDER_RIGHT 2
#define BOT_PITCH_SPEED 20
#define BOT_YAW_SPEED 20
#define RESPAWN_NONE 0 // Added by Stefan
#define RESPAWN_IDLE 1
#define RESPAWN_NEED_TO_RESPAWN 2
#define RESPAWN_IS_RESPAWNING 3
// game start messages for CS...
#define MSG_CS_IDLE 1
#define MSG_CS_TEAM_SELECT 2
#define MSG_CS_CT_SELECT 3
#define MSG_CS_T_SELECT 4
#define BOT_SKIN_LEN 32
#define BOT_NAME_LEN 32
#define MAX_BOT_WHINE 100
#define REMEMBER_ENEMY_TIME 20 // remember for 20 seconds
typedef struct {
int iId; // weapon ID
int iClip; // amount of ammo in the clip
int iAmmo1; // amount of ammo in primary reserve
int iAmmo2; // amount of ammo in secondary reserve
}
bot_current_weapon_t;
/*
Bot is a class now
*/
class cBot {
public:
// ------------------------
// TIMERS
// ------------------------
float fButtonTime;
float fChatTime;
float fMemoryTime;
float fDoRadio; // how much time we have before we can issue another radio message
float fNotStuckTime; // last time we got stuck
float f_goback_time; // time to go back (-movespeed)
float f_allow_keypress; // Timer to avoid 'too quick' using/defusing/etc
float f_defuse; // Timer to press the use key for defusing
float f_node_timer; // timer, to ensure navigation when something goes wrong
float f_use_timer; // time for use button (hostage rescuem, preventing to fast using)
float fBlindedTime; // How long it is blinded ( when > globals->time)
float f_max_speed; // Max speed is the max speed it can get when holding that particular weapon
float f_move_speed; // The bots move speed
float f_strafe_speed; // Strafe speed
float f_hold_duck; // Hold duck
float f_sec_weapon; // secondary weapon time interval
float f_prim_weapon; // primary weapon time interval (for burst fire)
float f_gren_time; // time to hold grenade
float f_shoot_wait_time; // wait time, for bursting aswell (how long we may shoot)
float f_may_jump_time; // Timer when just off a ladder on top, we may not do jump tricks.
float f_c4_time; // C4 time (plant/defuse)
float f_camp_time; // Camp timer
float f_wait_time; // Wait timer
float f_cover_time; // How long to take cover
float f_strafe_time; // How long till we pick a new strafe direction (fighting only)
float f_hear_time; // Decision timer for hearing
float f_walk_time; // Timer to force bot to walk
float f_follow_time; // How long to follow our friend
float f_update_weapon_time; // Aargh
float f_stuck_time; // How long stuck
float f_freeze_time; // How long it should 'freeze'.
float f_shoot_time; // Shoot time.
float f_light_time; // light timer
float fMoveToNodeTime; // How long we should take to move to next node.
float fKickTime;
float fCreateTime;
// Personality related
float fpXOffset;
float fpYOffset;
float fpZOffset;
float fpMinReactTime;
float fpMaxReactTime;
// ------------------------
// INTEGERS
// ------------------------
int iTeam; // team
int iIndex; // Index
int bot_class; // class
int bot_health; // Amount of health
int bot_armor; // Amount of armour
int bot_weapons; // bit map of weapons the bot is carrying
int bot_money; // for Counter-Strike
int bot_pathid; // Which path id we want to move to
int prev_health;
int play_rounds; // How many rounds a bot will play in round-based games.
int played_rounds; // how many rounds it has played already
int bot_use_special; // Use silencer etc.
int buy_flashbang;
int zoomed;
int iPrimaryWeapon;
int iSecondaryWeapon;
int i_camp_style; // 0 - see yourself, 1 stand, 2 duck
int respawn_state;
int bot_skill;
int iPathFlags; // With what thought to create a path?
int iDiedNode; // On which node did we die?
// Personality related
int ipHostage; // Hostage rescue frequency
int ipBombspot; // Bomb spot frequency
int ipRandom; // Random goal (wandering) frequency
int ipTurnSpeed; // Turn speed
int ipReplyToRadio; // Reply to radio frequency
int ipCreateRadio; // Creating new radio command frequency
int ipHelpTeammate; // Help teammate frequency
int ipWalkWithKnife; // Walk with knife frequency
int ipCampRate; // Camp frequency
int ipChatRate; // Chat frequency
int ipFearRate; // How much 'fear' has a bot
int ipHearRate; // How good can a bot hear?
// Buy-Personality related
int ipFavoPriWeapon;
int ipFavoSecWeapon;
int ipBuyFlashBang;
int ipBuyGrenade;
int ipBuySmokeGren;
int ipBuyDefuseKit;
int ipSaveForWeapon; // Frequency for NOT buying a weapon to buy the favo weapon
int ipBuyArmour;
int ipDroppedBomb; // how glad do we got to the dropped bomb?
// Remember stuck stuff
int iJumpTries;
int iDuckTries;
// ------------------------
// BOOLEANS
// ------------------------
bool buy_primary;
bool buy_secondary;
bool buy_ammo_primary;
bool buy_ammo_secondary;
bool buy_armor;
bool buy_grenade;
bool buy_smokegrenade; //31.08.04 Frashman added support for Smoke Grenade
bool bIsUsed; // Bot is 'used'/'playing'
bool bInitialize;
bool buy_defusekit;
bool bWalkKnife; // likes to walk around with knife
bool vip;
bool bFirstOutOfSight;
// ------------------------
// HUD
// ------------------------
bool bHUD_C4_plantable; // HUD says it is ok? -- BERKED
// chat
char chChatSentence[160];
// ------------------------
//
// ------------------------
edict_t *pEdict; // Edict_t of the bot
char name[BOT_NAME_LEN + 1];
char skin[BOT_SKIN_LEN + 1];
bool bStarted;
int start_action;
// TheFatal - START
int msecnum;
float msecdel;
int msecval;
// TheFatal - END
int iGoalNode; // Goal Node #
int iPreviousGoalNode; // Previous goal
int iCloseNode; // The closest node to this bot.
float fWanderTime; // Wandering around time
// Nav
Vector vHead; // Vector where bot should look at
Vector vBody; // Vector where bot should move to
Vector vEar; // Vector where the bot hears
// Console
int console_nr;
float f_console_timer;
char arg1[25];
char arg2[25];
char arg3[25];
// Timers
float prev_time;
Vector v_prev_origin;
Vector v_enemy; // Vector where we last saw our enemy (when not 0,0,0)
float f_jump_time;
float f_bot_see_enemy_time;
float f_bot_find_enemy_time;
edict_t *pButtonEdict; // button edict
edict_t *pBotEnemy; // Enemy edict
edict_t *killer_edict; // Killer edict
// Hostages edict
edict_t *pBotHostage; // the Hostage we will go after!
edict_t *hostage1; // we do not
edict_t *hostage2; // use
edict_t *hostage3; // any array
edict_t *hostage4; // here
// Swat Behaviour
edict_t *pSwatLeader; // Pointer to leader of swat!
Vector vecMoveAngles; // Vector we move to
bot_current_weapon_t current_weapon; // one current weapon for each bot
int m_rgAmmo[MAX_AMMO_SLOTS]; // total ammo amounts (1 array for each bot)
// ------------------------ FUNCTIONS
void UpdateStatus(); // Update status
void Think(); // Think functions
void Combat(); // Combat
void Memory(); // Memory
void Walk(); // Walk
void InteractWithPlayers(); // Interaction
void Act(); // Do as been told
bool Defuse(); // Defuse (ACT) sub-function
void FightEnemy(); // Fight
void StartGame();
void CheckGear();
void ThinkAboutGoals(); // Think about goals
bool TakeCover();
bool CarryWeapon(int iType);
int CarryWeaponType();
void Aim(Vector vTarget); // Aim at vector
void AimAtEnemy();
void PickBestWeapon();
void FireWeapon();
int ReturnTurnedAngle(float speed, float current, float ideal);
int FindEnemy();
float ReactionTime(int iSkill); // Reaction time based upon skill
void FindCover();
bool CanSeeVector(Vector vDest);
bool CanSeeEntity(edict_t * pEntity);
void InteractWithFriends();
void PrepareChat(char sentence[128]); // prepares bot to alk in act()
void clearHostages();
// Set methods
void setCurrentNode();
// Get methods
// "is" Methods (booleans, statements, etc)
bool isDead();
bool OnLadder(); // Bot on ladder or not?
bool hasHostages(); // Does the bot has used any hostages yet?
// Goal specific stuff
Vector BombSpotNear(float fDistance); // Is a bombspot near in fDistance?
// -------------------
void CheckAround(); // Check around body
// -------------------
void SetFace(); // Set
void SetBody(); // Set
// -------------------
// -------------------
void SpawnInit(); // When bot spawns again (added/revived)
void NewRound(); // When bot enters new round
// -------------------
// 20/06/04 - CS 1.6 shield functions
bool bHasShield();
bool bHasShieldDrawn();
// --------------------
// 01/07/04 - Add some debugging options
void Dump();
};
// new UTIL.CPP functions...
edict_t *UTIL_FindEntityInSphere(edict_t * pentStart,
const Vector & vecCenter, float flRadius);
edict_t *UTIL_FindEntityByString(edict_t * pentStart,
const char *szKeyword,
const char *szValue);
edict_t *UTIL_FindEntityByClassname(edict_t * pentStart,
const char *szName);
edict_t *UTIL_FindEntityByTargetname(edict_t * pentStart,
const char *szName);
void ClientPrint(edict_t * pEdict, int msg_dest, const char *msg_name);
void UTIL_SayText(const char *pText, edict_t * pEdict);
void UTIL_HostSay(edict_t * pEntity, int teamonly, char *message);
int UTIL_GetTeam(edict_t * pEntity);
int UTIL_GetClass(edict_t * pEntity);
int UTIL_GetBotIndex(edict_t * pEdict);
cBot *UTIL_GetBotPointer(edict_t * pEdict);
bool IsAlive(edict_t * pEdict);
bool FInViewCone(Vector * pOrigin, edict_t * pEdict);
bool FVisible(const Vector & vecOrigin, edict_t * pEdict);
Vector Center(edict_t * pEdict);
Vector GetGunPosition(edict_t * pEdict);
void UTIL_SelectItem(edict_t * pEdict, char *item_name);
Vector VecBModelOrigin(edict_t * pEdict);
void UTIL_ShowMenu(edict_t * pEdict, int slots, int displaytime,
bool needmore, char *pText);
void UTIL_BuildFileName(char *filename, char *arg1, char *arg2);
void UTIL_BuildFileNameRB(char *subdir, char *filename);
unsigned short FixedUnsigned16(float value, float scale);
short FixedSigned16(float value, float scale);
void HUD_DrawString(int r, int g, int b, char *msg, edict_t * edict);
void UTIL_FixAngles(Vector * Angles);
void UTIL_SayTextBot(const char *pText, cBot * pBot);
// combat.h
// dll.cpp
bool BotRadioAction();
#endif // BOT_H