forked from github/server
do not call log10(0) for new lighthouses.
some tests for LEARN MAGIC.
This commit is contained in:
parent
3a438ffd4f
commit
5dc9ccb03e
|
@ -522,7 +522,7 @@ static void test_pay_cmd_other_building(CuTest *tc) {
|
||||||
building *b;
|
building *b;
|
||||||
char cmd[32];
|
char cmd[32];
|
||||||
|
|
||||||
test_cleanup();
|
test_setup();
|
||||||
setup_pay_cmd(&fix);
|
setup_pay_cmd(&fix);
|
||||||
f = fix.u1->faction;
|
f = fix.u1->faction;
|
||||||
b = test_create_building(fix.u1->region, bt_get_or_create("lighthouse"));
|
b = test_create_building(fix.u1->region, bt_get_or_create("lighthouse"));
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <kernel/region.h>
|
#include <kernel/region.h>
|
||||||
#include <kernel/terrain.h>
|
#include <kernel/terrain.h>
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
|
#include <util/log.h>
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -25,14 +26,12 @@ static attrib_type at_lighthouse = {
|
||||||
*/
|
*/
|
||||||
void update_lighthouse(building * lh)
|
void update_lighthouse(building * lh)
|
||||||
{
|
{
|
||||||
if (is_building_type(lh->type, "lighthouse")) {
|
if (lh->size>0 && is_building_type(lh->type, "lighthouse")) {
|
||||||
region *r = lh->region;
|
region *r = lh->region;
|
||||||
int d = (int)log10(lh->size) + 1;
|
int d = (int)log10(lh->size) + 1;
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
if (lh->size > 0) {
|
|
||||||
r->flags |= RF_LIGHTHOUSE;
|
r->flags |= RF_LIGHTHOUSE;
|
||||||
}
|
|
||||||
|
|
||||||
for (x = -d; x <= d; ++x) {
|
for (x = -d; x <= d; ++x) {
|
||||||
int y;
|
int y;
|
||||||
|
@ -40,6 +39,7 @@ void update_lighthouse(building * lh)
|
||||||
attrib *a;
|
attrib *a;
|
||||||
region *r2;
|
region *r2;
|
||||||
int px = r->x + x, py = r->y + y;
|
int px = r->x + x, py = r->y + y;
|
||||||
|
|
||||||
pnormalize(&px, &py, rplane(r));
|
pnormalize(&px, &py, rplane(r));
|
||||||
r2 = findregion(px, py);
|
r2 = findregion(px, py);
|
||||||
if (!r2 || !fval(r2->terrain, SEA_REGION))
|
if (!r2 || !fval(r2->terrain, SEA_REGION))
|
||||||
|
|
|
@ -318,15 +318,58 @@ static void test_study_cmd(CuTest *tc) {
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_study_magic(CuTest *tc) {
|
||||||
|
unit *u;
|
||||||
|
faction *f;
|
||||||
|
const struct locale *lang;
|
||||||
|
const struct resource_type *rtype;
|
||||||
|
|
||||||
|
test_setup();
|
||||||
|
init_resources();
|
||||||
|
f = test_create_faction(0);
|
||||||
|
u = test_create_unit(f, test_create_region(0, 0, 0));
|
||||||
|
lang = f->locale;
|
||||||
|
CuAssertPtrNotNull(tc, rtype = get_resourcetype(R_SILVER));
|
||||||
|
u->thisorder = create_order(K_STUDY, lang, "%s", skillnames[SK_MAGIC]);
|
||||||
|
study_cmd(u, u->thisorder);
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error178"));
|
||||||
|
free_order(u->thisorder);
|
||||||
|
|
||||||
|
test_clear_messages(f);
|
||||||
|
u->thisorder = create_order(K_STUDY, lang, "%s %s", skillnames[SK_MAGIC], magic_school[M_GWYRRD]);
|
||||||
|
study_cmd(u, u->thisorder);
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error65"));
|
||||||
|
|
||||||
|
test_clear_messages(f);
|
||||||
|
i_change(&u->items, rtype->itype, 100);
|
||||||
|
study_cmd(u, u->thisorder);
|
||||||
|
CuAssertIntEquals(tc, M_GWYRRD, f->magiegebiet);
|
||||||
|
CuAssertIntEquals(tc, 0, i_get(u->items, rtype->itype));
|
||||||
|
CuAssertPtrNotNull(tc, get_mage(u));
|
||||||
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error65"));
|
||||||
|
CuAssertIntEquals(tc, M_GWYRRD, get_mage(u)->magietyp);
|
||||||
|
|
||||||
|
/* the static cost array in study_cost prevents this test:
|
||||||
|
test_clear_messages(f);
|
||||||
|
config_set("skills.cost.magic", "50");
|
||||||
|
i_change(&u->items, rtype->itype, 50);
|
||||||
|
study_cmd(u, u->thisorder);
|
||||||
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error65"));
|
||||||
|
*/
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
static void test_study_cost(CuTest *tc) {
|
static void test_study_cost(CuTest *tc) {
|
||||||
unit *u;
|
unit *u;
|
||||||
const struct item_type *itype;
|
const struct item_type *itype;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
init_resources();
|
init_resources();
|
||||||
itype = get_resourcetype(R_SILVER)->itype;
|
itype = get_resourcetype(R_SILVER)->itype;
|
||||||
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
||||||
scale_number(u, 2);
|
scale_number(u, 2);
|
||||||
u->thisorder = create_order(K_STUDY, u->faction->locale, "ALCHEMY");
|
u->thisorder = create_order(K_STUDY, u->faction->locale, skillnames[SK_ALCHEMY]);
|
||||||
i_change(&u->items, itype, u->number * study_cost(u, SK_ALCHEMY));
|
i_change(&u->items, itype, u->number * study_cost(u, SK_ALCHEMY));
|
||||||
learn_inject();
|
learn_inject();
|
||||||
study_cmd(u, u->thisorder);
|
study_cmd(u, u->thisorder);
|
||||||
|
@ -505,6 +548,7 @@ CuSuite *get_study_suite(void)
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_study_cmd);
|
SUITE_ADD_TEST(suite, test_study_cmd);
|
||||||
SUITE_ADD_TEST(suite, test_study_cost);
|
SUITE_ADD_TEST(suite, test_study_cost);
|
||||||
|
SUITE_ADD_TEST(suite, test_study_magic);
|
||||||
SUITE_ADD_TEST(suite, test_teach_cmd);
|
SUITE_ADD_TEST(suite, test_teach_cmd);
|
||||||
SUITE_ADD_TEST(suite, test_teach_two);
|
SUITE_ADD_TEST(suite, test_teach_two);
|
||||||
SUITE_ADD_TEST(suite, test_teach_one_to_many);
|
SUITE_ADD_TEST(suite, test_teach_one_to_many);
|
||||||
|
|
21
src/tests.c
21
src/tests.c
|
@ -94,16 +94,14 @@ struct locale * test_create_locale(void) {
|
||||||
for (i = 0; i != MAXKEYWORDS; ++i) {
|
for (i = 0; i != MAXKEYWORDS; ++i) {
|
||||||
locale_setstring(loc, mkname("keyword", keywords[i]), keywords[i]);
|
locale_setstring(loc, mkname("keyword", keywords[i]), keywords[i]);
|
||||||
}
|
}
|
||||||
for (i = 0; i != MAXSKILLS; ++i) {
|
|
||||||
locale_setstring(loc, mkname("skill", skillnames[i]), skillnames[i]);
|
|
||||||
}
|
|
||||||
for (i = 0; i != MAXPARAMS; ++i) {
|
for (i = 0; i != MAXPARAMS; ++i) {
|
||||||
locale_setstring(loc, parameters[i], parameters[i]);
|
locale_setstring(loc, parameters[i], parameters[i]);
|
||||||
test_translate_param(loc, i, parameters[i]);
|
test_translate_param(loc, i, parameters[i]);
|
||||||
}
|
}
|
||||||
init_parameters(loc);
|
for (i = 0; i != MAXMAGIETYP; ++i) {
|
||||||
init_keywords(loc);
|
locale_setstring(loc, mkname("school", magic_school[i]), magic_school[i]);
|
||||||
init_skills(loc);
|
}
|
||||||
|
init_locale(loc);
|
||||||
}
|
}
|
||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
|
@ -163,6 +161,13 @@ static void test_reset(void) {
|
||||||
int i;
|
int i;
|
||||||
turn = 0;
|
turn = 0;
|
||||||
default_locale = 0;
|
default_locale = 0;
|
||||||
|
|
||||||
|
if (errno) {
|
||||||
|
int error = errno;
|
||||||
|
errno = 0;
|
||||||
|
log_error("errno: %d (%s)", error, strerror(error));
|
||||||
|
}
|
||||||
|
|
||||||
free_gamedata();
|
free_gamedata();
|
||||||
free_terrains();
|
free_terrains();
|
||||||
free_resources();
|
free_resources();
|
||||||
|
@ -184,13 +189,13 @@ static void test_reset(void) {
|
||||||
for (i = 0; i != MAXKEYWORDS; ++i) {
|
for (i = 0; i != MAXKEYWORDS; ++i) {
|
||||||
enable_keyword(i, true);
|
enable_keyword(i, true);
|
||||||
}
|
}
|
||||||
|
random_source_reset();
|
||||||
|
|
||||||
if (errno) {
|
if (errno) {
|
||||||
int error = errno;
|
int error = errno;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
log_error("errno: %d (%s)", error, strerror(error));
|
log_error("errno: %d (%s)", error, strerror(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
random_source_reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_setup(void) {
|
void test_setup(void) {
|
||||||
|
|
Loading…
Reference in New Issue