-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.cpp
769 lines (609 loc) · 21.4 KB
/
bot.cpp
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
/*
Ricobot (C) Copyright 2004, Wei Mingzhi
All rights reserved.
Redistribution and use in source and binary forms with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the author nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY WEI MINGZHI "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//
// Ricobot - a bot example for Valve Software's Ricochet MOD
//
// bot.cpp
//
#include "bot.h"
bot_t bots[32]; // max of 32 bots in a game
bool b_observer_mode = FALSE;
bool b_botdontshoot = FALSE;
int bot_chat_percent = 10;
int number_names = 0;
char bot_names[MAX_BOT_NAMES][BOT_NAME_LEN+1];
void BotSpawnInit( bot_t *pBot )
{
pBot->msecnum = 0;
pBot->msecdel = 0.0;
pBot->msecval = 0.0;
pBot->pBotEnemy = NULL;
pBot->f_bot_see_enemy_time = gpGlobals->time;
pBot->f_bot_find_enemy_time = gpGlobals->time;
pBot->b_bot_say_killed = FALSE;
pBot->f_bot_say_killed = 0.0;
}
void BotNameInit( void )
{
FILE *bot_name_fp;
char bot_name_filename[256];
int str_index;
char name_buffer[80];
int length, index;
UTIL_BuildFileName(bot_name_filename, "bot_names.txt", NULL);
bot_name_fp = fopen(bot_name_filename, "r");
if (bot_name_fp != NULL)
{
while ((number_names < MAX_BOT_NAMES) &&
(fgets(name_buffer, 80, bot_name_fp) != NULL))
{
length = strlen(name_buffer);
if (name_buffer[length-1] == '\n')
{
name_buffer[length-1] = 0; // remove '\n'
length--;
}
str_index = 0;
while (str_index < length)
{
if ((name_buffer[str_index] < ' ') || (name_buffer[str_index] > '~') ||
(name_buffer[str_index] == '"'))
for (index=str_index; index < length; index++)
name_buffer[index] = name_buffer[index+1];
str_index++;
}
if (name_buffer[0] != 0)
{
strncpy(bot_names[number_names], name_buffer, BOT_NAME_LEN);
number_names++;
}
}
fclose(bot_name_fp);
}
}
void BotPickName( char *name_buffer )
{
int name_index, index;
bool used;
edict_t *pPlayer;
int attempts = 0;
// see if a name exists from a kicked bot (if so, reuse it)
for (index=0; index < 32; index++)
{
if ((bots[index].is_used == FALSE) && (bots[index].name[0]))
{
strcpy(name_buffer, bots[index].name);
return;
}
}
name_index = RANDOM_LONG(1, number_names) - 1; // zero based
// check make sure this name isn't used
used = TRUE;
while (used)
{
used = FALSE;
for (index = 1; index <= gpGlobals->maxClients; index++)
{
pPlayer = INDEXENT(index);
if (pPlayer && !pPlayer->free)
{
if (strcmp(bot_names[name_index], STRING(pPlayer->v.netname)) == 0)
{
used = TRUE;
break;
}
}
}
if (used)
{
name_index++;
if (name_index == number_names)
name_index = 0;
attempts++;
if (attempts == number_names)
used = FALSE; // break out of loop even if already used
}
}
strcpy(name_buffer, bot_names[name_index]);
}
void BotCreate( edict_t *pPlayer, const char *pname, const char *pskill )
{
edict_t *BotEnt;
bot_t *pBot;
char c_name[BOT_NAME_LEN + 1];
int skill;
int i, j, length;
if ((pname != NULL) && (*pname != 0))
{
strncpy( c_name, pname, BOT_NAME_LEN - 1 );
c_name[BOT_NAME_LEN] = 0; // make sure c_name is null terminated
}
else
{
if (number_names > 0)
BotPickName( c_name );
else
strcpy(c_name, "Bot");
}
skill = 0;
if ((pskill != NULL) && (*pskill != 0))
skill = atoi(pskill);
if (skill < 1 || skill > 5)
skill = default_bot_skill;
length = strlen(c_name);
// remove any illegal characters from name...
for (i = 0; i < length; i++)
{
if ((c_name[i] <= ' ') || (c_name[i] > '~') ||
(c_name[i] == '"'))
{
for (j = i; j < length; j++) // shuffle chars left (and null)
c_name[j] = c_name[j+1];
length--;
}
}
BotEnt = (*g_engfuncs.pfnCreateFakeClient)( c_name );
if (FNullEnt( BotEnt ))
{
if (pPlayer)
ClientPrint( pPlayer, HUD_PRINTNOTIFY, "Max. Players reached. Can't create bot!\n");
}
else
{
char ptr[128]; // allocate space for message from ClientConnect
int index;
index = 0;
while ((bots[index].is_used) && (index < 32))
index++;
if (index == 32)
{
ClientPrint( pPlayer, HUD_PRINTNOTIFY, "Can't create bot!\n");
return;
}
if (BotEnt->pvPrivateData != NULL)
FREE_PRIVATE(BotEnt);
BotEnt->pvPrivateData = NULL;
BotEnt->v.frags = 0;
// create the player entity by calling MOD's player function
// (from LINK_ENTITY_TO_CLASS for player object)
CALL_GAME_ENTITY(PLID, "player", VARS(BotEnt));
MDLL_ClientConnect( BotEnt, c_name, "127.0.0.1", ptr );
MDLL_ClientPutInServer( BotEnt );
BotEnt->v.flags |= FL_FAKECLIENT;
pBot = &bots[index]; // initialize all the variables for this bot...
pBot->is_used = TRUE;
pBot->respawn_state = RESPAWN_IDLE;
pBot->create_time = gpGlobals->time;
pBot->name[0] = 0; // name not set by server yet
pBot->pEdict = BotEnt;
BotSpawnInit(pBot);
pBot->need_to_initialize = FALSE; // don't need to initialize yet
BotEnt->v.idealpitch = BotEnt->v.v_angle.x;
BotEnt->v.ideal_yaw = BotEnt->v.v_angle.y;
BotEnt->v.pitch_speed = BOT_PITCH_SPEED;
BotEnt->v.yaw_speed = BOT_YAW_SPEED;
pBot->bot_skill = skill - 1; // 0 based for array indexes
}
}
void BotChangePitch( bot_t *pBot, float speed )
{
edict_t *pEdict = pBot->pEdict;
float ideal;
float current;
float current_180; // current +/- 180 degrees
float diff;
ClampAngle(pEdict->v.idealpitch);
// turn from the current v_angle pitch to the idealpitch by selecting
// the quickest way to turn to face that direction
current = pEdict->v.v_angle.x;
ideal = pEdict->v.idealpitch;
// find the difference in the current and ideal angle
diff = fabs(current - ideal);
// check if difference is less than the max degrees per turn
if (diff < speed)
speed = diff; // just need to turn a little bit (less than max)
// here we have four cases, both angle positive, one positive and
// the other negative, one negative and the other positive, or
// both negative. handle each case separately...
if (current >= 0 && ideal >= 0) // both positive
{
if (current > ideal)
speed = -speed;
}
else if (current >= 0 && ideal < 0)
{
current_180 = current - 180;
if (current_180 <= ideal)
speed = -speed;
}
else if (current < 0 && ideal >= 0)
{
current_180 = current + 180;
if (current_180 <= ideal)
speed = -speed;
}
else // (current < 0) && (ideal < 0) both negative
{
if (current > ideal)
speed = -speed;
}
current += speed;
pEdict->v.v_angle.x = current;
}
void BotChangeYaw( bot_t *pBot, float speed )
{
edict_t *pEdict = pBot->pEdict;
float ideal;
float current;
float current_180; // current +/- 180 degrees
float diff;
ClampAngle(pEdict->v.ideal_yaw);
// turn from the current v_angle yaw to the ideal_yaw by selecting
// the quickest way to turn to face that direction
current = pEdict->v.v_angle.y;
ideal = pEdict->v.ideal_yaw;
// find the difference in the current and ideal angle
diff = fabs(current - ideal);
// check if difference is less than the max degrees per turn
if (diff < speed)
speed = diff; // just need to turn a little bit (less than max)
// here we have four cases, both angle positive, one positive and
// the other negative, one negative and the other positive, or
// both negative. handle each case separately...
if (current >= 0 && ideal >= 0) // both positive
{
if (current > ideal)
speed = -speed;
}
else if (current >= 0 && ideal < 0)
{
current_180 = current - 180;
if (current_180 <= ideal)
speed = -speed;
}
else if (current < 0 && ideal >= 0)
{
current_180 = current + 180;
if (current_180 <= ideal)
speed = -speed;
}
else // (current < 0) && (ideal < 0) both negative
{
if (current > ideal)
speed = -speed;
}
current += speed;
pEdict->v.v_angle.y = current;
}
// The next 2 functions are taken from POD-Bot source
bool IsDeadlyDrop(bot_t *pBot, Vector vecTargetPos)
{
// Returns if given location would hurt Bot with falling damage
edict_t *pEdict = pBot->pEdict;
Vector vecBot = pEdict->v.origin;
TraceResult tr;
float height, last_height, distance;
Vector vecMove = UTIL_VecToAngles(vecTargetPos - vecBot);
vecMove.x = 0; // reset pitch to 0 (level horizontally)
vecMove.z = 0; // reset roll to 0 (straight up and down)
MAKE_VECTORS(vecMove);
Vector v_direction = (vecTargetPos - vecBot).Normalize (); // 1 unit long
Vector v_check = vecBot;
Vector v_down = vecBot;
v_down.z = v_down.z - 1000.0; // straight down 1000 units
TRACE_HULL(v_check, v_down, ignore_monsters, head_hull, pEdict, &tr);
// We're not on ground anymore ?
if (tr.flFraction > 0.036)
tr.flFraction = 0.036;
last_height = tr.flFraction * 1000.0; // height from ground
distance = (vecTargetPos - v_check).Length (); // distance from goal
while (distance > 16.0)
{
// move 10 units closer to the goal...
v_check = v_check + (v_direction * 16.0);
v_down = v_check;
v_down.z = v_down.z - 1000.0; // straight down 1000 units
TRACE_HULL(v_check, v_down, ignore_monsters, head_hull, pEdict, &tr);
// Wall blocking ?
if (tr.fStartSolid)
return FALSE;
height = tr.flFraction * 1000.0; // height from ground
// Drops more than 100 Units ?
if (last_height < height - 100)
return TRUE;
last_height = height;
distance = (vecTargetPos - v_check).Length(); // distance from goal
}
return FALSE;
}
// Adjust all Bot Body and View Angles to face an absolute Vector
void BotFacePosition(bot_t *pBot, Vector vecPos)
{
edict_t *pEdict = pBot->pEdict;
Vector vecDirection = UTIL_VecToAngles(vecPos - GetGunPosition(pEdict));
vecDirection.x = -vecDirection.x;
ClampAngles(vecDirection);
pEdict->v.ideal_yaw = vecDirection.y;
pEdict->v.idealpitch = vecDirection.x;
}
void BotMoveToPosition(bot_t *pBot, Vector vecPos)
{
edict_t *pEdict = pBot->pEdict;
if (pBot->pBotEnemy == NULL)
{
// No enemy, just head towards the position
pBot->vecLookAt = vecPos;
pBot->f_move_speed = pEdict->v.maxspeed;
}
else
{
// Otherwise we need to do strafing...
float f1 = pEdict->v.angles.y - VEC_TO_YAW(vecPos - pEdict->v.origin);
float flCos = cos(f1 * M_PI / 180);
float flSin = sin(f1 * M_PI / 180);
pBot->f_move_speed = pEdict->v.maxspeed * flCos;
pBot->f_sidemove_speed = pEdict->v.maxspeed * flSin;
}
}
edict_t *BotFindEnemy( bot_t *pBot )
{
Vector vecEnd;
edict_t *pNewEnemy = NULL;
edict_t *pEdict = pBot->pEdict;
if (pBot->pBotEnemy != NULL) // does the bot already have an enemy?
{
vecEnd = pBot->pBotEnemy->v.origin + pBot->pBotEnemy->v.view_ofs;
// if the enemy is dead?
if (!IsAlive(pBot->pBotEnemy)) // is the enemy dead?, assume bot killed it
pBot->pBotEnemy = NULL; // don't have an enemy anymore so null out the pointer...
else if (FInViewCone( &vecEnd, pEdict ) && FVisible( vecEnd, pEdict ) &&
fabs(pBot->pEdict->v.origin.z - pBot->pBotEnemy->v.origin.z) < 72)
return pBot->pBotEnemy; // if enemy is still visible and in field of view, keep it
}
float nearestdistance = 2500;
// search the world for players...
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
edict_t *pPlayer = INDEXENT(i);
// skip invalid players and skip self (i.e. this bot)
if (pPlayer && !pPlayer->free && pPlayer != pEdict)
{
if (!IsAlive(pPlayer))
continue; // skip this player if not alive (i.e. dead or dying)
if (b_observer_mode && !(pPlayer->v.flags & FL_FAKECLIENT))
continue;
if (pPlayer->v.playerclass != 0)
continue; // skip this player if he is spectating
if (pPlayer->v.groupinfo != pEdict->v.groupinfo)
continue; // skip this player is he is in a different arena
// see if the enemy is at the same height as the bot
if (fabs(pBot->pEdict->v.origin.z - pPlayer->v.origin.z) >= 72)
continue;
vecEnd = pPlayer->v.origin + pPlayer->v.view_ofs;
// see if bot can see the player...
if (FInViewCone( &vecEnd, pEdict ) && FVisible( vecEnd, pEdict ))
{
float distance = (pPlayer->v.origin - pEdict->v.origin).Length();
if (distance < nearestdistance)
{
nearestdistance = distance;
pNewEnemy = pPlayer;
}
}
}
}
return pNewEnemy;
}
void BotShootAtEnemy( bot_t *pBot )
{
edict_t *pEdict = pBot->pEdict;
if (FNullEnt(pBot->pBotEnemy))
return; // no enemy, no need to shoot
// is the bot's crosshair on the enemy yet?
Vector vecDir = (pBot->vecLookAt - GetGunPosition(pBot->pEdict)).Normalize();
UTIL_MakeVectors(pEdict->v.v_angle);
if (DotProduct(gpGlobals->v_forward, vecDir) > 0.9)
{
// we will likely hit the enemy, FIRE!!
// TODO: bounce/teleport attack
float distance = (pEdict->v.origin - pBot->pBotEnemy->v.origin).Length();
// if enemy is near enough, we have enough discs,
// and we haven't "Power Shot" powerup...
if (distance < 128 && pBot->disc_number >= 3 && !(pBot->m_iPowerups & POW_HARD)
&& RANDOM_LONG(1, 100) < (6 - pBot->bot_skill) * 20)
pEdict->v.button |= IN_ATTACK2; // Decapitate him!!!!
else
pEdict->v.button |= IN_ATTACK;
}
}
void BotThink( bot_t *pBot )
{
Vector v_diff; // vector from previous to current location
TraceResult tr;
edict_t *pEdict = pBot->pEdict;
pEdict->v.flags |= FL_FAKECLIENT;
if (pBot->name[0] == 0) // name filled in yet?
strcpy(pBot->name, STRING(pBot->pEdict->v.netname));
// TheFatal - START from Advanced Bot Framework (Thanks Rich!)
// adjust the millisecond delay based on the frame rate interval...
if (pBot->msecdel <= gpGlobals->time)
{
pBot->msecdel = gpGlobals->time + 0.5;
if (pBot->msecnum > 0)
pBot->msecval = 450.0 / pBot->msecnum;
pBot->msecnum = 0;
}
else
pBot->msecnum++;
if (pBot->msecval < 1) // don't allow msec to be less than 1...
pBot->msecval = 1;
if (pBot->msecval > 100) // ...or greater than 100
pBot->msecval = 100;
// TheFatal - END
pEdict->v.button = 0;
pBot->f_move_speed = 0.0;
pBot->f_sidemove_speed = 0.0;
if (FNullEnt(pBot->killer_edict))
pBot->b_bot_say_killed = FALSE;
if (pBot->b_bot_say_killed && pBot->f_bot_say_killed < gpGlobals->time)
{
int whine_index = 0;
bool used;
int i, recent_count;
char msg[120];
pBot->b_bot_say_killed = FALSE;
recent_count = 0;
while (recent_count < 5)
{
whine_index = RANDOM_LONG(0, whine_count - 1);
used = FALSE;
for (i = 0; i < 5; i++)
{
if (recent_bot_whine[i] == whine_index)
used = TRUE;
}
if (used)
recent_count++;
else
break;
}
for (i = 4; i > 0; i--)
recent_bot_whine[i] = recent_bot_whine[i-1];
recent_bot_whine[0] = whine_index;
if (strstr(bot_whine[whine_index], "%s") != NULL) // is "%s" in whine text?
sprintf(msg, bot_whine[whine_index], STRING(pBot->killer_edict->v.netname));
else
sprintf(msg, bot_whine[whine_index]);
UTIL_HostSay(pEdict, msg);
}
// if the bot is dead, randomly press fire to respawn...
if (pEdict->v.health < 1 || pEdict->v.deadflag != DEAD_NO)
{
if (pBot->need_to_initialize)
{
BotSpawnInit(pBot);
// did another player kill this bot AND bot whine messages loaded
if (pBot->killer_edict != NULL && whine_count > 0)
{
if (RANDOM_LONG(1, 100) <= bot_chat_percent)
{
pBot->b_bot_say_killed = TRUE;
pBot->f_bot_say_killed = gpGlobals->time + RANDOM_FLOAT(0.5, 2.5);
}
}
pBot->need_to_initialize = FALSE;
}
if (RANDOM_LONG(1, 100) > 50)
pEdict->v.button = IN_ATTACK;
g_engfuncs.pfnRunPlayerMove( pEdict, pEdict->v.v_angle, 0,
0, 0, pEdict->v.button, 0, pBot->msecval);
return;
}
// set this for the next time the bot dies so it will initialize stuff
if (pBot->need_to_initialize == FALSE)
pBot->need_to_initialize = TRUE;
// Get Speed Multiply Factor by dividing Target FPS by real FPS
float fSpeedFactor = CVAR_GET_FLOAT("fps_max") / (1.0 / gpGlobals->frametime);
if (fSpeedFactor < 1)
fSpeedFactor = 1.0;
BotChangeYaw(pBot, pEdict->v.yaw_speed * fSpeedFactor);
BotChangePitch(pBot, pEdict->v.pitch_speed * fSpeedFactor);
// set the body angles to point the gun correctly
pEdict->v.angles.x = -pEdict->v.v_angle.x / 3;
pEdict->v.angles.y = pEdict->v.v_angle.y;
ClampAngles(pEdict->v.angles);
ClampAngles(pEdict->v.v_angle);
// handle movement related actions...
if (b_botdontshoot == 0)
pBot->pBotEnemy = BotFindEnemy( pBot );
else
pBot->pBotEnemy = NULL; // clear enemy pointer (no ememy for you!)
if (pBot->pBotEnemy != NULL) // does an enemy exist?
{
// Aim at the enemy
pBot->vecLookAt = pBot->pBotEnemy->v.origin;
// TODO: bounce/teleport attack
BotShootAtEnemy( pBot ); // shoot at the enemy
}
if (pEdict->v.flags & (FL_ONGROUND | FL_PARTIALGROUND))
{
// jump to another disc randomly. TODO: make this much more advanced
if (pBot->vecTargetPos == Vector(0, 0, 0))
{
// find a jump arrow randomly.
// TODO: let bots go for powerups or find paths on purpose
int iCount = 0;
Vector vecWPT[8];
edict_t *p = NULL;
while ((p = UTIL_FindEntityInSphere( p, pBot->pEdict->v.origin, 240.0 )) != NULL)
{
if (strcmp(STRING(p->v.classname), "trigger_jump") == 0)
{
Vector v_dest = VecBModelOrigin(p);
if (fabs(pEdict->v.absmin.z - p->v.absmax.z) < 32 &&
!IsDeadlyDrop(pBot, v_dest))
{
vecWPT[iCount++] = v_dest;
if (iCount >= 8)
break;
}
}
}
if (iCount > 0)
pBot->vecTargetPos = vecWPT[RANDOM_LONG(0, iCount - 1)];
}
// try not to knock into other players
if (pBot->vecTargetPos != Vector(0, 0, 0))
{
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
edict_t *pPlayer = INDEXENT(i);
if (FNullEnt(pPlayer))
continue;
if (pPlayer == pEdict || pPlayer->v.playerclass != 0 ||
pPlayer->v.groupinfo != pEdict->v.groupinfo ||
pPlayer->v.origin.z - pEdict->v.origin.z > 128 ||
pPlayer->v.origin.z - pEdict->v.origin.z < 0 ||
pPlayer->v.flags & (FL_ONGROUND | FL_PARTIALGROUND))
continue;
Vector2D vecPlayer = (pPlayer->v.origin - pEdict->v.origin).Make2D().Normalize();
Vector2D vecTarget = (pBot->vecTargetPos - pEdict->v.origin).Make2D().Normalize();
if (DotProduct(vecPlayer, vecTarget) > 0.9)
{
pBot->vecTargetPos = Vector(0,0,0);
break;
}
}
}
// move to the destination position
if (pBot->vecTargetPos != Vector(0, 0, 0))
BotMoveToPosition(pBot, pBot->vecTargetPos);
}
else
pBot->vecTargetPos = Vector(0, 0, 0);
BotFacePosition(pBot, pBot->vecLookAt);
g_engfuncs.pfnRunPlayerMove( pEdict, pEdict->v.v_angle, pBot->f_move_speed,
pBot->f_sidemove_speed, 0, pEdict->v.button, pEdict->v.impulse, pBot->msecval);
}