Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Server Code Submissions

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-03-2010, 03:38 AM
Secrets's Avatar
Secrets
Demi-God
 
Join Date: May 2007
Location: b
Posts: 1,449
Default Random NPC names with the @ Symbol

This makes it so it picks a random NPC name whenever the NPC has the symbol @ in its name. It also supports having the @ in the name where ever you want, so you could do "Guard @" and it would show up as "Guard Pyzui" for example, on a #repop of the zone. Good for completely random NPCs.

I don't know if this should be added to official SVN or not, but it shouldn't hurt because we never know if SOE will do random mob names in the future, plus it's not going to affect PEQ content (no @ symbols in the NPCs name atm, it's why I picked it)

It also adds support for a random name to be generated in MiscFunctions.cpp. Perhaps this could be ported to perl for whatever reason you may have.

Code:
Index: common/MiscFunctions.cpp
===================================================================
--- common/MiscFunctions.cpp	(revision 1272)
+++ common/MiscFunctions.cpp	(working copy)
@@ -490,3 +490,80 @@
 	return NewString;
 }
 
+char *GetRandomName()
+{
+
+// creates up to a 10 char name
+			char vowels[18]="aeiouyaeiouaeioe";
+			char cons[48]="bcdfghjklmnpqrstvwxzybcdgklmnprstvwbcdgkpstrkd";
+			char rndname[17]="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+			char paircons[33]="ngrkndstshthphsktrdrbrgrfrclcr";
+			int rndnum=rand()%76,n=1;
+			bool dlc=false;
+			bool vwl=false;
+			bool dbl=false;
+			if (rndnum>63)
+			{	// rndnum is 0 - 75 where 64-75 is cons pair, 17-63 is cons, 0-16 is vowel
+				rndnum=(rndnum-61)*2;	// name can't start with "ng" "nd" or "rk"
+				rndname[0]=paircons[rndnum];
+				rndname[1]=paircons[rndnum+1];
+				n=2;
+			}
+			else if (rndnum>16)
+			{
+				rndnum-=17;
+				rndname[0]=cons[rndnum];
+			}
+			else
+			{
+				rndname[0]=vowels[rndnum];
+				vwl=true;
+			}
+			int namlen=(rand()%6)+5;
+			for (int i=n;i<namlen;i++)
+			{
+				dlc=false;
+				if (vwl)	//last char was a vowel
+				{			// so pick a cons or cons pair
+					rndnum=rand()%63;
+					if (rndnum>46)
+					{	// pick a cons pair
+						if (i>namlen-3)	// last 2 chars in name?
+						{	// name can only end in cons pair "rk" "st" "sh" "th" "ph" "sk" "nd" or "ng"
+							rndnum=(rand()%8)*2;
+						}
+						else
+						{	// pick any from the set
+							rndnum=(rndnum-47)*2;
+						}
+						rndname[i]=paircons[rndnum];
+						rndname[i+1]=paircons[rndnum+1];
+						dlc=true;	// flag keeps second letter from being doubled below
+						i+=1;
+					}
+					else
+					{	// select a single cons
+						rndname[i]=cons[rndnum];
+					}
+				}
+				else
+				{		// select a vowel
+					rndname[i]=vowels[rand()%17];
+				}
+				vwl=!vwl;
+				if (!dbl && !dlc)
+				{	// one chance at double letters in name
+					if (!(rand()%(i+10)))	// chances decrease towards end of name
+					{
+						rndname[i+1]=rndname[i];
+						dbl=true;
+						i+=1;
+					}
+				}
+			}
+			rndname[0]=toupper(rndname[0]);
+			char *NewString = new char[strlen(rndname) + 1];
+			strcpy(NewString, rndname);
+			return NewString;
+
+}
Index: common/MiscFunctions.h
===================================================================
--- common/MiscFunctions.h	(revision 1272)
+++ common/MiscFunctions.h	(working copy)
@@ -81,6 +81,7 @@
 int FloatToEQH(float d);
 void RemoveApostrophes(std::string &s);
 char *RemoveApostrophes(const char *s);
+char *GetRandomName();
 
 
 
Index: zone/mob.cpp
===================================================================
--- zone/mob.cpp	(revision 1272)
+++ zone/mob.cpp	(working copy)
@@ -141,6 +141,17 @@
 	name[0]=0;
 	clean_name[0]=0;
 	lastname[0]=0;
+
+	string findname("@");
+	string myname(in_name);
+	  string::size_type pos = 0;
+    while ( (pos = myname.find(findname, pos)) != string::npos ) {
+        myname.replace( pos, findname.size(), GetRandomName());
+        pos++;
+    }
+
+	in_name = myname.c_str();
+
 	if(in_name)
 		strncpy(name,in_name,64);
 	if(in_lastname)
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 08:38 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3