diff --git a/res/core/messages.xml b/res/core/messages.xml
index 766cd481c..d40efb9ac 100644
--- a/res/core/messages.xml
+++ b/res/core/messages.xml
@@ -5291,6 +5291,7 @@
+
diff --git a/res/translations/messages.de.po b/res/translations/messages.de.po
index a1d30c85c..776a1e207 100644
--- a/res/translations/messages.de.po
+++ b/res/translations/messages.de.po
@@ -2370,7 +2370,7 @@ msgid "sp_confusion_effect_0"
msgstr "\"$unit($mage) stimmt einen seltsamen Gesang an. Ein plötzlicher Tumult entsteht, der sich jedoch schnell wieder legt.\""
msgid "pest"
-msgstr "\"Hier wütete die Pest, und $int($dead) Bauern starben.\""
+msgstr "\"Hier wütete die Pest, und $int($dead) $resource($peasants,$dead) $if($eq($dead,1), \"starb\", \"starben\").\""
msgid "wormhole_exit"
msgstr "\"$unit($unit) reist durch ein Wurmloch nach $region($region).\""
diff --git a/res/translations/messages.en.po b/res/translations/messages.en.po
index 037b50d4d..7724fdc07 100644
--- a/res/translations/messages.en.po
+++ b/res/translations/messages.en.po
@@ -2370,7 +2370,7 @@ msgid "sp_confusion_effect_0"
msgstr "\"$unit($mage) intones a mysterious chant. There is a sudden hubbub, but order is restored quickly.\""
msgid "pest"
-msgstr "\"The region is visited by the plague and $int($dead) peasants died.\""
+msgstr "\"The region is visited by the plague and $int($dead) $resource($peasants,$dead) died.\""
msgid "wormhole_exit"
msgstr "\"$unit($unit) travels through a wormhole to $region($region).\""
diff --git a/res/translations/strings.de.po b/res/translations/strings.de.po
index 68f126335..e6931c344 100644
--- a/res/translations/strings.de.po
+++ b/res/translations/strings.de.po
@@ -571,7 +571,7 @@ msgid "balloon"
msgstr "Ballon"
msgid "nr_schemes_template"
-msgstr "Schemen der Regionen {0} sind erkennbar."
+msgstr "Schemen von {0} sind erkennbar."
msgid "list_two"
msgstr "{0} und {1}"
diff --git a/scripts/tests/e2/astral.lua b/scripts/tests/e2/astral.lua
index 1573c9af2..5c4461921 100644
--- a/scripts/tests/e2/astral.lua
+++ b/scripts/tests/e2/astral.lua
@@ -15,16 +15,20 @@ end
function test_fetch_astral()
local r = region.create(0, 0, "plain")
+ local ra = r:get_astral('fog')
+ local rb = region.create(ra.x + 1, ra.y, 'fog')
local f = faction.create("human")
local u1 = unit.create(f, r, 1)
local u2 = unit.create(f, r, 1)
+ local u3 = unit.create(f, rb, 1)
+ rb.plane = ra.plane
u1.magic = "gray"
u1:set_skill("magic", 6)
u1.aura = 0
u1:add_spell("fetch_astral")
u1:clear_orders()
- u1:add_order("ZAUBERE Ruf~der~Realitaet " .. itoa36(u2.id))
+ u1:add_order("ZAUBERE Ruf~der~Realitaet " .. itoa36(u2.id) .. " " .. itoa36(u3.id))
process_orders()
assert_equal(1, f:count_msg_type('missing_components_list'), 'no components')
@@ -33,10 +37,11 @@ function test_fetch_astral()
assert_equal(12, u1.aura)
assert_equal(1, f:count_msg_type('spellfail_astralonly'), 'astral space')
- u2.region = u2.region:get_astral('fog')
+ u2.region = ra
process_orders()
assert_equal(0, u1.aura)
- assert_equal(u1.region, u2.region)
+ assert_equal(r, u2.region)
+ assert_equal(rb, u3.region)
end
function test_pull_astral()
diff --git a/scripts/tests/e2/insects.lua b/scripts/tests/e2/insects.lua
index 1898e215c..f5b8a3213 100644
--- a/scripts/tests/e2/insects.lua
+++ b/scripts/tests/e2/insects.lua
@@ -85,3 +85,30 @@ function test_recruit_in_desert()
assert_equal('winter', get_season(get_turn()))
assert_equal(2, u.number)
end
+
+function test_ride_through_mountain()
+ local r1 = region.create(1, 0, "plain")
+ local r2 = region.create(2, 0, "mountain")
+ local r3 = region.create(3, 0, "plain")
+ local f = faction.create("insect")
+ local u = unit.create(f, r1, 1)
+ u.name="Hercules"
+ u:add_order('NACH O O')
+ u:add_item('horse', 1)
+ u:set_skill('riding', 1, true)
+ process_orders()
+ assert_equal(r3, u.region)
+end
+
+function test_ride_from_mountain()
+ local r1 = region.create(1, 0, "mountain")
+ local r2 = region.create(2, 0, "plain")
+ local r3 = region.create(3, 0, "plain")
+ local f = faction.create("insect")
+ local u = unit.create(f, r1, 1)
+ u:add_order('NACH O O')
+ u:add_item('horse', 1)
+ u:set_skill('riding', 1, true)
+ process_orders()
+ assert_equal(r2, u.region)
+end
diff --git a/src/battle.c b/src/battle.c
index 493e6c1c9..835917e62 100644
--- a/src/battle.c
+++ b/src/battle.c
@@ -1153,7 +1153,8 @@ static void destroy_items(troop dt) {
}
static void calculate_defense_type(troop at, troop dt, int type, bool missile,
- const weapon_type **dwtype, int *defskill) {
+ const weapon_type **dwtype, int *defskill)
+{
const weapon *weapon;
weapon = select_weapon(dt, false, true); /* missile=true to get the unmodified best weapon she has */
*defskill = weapon_effskill(dt, at, weapon, false, false);
@@ -1253,7 +1254,7 @@ static int apply_magicshield(int reduced_damage, fighter *df,
}
}
}
-
+
return reduced_damage;
}
@@ -1265,25 +1266,22 @@ terminate(troop dt, troop at, int type, const char *damage_formula, bool missile
unit *au = af->unit;
unit *du = df->unit;
battle *b = df->side->battle;
-
int armor_value;
-
const weapon_type *dwtype = NULL;
const weapon_type *awtype = NULL;
const armor_type *armor = NULL;
const armor_type *shield = NULL;
-
int reduced_damage, attskill = 0, defskill = 0;
bool magic = false;
-
+
int damage = dice_rand(damage_formula);
-
+
assert(du->number > 0);
++at.fighter->hits;
-
+
calculate_attack_type(at, dt, type, missile, &awtype, &attskill, &magic);
calculate_defense_type(at, dt, type, missile, &dwtype, &defskill);
-
+
if (is_riding(at) && (awtype == NULL || (fval(awtype, WTF_HORSEBONUS)
&& !fval(awtype, WTF_MISSILE)))) {
damage += CavalryBonus(au, dt, BONUS_DAMAGE);
diff --git a/src/bind_faction.c b/src/bind_faction.c
index 07121d530..ada69f12b 100644
--- a/src/bind_faction.c
+++ b/src/bind_faction.c
@@ -260,7 +260,7 @@ static int tolua_faction_debug_messages(lua_State * L)
int i = 1;
if (f->msgs) {
mlist *ml;
- for (ml = self->msgs->begin; ml; ml = ml->next, ++i) {
+ for (ml = f->msgs->begin; ml; ml = ml->next, ++i) {
char buf[120];
nr_render(ml->msg, default_locale, buf, sizeof(buf), NULL);
puts(buf);
diff --git a/src/bind_faction.h b/src/bind_faction.h
index aed077f10..8f1255e65 100644
--- a/src/bind_faction.h
+++ b/src/bind_faction.h
@@ -1,8 +1,11 @@
+#pragma once
+
+struct lua_State;
+
#ifdef __cplusplus
extern "C" {
#endif
- struct lua_State;
int tolua_factionlist_next(struct lua_State *L);
void tolua_faction_open(struct lua_State *L);
diff --git a/src/bind_region.c b/src/bind_region.c
index 29c7e6893..d0c184e0d 100644
--- a/src/bind_region.c
+++ b/src/bind_region.c
@@ -114,6 +114,14 @@ static int tolua_region_get_plane(lua_State * L)
return 1;
}
+static int tolua_region_set_plane(lua_State * L)
+{
+ region *r = (region *)tolua_tousertype(L, 1, NULL);
+ plane *pl = (plane *)tolua_tousertype(L, 2, NULL);
+ r->_plane = pl;
+ return 0;
+}
+
static int tolua_region_get_terrain(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, NULL);
@@ -768,7 +776,8 @@ void tolua_region_open(lua_State * L)
tolua_variable(L, TOLUA_CAST "id", tolua_region_get_id, NULL);
tolua_variable(L, TOLUA_CAST "x", tolua_region_get_x, NULL);
tolua_variable(L, TOLUA_CAST "y", tolua_region_get_y, NULL);
- tolua_variable(L, TOLUA_CAST "plane", tolua_region_get_plane, NULL);
+ tolua_variable(L, TOLUA_CAST "plane", tolua_region_get_plane,
+ tolua_region_set_plane);
tolua_variable(L, TOLUA_CAST "name", tolua_region_get_name,
tolua_region_set_name);
tolua_variable(L, TOLUA_CAST "morale", tolua_region_get_morale,
diff --git a/src/creport.c b/src/creport.c
index 4088db49c..72bca8c70 100644
--- a/src/creport.c
+++ b/src/creport.c
@@ -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);
}
}
diff --git a/src/laws.c b/src/laws.c
index 7f78ac04b..50d364660 100644
--- a/src/laws.c
+++ b/src/laws.c
@@ -2181,6 +2181,21 @@ int email_cmd(unit * u, struct order *ord)
return 0;
}
+bool password_wellformed(const char *password)
+{
+ unsigned char *c = (unsigned char *)password;
+ int i;
+ if (!password || password[0]=='\0') {
+ return false;
+ }
+ for (i = 0; c[i] && i != PASSWORD_MAXSIZE; ++i) {
+ if (!isalnum(c[i])) {
+ return false;
+ }
+ }
+ return true;
+}
+
int password_cmd(unit * u, struct order *ord)
{
char pwbuf[PASSWORD_MAXSIZE + 1];
@@ -2194,19 +2209,11 @@ int password_cmd(unit * u, struct order *ord)
pwbuf[PASSWORD_MAXSIZE - 1] = '\0';
}
- if (s && *s) {
- unsigned char *c = (unsigned char *)pwbuf;
- int i, r = 0;
-
- for (i = 0; c[i] && i != PASSWORD_MAXSIZE; ++i) {
- if (!isalnum(c[i])) {
- c[i] = 'X';
- ++r;
- }
- }
- if (r != 0) {
+ if (!s || !password_wellformed(s)) {
+ if (s) {
cmistake(u, ord, 283, MSG_EVENT);
}
+ password_generate(pwbuf, PASSWORD_MAXSIZE);
}
faction_setpassword(u->faction, password_hash(pwbuf, PASSWORD_DEFAULT));
ADDMSG(&u->faction->msgs, msg_message("changepasswd", "value", pwbuf));
diff --git a/src/laws.h b/src/laws.h
index 4924a5f6e..a49848ac9 100755
--- a/src/laws.h
+++ b/src/laws.h
@@ -48,6 +48,7 @@ extern "C" {
void sinkships(struct region * r);
void do_enter(struct region *r, bool is_final_attempt);
bool long_order_allowed(const struct unit *u);
+ bool password_wellformed(const char *password);
int password_cmd(struct unit *u, struct order *ord);
int banner_cmd(struct unit *u, struct order *ord);
diff --git a/src/laws.test.c b/src/laws.test.c
index 5dff45a92..8b92629b2 100644
--- a/src/laws.test.c
+++ b/src/laws.test.c
@@ -49,37 +49,6 @@ static void test_new_building_can_be_renamed(CuTest * tc)
test_teardown();
}
-static void test_password_cmd(CuTest * tc)
-{
- unit *u;
- faction * f;
- test_setup();
- u = test_create_unit(f = test_create_faction(NULL), test_create_plain(0, 0));
-
- u->thisorder = create_order(K_PASSWORD, f->locale, "abcdefgh");
- password_cmd(u, u->thisorder);
- CuAssertPtrNotNull(tc, faction_getpassword(f));
- CuAssertTrue(tc, checkpasswd(f, "abcdefgh"));
- CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
- free_order(u->thisorder);
-
- u->thisorder = create_order(K_PASSWORD, f->locale, "abc*de*");
- password_cmd(u, u->thisorder);
- CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error283"));
- CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
- CuAssertTrue(tc, !checkpasswd(f, "abc*de*"));
- CuAssertTrue(tc, checkpasswd(f, "abcXdeX"));
- free_order(u->thisorder);
-
- u->thisorder = create_order(K_PASSWORD, f->locale, "1234567890123456789012345678901234567890");
- password_cmd(u, u->thisorder);
- CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error321"));
- CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
- CuAssertTrue(tc, checkpasswd(f, "1234567890123456789012345678901"));
-
- test_teardown();
-}
-
static void test_rename_building(CuTest * tc)
{
region *r;
@@ -1949,6 +1918,60 @@ static void test_long_order_on_ocean(CuTest *tc) {
test_teardown();
}
+static void test_password_cmd(CuTest *tc) {
+ unit *u;
+ message *msg;
+ faction * f;
+
+ CuAssertTrue(tc, password_wellformed("PASSword"));
+ CuAssertTrue(tc, password_wellformed("1234567"));
+ CuAssertTrue(tc, !password_wellformed("$password"));
+ CuAssertTrue(tc, !password_wellformed("no space"));
+
+ test_setup();
+ mt_create_error(283);
+ mt_create_error(321);
+ mt_create_va(mt_new("changepasswd", NULL), "value:string", MT_NEW_END);
+ u = test_create_unit(f = test_create_faction(NULL), test_create_plain(0, 0));
+ u->thisorder = create_order(K_PASSWORD, f->locale, "password1234", NULL);
+ password_cmd(u, u->thisorder);
+ CuAssertTrue(tc, checkpasswd(f, "password1234"));
+ CuAssertPtrNotNull(tc, msg = test_find_messagetype(f->msgs, "changepasswd"));
+ free_order(u->thisorder);
+ test_clear_messages(f);
+
+ u->thisorder = create_order(K_PASSWORD, f->locale, "bad-password", NULL);
+ password_cmd(u, u->thisorder);
+ CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error283"));
+ CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
+ CuAssertTrue(tc, !checkpasswd(f, "password1234"));
+ free_order(u->thisorder);
+ test_clear_messages(f);
+
+ u->thisorder = create_order(K_PASSWORD, f->locale, "''", NULL);
+ password_cmd(u, u->thisorder);
+ CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error283"));
+ CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
+ free_order(u->thisorder);
+ test_clear_messages(f);
+
+ u->thisorder = create_order(K_PASSWORD, f->locale, NULL);
+ password_cmd(u, u->thisorder);
+ CuAssertTrue(tc, !checkpasswd(f, "password1234"));
+ CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error283"));
+ CuAssertPtrNotNull(tc, msg = test_find_messagetype(f->msgs, "changepasswd"));
+ free_order(u->thisorder);
+ test_clear_messages(f);
+
+ u->thisorder = create_order(K_PASSWORD, f->locale, "1234567890123456789012345678901234567890");
+ password_cmd(u, u->thisorder);
+ CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error321"));
+ CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
+ CuAssertTrue(tc, checkpasswd(f, "1234567890123456789012345678901"));
+
+ test_teardown();
+}
+
static void test_peasant_migration(CuTest *tc) {
region *r1, *r2;
int rmax;
diff --git a/src/randenc.c b/src/randenc.c
index 368a839e9..356c9c695 100644
--- a/src/randenc.c
+++ b/src/randenc.c
@@ -587,7 +587,8 @@ void plagues(region * r)
}
if (dead > 0) {
- ADDMSG(&r->msgs, msg_message("pest", "dead", dead));
+ ADDMSG(&r->msgs, msg_message("pest", "peasants dead",
+ get_resourcetype(R_PEASANT), dead));
deathcounts(r, dead);
rsetpeasants(r, peasants - dead);
}
diff --git a/src/report.c b/src/report.c
index 392ede0da..c69ddcdab 100644
--- a/src/report.c
+++ b/src/report.c
@@ -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) &&
diff --git a/src/spells.c b/src/spells.c
index 3c6a9304a..e5d0191af 100644
--- a/src/spells.c
+++ b/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,
@@ -5328,7 +5283,6 @@ int sp_fetchastral(castorder * co)
spellparameter *pa = co->par;
double power = co->force;
int remaining_cap = (int)((power - 3) * 1500);
- region_list *rtl = NULL;
region *rt = co_get_region(co); /* region to which we are fetching */
region *ro = NULL; /* region in which the target is */
@@ -5350,21 +5304,13 @@ int sp_fetchastral(castorder * co)
if (u->region != ro) {
/* this can happen several times if the units are from different astral
* regions. Only possible on the intersections of schemes */
- region_list *rfind;
if (!is_astral(u->region)) {
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
"spellfail_astralonly", ""));
continue;
}
- if (rtl != NULL)
- free_regionlist(rtl);
- rtl = astralregions(u->region, NULL);
- for (rfind = rtl; rfind != NULL; rfind = rfind->next) {
- if (rfind->data == mage->region)
- break;
- }
- if (rfind == NULL) {
+ if (r_standard_to_astral(mage->region) != u->region) {
/* the region r is not in the schemes of rt */
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
"spellfail_distance", "target", u));
@@ -5446,8 +5392,6 @@ int sp_fetchastral(castorder * co)
if (m)
msg_release(m);
}
- if (rtl != NULL)
- free_regionlist(rtl);
return cast_level;
}
@@ -5545,11 +5489,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 +5503,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 +5564,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 */
diff --git a/src/teleport.c b/src/teleport.c
index c59c92c40..590c458be 100644
--- a/src/teleport.c
+++ b/src/teleport.c
@@ -43,37 +43,6 @@ static region *tpregion(const region * r)
return rt;
}
-region_list *astralregions(const region * r, bool(*valid) (const region *))
-{
- region_list *rlist = NULL;
- int x, y;
-
- assert(is_astral(r));
- if (!is_astral(r)) {
- log_error("astralregions was called with a non-astral region.\n");
- return NULL;
- }
- r = r_astral_to_standard(r);
- if (r == NULL)
- return NULL;
-
- for (x = -TP_RADIUS; x <= +TP_RADIUS; ++x) {
- for (y = -TP_RADIUS; y <= +TP_RADIUS; ++y) {
- region *rn;
- int dist = koor_distance(0, 0, x, y);
- int nx = r->x + x, ny = r->y + y;
-
- if (dist > TP_RADIUS)
- continue;
- pnormalize(&nx, &ny, rplane(r));
- rn = findregion(nx, ny);
- if (rn != NULL && (valid == NULL || valid(rn)))
- add_regionlist(&rlist, rn);
- }
- }
- return rlist;
-}
-
int get_astralregions(const region * r, bool(*valid) (const region *), region *result[])
{
@@ -91,7 +60,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;
}
}
}
diff --git a/src/teleport.h b/src/teleport.h
index cb225e978..72815f497 100644
--- a/src/teleport.h
+++ b/src/teleport.h
@@ -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;
@@ -15,8 +16,6 @@ extern "C" {
struct region *r_standard_to_astral(const struct region *r);
struct region *r_astral_to_standard(const struct region *);
- struct region_list *astralregions(const struct region *rastral,
- bool(*valid) (const struct region *));
struct region_list *all_in_range(const struct region *r, int n,
bool(*valid) (const struct region *));
bool inhabitable(const struct region *r);