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

be_ai_chat.c File Reference

#include "../game/q_shared.h"
#include "l_memory.h"
#include "l_libvar.h"
#include "l_script.h"
#include "l_precomp.h"
#include "l_struct.h"
#include "l_utils.h"
#include "l_log.h"
#include "aasfile.h"
#include "../game/botlib.h"
#include "../game/be_aas.h"
#include "be_aas_funcs.h"
#include "be_interface.h"
#include "../game/be_ea.h"
#include "../game/be_ai_chat.h"

Include dependency graph for be_ai_chat.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  bot_chat_s
struct  bot_chatmessage_s
struct  bot_chatstate_s
struct  bot_chattype_s
struct  bot_ichatdata_t
struct  bot_matchpiece_s
struct  bot_matchstring_s
struct  bot_matchtemplate_s
struct  bot_randomlist_s
struct  bot_randomstring_s
struct  bot_replychat_s
struct  bot_replychatkey_s
struct  bot_stringlist_s
struct  bot_synonym_s
struct  bot_synonymlist_s

Defines

#define CHATMESSAGE_RECENTTIME   20
#define ESCAPE_CHAR   0x01
#define MT_STRING   2
#define MT_VARIABLE   1
#define RCKFL_AND   1
#define RCKFL_BOTNAMES   32
#define RCKFL_GENDERFEMALE   64
#define RCKFL_GENDERLESS   256
#define RCKFL_GENDERMALE   128
#define RCKFL_NAME   4
#define RCKFL_NOT   2
#define RCKFL_STRING   8
#define RCKFL_VARIABLES   16

Typedefs

typedef bot_chat_s bot_chat_t
typedef bot_chatmessage_s bot_chatmessage_t
typedef bot_chatstate_s bot_chatstate_t
typedef bot_chattype_s bot_chattype_t
typedef bot_matchpiece_s bot_matchpiece_t
typedef bot_matchstring_s bot_matchstring_t
typedef bot_matchtemplate_s bot_matchtemplate_t
typedef bot_randomlist_s bot_randomlist_t
typedef bot_randomstring_s bot_randomstring_t
typedef bot_replychat_s bot_replychat_t
typedef bot_replychatkey_s bot_replychatkey_t
typedef bot_stringlist_s bot_stringlist_t
typedef bot_synonym_s bot_synonym_t
typedef bot_synonymlist_s bot_synonymlist_t

Functions

