How To Documentation
How To Add an In-Game Language to ChatBlade

Related ChatBlade Classes and functions:  
    CBLanguageTable
    CBClientImplementation
    CBSampleImplementation
    CBChatHandler
    CBSlashCommands
    CBConstants.h
    CBStringLiterals.h
    Elvish.XML

 
Summary:  
  Jump to section   Implement CBClientImplementation::LoadLanguageTables().  
  Jump to section Create a CBLanguageTable instance for each in-game artificial language desired.  
  Jump to section Fill the CBLanguageTable instances with fake words using CBLanguageTable::AddWord().  
  Jump to section Add each CBLanguageTable instance to ChatBlade via CBLanguageTable::AddLanguageTable().  
  Jump to section Add in constants representing the new LanguageID and a string representing that Language to ChatBlade.  
  Jump to section Modify CBClientImplementation::GetLanguageString() to return the name of the new language.  
  Jump to section Modify CBSlashCommands::OnCommandLanguage() to handle the new Language ID.  
  Jump to section Implement CBClientImplementation::GetLanguageKnowledgeLevel().  
Note:  Each in game artificial language should have a unique LanguageID.  
 

 
Details:  
 
Implement CBClientImplementation::LoadLanguageTables().  
     The loading of the Language tables should take place in CBClientImplementation::LoadLanguageTables().  
ChatBlade shall call this function from CBChatHandler::InitializeChat() via CBChatHandler::InitializeLanguageTables().  
Developers should implement  CBClientImplementation::LoadLanguageTables().  
A example that loads an Elvish language table is provided in CBSampleImplementation::LoadLanguageTables().  
That sample uses an XML file containing the desired words of the Elvish language, though most any mechanism can be used.  
See CBSampleImplementation.cpp and Elvish.XML.  
Sample Code:  
 
Create a CBLanguageTable instance for each in-game artificial language desired. 
     Each in-game artificial language should have a CBLanguageTable instance created for it.  
Each Language needs a unique LanguageID, that is used as the key for the Language Table.  
A CBLanguageTable instance can be reused if its LanguageID is reset and CBLanguageTable::Clear() is called in between each loading of a different Language.  
Sample Code:  
 
Fill the CBLanguageTable instances with fake words using CBLanguageTable::AddWord().  
     Each CBLanguageTable instance should be loaded up with words of various lengths that sound like representative words of the language of the Language Table.  
So if it were an Elvish Language Table words such as "Delle" and "Lithene" might be added.  If it were an Orcish Language Table words such as "Hakku" and "Volkar" might be used instead.  
Words of varying lengths should be added.  ChatBlade tries to match short typed in words with short words from the Language Table, and long Chat words, with the longer words from the Language Table.  So a variety of word lengths should be added for best effect.  
ChatBlade makes sure that each real word always matches the same word inside a Language Table.  
Words are added to a Language Table via the CBLanguageTable::AddWord() function.  
Developers should call CBLanguageTable::AddWord() once for each artificial word added.  
For best results Developers should make up at least 100 words which are representative of the target Language and add them to the Language Table.  
Sample Code:  
 
Add each CBLanguageTable instance to ChatBlade via CBLanguageTable::AddLanguageTable().  
     Once the CBLanguageTable instance has been populated with words the Language should be added to ChatBlade via the static CBLanguageTable::AddLanguageTable() function which copies the instance and stores it.  
ChatBlade keeps a map of all the Languages added as an internal member of the CBChatHandler class.  
Each Language is indexed by its unique LanguageID and is stored in CBData::pChatHandler->m_LanguageTableMap.  
When a Player overhears a Chat Message in a Language his Character is not fluent in, ChatBlade shall replace the real words of the Chat Message with words taken from the appropriate Language Table.  
The better a Character understands the in-game Language, the less chance there is of each word being replaced with artificial words from the Language Table.  
Sample Code:  
 
Add in constants representing the new LanguageID and a string representing that Language to ChatBlade.  
Each in-game Language in ChatBlade needs a unique LanguageID.  These LanguageIDs are stored in CBConstants.h.  
     For each new Language added a new constant should be #defined in the .h file.  
In addition a new string constant representing the name of the Language should be defined in CBStringLiterals.h.  
ChatBlade uses this string to determine when the Player wants to change to that Language using the /language Slash Command.  
Sample Code:  
 
Modify CBClientImplementation::GetLanguageString() to return the name of the new language.    
     CBClientImplementation::GetLanguageString() is a helper function which should supply the text name of a Language when given a LanguageID.   
Developers should modify this function to return the correct string for any new LanguageIDs added to the game.  
Sample Code:  
 
Modify CBSlashCommands::OnCommandLanguage() to handle the new Language ID.  
      CBSlashCommands::OnCommandLanguage() is a Slash Command which allows the Player to change, or display their In-Game Chat Language.  
