ogamespec / ogame-opensource

This is revived OGame v 0.84 with old design.
Creative Commons Zero v1.0 Universal
81 stars 38 forks source link

Fixed ProdResources by Quaua #115

Closed ogamespec closed 4 months ago

ogamespec commented 4 months ago

ProdResources is the primary method that calculates the production of a planet between the from and to time points. Quaua found an error there and sent a corrected version of ProdResources.

ProdResources - это основной метод, который производит вычисление выработки планеты между моментами времени from и to. Quaua нашёл там ошибку и прислал исправленную версию ProdResources.

function ProdResources(&$planet, $time_from, $time_to) {
    global $db_prefix, $GlobalUni;

    // Verifica se il pianeta è valido
    if (!( $planet['type'] > 0 && $planet['type'] < 10000)) {
        return $planet; // Non è un pianeta valido, restituisco il pianeta senza fare alcuna operazione
    }

    // Carica l'utente proprietario del pianeta
    $user = LoadUser($planet['owner_id']);

    // Verifica se l'utente è un account tecnico "space"
    if ($user['player_id'] == 99999) {
        return $planet; // Non eseguo alcuna operazione se l'utente è un account tecnico "space"
    }

    // Calcola la differenza di tempo
    $tempo = time();
    $time_diff = $tempo - $planet['lastpeek'];

    // Carica le impostazioni globali dell'universo
    $unitab = $GlobalUni;
    $speed = $unitab['speed'];

    // Determina il fattore geologico in base allo status premium dell'utente
    $prem = PremiumStatus($user);
    $g_factor = ($prem['geologist']) ? 1.1 : 1.0; // Fattore geologico

    // Calcola la produzione oraria di metallo, cristalli e deuterio
    $m_hourly = prod_metal($planet['b1'], $planet['mprod']) * $planet['factor'] * $speed + ($g_factor + 20 * $speed);
    $c_hourly = prod_crys($planet['b2'], $planet['kprod']) * $planet['factor'] * $speed + ($g_factor + 10 * $speed);
    $d_hourly = prod_deut($planet['b3'], $planet['temp']+40, $planet['dprod']) * $planet['factor'] * $speed * $g_factor;
    $d_hourly -= cons_fusion($planet['b12'], $planet['fprod']) * $speed;

    // Aggiorna le risorse in base al tempo trascorso
    $planet['m'] += ($m_hourly * $time_diff) / 3600;
    $planet['k'] += ($c_hourly * $time_diff) / 3600;
    $planet['d'] += ($d_hourly * $time_diff) / 3600;

    // Limita le risorse massime
    $planet['m'] = min($planet['m'], $planet['mmax']);
    $planet['k'] = min($planet['k'], $planet['kmax']);
    $planet['d'] = min($planet['d'], $planet['dmax']);

    // Aggiorna le risorse nel database in modo sicuro
    $planet_id = intval($planet['planet_id']);
    $m = intval($planet['m']);
    $k = intval($planet['k']);
    $d = intval($planet['d']);
    $time_to = intval($time_to);

    $query = "UPDATE ".$db_prefix."planets SET m = $m, k = $k, d = $d, lastpeek = $tempo WHERE planet_id = $planet_id";
    $result = dbquery($query);

    return $planet;
}
ogamespec commented 4 months ago

Посмотрел код Quaua, он сломан. Во первых тут / Looked at Quaua's code, it's broken. First of all, here::

($g_factor + 20 * $speed)

Коэффициент Геолога просто прибавляется к естественной выработке планеты / The Geologist factor is simply added to the planet's natural production.

Во вторых тут / Second here::

    // Limita le risorse massime
    $planet['m'] = min($planet['m'], $planet['mmax']);

Если на планете было ресурсов больше чем в хранилищах, то этот код просто отрежет лишние ресурсы / If there were more resources on the planet than in the storages, this code will simply cut off the extra resources.

ogamespec commented 4 months ago

В третьих тут / Third here: $tempo = time();

Теряется возможность вычислять отложенный прирост ресов (не привязанный к реальному времени).

The ability to calculate deferred res growth (not tied to real time) is lost.

ogamespec commented 4 months ago

Закрываю эту Issue, т.к. нет ничего определенного по ней. Нужны конкретные цифры (постройки на планете, время между обновлениями), скрины некорректной выработки, хотя бы что-то..

I am closing this Issue, as there is nothing definite about it. We need specific figures (buildings on the planet, time between updates), screens of incorrect output, at least something.