fixing astral space properly

This commit is contained in:
Enno Rehling 2008-05-20 15:38:50 +00:00
parent 5d4c66762b
commit 67c43c6ed2
1 changed files with 23 additions and 37 deletions

View File

@ -567,9 +567,9 @@ static int
fix_astralplane(void) fix_astralplane(void)
{ {
plane * astralplane = get_astralplane(); plane * astralplane = get_astralplane();
region * rs; region ** rs_p = &regions;
region_list * rlist = NULL;
faction * monsters = get_monsters(); faction * monsters = get_monsters();
int fixes = 0;
if (astralplane==NULL || monsters==NULL) return 0; if (astralplane==NULL || monsters==NULL) return 0;
@ -577,46 +577,32 @@ fix_astralplane(void)
freset(astralplane, PFL_NOFEED); freset(astralplane, PFL_NOFEED);
set_ursprung(monsters, astralplane->id, 0, 0); set_ursprung(monsters, astralplane->id, 0, 0);
for (rs=regions;rs;rs=rs->next) if (rplane(rs)==astralplane) { while (*rs_p) {
region * ra = r_standard_to_astral(rs); region * rs = *rs_p;
if (ra==NULL) continue; if (rterrain(rs)==T_FIREWALL && rplane(rs)==NULL) {
if (rterrain(rs)!=T_FIREWALL) continue; region * ra = r_standard_to_astral(rs);
if (rterrain(ra)==T_ASTRALB) continue; if (ra && rterrain(ra)!=T_ASTRALB) {
if (ra->units!=NULL) { unit * u;
add_regionlist(&rlist, ra); ++fixes;
} for (u=ra->units;u;u=u->next) {
log_printf("protecting firewall in %s by blocking astral space in %s.\n", regionname(rs, NULL), regionname(ra, NULL)); if (!is_monsters(u->faction)) break;
terraform(ra, T_ASTRALB);
}
while (rlist!=NULL) {
region_list * rnew = rlist;
region * r = rnew->data;
direction_t dir;
rlist = rlist->next;
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
region * rnext = rconnect(r, dir);
if (rnext==NULL) continue;
if (rterrain(rnext)!=T_ASTRAL) continue;
while (r->units) {
unit * u = r->units;
move_unit(u, rnext, NULL);
if (is_monsters(u->faction)) {
set_number(u, 0);
} }
} if (u) {
break; log_printf("could not fix fog in %s because of %s.\n", regionname(ra, NULL), unitname(u));
} }
if (r->units!=NULL) { else {
unit * u; while (ra->units) {
for (u=r->units;u;u=u->next) { remove_unit(&ra->units, ra->units);
if (!is_monsters(u->faction)) { }
log_error(("Einheit %s in %u, %u steckt im Nebel fest.\n", log_printf("protecting firewall in %s by blocking astral space in %s.\n", regionname(rs, NULL), regionname(ra, NULL));
unitname(u), r->x, r->y)); terraform(ra, T_ASTRALB);
} }
} }
} }
free(rnew); rs_p = &rs->next;
} }
log_printf("fixed %d fog/firewall regions.\n", fixes);
return 0; return 0;
} }