forked from github/server
begin adding tests for skills.
This commit is contained in:
parent
0b20c379b6
commit
88a96d5723
5 changed files with 77 additions and 32 deletions
|
@ -27,7 +27,7 @@ region.test.c
|
||||||
# resources.test.c
|
# resources.test.c
|
||||||
save.test.c
|
save.test.c
|
||||||
ship.test.c
|
ship.test.c
|
||||||
# skills.test.c
|
skills.test.c
|
||||||
spellbook.test.c
|
spellbook.test.c
|
||||||
spell.test.c
|
spell.test.c
|
||||||
# terrain.test.c
|
# terrain.test.c
|
||||||
|
|
36
src/kernel/skills.test.c
Normal file
36
src/kernel/skills.test.c
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#include <platform.h>
|
||||||
|
#endif
|
||||||
|
#include "skills.h"
|
||||||
|
|
||||||
|
#include "unit.h"
|
||||||
|
|
||||||
|
#include <CuTest.h>
|
||||||
|
#include <tests.h>
|
||||||
|
|
||||||
|
static void test_skills(CuTest * tc)
|
||||||
|
{
|
||||||
|
unit *u;
|
||||||
|
|
||||||
|
test_setup();
|
||||||
|
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
|
||||||
|
CuAssertPtrEquals(tc, NULL, u->skills);
|
||||||
|
CuAssertIntEquals(tc, 0, u->skill_size);
|
||||||
|
CuAssertIntEquals(tc, 0, get_level(u, SK_CROSSBOW));
|
||||||
|
set_level(u, SK_CROSSBOW, 1);
|
||||||
|
CuAssertPtrNotNull(tc, u->skills);
|
||||||
|
CuAssertIntEquals(tc, 1, u->skill_size);
|
||||||
|
CuAssertIntEquals(tc, 1, get_level(u, SK_CROSSBOW));
|
||||||
|
set_level(u, SK_CROSSBOW, 0);
|
||||||
|
CuAssertPtrEquals(tc, NULL, u->skills);
|
||||||
|
CuAssertIntEquals(tc, 0, u->skill_size);
|
||||||
|
test_teardown();
|
||||||
|
}
|
||||||
|
|
||||||
|
CuSuite *get_skills_suite(void)
|
||||||
|
{
|
||||||
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
SUITE_ADD_TEST(suite, test_skills);
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
|
|
|
@ -1198,8 +1198,13 @@ void remove_skill(unit * u, skill_t sk)
|
||||||
for (i = 0; i != u->skill_size; ++i) {
|
for (i = 0; i != u->skill_size; ++i) {
|
||||||
sv = u->skills + i;
|
sv = u->skills + i;
|
||||||
if (sv->id == sk) {
|
if (sv->id == sk) {
|
||||||
memmove(sv, sv + 1, (u->skill_size - i - 1) * sizeof(skill));
|
if (u->skill_size - i - 1 > 0) {
|
||||||
--u->skill_size;
|
memmove(sv, sv + 1, (u->skill_size - i - 1) * sizeof(skill));
|
||||||
|
}
|
||||||
|
if (--u->skill_size == 0) {
|
||||||
|
free(u->skills);
|
||||||
|
u->skills = NULL;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
43
src/laws.c
43
src/laws.c
|
@ -161,10 +161,33 @@ static bool RemoveNMRNewbie(void)
|
||||||
return value != 0;
|
return value != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void dumbeffect(unit *u) {
|
||||||
|
int effect = get_effect(u, oldpotiontype[P_FOOL]);
|
||||||
|
if (effect > 0) { /* Trank "Dumpfbackenbrot" */
|
||||||
|
skill *sv = u->skills, *sb = NULL;
|
||||||
|
while (sv != u->skills + u->skill_size) {
|
||||||
|
if (sb == NULL || skill_compare(sv, sb) > 0) {
|
||||||
|
sb = sv;
|
||||||
|
}
|
||||||
|
++sv;
|
||||||
|
}
|
||||||
|
/* bestes Talent raussuchen */
|
||||||
|
if (sb != NULL) {
|
||||||
|
int weeks = u->number;
|
||||||
|
if (weeks > effect) weeks = effect;
|
||||||
|
reduce_skill(u, sb, weeks);
|
||||||
|
ADDMSG(&u->faction->msgs, msg_message("dumbeffect",
|
||||||
|
"unit weeks skill", u, weeks, (skill_t)sb->id));
|
||||||
|
} /* sonst Glück gehabt: wer nix weiss, kann nix vergessen... */
|
||||||
|
change_effect(u, oldpotiontype[P_FOOL], -effect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void age_unit(region * r, unit * u)
|
static void age_unit(region * r, unit * u)
|
||||||
{
|
{
|
||||||
const race *rc = u_race(u);
|
const race *rc = u_race(u);
|
||||||
|
|
||||||
|
dumbeffect(u);
|
||||||
++u->age;
|
++u->age;
|
||||||
if (u->number > 0 && rc->age_unit) {
|
if (u->number > 0 && rc->age_unit) {
|
||||||
rc->age_unit(u);
|
rc->age_unit(u);
|
||||||
|
@ -198,26 +221,6 @@ static void live(region * r)
|
||||||
/* IUW: age_unit() kann u loeschen, u->next ist dann
|
/* IUW: age_unit() kann u loeschen, u->next ist dann
|
||||||
* undefiniert, also muessen wir hier schon das nächste
|
* undefiniert, also muessen wir hier schon das nächste
|
||||||
* Element bestimmen */
|
* Element bestimmen */
|
||||||
|
|
||||||
int effect = get_effect(u, oldpotiontype[P_FOOL]);
|
|
||||||
if (effect > 0) { /* Trank "Dumpfbackenbrot" */
|
|
||||||
skill *sv = u->skills, *sb = NULL;
|
|
||||||
while (sv != u->skills + u->skill_size) {
|
|
||||||
if (sb == NULL || skill_compare(sv, sb) > 0) {
|
|
||||||
sb = sv;
|
|
||||||
}
|
|
||||||
++sv;
|
|
||||||
}
|
|
||||||
/* bestes Talent raussuchen */
|
|
||||||
if (sb != NULL) {
|
|
||||||
int weeks = u->number;
|
|
||||||
if (weeks > effect) weeks = effect;
|
|
||||||
reduce_skill(u, sb, weeks);
|
|
||||||
ADDMSG(&u->faction->msgs, msg_message("dumbeffect",
|
|
||||||
"unit weeks skill", u, weeks, (skill_t)sb->id));
|
|
||||||
} /* sonst Glück gehabt: wer nix weiss, kann nix vergessen... */
|
|
||||||
change_effect(u, oldpotiontype[P_FOOL], -effect);
|
|
||||||
}
|
|
||||||
age_unit(r, u);
|
age_unit(r, u);
|
||||||
if (*up == u)
|
if (*up == u)
|
||||||
up = &u->next;
|
up = &u->next;
|
||||||
|
|
|
@ -92,33 +92,34 @@ int RunAllTests(int argc, char *argv[])
|
||||||
/* items */
|
/* items */
|
||||||
ADD_SUITE(xerewards);
|
ADD_SUITE(xerewards);
|
||||||
/* kernel */
|
/* kernel */
|
||||||
|
ADD_SUITE(academy);
|
||||||
|
ADD_SUITE(alchemy);
|
||||||
ADD_SUITE(alliance);
|
ADD_SUITE(alliance);
|
||||||
|
ADD_SUITE(ally);
|
||||||
|
ADD_SUITE(building);
|
||||||
ADD_SUITE(command);
|
ADD_SUITE(command);
|
||||||
ADD_SUITE(db);
|
ADD_SUITE(db);
|
||||||
ADD_SUITE(plane);
|
|
||||||
ADD_SUITE(unit);
|
|
||||||
ADD_SUITE(faction);
|
ADD_SUITE(faction);
|
||||||
ADD_SUITE(group);
|
ADD_SUITE(group);
|
||||||
ADD_SUITE(build);
|
ADD_SUITE(build);
|
||||||
ADD_SUITE(pool);
|
|
||||||
ADD_SUITE(curse);
|
ADD_SUITE(curse);
|
||||||
ADD_SUITE(equipment);
|
ADD_SUITE(equipment);
|
||||||
ADD_SUITE(familiar);
|
ADD_SUITE(familiar);
|
||||||
ADD_SUITE(item);
|
ADD_SUITE(item);
|
||||||
ADD_SUITE(magic);
|
ADD_SUITE(magic);
|
||||||
ADD_SUITE(academy);
|
ADD_SUITE(magicresistance);
|
||||||
ADD_SUITE(alchemy);
|
ADD_SUITE(messages);
|
||||||
|
ADD_SUITE(plane);
|
||||||
|
ADD_SUITE(pool);
|
||||||
ADD_SUITE(reports);
|
ADD_SUITE(reports);
|
||||||
ADD_SUITE(region);
|
ADD_SUITE(region);
|
||||||
ADD_SUITE(save);
|
ADD_SUITE(save);
|
||||||
ADD_SUITE(ship);
|
ADD_SUITE(ship);
|
||||||
|
ADD_SUITE(skills);
|
||||||
ADD_SUITE(spellbook);
|
ADD_SUITE(spellbook);
|
||||||
ADD_SUITE(building);
|
|
||||||
ADD_SUITE(spell);
|
ADD_SUITE(spell);
|
||||||
ADD_SUITE(spells);
|
ADD_SUITE(spells);
|
||||||
ADD_SUITE(magicresistance);
|
ADD_SUITE(unit);
|
||||||
ADD_SUITE(ally);
|
|
||||||
ADD_SUITE(messages);
|
|
||||||
/* gamecode */
|
/* gamecode */
|
||||||
ADD_SUITE(battle);
|
ADD_SUITE(battle);
|
||||||
ADD_SUITE(calendar);
|
ADD_SUITE(calendar);
|
||||||
|
|
Loading…
Reference in a new issue