forked from townforge/townforge
cc: fix temperature to heating function
This commit is contained in:
parent
ac171bf477
commit
6918004419
@ -1843,7 +1843,7 @@ uint32_t get_heating_needs(uint8_t role)
|
||||
switch (role)
|
||||
{
|
||||
case ROLE_EMPTY: return 0;
|
||||
case ROLE_AGRICULTURAL: return 40;
|
||||
case ROLE_AGRICULTURAL: return 10;
|
||||
case ROLE_CRAFT: return 80;
|
||||
case ROLE_INDUSTRIAL: return 60;
|
||||
case ROLE_COMMERCIAL: return 130;
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "blockchain_db/blockchain_db.h"
|
||||
#include "cc_config.h"
|
||||
#include "cc.h"
|
||||
#include "sqrtint.h"
|
||||
#include "cc_calendar.h"
|
||||
#include "cc_city_specialization.h"
|
||||
#include "cc_temperature.h"
|
||||
@ -45,22 +46,15 @@ int32_t get_base_temperature(uint64_t height)
|
||||
|
||||
uint32_t get_heating_needs(int32_t temperature, uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint8_t role, uint32_t economic_power, uint8_t geothermal_heating)
|
||||
{
|
||||
temperature += geothermal_heating / 8;
|
||||
if (temperature >= 100)
|
||||
return 0;
|
||||
int64_t heating_needs = get_heating_needs(role);
|
||||
if (heating_needs == 0)
|
||||
return 0;
|
||||
|
||||
// 100 (10): 0
|
||||
// 73 (max base): ~2
|
||||
// 0 (0): ~8
|
||||
// -92 (min base): ~23
|
||||
// -100 (-10): ~25
|
||||
// -150 (-15): ~42
|
||||
const int64_t area = (x1 - x0 + 1) * (y1 - y0 + 1);
|
||||
const int64_t scale = area * heating_needs * economic_power * HEATING_SCALE_PER_BILLION;
|
||||
|
||||
#warning TODO: geothermal_heating
|
||||
#warning TODO: should go *down* with temperature
|
||||
heating_needs = (10000 * scale * (300 + temperature) - 25 * scale) / 100000000000000;
|
||||
heating_needs = area * heating_needs * economic_power * (100 - temperature) * sqrtint(100 - temperature) / 2560000 / 128;
|
||||
if (heating_needs < 0)
|
||||
heating_needs = 0;
|
||||
if (heating_needs > std::numeric_limits<uint32_t>::max())
|
||||
|
@ -3370,12 +3370,14 @@ TEST(cc, base_temperature)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(cc, test_temperature)
|
||||
TEST(cc, test_heating)
|
||||
{
|
||||
for (int i = 4; i <= 256; i *= 4)
|
||||
uint32_t heating = 0xffffffff;
|
||||
for (int32_t i = -256; i <= 0; i += 20)
|
||||
{
|
||||
int32_t t = cc::get_heating_needs(0, 0, 0, i, i, ROLE_RESIDENTIAL1, 100, 100);
|
||||
MGINFO("" << (i*i) << ": " << t);
|
||||
uint32_t h = cc::get_heating_needs(i, 0, 0, 32, 32, ROLE_RESIDENTIAL1, 100, 100);
|
||||
ASSERT_LE(h, heating);
|
||||
heating = h;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user