morale is ony [0-10], so unsigned short is more than fine.

This commit is contained in:
Enno Rehling 2019-08-03 15:28:50 +02:00
parent a51d3edee7
commit 8106cf15a1
2 changed files with 12 additions and 8 deletions

View File

@ -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);
}
}

View File

@ -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;