Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

be_ai_weight.h File Reference

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Data Structures

struct  fuzzyseperator_s
struct  weight_s
struct  weightconfig_s

Defines

#define MAX_WEIGHTS   128
#define WT_BALANCE   1

Typedefs

typedef fuzzyseperator_s fuzzyseperator_t
typedef weight_s weight_t
typedef weightconfig_s weightconfig_t

Functions

void BotShutdownWeights (void)
void EvolveWeightConfig (weightconfig_t *config)
int FindFuzzyWeight (weightconfig_t *wc, char *name)
void FreeWeightConfig (weightconfig_t *config)
float FuzzyWeight (int *inventory, weightconfig_t *wc, int weightnum)
float FuzzyWeightUndecided (int *inventory, weightconfig_t *wc, int weightnum)
void InterbreedWeightConfigs (weightconfig_t *config1, weightconfig_t *config2, weightconfig_t *configout)
weightconfig_tReadWeightConfig (char *filename)
void ScaleBalanceRange (weightconfig_t *config, float scale)
void ScaleWeight (weightconfig_t *config, char *name, float scale)
qboolean WriteWeightConfig (char *filename, weightconfig_t *config)


Define Documentation

#define MAX_WEIGHTS   128
 

Definition at line 33 of file be_ai_weight.h.

#define WT_BALANCE   1
 

Definition at line 32 of file be_ai_weight.h.

Referenced by InterbreedFuzzySeperator_r().


Typedef Documentation

typedef struct fuzzyseperator_s fuzzyseperator_t
 

Referenced by EvolveFuzzySeperator_r(), FreeFuzzySeperators_r(), FuzzyWeight(), FuzzyWeight_r(), FuzzyWeightUndecided(), FuzzyWeightUndecided_r(), InterbreedFuzzySeperator_r(), ReadFuzzySeperators_r(), ReadFuzzyWeight(), ReadWeightConfig(), ScaleFuzzySeperator_r(), and ScaleFuzzySeperatorBalanceRange_r().

typedef struct weight_s weight_t
 

typedef struct weightconfig_s weightconfig_t
 

Referenced by EvolveWeightConfig(), FindFuzzyWeight(), FreeWeightConfig(), FreeWeightConfig2(), FuzzyWeight(), FuzzyWeightUndecided(), InterbreedWeightConfigs(), ItemWeightIndex(), ReadWeightConfig(), ScaleFuzzyBalanceRange(), ScaleWeight(), and WeaponWeightIndex().


Function Documentation

void BotShutdownWeights void   ) 
 

Definition at line 900 of file be_ai_weight.c.

References FreeWeightConfig2(), i, and weightFileList.

Referenced by Export_BotLibShutdown().

00901 {
00902     int i;
00903 
00904     for( i = 0; i < MAX_WEIGHT_FILES; i++ )
00905     {
00906         if (weightFileList[i])
00907         {
00908             FreeWeightConfig2(weightFileList[i]);
00909             weightFileList[i] = NULL;
00910         } //end if
00911     } //end for
00912 } //end of the function BotShutdownWeights

Here is the call graph for this function:

void EvolveWeightConfig weightconfig_t config  ) 
 

Definition at line 729 of file be_ai_weight.c.

References EvolveFuzzySeperator_r(), weight_s::firstseperator, i, weightconfig_s::numweights, weightconfig_t, and weightconfig_s::weights.

Referenced by BotMutateGoalFuzzyLogic().

00730 {
00731     int i;
00732 
00733     for (i = 0; i < config->numweights; i++)
00734     {
00735         EvolveFuzzySeperator_r(config->weights[i].firstseperator);
00736     } //end for
00737 } //end of the function EvolveWeightConfig

Here is the call graph for this function:

int FindFuzzyWeight weightconfig_t wc,
char *  name
 

Definition at line 557 of file be_ai_weight.c.

References i, name, weight_s::name, weightconfig_s::numweights, strcmp(), weightconfig_t, and weightconfig_s::weights.

Referenced by ItemWeightIndex(), and WeaponWeightIndex().

