Merge pull request #573 from ennorehling/bug-2237-lighthouse-capacity

bug 2237: lighthouse capacity
This commit is contained in:
Enno Rehling 2016-09-17 15:43:21 +02:00 committed by GitHub
commit 3262fdecd4
2 changed files with 44 additions and 2 deletions

View File

@ -1316,9 +1316,10 @@ static void prepare_reports(void)
}
for (u = r->units; u; u = u->next) {
if (u->building && u->building->type == bt_lighthouse) {
b = u->building;
if (b && b->type == bt_lighthouse && inside_building(u)) {
/* we are in a lighthouse. add the regions we can see from here! */
prepare_lighthouse(u->building, u->faction);
prepare_lighthouse(b, u->faction);
}
if (u_race(u) != get_race(RC_SPELL) || u->number == RS_FARVISION) {
@ -1420,6 +1421,7 @@ void prepare_seen(faction *f)
static void prepare_report(struct report_context *ctx, faction *f)
{
assert(f->seen);
prepare_seen(f);
ctx->f = f;
ctx->report_time = time(NULL);

View File

@ -3,6 +3,7 @@
#include "reports.h"
#include "report.h"
#include "creport.h"
#include "lighthouse.h"
#include "move.h"
#include "seen.h"
#include "travelthru.h"
@ -17,6 +18,7 @@
#include <kernel/unit.h>
#include <kernel/spell.h>
#include <kernel/spellbook.h>
#include <kernel/terrain.h>
#include <util/language.h>
#include <util/lists.h>
@ -450,6 +452,43 @@ static void test_arg_resources(CuTest *tc) {
test_cleanup();
}
void test_prepare_lighthouse(CuTest *tc) {
building *b;
building_type *btype;
unit *u;
region *r1, *r2;
faction *f;
const struct terrain_type *t_ocean, *t_plain;
test_setup();
f = test_create_faction(0);
t_ocean = test_create_terrain("ocean", SEA_REGION);
t_plain = test_create_terrain("plain", LAND_REGION);
btype = test_create_buildingtype("lighthouse");
btype->maxcapacity = 4;
r1 = test_create_region(0, 0, t_plain);
r2 = test_create_region(1, 0, t_ocean);
b = test_create_building(r1, btype);
b->flags |= BLD_MAINTAINED;
b->size = 10;
update_lighthouse(b);
u = test_create_unit(test_create_faction(0), r1);
u->number = 4;
u->building = b;
set_level(u, SK_PERCEPTION, 3);
CuAssertIntEquals(tc, 1, lighthouse_range(b, u->faction));
CuAssertPtrEquals(tc, b, inside_building(u));
u = test_create_unit(f, r1);
u->building = b;
set_level(u, SK_PERCEPTION, 3);
CuAssertIntEquals(tc, 0, lighthouse_range(b, u->faction));
CuAssertPtrEquals(tc, NULL, inside_building(u));
init_reports();
CuAssertPtrNotNull(tc, find_seen(f->seen, r1));
CuAssertPtrEquals(tc, 0, find_seen(f->seen, r2));
test_cleanup();
}
CuSuite *get_reports_suite(void)
{
CuSuite *suite = CuSuiteNew();
@ -464,5 +503,6 @@ CuSuite *get_reports_suite(void)
SUITE_ADD_TEST(suite, test_write_unit);
SUITE_ADD_TEST(suite, test_write_spell_syntax);
SUITE_ADD_TEST(suite, test_arg_resources);
SUITE_ADD_TEST(suite, test_prepare_lighthouse);
return suite;
}