Log in

View Full Version : COMMITTED: Spawn Variance


Wolftousen
05-15-2010, 10:16 PM
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:

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:
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...).

KLS
05-16-2010, 03:24 AM
I'm a bit confused as to what the problem is or how this fixes it. Could you go into detail?

Wolftousen
05-16-2010, 05:00 AM
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:

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.

KLS
05-16-2010, 12:32 PM
That 2nd change makes more sense.