00558 {
00559     int i;
00560 
00561     for (i = 0; i < wc->numweights; i++)
00562     {
00563         if (!strcmp(wc->weights[i].name, name))
00564         {
00565             return i;
00566         } //end if
00567     } //end if
00568     return -1;
00569 } //end of the function FindFuzzyWeight

Here is the call graph for this function:

void FreeWeightConfig weightconfig_t config  ) 
 

Definition at line 142 of file be_ai_weight.c.

References FreeWeightConfig2(), LibVarGetValue(), and weightconfig_t.

Referenced by BotFreeItemWeights(), BotFreeWeaponWeights(), and ReadWeightConfig().

00143 {
00144     if (!LibVarGetValue("bot_reloadcharacters")) return;
00145     FreeWeightConfig2(config);
00146 } //end of the function FreeWeightConfig

Here is the call graph for this function:

float FuzzyWeight int *  inventory,
weightconfig_t wc,
int  weightnum
 

Definition at line 644 of file be_ai_weight.c.

References fuzzyseperator_s::child, weight_s::firstseperator, fuzzyseperator_t, FuzzyWeight_r(), fuzzyseperator_s::index, fuzzyseperator_s::next, s, fuzzyseperator_s::value, fuzzyseperator_s::weight, weightconfig_t, and weightconfig_s::weights.

Referenced by BotChooseBestFightWeapon(), BotChooseLTGItem(), and BotChooseNBGItem().

00645 {
00646 #ifdef EVALUATERECURSIVELY
00647     return FuzzyWeight_r(inventory, wc->weights[weightnum].firstseperator);
00648 #else
00649     fuzzyseperator_t *s;
00650 
00651     s = wc->weights[weightnum].firstseperator;
00652     if (!s) return 0;
00653     while(1)
00654     {
00655         if (inventory[s->index] < s->value)
00656         {
00657             if (s->child) s = s->child;
00658             else return s->weight;
00659         } //end if
00660         else
00661         {
00662             if (s->next) s = s->next;
00663             else return s->weight;
00664         } //end else
00665     } //end if
00666     return 0;
00667 #endif
00668 } //end of the function FuzzyWeight

Here is the call graph for this function:

float FuzzyWeightUndecided int *  inventory,
weightconfig_t wc,
int  weightnum
 

Definition at line 675 of file be_ai_weight.c.

References fuzzyseperator_s::child, weight_s::firstseperator, fuzzyseperator_t, FuzzyWeightUndecided_r(), fuzzyseperator_s::index, fuzzyseperator_s::maxweight, fuzzyseperator_s::minweight, fuzzyseperator_s::next, random, s, fuzzyseperator_s::value, weightconfig_t, and weightconfig_s::weights.

Referenced by BotChooseLTGItem(), and BotChooseNBGItem().

00676 {
00677 #ifdef EVALUATERECURSIVELY
00678     return FuzzyWeightUndecided_r(inventory, wc->weights[weightnum].firstseperator);
00679 #else
00680     fuzzyseperator_t *s;
00681 
00682     s = wc->weights[weightnum].firstseperator;
00683     if (!s) return 0;
00684     while(1)
00685     {
00686         if (inventory[s->index] < s->value)
00687         {
00688             if (s->child) s = s->child;
00689             else return s->minweight + random() * (s->maxweight - s->minweight);
00690         } //end if
00691         else
00692         {
00693             if (s->next) s = s->next;
00694             else return s->minweight + random() * (s->maxweight - s->minweight);
00695         } //end else
00696     } //end if
00697     return 0;
00698 #endif
00699 } //end of the function FuzzyWeightUndecided

Here is the call graph for this function:

void InterbreedWeightConfigs weightconfig_t config1,
weightconfig_t config2,
weightconfig_t configout
 

Definition at line 876 of file be_ai_weight.c.

References botimport, weight_s::firstseperator, i, InterbreedFuzzySeperator_r(), weightconfig_s::numweights, PRT_ERROR, weightconfig_t, and weightconfig_s::weights.

Referenced by BotInterbreedGoalFuzzyLogic().