bot_consolemessage_tAllocConsoleMessage (void)
int BotAllocChatState (void)
int BotChatLength (int chatstate)
bot_chatstate_tBotChatStateFromHandle (int handle)
bot_stringlist_tBotCheckChatMessageIntegrety (char *message, bot_stringlist_t *stringlist)
void BotCheckInitialChatIntegrety (bot_chat_t *chat)
void BotCheckReplyChatIntegrety (bot_replychat_t *replychat)
void BotCheckValidReplyChatKeySet (source_t *source, bot_replychatkey_t *keys)
char * BotChooseInitialChatMessage (bot_chatstate_t *cs, char *type)
void BotConstructChatMessage (bot_chatstate_t *chatstate, char *message, unsigned long mcontext, bot_match_t *match, unsigned long vcontext, int reply)
void BotDumpInitialChat (bot_chat_t *chat)
void BotDumpMatchTemplates (bot_matchtemplate_t *matches)
void BotDumpRandomStringList (bot_randomlist_t *randomlist)
void BotDumpReplyChat (bot_replychat_t *replychat)
void BotDumpSynonymList (bot_synonymlist_t *synlist)
void BotEnterChat (int chatstate, int clientto, int sendto)
int BotExpandChatMessage (char *outmessage, char *message, unsigned long mcontext, bot_match_t *match, unsigned long vcontext, int reply)
int BotFindMatch (char *str, bot_match_t *match, unsigned long int context)
bot_stringlist_tBotFindStringInList (bot_stringlist_t *list, char *string)
void BotFreeChatFile (int chatstate)
void BotFreeChatState (int handle)
void BotFreeMatchPieces (bot_matchpiece_t *matchpieces)
void BotFreeMatchTemplates (bot_matchtemplate_t *mt)
void BotFreeReplyChat (bot_replychat_t *replychat)
void BotGetChatMessage (int chatstate, char *buf, int size)
void BotInitialChat (int chatstate, char *type, int mcontext, char *var0, char *var1, char *var2, char *var3, char *var4, char *var5, char *var6, char *var7)
int BotLoadChatFile (int chatstate, char *chatfile, char *chatname)
int BotLoadChatMessage (source_t *source, char *chatmessagestring)
bot_chat_tBotLoadInitialChat (char *chatfile, char *chatname)
bot_matchpiece_tBotLoadMatchPieces (source_t *source, char *endtoken)
bot_matchtemplate_tBotLoadMatchTemplates (char *matchfile)
bot_randomlist_tBotLoadRandomStrings (char *filename)
bot_replychat_tBotLoadReplyChat (char *filename)
bot_synonymlist_tBotLoadSynonyms (char *filename)
void BotMatchVariable (bot_match_t *match, int variable, char *buf, int size)
int BotNextConsoleMessage (int chatstate, bot_consolemessage_t *cm)
int BotNumConsoleMessages (int chatstate)
int BotNumInitialChats (int chatstate, char *type)
void BotPrintReplyChatKeys (bot_replychat_t *replychat)
void BotQueueConsoleMessage (int chatstate, int type, char *message)
void BotRemoveConsoleMessage (int chatstate, int handle)
void BotRemoveTildes (char *message)
void BotReplaceReplySynonyms (char *string, unsigned long int context)
void BotReplaceSynonyms (char *string, unsigned long int context)
void BotReplaceWeightedSynonyms (char *string, unsigned long int context)
int BotReplyChat (int chatstate, char *message, int mcontext, int vcontext, char *var0, char *var1, char *var2, char *var3, char *var4, char *var5, char *var6, char *var7)
void BotResetChatAI (void)
void BotSetChatGender (int chatstate, int gender)
void BotSetChatName (int chatstate, char *name, int client)
int BotSetupChatAI (void)
void BotShutdownChatAI (void)
void FreeConsoleMessage (bot_consolemessage_t *message)
void InitConsoleMessageHeap (void)
int IsWhiteSpace (char c)
char * RandomString (char *name)
int StringContains (char *str1, char *str2, int casesensitive)
char * StringContainsWord (char *str1, char *str2, int casesensitive)
void StringReplaceWords (char *string, char *synonym, char *replacement)
int StringsMatch (bot_matchpiece_t *pieces, bot_match_t *match)
void UnifyWhiteSpaces (char *string)

Variables

bot_chatstate_tbotchatstates [MAX_CLIENTS+1]
bot_consolemessage_tconsolemessageheap = NULL
bot_consolemessage_tfreeconsolemessages = NULL
bot_ichatdata_tichatdata [MAX_CLIENTS]
bot_matchtemplate_tmatchtemplates = NULL
bot_randomlist_trandomstrings = NULL
bot_replychat_treplychats = NULL
bot_synonymlist_tsynonyms = NULL


Define Documentation

#define CHATMESSAGE_RECENTTIME   20
 

Definition at line 71 of file be_ai_chat.c.

#define ESCAPE_CHAR   0x01
 

Definition at line 50 of file be_ai_chat.c.

Referenced by BotLoadChatMessage().

#define MT_STRING   2
 

Definition at line 59 of file be_ai_chat.c.

#define MT_VARIABLE   1
 

Definition at line 58 of file be_ai_chat.c.

#define RCKFL_AND   1
 

Definition at line 61 of file be_ai_chat.c.

Referenced by BotCheckValidReplyChatKeySet().

#define RCKFL_BOTNAMES   32
 

Definition at line 66 of file be_ai_chat.c.

#define RCKFL_GENDERFEMALE   64
 

Definition at line 67 of file be_ai_chat.c.

#define RCKFL_GENDERLESS   256
 

Definition at line 69 of file be_ai_chat.c.

#define RCKFL_GENDERMALE   128
 

Definition at line 68 of file be_ai_chat.c.

#define RCKFL_NAME   4
 

Definition at line 63 of file be_ai_chat.c.

#define RCKFL_NOT   2
 

Definition at line 62 of file be_ai_chat.c.

#define RCKFL_STRING   8
 

Definition at line 64 of file be_ai_chat.c.

#define RCKFL_VARIABLES   16
 

Definition at line 65 of file be_ai_chat.c.


Typedef Documentation

typedef struct bot_chat_s bot_chat_t
 

