forked from github/server
lighthouses protect from drifting
do not check for maintenance in update_lighthouse, but when the lighthouse is used.
This commit is contained in:
parent
65c05f37d2
commit
43a0368fb4
|
@ -21,7 +21,12 @@ attrib_type at_lighthouse = {
|
||||||
|
|
||||||
bool is_lighthouse(const building_type *btype)
|
bool is_lighthouse(const building_type *btype)
|
||||||
{
|
{
|
||||||
return is_building_type(btype, "lighthouse");
|
static int config;
|
||||||
|
static const building_type *bt_lighthouse;
|
||||||
|
if (bt_changed(&config)) {
|
||||||
|
bt_lighthouse = bt_find("lighthouse");
|
||||||
|
}
|
||||||
|
return btype == bt_lighthouse;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* update_lighthouse: call this function whenever the size of a lighthouse changes
|
/* update_lighthouse: call this function whenever the size of a lighthouse changes
|
||||||
|
@ -81,7 +86,7 @@ void remove_lighthouse(const building *lh) {
|
||||||
|
|
||||||
int lighthouse_range(const building * b)
|
int lighthouse_range(const building * b)
|
||||||
{
|
{
|
||||||
if (b->size >= 10 && (b->flags & BLD_MAINTAINED)) {
|
if (b->size >= 10) {
|
||||||
return (int)log10(b->size) + 1;
|
return (int)log10(b->size) + 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -112,13 +117,19 @@ bool lighthouse_guarded(const region * r)
|
||||||
for (a = a_find(r->attribs, &at_lighthouse); a && a->type == &at_lighthouse;
|
for (a = a_find(r->attribs, &at_lighthouse); a && a->type == &at_lighthouse;
|
||||||
a = a->next) {
|
a = a->next) {
|
||||||
building *b = (building *)a->data.v;
|
building *b = (building *)a->data.v;
|
||||||
|
if (b->flags & BLD_MAINTAINED) {
|
||||||
assert(is_building_type(b->type, "lighthouse"));
|
if (r == b->region) {
|
||||||
if ((b->flags & BLD_MAINTAINED) && b->size >= 10) {
|
return true;
|
||||||
int maxd = (int)log10(b->size) + 1;
|
}
|
||||||
int d = distance(r, b->region);
|
else {
|
||||||
assert(maxd >= d);
|
int maxd = lighthouse_range(b);
|
||||||
return true;
|
if (maxd > 0) {
|
||||||
|
int d = distance(r, b->region);
|
||||||
|
if (maxd >= d) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,6 @@ static void test_lighthouse_range(CuTest * tc)
|
||||||
b->size = 9;
|
b->size = 9;
|
||||||
CuAssertIntEquals(tc, 0, lighthouse_range(b));
|
CuAssertIntEquals(tc, 0, lighthouse_range(b));
|
||||||
b->size = 10;
|
b->size = 10;
|
||||||
CuAssertIntEquals(tc, 0, lighthouse_range(b));
|
|
||||||
b->flags |= BLD_MAINTAINED;
|
|
||||||
CuAssertIntEquals(tc, 2, lighthouse_range(b));
|
CuAssertIntEquals(tc, 2, lighthouse_range(b));
|
||||||
u1->building = b;
|
u1->building = b;
|
||||||
u2->building = b;
|
u2->building = b;
|
||||||
|
@ -39,6 +37,8 @@ static void test_lighthouse_range(CuTest * tc)
|
||||||
set_level(u1, SK_PERCEPTION, 3);
|
set_level(u1, SK_PERCEPTION, 3);
|
||||||
set_level(u2, SK_PERCEPTION, 3);
|
set_level(u2, SK_PERCEPTION, 3);
|
||||||
|
|
||||||
|
CuAssertIntEquals(tc, 0, lighthouse_view_distance(b, u1));
|
||||||
|
b->flags |= BLD_MAINTAINED;
|
||||||
CuAssertIntEquals(tc, 1, lighthouse_view_distance(b, u1));
|
CuAssertIntEquals(tc, 1, lighthouse_view_distance(b, u1));
|
||||||
set_level(u1, SK_PERCEPTION, 6);
|
set_level(u1, SK_PERCEPTION, 6);
|
||||||
CuAssertIntEquals(tc, 1, lighthouse_view_distance(b, u2));
|
CuAssertIntEquals(tc, 1, lighthouse_view_distance(b, u2));
|
||||||
|
@ -126,6 +126,7 @@ static void test_lighthouse_guard(CuTest * tc) {
|
||||||
CuAssertIntEquals(tc, true, lighthouse_guarded(r3));
|
CuAssertIntEquals(tc, true, lighthouse_guarded(r3));
|
||||||
CuAssertIntEquals(tc, false, lighthouse_guarded(r4));
|
CuAssertIntEquals(tc, false, lighthouse_guarded(r4));
|
||||||
b->size = 1; /* size can go down in destroy_cmd */
|
b->size = 1; /* size can go down in destroy_cmd */
|
||||||
|
update_lighthouse(b);
|
||||||
CuAssertIntEquals(tc, false, lighthouse_guarded(r2));
|
CuAssertIntEquals(tc, false, lighthouse_guarded(r2));
|
||||||
CuAssertIntEquals(tc, false, lighthouse_guarded(r3));
|
CuAssertIntEquals(tc, false, lighthouse_guarded(r3));
|
||||||
test_teardown();
|
test_teardown();
|
||||||
|
|
Loading…
Reference in New Issue