Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Development

Development::Development Forum for development topics and for those interested in EQEMu development. (Not a support forum)

Reply
 
Thread Tools Display Modes
  #1  
Old 11-30-2004, 07:11 PM
mByte
Hill Giant
 
Join Date: Feb 2002
Posts: 206
Default New NPC Random Code...

Noticed it wasnt very random so I added some fixes, tested it out looked pretty random if you ask me.

add this line to the private member of SpawnGroup
spawngroup.h
Code:
uint32 SelectSpawn(int minRand, int maxRand);
add the SelectSpawn method
spawngroup.cpp
Code:
uint32 SpawnGroup::SelectSpawn(int minRand, int maxRand)
{

	if(minRand > maxRand)
	{
		if(maxRand < 10)
			maxRand = 11;

		minRand = (rand()%maxRand);
	}

	int currentPick[1];
	int npcId = 0;

	currentPick[0] = 0; //npcId
	currentPick[1] = 1; //npcChance

	LinkedListIterator<SpawnEntry*> iterator(list_);
	iterator.Reset();
	while(iterator.MoreElements()) 
	{

		//cout << iterator.GetData()->NPCType << " " << iterator.GetData()->chance << " " << minRand << " " << maxRand << "\n";
		//First NPC is always the current pick
		if(currentPick[0] == 0){
			currentPick[0] = iterator.GetData()->NPCType;
			currentPick[1] = iterator.GetData()->chance;
		}
		else{
		//Now check for best spawn matching random!
			if((iterator.GetData()->chance >= minRand)){
					if(currentPick[1] > maxRand)
					{
						currentPick[0] = iterator.GetData()->NPCType;
						currentPick[1] = iterator.GetData()->chance;
					}
					else if(iterator.GetData()->chance > currentPick[1])
					{
						currentPick[0] = iterator.GetData()->NPCType;
						currentPick[1] = iterator.GetData()->chance;
					}
			   }
		}
		iterator.Advance();
	}

	npcId = currentPick[0];
	return npcId;
}
Replace the GetNPCType() method
spawngroup.cpp
Code:
uint32 SpawnGroup::GetNPCType() {
#if EQDEBUG >= 10
	LogFile->write(EQEMuLog::Debug, "SpawnGroup[%08x]::GetNPCType()", (int32) this);
#endif

	int npcType = -1;
	int minChance = (rand() % 100) % 50;
	int maxChance = (rand() % 100);

	//Check for 100% Chance
	LinkedListIterator<SpawnEntry*> iterator(list_);
	iterator.Reset();
	while(iterator.MoreElements()) {
		if(iterator.GetData()->chance == 100)
		{
			//cout << "Found a spawn that has 100% chance\n";
			npcType = iterator.GetData()->NPCType;
			break;
		}
		iterator.Advance();
	}

	//No 100% found - Find npc to load.
	if(npcType == -1)
	{
		//cout << "Looking for a good spawn!\n";
		npcType = SelectSpawn(minChance, maxChance);
	}

	return npcType;
}
__________________
mByte
Reply With Quote
Reply


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 12:55 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 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3