mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
Random name generation improvement (#359)
* Update RandomPlayerbotFactory.cpp
This commit is contained in:
@@ -219,7 +219,7 @@ Player* RandomPlayerbotFactory::CreateRandomBot(WorldSession* session, uint8 cls
|
||||
|
||||
std::string const RandomPlayerbotFactory::CreateRandomBotName(uint8 gender)
|
||||
{
|
||||
std::string botName = "";
|
||||
std::string botName = "";
|
||||
int tries = 10;
|
||||
while(--tries) {
|
||||
QueryResult result = CharacterDatabase.Query("SELECT name FROM playerbots_names "
|
||||
@@ -235,7 +235,80 @@ std::string const RandomPlayerbotFactory::CreateRandomBotName(uint8 gender)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
LOG_ERROR("playerbots", "No more names left for random bots. Simply random.");
|
||||
|
||||
//CONLANG NAME GENERATION
|
||||
LOG_ERROR("playerbots", "No more names left for random bots. Attempting conlang name generation.");
|
||||
const std::string groupCategory = "SCVKRU";
|
||||
const std::string groupFormStart[2][4] = {
|
||||
{"SV","SV","VK","RV"},
|
||||
{"V" ,"SU","VS","RV"}
|
||||
};
|
||||
const std::string groupFormMid[2][6] = {
|
||||
{"CV","CVC","CVC","CVK","VC","VK"},
|
||||
{"CV","CVC","CVK","KVC","VC","KV"}
|
||||
};
|
||||
const std::string groupFormEnd[2][4] = {
|
||||
{"CV","VC","VK","CV"},
|
||||
{"RU","UR","VR","V" }
|
||||
};
|
||||
const std::string groupLetter[2][6] = {
|
||||
//S C V K R U
|
||||
{"dtspkThfS","bcCdfghjkmnNqqrrlsStTvwxyz","aaeeiouA" ,"ppttkkbdg","lmmnrr" ,"AEO" },
|
||||
{"dtskThfS" ,"bcCdfghjkmmnNqrrlssStTvwyz","aaaeeiiuAAEIO","ppttkbbdg","lmmnrrr","AEOy"}
|
||||
};
|
||||
const std::string replaceRule[2][17] = {
|
||||
{"ST" ,"ka","ko","ku","kr","S" ,"T" ,"C" ,"N" ,"jj","AA","AI" ,"A" ,"E" ,"O" ,"I" ,"aa"},
|
||||
{"sth","ca","co","cu","cr","sh","th","ch","ng","dg","A" ,"ayu","ai","ei","ou","iu","ae"}
|
||||
};
|
||||
|
||||
tries = 10;
|
||||
while (--tries)
|
||||
{
|
||||
botName.clear();
|
||||
//Build name from groupForms
|
||||
//Pick random start group
|
||||
botName = groupFormStart[gender][rand()%4];
|
||||
//Pick up to 2 and then up to 1 additional middle group
|
||||
for (int i = 0; i < rand()%3 + rand()%2; i++)
|
||||
{
|
||||
botName += groupFormMid[gender][rand()%6];
|
||||
}
|
||||
//Pick up to 1 end group
|
||||
botName += rand()%2 ? groupFormEnd[gender][rand()%4] : "";
|
||||
//If name is single letter add random end group
|
||||
botName += (botName.size() < 2) ? groupFormEnd[gender][rand()%4] : "";
|
||||
|
||||
//Replace Catagory value with random Letter from that Catagory's Letter string for a given bot gender
|
||||
for (int i=0; i < botName.size(); i++)
|
||||
{
|
||||
botName[i] = groupLetter[gender][groupCategory.find(botName[i])][rand()%groupLetter[gender][groupCategory.find(botName[i])].size()];
|
||||
}
|
||||
|
||||
//Itterate over replace rules
|
||||
for (int i = 0; i < 17; i++)
|
||||
{
|
||||
int j = botName.find(replaceRule[0][i]);
|
||||
while ( j > -1)
|
||||
{
|
||||
botName.replace(j,replaceRule[0][i].size(),replaceRule[1][i]);
|
||||
j = botName.find(replaceRule[0][i]);
|
||||
}
|
||||
}
|
||||
|
||||
//Capitalize first letter
|
||||
botName[0] -= 32;
|
||||
|
||||
if (ObjectMgr::CheckPlayerName(botName) != CHAR_NAME_SUCCESS ||
|
||||
(sObjectMgr->IsReservedName(botName) || sObjectMgr->IsProfanityName(botName)))
|
||||
{
|
||||
botName.clear();
|
||||
continue;
|
||||
}
|
||||
return std::move(botName);
|
||||
}
|
||||
|
||||
//TRUE RANDOM NAME GENERATION
|
||||
LOG_ERROR("playerbots", "Conlang name generation failed. True random name fallback.");
|
||||
tries = 10;
|
||||
while(--tries) {
|
||||
for (uint8 i = 0; i < 10; i++) {
|
||||
|
||||
Reference in New Issue
Block a user