This function should allow Players to change to the specified Language, provided their Character is fluent in it.  
A copy/paste/replace modification of an existing Language section in the code is required.  
Developers should modify this function to add in code to support any new in-game Languages added to the game.  
Sample Code:  
 
Implement CBClientImplementation::GetLanguageKnowledgeLevel().  
     ChatBlade relies on information returned from CBClientImplementation::GetLanguageKnowledgeLevel() to determine how drastically to alter Game Chat that is in a Language the current Character is not fluent in.  
ChatBlade shall call CBClientImplementation::GetLanguageKnowledgeLevel() when a Chat Message arrives with a Language that is not set for Default.  
CBClientImplementation::GetLanguageKnowledgeLevel(nLanguageID) should return an int in the range of 0 - 100.  With 0 meaning the Character does not understand the Language at all, and 100 meaning the Character is fully fluent in the specified Language.  
If this function returns 0 then all the words of a Chat Message would be replaced with artificial words from the appropriate Language Table.  If this function returns 100 then no words shall be altered, and the Player can read the Chat Message, just as it was sent.  If this function returns 50 then approximately half of the words of each Chat Message would be changed to words stored in the corresponding Language Table that matches the Language the Chat Message was sent in.  
In addition, if this function returns 100 then ChatBlade shall allow the Player to change his default Chat Language to the in-game Language via the /language Slash Command.  
Chat words with Numerals in them are not replaced.  
Sample Code:  
 

 

Code Samples:  

See CBSampleImplementation.cpp  and Elvish.XML for a complete sample of LoadLanguageTables() using an Elvish XML file. 
 
 
Creating a CBLanguageTable instance for Elvish.
     CBLanguageTable cbElvishLanguageTable(CB_LANGUAGE_ELVISH);
//  or
CBLanguageTable cbReusableLanguageTable;
cbReusableLanguageTable.SetLanguageID(CB_LANGUAGE_ELVISH);
 
 
Adding some Elvish sounding words to the Language Table.  
     cbElvishLanguageTable.AddWord("FELLENE");
cbElvishLanguageTable.AddWord("DEN");
cbElvishLanguageTable.AddWord("SYLLE");
cbElvishLanguageTable.AddWord("NENALAE");
cbElvishLanguageTable.AddWord("TISDARFORRETH");
cbElvishLanguageTable.AddWord("ZEN");
 
 
Adding a copy of the instance to ChatBlade.  
     CBLanguageTable::AddLanguageTable(cbElvishLanguageTable);
 
 
Defining our LanguageID and Language string constants for Vulcan in CBConstants.h and CBStringLiterals.h.  
     #define CB_LANGUAGE_VULCAN 4
 
#define CB_STRING_VULCAN _T("Vulcan")
 
 
Modifying CBClientImplementation::GetLanguageString() to return "Vulcan" when supplied a constant of CB_LANGUAGE_VULCAN
     case CB_LANGUAGE_VULCAN:
sLanguageString = CB_STRING_VULCAN;  //  Assuming a constant that = "Vulcan"
break;
 
 
Modifying CBSlashCommands::OnCommandLanguage() to support Vulcan using 2 code snippets.    
//  Vulcan
     if(CBData::pChatHandler->m_ClientImplementation.GetLanguageKnowledgeLevel(CB_LANGUAGE_VULCAN) > 99)
     {
CBData::pChatHandler->m_ClientImplementation.GetLanguageString(CB_STRING_VULCAN, sLanguage);
sString += sLanguage + CB_STRING_NEWLINE;
}
 
 
// See if they want to reset their current Language to Vulcan
if((CBUtils::CBStringIgnoreCompare(sCommandParameters, CB_STRING_VULCAN) == 0))
     {
if(CBData::pChatHandler->m_ClientImplementation.GetLanguageKnowledgeLevel(CB_LANGUAGE_VULCAN) > 99)
     {
// Change our current Language
CBData::nCurrentLanguageID = CB_LANGUAGE_VULCAN;
// Tell the user the Language has been changed
CBData::pChatHandler->AddMessageCommandFeedback(CB_TEXT_LANGUAGE_CHANGED);
}
else
     {
// Tell the user they are not fluent in that Language
CBData::pChatHandler->AddMessageCommandFeedback(CB_TEXT_NOT_FLUENT);
}
return(CB_SUCCESS);
}
 
 
Implementing CBClientImplementation::GetLanguageKnowledgeLevel(nLanguageID).  
     switch(nLanguageID)
     {
case CB_LANGUAGE_VULCAN:
//  Get the level of the current Characters knowledge of this Language from the Game database
nKnowledgeLevel = DevelopersDatabaseLookupFunction(sCharacterName, nLanguageID);
break;
 
default:
nKnowledgeLevel = 100;
}
return nKnowledgeLevel;
    
    

 

 

 

 

 

 
 
 
 
ChatBlade Copyright Flex Dolphynn