Referenced by BotCheckInitialChatIntegrety(), BotChooseInitialChatMessage(), BotDumpInitialChat(), and BotLoadInitialChat().

typedef struct bot_chatmessage_s bot_chatmessage_t
 

Referenced by BotCheckInitialChatIntegrety(), BotCheckReplyChatIntegrety(), BotChooseInitialChatMessage(), BotDumpInitialChat(), BotDumpReplyChat(), BotFreeReplyChat(), BotLoadInitialChat(), BotLoadReplyChat(), BotReplyChat(), and BotResetChatAI().

typedef struct bot_chatstate_s bot_chatstate_t
 

Referenced by BotAllocChatState(), BotChatLength(), BotChatStateFromHandle(), BotChooseInitialChatMessage(), BotConstructChatMessage(), BotEnterChat(), BotFreeChatFile(), BotFreeChatState(), BotGetChatMessage(), BotInitialChat(), BotLoadChatFile(), BotNextConsoleMessage(), BotNumConsoleMessages(), BotNumInitialChats(), BotQueueConsoleMessage(), BotRemoveConsoleMessage(), BotReplyChat(), BotSetChatGender(), and BotSetChatName().

typedef struct bot_chattype_s bot_chattype_t
 

Referenced by BotCheckInitialChatIntegrety(), BotChooseInitialChatMessage(), BotDumpInitialChat(), BotLoadInitialChat(), and BotNumInitialChats().

typedef struct bot_matchpiece_s bot_matchpiece_t
 

Referenced by BotCheckValidReplyChatKeySet(), BotDumpMatchTemplates(), BotDumpReplyChat(), BotFreeMatchPieces(), BotLoadMatchPieces(), BotPrintReplyChatKeys(), and StringsMatch().

typedef struct bot_matchstring_s bot_matchstring_t
 

Referenced by BotCheckValidReplyChatKeySet(), BotDumpMatchTemplates(), BotFreeMatchPieces(), BotLoadMatchPieces(), and StringsMatch().

typedef struct bot_matchtemplate_s bot_matchtemplate_t
 

Referenced by BotDumpMatchTemplates(), BotFindMatch(), BotFreeMatchTemplates(), and BotLoadMatchTemplates().

typedef struct bot_randomlist_s bot_randomlist_t
 

Referenced by BotDumpRandomStringList(), BotLoadRandomStrings(), and RandomString().

typedef struct bot_randomstring_s bot_randomstring_t
 

Referenced by BotDumpRandomStringList(), BotLoadRandomStrings(), and RandomString().

typedef struct bot_replychat_s bot_replychat_t
 

Referenced by BotCheckReplyChatIntegrety(), BotDumpReplyChat(), BotFreeReplyChat(), BotLoadReplyChat(), BotPrintReplyChatKeys(), BotReplyChat(), and BotResetChatAI().

typedef struct bot_replychatkey_s bot_replychatkey_t
 

Referenced by BotCheckValidReplyChatKeySet(), BotDumpReplyChat(), BotFreeReplyChat(), BotLoadReplyChat(), BotPrintReplyChatKeys(), and BotReplyChat().

typedef struct bot_stringlist_s bot_stringlist_t
 

Referenced by BotCheckChatMessageIntegrety(), BotCheckInitialChatIntegrety(), BotCheckReplyChatIntegrety(), and BotFindStringInList().

typedef struct bot_synonym_s bot_synonym_t
 

Referenced by BotDumpSynonymList(), BotLoadSynonyms(), BotReplaceReplySynonyms(), BotReplaceSynonyms(), and BotReplaceWeightedSynonyms().

typedef struct bot_synonymlist_s bot_synonymlist_t
 

Referenced by BotDumpSynonymList(), BotLoadSynonyms(), BotReplaceReplySynonyms(), BotReplaceSynonyms(), and BotReplaceWeightedSynonyms().


Function Documentation

bot_consolemessage_t* AllocConsoleMessage void   ) 
 

Definition at line 268 of file be_ai_chat.c.

References bot_consolemessage_t, freeconsolemessages, bot_consolemessage_s::next, and bot_consolemessage_s::prev.

Referenced by BotQueueConsoleMessage().

