forked from github/server
stop using astralregions, avoid dynamic allocations.
This commit is contained in:
parent
b6edc0b940
commit
a2963a8621
|
@ -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_borders(r, f, r->seen.mode, F);
|
||||
if (r->seen.mode >= seen_unit && is_astral(r)
|
||||
&& !is_cursed(r->attribs, &ct_astralblock)) {
|
||||
&& !is_cursed(r->attribs, &ct_astralblock))
|
||||
{
|
||||
/* Sonderbehandlung Teleport-Ebene */
|
||||
region_list *rl = astralregions(r, inhabitable);
|
||||
region *rl[MAX_SCHEMES];
|
||||
int num = get_astralregions(r, inhabitable, rl);
|
||||
|
||||
if (rl) {
|
||||
region_list *rl2 = rl;
|
||||
while (rl2) {
|
||||
region *r2 = rl2->data;
|
||||
if (num > 0) {
|
||||
int i;
|
||||
for (i = 0; i != num; ++i) {
|
||||
region *r2 = rl[i];
|
||||
plane *plx = rplane(r2);
|
||||
|
||||
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);
|
||||
fprintf(F, "SCHEMEN %d %d\n", nx, ny);
|
||||
fprintf(F, "\"%s\";Name\n", rname(r2, f->locale));
|
||||
rl2 = rl2->next;
|
||||
}
|
||||
free_regionlist(rl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
#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) {
|
||||
|
||||
if (r->seen.mode >= seen_unit && is_astral(r) &&
|
||||
|
|
81
src/spells.c
81
src/spells.c
|
@ -1852,8 +1852,6 @@ static int sp_treewalkenter(castorder * co)
|
|||
static int sp_treewalkexit(castorder * co)
|
||||
{
|
||||
region *rt;
|
||||
region_list *rl, *rl2;
|
||||
int tax, tay;
|
||||
unit *u, *u2;
|
||||
int remaining_cap;
|
||||
int n;
|
||||
|
@ -1885,23 +1883,7 @@ static int sp_treewalkexit(castorder * co)
|
|||
/* Koordinaten setzen und Region loeschen fuer Ueberpruefung auf
|
||||
* Gueltigkeit */
|
||||
rt = pa->param[0]->data.r;
|
||||
tax = rt->x;
|
||||
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) {
|
||||
if (!rt || !inhabitable(rt) || r_standard_to_astral(rt) != r) {
|
||||
cmistake(caster, co->order, 195, MSG_MAGIC);
|
||||
return 0;
|
||||
}
|
||||
|
@ -5051,7 +5033,6 @@ int sp_pullastral(castorder * co)
|
|||
{
|
||||
region *rt, *ro;
|
||||
unit *u, *u2;
|
||||
region_list *rl, *rl2;
|
||||
int remaining_cap;
|
||||
int n, w;
|
||||
region *r = co_get_region(co);
|
||||
|
@ -5064,23 +5045,12 @@ int sp_pullastral(castorder * co)
|
|||
case 1:
|
||||
rt = r;
|
||||
ro = pa->param[0]->data.r;
|
||||
rl = astralregions(r, NULL);
|
||||
rl2 = rl;
|
||||
while (rl2 != NULL) {
|
||||
region *r2 = rl2->data;
|
||||
if (r2->x == ro->x && r2->y == ro->y) {
|
||||
ro = r2;
|
||||
break;
|
||||
}
|
||||
rl2 = rl2->next;
|
||||
}
|
||||
if (!rl2) {
|
||||
|
||||
if (r_astral_to_standard(r) != ro) {
|
||||
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
|
||||
"spellfail::nocontact", "target", rt));
|
||||
free_regionlist(rl);
|
||||
return 0;
|
||||
}
|
||||
free_regionlist(rl);
|
||||
break;
|
||||
default:
|
||||
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
|
||||
|
@ -5192,7 +5162,6 @@ int sp_pullastral(castorder * co)
|
|||
int sp_leaveastral(castorder * co)
|
||||
{
|
||||
region *rt, *ro;
|
||||
region_list *rl, *rl2;
|
||||
unit *u, *u2;
|
||||
int remaining_cap;
|
||||
int n, w;
|
||||
|
@ -5204,27 +5173,13 @@ int sp_leaveastral(castorder * co)
|
|||
|
||||
switch (getplaneid(r)) {
|
||||
case 1:
|
||||
ro = 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,
|
||||
"spellfail::noway", ""));
|
||||
return 0;
|
||||
}
|
||||
rl = astralregions(r, inhabitable);
|
||||
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);
|
||||
ro = r;
|
||||
break;
|
||||
default:
|
||||
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
|
||||
|
@ -5545,11 +5500,12 @@ int sp_showastral(castorder * co)
|
|||
/* ------------------------------------------------------------- */
|
||||
int sp_viewreality(castorder * co)
|
||||
{
|
||||
region_list *rl, *rl2;
|
||||
region *r = co_get_region(co);
|
||||
unit *mage = co_get_caster(co);
|
||||
int cast_level = co->level;
|
||||
message *m;
|
||||
region *rl[MAX_SCHEMES];
|
||||
int num;
|
||||
|
||||
if (getplaneid(r) != 1) {
|
||||
/* sprintf(buf, "Dieser Zauber kann nur im Astralraum gezaubert werden."); */
|
||||
|
@ -5558,18 +5514,17 @@ int sp_viewreality(castorder * co)
|
|||
return 0;
|
||||
}
|
||||
|
||||
rl = astralregions(r, NULL);
|
||||
|
||||
/* Irgendwann mal auf Curses u/o Attribut umstellen. */
|
||||
for (rl2 = rl; rl2; rl2 = rl2->next) {
|
||||
region *rt = rl2->data;
|
||||
if (!is_cursed(rt->attribs, &ct_astralblock)) {
|
||||
set_observer(rt, mage->faction, co->level / 2, 2);
|
||||
num = get_astralregions(r, NULL, rl);
|
||||
if (num > 0) {
|
||||
int i;
|
||||
for (i = 0; i != num; ++i) {
|
||||
region *rt = rl[i];
|
||||
if (!is_cursed(rt->attribs, &ct_astralblock)) {
|
||||
set_observer(rt, mage->faction, co->level / 2, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free_regionlist(rl);
|
||||
|
||||
m = msg_message("viewreality_effect", "unit", mage);
|
||||
r_addmessage(r, mage->faction, m);
|
||||
msg_release(m);
|
||||
|
@ -5620,11 +5575,7 @@ int sp_disruptastral(castorder * co)
|
|||
continue;
|
||||
|
||||
if (r2->units != NULL) {
|
||||
region_list *trl2;
|
||||
|
||||
trl = astralregions(rl2->data, inhabitable);
|
||||
for (trl2 = trl; trl2; trl2 = trl2->next)
|
||||
++inhab_regions;
|
||||
inhab_regions = get_astralregions(r, inhabitable, NULL);
|
||||
}
|
||||
|
||||
/* Nicht-Permanente Tore zerstoeren */
|
||||
|
|
|
@ -91,7 +91,10 @@ int get_astralregions(const region * r, bool(*valid) (const region *), region *r
|
|||
pnormalize(&nx, &ny, rplane(r));
|
||||
rn = findregion(nx, ny);
|
||||
if (rn != NULL && (valid == NULL || valid(rn))) {
|
||||
result[num++] = rn;
|
||||
if (result) {
|
||||
result[num] = rn;
|
||||
}
|
||||
++num;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#define TP_RADIUS 2 /* Radius von Schemen */
|
||||
#define MAX_SCHEMES ((TP_RADIUS * 2 + 1) * (TP_RADIUS * 2 + 1) - 4)
|
||||
|
||||
struct region;
|
||||
struct region_list;
|
||||
|
|
Loading…
Reference in New Issue