diff --git a/src/kernel/region.c b/src/kernel/region.c index d7ae32130..01dd08b33 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -626,6 +626,7 @@ void rsetpeasants(region * r, int value) assert(value >= 0); if (r->land) { if (value > USHRT_MAX) { + log_warning("region %s cannot have %d peasants.", regionname(r, NULL), value); value = USHRT_MAX; } r->land->peasants = (unsigned short)value; @@ -662,15 +663,18 @@ void rsetmoney(region * r, int value) int rherbs(const region *r) { - return r->land?r->land->herbs:0; + return r->land ? r->land->herbs : 0; } void rsetherbs(region *r, int value) { assert(r->land || value==0); - assert(value >= 0 && value<=SHRT_MAX); if (r->land) { - r->land->herbs = value; + if (value > USHRT_MAX) { + log_warning("region %s cannot have %d herbs.", regionname(r, NULL), value); + value = USHRT_MAX; + } + r->land->herbs = (unsigned short)value; } } @@ -1481,7 +1485,7 @@ const char *region_getname(const region * r) int region_get_morale(const region * r) { if (r->land) { - assert(r->land->morale >= 0 && r->land->morale <= MORALE_MAX); + assert(r->land->morale <= MORALE_MAX); return r->land->morale; } return -1; @@ -1490,11 +1494,11 @@ int region_get_morale(const region * r) void region_set_morale(region * r, int morale, int turn) { if (r->land) { - r->land->morale = morale; + r->land->morale = (unsigned short)morale; if (turn >= 0 && r->land->ownership) { r->land->ownership->morale_turn = turn; } - assert(r->land->morale >= 0 && r->land->morale <= MORALE_MAX); + assert(r->land->morale <= MORALE_MAX); } } diff --git a/src/kernel/region.h b/src/kernel/region.h index 6f1afd4ad..096d68b11 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -97,10 +97,10 @@ extern "C" { char *display; demand *demands; const struct item_type *herbtype; + unsigned short herbs; unsigned short peasants; + unsigned short morale; short newpeasants; - int herbs; - int morale; int trees[3]; /* 0 -> seeds, 1 -> shoots, 2 -> trees */ int horses; int money;