function BotBuild($obj_id) { global $BotID, $BotNow, $GlobalUni; $user = LoadUser($BotID); $aktplanet = GetPlanet($user['aktplanet']); $level = $aktplanet['b' . $obj_id] + 1; $text = CanBuild($user, $aktplanet, $obj_id, $level, 0); if ($text === '') { $speed = $GlobalUni['speed']; $duration = floor(BuildDuration($obj_id, $level, $aktplanet['b14'], $aktplanet['b15'], $speed)); BuildEnque($user['aktplanet'], $obj_id, 0, $BotNow); UpdatePlanetActivity($user['aktplanet'], $BotNow); return $duration; } else { return 0; } }
echo " " . loca("NAME_{$gid}") . " </a>\n"; echo " </th> \n"; foreach ($plist as $j => $planet) { // Загрузить очередь построек планеты. $bqueue = array(); $result = GetBuildQueue($planet['planet_id']); while ($row = dbarray($result)) { $bqueue[] = $row; } echo " <th width=\"75\" >\n"; if ($planet["b{$gid}"] > 0) { echo " <a style=\"cursor:pointer\" \n"; echo " onClick=\"if(t==0){t=setTimeout('document.location.href=\\'index.php?page=b_building&session={$session}&planet=" . $planet['planet_id'] . "&cp=" . $planet['planet_id'] . "\\';t=0;',500);}\" \n"; echo " onDblClick=\"clearTimeout(t);document.location.href='index.php?page=imperium&session={$session}&planettype={$planettype}&no_header=1&modus=add&planet=" . $planet['planet_id'] . "&techid={$gid}';t=0;\"\n"; echo " title=\"Щёлкнуть 1 раз: обзор, постройки, 2 раза: строить\"> \n"; if (CanBuild($GlobalUser, $planet, $gid, $planet["b{$gid}"] + 1, 0) === "") { echo " <font color=\"lime\">\n"; } else { echo " <font color=\"red\">\n"; } echo " " . $planet["b{$gid}"] . " </font> \n\n"; echo " </font>\n"; echo " </a> \n"; // Build queue. foreach ($bqueue as $i => $row) { if ($row['tech_id'] != $gid || $row['planet_id'] != $planet['planet_id']) { continue; } if ($i == 0) { echo " <a href=\"index.php?page=imperium&session={$session}&planettype={$planettype}&no_header=1&planet=" . $planet['planet_id'] . "&modus=remove&listid=" . $row['list_id'] . "\">\n"; echo " <font color=\"magenta\">" . $row['level'] . "</font>\n";
function BuildEnque($planet_id, $id, $destroy, $now = 0) { global $db_prefix, $GlobalUni; $speed = $GlobalUni['speed']; if ($GlobalUni['freeze']) { return; } $planet = GetPlanet($planet_id); $user = LoadUser($planet['owner_id']); $prem = PremiumStatus($user); if ($prem['commander']) { $maxcnt = 5; } else { $maxcnt = 1; } if ($now == 0) { $now = time(); } // Запишем действие пользователя, даже если он делает что-то не так if ($destroy) { UserLog($planet['owner_id'], "BUILD", "Снос " . loca("NAME_{$id}") . " " . ($planet['b' . $id] - 1) . " на планете {$planet_id}"); } else { UserLog($planet['owner_id'], "BUILD", "Постройка " . loca("NAME_{$id}") . " " . ($planet['b' . $id] + 1) . " на планете {$planet_id}"); } $result = GetBuildQueue($planet_id); $cnt = dbrows($result); if ($cnt >= $maxcnt) { return; } // Очередь построек заполнена // Загрузить очередь. Отсортирована по порядку list_id $queue = array(); for ($i = 0; $i < $cnt; $i++) { $queue[$i] = dbarray($result); } // Нельзя в одну секунду добавлять в очередь несколько построек. for ($i = 0; $i < $cnt; $i++) { if ($queue[$i]['start'] == $now) { return; } } // Определить добавляемый уровень и порядок постройки (list_id). $nowlevel = $planet['b' . $id]; $list_id = 0; for ($i = 0; $i < $cnt; $i++) { if ($queue[$i]['tech_id'] == $id) { $nowlevel = $queue[$i]['level']; } if ($queue[$i]['list_id'] > $list_id) { $list_id = $queue[$i]['list_id']; } } $list_id++; if ($destroy) { $lvl = $nowlevel - 1; } else { $lvl = $nowlevel + 1; } if ($lvl < 0) { return; } // Невозможно построить/снести отрицательный уровень if ($list_id == 1) { $text = CanBuild($user, $planet, $id, $lvl, $destroy); } else { $text = ''; } if ($text === '') { // Списать ресурсы для самой первой постройки if ($list_id == 1) { $res = BuildPrice($id, $lvl); $m = $res['m']; $k = $res['k']; $d = $res['d']; $e = $res['e']; AdjustResources($m, $k, $d, $planet_id, '-'); } if ($destroy) { $BuildEvent = "Demolish"; } else { $BuildEvent = "Build"; } $duration = floor(BuildDuration($id, $lvl, $planet['b14'], $planet['b15'], $speed)); $row = array('', $user['player_id'], $planet_id, $list_id, $id, $lvl, $destroy, $now, $now + $duration); $sub_id = AddDBRow($row, "buildqueue"); if ($list_id == 1) { AddQueue($user['player_id'], $BuildEvent, $sub_id, $id, $lvl, $now, $duration, 20); } } }