Merge pull request #704 from ennorehling/master

Valenar crash: bad report interval when a faction has no units.
This commit is contained in:
Enno Rehling 2017-06-26 20:50:05 +02:00 committed by GitHub
commit 2c356103e2
1 changed files with 33 additions and 28 deletions

View File

@ -1367,6 +1367,9 @@ void reorder_units(region * r)
static region *lastregion(faction * f) static region *lastregion(faction * f)
{ {
if (!f->units) {
return NULL;
}
return f->last ? f->last->next : NULL; return f->last ? f->last->next : NULL;
} }
@ -1418,43 +1421,45 @@ void prepare_report(report_context *ctx, faction *f)
ctx->addresses = NULL; ctx->addresses = NULL;
ctx->userdata = NULL; ctx->userdata = NULL;
/* [first,last) interval of regions with a unit in it: */ /* [first,last) interval of regions with a unit in it: */
ctx->first = firstregion(f); if (f->units) {
ctx->last = lastregion(f); ctx->first = firstregion(f);
ctx->last = lastregion(f);
for (r = ctx->first; r!=ctx->last; r = r->next) { for (r = ctx->first; r != ctx->last; r = r->next) {
int range = 0; int range = 0;
unit *u; unit *u;
if (fval(r, RF_LIGHTHOUSE) && bt_lighthouse) { if (fval(r, RF_LIGHTHOUSE) && bt_lighthouse) {
if (rule_region_owners && f == region_get_owner(r)) { if (rule_region_owners && f == region_get_owner(r)) {
/* region owners get the report from lighthouses */ /* region owners get the report from lighthouses */
building *b; building *b;
for (b = r->buildings; b; b = b->next) { for (b = r->buildings; b; b = b->next) {
if (b->type == bt_lighthouse) { if (b->type == bt_lighthouse) {
int br = lighthouse_range(b, NULL); int br = lighthouse_range(b, NULL);
if (br > range) range = br; if (br > range) range = br;
}
} }
} }
} }
} for (u = r->units; u; u = u->next) {
for (u = r->units; u; u = u->next) { if (u->faction == f) {
if (u->faction == f) { add_seen_nb(f, r, seen_unit);
add_seen_nb(f, r, seen_unit); if (fval(r, RF_LIGHTHOUSE) && bt_lighthouse) {
if (fval(r, RF_LIGHTHOUSE) && bt_lighthouse) { if (u->building && u->building->type == bt_lighthouse && inside_building(u)) {
if (u->building && u->building->type == bt_lighthouse && inside_building(u)) { int br = lighthouse_range(u->building, f);
int br = lighthouse_range(u->building, f); if (br > range) range = br;
if (br > range) range = br; }
} }
} }
} }
} if (range > 0) {
if (range > 0) { /* we are in at least one lighthouse. add the regions we can see from here! */
/* we are in at least one lighthouse. add the regions we can see from here! */ prepare_lighthouse(f, r, range);
prepare_lighthouse(f, r, range); }
}
if (fval(r, RF_TRAVELUNIT) && r->seen.mode<seen_travel) { if (fval(r, RF_TRAVELUNIT) && r->seen.mode < seen_travel) {
travelthru_map(r, cb_add_seen, f); travelthru_map(r, cb_add_seen, f);
}
} }
} }
/* [fast,last) interval of seen regions (with lighthouses and travel) /* [fast,last) interval of seen regions (with lighthouses and travel)