ugml / php-client

ugamela is an open-source clone of the popular browsergame ogame.
https://ugamela.org
GNU Affero General Public License v3.0
14 stars 5 forks source link

Resources: Scale production down properly when energy consumption is too high #44

Closed Phoscur closed 4 years ago

Phoscur commented 6 years ago

When energy consumption is too high, production should scale down not just cut in a half. Instead calculate the quotient.

https://github.com/mamen/ugamela/blob/acb7ae51c04cbebdd65d321633f4f71c910e4ba1/core/classes/units/planet.php#L187

But this might be only the tip of the iceberg of inaccuracies of the resource calculation.

mamen commented 6 years ago

I know that the whole update-process of entities is not very well implemented. Currently, I just hacked the basics together to allow some testing and implementation of other mechanics. Enteties are currently only updated, if the client is online. Thus, if a building is finished, it won't use energy until the user is online and the planet is updated.

In the future, all of this will be moved to the eventhandler, which does not care, if the user is online or not and thus update the entities in (almost) real-time.

Phoscur commented 6 years ago

Thus, if a building is finished, it won't use energy until the user is online and the planet is updated. This is oversimplified expecting the user to be online triggering update events to recalculate resource production.

Buildings and Resources are an entwined subject since they use and produce eachother. But a proper algorithm can calculate the resources of any given point in time, given stocks and building queue.

10 years ago, I reimplemented resource calculation a third time in JavaScript (after I had done it in PHP and in MySQL procedures), going for maximum abstraction with Value Objects [from my point of view today, this is overdoing it :P ] It doesn't include the building queue, but it would fit well around this calculation method at line 50 - have a look at the do-while-loop Additionally, just loop through the building queue and each time recalculate all resource processes.

There can also be limited processes that trigger recalculation (fusion plant).

On a sidenote, this model would also support a more realistic building and packaging process of resources - not spontanious, but rather consuming resources.

ghost commented 4 years ago

You can try to implement this :


$parse['production_level'] = 100;

if (
    $CurrentPlanet['energy_max'] == 0 
    && $CurrentPlanet['energy_used'] > 0
) {
    $post_porcent = 0;
} elseif (
    $CurrentPlanet['energy_max'] >  0 
    && ($CurrentPlanet['energy_used'] + $CurrentPlanet['energy_max']) < 0 
) {
    $post_porcent = floor(($CurrentPlanet['energy_max']) / $CurrentPlanet['energy_used'] * 100);
} else {
    $post_porcent = 100;
}

if (
    $post_porcent > 100
) {
    $post_porcent = 100;
}
Phoscur commented 4 years ago

Thanks for your code @Paroxyste, but this ignores all the aforementioned issues.

The php-client is discontinued anyways.