Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change people growth to people/hour #216

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions db/migrations/0028_20200614-fix_planet_prod_people.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE planets
MODIFY planet_prod_people INT(10) NOT NULL DEFAULT 0;
132 changes: 71 additions & 61 deletions eventhandler/src/planet/PlanetEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@

namespace planet
{
PlanetEntity::PlanetEntity(int entityId) {

this->entityId = entityId;

this->store.resize(6);
this->cnt.resize(8);
this->ressource.resize(7);
this->bunker.resize(5);

this->loadData();
PlanetEntity::PlanetEntity(int entityId)
:entityId(entityId),
store(6),
cnt(8),
ressource(6),
bunker(5)
{
this->loadData();
}

PlanetEntity::~PlanetEntity() {

}
PlanetEntity::~PlanetEntity() {}

void PlanetEntity::loadData() {
My &my = My::instance();
Expand All @@ -29,7 +25,7 @@ namespace planet
<< " users.user_race_id, "
<< " users.user_specialist_id, "
<< " users.user_specialist_time, "
<< " users.boost_bonus_production, "
<< " users.boost_bonus_production, "
<< " users.user_hmode_to, "
<< " stars.type_id "
<< "FROM "
Expand Down Expand Up @@ -68,16 +64,15 @@ namespace planet
this->solType = (int)pRow["type_id"];
this->planetType = (int)pRow["planet_type_id"];
this->speicalistId = (int)pRow["user_specialist_time"] < time(0) ? 0 : (int)pRow["user_specialist_id"];
this->boostBonusProduction = (float)pRow["boost_bonus_production"];
this->boostBonusProduction = (float)pRow["boost_bonus_production"];

this->solarPowerBonus = etoa::getSolarPowerBonus((int)pRow["planet_temp_from"], (int)pRow["planet_temp_to"]);
this->solarFuelBonus = 1 - (etoa::getSolarFuelBonus((int)pRow["planet_temp_from"], (int)pRow["planet_temp_to"]));

if ((int)pRow["planet_last_updated"]==0)
this->t=5;
else
this->t = time(0) - (int)pRow["planet_last_updated"];


if ((int)pRow["planet_last_updated"]==0)
this->t=5;
else
this->t = time(0) - (int)pRow["planet_last_updated"];

this->isMain = (bool)pRow["planet_user_main"];

Expand All @@ -87,7 +82,6 @@ namespace planet
this->ressource[3] = (double)pRow["planet_res_fuel"];
this->ressource[4] = (double)pRow["planet_res_food"];
this->ressource[5] = (double)pRow["planet_people"];
this->ressource[6] = 0;

this->store[0] = (double)pRow["planet_store_metal"];
this->store[1] = (double)pRow["planet_store_crystal"];
Expand Down Expand Up @@ -124,53 +118,69 @@ namespace planet

}

void PlanetEntity::updateResources() {
Config &config = Config::instance();
void PlanetEntity::updateResources()
{
Config &config = Config::instance();

if (this->isUmod) {
for (int i = 0; i < 6; i++) {
if (this->isUmod)
{
for (size_t i = 0; i < ressource.size(); i++)
{
this->ressource[i] = 0;
}
return;
}

for (int i = 0; i < 5; i++) {
if (this->store[i] > (this->ressource[i]+(this->cnt[i]/3600)*this->t))
this->ressource[i] = (this->cnt[i]/3600)*this->t;
for (int i = 0; i < 5; i++)
{
if (this->store[i] > (this->ressource[i] + (this->cnt[i] / 3600)*this->t))
{
this->ressource[i] = (this->cnt[i] / 3600)*this->t;
}
else if (this->store[i] > this->ressource[i])
{
this->ressource[i] = this->store[i] - this->ressource[i];
}
else
{
this->ressource[i] = 0;
}
}



// logistic population growth

if (this->store[5] < config.nget("user_start_people", 1))
this->store[5] = config.nget("user_start_people", 1);


this->birthRate = ((double)config.nget("people_multiply", 0) + this->planet_->getTypePopulation() + this->race_->getRacePopulation() + this->sol_->getTypePopulation() + this->specialist_->getSpecialistPopulation() - 4)* (1-(this->ressource[5] / (this->store[5]+1)))/24;

this->ressource[6] = ((this->ressource[5] * this->birthRate) / 3600);

// logistic population growth
if (this->store[5] < config.nget("user_start_people", 1))
{
this->store[5] = config.nget("user_start_people", 1);
}

this->birthRate = ((double)config.nget("people_multiply", 0)
+ this->planet_->getTypePopulation()
+ this->race_->getRacePopulation()
+ this->sol_->getTypePopulation()
+ this->specialist_->getSpecialistPopulation() - 4)
* (1 - (this->ressource[5] / (this->store[5] + 1))) / 24;

this->cnt[5] = this->ressource[5] * this->birthRate;


if (!this->ressource[5])
{
this->ressource[5] = 1;

if (this->store[5] >= (this->ressource[5] + this->ressource[6]*this->t) && this->birthRate < 0)
this->ressource[5]=(this->store[5]-this->ressource[5]);


else if (this->store[5] < (this->ressource[5] + this->ressource[6]*this->t) && this->birthRate > 0)
this->ressource[5]=(this->store[5]-this->ressource[5]);

else
this->ressource[5] = (this->ressource[6]*this->t);

}

if ((this->store[5] >= (this->ressource[5] + (this->cnt[5] / 3600) * this->t))
&& (this->birthRate < 0))
{
this->ressource[5] = (this->store[5] - this->ressource[5]);
}
else if ((this->store[5] < (this->ressource[5] + (this->cnt[5] / 3600) * this->t))
&& (this->birthRate > 0))
{
this->ressource[5] = (this->store[5] - this->ressource[5]);
}
else
{
this->ressource[5] = (this->cnt[5] / 3600) * this->t;
}
}

void PlanetEntity::updateProduction() {
Expand All @@ -194,7 +204,6 @@ namespace planet
this->cnt[2] = 0;
this->cnt[3] = 0;
this->cnt[4] = 0;
this->cnt[5] = 0;
this->cnt[6] = 0;
this->cnt[7] = 0;

Expand Down Expand Up @@ -335,10 +344,11 @@ namespace planet

void PlanetEntity::addBoni() {
Config &config = Config::instance();
float boost = 0;
if (config.nget("boost_system_enable", 0) == 1) {
boost += this->boostBonusProduction;
}
float boost = 0;
if (config.nget("boost_system_enable", 0) == 1)
{
boost += this->boostBonusProduction;
}

double energyTechPowerBonus = this->getEnergyTechnologyBonus(
(int)config.idget("ENERGY_TECH_ID"),
Expand Down Expand Up @@ -444,7 +454,7 @@ namespace planet
<< " planet_prod_fuel=" << this->cnt[3] << ", "
<< " planet_prod_food=" << this->cnt[4] << ", "
<< " planet_prod_power=" << this->cnt[6] << ", "
<< " planet_prod_people=" << this->ressource[6] << ", "
<< " planet_prod_people=" << this->cnt[5] << ", "
<< " planet_store_metal=" << this->store[0] << ", "
<< " planet_store_crystal=" << this->store [1] << ", "
<< " planet_store_plastic=" << this->store[2] << ", "
Expand Down Expand Up @@ -473,7 +483,7 @@ namespace planet
<< " planet_res_fuel=planet_res_fuel+'" << this->ressource[3] << "', "
<< " planet_res_food=planet_res_food+'" << this->ressource[4] << "', "
<< " planet_last_updated='" << time(0) << "', "
<< " planet_prod_people=" << this->ressource[6] << ", "
<< " planet_prod_people=" << this->cnt[5] << ", "
<< " planet_people=planet_people+'" << this->ressource[5] <<"' "
<< "WHERE "
<< " id='" << this->entityId << "' "
Expand Down
2 changes: 2 additions & 0 deletions htdocs/classes/resourceboxdrawer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ private static function getResourceTootltip($title, $icon, $amount, $store, $pro
$storeFullMessage = '';
if ($production > 0 && $remainingStore > 0 && $title != 'Bevölkerung') {
$storeFullMessage = sprintf('<br><b>Voll in:</b> %s', tf(($remainingStore / $production) * 3600));
} else if ($title === 'Bevölkerung') {
$storeFullMessage = sprintf('<br><b>Wachstum:</b> %s', nf($production));
}

return mTT(
Expand Down
Loading