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
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
|
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
This file is part of Quake III Arena source code.
Quake III Arena source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
Quake III Arena source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
/*****************************************************************************
* name: be_ai_char.c
*
* desc: bot characters
*
* $Archive: /MissionPack/code/botlib/be_ai_char.c $
*
*****************************************************************************/
#include "../qcommon/q_shared.h"
#include "l_log.h"
#include "l_memory.h"
#include "l_utils.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "l_libvar.h"
#include "aasfile.h"
#include "botlib.h"
#include "be_aas.h"
#include "be_aas_funcs.h"
#include "be_interface.h"
#include "be_ai_char.h"
#define MAX_CHARACTERISTICS 80
#define CT_INTEGER 1
#define CT_FLOAT 2
#define CT_STRING 3
#define DEFAULT_CHARACTER "bots/default_c.c"
//characteristic value
union cvalue
{
int integer;
float _float;
char *string;
};
//a characteristic
typedef struct bot_characteristic_s
{
char type; //characteristic type
union cvalue value; //characteristic value
} bot_characteristic_t;
//a bot character
typedef struct bot_character_s
{
char filename[MAX_QPATH];
float skill;
bot_characteristic_t c[1]; //variable sized
} bot_character_t;
bot_character_t *botcharacters[MAX_CLIENTS + 1];
//========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//========================================================================
bot_character_t *BotCharacterFromHandle(int handle)
{
if (handle <= 0 || handle > MAX_CLIENTS)
{
botimport.Print(PRT_FATAL, "character handle %d out of range\n", handle);
return NULL;
} //end if
if (!botcharacters[handle])
{
botimport.Print(PRT_FATAL, "invalid character %d\n", handle);
return NULL;
} //end if
return botcharacters[handle];
} //end of the function BotCharacterFromHandle
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void BotDumpCharacter(bot_character_t *ch)
{
int i;
Log_Write("%s", ch->filename);
Log_Write("skill %d\n", ch->skill);
Log_Write("{\n");
for (i = 0; i < MAX_CHARACTERISTICS; i++)
{
switch(ch->c[i].type)
{
case CT_INTEGER: Log_Write(" %4d %d\n", i, ch->c[i].value.integer); break;
case CT_FLOAT: Log_Write(" %4d %f\n", i, ch->c[i].value._float); break;
case CT_STRING: Log_Write(" %4d %s\n", i, ch->c[i].value.string); break;
} //end case
} //end for
Log_Write("}\n");
} //end of the function BotDumpCharacter
//========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//========================================================================
void BotFreeCharacterStrings(bot_character_t *ch)
{
int i;
for (i = 0; i < MAX_CHARACTERISTICS; i++)
{
if (ch->c[i].type == CT_STRING)
{
FreeMemory(ch->c[i].value.string);
} //end if
} //end for
} //end of the function BotFreeCharacterStrings
//========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//========================================================================
void BotFreeCharacter2(int handle)
{
if (handle <= 0 || handle > MAX_CLIENTS)
{
botimport.Print(PRT_FATAL, "character handle %d out of range\n", handle);
return;
} //end if
if (!botcharacters[handle])
{
botimport.Print(PRT_FATAL, "invalid character %d\n", handle);
return;
} //end if
BotFreeCharacterStrings(botcharacters[handle]);
FreeMemory(botcharacters[handle]);
botcharacters[handle] = NULL;
} //end of the function BotFreeCharacter2
//========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//========================================================================
void BotFreeCharacter(int handle)
{
if (!LibVarGetValue("bot_reloadcharacters")) return;
BotFreeCharacter2(handle);
} //end of the function BotFreeCharacter
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void BotDefaultCharacteristics(bot_character_t *ch, bot_character_t *defaultch)
{
int i;
for (i = 0; i < MAX_CHARACTERISTICS; i++)
{
if (ch->c[i].type) continue;
//
if (defaultch->c[i].type == CT_FLOAT)
{
ch->c[i].type = CT_FLOAT;
ch->c[i].value._float = defaultch->c[i].value._float;
} //end if
else if (defaultch->c[i].type == CT_INTEGER)
{
ch->c[i].type = CT_INTEGER;
ch->c[i].value.integer = defaultch->c[i].value.integer;
} //end else if
else if (defaultch->c[i].type == CT_STRING)
{
ch->c[i].type = CT_STRING;
ch->c[i].value.string = (char *) GetMemory(strlen(defaultch->c[i].value.string)+1);
strcpy(ch->c[i].value.string, defaultch->c[i].value.string);
} //end else if
} //end for
} //end of the function BotDefaultCharacteristics
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
bot_character_t *BotLoadCharacterFromFile(char *charfile, int skill)
{
int indent, index, foundcharacter;
bot_character_t *ch;
source_t *source;
token_t token;
foundcharacter = qfalse;
//a bot character is parsed in two phases
PC_SetBaseFolder(BOTFILESBASEFOLDER);
source = LoadSourceFile(charfile);
if (!source)
{
botimport.Print(PRT_ERROR, "counldn't load %s\n", charfile);
return NULL;
} //end if
ch = (bot_character_t *) GetClearedMemory(sizeof(bot_character_t) +
MAX_CHARACTERISTICS * sizeof(bot_characteristic_t));
strcpy(ch->filename, charfile);
while(PC_ReadToken(source, &token))
{
if (!strcmp(token.string, "skill"))
{
if (!PC_ExpectTokenType(source, TT_NUMBER, 0, &token))
{
FreeSource(source);
BotFreeCharacterStrings(ch);
FreeMemory(ch);
return NULL;
} //end if
if (!PC_ExpectTokenString(source, "{"))
{
FreeSource(source);
BotFreeCharacterStrings(ch);
FreeMemory(ch);
return NULL;
} //end if
//if it's the correct skill
if (skill < 0 || token.intvalue == skill)
{
foundcharacter = qtrue;
ch->skill = token.intvalue;
while(PC_ExpectAnyToken(source, &token))
{
if (!strcmp(token.string, "}")) break;
if (token.type != TT_NUMBER || !(token.subtype & TT_INTEGER))
{
SourceError(source, "expected integer index, found %s\n", token.string);
FreeSource(source);
BotFreeCharacterStrings(ch);
FreeMemory(ch);
return NULL;
} //end if
index = token.intvalue;
if (index < 0 || index > MAX_CHARACTERISTICS)
{
SourceError(source, "characteristic index out of range [0, %d]\n", MAX_CHARACTERISTICS);
FreeSource(source);
BotFreeCharacterStrings(ch);
FreeMemory(ch);
return NULL;
} //end if
if (ch->c[index].type)
{
SourceError(source, "characteristic %d already initialized\n", index);
FreeSource(source);
BotFreeCharacterStrings(ch);
FreeMemory(ch);
return NULL;
} //end if
if (!PC_ExpectAnyToken(source, &token))
{
FreeSource(source);
BotFreeCharacterStrings(ch);
FreeMemory(ch);
return NULL;
} //end if
if (token.type == TT_NUMBER)
{
if (token.subtype & TT_FLOAT)
{
ch->c[index].value._float = token.floatvalue;
ch->c[index].type = CT_FLOAT;
} //end if
else
{
ch->c[index].value.integer = token.intvalue;
ch->c[index].type = CT_INTEGER;
} //end else
} //end if
else if (token.type == TT_STRING)
{
StripDoubleQuotes(token.string);
ch->c[index].value.string = GetMemory(strlen(token.string)+1);
strcpy(ch->c[index].value.string, token.string);
ch->c[index].type = CT_STRING;
} //end else if
else
{
SourceError(source, "expected integer, float or string, found %s\n", token.string);
FreeSource(source);
BotFreeCharacterStrings(ch);
FreeMemory(ch);
return NULL;
} //end else
} //end if
break;
} //end if
else
{
indent = 1;
while(indent)
{
if (!PC_ExpectAnyToken(source, &token))
{
FreeSource(source);
BotFreeCharacterStrings(ch);
FreeMemory(ch);
return NULL;
} //end if
if (!strcmp(token.string, "{")) indent++;
else if (!strcmp(token.string, "}")) indent--;
} //end while
} //end else
} //end if
else
{
SourceError(source, "unknown definition %s\n", token.string);
FreeSource(source);
BotFreeCharacterStrings(ch);
FreeMemory(ch);
return NULL;
} //end else
} //end while
FreeSource(source);
//
if (!foundcharacter)
{
BotFreeCharacterStrings(ch);
FreeMemory(ch);
return NULL;
} //end if
return ch;
} //end of the function BotLoadCharacterFromFile
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int BotFindCachedCharacter(char *charfile, float skill)
{
int handle;
for (handle = 1; handle <= MAX_CLIENTS; handle++)
{
if ( !botcharacters[handle] ) continue;
if ( strcmp( botcharacters[handle]->filename, charfile ) == 0 &&
(skill < 0 || fabs(botcharacters[handle]->skill - skill) < 0.01) )
{
return handle;
} //end if
} //end for
return 0;
} //end of the function BotFindCachedCharacter
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int BotLoadCachedCharacter(char *charfile, float skill, int reload)
{
int handle, cachedhandle, intskill;
bot_character_t *ch = NULL;
#ifdef DEBUG
int starttime;
starttime = Sys_MilliSeconds();
#endif //DEBUG
//find a free spot for a character
for (handle = 1; handle <= MAX_CLIENTS; handle++)
{
if (!botcharacters[handle]) break;
} //end for
if (handle > MAX_CLIENTS) return 0;
//try to load a cached character with the given skill
if (!reload)
{
cachedhandle = BotFindCachedCharacter(charfile, skill);
if (cachedhandle)
{
botimport.Print(PRT_MESSAGE, "loaded cached skill %f from %s\n", skill, charfile);
return cachedhandle;
} //end if
} //end else
//
intskill = (int) (skill + 0.5);
//try to load the character with the given skill
ch = BotLoadCharacterFromFile(charfile, intskill);
if (ch)
{
botcharacters[handle] = ch;
//
botimport.Print(PRT_MESSAGE, "loaded skill %d from %s\n", intskill, charfile);
#ifdef DEBUG
if (bot_developer)
{
botimport.Print(PRT_MESSAGE, "skill %d loaded in %d msec from %s\n", intskill, Sys_MilliSeconds() - starttime, charfile);
} //end if
#endif //DEBUG
return handle;
} //end if
//
botimport.Print(PRT_WARNING, "couldn't find skill %d in %s\n", intskill, charfile);
//
if (!reload)
{
//try to load a cached default character with the given skill
cachedhandle = BotFindCachedCharacter(DEFAULT_CHARACTER, skill);
if (cachedhandle)
{
botimport.Print(PRT_MESSAGE, "loaded cached default skill %d from %s\n", intskill, charfile);
return cachedhandle;
} //end if
} //end if
//try to load the default character with the given skill
ch = BotLoadCharacterFromFile(DEFAULT_CHARACTER, intskill);
if (ch)
{
botcharacters[handle] = ch;
botimport.Print(PRT_MESSAGE, "loaded default skill %d from %s\n", intskill, charfile);
return handle;
} //end if
//
if (!reload)
{
//try to load a cached character with any skill
cachedhandle = BotFindCachedCharacter(charfile, -1);
if (cachedhandle)
{
botimport.Print(PRT_MESSAGE, "loaded cached skill %f from %s\n", botcharacters[cachedhandle]->skill, charfile);
return cachedhandle;
} //end if
} //end if
//try to load a character with any skill
ch = BotLoadCharacterFromFile(charfile, -1);
if (ch)
{
botcharacters[handle] = ch;
botimport.Print(PRT_MESSAGE, "loaded skill %f from %s\n", ch->skill, charfile);
return handle;
} //end if
//
if (!reload)
{
//try to load a cached character with any skill
cachedhandle = BotFindCachedCharacter(DEFAULT_CHARACTER, -1);
if (cachedhandle)
{
botimport.Print(PRT_MESSAGE, "loaded cached default skill %f from %s\n", botcharacters[cachedhandle]->skill, charfile);
return cachedhandle;
} //end if
} //end if
//try to load a character with any skill
ch = BotLoadCharacterFromFile(DEFAULT_CHARACTER, -1);
if (ch)
{
botcharacters[handle] = ch;
botimport.Print(PRT_MESSAGE, "loaded default skill %f from %s\n", ch->skill, charfile);
return handle;
} //end if
//
botimport.Print(PRT_WARNING, "couldn't load any skill from %s\n", charfile);
//couldn't load any character
return 0;
} //end of the function BotLoadCachedCharacter
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int BotLoadCharacterSkill(char *charfile, float skill)
{
int ch, defaultch;
defaultch = BotLoadCachedCharacter(DEFAULT_CHARACTER, skill, qfalse);
ch = BotLoadCachedCharacter(charfile, skill, LibVarGetValue("bot_reloadcharacters"));
if (defaultch && ch)
{
BotDefaultCharacteristics(botcharacters[ch], botcharacters[defaultch]);
} //end if
return ch;
} //end of the function BotLoadCharacterSkill
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int BotInterpolateCharacters(int handle1, int handle2, float desiredskill)
{
bot_character_t *ch1, *ch2, *out;
int i, handle;
float scale;
ch1 = BotCharacterFromHandle(handle1);
ch2 = BotCharacterFromHandle(handle2);
if (!ch1 || !ch2)
return 0;
//find a free spot for a character
for (handle = 1; handle <= MAX_CLIENTS; handle++)
{
if (!botcharacters[handle]) break;
} //end for
if (handle > MAX_CLIENTS) return 0;
out = (bot_character_t *) GetClearedMemory(sizeof(bot_character_t) +
MAX_CHARACTERISTICS * sizeof(bot_characteristic_t));
out->skill = desiredskill;
strcpy(out->filename, ch1->filename);
botcharacters[handle] = out;
scale = (float) (desiredskill - ch1->skill) / (ch2->skill - ch1->skill);
for (i = 0; i < MAX_CHARACTERISTICS; i++)
{
//
if (ch1->c[i].type == CT_FLOAT && ch2->c[i].type == CT_FLOAT)
{
out->c[i].type = CT_FLOAT;
out->c[i].value._float = ch1->c[i].value._float +
(ch2->c[i].value._float - ch1->c[i].value._float) * scale;
} //end if
else if (ch1->c[i].type == CT_INTEGER)
{
out->c[i].type = CT_INTEGER;
out->c[i].value.integer = ch1->c[i].value.integer;
} //end else if
else if (ch1->c[i].type == CT_STRING)
{
out->c[i].type = CT_STRING;
out->c[i].value.string = (char *) GetMemory(strlen(ch1->c[i].value.string)+1);
strcpy(out->c[i].value.string, ch1->c[i].value.string);
} //end else if
} //end for
return handle;
} //end of the function BotInterpolateCharacters
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int BotLoadCharacter(char *charfile, float skill)
{
int firstskill, secondskill, handle;
//make sure the skill is in the valid range
if (skill < 1.0) skill = 1.0;
else if (skill > 5.0) skill = 5.0;
//skill 1, 4 and 5 should be available in the character files
if (skill == 1.0 || skill == 4.0 || skill == 5.0)
{
return BotLoadCharacterSkill(charfile, skill);
} //end if
//check if there's a cached skill
handle = BotFindCachedCharacter(charfile, skill);
if (handle)
{
botimport.Print(PRT_MESSAGE, "loaded cached skill %f from %s\n", skill, charfile);
return handle;
} //end if
if (skill < 4.0)
{
//load skill 1 and 4
firstskill = BotLoadCharacterSkill(charfile, 1);
if (!firstskill) return 0;
secondskill = BotLoadCharacterSkill(charfile, 4);
if (!secondskill) return firstskill;
} //end if
else
{
//load skill 4 and 5
firstskill = BotLoadCharacterSkill(charfile, 4);
if (!firstskill) return 0;
secondskill = BotLoadCharacterSkill(charfile, 5);
if (!secondskill) return firstskill;
} //end else
//interpolate between the two skills
handle = BotInterpolateCharacters(firstskill, secondskill, skill);
if (!handle) return 0;
//write the character to the log file
BotDumpCharacter(botcharacters[handle]);
//
return handle;
} //end of the function BotLoadCharacter
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int CheckCharacteristicIndex(int character, int index)
{
bot_character_t *ch;
ch = BotCharacterFromHandle(character);
if (!ch) return qfalse;
if (index < 0 || index >= MAX_CHARACTERISTICS)
{
botimport.Print(PRT_ERROR, "characteristic %d does not exist\n", index);
return qfalse;
} //end if
if (!ch->c[index].type)
{
botimport.Print(PRT_ERROR, "characteristic %d is not initialized\n", index);
return qfalse;
} //end if
return qtrue;
} //end of the function CheckCharacteristicIndex
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
float Characteristic_Float(int character, int index)
{
bot_character_t *ch;
ch = BotCharacterFromHandle(character);
if (!ch) return 0;
//check if the index is in range
if (!CheckCharacteristicIndex(character, index)) return 0;
//an integer will be converted to a float
if (ch->c[index].type == CT_INTEGER)
{
return (float) ch->c[index].value.integer;
} //end if
//floats are just returned
else if (ch->c[index].type == CT_FLOAT)
{
return ch->c[index].value._float;
} //end else if
//cannot convert a string pointer to a float
else
{
botimport.Print(PRT_ERROR, "characteristic %d is not a float\n", index);
return 0;
} //end else if
// return 0;
} //end of the function Characteristic_Float
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
float Characteristic_BFloat(int character, int index, float min, float max)
{
float value;
bot_character_t *ch;
ch = BotCharacterFromHandle(character);
if (!ch) return 0;
if (min > max)
{
botimport.Print(PRT_ERROR, "cannot bound characteristic %d between %f and %f\n", index, min, max);
return 0;
} //end if
value = Characteristic_Float(character, index);
if (value < min) return min;
if (value > max) return max;
return value;
} //end of the function Characteristic_BFloat
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int Characteristic_Integer(int character, int index)
{
bot_character_t *ch;
ch = BotCharacterFromHandle(character);
if (!ch) return 0;
//check if the index is in range
if (!CheckCharacteristicIndex(character, index)) return 0;
//an integer will just be returned
if (ch->c[index].type == CT_INTEGER)
{
return ch->c[index].value.integer;
} //end if
//floats are casted to integers
else if (ch->c[index].type == CT_FLOAT)
{
return (int) ch->c[index].value._float;
} //end else if
else
{
botimport.Print(PRT_ERROR, "characteristic %d is not a integer\n", index);
return 0;
} //end else if
// return 0;
} //end of the function Characteristic_Integer
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int Characteristic_BInteger(int character, int index, int min, int max)
{
int value;
bot_character_t *ch;
ch = BotCharacterFromHandle(character);
if (!ch) return 0;
if (min > max)
{
botimport.Print(PRT_ERROR, "cannot bound characteristic %d between %d and %d\n", index, min, max);
return 0;
} //end if
value = Characteristic_Integer(character, index);
if (value < min) return min;
if (value > max) return max;
return value;
} //end of the function Characteristic_BInteger
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void Characteristic_String(int character, int index, char *buf, int size)
{
bot_character_t *ch;
ch = BotCharacterFromHandle(character);
if (!ch) return;
//check if the index is in range
if (!CheckCharacteristicIndex(character, index)) return;
//an integer will be converted to a float
if (ch->c[index].type == CT_STRING)
{
strncpy(buf, ch->c[index].value.string, size-1);
buf[size-1] = '\0';
return;
} //end if
else
{
botimport.Print(PRT_ERROR, "characteristic %d is not a string\n", index);
return;
} //end else if
return;
} //end of the function Characteristic_String
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
void BotShutdownCharacters(void)
{
int handle;
for (handle = 1; handle <= MAX_CLIENTS; handle++)
{
if (botcharacters[handle])
{
BotFreeCharacter2(handle);
} //end if
} //end for
} //end of the function BotShutdownCharacters
|