stop using astralregions, avoid dynamic allocations.

This commit is contained in:
Enno Rehling 2019-09-23 20:44:19 +02:00
parent b6edc0b940
commit a2963a8621
5 changed files with 29 additions and 76 deletions

View File

@ -1464,14 +1464,16 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r)
cr_output_curses_compat(F, f, r, TYP_REGION); cr_output_curses_compat(F, f, r, TYP_REGION);
cr_borders(r, f, r->seen.mode, F); cr_borders(r, f, r->seen.mode, F);
if (r->seen.mode >= seen_unit && is_astral(r) if (r->seen.mode >= seen_unit && is_astral(r)
&& !is_cursed(r->attribs, &ct_astralblock)) { && !is_cursed(r->attribs, &ct_astralblock))
{
/* Sonderbehandlung Teleport-Ebene */ /* Sonderbehandlung Teleport-Ebene */
region_list *rl = astralregions(r, inhabitable); region *rl[MAX_SCHEMES];
int num = get_astralregions(r, inhabitable, rl);
if (rl) { if (num > 0) {
region_list *rl2 = rl; int i;
while (rl2) { for (i = 0; i != num; ++i) {
region *r2 = rl2->data; region *r2 = rl[i];
plane *plx = rplane(r2); plane *plx = rplane(r2);
nx = r2->x; nx = r2->x;
@ -1480,9 +1482,7 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r)
adjust_coordinates(f, &nx, &ny, plx); adjust_coordinates(f, &nx, &ny, plx);
fprintf(F, "SCHEMEN %d %d\n", nx, ny); fprintf(F, "SCHEMEN %d %d\n", nx, ny);
fprintf(F, "\"%s\";Name\n", rname(r2, f->locale)); fprintf(F, "\"%s\";Name\n", rname(r2, f->locale));
rl2 = rl2->next;
} }
free_regionlist(rl);
} }
} }

View File

