function auto_ground() { if (rand(0, 9) == 0 || defined('DEBUG') && DEBUG) { fix_ground(); } $nlocations = fetch_value("select count(*) from phaos_locations", __FILE__, __LINE__, __FUNCTION__); //CAVEAT: this includes items stored in shops $nground = fetch_value("select count(DISTINCT(location)) from phaos_ground where number>0 and location>'0'", __FILE__, __LINE__, __FUNCTION__); $proportion = 25; $missingitems = (int) ($nlocations / $proportion) - $nground; defined('DEBUG') and DEBUG and $GLOBALS['debugmsgs'][] = "Ground: missing {$missingitems} items ({$nground}/{$nlocations})."; if ($missingitems > 0) { $add = $missingitems < 12 ? $missingitems : 12; while ($add-- > 0) { $location = random_location("item_drop"); $item_cluster_limit = 4; $items_here = fetch_items_for_location($location); if (count($items_here) >= $item_cluster_limit) { continue; } $minvalue = 1; $maxvalue = powrand(2.75, 0.83, 5) * powrand(2.75, 0.5, 8); $item = random_item($minvalue, $maxvalue); if ($item) { item_drop($location, $item); } } } }
$tries = 40; //FIXME: replace the completely random selection of refill candidates by choosing only those with a deficit while ($restock > 0 && $tries-- > 0) { $shop_refill = fetch_first("SELECT * FROM phaos_shop_refill WHERE shop_id='{$shop_id}' order by rand()*item_count_min DESC LIMIT 1", __FILE__, __LINE__); if (!$shop_refill) { break; //stop loop } if (@$inventory[$shop_refill['item_type']] >= $shop_refill['item_count_min']) { continue; //next try } defined('DEBUG') and DEBUG and $GLOBALS['debugmsgs'][] = "passed({$shop_refill['item_type']}):(" . @$inventory[$shop_refill['item_type']] . ">=" . $shop_refill['item_count_min'] . ")"; $minvalue = $shop_refill['item_value_min']; $maxvalue = (int) ($minvalue * $shop_refill['item_value_growth'] * powrand($shop_refill['item_value_growth'], $shop_refill['item_value_growth_probability'], 23)); $item = random_item($minvalue, $maxvalue, $shop_refill['item_type'], $shop_refill['item_name_like']); defined('DEBUG') and DEBUG and $GLOBALS['debugmsgs'][] = "{$item['type']}({$item['id']}) from between values ({$minvalue},{$maxvalue})"; if ($item) { item_drop($shop_basics['item_location_id'], $item); @($inventory[$item['type']] += $item['number']); $restock--; } } } //buying section do_buy($character, $shop_basics); if ($sorrys) { $sorry = $lang_shop["sorry"]; } ?>