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 02-22-2012, 02:27 PM
Harcourt
Sarnak
 
Join Date: Jul 2011
Posts: 33
Default 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.
Reply With Quote
  #2  
Old 02-22-2012, 02:44 PM
Derision
Developer
 
Join Date: Feb 2004
Location: UK
Posts: 1,540
Default

Quote:
Originally Posted by Harcourt View Post
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.

Last edited by Derision; 02-22-2012 at 02:49 PM.. Reason: I meant line 109 :)
Reply With Quote
  #3  
Old 02-22-2012, 03:03 PM
Harcourt
Sarnak
 
Join Date: Jul 2011
Posts: 33
Default

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.
Reply With Quote
  #4  
Old 02-22-2012, 03:19 PM
Derision
Developer
 
Join Date: Feb 2004
Location: UK
Posts: 1,540
Default

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
Reply With Quote
  #5  
Old 02-22-2012, 04:40 PM
Harcourt
Sarnak
 
Join Date: Jul 2011
Posts: 33
Default

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.
Reply With Quote
  #6  
Old 02-22-2012, 05:43 PM
Harcourt
Sarnak
 
Join Date: Jul 2011
Posts: 33
Default

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
Reply With Quote
  #7  
Old 04-19-2015, 08:13 AM
dagulus2
Hill Giant
 
Join Date: Feb 2013
Posts: 220
Default

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?
Reply With Quote
  #8  
Old 04-19-2015, 11:36 AM
Kingly_Krab
Administrator
 
Join Date: May 2013
Location: United States
Posts: 1,589
Default

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];
}
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 03:18 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