00269 {
00270     bot_consolemessage_t *message;
00271     message = freeconsolemessages;
00272     if (freeconsolemessages) freeconsolemessages = freeconsolemessages->next;
00273     if (freeconsolemessages) freeconsolemessages->prev = NULL;
00274     return message;
00275 } //end of the function AllocConsoleMessage

int BotAllocChatState void   ) 
 

Definition at line 2895 of file be_ai_chat.c.

References bot_chatstate_t, botchatstates, GetClearedMemory(), and i.

02896 {
02897     int i;
02898 
02899     for (i = 1; i <= MAX_CLIENTS; i++)
02900     {
02901         if (!botchatstates[i])
02902         {
02903             botchatstates[i] = GetClearedMemory(sizeof(bot_chatstate_t));
02904             return i;
02905         } //end if
02906     } //end for
02907     return 0;
02908 } //end of the function BotAllocChatState

Here is the call graph for this function:

int BotChatLength int  chatstate  ) 
 

Definition at line 2771 of file be_ai_chat.c.

References bot_chatstate_t, BotChatStateFromHandle(), bot_chatstate_s::chatmessage, and strlen().

02772 {
02773     bot_chatstate_t *cs;
02774 
02775     cs = BotChatStateFromHandle(chatstate);
02776     if (!cs) return 0;
02777     return strlen(cs->chatmessage);
02778 } //end of the function BotChatLength

Here is the call graph for this function:

bot_chatstate_t* BotChatStateFromHandle int  handle  ) 
 

Definition at line 219 of file be_ai_chat.c.

References bot_chatstate_t, botchatstates, botimport, and PRT_FATAL.

Referenced by BotChatLength(), BotEnterChat(), BotFreeChatFile(), BotGetChatMessage(), BotInitialChat(), BotLoadChatFile(), BotNextConsoleMessage(), BotNumConsoleMessages(), BotNumInitialChats(), BotQueueConsoleMessage(), BotRemoveConsoleMessage(), BotReplyChat(), BotSetChatGender(), and BotSetChatName().

00220 {
00221     if (handle <= 0 || handle > MAX_CLIENTS)
00222     {
00223         botimport.Print(PRT_FATAL, "chat state handle %d out of range\n", handle);
00224         return NULL;
00225     } //end if
00226     if (!botchatstates[handle])
00227     {
00228         botimport.Print(PRT_FATAL, "invalid chat state %d\n", handle);
00229         return NULL;
00230     } //end if
00231     return botchatstates[handle];
00232 } //end of the function BotChatStateFromHandle

bot_stringlist_t* BotCheckChatMessageIntegrety char *  message,
bot_stringlist_t stringlist
 

Definition at line 1513 of file be_ai_chat.c.

References bot_stringlist_t, BotFindStringInList(), botimport, GetClearedMemory(), i, Log_Write(), bot_stringlist_s::next, PRT_FATAL, RandomString(), s, strcpy(), bot_stringlist_s::string, and strlen().

Referenced by BotCheckInitialChatIntegrety(), and BotCheckReplyChatIntegrety().

01514 {
01515     int i;
01516     char *msgptr;
01517     char temp[MAX_MESSAGE_SIZE];
01518     bot_stringlist_t *s;
01519 
01520     msgptr = message;
01521     //
01522     while(*msgptr)
01523     {
01524         if (*msgptr == ESCAPE_CHAR)
01525         {
01526             msgptr++;
01527             switch(*msgptr)
01528             {
01529                 case 'v': //variable
01530                 {
01531                     //step over the 'v'
01532                     msgptr++;
01533                     while(*msgptr && *msgptr != ESCAPE_CHAR) msgptr++;
01534                     //step over the trailing escape char
01535                     if (*msgptr) msgptr++;
01536                     break;
01537                 } //end case
01538                 case 'r': //random
01539                 {
01540                     //step over the 'r'
01541                     msgptr++;
01542                     for (i = 0; (*msgptr && *msgptr != ESCAPE_CHAR); i++)
01543                     {
01544                         temp[i] = *msgptr++;
01545                     } //end while
01546                     temp[i] = '\0';
01547                     //step over the trailing escape char
01548                     if (*msgptr) msgptr++;
01549                     //find the random keyword
01550                     if (!RandomString(temp))
01551                     {
01552                         if (!BotFindStringInList(stringlist, temp))
01553                         {
01554                             Log_Write("%s = {\"%s\"} //MISSING RANDOM\r\n", temp, temp);
01555                             s = GetClearedMemory(sizeof(bot_stringlist_t) + strlen(temp) + 1);
01556                             s->string = (char *) s + sizeof(bot_stringlist_t);
01557                             strcpy(s->string, temp);
01558                             s->next = stringlist;
01559                             stringlist = s;
01560                         } //end if
01561                     } //end if
01562                     break;
01563                 } //end case
01564                 default:
01565                 {
01566                     botimport.Print(PRT_FATAL, "BotCheckChatMessageIntegrety: message \"%s\" invalid escape char\n", message);
01567                     break;
01568                 } //end default
01569             } //end switch
01570         } //end if
01571         else
01572         {
01573             msgptr++;
01574         } //end else
01575     } //end while
01576     return stringlist;
01577 } //end of the function BotCheckChatMessageIntegrety