00878 {
00879     int i;
00880 
00881     if (config1->numweights != config2->numweights ||
00882         config1->numweights != configout->numweights)
00883     {
00884         botimport.Print(PRT_ERROR, "cannot interbreed weight configs, unequal numweights\n");
00885         return;
00886     } //end if
00887     for (i = 0; i < config1->numweights; i++)
00888     {
00889         InterbreedFuzzySeperator_r(config1->weights[i].firstseperator,
00890                                     config2->weights[i].firstseperator,
00891                                     configout->weights[i].firstseperator);
00892     } //end for
00893 } //end of the function InterbreedWeightConfigs

Here is the call graph for this function:

weightconfig_t* ReadWeightConfig char *  filename  ) 
 

Definition at line 279 of file be_ai_weight.c.

References BOTFILESBASEFOLDER, botimport, fuzzyseperator_s::child, weightconfig_s::filename, weight_s::firstseperator, FreeMemory(), FreeSource(), FreeWeightConfig(), fuzzyseperator_t, GetClearedMemory(), fuzzyseperator_s::index, LibVarGetValue(), LoadSourceFile(), n, weight_s::name, fuzzyseperator_s::next, weightconfig_s::numweights, PC_ExpectAnyToken(), PC_ExpectTokenString(), PC_ExpectTokenType(), PC_ReadToken(), PC_SetBaseFolder(), PRT_ERROR, PRT_MESSAGE, Q_strncpyz(), ReadFuzzySeperators_r(), ReadFuzzyWeight(), source, source_t, SourceError(), SourceWarning(), strcmp(), strcpy(), token_s::string, StripDoubleQuotes(), strlen(), Sys_MilliSeconds(), token, token_t, TT_STRING, fuzzyseperator_s::value, weightconfig_t, weightFileList, and weightconfig_s::weights.

Referenced by BotLoadItemWeights(), and BotLoadWeaponWeights().

