Merge pull request #923 from eressea/2706-lighthouse-drifting

2706 lighthouses and drifting
This commit is contained in:
Enno Rehling 2020-09-25 17:39:26 +02:00 committed by GitHub
commit c2754687dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 13 deletions

View File

@ -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;
}
}
}
} }
} }

View File

@ -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();

View File

@ -2192,8 +2192,8 @@ void move_cmd_ex(unit * u, order * ord, const char *directions)
init_order(ord, u->faction->locale); init_order(ord, u->faction->locale);
} }
if (u->ship && u == ship_owner(u->ship)) { if (u->ship && u == ship_owner(u->ship)) {
bool drifting = (getkeyword(ord) == K_MOVE); keyword_t kwd = getkeyword(ord);
sail(u, ord, drifting); sail(u, ord, (kwd == K_MOVE || kwd == K_ROUTE));
} }
else { else {
travel(u, ord); travel(u, ord);