croppers // Fixes: // - Uses WORLD_MIN/WORLD_MAX from config if present (works for 0..N or -W..+W) // - If not defined in config, auto-detects bounds from DB // - Larger window cap + extra expansion // - Global fallback so it never returns only a few rows include_once("GameEngine/Generator.php"); $start_timer = $generator->pageLoadTimeStart(); include_once("GameEngine/config.php"); use App\Utils\AccessLogger; include_once("GameEngine/Village.php"); AccessLogger::logRequest(); if ($session->goldclub == 0) { header("Location: plus.php?id=3"); exit; } // Tables $TBP = defined('TB_PREFIX') ? TB_PREFIX : 's1_'; $CROP_TABLE = $TBP . 'croppers'; $VDATA = $TBP . 'vdata'; $USERS = $TBP . 'users'; $RENDER_MAX = 100; // ---------- POST -> GET ---------- if (!empty($_POST['type'])) { $x = isset($_POST['x']) ? preg_replace("/[^0-9-]/", "", $_POST['x']) : '0'; $y = isset($_POST['y']) ? preg_replace("/[^0-9-]/", "", $_POST['y']) : '0'; $b = isset($_POST['bonus_getreide']) ? preg_replace("/[^0-9a-zA-Z]/", "", $_POST['bonus_getreide']) : 'all'; if ($_POST['type'] == 15) header("Location: " . $_SERVER['PHP_SELF'] . "?s=1&x=$x&y=$y&b=$b"); elseif ($_POST['type'] == 9) header("Location: " . $_SERVER['PHP_SELF'] . "?s=2&x=$x&y=$y&b=$b"); else header("Location: " . $_SERVER['PHP_SELF'] . "?s=3&x=$x&y=$y&b=$b"); exit; } // ---------- Helpers ---------- /** * Wrap-aware BETWEEN that works for arbitrary [min..max] (e.g. 0..49 or -300..300) */ function betweenWrapFlexible($col, $center, $R, $min, $max) { $span = $max - $min + 1; $lo = $center - $R; $hi = $center + $R; // normalize to [min,max] $norm = function($v) use ($min,$span) { $n = ($v - $min) % $span; if ($n < 0) $n += $span; return $min + $n; }; $loN = $norm($lo); $hiN = $norm($hi); if ($loN <= $hiN) return "($col BETWEEN $loN AND $hiN)"; return "(($col BETWEEN $min AND $hiN) OR ($col BETWEEN $loN AND $max))"; } // ---------- Coordinates ---------- if (!empty($_GET['x']) && !empty($_GET['y']) && is_numeric($_GET['x']) && is_numeric($_GET['y'])) { $coor2 = ['x'=>(int)$_GET['x'], 'y'=>(int)$_GET['y']]; } else { $wref2 = $village->wid; $coor2 = $database->getCoor($wref2); } $startX = isset($coor2['x']) ? (int)$coor2['x'] : 0; $startY = isset($coor2['y']) ? (int)$coor2['y'] : 0; // ---------- UI selections ---------- // UI selections $selBonus = isset($_GET['b']) ? $_GET['b'] : 'all'; $selType = (!empty($_GET['s'])) ? (int)$_GET['s'] : 0; $minBonus = ($selBonus !== 'all') ? (int)$selBonus : null; $fieldWhere = ($selType === 1) ? "6" : (($selType === 2) ? "1" : "1,6"); $bonusCond = is_null($minBonus) ? "1" : ("c.best_oasis_bonus >= ".(int)$minBonus); // Only run the queries after the user pressed Search (i.e., we have s, x, y in the URL) $rows = []; $out = []; $searchTriggered = isset($_GET['s']) && isset($_GET['x']) && isset($_GET['y']); if ($searchTriggered) { // --- Windowed fetch with bigger cap and one more expansion --- $R = 40; // start radius $tries= 0; $CAP = 2000; // increased cap per window do { $tries++; $condX = betweenWrapFlexible('c.x', $startX, $R, $MIN_X, $MAX_X); $condY = betweenWrapFlexible('c.y', $startY, $R, $MIN_Y, $MAX_Y); $sql = "SELECT c.wref, c.x, c.y, c.fieldtype, c.best_oasis_bonus FROM `$CROP_TABLE` c WHERE c.fieldtype IN ($fieldWhere) AND $bonusCond AND $condX AND $condY LIMIT $CAP"; $res = mysqli_query($database->dblink, $sql); $rows = []; if ($res) { while ($r = mysqli_fetch_assoc($res)) { $r['__dist'] = $database->getDistance($startX, $startY, (int)$r['x'], (int)$r['y']); $rows[] = $r; } } if (count($rows) < $RENDER_MAX && $tries < 4) { // 40 -> 80 -> 160 -> 320 $R *= 2; } else { break; } } while (true); // --- Global fallback if window was too sparse --- if (count($rows) < $RENDER_MAX) { $sql = "SELECT c.wref, c.x, c.y, c.fieldtype, c.best_oasis_bonus FROM `$CROP_TABLE` c WHERE c.fieldtype IN ($fieldWhere) AND $bonusCond LIMIT 5000"; $res = mysqli_query($database->dblink, $sql); $rows = []; if ($res) { while ($r = mysqli_fetch_assoc($res)) { $r['__dist'] = $database->getDistance($startX, $startY, (int)$r['x'], (int)$r['y']); $rows[] = $r; } } } // Sort by distance and keep first RENDER_MAX usort($rows, function($a,$b){ return $a['__dist'] <=> $b['__dist']; }); $out = array_slice($rows, 0, $RENDER_MAX); } // Live owner info for visible rows $wrefs = array_map(function($r){ return (int)$r['wref']; }, $out); $owners = []; if ($wrefs) { $in = implode(',', array_unique($wrefs)); $sql = "SELECT v.wref, v.name AS vname, v.owner AS owner_id, u.username FROM `$VDATA` v JOIN `$USERS` u ON u.id = v.owner WHERE v.wref IN ($in)"; $res = mysqli_query($database->dblink, $sql); if ($res) while ($row = mysqli_fetch_assoc($res)) { $owners[(int)$row['wref']] = $row; } } ?> <?php echo SERVER_NAME ?> - Crop Finder gpack == null || GP_ENABLE == false) { echo " "; echo " "; } else { echo " "; echo " "; } ?>

