extract main volcano loop to volcano module, start adding tests

This commit is contained in:
Enno Rehling 2016-08-22 21:27:24 +02:00
parent 5e5882d674
commit 4bdc9a5153
5 changed files with 53 additions and 28 deletions

View File

@ -192,6 +192,7 @@ set(TESTS_SRC
battle.test.c battle.test.c
vortex.test.c vortex.test.c
tests.test.c tests.test.c
volcano.test.c
reports.test.c reports.test.c
seen.test.c seen.test.c
travelthru.test.c travelthru.test.c

View File

@ -843,32 +843,7 @@ void randomevents(void)
} }
} }
/* Vulkane qualmen, brechen aus ... */ volcano_update();
for (r = regions; r; r = r->next) {
if (r->terrain == newterrain(T_VOLCANO_SMOKING)) {
if (a_find(r->attribs, &at_reduceproduction)) {
ADDMSG(&r->msgs, msg_message("volcanostopsmoke", "region", r));
rsetterrain(r, T_VOLCANO);
}
else {
if (rng_int() % 100 < 12) {
ADDMSG(&r->msgs, msg_message("volcanostopsmoke", "region", r));
rsetterrain(r, T_VOLCANO);
}
else if (r->age > 20 && rng_int() % 100 < 8) {
volcano_outbreak(r);
rsetterrain(r, T_VOLCANO);
}
}
}
else if (r->terrain == newterrain(T_VOLCANO)) {
if (rng_int() % 100 < 4) {
ADDMSG(&r->msgs, msg_message("volcanostartsmoke", "region", r));
rsetterrain(r, T_VOLCANO_SMOKING);
}
}
}
/* Monumente zerfallen, Schiffe verfaulen */ /* Monumente zerfallen, Schiffe verfaulen */
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {

View File

@ -30,6 +30,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/race.h> #include <kernel/race.h>
#include <kernel/region.h> #include <kernel/region.h>
#include <kernel/unit.h> #include <kernel/unit.h>
#include <kernel/terrainid.h>
/* attributes includes */ /* attributes includes */
#include <attributes/reduceproduction.h> #include <attributes/reduceproduction.h>
@ -257,3 +258,33 @@ void volcano_outbreak(region * r)
} }
} }
void volcano_update(void)
{
region *r;
/* Vulkane qualmen, brechen aus ... */
for (r = regions; r; r = r->next) {
if (r->terrain == newterrain(T_VOLCANO_SMOKING)) {
if (a_find(r->attribs, &at_reduceproduction)) {
ADDMSG(&r->msgs, msg_message("volcanostopsmoke", "region", r));
rsetterrain(r, T_VOLCANO);
}
else {
if (rng_int() % 100 < 12) {
ADDMSG(&r->msgs, msg_message("volcanostopsmoke", "region", r));
rsetterrain(r, T_VOLCANO);
}
else if (r->age > 20 && rng_int() % 100 < 8) {
volcano_outbreak(r);
rsetterrain(r, T_VOLCANO);
}
}
}
else if (r->terrain == newterrain(T_VOLCANO)) {
if (rng_int() % 100 < 4) {
ADDMSG(&r->msgs, msg_message("volcanostartsmoke", "region", r));
rsetterrain(r, T_VOLCANO_SMOKING);
}
}
}
}

View File

@ -26,6 +26,7 @@ extern "C" {
struct region; struct region;
void volcano_outbreak(struct region * r); void volcano_outbreak(struct region * r);
void volcano_update(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

17
src/volcano.test.c Normal file
View File

@ -0,0 +1,17 @@
#include <tests.h>
#include "volcano.h"
#include <CuTest.h>
static void test_volcano_update(CuTest *tc) {
test_cleanup();
volcano_update();
test_cleanup();
}
CuSuite *get_volcano_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_volcano_update);
return suite;
}