EOSERV Bug Tracker > Bug #331: Map Drop Item Optimization

Bug #331: Map Drop Item Optimization

Map Drop Item Optimization
ID #331
Submitter Apollo
Product EOSERV
Severity Feature Request
Status OPEN, NEW
Submitted 18th May 2015
Updated 18th May 2015
Apollo Submitter 8 years, 51 weeks ago

Cycle out drops would in some cases would work better than simply destroying map items at given intervals. Using the max map item config to limit the number of on map drop items could benefit from simply despawning the oldest item when a new one is dropped if the cap is met. Also, if time despawning is still desired it should be given a minimum count of items to be met before destroying any items. If a map has only 2-3 items it is virtually unnecessary to despawn anything, or maybe pair it with a max drop time that would eventually destroy items once they become old enough for the sake of cleaning up a map.

Comments

insomniac 8 years, 44 weeks ago

I was looking over this topic and highly agree so I wrote a function it might save a little time if this feature gets added to the official build of EOSERV.

bool paircompare(const std::pair<int, double>& first_element, const std::pair<int, double>& second_element)

{

return first_element.second < second_element.second;

}

void world_despawn_items(void *world_void)

{

World *world = static_cast<World *>(world_void);

std::vector<std::pair<int,double>> old_items;

int min_item_amount = static_cast<int>(world->config["MapItemMinAmount"]);

int max_item_amount = static_cast<int>(world->config["MaxMap"]);

UTIL_PTR_VECTOR_FOREACH(world->maps, Map, map)

{

old_items.clear();//clears the vector

UTIL_PTR_LIST_FOREACH(map->items, Map_Item, item)

{

if (item->unprotecttime < (Timer::GetTime() - static_cast<double>(world->config["ItemDespawnRate"])))//item is not owned??

old_items.push_back(std::make_pair(item->uid,item->unprotecttime));

}

std::sort(old_items.begin(), old_items.end(), paircompare);//sorts the vector by the oldest timers

restart_loop:

UTIL_PTR_LIST_FOREACH(map->items, Map_Item, item)

{

if(old_items.size() <= min_item_amount)break;//compare size before executing the rest of the code

for (std::size_t i = 0; i < old_items.size(); ++i)

{

if (item->uid == old_items[i].first)//check uid

{

if(old_items.size() > max_item_amount)//make sure map item size is more than max

{

map->DelItem(item->uid, 0);

old_items.erase(old_items.begin() + i );

goto restart_loop;//recheck map item size and execute code again if needed

}

}

}

}

}

}

insomniac 8 years, 44 weeks ago

I added a boolean check in case people still want to clear all items regardless

bool clear_all = world->config["MapItemClearAll"];

restart_loop:

UTIL_PTR_LIST_FOREACH(map->items, Map_Item, item)

{

if(old_items.size() <= min_item_amount && !clear_all)break;//compare size before executing the rest of the code

for (std::size_t i = 0; i < old_items.size(); ++i)

{

if (item->uid == old_items[i].first)//check uid

{

if(old_items.size() > max_item_amount || clear_all)//make sure map item size is more than max or should clear all

{

map->DelItem(item->uid, 0);

old_items.erase(old_items.begin() + i );

goto restart_loop;//recheck map item size and execute code again if needed

}

}

}

}

Add Comment

Please don't post unless you have something relevant to the bug to say.
Do not comment to say "thanks" or "fix this please".

Please log in to add comments. EOSERV Bug Tracker > Bug #331: Map Drop Item Optimization