diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8da9e1e64..d083ef3b1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -88,6 +88,7 @@ set (ERESSEA_SRC names.c lighthouse.c reports.c + teleport.c guard.c prefix.c donations.c diff --git a/src/bindings.c b/src/bindings.c index 48d40a1f4..938b75be8 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -45,7 +45,6 @@ without prior permission by the authors of Eressea. #include #include #include -#include #include #include #include @@ -54,6 +53,7 @@ without prior permission by the authors of Eressea. #include "creport.h" #include "economy.h" #include "summary.h" +#include "teleport.h" #include "laws.h" #include "monster.h" #include "market.h" diff --git a/src/creport.c b/src/creport.c index 9b0182252..186afab4d 100644 --- a/src/creport.c +++ b/src/creport.c @@ -36,6 +36,7 @@ without prior permission by the authors of Eressea. #include "move.h" #include "reports.h" #include "alchemy.h" +#include "teleport.h" /* kernel includes */ #include @@ -55,7 +56,6 @@ without prior permission by the authors of Eressea. #include #include #include -#include #include #include #include diff --git a/src/gmtool.c b/src/gmtool.c index 36f9fe753..3c50aaf45 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -19,6 +19,7 @@ #include "listbox.h" #include "wormhole.h" #include "calendar.h" +#include "teleport.h" #include #include @@ -36,7 +37,6 @@ #include #include #include -#include #include #include #include diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index b1c3bcd0f..fd8496f89 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -50,7 +50,6 @@ ship.c skills.c spellbook.c spell.c -teleport.c terrain.c unit.c xmlreader.c diff --git a/src/laws.c b/src/laws.c index adaa4a6cc..30bcbf096 100755 --- a/src/laws.c +++ b/src/laws.c @@ -36,6 +36,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "study.h" #include "wormhole.h" #include "prefix.h" +#include "teleport.h" #include "calendar.h" #include "guard.h" @@ -59,7 +60,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include /* for volcanoes in emigration (needs a flag) */ #include diff --git a/src/magic.c b/src/magic.c index dc6d6e9dc..48e0fc604 100644 --- a/src/magic.c +++ b/src/magic.c @@ -41,7 +41,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include @@ -1127,8 +1126,13 @@ double magic_resistance(unit * target) curse *c; const curse_type * ct_goodresist = 0, *ct_badresist = 0; const resource_type *rtype; - double probability = u_race(target)->magres; + const race *rc = u_race(target); + double probability = rc->magres; + const plane *pl = rplane(target->region); + if (rc == get_race(RC_HIRNTOETER) && !pl) { + probability /= 2; + } assert(target->number > 0); /* Magier haben einen Resistenzbonus vom Magietalent * 5% */ probability += effskill(target, SK_MAGIC, 0) * 0.05; @@ -1989,7 +1993,7 @@ static spellparameter *add_spellparameter(region * target_r, unit * u, case 'r': /* Parameter sind zwei Regionskoordinaten */ /* this silly thing only works in the normal plane! */ - j = addparam_region(param + i, &spobj, u, ord, get_normalplane()); + j = addparam_region(param + i, &spobj, u, ord, NULL); ++c; break; case 'b': diff --git a/src/magic.test.c b/src/magic.test.c index 6ed4d81a9..1f0995bc6 100644 --- a/src/magic.test.c +++ b/src/magic.test.c @@ -1,7 +1,9 @@ #include #include "magic.h" +#include "teleport.h" +#include #include #include #include @@ -402,6 +404,25 @@ void test_multi_cast(CuTest *tc) { test_cleanup(); } +static void test_magic_resistance(CuTest *tc) { + unit *u; + race *rc; + + test_cleanup(); + rc = test_create_race("human"); + u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); + CuAssertDblEquals(tc, rc->magres, magic_resistance(u), 0.01); + rc->magres = 1.0; + CuAssertDblEquals_Msg(tc, "magic resistance is capped at 0.9", 0.9, magic_resistance(u), 0.01); + rc = test_create_race("braineater"); + rc->magres = 1.0; + u_setrace(u, rc); + CuAssertDblEquals_Msg(tc, "brain eaters outside astral space have 50% magres", 0.5, magic_resistance(u), 0.01); + u->region->_plane = get_astralplane(); + CuAssertDblEquals_Msg(tc, "brain eaters in astral space have full magres", 0.9, magic_resistance(u), 0.01); + test_cleanup(); +} + CuSuite *get_magic_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -417,5 +438,6 @@ CuSuite *get_magic_suite(void) SUITE_ADD_TEST(suite, test_set_main_combatspell); SUITE_ADD_TEST(suite, test_set_post_combatspell); SUITE_ADD_TEST(suite, test_hasspell); + SUITE_ADD_TEST(suite, test_magic_resistance); return suite; } diff --git a/src/move.c b/src/move.c index 04a50b45d..19b0b86af 100644 --- a/src/move.c +++ b/src/move.c @@ -44,13 +44,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include #include +#include "teleport.h" #include "direction.h" #include "calendar.h" #include "skill.h" diff --git a/src/report.c b/src/report.c index f22cb6049..323a94f02 100644 --- a/src/report.c +++ b/src/report.c @@ -42,6 +42,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "upkeep.h" #include "vortex.h" #include "calendar.h" +#include "teleport.h" /* kernel includes */ #include @@ -65,7 +66,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/seen.h b/src/seen.h index de600d353..1f0197cc7 100644 --- a/src/seen.h +++ b/src/seen.h @@ -43,7 +43,7 @@ extern "C" { struct seen_region *next; struct region *r; seen_t mode; - bool disbelieves; + bool disbelieves; /* potion of truth */ } seen_region; struct seen_region **seen_init(void); diff --git a/src/spells.c b/src/spells.c index 1445598d9..6724f39a5 100644 --- a/src/spells.c +++ b/src/spells.c @@ -22,6 +22,7 @@ #include "direction.h" #include "randenc.h" #include "monster.h" +#include "teleport.h" #include #include @@ -49,7 +50,6 @@ #include #include #include -#include #include #include #include @@ -3146,7 +3146,7 @@ static int sp_chaossuction(castorder * co) unit *mage = co->magician.u; int cast_level = co->level; - if (getplane(r) != get_normalplane()) { + if (rplane(r)) { /* Der Zauber funktioniert nur in der materiellen Welt. */ cmistake(mage, co->order, 190, MSG_MAGIC); return 0; @@ -5436,8 +5436,9 @@ int sp_fetchastral(castorder * co) region *rt = co_get_region(co); /* region to which we are fetching */ region *ro = NULL; /* region in which the target is */ - if (rplane(rt) != get_normalplane()) { - ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "error190", "")); + if (rplane(rt)) { + /* Der Zauber funktioniert nur in der materiellen Welt. */ + cmistake(mage, co->order, 190, MSG_MAGIC); return 0; } diff --git a/src/kernel/teleport.c b/src/teleport.c similarity index 93% rename from src/kernel/teleport.c rename to src/teleport.c index 59b18ade8..f0f2c8996 100644 --- a/src/kernel/teleport.c +++ b/src/teleport.c @@ -21,19 +21,19 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "teleport.h" /* kernel includes */ -#include "equipment.h" -#include "unit.h" -#include "region.h" -#include "race.h" -#include "skill.h" -#include "terrain.h" -#include "faction.h" -#include "plane.h" +#include +#include +#include +#include +#include +#include +#include /* util includes */ #include #include +#include "skill.h" #include "monster.h" /* libc includes */ @@ -96,8 +96,7 @@ region_list *astralregions(const region * r, bool(*valid) (const region *)) region *r_standard_to_astral(const region * r) { - if (rplane(r) != get_normalplane()) - return NULL; + assert(!rplane(r)); return tpregion(r); } @@ -109,9 +108,9 @@ region *r_astral_to_standard(const region * r) assert(is_astral(r)); x = (r->x - TE_CENTER_X) * TP_DISTANCE; y = (r->y - TE_CENTER_Y) * TP_DISTANCE; - pnormalize(&x, &y, get_normalplane()); + pnormalize(&x, &y, NULL); r2 = findregion(x, y); - if (r2 == NULL || rplane(r2) != get_normalplane()) + if (r2 == NULL || rplane(r2)) return NULL; return r2; @@ -168,11 +167,6 @@ void spawn_braineaters(float chance) } } -plane *get_normalplane(void) -{ - return NULL; -} - bool is_astral(const region * r) { plane *pl = get_astralplane(); diff --git a/src/kernel/teleport.h b/src/teleport.h similarity index 97% rename from src/kernel/teleport.h rename to src/teleport.h index d0e8f86a9..cc0a3f143 100644 --- a/src/kernel/teleport.h +++ b/src/teleport.h @@ -31,7 +31,6 @@ extern "C" { extern bool inhabitable(const struct region *r); extern bool is_astral(const struct region *r); extern struct plane *get_astralplane(void); - extern struct plane *get_normalplane(void); void create_teleport_plane(void); void set_teleport_plane_regiontypes(void);