Here is the call graph for this function:

void BotCheckInitialChatIntegrety bot_chat_t chat  ) 
 

Definition at line 1584 of file be_ai_chat.c.

References bot_chat_t, bot_chatmessage_t, bot_chattype_t, bot_stringlist_t, BotCheckChatMessageIntegrety(), cm, bot_chattype_s::firstchatmessage, FreeMemory(), bot_stringlist_s::next, bot_chattype_s::next, s, t, and bot_chat_s::types.

Referenced by BotLoadInitialChat().

01585 {
01586     bot_chattype_t *t;
01587     bot_chatmessage_t *cm;
01588     bot_stringlist_t *stringlist, *s, *nexts;
01589 
01590     stringlist = NULL;
01591     for (t = chat->types; t; t = t->next)
01592     {
01593         for (cm = t->firstchatmessage; cm; cm = cm->next)
01594         {
01595             stringlist = BotCheckChatMessageIntegrety(cm->chatmessage, stringlist);
01596         } //end for
01597     } //end for
01598     for (s = stringlist; s; s = nexts)
01599     {
01600         nexts = s->next;
01601         FreeMemory(s);
01602     } //end for
01603 } //end of the function BotCheckInitialChatIntegrety

Here is the call graph for this function:

void BotCheckReplyChatIntegrety bot_replychat_t replychat  ) 
 

Definition at line 1610 of file be_ai_chat.c.

References bot_chatmessage_t, bot_replychat_t, bot_stringlist_t, BotCheckChatMessageIntegrety(), cm, bot_replychat_s::firstchatmessage, FreeMemory(), bot_stringlist_s::next, bot_replychat_s::next, and s.

Referenced by BotLoadReplyChat().

01611 {
01612     bot_replychat_t *rp;
01613     bot_chatmessage_t *cm;
01614     bot_stringlist_t *stringlist, *s, *nexts;
01615 
01616     stringlist = NULL;
01617     for (rp = replychat; rp; rp = rp->next)
01618     {
01619         for (cm = rp->firstchatmessage; cm; cm = cm->next)
01620         {
01621             stringlist = BotCheckChatMessageIntegrety(cm->chatmessage, stringlist);
01622         } //end for
01623     } //end for
01624     for (s = stringlist; s; s = nexts)
01625     {
01626         nexts = s->next;
01627         FreeMemory(s);
01628     } //end for
01629 } //end of the function BotCheckReplyChatIntegrety

Here is the call graph for this function:

void BotCheckValidReplyChatKeySet source_t source,
bot_replychatkey_t keys
 

Definition at line 1721 of file be_ai_chat.c.

References bot_matchpiece_t, bot_matchstring_t, bot_replychatkey_t, bot_matchpiece_s::firststring, bot_replychatkey_s::flags, m, bot_replychatkey_s::match, bot_matchstring_s::next, bot_matchpiece_s::next, bot_replychatkey_s::next, qfalse, RCKFL_AND, source, source_t, SourceWarning(), bot_replychatkey_s::string, bot_matchstring_s::string, StringContains(), and bot_matchpiece_s::type.

Referenced by BotLoadReplyChat().

