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

Reply
 
Thread Tools Display Modes
  #1  
Old 05-15-2010, 10:16 PM
Wolftousen
Sarnak
 
Join Date: Apr 2008
Posts: 49
Default COMMITTED: Spawn Variance

Was confused as to why a certain spawn kept going off at the same spawn time even though it had variance set in the database entry.

Went and found out that the function that controls spawn time has some minor bugs that prevent variance from working properly:

zone/spawn2.cpp rev 1488:

Code:
int32 Spawn2::resetTimer()
{
	int32 rspawn = respawn_ * 1000;
	
	if (variance_ != 0) {
		int var_over_2 = variance_/2;
		rspawn = MakeRandomInt(rspawn - var_over_2, rspawn + var_over_2);
		
		//put a lower bound on it, not a lot of difference below 100, so set that as the bound.
		if(rspawn < 100)
			rspawn = 100;
	}
	
	return (rspawn);
	
}

this should be:
Code:
int32 Spawn2::resetTimer()
{
	int32 rspawn = respawn_ * 1000;
	
	if (variance_ != 0) {
		int var_over_2 = (variance_ * 1000) / 2;
		rspawn = MakeRandomInt(rspawn - var_over_2, rspawn + var_over_2);
	}
	
	return (rspawn);
	
}

The if statement that tests rspawn < 100 prevents the spawn time from varying to be less than it's base.

Not multiplying variance_ by 1000 means it is not operating in seconds, but something smaller (micro seconds i think, i forget...).
Reply With Quote
  #2  
Old 05-16-2010, 03:24 AM
KLS
Administrator
 
Join Date: Sep 2006
Posts: 1,348
Default

I'm a bit confused as to what the problem is or how this fixes it. Could you go into detail?
Reply With Quote
  #3  
Old 05-16-2010, 05:00 AM
Wolftousen
Sarnak
 
Join Date: Apr 2008
Posts: 49
Default

Code:
int32 Spawn2::resetTimer()
{
1.	int32 rspawn = respawn_ * 1000;
	
2.	if (variance_ != 0) {
3.		int var_over_2 = variance_/2;
4.		rspawn = MakeRandomInt(rspawn - var_over_2, rspawn + var_over_2);
		
		//put a lower bound on it, not a lot of difference below 100, so set that as the bound.
5.		if(rspawn < 100)
6.			rspawn = 100;
	}
	
7.	return (rspawn);
	
}
Line 1 - takes the stored spawn time (that is stored in seconds) and converts it to milliseconds.

Line 3 - takes the variance (stored in seconds) to the spawn time and divides it in half
Issue: variance is never converted to milliseconds, so you are only adding/subtracting fractions of a second to the spawn time.

Line 5,6: test to see if the acquired spawn time is less than 100
Issue: scrap this issue, i was wrong about it, this actually insures > 0 spawn time.


For example:
PEQ has Dozekar the Cursed set to spawn every 26.04 hours (93744 is value in database for this) with a variance of up to +-5.20805555555556 hours (18749 is value in database for this).

If i go through this function the way it is set up right now:
line 1: rspawn = 93744000;
line 2: evaluates to true
line 3: var_over_2 = 9374.5
line 4: rspawn = 93734625.5 to 93753374.5
line 5: rspawn will usually evaluate to false
line 7: return value from line 4


The values at line 4 should be 74995000 to 112493000 otherwise you are only varying the spawn time by fractions of a second which is pointless.

final code:

Code:
int32 Spawn2::resetTimer()
{
	int32 rspawn = respawn_ * 1000;
	
	if (variance_ != 0) {
		int var_over_2 = (variance_ * 1000) / 2;
		rspawn = MakeRandomInt(rspawn - var_over_2, rspawn + var_over_2);
	}

	//put a lower bound on it, not a lot of difference below 100, so set that as the bound.
		if(rspawn < 100)
			rspawn = 100;

	return (rspawn);
	
}
Hope that clears it up.
Reply With Quote
  #4  
Old 05-16-2010, 12:32 PM
KLS
Administrator
 
Join Date: Sep 2006
Posts: 1,348
Default

That 2nd change makes more sense.
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 05:56 AM.


 

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