BUG 2366: add a test to verify that view_reality sets an observer.

This commit is contained in:
Enno Rehling 2017-10-10 18:45:44 +02:00
parent 0ffb4e3ca9
commit 9d48bfc36c
4 changed files with 65 additions and 21 deletions

View File

@ -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 */

View File

@ -1,11 +1,13 @@
#include <platform.h>
#include "spells.h"
#include "teleport.h"
#include <kernel/config.h>
#include <kernel/curse.h>
#include <kernel/faction.h>
#include <kernel/order.h>
#include <kernel/plane.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/spell.h>
@ -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);

View File

@ -39,25 +39,24 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* libc includes */
#include <assert.h>
#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);

View File

@ -18,24 +18,32 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifndef TELEPORT_H
#define TELEPORT_H
#include <stdbool.h>
#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