01722 {
01723     int allprefixed, hasvariableskey, hasstringkey;
01724     bot_matchpiece_t *m;
01725     bot_matchstring_t *ms;
01726     bot_replychatkey_t *key, *key2;
01727 
01728     //
01729     allprefixed = qtrue;
01730     hasvariableskey = hasstringkey = qfalse;
01731     for (key = keys; key; key = key->next)
01732     {
01733         if (!(key->flags & (RCKFL_AND|RCKFL_NOT)))
01734         {
01735             allprefixed = qfalse;
01736             if (key->flags & RCKFL_VARIABLES)
01737             {
01738                 for (m = key->match; m; m = m->next)
01739                 {
01740                     if (m->type == MT_VARIABLE) hasvariableskey = qtrue;
01741                 } //end for
01742             } //end if
01743             else if (key->flags & RCKFL_STRING)
01744             {
01745                 hasstringkey = qtrue;
01746             } //end else if
01747         } //end if
01748         else if ((key->flags & RCKFL_AND) && (key->flags & RCKFL_STRING))
01749         {
01750             for (key2 = keys; key2; key2 = key2->next)
01751             {
01752                 if (key2 == key) continue;
01753                 if (key2->flags & RCKFL_NOT) continue;
01754                 if (key2->flags & RCKFL_VARIABLES)
01755                 {
01756                     for (m = key2->match; m; m = m->next)
01757                     {
01758                         if (m->type == MT_STRING)
01759                         {
01760                             for (ms = m->firststring; ms; ms = ms->next)
01761                             {
01762                                 if (StringContains(ms->string, key->string, qfalse) != -1)
01763                                 {
01764                                     break;
01765                                 } //end if
01766                             } //end for
01767                             if (ms) break;
01768                         } //end if
01769                         else if (m->type == MT_VARIABLE)
01770                         {
01771                             break;
01772                         } //end if
01773                     } //end for
01774                     if (!m)
01775                     {
01776                         SourceWarning(source, "one of the match templates does not "
01777                                         "leave space for the key %s with the & prefix", key->string);
01778                     } //end if
01779                 } //end if
01780             } //end for
01781         } //end else
01782         if ((key->flags & RCKFL_NOT) && (key->flags & RCKFL_STRING))
01783         {
01784             for (key2 = keys; key2; key2 = key2->next)
01785             {
01786                 if (key2 == key) continue;
01787                 if (key2->flags & RCKFL_NOT) continue;
01788                 if (key2->flags & RCKFL_STRING)
01789                 {
01790                     if (StringContains(key2->string, key->string, qfalse) != -1)
01791                     {
01792                         SourceWarning(source, "the key %s with prefix ! is inside the key %s", key->string, key2->string);
01793                     } //end if
01794                 } //end if
01795                 else if (key2->flags & RCKFL_VARIABLES)
01796                 {
01797                     for (m = key2->match; m; m = m->next)
01798                     {
01799                         if (m->type == MT_STRING)
01800                         {
01801                             for (ms = m->firststring; ms; ms = ms->next)
01802                             {
01803                                 if (StringContains(ms->string, key->string, qfalse) != -1)
01804                                 {
01805                                     SourceWarning(source, "the key %s with prefix ! is inside "
01806                                                 "the match template string %s", key->string, ms->string);
01807                                 } //end if
01808                             } //end for
01809                         } //end if
01810                     } //end for
01811                 } //end else if
01812             } //end for
01813         } //end if
01814     } //end for
01815     if (allprefixed) SourceWarning(source, "all keys have a & or ! prefix");
01816     if (hasvariableskey && hasstringkey)
01817     {
01818         SourceWarning(source, "variables from the match template(s) could be "
01819                                 "invalid when outputting one of the chat messages");
01820     } //end if
01821 } //end of the function BotCheckValidReplyChatKeySet

Here is the call graph for this function:

char* BotChooseInitialChatMessage bot_chatstate_t cs,
char *  type
 

Definition at line 2407 of file be_ai_chat.c.

References AAS_Time(), bot_chat_t, bot_chatmessage_t, bot_chatstate_t, bot_chattype_t, bot_chatstate_s::chat, bot_chatmessage_s::chatmessage, bot_chattype_s::firstchatmessage, m, n, bot_chattype_s::name, bot_chatmessage_s::next, bot_chattype_s::next, Q_stricmp(), random, t, bot_chatmessage_s::time, type, and bot_chat_s::types.

Referenced by BotInitialChat().

