EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Development::Development (https://www.eqemulator.org/forums/forumdisplay.php?f=590)
-   -   Forage oddness (https://www.eqemulator.org/forums/showthread.php?t=34951)

Harcourt 02-22-2012 02:27 PM

Forage oddness
 
This looks odd to me, and I thought I'd run it by folks who know the code. By the way, if I created a local fix I have no idea how I'd communicate it to anyone. I assume commit privileges are not just given to everyone.

Anyhow, in forage.cpp (rev 2103), on line #111 the variable chancepool is repeatedly overwritten inside the loop. (I assume this was intended to be a += instead of =)

Next, on line #132 we have rindex being assigned a random value. (Why am I thinking of string operations now...) So far, so good. But below, it is compared against each of the chance values (from the forage table). I suspect that this loop is missing something like "rindex -= chance[i]"

I'm not 100% sure that this is a fair distribution of probability, but it looks like it would be better than what is in there.

Derision 02-22-2012 02:44 PM

Quote:

Originally Posted by Harcourt (Post 207472)
Anyhow, in forage.cpp (rev 2103), on line #111 the variable chancepool is repeatedly overwritten inside the loop. (I assume this was intended to be a += instead of =)

If you look a little further up at line 109, you will see this:
Code:

    chance[index] = atoi(row[1])+chancepool;
So if there are three possible forage items, the first with chance 5, the next with chance 10, and the last with chance 50, we get:
Code:

  chance[0] = 5
  chance[1] = 15
  chance[2] = 65

On line 132, a random number between 1 and 65 is generated. Then, in the loop, if the random number is <=5, the first item is chosen, if it is > 5 and <=15, the second item is chosen, else the last item is chosen.

Harcourt 02-22-2012 03:03 PM

Thanks for clearing that up. See, it is a good idea to ask about these things.

The only problem I have with that then is that items at the beginning of the forage table would seem to have a higher probability of dropping. I think that ideally one would want to start at a random spot in the table and wrap around.

Edit: On second thought this looks OK.

Derision 02-22-2012 03:19 PM

I don't follow why items at the beginning of the table would have a higher probability of dropping ?

If we assume the random number is truly random, then the probability of an item is in proportion to it's chance value versus the sum of the chance values of all the possible items, i.e.

Item 0 has a 5/65 chance, item 1 has a 10/65 chance, and item 2 has a 50/65 chance.

The position in the table should have no bearing on it's chance to be selected, unless there is something I am missing. I didn't write this code BTW, this is just my conclusion by looking at it.

EDIT: I took too long writing this before you edited your post :)

Harcourt 02-22-2012 04:40 PM

That is a good explanation. I needed to go through it myself before I edited it. This is one of the things I look for in my own code, so I tend to question it in new (to me) code.

Harcourt 02-22-2012 05:43 PM

Postscript: this entire question is moot.

Client::Forage only calls uses the database for 25% of the drops, the rest of the time using stock items. This looks like temporary code to get some sort of foraging behavior, and is definitely not like live. For example Mushrooms (14905) are not foraged in EK or Crescent Reach.

For my own use, I think I'll use the database for all forage drops. A couple of hours and a G15 keyboard gave me the stats from live for a zone. This may be more than the rest of community wants to do, but I only care about a few zones atm.

PS: it may be the case that I have yet again misread the code, but a breakpoint verified foraging without checking the db tables.

Anyhow, just a heads up to anyone OCD about foraging

dagulus2 04-19-2015 08:13 AM

Just been looking at this today. Is there any easy way to remove the Mushrooms from the list of 'stock' forage drops? Where does it pull those items from?

Kingly_Krab 04-19-2015 11:36 AM

Check forage.cpp, the defaults are stored here:
Code:

uint32 common_food_ids[MAX_COMMON_FOOD_IDS] = {
    13046, // Fruit
    13045, // Berries
    13419, // Vegetables
    13048, // Rabbit Meat
    13047, // Roots
    13044, // Pod Of Water
    14905, // mushroom
    13106 // Fishing Grubs
};

So you can remove that and remove this:
Code:

if(foragedfood == 0) {
    uint8 index = 0;
    index = zone->random.Int(0, MAX_COMMON_FOOD_IDS-1);
    foragedfood = common_food_ids[index];
}



All times are GMT -4. The time now is 07:00 PM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.