forked from github/server
adding more tests.
test for build() test for scale_number() update submodules
This commit is contained in:
parent
2ceeb0b819
commit
d435c13bfc
2
critbit
2
critbit
|
@ -1 +1 @@
|
|||
Subproject commit 2a7af5e2347217ea4efcf7fb3f0bc9c2681d1a17
|
||||
Subproject commit 4ab2cfe0a6dd6d57ebb460f9b824f68dba50b7de
|
|
@ -1 +1 @@
|
|||
Subproject commit f84066fb7d3254bdd9e89694acc4c1c20d001eed
|
||||
Subproject commit fe53382982d0f417b6f7ad0fe08e32393cb07c21
|
|
@ -4,6 +4,7 @@ SET(_TEST_FILES
|
|||
build.test.c
|
||||
config.test.c
|
||||
faction.test.c
|
||||
unit.test.c
|
||||
save.test.c
|
||||
ship.test.c
|
||||
spell.test.c
|
||||
|
|
|
@ -521,9 +521,7 @@ int build(unit * u, const construction * ctype, int completed, int want)
|
|||
}
|
||||
}
|
||||
|
||||
if (want > 0) {
|
||||
n = _min(want, n);
|
||||
}
|
||||
if (want < n) n = want;
|
||||
|
||||
if (type->maxsize > 0) {
|
||||
n = _min(type->maxsize - completed, n);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/alchemy.h>
|
||||
#include "types.h"
|
||||
#include "build.h"
|
||||
#include "order.h"
|
||||
|
@ -21,6 +22,7 @@ typedef struct build_fixture {
|
|||
unit *u;
|
||||
region *r;
|
||||
race *rc;
|
||||
construction cons;
|
||||
} build_fixture;
|
||||
|
||||
static unit * setup_build(build_fixture *bf) {
|
||||
|
@ -32,37 +34,159 @@ static unit * setup_build(build_fixture *bf) {
|
|||
assert(bf->rc && bf->f && bf->r);
|
||||
bf->u = test_create_unit(bf->f, bf->r);
|
||||
assert(bf->u);
|
||||
|
||||
bf->cons.materials = calloc(2, sizeof(requirement));
|
||||
bf->cons.materials[0].number = 1;
|
||||
bf->cons.materials[0].rtype = get_resourcetype(R_SILVER);
|
||||
bf->cons.skill = SK_ARMORER;
|
||||
bf->cons.minskill = 2;
|
||||
bf->cons.maxsize = -1;
|
||||
bf->cons.reqsize = 1;
|
||||
return bf->u;
|
||||
}
|
||||
|
||||
static void test_build(CuTest *tc) {
|
||||
build_fixture bf;
|
||||
static void test_build_requires_materials(CuTest *tc) {
|
||||
build_fixture bf = { 0 };
|
||||
unit *u;
|
||||
const struct item_type *itype;
|
||||
|
||||
u = setup_build(&bf);
|
||||
set_level(u, SK_ARMORER, 2);
|
||||
CuAssertIntEquals(tc, ENOMATERIALS, build(u, &bf.cons, 0, 1));
|
||||
itype = bf.cons.materials[0].rtype->itype;
|
||||
i_change(&u->items, itype, 2);
|
||||
CuAssertIntEquals(tc, 1, build(u, &bf.cons, 0, 1));
|
||||
CuAssertIntEquals(tc, 1, i_get(u->items, itype));
|
||||
}
|
||||
|
||||
static void test_build_requires_building(CuTest *tc) {
|
||||
build_fixture bf = { 0 };
|
||||
unit *u;
|
||||
const struct resource_type *rtype;
|
||||
building_type *btype;
|
||||
|
||||
u = setup_build(&bf);
|
||||
rtype = bf.cons.materials[0].rtype;
|
||||
i_change(&u->items, rtype->itype, 1);
|
||||
set_level(u, SK_ARMORER, 2);
|
||||
bf.cons.btype = btype = bt_get_or_create("hodor");
|
||||
btype->maxcapacity = 1;
|
||||
btype->capacity = 1;
|
||||
CuAssertIntEquals_Msg(tc, "must be inside a production building", EBUILDINGREQ, build(u, &bf.cons, 0, 1));
|
||||
u->building = test_create_building(u->region, btype);
|
||||
fset(u->building, BLD_WORKING);
|
||||
CuAssertIntEquals(tc, 1, build(u, &bf.cons, 0, 1));
|
||||
btype->maxcapacity = 0;
|
||||
CuAssertIntEquals_Msg(tc, "cannot build when production building capacity exceeded", EBUILDINGREQ, build(u, &bf.cons, 0, 1));
|
||||
}
|
||||
|
||||
static void test_build_failure_missing_skill(CuTest *tc) {
|
||||
build_fixture bf = { 0 };
|
||||
unit *u;
|
||||
construction cons = { 0 };
|
||||
const struct resource_type *rtype;
|
||||
|
||||
u = setup_build(&bf);
|
||||
rtype = get_resourcetype(R_SILVER);
|
||||
assert(rtype);
|
||||
|
||||
cons.materials = calloc(2, sizeof(requirement));
|
||||
cons.materials[0].number = 1;
|
||||
cons.materials[0].rtype = rtype;
|
||||
cons.skill = SK_ARMORER;
|
||||
cons.minskill = 2;
|
||||
cons.reqsize = 1;
|
||||
CuAssertIntEquals(tc, ENEEDSKILL, build(u, &cons, 1, 1));
|
||||
set_level(u, SK_ARMORER, 1);
|
||||
CuAssertIntEquals(tc, ELOWSKILL, build(u, &cons, 1, 1));
|
||||
set_level(u, SK_ARMORER, 2);
|
||||
CuAssertIntEquals(tc, ENOMATERIALS, build(u, &cons, 1, 1));
|
||||
rtype = bf.cons.materials[0].rtype;
|
||||
i_change(&u->items, rtype->itype, 1);
|
||||
CuAssertIntEquals(tc, 1, build(u, &cons, 1, 1));
|
||||
CuAssertIntEquals(tc, ENEEDSKILL, build(u, &bf.cons, 1, 1));
|
||||
}
|
||||
|
||||
static void test_build_failure_low_skill(CuTest *tc) {
|
||||
build_fixture bf = { 0 };
|
||||
unit *u;
|
||||
const struct resource_type *rtype;
|
||||
|
||||
u = setup_build(&bf);
|
||||
rtype = bf.cons.materials[0].rtype;
|
||||
i_change(&u->items, rtype->itype, 1);
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill-1);
|
||||
CuAssertIntEquals(tc, ELOWSKILL, build(u, &bf.cons, 0, 10));
|
||||
}
|
||||
|
||||
static void test_build_failure_completed(CuTest *tc) {
|
||||
build_fixture bf = { 0 };
|
||||
unit *u;
|
||||
const struct resource_type *rtype;
|
||||
|
||||
u = setup_build(&bf);
|
||||
rtype = bf.cons.materials[0].rtype;
|
||||
i_change(&u->items, rtype->itype, 1);
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill);
|
||||
bf.cons.maxsize = 1;
|
||||
CuAssertIntEquals(tc, ECOMPLETE, build(u, &bf.cons, bf.cons.maxsize, 10));
|
||||
CuAssertIntEquals(tc, 1, i_get(u->items, rtype->itype));
|
||||
}
|
||||
|
||||
static void test_build_limits(CuTest *tc) {
|
||||
build_fixture bf = { 0 };
|
||||
unit *u;
|
||||
const struct resource_type *rtype;
|
||||
|
||||
u = setup_build(&bf);
|
||||
rtype = bf.cons.materials[0].rtype;
|
||||
i_change(&u->items, rtype->itype, 1);
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill);
|
||||
CuAssertIntEquals(tc, 1, build(u, &bf.cons, 0, 10));
|
||||
CuAssertIntEquals(tc, 0, i_get(u->items, rtype->itype));
|
||||
|
||||
scale_number(u, 2);
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill);
|
||||
i_change(&u->items, rtype->itype, 2);
|
||||
CuAssertIntEquals(tc, 2, build(u, &cons, 2, 2));
|
||||
CuAssertIntEquals(tc, 2, build(u, &bf.cons, 0, 10));
|
||||
CuAssertIntEquals(tc, 0, i_get(u->items, rtype->itype));
|
||||
|
||||
scale_number(u, 2);
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill * 2);
|
||||
i_change(&u->items, rtype->itype, 4);
|
||||
CuAssertIntEquals(tc, 4, build(u, &bf.cons, 0, 10));
|
||||
CuAssertIntEquals(tc, 0, i_get(u->items, rtype->itype));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_build_with_ring(CuTest *tc) {
|
||||
build_fixture bf = { 0 };
|
||||
unit *u;
|
||||
item_type *ring;
|
||||
const struct resource_type *rtype;
|
||||
|
||||
u = setup_build(&bf);
|
||||
rtype = bf.cons.materials[0].rtype;
|
||||
ring = it_get_or_create(rt_get_or_create("roqf"));
|
||||
assert(rtype && ring);
|
||||
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill);
|
||||
i_change(&u->items, rtype->itype, 20);
|
||||
i_change(&u->items, ring, 1);
|
||||
CuAssertIntEquals(tc, 10, build(u, &bf.cons, 0, 20));
|
||||
CuAssertIntEquals(tc, 10, i_get(u->items, rtype->itype));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_build_with_potion(CuTest *tc) {
|
||||
build_fixture bf = { 0 };
|
||||
unit *u;
|
||||
const potion_type *ptype;
|
||||
const struct resource_type *rtype;
|
||||
|
||||
u = setup_build(&bf);
|
||||
rtype = bf.cons.materials[0].rtype;
|
||||
oldpotiontype[P_DOMORE] = ptype = new_potiontype(it_get_or_create(rt_get_or_create("hodor")), 1);
|
||||
assert(rtype && ptype);
|
||||
|
||||
i_change(&u->items, rtype->itype, 20);
|
||||
change_effect(u, ptype, 4);
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill);
|
||||
CuAssertIntEquals(tc, 2, build(u, &bf.cons, 0, 20));
|
||||
CuAssertIntEquals(tc, 18, i_get(u->items, rtype->itype));
|
||||
CuAssertIntEquals(tc, 3, get_effect(u, ptype));
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill*2);
|
||||
CuAssertIntEquals(tc, 4, build(u, &bf.cons, 0, 20));
|
||||
CuAssertIntEquals(tc, 2, get_effect(u, ptype));
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill);
|
||||
scale_number(u, 2); // OBS: this scales the effects, too:
|
||||
CuAssertIntEquals(tc, 4, get_effect(u, ptype));
|
||||
CuAssertIntEquals(tc, 4, build(u, &bf.cons, 0, 20));
|
||||
CuAssertIntEquals(tc, 2, get_effect(u, ptype));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
|
@ -82,7 +206,7 @@ static void test_build_building_no_materials(CuTest *tc) {
|
|||
|
||||
static void test_build_building_with_golem(CuTest *tc) {
|
||||
unit *u;
|
||||
build_fixture bf;
|
||||
build_fixture bf = { 0 };
|
||||
const building_type *btype;
|
||||
|
||||
u = setup_build(&bf);
|
||||
|
@ -92,7 +216,7 @@ static void test_build_building_with_golem(CuTest *tc) {
|
|||
assert(btype->construction);
|
||||
|
||||
set_level(bf.u, SK_BUILDING, 1);
|
||||
CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 4, 0));
|
||||
CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 1, 0));
|
||||
CuAssertPtrNotNull(tc, u->region->buildings);
|
||||
CuAssertIntEquals(tc, 1, u->region->buildings->size);
|
||||
CuAssertIntEquals(tc, 0, u->number);
|
||||
|
@ -124,7 +248,14 @@ static void test_build_building_success(CuTest *tc) {
|
|||
CuSuite *get_build_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_build);
|
||||
SUITE_ADD_TEST(suite, test_build_limits);
|
||||
SUITE_ADD_TEST(suite, test_build_failure_low_skill);
|
||||
SUITE_ADD_TEST(suite, test_build_failure_missing_skill);
|
||||
SUITE_ADD_TEST(suite, test_build_requires_materials);
|
||||
SUITE_ADD_TEST(suite, test_build_requires_building);
|
||||
SUITE_ADD_TEST(suite, test_build_failure_completed);
|
||||
SUITE_ADD_TEST(suite, test_build_with_ring);
|
||||
SUITE_ADD_TEST(suite, test_build_with_potion);
|
||||
SUITE_ADD_TEST(suite, test_build_building_success);
|
||||
SUITE_ADD_TEST(suite, test_build_building_with_golem);
|
||||
SUITE_ADD_TEST(suite, test_build_building_no_materials);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -74,7 +74,7 @@ attrib_type at_creator = {
|
|||
|
||||
#define UMAXHASH MAXUNITS
|
||||
static unit *unithash[UMAXHASH];
|
||||
static unit *delmarker = (unit *) unithash; /* a funny hack */
|
||||
static unit *delmarker = (unit *)unithash; /* a funny hack */
|
||||
|
||||
#define HASH_STATISTICS 1
|
||||
#if HASH_STATISTICS
|
||||
|
@ -134,7 +134,7 @@ static dead *deadhash[DMAXHASH];
|
|||
|
||||
static void dhash(int no, faction * f)
|
||||
{
|
||||
dead *hash = (dead *) calloc(1, sizeof(dead));
|
||||
dead *hash = (dead *)calloc(1, sizeof(dead));
|
||||
dead *old = deadhash[no % DMAXHASH];
|
||||
hash->no = no;
|
||||
hash->f = f;
|
||||
|
@ -177,7 +177,8 @@ static buddy *get_friends(const unit * u, int *numfriends)
|
|||
int allied = 0;
|
||||
if (get_param_int(global.parameters, "rules.alliances", 0) != 0) {
|
||||
allied = (f->alliance && f->alliance == u2->faction->alliance);
|
||||
} else if (alliedunit(u, u2->faction, HELP_MONEY)
|
||||
}
|
||||
else if (alliedunit(u, u2->faction, HELP_MONEY)
|
||||
&& alliedunit(u2, f, HELP_GIVE)) {
|
||||
allied = 1;
|
||||
}
|
||||
|
@ -196,7 +197,8 @@ static buddy *get_friends(const unit * u, int *numfriends)
|
|||
nf->unit = u2;
|
||||
nf->number = 0;
|
||||
*fr = nf;
|
||||
} else if (nf->faction == u2->faction
|
||||
}
|
||||
else if (nf->faction == u2->faction
|
||||
&& (u_race(u2)->ec_flags & GIVEITEM)) {
|
||||
/* we don't like to gift it to units that won't give it back */
|
||||
if ((u_race(nf->unit)->ec_flags & GIVEITEM) == 0) {
|
||||
|
@ -256,7 +258,8 @@ int gift_items(unit * u, int flags)
|
|||
i_merge(&u2->items, &u->items);
|
||||
u->items = NULL;
|
||||
break;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
u3 = u2;
|
||||
}
|
||||
}
|
||||
|
@ -318,7 +321,8 @@ int gift_items(unit * u, int flags)
|
|||
if (itm->number > 0 && (itm->type->flags & ITF_NOTLOST)) {
|
||||
itm_p = &itm->next;
|
||||
retval = -1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
i_remove(itm_p, itm);
|
||||
i_free(itm);
|
||||
}
|
||||
|
@ -444,7 +448,8 @@ const char *u_description(const unit * u, const struct locale *lang)
|
|||
{
|
||||
if (u->display && u->display[0]) {
|
||||
return u->display;
|
||||
} else if (u_race(u)->describe) {
|
||||
}
|
||||
else if (u_race(u)->describe) {
|
||||
return u_race(u)->describe(u, lang);
|
||||
}
|
||||
return NULL;
|
||||
|
@ -522,7 +527,7 @@ unit *utarget(const unit * u)
|
|||
return NULL;
|
||||
a = a_find(u->attribs, &at_target);
|
||||
assert(a || !"flag set, but no target found");
|
||||
return (unit *) a->data.v;
|
||||
return (unit *)a->data.v;
|
||||
}
|
||||
|
||||
void usettarget(unit * u, const unit * t)
|
||||
|
@ -534,7 +539,8 @@ void usettarget(unit * u, const unit * t)
|
|||
if (!t) {
|
||||
a_remove(&u->attribs, a);
|
||||
freset(u, UFL_TARGET);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
a->data.v = (void *)t;
|
||||
fset(u, UFL_TARGET);
|
||||
}
|
||||
|
@ -589,7 +595,8 @@ void usetsiege(unit * u, const struct building *t)
|
|||
if (!t) {
|
||||
a_remove(&u->attribs, a);
|
||||
freset(u, UFL_SIEGE);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
a->data.v = (void *)t;
|
||||
fset(u, UFL_SIEGE);
|
||||
}
|
||||
|
@ -628,7 +635,7 @@ bool ucontact(const unit * u, const unit * u2)
|
|||
/* Explizites KONTAKTIERE */
|
||||
for (ru = a_find(u->attribs, &at_contact); ru && ru->type == &at_contact;
|
||||
ru = ru->next) {
|
||||
if (((unit *) ru->data.v) == u2) {
|
||||
if (((unit *)ru->data.v) == u2) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -661,11 +668,11 @@ int resolve_unit(variant id, void *address)
|
|||
if (id.i != 0) {
|
||||
u = findunit(id.i);
|
||||
if (u == NULL) {
|
||||
*(unit **) address = NULL;
|
||||
*(unit **)address = NULL;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
*(unit **) address = u;
|
||||
*(unit **)address = u;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -780,7 +787,7 @@ ship *leftship(const unit * u)
|
|||
* Zeitpunkt noch auf ein existierendes Schiff zeigt! */
|
||||
|
||||
if (a)
|
||||
return (ship *) (a->data.v);
|
||||
return (ship *)(a->data.v);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -808,7 +815,7 @@ void leave_ship(unit * u)
|
|||
struct ship *sh = u->ship;
|
||||
|
||||
u->ship = 0;
|
||||
if (sh->_owner==u) {
|
||||
if (sh->_owner == u) {
|
||||
ship_update_owner(sh);
|
||||
sh->_owner = ship_owner(sh);
|
||||
}
|
||||
|
@ -820,9 +827,9 @@ void leave_building(unit * u)
|
|||
building * b = u->building;
|
||||
|
||||
u->building = 0;
|
||||
if (b->_owner==u) {
|
||||
if (b->_owner == u) {
|
||||
building_update_owner(b);
|
||||
assert(b->_owner!=u);
|
||||
assert(b->_owner != u);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -855,7 +862,8 @@ bool leave(unit * u, bool force)
|
|||
}
|
||||
if (u->building) {
|
||||
leave_building(u);
|
||||
} else if (u->ship) {
|
||||
}
|
||||
else if (u->ship) {
|
||||
leave_ship(u);
|
||||
}
|
||||
return true;
|
||||
|
@ -908,7 +916,8 @@ void move_unit(unit * u, region * r, unit ** ulist)
|
|||
#endif
|
||||
}
|
||||
translist(&u->region->units, ulist, u);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
addlist(ulist, u);
|
||||
}
|
||||
|
||||
|
@ -951,7 +960,8 @@ void transfermen(unit * u, unit * u2, int n)
|
|||
/* new unit, easy to solve */
|
||||
level = sv->level;
|
||||
weeks = sv->weeks;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
double dlevel = 0.0;
|
||||
|
||||
if (sv && sv->level) {
|
||||
|
@ -972,7 +982,8 @@ void transfermen(unit * u, unit * u2, int n)
|
|||
* next level */
|
||||
level = (int)dlevel;
|
||||
weeks = (level + 1) - (int)((dlevel - level) * (level + 1));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
/* make it harder to reach the next level.
|
||||
* weeks+level is the max difficulty, 1 - the fraction between
|
||||
* level and dlevel applied to the number of weeks between this
|
||||
|
@ -989,14 +1000,15 @@ void transfermen(unit * u, unit * u2, int n)
|
|||
assert(sn->weeks > 0 && sn->weeks <= sn->level * 2 + 1);
|
||||
assert(u2->number != 0 || (sn->level == sv->level
|
||||
&& sn->weeks == sv->weeks));
|
||||
} else if (sn) {
|
||||
}
|
||||
else if (sn) {
|
||||
remove_skill(u2, sk);
|
||||
sn = NULL;
|
||||
}
|
||||
}
|
||||
a = a_find(u->attribs, &at_effect);
|
||||
while (a && a->type == &at_effect) {
|
||||
effect_data *olde = (effect_data *) a->data.v;
|
||||
effect_data *olde = (effect_data *)a->data.v;
|
||||
if (olde->value)
|
||||
change_effect(u2, olde->type, olde->value);
|
||||
a = a->next;
|
||||
|
@ -1020,19 +1032,21 @@ void transfermen(unit * u, unit * u2, int n)
|
|||
a = a_find(u2->attribs, &at_effect);
|
||||
while (a && a->type == &at_effect) {
|
||||
attrib *an = a->next;
|
||||
effect_data *olde = (effect_data *) a->data.v;
|
||||
effect_data *olde = (effect_data *)a->data.v;
|
||||
int e = get_effect(u, olde->type);
|
||||
if (e != 0)
|
||||
change_effect(u2, olde->type, -e);
|
||||
a = an;
|
||||
}
|
||||
} else if (r->land) {
|
||||
}
|
||||
else if (r->land) {
|
||||
if ((u_race(u)->ec_flags & ECF_REC_ETHEREAL) == 0) {
|
||||
const race *rc = u_race(u);
|
||||
if (rc->ec_flags & ECF_REC_HORSES) { /* Zentauren an die Pferde */
|
||||
int h = rhorses(r) + n;
|
||||
rsethorses(r, h);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
int p = rpeasants(r);
|
||||
p += (int)(n * rc->recruit_multi);
|
||||
rsetpeasants(r, p);
|
||||
|
@ -1049,10 +1063,12 @@ struct building *inside_building(const struct unit *u)
|
|||
if (!fval(u->building, BLD_WORKING)) {
|
||||
/* Unterhalt nicht bezahlt */
|
||||
return NULL;
|
||||
} else if (u->building->size < u->building->type->maxsize) {
|
||||
}
|
||||
else if (u->building->size < u->building->type->maxsize) {
|
||||
/* Gebaeude noch nicht fertig */
|
||||
return NULL;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
int p = 0, cap = buildingcapacity(u->building);
|
||||
const unit *u2;
|
||||
for (u2 = u->region->units; u2; u2 = u2->next) {
|
||||
|
@ -1143,7 +1159,8 @@ bool learn_skill(unit * u, skill_t sk, double chance)
|
|||
if (sv->id == sk) {
|
||||
if (sv->weeks <= 1) {
|
||||
sk_set(sv, sv->level + 1);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sv->weeks--;
|
||||
}
|
||||
return true;
|
||||
|
@ -1258,7 +1275,7 @@ static int att_modification(const unit * u, skill_t sk)
|
|||
if (skillmod_ct) {
|
||||
attrib *a = a_find(u->attribs, &at_curse);
|
||||
while (a && a->type == &at_curse) {
|
||||
curse *c = (curse *) a->data.v;
|
||||
curse *c = (curse *)a->data.v;
|
||||
if (c->type == skillmod_ct && c->data.i == sk) {
|
||||
result += curse_geteffect(c);
|
||||
break;
|
||||
|
@ -1274,7 +1291,7 @@ static int att_modification(const unit * u, skill_t sk)
|
|||
double bonus = 0, malus = 0;
|
||||
attrib *a = a_find(u->region->attribs, &at_curse);
|
||||
while (a && a->type == &at_curse) {
|
||||
curse *c = (curse *) a->data.v;
|
||||
curse *c = (curse *)a->data.v;
|
||||
if (curse_active(c) && c->type == gbdream_ct) {
|
||||
double mod = curse_geteffect(c);
|
||||
unit *mage = c->magician;
|
||||
|
@ -1284,7 +1301,8 @@ static int att_modification(const unit * u, skill_t sk)
|
|||
|| alliedunit(mage, u->faction, HELP_GUARD)) {
|
||||
bonus = mod;
|
||||
}
|
||||
} else if (mod < malus) {
|
||||
}
|
||||
else if (mod < malus) {
|
||||
if (mage == NULL || !alliedunit(mage, u->faction, HELP_GUARD)) {
|
||||
malus = mod;
|
||||
}
|
||||
|
@ -1300,7 +1318,7 @@ static int att_modification(const unit * u, skill_t sk)
|
|||
|
||||
int
|
||||
get_modifier(const unit * u, skill_t sk, int level, const region * r,
|
||||
bool noitem)
|
||||
bool noitem)
|
||||
{
|
||||
int bskill = level;
|
||||
int skill = bskill;
|
||||
|
@ -1424,10 +1442,12 @@ void name_unit(unit * u)
|
|||
const char *gen_name = u_race(u)->generate_name(u);
|
||||
if (gen_name) {
|
||||
unit_setname(u, gen_name);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
unit_setname(u, racename(u->faction->locale, u, u_race(u)));
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
char name[32];
|
||||
const char * result;
|
||||
const struct locale * lang = u->faction ? u->faction->locale : default_locale;
|
||||
|
@ -1441,7 +1461,8 @@ void name_unit(unit * u)
|
|||
}
|
||||
}
|
||||
result = prefix[i];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
result = parameters[P_UNIT];
|
||||
}
|
||||
strlcpy(name, result, sizeof(name));
|
||||
|
@ -1495,7 +1516,8 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace,
|
|||
|
||||
if (!dname) {
|
||||
name_unit(u);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
u->name = _strdup(dname);
|
||||
}
|
||||
|
||||
|
@ -1539,7 +1561,7 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace,
|
|||
if (creator->faction == f && fval(creator, UFL_GROUP)) {
|
||||
a = a_find(creator->attribs, &at_group);
|
||||
if (a) {
|
||||
group *g = (group *) a->data.v;
|
||||
group *g = (group *)a->data.v;
|
||||
set_group(u, g);
|
||||
}
|
||||
}
|
||||
|
@ -1699,7 +1721,6 @@ int unit_max_hp(const unit * u)
|
|||
|
||||
void scale_number(unit * u, int n)
|
||||
{
|
||||
skill_t sk;
|
||||
const attrib *a;
|
||||
int remain;
|
||||
|
||||
|
@ -1714,14 +1735,15 @@ void scale_number(unit * u, int n)
|
|||
assert(u->hp >= 0);
|
||||
if ((rng_int() % u->number) < remain)
|
||||
++u->hp; /* Nachkommastellen */
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
remain = 0;
|
||||
u->hp = 0;
|
||||
}
|
||||
if (u->number > 0) {
|
||||
for (a = a_find(u->attribs, &at_effect); a && a->type == &at_effect;
|
||||
a = a->next) {
|
||||
effect_data *data = (effect_data *) a->data.v;
|
||||
effect_data *data = (effect_data *)a->data.v;
|
||||
int snew = data->value / u->number * n;
|
||||
if (n) {
|
||||
remain = data->value - snew / n * u->number;
|
||||
|
@ -1734,6 +1756,7 @@ void scale_number(unit * u, int n)
|
|||
}
|
||||
}
|
||||
if (u->number == 0 || n == 0) {
|
||||
skill_t sk;
|
||||
for (sk = 0; sk < MAXSKILLS; sk++) {
|
||||
remove_skill(u, sk);
|
||||
}
|
||||
|
@ -1767,7 +1790,7 @@ void unit_add_spell(unit * u, sc_mage * m, struct spell * sp, int level)
|
|||
|
||||
if (!mage) {
|
||||
log_debug("adding new spell %s to a previously non-mage unit %s\n", sp->sname, unitname(u));
|
||||
mage = create_mage(u, u->faction?u->faction->magiegebiet:M_GRAY);
|
||||
mage = create_mage(u, u->faction ? u->faction->magiegebiet : M_GRAY);
|
||||
}
|
||||
if (!mage->spellbook) {
|
||||
mage->spellbook = create_spellbook(0);
|
||||
|
@ -1782,7 +1805,7 @@ struct spellbook * unit_get_spellbook(const struct unit * u)
|
|||
if (mage->spellbook) {
|
||||
return mage->spellbook;
|
||||
}
|
||||
if (mage->magietyp!=M_GRAY) {
|
||||
if (mage->magietyp != M_GRAY) {
|
||||
return faction_get_spellbook(u->faction);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include "alchemy.h"
|
||||
#include "unit.h"
|
||||
#include "item.h"
|
||||
#include "region.h"
|
||||
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
static void test_scale_number(CuTest *tc) {
|
||||
unit *u;
|
||||
const struct potion_type *ptype;
|
||||
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
ptype = new_potiontype(it_get_or_create(rt_get_or_create("hodor")), 1);
|
||||
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
||||
change_effect(u, ptype, 1);
|
||||
CuAssertIntEquals(tc, 1, u->number);
|
||||
CuAssertIntEquals(tc, 1, u->hp);
|
||||
CuAssertIntEquals(tc, 1, get_effect(u, ptype));
|
||||
scale_number(u, 2);
|
||||
CuAssertIntEquals(tc, 2, u->number);
|
||||
CuAssertIntEquals(tc, 2, u->hp);
|
||||
CuAssertIntEquals(tc, 2, get_effect(u, ptype));
|
||||
set_level(u, SK_ALCHEMY, 1);
|
||||
scale_number(u, 0);
|
||||
CuAssertIntEquals(tc, 0, get_level(u, SK_ALCHEMY));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_unit_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_scale_number);
|
||||
return suite;
|
||||
}
|
|
@ -515,6 +515,7 @@ int autoseed(newfaction ** players, int nsize, int max_agediff)
|
|||
static const terrain_type **terrainarr = 0;
|
||||
static int *distribution;
|
||||
|
||||
assert(players);
|
||||
if (nterrains < 0) {
|
||||
int n = 0;
|
||||
const terrain_type *terrain = terrains();
|
||||
|
|
|
@ -36,6 +36,7 @@ int RunAllTests(void)
|
|||
ADD_TESTS(suite, umlaut);
|
||||
ADD_TESTS(suite, strings);
|
||||
/* kernel */
|
||||
ADD_TESTS(suite, unit);
|
||||
ADD_TESTS(suite, faction);
|
||||
ADD_TESTS(suite, build);
|
||||
ADD_TESTS(suite, pool);
|
||||
|
|
Loading…
Reference in New Issue