00280 {
00281     int newindent, avail = 0, n;
00282     token_t token;
00283     source_t *source;
00284     fuzzyseperator_t *fs;
00285     weightconfig_t *config = NULL;
00286 #ifdef DEBUG
00287     int starttime;
00288 
00289     starttime = Sys_MilliSeconds();
00290 #endif //DEBUG
00291 
00292     if (!LibVarGetValue("bot_reloadcharacters"))
00293     {
00294         avail = -1;
00295         for( n = 0; n < MAX_WEIGHT_FILES; n++ )
00296         {
00297             config = weightFileList[n];
00298             if( !config )
00299             {
00300                 if( avail == -1 )
00301                 {
00302                     avail = n;
00303                 } //end if
00304                 continue;
00305             } //end if
00306             if( strcmp( filename, config->filename ) == 0 )
00307             {
00308                 //botimport.Print( PRT_MESSAGE, "retained %s\n", filename );
00309                 return config;
00310             } //end if
00311         } //end for
00312 
00313         if( avail == -1 )
00314         {
00315             botimport.Print( PRT_ERROR, "weightFileList was full trying to load %s\n", filename );
00316             return NULL;
00317         } //end if
00318     } //end if
00319 
00320     PC_SetBaseFolder(BOTFILESBASEFOLDER);
00321     source = LoadSourceFile(filename);
00322     if (!source)
00323     {
00324         botimport.Print(PRT_ERROR, "counldn't load %s\n", filename);
00325         return NULL;
00326     } //end if
00327     //
00328     config = (weightconfig_t *) GetClearedMemory(sizeof(weightconfig_t));
00329     config->numweights = 0;
00330     Q_strncpyz( config->filename, filename, sizeof(config->filename) );
00331     //parse the item config file
00332     while(PC_ReadToken(source, &token))
00333     {
00334         if (!strcmp(token.string, "weight"))
00335         {
00336             if (config->numweights >= MAX_WEIGHTS)
00337             {
00338                 SourceWarning(source, "too many fuzzy weights\n");
00339                 break;
00340             } //end if
00341             if (!PC_ExpectTokenType(source, TT_STRING, 0, &token))
00342             {
00343                 FreeWeightConfig(config);
00344                 FreeSource(source);
00345                 return NULL;
00346             } //end if
00347             StripDoubleQuotes(token.string);
00348             config->weights[config->numweights].name = (char *) GetClearedMemory(strlen(token.string) + 1);
00349             strcpy(config->weights[config->numweights].name, token.string);
00350             if (!PC_ExpectAnyToken(source, &token))
00351             {
00352                 FreeWeightConfig(config);
00353                 FreeSource(source);
00354                 return NULL;
00355             } //end if
00356             newindent = qfalse;
00357             if (!strcmp(token.string, "{"))
00358             {
00359                 newindent = qtrue;
00360                 if (!PC_ExpectAnyToken(source, &token))
00361                 {
00362                     FreeWeightConfig(config);
00363                     FreeSource(source);
00364                     return NULL;
00365                 } //end if
00366             } //end if
00367             if (!strcmp(token.string, "switch"))
00368             {
00369                 fs = ReadFuzzySeperators_r(source);
00370                 if (!fs)
00371                 {
00372                     FreeWeightConfig(config);
00373                     FreeSource(source);
00374                     return NULL;
00375                 } //end if
00376                 config->weights[config->numweights].firstseperator = fs;
00377             } //end if
00378             else if (!strcmp(token.string, "return"))
00379             {
00380                 fs = (fuzzyseperator_t *) GetClearedMemory(sizeof(fuzzyseperator_t));
00381                 fs->index = 0;
00382                 fs->value = MAX_INVENTORYVALUE;
00383                 fs->next = NULL;
00384                 fs->child = NULL;
00385                 if (!ReadFuzzyWeight(source, fs))
00386                 {
00387                     FreeMemory(fs);
00388                     FreeWeightConfig(config);
00389                     FreeSource(source);
00390                     return NULL;
00391                 } //end if
00392                 config->weights[config->numweights].firstseperator = fs;
00393             } //end else if
00394             else
00395             {
00396                 SourceError(source, "invalid name %s\n", token.string);
00397                 FreeWeightConfig(config);
00398                 FreeSource(source);
00399                 return NULL;
00400             } //end else
00401             if (newindent)
00402             {
00403                 if (!PC_ExpectTokenString(source, "}"))
00404                 {
00405                     FreeWeightConfig(config);
00406                     FreeSource(source);
00407                     return NULL;
00408                 } //end if
00409             } //end if
00410             config->numweights++;
00411         } //end if
00412         else
00413         {
00414             SourceError(source, "invalid name %s\n", token.string);
00415             FreeWeightConfig(config);
00416             FreeSource(source);
00417             return NULL;
00418         } //end else
00419     } //end while
00420     //free the source at the end of a pass
00421     FreeSource(source);
00422     //if the file was located in a pak file
00423     botimport.Print(PRT_MESSAGE, "loaded %s\n", filename);
00424 #ifdef DEBUG
00425     if (bot_developer)
00426     {
00427         botimport.Print(PRT_MESSAGE, "weights loaded in %d msec\n", Sys_MilliSeconds() - starttime);
00428     } //end if
00429 #endif //DEBUG
00430     //
00431     if (!LibVarGetValue("bot_reloadcharacters"))
00432     {
00433         weightFileList[avail] = config;
00434     } //end if
00435     //
00436     return config;
00437 } //end of the function ReadWeightConfig

Here is the call graph for this function:

void ScaleBalanceRange weightconfig_t config,
float  scale
 

void ScaleWeight weightconfig_t config,
char *  name,
float  scale
 

Definition at line 766 of file be_ai_weight.c.

References weight_s::firstseperator, i, weight_s::name, name, weightconfig_s::numweights, ScaleFuzzySeperator_r(), strcmp(), weightconfig_t, and weightconfig_s::weights.

00767 {
00768     int i;
00769 
00770     if (scale < 0) scale = 0;
00771     else if (scale > 1) scale = 1;
00772     for (i = 0; i < config->numweights; i++)
00773     {
00774         if (!strcmp(name, config->weights[i].name))
00775         {
00776             ScaleFuzzySeperator_r(config->weights[i].firstseperator, scale);
00777             break;
00778         } //end if
00779     } //end for
00780 } //end of the function ScaleWeight

Here is the call graph for this function:

qboolean WriteWeightConfig char *  filename,
weightconfig_t config
 


Generated on Thu Aug 25 12:42:16 2005 for Quake III Arena by  doxygen 1.3.9.1