2014-12-10 19:04:02 +01:00
|
|
|
#include <platform.h>
|
|
|
|
#include "morale.h"
|
|
|
|
|
2018-02-14 20:00:48 +01:00
|
|
|
#include "kernel/calendar.h"
|
|
|
|
#include "kernel/config.h"
|
|
|
|
#include "kernel/curse.h"
|
|
|
|
#include "kernel/region.h"
|
|
|
|
#include "kernel/faction.h"
|
|
|
|
#include "kernel/race.h"
|
|
|
|
#include "kernel/building.h"
|
2014-12-10 19:04:02 +01:00
|
|
|
|
|
|
|
#include <util/rand.h>
|
|
|
|
|
2018-02-14 20:00:48 +01:00
|
|
|
#include <spells/regioncurse.h>
|
|
|
|
|
2015-12-07 17:59:50 +01:00
|
|
|
#include <assert.h>
|
|
|
|
|
2017-02-06 10:44:11 +01:00
|
|
|
static double popularity(void)
|
2014-12-10 19:04:02 +01:00
|
|
|
{
|
2017-02-06 09:46:36 +01:00
|
|
|
return 1.0 / (MORALE_AVERAGE - MORALE_COOLDOWN); /* 10 turns average */
|
2014-12-10 19:04:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void morale_update(region *r) {
|
2015-12-07 17:59:50 +01:00
|
|
|
int morale = region_get_morale(r);
|
|
|
|
assert(r->land);
|
|
|
|
|
2014-12-10 19:04:02 +01:00
|
|
|
if (r->land->ownership && r->land->ownership->owner) {
|
|
|
|
int stability = turn - r->land->ownership->morale_turn;
|
|
|
|
int maxmorale = MORALE_DEFAULT;
|
2017-04-28 21:29:42 +02:00
|
|
|
building *b = largestbuilding(r, cmp_taxes, false);
|
2014-12-10 19:04:02 +01:00
|
|
|
if (b) {
|
|
|
|
int bsize = buildingeffsize(b, false);
|
2017-04-29 19:21:48 +02:00
|
|
|
assert(b->type->taxes>0);
|
|
|
|
maxmorale = (bsize + 1) * MORALE_TAX_FACTOR / b->type->taxes;
|
2014-12-10 19:04:02 +01:00
|
|
|
}
|
2015-12-07 17:59:50 +01:00
|
|
|
if (morale < maxmorale) {
|
2014-12-10 19:04:02 +01:00
|
|
|
if (stability > MORALE_COOLDOWN && r->land->ownership->owner
|
2015-12-07 17:59:50 +01:00
|
|
|
&& morale < MORALE_MAX) {
|
2017-02-06 09:46:36 +01:00
|
|
|
double ch = popularity();
|
2017-08-21 20:48:00 +02:00
|
|
|
if (is_cursed(r->attribs, &ct_generous)) {
|
2014-12-10 19:04:02 +01:00
|
|
|
ch *= 1.2; /* 20% improvement */
|
|
|
|
}
|
|
|
|
if (stability >= MORALE_AVERAGE * 2 || chance(ch)) {
|
2015-12-07 17:59:50 +01:00
|
|
|
region_set_morale(r, morale + 1, turn);
|
2014-12-10 19:04:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-07 17:59:50 +01:00
|
|
|
else if (morale > maxmorale) {
|
|
|
|
region_set_morale(r, morale - 1, turn);
|
2014-12-10 19:04:02 +01:00
|
|
|
}
|
|
|
|
}
|
2015-12-07 17:59:50 +01:00
|
|
|
else if (morale > MORALE_DEFAULT) {
|
|
|
|
region_set_morale(r, morale - 1, turn);
|
2014-12-10 19:04:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void morale_change(region *r, int value) {
|
|
|
|
int morale = region_get_morale(r);
|
|
|
|
if (morale > 0) {
|
2019-01-24 17:50:58 +01:00
|
|
|
morale = morale - value;
|
|
|
|
if (morale < 0) morale = 0;
|
2014-12-10 19:04:02 +01:00
|
|
|
region_set_morale(r, morale, turn);
|
|
|
|
}
|
|
|
|
}
|