forked from github/server
Merge pull request #465 from eressea/feature/issue-464-stonecircles
fix crash when aging stone circles without an astral plane
This commit is contained in:
commit
cebea47720
2 changed files with 54 additions and 53 deletions
43
src/laws.c
43
src/laws.c
|
@ -3019,15 +3019,6 @@ int renumber_cmd(unit * u, order * ord)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static building *age_building(building * b)
|
|
||||||
{
|
|
||||||
const struct building_type *bt_blessed;
|
|
||||||
const struct curse_type *ct_astralblock;
|
|
||||||
const struct resource_type *rtype = get_resourcetype(R_UNICORN);
|
|
||||||
|
|
||||||
bt_blessed = bt_find("blessedstonecircle");
|
|
||||||
ct_astralblock = ct_find("astralblock");
|
|
||||||
|
|
||||||
/* blesses stone circles create an astral protection in the astral region
|
/* blesses stone circles create an astral protection in the astral region
|
||||||
* above the shield, which prevents chaos suction and other spells.
|
* above the shield, which prevents chaos suction and other spells.
|
||||||
* The shield is created when a magician enters the blessed stone circle,
|
* The shield is created when a magician enters the blessed stone circle,
|
||||||
|
@ -3035,16 +3026,19 @@ static building *age_building(building * b)
|
||||||
*
|
*
|
||||||
* TODO: this would be nicer in a btype->age function, but we don't have it.
|
* TODO: this would be nicer in a btype->age function, but we don't have it.
|
||||||
*/
|
*/
|
||||||
if (rtype && ct_astralblock && bt_blessed && b->type == bt_blessed) {
|
static void age_stonecircle(building *b) {
|
||||||
|
const struct resource_type *rtype = get_resourcetype(R_UNICORN);
|
||||||
region *r = b->region;
|
region *r = b->region;
|
||||||
region *rt = r_standard_to_astral(r);
|
|
||||||
unit *u, *mage = NULL;
|
unit *u, *mage = NULL;
|
||||||
|
|
||||||
/* step 1: give unicorns to people in the building,
|
/* step 1: give unicorns to people in the building,
|
||||||
* find out if there's a magician in there. */
|
* find out if there's a magician in there. */
|
||||||
for (u = r->units; u; u = u->next) {
|
for (u = r->units; u; u = u->next) {
|
||||||
if (b == u->building && inside_building(u)) {
|
if (b == u->building && inside_building(u)) {
|
||||||
if ((u_race(u)->ec_flags & ECF_KEEP_ITEM) == 0) {
|
if (!mage && is_mage(u)) {
|
||||||
|
mage = u;
|
||||||
|
}
|
||||||
|
if (rtype && (u_race(u)->ec_flags & ECF_KEEP_ITEM) == 0) {
|
||||||
int n, unicorns = 0;
|
int n, unicorns = 0;
|
||||||
for (n = 0; n != u->number; ++n) {
|
for (n = 0; n != u->number; ++n) {
|
||||||
if (chance(0.02)) {
|
if (chance(0.02)) {
|
||||||
|
@ -3058,18 +3052,17 @@ static building *age_building(building * b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mage == NULL && is_mage(u)) {
|
|
||||||
mage = u;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if there's a magician, and a connection to astral space, create the
|
/* step 2: if there's a magician, and a connection to astral space, create the
|
||||||
* curse. */
|
* curse. */
|
||||||
if (rt && !fval(rt->terrain, FORBIDDEN_REGION) && mage != NULL) {
|
if (get_astralplane()) {
|
||||||
|
region *rt = r_standard_to_astral(r);
|
||||||
|
if (mage && rt && !fval(rt->terrain, FORBIDDEN_REGION)) {
|
||||||
|
const struct curse_type *ct_astralblock = ct_find("astralblock");
|
||||||
curse *c = get_curse(rt->attribs, ct_astralblock);
|
curse *c = get_curse(rt->attribs, ct_astralblock);
|
||||||
if (c == NULL) {
|
if (!c) {
|
||||||
if (mage != NULL) {
|
|
||||||
int sk = effskill(mage, SK_MAGIC, 0);
|
int sk = effskill(mage, SK_MAGIC, 0);
|
||||||
float effect = 100;
|
float effect = 100;
|
||||||
/* the mage reactivates the circle */
|
/* the mage reactivates the circle */
|
||||||
|
@ -3078,15 +3071,23 @@ static building *age_building(building * b)
|
||||||
ADDMSG(&r->msgs,
|
ADDMSG(&r->msgs,
|
||||||
msg_message("astralshield_activate", "region unit", r, mage));
|
msg_message("astralshield_activate", "region unit", r, mage));
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
else if (mage != NULL) {
|
|
||||||
int sk = effskill(mage, SK_MAGIC, 0);
|
int sk = effskill(mage, SK_MAGIC, 0);
|
||||||
c->duration = _max(c->duration, sk / 2);
|
c->duration = _max(c->duration, sk / 2);
|
||||||
c->vigour = _max(c->vigour, (float)sk);
|
c->vigour = _max(c->vigour, (float)sk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static building *age_building(building * b)
|
||||||
|
{
|
||||||
|
const struct building_type *bt_blessed;
|
||||||
|
|
||||||
|
bt_blessed = bt_find("blessedstonecircle");
|
||||||
|
if (bt_blessed && b->type == bt_blessed) {
|
||||||
|
age_stonecircle(b);
|
||||||
|
}
|
||||||
a_age(&b->attribs, b);
|
a_age(&b->attribs, b);
|
||||||
handle_event(b->attribs, "timer", b);
|
handle_event(b->attribs, "timer", b);
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ region_list *astralregions(const region * r, bool(*valid) (const region *))
|
||||||
|
|
||||||
region *r_standard_to_astral(const region * r)
|
region *r_standard_to_astral(const region * r)
|
||||||
{
|
{
|
||||||
assert(!rplane(r));
|
assert(!is_astral(r));
|
||||||
return tpregion(r);
|
return tpregion(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue