Skip to content

Commit

Permalink
test and implement resource setters for ocean (eressea#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
stm2 committed Dec 17, 2015
1 parent 6c77e5e commit b840154
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 18 additions & 16 deletions src/kernel/region.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,51 +598,55 @@ 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)
{
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)
{
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)
{
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;
}


Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/kernel/region.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions src/test_eressea.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b840154

Please sign in to comment.