02408 {
02409     int n, numchatmessages;
02410     float besttime;
02411     bot_chattype_t *t;
02412     bot_chatmessage_t *m, *bestchatmessage;
02413     bot_chat_t *chat;
02414 
02415     chat = cs->chat;
02416     for (t = chat->types; t; t = t->next)
02417     {
02418         if (!Q_stricmp(t->name, type))
02419         {
02420             numchatmessages = 0;
02421             for (m = t->firstchatmessage; m; m = m->next)
02422             {
02423                 if (m->time > AAS_Time()) continue;
02424                 numchatmessages++;
02425             } //end if
02426             //if all chat messages have been used recently
02427             if (numchatmessages <= 0)
02428             {
02429                 besttime = 0;
02430                 bestchatmessage = NULL;
02431                 for (m = t->firstchatmessage; m; m = m->next)
02432                 {
02433                     if (!besttime || m->time < besttime)
02434                     {
02435                         bestchatmessage = m;
02436                         besttime = m->time;
02437                     } //end if
02438                 } //end for
02439                 if (bestchatmessage) return bestchatmessage->chatmessage;
02440             } //end if
02441             else //choose a chat message randomly
02442             {
02443                 n = random() * numchatmessages;
02444                 for (m = t->firstchatmessage; m; m = m->next)
02445                 {
02446                     if (m->time > AAS_Time()) continue;
02447                     if (--n < 0)
02448                     {
02449                         m->time = AAS_Time() + CHATMESSAGE_RECENTTIME;
02450                         return m->chatmessage;
02451                     } //end if
02452                 } //end for
02453             } //end else
02454             return NULL;
02455         } //end if
02456     } //end for
02457     return NULL;
02458 } //end of the function BotChooseInitialChatMessage

Here is the call graph for this function:

void BotConstructChatMessage bot_chatstate_t chatstate,
char *  message,
unsigned long  mcontext,
bot_match_t match,
unsigned long  vcontext,
int  reply
 

Definition at line 2379 of file be_ai_chat.c.

References bot_chatstate_t, bot_match_t, BotExpandChatMessage(), botimport, bot_chatstate_s::chatmessage, i, match(), PRT_WARNING, and strcpy().

Referenced by BotInitialChat(), and BotReplyChat().

02381 {
02382     int i;
02383     char srcmessage[MAX_MESSAGE_SIZE];
02384 
02385     strcpy(srcmessage, message);
02386     for (i = 0; i < 10; i++)
02387     {
02388         if (!BotExpandChatMessage(chatstate->chatmessage, srcmessage, mcontext, match, vcontext, reply))
02389         {
02390             break;
02391         } //end if
02392         strcpy(srcmessage, chatstate->chatmessage);
02393     } //end for
02394     if (i >= 10)
02395     {
02396         botimport.Print(PRT_WARNING, "too many expansions in chat message\n");
02397         botimport.Print(PRT_WARNING, "%s\n", chatstate->chatmessage);
02398     } //end if
02399 } //end of the function BotConstructChatMessage

Here is the call graph for this function:

void BotDumpInitialChat bot_chat_t chat  ) 
 

Definition at line 1988 of file be_ai_chat.c.

References bot_chat_t, bot_chatmessage_t, bot_chattype_t, bot_chatmessage_s::chatmessage, bot_chattype_s::firstchatmessage, Log_Write(), m, bot_chattype_s::name, bot_chatmessage_s::next, bot_chattype_s::next, bot_chattype_s::numchatmessages, t, and bot_chat_s::types.

01989 {
01990     bot_chattype_t *t;
01991     bot_chatmessage_t *m;
01992 
01993     Log_Write("{");
01994     for (t = chat->types; t; t = t->next)
01995     {
01996         Log_Write(" type \"%s\"", t->name);
01997         Log_Write(" {");
01998         Log_Write("  numchatmessages = %d", t->numchatmessages);
01999         for (m = t->firstchatmessage; m; m = m->next)
02000         {
02001             Log_Write("  \"%s\"", m->chatmessage);
02002         } //end for
02003         Log_Write(" }");
02004     } //end for
02005     Log_Write("}");
02006 } //end of the function BotDumpInitialChat

Here is the call graph for this function:

void BotDumpMatchTemplates bot_matchtemplate_t matches  ) 
 

Definition at line 1077 of file be_ai_chat.c.

References bot_matchpiece_t, bot_matchstring_t, bot_matchtemplate_t, bot_matchtemplate_s::first, bot_matchpiece_s::firststring, fp, fprintf(), Log_FilePointer(), bot_matchstring_s::next,