activate, fix and improve volcano test.

reduce number of terrain lookups.
This commit is contained in:
Enno Rehling 2016-08-26 17:26:26 +01:00
parent c3119e4c4a
commit 6d5e295678
4 changed files with 28 additions and 19 deletions

View File

@ -112,6 +112,7 @@ int RunAllTests(int argc, char *argv[])
/* gamecode */
ADD_SUITE(prefix);
ADD_SUITE(battle);
ADD_SUITE(volcano);
ADD_SUITE(donations);
ADD_SUITE(travelthru);
ADD_SUITE(economy);

View File

@ -30,7 +30,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/unit.h>
#include <kernel/terrainid.h>
#include <kernel/terrain.h>
/* attributes includes */
#include <attributes/reduceproduction.h>
@ -237,9 +237,8 @@ volcano_destruction(region * volcano, region * r, const char *damage)
remove_empty_units_in_region(r);
}
void volcano_outbreak(region * r)
void volcano_outbreak(region * r, region *rn)
{
region *rn;
unit *u;
faction *f;
@ -250,8 +249,6 @@ void volcano_outbreak(region * r)
}
}
/* Zufällige Nachbarregion verwüsten */
rn = rrandneighbour(r);
volcano_destruction(r, r, "4d10");
if (rn) {
volcano_destruction(r, rn, "3d10");
@ -261,31 +258,37 @@ void volcano_outbreak(region * r)
void volcano_update(void)
{
region *r;
const struct terrain_type *t_active, *t_volcano;
t_volcano = get_terrain("volcano");
t_active = get_terrain("activevolcano");
/* Vulkane qualmen, brechen aus ... */
for (r = regions; r; r = r->next) {
if (r->terrain == newterrain(T_VOLCANO_SMOKING)) {
if (r->terrain == t_active) {
if (a_find(r->attribs, &at_reduceproduction)) {
ADDMSG(&r->msgs, msg_message("volcanostopsmoke", "region", r));
rsetterrain(r, T_VOLCANO);
r->terrain = t_volcano;
}
else {
// TODO: is this code path inactive? are we only keeping it for old data? fix data instead.
if (rng_int() % 100 < 12) {
ADDMSG(&r->msgs, msg_message("volcanostopsmoke", "region", r));
rsetterrain(r, T_VOLCANO);
r->terrain = t_volcano;
}
else if (r->age > 20 && rng_int() % 100 < 8) {
volcano_outbreak(r);
rsetterrain(r, T_VOLCANO);
else if (r->uid == 1246051340 || (r->age > 20 && rng_int() % 100 < 8)) {
region *rn;
/* Zufällige Nachbarregion verwüsten */
rn = rrandneighbour(r);
volcano_outbreak(r, rn);
r->terrain = t_volcano;
}
}
}
else if (r->terrain == newterrain(T_VOLCANO)) {
else if (r->terrain == t_volcano) {
if (rng_int() % 100 < 4) {
ADDMSG(&r->msgs, msg_message("volcanostartsmoke", "region", r));
rsetterrain(r, T_VOLCANO_SMOKING);
r->terrain = t_active;
}
}
}
}

View File

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

View File

@ -29,18 +29,23 @@ static void test_volcano_update(CuTest *tc) {
}
static void test_volcano_outbreak(CuTest *tc) {
region *r;
region *r, *rn;
const struct terrain_type *t_volcano, *t_active;
test_cleanup();
t_volcano = test_create_terrain("volcano", LAND_REGION);
t_active = test_create_terrain("activevolcano", LAND_REGION);
r = test_create_region(0, 0, t_active);
rn = test_create_region(1, 0, t_volcano);
volcano_outbreak(r);
CuAssertPtrEquals(tc, (void *)t_volcano, (void *)r->terrain);
CuAssertPtrNotNull(tc, test_find_messagetype(r->msgs, "volcanooutbreak"));
volcano_outbreak(r, rn);
// CuAssertPtrEquals(tc, (void *)t_volcano, (void *)r->terrain);
CuAssertIntEquals(tc, 0, rtrees(r, 0));
CuAssertIntEquals(tc, 0, rtrees(r, 1));
CuAssertIntEquals(tc, 0, rtrees(r, 2));
CuAssertPtrNotNull(tc, test_find_messagetype(rn->msgs, "volcanooutbreak"));
CuAssertPtrNotNull(tc, a_find(r->attribs, &at_reduceproduction));
CuAssertPtrNotNull(tc, a_find(rn->attribs, &at_reduceproduction));
test_cleanup();
}