new lighthouse behavior as described in http://bugs.eressea.de/view.php?id=1847

This commit is contained in:
Enno Rehling 2011-04-24 12:19:34 -07:00
parent 28a1e8d3cc
commit ec9e7bf833
2 changed files with 53 additions and 21 deletions

View File

@ -864,6 +864,33 @@ function test_coordinates_noname_plane()
assert_true(find_in_report(f, r.name .. " %(0,0%), Berg"))
end
function test_lighthouse()
local r = region.create(0, 0, "mountain")
local f = faction.create("noreply@eressea.de", "human", "de")
region.create(1, 0, "mountain")
region.create(2, 0, "ocean")
region.create(0, 1, "firewall")
region.create(3, 0, "mountain")
region.create(4, 0, "plain")
local u = unit.create(f, r, 1)
local b = building.create(r, "lighthouse")
b.size = 100
u.building = b
u:set_skill("perception", 9)
u:add_item("money", 1000)
assert_not_nil(b)
init_reports()
write_report(f)
assert_true(find_in_report(f, " %(1,0%) %(vom Turm erblickt%)"))
assert_true(find_in_report(f, " %(2,0%) %(vom Turm erblickt%)"))
assert_true(find_in_report(f, " %(3,0%) %(vom Turm erblickt%)"))
assert_false(find_in_report(f, " %(0,0%) %(vom Turm erblickt%)"))
assert_false(find_in_report(f, " %(0,1%) %(vom Turm erblickt%)"))
assert_false(find_in_report(f, " %(4,0%) %(vom Turm erblickt%)"))
end
module("tests.parser", package.seeall, lunit.testcase)
function setup()

View File

@ -1373,14 +1373,37 @@ static void view_regatta(struct seen_region **seen, region * r, faction * f)
recurse_regatta(seen, r, r, f, skill / 2);
}
static void prepare_lighthouse(building * b, faction * f)
{
int range = lighthouse_range(b, f);
region_list *rlist = get_regions_distance(b->region, range);
region_list *rp = rlist;
while (rp) {
region *rl = rp->data;
if (!fval(rl->terrain, FORBIDDEN_REGION)) {
int d;
add_seen(f->seen, rl, see_lighthouse, false);
for (d = 0; d != MAXDIRECTIONS; ++d) {
region *rn = rconnect(rl, d);
if (rn != NULL) {
add_seen(f->seen, rn, see_neighbour, false);
}
}
}
rp = rp->next;
}
free_regionlist(rlist);
}
static void prepare_reports(void)
{
region *r;
faction *f;
static const struct building_type *bt_lighthouse = NULL;
if (bt_lighthouse == NULL)
if (bt_lighthouse == NULL) {
bt_lighthouse = bt_find("lighthouse");
}
for (f = factions; f; f = f->next) {
if (f->seen)
seen_done(f->seen);
@ -1407,25 +1430,7 @@ static void prepare_reports(void)
for (u = r->units; u; u = u->next) {
if (u->building && u->building->type == bt_lighthouse) {
/* we are in a lighthouse. add the regions we can see from here! */
int range = lighthouse_range(u->building, u->faction);
region_list *rlist = get_regions_distance(r, range);
region_list *rp = rlist;
while (rp) {
region *rl = rp->data;
if (fval(rl->terrain, SEA_REGION)) {
direction_t d;
add_seen(u->faction->seen, rl, see_lighthouse, false);
for (d = 0; d != MAXDIRECTIONS; ++d) {
region *rn = rconnect(rl, d);
if (rn != NULL) {
add_seen(u->faction->seen, rn, see_neighbour, false);
}
}
}
rp = rp->next;
}
free_regionlist(rlist);
prepare_lighthouse(u->building, u->faction);
}
if (u->race != new_race[RC_SPELL] || u->number == RS_FARVISION) {