Crop Finder



Cropper Type: /> 15 crop /> 9 crop /> both
Oasis Crop Bonus (min):
Start position: x: y:
"; echo "Debug: bounds=[$MIN_X..$MAX_X]x[$MIN_Y..$MAX_Y], R=$R, tries=$tries, fetched=".count($rows).", render=".count($out).", type={$selType}, minBonus=".($minBonus??'all'); echo "
"; } ?> "; } else { foreach ($out as $row) { $field = ($row['fieldtype'] == 1) ? '9c' : '15c'; $x=(int)$row['x']; $y=(int)$row['y']; $id=(int)$row['wref']; $ov = $owners[$id] ?? null; $isOcc = $ov !== null; echo ""; if (!$isOcc) { echo ""; echo ""; echo ""; } else { $vname = htmlspecialchars($ov['vname'] ?? '', ENT_QUOTES, 'UTF-8'); $owner = (int)($ov['owner_id'] ?? 0); $uname = htmlspecialchars($ov['username'] ?? '', ENT_QUOTES, 'UTF-8'); echo ""; echo ""; echo ""; } echo ""; echo ""; echo ""; } } ?>
Crop Finder -
Type Coordinates Owner Occupied Distance Oasis
No crops fields found for the selected filters.
$fieldgetMapCheck($id)."\">".ABANDVALLEY." ($x|$y)-".UNOCCUPIED."getMapCheck($id)."\">".$vname." ($x|$y)".$uname."".OCCUPIED."
".(int)$row['__dist']."
+".(int)$row['best_oasis_bonus']."%







"; include("Templates/links.tpl"); } ?>
pageLoadTimeEnd()-$start_timer)*1000); ?> ms