Exemple #1
0
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;
    }
}
Exemple #2
0
                    echo "<tr><td class=c align=center><a href=\"index.php?page=b_building&session={$session}&techid={$gid}&modus=destroy&planet=" . $aktplanet['planet_id'] . "\">Снести: " . loca("NAME_{$gid}") . " Level " . $aktplanet['b' . $gid] . " уничтожить?</a></td></tr>\n";
                } else {
                    echo "<tr><td class=c align=center>об оборонительных сооружениях</a></td></tr>";
                }
                $res = BuildPrice($gid, $aktplanet['b' . $gid] - 1);
                $m = $res['m'];
                $k = $res['k'];
                $d = $res['d'];
                $e = $res['e'];
                echo "<br><tr><th>Необходимо ";
                if ($m) {
                    echo "металла:<b>" . nicenum($m) . "</b> ";
                }
                if ($k) {
                    echo "кристалла:<b>" . nicenum($k) . "</b> ";
                }
                if ($d) {
                    echo "дейтерия:<b>" . nicenum($d) . "</b> ";
                }
                $t = BuildDuration($gid, $aktplanet['b' . $gid] - 1, $aktplanet['b14'], $aktplanet['b15'], $speed);
                echo "<tr><th><br>Продолжительность сноса:  " . BuildDurationFormat($t) . "<br></th></tr></table>\n";
            }
        }
    }
}
echo "<br><br><br><br>\n";
echo "</center>\n";
echo "</div>\n";
echo "<!-- END CONTENT AREA -->\n";
PageFooter();
ob_end_flush();
Exemple #3
0
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);
        }
    }
}
 $d = $res['d'];
 $e = $res['e'];
 echo "<br>Стоимость:";
 if ($m) {
     echo " Металл: <b>" . nicenum($m) . "</b>";
 }
 if ($k) {
     echo " Кристалл: <b>" . nicenum($k) . "</b>";
 }
 if ($d) {
     echo " Дейтерий: <b>" . nicenum($d) . "</b>";
 }
 if ($e) {
     echo " Энергия: <b>" . nicenum($e) . "</b>";
 }
 $t = BuildDuration($id, $lvl + 1, $aktplanet['b14'], $aktplanet['b15'], $speed);
 echo "<br>Длительность: " . BuildDurationFormat($t) . "<br>";
 if ($prem['commander']) {
     if ($cnt) {
         if ($cnt < 5) {
             echo "<td class=k><a href=\"index.php?page=b_building&session={$session}&modus=add&techid={$id}&planet=" . $aktplanet['planet_id'] . "\">В очередь на строительство</a></td>";
         } else {
             echo "<td class=k>";
         }
     } else {
         if ($aktplanet['fields'] >= $aktplanet['maxfields']) {
             echo "<td class=l><font color=#FF0000>Нет места! </font>";
         } else {
             if ($id == 31 && $reslab_operating) {
                 echo "<td class=l><font  color=#FF0000>В процессе</font> <br>";
             } else {