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 ef523e0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 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

This comment has been minimized.

Copy link
@ennorehling

ennorehling Dec 17, 2015

du musst die Datei dann aber auch in deinem commit mit drin haben!

This comment has been minimized.

Copy link
@stm2

stm2 Dec 17, 2015

Author Owner

Jetzt kommst du dir wohl sehr schlau vor! ;)

unit.test.c
save.test.c
ship.test.c
Expand Down
33 changes: 18 additions & 15 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,12 +708,11 @@ int rtrees(const region * r, int ageclass)

int rsettrees(const region * r, int ageclass, int value)
{
if (!r->land)
assert(value == 0);
else {
if (r->land) {
assert(value >= 0);
return r->land->trees[ageclass] = value;
}
assert(value == 0);
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
2 changes: 2 additions & 0 deletions src/kernel/terrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ extern "C" {
#define SWIM_INTO (1<<8) /* man darf hierhin schwimmen */
#define WALK_INTO (1<<9) /* man darf hierhin laufen */

struct region;

typedef struct production_rule {
char *name;
const struct resource_type *rtype;
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 ef523e0

Please sign in to comment.