From b840154352db8b8730d59c418b3ff9a3d91d1520 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Thu, 17 Dec 2015 13:37:25 +0100 Subject: [PATCH] test and implement resource setters for ocean (#43) see also #433 and https://bugs.eressea.de/view.php?id=2173#c6411 --- src/kernel/CMakeLists.txt | 1 + src/kernel/region.c | 34 ++++++++++++++++++---------------- src/kernel/region.h | 8 ++++---- src/test_eressea.c | 1 + 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index b1c3bcd0f..9c3b7d888 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -6,6 +6,7 @@ build.test.c config.test.c group.test.c faction.test.c +region.test.c unit.test.c save.test.c ship.test.c diff --git a/src/kernel/region.c b/src/kernel/region.c index 5e264d3a2..43916da8d 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -598,12 +598,13 @@ int rpeasants(const region * r) return r->land ? r->land->peasants : 0; } -void rsetpeasants(region * r, int value) +int rsetpeasants(const region * r, int value) { + assert(value >= 0); if (r->land) { - assert(value >= 0); - r->land->peasants = value; + return r->land->peasants = value; } + return 0; } int rmoney(const region * r) @@ -611,12 +612,13 @@ int rmoney(const region * r) return r->land ? r->land->money : 0; } -void rsethorses(const region * r, int value) +int rsethorses(const region * r, int value) { + assert(value >= 0); if (r->land) { - assert(value >= 0); - r->land->horses = value; + return r->land->horses = value; } + return 0; } int rhorses(const region * r) @@ -624,12 +626,13 @@ int rhorses(const region * r) return r->land ? r->land->horses : 0; } -void rsetmoney(region * r, int value) +int rsetmoney(const region * r, int value) { + assert(value >= 0); if (r->land) { - assert(value >= 0); - r->land->money = value; + return r->land->money = value; } + return 0; } int rherbs(const struct region *r) @@ -637,12 +640,13 @@ int rherbs(const struct region *r) return r->land?r->land->herbs:0; } -void rsetherbs(const struct region *r, int value) +int rsetherbs(const struct region *r, int value) { + assert(value >= 0 && value < (1 << 15)); if (r->land) { - assert(value >= 0 && value < (1 << 15)); - r->land->herbs = (short)(value); + return r->land->herbs = (short)(value); } + return 0; } @@ -704,10 +708,8 @@ int rtrees(const region * r, int ageclass) int rsettrees(const region * r, int ageclass, int value) { - if (!r->land) - assert(value == 0); - else { - assert(value >= 0); + assert(value >= 0); + if (r->land) { return r->land->trees[ageclass] = value; } return 0; diff --git a/src/kernel/region.h b/src/kernel/region.h index 5974fd96c..b2d33e9f0 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -195,14 +195,14 @@ extern "C" { int rsettrees(const struct region *r, int ageclass, int value); int rpeasants(const struct region *r); - void rsetpeasants(struct region *r, int value); + int rsetpeasants(const struct region *r, int value); int rmoney(const struct region *r); - void rsetmoney(struct region *r, int value); + int rsetmoney(const struct region *r, int value); int rhorses(const struct region *r); - void rsethorses(const struct region *r, int value); + int rsethorses(const struct region *r, int value); int rherbs(const struct region *r); - void rsetherbs(const struct region *r, int value); + int rsetherbs(const struct region *r, int value); #define rbuildings(r) ((r)->buildings) diff --git a/src/test_eressea.c b/src/test_eressea.c index f3d4b71ae..adc8b243d 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -98,6 +98,7 @@ int RunAllTests(int argc, char *argv[]) ADD_SUITE(item); ADD_SUITE(magic); ADD_SUITE(alchemy); + ADD_SUITE(region); ADD_SUITE(reports); ADD_SUITE(save); ADD_SUITE(ship);