diff --git a/src/spells.h b/src/spells.h index 3b6280e83..39157aaf6 100644 --- a/src/spells.h +++ b/src/spells.h @@ -22,11 +22,10 @@ extern "C" { #endif + struct castorder; struct curse_type; struct region; struct unit; - struct faction; - struct region; struct message; extern const struct curse_type ct_magicresistance; @@ -34,8 +33,9 @@ extern "C" { void register_magicresistance(void); void register_spells(void); - int sp_baddreams(castorder * co); - int sp_gooddreams(castorder * co); + int sp_baddreams(struct castorder * co); + int sp_gooddreams(struct castorder * co); + int sp_viewreality(struct castorder * co); #define ACTION_RESET 0x01 /* reset the one-time-flag FFL_SELECT (on first pass) */ #define ACTION_CANSEE 0x02 /* to people who can see the actor */ diff --git a/src/spells.test.c b/src/spells.test.c index cd72f0177..638d1e858 100644 --- a/src/spells.test.c +++ b/src/spells.test.c @@ -1,11 +1,13 @@ #include #include "spells.h" +#include "teleport.h" #include #include #include #include +#include #include #include #include @@ -113,6 +115,40 @@ static void test_bad_dreams(CuTest *tc) { test_cleanup(); } +static void test_view_reality(CuTest *tc) { + region *r, *ra; + faction *f; + unit *u; + castorder co; + + test_setup(); + r = test_create_region(0, 0, NULL); + ra = test_create_region(real2tp(r->x), real2tp(r->y), NULL); + ra->_plane = get_astralplane(); + f = test_create_faction(0); + u = test_create_unit(f, r); + + test_create_castorder(&co, u, 10, 10., 0, NULL); + CuAssertIntEquals(tc, -1, get_observer(r, f)); + CuAssertIntEquals(tc, 0, sp_viewreality(&co)); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "spell_astral_only")); + free_castorder(&co); + + test_clear_messagelist(&f->msgs); + move_unit(u, ra, NULL); + + test_create_castorder(&co, u, 9, 10., 0, NULL); + CuAssertIntEquals(tc, -1, get_observer(r, f)); + CuAssertIntEquals(tc, 9, sp_viewreality(&co)); + CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "spell_astral_only")); + CuAssertIntEquals(tc, 4, get_observer(r, f)); + CuAssertPtrEquals(tc, f, (void *)ra->individual_messages->viewer); + CuAssertPtrNotNull(tc, test_find_messagetype(ra->individual_messages->msgs, "viewreality_effect")); + free_castorder(&co); + + test_cleanup(); +} + static void test_watch_region(CuTest *tc) { region *r; faction *f; @@ -133,6 +169,7 @@ CuSuite *get_spells_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_watch_region); + SUITE_ADD_TEST(suite, test_view_reality); SUITE_ADD_TEST(suite, test_good_dreams); SUITE_ADD_TEST(suite, test_bad_dreams); SUITE_ADD_TEST(suite, test_dreams); diff --git a/src/teleport.c b/src/teleport.c index 78098c264..c529d5129 100644 --- a/src/teleport.c +++ b/src/teleport.c @@ -39,25 +39,24 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* libc includes */ #include -#define TE_CENTER_X 1000 -#define TE_CENTER_Y 1000 +#define TE_CENTER 1000 #define TP_RADIUS 2 #define TP_DISTANCE 4 -static int real2tp(int rk) +int real2tp(int rk) { /* in C: * -4 / 5 = 0; * +4 / 5 = 0; * !!!!!!!!!!; */ - return (rk + (TP_DISTANCE * 5000)) / TP_DISTANCE - 5000; + return TE_CENTER + (rk + (TP_DISTANCE * 5000)) / TP_DISTANCE - 5000; } static region *tpregion(const region * r) { region *rt = - findregion(TE_CENTER_X + real2tp(r->x), TE_CENTER_Y + real2tp(r->y)); + findregion(real2tp(r->x), real2tp(r->y)); if (!is_astral(rt)) return NULL; return rt; @@ -106,8 +105,8 @@ region *r_astral_to_standard(const region * r) region *r2; assert(is_astral(r)); - x = (r->x - TE_CENTER_X) * TP_DISTANCE; - y = (r->y - TE_CENTER_Y) * TP_DISTANCE; + x = (r->x - TE_CENTER) * TP_DISTANCE; + y = (r->y - TE_CENTER) * TP_DISTANCE; pnormalize(&x, &y, NULL); r2 = findregion(x, y); if (r2 == NULL || rplane(r2)) @@ -188,8 +187,8 @@ plane *get_astralplane(void) astralspace = getplanebyname("Astralraum"); if (!astralspace) { astralspace = create_new_plane(1, "Astralraum", - TE_CENTER_X - 500, TE_CENTER_X + 500, - TE_CENTER_Y - 500, TE_CENTER_Y + 500, 0); + TE_CENTER - 500, TE_CENTER + 500, + TE_CENTER - 500, TE_CENTER + 500, 0); } return astralspace; } @@ -208,8 +207,8 @@ void create_teleport_plane(void) region *ra = tpregion(r); if (ra == NULL) { - int x = TE_CENTER_X + real2tp(r->x); - int y = TE_CENTER_Y + real2tp(r->y); + int x = real2tp(r->x); + int y = real2tp(r->y); pnormalize(&x, &y, aplane); ra = new_region(x, y, aplane, 0); diff --git a/src/teleport.h b/src/teleport.h index cc0a3f143..153c0114b 100644 --- a/src/teleport.h +++ b/src/teleport.h @@ -18,24 +18,32 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef TELEPORT_H #define TELEPORT_H + +#include + #ifdef __cplusplus extern "C" { #endif + struct region; + struct region_list; + struct plane; + struct region *r_standard_to_astral(const struct region *r); struct region *r_astral_to_standard(const struct region *); - extern struct region_list *astralregions(const struct region *rastral, + struct region_list *astralregions(const struct region *rastral, bool(*valid) (const struct region *)); - extern struct region_list *all_in_range(const struct region *r, int n, + struct region_list *all_in_range(const struct region *r, int n, bool(*valid) (const struct region *)); - extern bool inhabitable(const struct region *r); - extern bool is_astral(const struct region *r); - extern struct plane *get_astralplane(void); + bool inhabitable(const struct region *r); + bool is_astral(const struct region *r); + struct plane *get_astralplane(void); void create_teleport_plane(void); - void set_teleport_plane_regiontypes(void); void spawn_braineaters(float chance); + int real2tp(int rk); + #ifdef __cplusplus } #endif