forked from github/server
Merge pull request #923 from eressea/2706-lighthouse-drifting
2706 lighthouses and drifting
This commit is contained in:
commit
c2754687dc
|
@ -21,7 +21,12 @@ attrib_type at_lighthouse = {
|
|||
|
||||
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
|
||||
|
@ -81,7 +86,7 @@ void remove_lighthouse(const building *lh) {
|
|||
|
||||
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 0;
|
||||
|
@ -112,13 +117,19 @@ bool lighthouse_guarded(const region * r)
|
|||
for (a = a_find(r->attribs, &at_lighthouse); a && a->type == &at_lighthouse;
|
||||
a = a->next) {
|
||||
building *b = (building *)a->data.v;
|
||||
|
||||
assert(is_building_type(b->type, "lighthouse"));
|
||||
if ((b->flags & BLD_MAINTAINED) && b->size >= 10) {
|
||||
int maxd = (int)log10(b->size) + 1;
|
||||
int d = distance(r, b->region);
|
||||
assert(maxd >= d);
|
||||
return true;
|
||||
if (b->flags & BLD_MAINTAINED) {
|
||||
if (r == b->region) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
int maxd = lighthouse_range(b);
|
||||
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;
|
||||
CuAssertIntEquals(tc, 0, lighthouse_range(b));
|
||||
b->size = 10;
|
||||
CuAssertIntEquals(tc, 0, lighthouse_range(b));
|
||||
b->flags |= BLD_MAINTAINED;
|
||||
CuAssertIntEquals(tc, 2, lighthouse_range(b));
|
||||
u1->building = b;
|
||||
u2->building = b;
|
||||
|
@ -39,6 +37,8 @@ static void test_lighthouse_range(CuTest * tc)
|
|||
set_level(u1, 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));
|
||||
set_level(u1, SK_PERCEPTION, 6);
|
||||
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, false, lighthouse_guarded(r4));
|
||||
b->size = 1; /* size can go down in destroy_cmd */
|
||||
update_lighthouse(b);
|
||||
CuAssertIntEquals(tc, false, lighthouse_guarded(r2));
|
||||
CuAssertIntEquals(tc, false, lighthouse_guarded(r3));
|
||||
test_teardown();
|
||||
|
|
|
@ -2192,8 +2192,8 @@ void move_cmd_ex(unit * u, order * ord, const char *directions)
|
|||
init_order(ord, u->faction->locale);
|
||||
}
|
||||
if (u->ship && u == ship_owner(u->ship)) {
|
||||
bool drifting = (getkeyword(ord) == K_MOVE);
|
||||
sail(u, ord, drifting);
|
||||
keyword_t kwd = getkeyword(ord);
|
||||
sail(u, ord, (kwd == K_MOVE || kwd == K_ROUTE));
|
||||
}
|
||||
else {
|
||||
travel(u, ord);
|
||||
|
|
Loading…
Reference in New Issue