@ -1062,8 +1062,6 @@ char *report_list(const struct locale *lang, char *buffer, size_t len, int argc,
return format_list(argc, argv, buffer, len, two, start, middle, end); return format_list(argc, argv, buffer, len, two, start, middle, end);
} }
#define MAX_SCHEMES ((TP_RADIUS * 2 + 1) * (TP_RADIUS * 2 + 1) - 4)
static void report_region_schemes(struct stream *out, const region * r, faction * f) { static void report_region_schemes(struct stream *out, const region * r, faction * f) {
if (r->seen.mode >= seen_unit && is_astral(r) && if (r->seen.mode >= seen_unit && is_astral(r) &&

View File

@ -1852,8 +1852,6 @@ static int sp_treewalkenter(castorder * co)
static int sp_treewalkexit(castorder * co) static int sp_treewalkexit(castorder * co)
{ {
region *rt; region *rt;
region_list *rl, *rl2;
int tax, tay;
unit *u, *u2; unit *u, *u2;
int remaining_cap; int remaining_cap;
int n; int n;
@ -1885,23 +1883,7 @@ static int sp_treewalkexit(castorder * co)
/* Koordinaten setzen und Region loeschen fuer Ueberpruefung auf /* Koordinaten setzen und Region loeschen fuer Ueberpruefung auf
* Gueltigkeit */ * Gueltigkeit */
rt = pa->param[0]->data.r; rt = pa->param[0]->data.r;
tax = rt->x; if (!rt || !inhabitable(rt) || r_standard_to_astral(rt) != r) {
tay = rt->y;
rl = astralregions(r, inhabitable);
rt = NULL;
rl2 = rl;
while (rl2) {
if (rl2->data->x == tax && rl2->data->y == tay) {
rt = rl2->data;
break;
}
rl2 = rl2->next;
}
free_regionlist(rl);
if (!rt) {
cmistake(caster, co->order, 195, MSG_MAGIC); cmistake(caster, co->order, 195, MSG_MAGIC);
return 0; return 0;
} }
@ -5051,7 +5033,6 @@ int sp_pullastral(castorder * co)
{ {
region *rt, *ro; region *rt, *ro;
unit *u, *u2; unit *u, *u2;
region_list *rl, *rl2;
int remaining_cap; int remaining_cap;
int n, w; int n, w;
region *r = co_get_region(co); region *r = co_get_region(co);
@ -5064,23 +5045,12 @@ int sp_pullastral(castorder * co)
case 1: case 1:
rt = r; rt = r;
ro = pa->param[0]->data.r; ro = pa->param[0]->data.r;
rl = astralregions(r, NULL);
rl2 = rl; if (r_astral_to_standard(r) != ro) {
while (rl2 != NULL) {
region *r2 = rl2->data;
if (r2->x == ro->x && r2->y == ro->y) {
ro = r2;
break;
}
rl2 = rl2->next;
}
if (!rl2) {
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
"spellfail::nocontact", "target", rt)); "spellfail::nocontact", "target", rt));
free_regionlist(rl);
return 0; return 0;
} }
free_regionlist(rl);
break; break;
default: default:
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
@ -5192,7 +5162,6 @@ int sp_pullastral(castorder * co)
int sp_leaveastral(castorder * co) int sp_leaveastral(castorder * co)
{ {
region *rt, *ro; region *rt, *ro;
region_list *rl, *rl2;
unit *u, *u2; unit *u, *u2;
int remaining_cap; int remaining_cap;
int n, w; int n, w;
@ -5204,27 +5173,13 @@ int sp_leaveastral(castorder * co)
switch (getplaneid(r)) { switch (getplaneid(r)) {
case 1: case 1:
ro = r;
rt = pa->param[0]->data.r; rt = pa->param[0]->data.r;
if (!rt) { if (!rt || r_standard_to_astral(rt) != r || !inhabitable(rt)) {
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
"spellfail::noway", "")); "spellfail::noway", ""));
return 0; return 0;
} }
rl = astralregions(r, inhabitable); ro = r;
rl2 = rl;
while (rl2 != NULL) {
if (rl2->data == rt)
break;
rl2 = rl2->next;
}
if (rl2 == NULL) {
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
"spellfail::noway", ""));
free_regionlist(rl);
return 0;
}
free_regionlist(rl);
break; break;
default: default:
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
@ -5545,11 +5500,12 @@ int sp_showastral(castorder * co)
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
int sp_viewreality(castorder * co) int sp_viewreality(castorder * co)
{ {
region_list *rl, *rl2;
region *r = co_get_region(co); region *r = co_get_region(co);
unit *mage = co_get_caster(co); unit *mage = co_get_caster(co);
int cast_level = co->level; int cast_level = co->level;
message *m; message *m;
region *rl[MAX_SCHEMES];
int num;
if (getplaneid(r) != 1) { if (getplaneid(r) != 1) {
/* sprintf(buf, "Dieser Zauber kann nur im Astralraum gezaubert werden."); */ /* sprintf(buf, "Dieser Zauber kann nur im Astralraum gezaubert werden."); */
@ -5558,18 +5514,17 @@ int sp_viewreality(castorder * co)
return 0; return 0;
} }
rl = astralregions(r, NULL); num = get_astralregions(r, NULL, rl);
if (num > 0) {
/* Irgendwann mal auf Curses u/o Attribut umstellen. */ int i;
for (rl2 = rl; rl2; rl2 = rl2->next) { for (i = 0; i != num; ++i) {
region *rt = rl2->data; region *rt = rl[i];
if (!is_cursed(rt->attribs, &ct_astralblock)) { if (!is_cursed(rt->attribs, &ct_astralblock)) {
set_observer(rt, mage->faction, co->level / 2, 2); set_observer(rt, mage->faction, co->level / 2, 2);
}
} }
} }
free_regionlist(rl);
m = msg_message("viewreality_effect", "unit", mage); m = msg_message("viewreality_effect", "unit", mage);
r_addmessage(r, mage->faction, m); r_addmessage(r, mage->faction, m);
msg_release(m); msg_release(m);
@ -5620,11 +5575,7 @@ int sp_disruptastral(castorder * co)
continue; continue;
if (r2->units != NULL) { if (r2->units != NULL) {
region_list *trl2; inhab_regions = get_astralregions(r, inhabitable, NULL);
trl = astralregions(rl2->data, inhabitable);
for (trl2 = trl; trl2; trl2 = trl2->next)
++inhab_regions;
} }
/* Nicht-Permanente Tore zerstoeren */ /* Nicht-Permanente Tore zerstoeren */

View File

@ -91,7 +91,10 @@ int get_astralregions(const region * r, bool(*valid) (const region *), region *r
pnormalize(&nx, &ny, rplane(r)); pnormalize(&nx, &ny, rplane(r));
rn = findregion(nx, ny); rn = findregion(nx, ny);
if (rn != NULL && (valid == NULL || valid(rn))) { if (rn != NULL && (valid == NULL || valid(rn))) {
result[num++] = rn; if (result) {
result[num] = rn;
}
++num;
} }
} }
} }

View File

@ -8,6 +8,7 @@ extern "C" {
#endif #endif
#define TP_RADIUS 2 /* Radius von Schemen */ #define TP_RADIUS 2 /* Radius von Schemen */
#define MAX_SCHEMES ((TP_RADIUS * 2 + 1) * (TP_RADIUS * 2 + 1) - 4)
struct region; struct region;
struct region_list; struct region_list;