From 1112890293f5275243e24d01a406f13ce3a6d36f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 28 Apr 2017 20:10:20 +0200 Subject: [PATCH] use building_taxes everywhere. make it return an integer, not double. --- src/economy.c | 4 ++-- src/kernel/building.c | 28 +++++++++++++--------------- src/kernel/building.h | 3 ++- src/kernel/region.h | 2 +- src/morale.c | 2 +- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/economy.c b/src/economy.c index 87e31b97c..63d47cebe 100644 --- a/src/economy.c +++ b/src/economy.c @@ -2949,8 +2949,8 @@ static void peasant_taxes(region * r) maxsize = buildingeffsize(b, false); if (maxsize > 0) { - double taxfactor = money * b->type->taxes(b, maxsize); - double morale = MORALE_TAX_FACTOR * money * region_get_morale(r); + double taxfactor = money / building_taxes(b, maxsize); + double morale = money * region_get_morale(r) / MORALE_TAX_FACTOR; if (taxfactor > morale) { taxfactor = morale; } diff --git a/src/kernel/building.c b/src/kernel/building.c index 262836f3a..ffaab81cb 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -784,12 +784,12 @@ bool is_owner_building(const struct building * b) return false; } -double building_taxes(const building *b, int bsize) { +int building_taxes(const building *b, int bsize) { assert(b); if (!b->type->taxes) return 0; else { int level = buildingeffsize(b, false); - return b->type->taxes(b, level); + return (int)(0.5+1/b->type->taxes(b, level)); } } @@ -803,12 +803,12 @@ int cmp_taxes(const building * b, const building * a) return -1; } else if (a) { - double newtaxes = building_taxes(b, b->size); - double oldtaxes = building_taxes(a, a->size); + int newtaxes = building_taxes(b, b->size); + int oldtaxes = building_taxes(a, a->size); - if (newtaxes < oldtaxes) + if (newtaxes > oldtaxes) return -1; - else if (newtaxes > oldtaxes) + else if (newtaxes < oldtaxes) return 1; else if (b->size < a->size) return -1; @@ -840,20 +840,18 @@ int cmp_current_owner(const building * b, const building * a) if (!u || u->faction != f) return -1; if (a) { - int newsize = buildingeffsize(b, false); - double newtaxes = b->type->taxes(b, newsize); - int oldsize = buildingeffsize(a, false); - double oldtaxes = a->type->taxes(a, oldsize); + int newtaxes = building_taxes(b, b->size); + int oldtaxes = building_taxes(a, a->size); - if (newtaxes > oldtaxes) { + if (newtaxes < oldtaxes) { return 1; } - if (newtaxes < oldtaxes) { + if (newtaxes > oldtaxes) { return -1; } - if (newsize != oldsize) { - return newsize - oldsize; - } + //if (newsize != oldsize) { + // return newsize - oldsize; + //} return (b->size - a->size); } else { diff --git a/src/kernel/building.h b/src/kernel/building.h index f7c0c1cdc..6414011bf 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -71,7 +71,7 @@ extern "C" { const char *(*name) (const struct building_type *, const struct building * b, int size); void(*age) (struct building *); - double(*taxes) (const struct building *, int size); + double(*taxes) (const struct building *, int level); struct attrib *attribs; } building_type; @@ -139,6 +139,7 @@ extern "C" { int cmp_taxes(const struct building *b, const struct building *bother); int cmp_current_owner(const struct building *b, const struct building *bother); + int building_taxes(const building *b, int bsize); /* old functions, still in build.c: */ int buildingeffsize(const building * b, int imaginary); diff --git a/src/kernel/region.h b/src/kernel/region.h index 9fa1a2daa..75c9a76db 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -66,7 +66,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. struct faction; struct gamedata; -#define MORALE_TAX_FACTOR 0.005 /* 0.5% tax per point of morale */ +#define MORALE_TAX_FACTOR 200 /* 0.5% tax per point of morale, 1 silver per 200 */ #define MORALE_MAX 10 /* Maximum morale allowed */ #define MORALE_DEFAULT 1 /* Morale of peasants when they are conquered for the first time */ #define MORALE_TAKEOVER 0 /* Morale of peasants after they lose their lord */ diff --git a/src/morale.c b/src/morale.c index 67108333e..1f0edc837 100644 --- a/src/morale.c +++ b/src/morale.c @@ -46,7 +46,7 @@ void morale_update(region *r) { building *b = largestbuilding(r, &cmp_taxes, false); if (b) { int bsize = buildingeffsize(b, false); - maxmorale = (int)(0.5 + b->type->taxes(b, bsize + 1) / MORALE_TAX_FACTOR); + maxmorale = (int)(0.5 + b->type->taxes(b, bsize + 1) * MORALE_TAX_FACTOR); } if (morale < maxmorale) { if (stability > MORALE_COOLDOWN && r->land->ownership->owner