forked from github/server
Merge branch 'test-alliance' of https://github.com/ennorehling/eressea into ennorehling-test-alliance
Conflicts: src/util/CMakeLists.txt
This commit is contained in:
commit
238a0e22f2
|
@ -11,6 +11,7 @@
|
|||
"settings": {
|
||||
"game.id": 2,
|
||||
"game.name": "Eressea",
|
||||
"orders.default": "work",
|
||||
"NewbieImmunity": 8,
|
||||
"modules.wormholes": true,
|
||||
"entertain.base": 0,
|
||||
|
|
|
@ -67,9 +67,5 @@
|
|||
<text locale="de">ERESSEA 2 BEFEHLE</text>
|
||||
<text locale="en">ERESSEA 2 ORDERS</text>
|
||||
</string>
|
||||
<string name="defaultorder">
|
||||
<text locale="de">ARBEITEN</text>
|
||||
<text locale="en">WORK</text>
|
||||
</string>
|
||||
</strings>
|
||||
</eressea>
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
"settings": {
|
||||
"game.id": 3,
|
||||
"game.name": "E3",
|
||||
"orders.default": "work",
|
||||
"database.gameid": 7,
|
||||
"NewbieImmunity": 4,
|
||||
"modules.astralspace": false,
|
||||
|
|
|
@ -59,9 +59,5 @@
|
|||
<text locale="de">ERESSEA 3 BEFEHLE</text>
|
||||
<text locale="en">ERESSEA 3 ORDERS</text>
|
||||
</string>
|
||||
<string name="defaultorder">
|
||||
<text locale="de">ARBEITEN</text>
|
||||
<text locale="en">WORK</text>
|
||||
</string>
|
||||
</strings>
|
||||
</eressea>
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
"settings": {
|
||||
"game.id": 4,
|
||||
"game.name": "Deveron",
|
||||
"orders.default": "work",
|
||||
"database.gameid": 7,
|
||||
"NewbieImmunity": 4,
|
||||
"modules.astralspace": false,
|
||||
|
|
|
@ -60,9 +60,5 @@
|
|||
<text locale="de">ERESSEA 4 BEFEHLE</text>
|
||||
<text locale="en">ERESSEA 4 ORDERS</text>
|
||||
</string>
|
||||
<string name="defaultorder">
|
||||
<text locale="de">ARBEITEN</text>
|
||||
<text locale="en">WORK</text>
|
||||
</string>
|
||||
</strings>
|
||||
</eressea>
|
||||
|
|
|
@ -284,10 +284,6 @@
|
|||
getting it after the second turn, please make one of your units give the
|
||||
order OPTION COMPUTER.</text>
|
||||
</string>
|
||||
<string name="defaultorder">
|
||||
<text locale="de">ARBEITEN</text>
|
||||
<text locale="en">WORK</text>
|
||||
</string>
|
||||
<string name="temple">
|
||||
<text locale="de">Tempel</text>
|
||||
<text locale="en">temple</text>
|
||||
|
|
|
@ -2318,7 +2318,7 @@ void do_attack(fighter * af)
|
|||
if (apr > 0) {
|
||||
/* Wenn die Waffe nachladen muss, oder es sich nicht um einen
|
||||
* Waffen-Angriff handelt, dann gilt der Speed nicht. */
|
||||
/* FIXME allow multiple AT_NATURAL attacks? */
|
||||
/* TODO: allow multiple AT_NATURAL attacks? */
|
||||
if (u_race(au)->attack[a].type != AT_STANDARD)
|
||||
continue;
|
||||
else {
|
||||
|
|
|
@ -17,6 +17,7 @@ without prior permission by the authors of Eressea.
|
|||
#include <kernel/save.h>
|
||||
#include <kernel/version.h>
|
||||
|
||||
#include <util/gamedata.h>
|
||||
#include <util/log.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
|
|
@ -2,26 +2,34 @@ project(kernel C)
|
|||
|
||||
SET(_TEST_FILES
|
||||
alliance.test.c
|
||||
build.test.c
|
||||
config.test.c
|
||||
group.test.c
|
||||
faction.test.c
|
||||
unit.test.c
|
||||
save.test.c
|
||||
ship.test.c
|
||||
spell.test.c
|
||||
ally.test.c
|
||||
build.test.c
|
||||
building.test.c
|
||||
equipment.test.c
|
||||
command.test.c
|
||||
config.test.c
|
||||
# connection.test.c
|
||||
curse.test.c
|
||||
equipment.test.c
|
||||
faction.test.c
|
||||
group.test.c
|
||||
item.test.c
|
||||
messages.test.c
|
||||
order.test.c
|
||||
# pathdinder.test.c
|
||||
plane.test.c
|
||||
pool.test.c
|
||||
race.test.c
|
||||
# region.test.c
|
||||
# resources.test.c
|
||||
save.test.c
|
||||
ship.test.c
|
||||
# skills.test.c
|
||||
spellbook.test.c
|
||||
curse.test.c
|
||||
spell.test.c
|
||||
# terrain.test.c
|
||||
unit.test.c
|
||||
jsonconf.test.c
|
||||
messages.test.c
|
||||
# xmlreader.test.c
|
||||
)
|
||||
|
||||
SET(_FILES
|
||||
|
|
|
@ -277,9 +277,25 @@ static void perform_join(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void execute(const struct syntaxtree *syntax, keyword_t kwd)
|
||||
|
||||
static syntaxtree * build_syntax(void) {
|
||||
syntaxtree *slang, *stree = stree_create();
|
||||
for (slang = stree; slang; slang = slang->next) {
|
||||
void *leaf = 0;
|
||||
add_command(&leaf, NULL, LOC(slang->lang, alliance_kwd[ALLIANCE_KICK]), &cmd_kick);
|
||||
add_command(&leaf, NULL, LOC(slang->lang, alliance_kwd[ALLIANCE_LEAVE]), &cmd_leave);
|
||||
add_command(&leaf, NULL, LOC(slang->lang, alliance_kwd[ALLIANCE_TRANSFER]), &cmd_transfer);
|
||||
add_command(&leaf, NULL, LOC(slang->lang, alliance_kwd[ALLIANCE_NEW]), &cmd_new);
|
||||
add_command(&leaf, NULL, LOC(slang->lang, alliance_kwd[ALLIANCE_INVITE]), &cmd_invite);
|
||||
add_command(&leaf, NULL, LOC(slang->lang, alliance_kwd[ALLIANCE_JOIN]), &cmd_join);
|
||||
slang->root = leaf;
|
||||
}
|
||||
return stree;
|
||||
}
|
||||
|
||||
static void execute(keyword_t kwd)
|
||||
{
|
||||
int run = 0;
|
||||
struct syntaxtree *syntax = 0;
|
||||
|
||||
region **rp = ®ions;
|
||||
while (*rp) {
|
||||
|
@ -289,12 +305,13 @@ static void execute(const struct syntaxtree *syntax, keyword_t kwd)
|
|||
unit *u = *up;
|
||||
if (u->number) {
|
||||
const struct locale *lang = u->faction->locale;
|
||||
void *root = stree_find(syntax, lang);
|
||||
order *ord;
|
||||
for (ord = u->orders; ord; ord = ord->next) {
|
||||
if (getkeyword(ord) == kwd) {
|
||||
void *root;
|
||||
if (!syntax) syntax = build_syntax();
|
||||
root = stree_find(syntax, lang);
|
||||
do_command(root, u, ord);
|
||||
run = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -304,8 +321,8 @@ static void execute(const struct syntaxtree *syntax, keyword_t kwd)
|
|||
if (*rp == r)
|
||||
rp = &r->next;
|
||||
}
|
||||
|
||||
if (run) {
|
||||
if (syntax) {
|
||||
stree_free(syntax);
|
||||
perform_kick();
|
||||
perform_leave();
|
||||
perform_transfer();
|
||||
|
@ -314,42 +331,21 @@ static void execute(const struct syntaxtree *syntax, keyword_t kwd)
|
|||
}
|
||||
}
|
||||
|
||||
const char* alliance_kwd[ALLIANCE_MAX] = {
|
||||
"kick",
|
||||
"leave",
|
||||
"command",
|
||||
"new",
|
||||
"invite",
|
||||
"join"
|
||||
};
|
||||
|
||||
void alliance_cmd(void)
|
||||
{
|
||||
static syntaxtree *stree = NULL;
|
||||
if (stree == NULL) {
|
||||
syntaxtree *slang = stree = stree_create();
|
||||
while (slang) {
|
||||
void *leaf = 0;
|
||||
add_command(&leaf, NULL, LOC(slang->lang, "new"), &cmd_new);
|
||||
add_command(&leaf, NULL, LOC(slang->lang, "invite"), &cmd_invite);
|
||||
add_command(&leaf, NULL, LOC(slang->lang, "join"), &cmd_join);
|
||||
add_command(&leaf, NULL, LOC(slang->lang, "kick"), &cmd_kick);
|
||||
add_command(&leaf, NULL, LOC(slang->lang, "leave"), &cmd_leave);
|
||||
add_command(&leaf, NULL, LOC(slang->lang, "command"), &cmd_transfer);
|
||||
slang->root = leaf;
|
||||
slang = slang->next;
|
||||
}
|
||||
}
|
||||
execute(stree, K_ALLIANCE);
|
||||
execute(K_ALLIANCE);
|
||||
/* some may have been kicked, must remove f->alliance==NULL */
|
||||
}
|
||||
|
||||
void alliancejoin(void)
|
||||
{
|
||||
static syntaxtree *stree = NULL;
|
||||
if (stree == NULL) {
|
||||
syntaxtree *slang = stree = stree_create();
|
||||
while (slang) {
|
||||
void *leaf = 0;
|
||||
add_command(&leaf, NULL, LOC(slang->lang, "join"), &cmd_join);
|
||||
add_command(&slang->root, leaf, LOC(slang->lang, "alliance"), NULL);
|
||||
slang = slang->next;
|
||||
}
|
||||
}
|
||||
execute(stree, K_ALLIANCE);
|
||||
}
|
||||
|
||||
void setalliance(faction * f, alliance * al)
|
||||
{
|
||||
if (f->alliance == al)
|
||||
|
@ -442,82 +438,6 @@ void alliancevictory(void)
|
|||
}
|
||||
}
|
||||
|
||||
int victorycondition(const alliance * al, const char *name)
|
||||
{
|
||||
const char *gems[] =
|
||||
{ "opal", "diamond", "zaphire", "topaz", "beryl", "agate", "garnet",
|
||||
"emerald", NULL };
|
||||
if (strcmp(name, "gems") == 0) {
|
||||
const char **igem;
|
||||
|
||||
for (igem = gems; *igem; ++igem) {
|
||||
const struct resource_type *rtype = rt_find(*igem);
|
||||
quicklist *flist = al->members;
|
||||
int qi;
|
||||
bool found = false;
|
||||
|
||||
assert(rtype);
|
||||
for (qi = 0; flist && !found; ql_advance(&flist, &qi, 1)) {
|
||||
faction *f = (faction *)ql_get(flist, 0);
|
||||
unit *u;
|
||||
|
||||
for (u = f->units; u; u = u->nextF) {
|
||||
if (i_get(u->items, rtype->itype) > 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
||||
}
|
||||
else if (strcmp(name, "phoenix") == 0) {
|
||||
quicklist *flist = al->members;
|
||||
int qi;
|
||||
|
||||
for (qi = 0; flist; ql_advance(&flist, &qi, 1)) {
|
||||
faction *f = (faction *)ql_get(flist, qi);
|
||||
if (key_get(f->attribs, atoi36("phnx"))) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
else if (strcmp(name, "pyramid") == 0) {
|
||||
|
||||
/* Logik:
|
||||
* - if (pyr > last_passed_size && pyr > all_others) {
|
||||
* pyr->passed->counter++;
|
||||
* for(all_other_pyrs) {
|
||||
* pyr->passed->counter=0;
|
||||
* }
|
||||
*
|
||||
* if(pyr->passed->counter >= 3) {
|
||||
* set(pyr, passed);
|
||||
* pyr->owner->set_attrib(pyra);
|
||||
* }
|
||||
* last_passed_size = pyr->size;
|
||||
* }
|
||||
*/
|
||||
|
||||
quicklist *flist = al->members;
|
||||
int qi;
|
||||
|
||||
for (qi = 0; flist; ql_advance(&flist, &qi, 1)) {
|
||||
faction *f = (faction *)ql_get(flist, qi);
|
||||
if (key_get(f->attribs, atoi36("pyra"))) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void alliance_setname(alliance * self, const char *name)
|
||||
{
|
||||
free(self->name);
|
||||
|
|
|
@ -38,6 +38,7 @@ extern "C" {
|
|||
ALLIANCE_MAX
|
||||
};
|
||||
|
||||
extern const char* alliance_kwd[ALLIANCE_MAX];
|
||||
#define ALF_NON_ALLIED (1<<0) /* this alliance is just a default for a non-allied faction */
|
||||
|
||||
#define ALLY_ENEMY (1<<0)
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/order.h>
|
||||
#include <util/base36.h>
|
||||
#include "alliance.h"
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
@ -83,12 +86,126 @@ static void test_alliance_dead_faction(CuTest *tc) {
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_alliance_cmd(CuTest *tc) {
|
||||
unit *u1, *u2;
|
||||
struct region *r;
|
||||
struct alliance *al;
|
||||
|
||||
test_cleanup();
|
||||
r = test_create_region(0, 0, 0);
|
||||
u1 = test_create_unit(test_create_faction(0), r);
|
||||
u2 = test_create_unit(test_create_faction(0), r);
|
||||
unit_addorder(u1, create_order(K_ALLIANCE, u1->faction->locale, "%s %s", alliance_kwd[ALLIANCE_NEW], itoa36(42)));
|
||||
unit_addorder(u1, create_order(K_ALLIANCE, u1->faction->locale, "%s %s", alliance_kwd[ALLIANCE_INVITE], itoa36(u2->faction->no)));
|
||||
unit_addorder(u2, create_order(K_ALLIANCE, u1->faction->locale, "%s %s", alliance_kwd[ALLIANCE_JOIN], itoa36(42)));
|
||||
CuAssertTrue(tc, is_allied(u1->faction, u1->faction));
|
||||
CuAssertTrue(tc, !is_allied(u1->faction, u2->faction));
|
||||
CuAssertPtrEquals(tc, 0, f_get_alliance(u1->faction));
|
||||
alliance_cmd();
|
||||
al = f_get_alliance(u1->faction);
|
||||
CuAssertPtrNotNull(tc, al);
|
||||
CuAssertIntEquals(tc, 42, al->id);
|
||||
CuAssertPtrNotNull(tc, al->members);
|
||||
CuAssertPtrEquals(tc, u1->faction, alliance_get_leader(al));
|
||||
CuAssertPtrEquals(tc, al, findalliance(42));
|
||||
CuAssertTrue(tc, is_allied(u1->faction, u1->faction));
|
||||
CuAssertPtrEquals(tc, al, u2->faction->alliance);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_alliance_cmd_kick(CuTest *tc) {
|
||||
unit *u1, *u2;
|
||||
struct region *r;
|
||||
struct alliance *al;
|
||||
|
||||
test_cleanup();
|
||||
al = makealliance(42, "Hodor");
|
||||
r = test_create_region(0, 0, 0);
|
||||
u1 = test_create_unit(test_create_faction(0), r);
|
||||
u2 = test_create_unit(test_create_faction(0), r);
|
||||
setalliance(u1->faction, al);
|
||||
setalliance(u2->faction, al);
|
||||
|
||||
unit_addorder(u1, create_order(K_ALLIANCE, u1->faction->locale, "%s %s", alliance_kwd[ALLIANCE_KICK], itoa36(u2->faction->no)));
|
||||
CuAssertTrue(tc, is_allied(u1->faction, u2->faction));
|
||||
alliance_cmd();
|
||||
CuAssertTrue(tc, !is_allied(u1->faction, u2->faction));
|
||||
CuAssertPtrEquals(tc, 0, f_get_alliance(u2->faction));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_alliance_cmd_no_invite(CuTest *tc) {
|
||||
unit *u1, *u2;
|
||||
struct region *r;
|
||||
|
||||
test_cleanup();
|
||||
r = test_create_region(0, 0, 0);
|
||||
u1 = test_create_unit(test_create_faction(0), r);
|
||||
u2 = test_create_unit(test_create_faction(0), r);
|
||||
unit_addorder(u1, create_order(K_ALLIANCE, u1->faction->locale, "%s %s", alliance_kwd[ALLIANCE_NEW], itoa36(42)));
|
||||
unit_addorder(u2, create_order(K_ALLIANCE, u1->faction->locale, "%s %s", alliance_kwd[ALLIANCE_JOIN], itoa36(42)));
|
||||
CuAssertTrue(tc, is_allied(u1->faction, u1->faction));
|
||||
CuAssertTrue(tc, !is_allied(u1->faction, u2->faction));
|
||||
CuAssertPtrEquals(tc, 0, f_get_alliance(u1->faction));
|
||||
alliance_cmd();
|
||||
CuAssertPtrNotNull(tc, f_get_alliance(u1->faction));
|
||||
CuAssertPtrEquals(tc, 0, f_get_alliance(u2->faction));
|
||||
CuAssertTrue(tc, !is_allied(u1->faction, u2->faction));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_alliance_cmd_leave(CuTest *tc) {
|
||||
unit *u1, *u2;
|
||||
struct region *r;
|
||||
struct alliance *al;
|
||||
|
||||
test_cleanup();
|
||||
al = makealliance(42, "Hodor");
|
||||
r = test_create_region(0, 0, 0);
|
||||
u1 = test_create_unit(test_create_faction(0), r);
|
||||
u2 = test_create_unit(test_create_faction(0), r);
|
||||
setalliance(u1->faction, al);
|
||||
setalliance(u2->faction, al);
|
||||
|
||||
unit_addorder(u1, create_order(K_ALLIANCE, u1->faction->locale, "%s", alliance_kwd[ALLIANCE_LEAVE]));
|
||||
CuAssertTrue(tc, is_allied(u1->faction, u2->faction));
|
||||
alliance_cmd();
|
||||
CuAssertTrue(tc, !is_allied(u1->faction, u2->faction));
|
||||
CuAssertPtrEquals(tc, 0, f_get_alliance(u1->faction));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_alliance_cmd_transfer(CuTest *tc) {
|
||||
unit *u1, *u2;
|
||||
struct region *r;
|
||||
struct alliance *al;
|
||||
|
||||
test_cleanup();
|
||||
al = makealliance(42, "Hodor");
|
||||
r = test_create_region(0, 0, 0);
|
||||
u1 = test_create_unit(test_create_faction(0), r);
|
||||
u2 = test_create_unit(test_create_faction(0), r);
|
||||
setalliance(u1->faction, al);
|
||||
setalliance(u2->faction, al);
|
||||
CuAssertPtrEquals(tc, u1->faction, alliance_get_leader(al));
|
||||
unit_addorder(u1, create_order(K_ALLIANCE, u1->faction->locale, "%s %s", alliance_kwd[ALLIANCE_TRANSFER], itoa36(u2->faction->no)));
|
||||
alliance_cmd();
|
||||
CuAssertPtrEquals(tc, u2->faction, alliance_get_leader(al));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
|
||||
CuSuite *get_alliance_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_alliance_dead_faction);
|
||||
SUITE_ADD_TEST(suite, test_alliance_make);
|
||||
SUITE_ADD_TEST(suite, test_alliance_join);
|
||||
SUITE_ADD_TEST(suite, test_alliance_cmd);
|
||||
SUITE_ADD_TEST(suite, test_alliance_cmd_no_invite);
|
||||
SUITE_ADD_TEST(suite, test_alliance_cmd_kick);
|
||||
SUITE_ADD_TEST(suite, test_alliance_cmd_leave);
|
||||
SUITE_ADD_TEST(suite, test_alliance_cmd_transfer);
|
||||
return suite;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/bsdstring.h>
|
||||
#include <util/event.h>
|
||||
#include <util/functions.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <quicklist.h>
|
||||
|
|
|
@ -43,6 +43,15 @@ void *stree_find(const syntaxtree * stree, const struct locale *lang)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void stree_free(syntaxtree *stree) {
|
||||
while (stree) {
|
||||
syntaxtree *snext = stree->next;
|
||||
freetokens(stree->root);
|
||||
free(stree);
|
||||
stree = snext;
|
||||
}
|
||||
}
|
||||
|
||||
syntaxtree *stree_create(void)
|
||||
{
|
||||
syntaxtree *sroot = NULL;
|
||||
|
@ -65,6 +74,7 @@ const char *str, parser fun)
|
|||
command *cmd = (command *)malloc(sizeof(command));
|
||||
variant var;
|
||||
|
||||
assert(str);
|
||||
cmd->fun = fun;
|
||||
cmd->nodes = tnext;
|
||||
var.v = cmd;
|
||||
|
|
|
@ -32,6 +32,7 @@ extern "C" {
|
|||
void do_command(const void *troot, struct unit *u, struct order *);
|
||||
|
||||
struct syntaxtree *stree_create(void);
|
||||
void stree_free(struct syntaxtree *);
|
||||
void *stree_find(const struct syntaxtree *stree,
|
||||
const struct locale *lang);
|
||||
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
|
||||
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
|
||||
+-------------------+ Stefan Reich <reich@halbling.de>
|
||||
|
||||
This program may not be used, modified or distributed
|
||||
without prior permission by the authors of Eressea.
|
||||
|
||||
*/
|
||||
#include "command.h"
|
||||
#include "unit.h"
|
||||
#include "order.h"
|
||||
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
||||
static void parser_two(const void *nodes, struct unit * u, struct order *ord) {
|
||||
scale_number(u, 2);
|
||||
}
|
||||
|
||||
static void parser_six(const void *nodes, struct unit * u, struct order *ord) {
|
||||
scale_number(u, 6);
|
||||
}
|
||||
|
||||
static void test_command(CuTest * tc) {
|
||||
struct syntaxtree *st;
|
||||
struct locale * loc;
|
||||
unit *u;
|
||||
|
||||
test_cleanup();
|
||||
loc = test_create_locale();
|
||||
st = stree_create();
|
||||
CuAssertPtrNotNull(tc, st);
|
||||
CuAssertPtrEquals(tc, loc, (struct locale *)st->lang);
|
||||
CuAssertPtrEquals(tc, 0, st->root);
|
||||
CuAssertPtrEquals(tc, 0, st->next);
|
||||
add_command(&st->root, 0, "two", parser_two);
|
||||
add_command(&st->root, 0, "six", parser_six);
|
||||
CuAssertPtrNotNull(tc, st->root);
|
||||
CuAssertPtrEquals(tc, st->root, stree_find(st, loc));
|
||||
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
||||
u->thisorder = create_order(K_ALLIANCE, loc, "two");
|
||||
do_command(st->root, u, u->thisorder);
|
||||
CuAssertIntEquals(tc, u->number, 2);
|
||||
stree_free(st);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_command_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_command);
|
||||
return suite;
|
||||
}
|
|
@ -1003,33 +1003,24 @@ void kernel_init(void)
|
|||
}
|
||||
|
||||
static order * defaults[MAXLOCALES];
|
||||
keyword_t default_keyword = NOKEYWORD;
|
||||
|
||||
void set_default_order(int kwd) {
|
||||
default_keyword = (keyword_t)kwd;
|
||||
}
|
||||
|
||||
// TODO: outside of tests, default_keyword is never used, why is this here?
|
||||
// see also test_long_order_hungry
|
||||
order *default_order(const struct locale *lang)
|
||||
{
|
||||
static int usedefault = 1;
|
||||
int i = locale_index(lang);
|
||||
order *result = 0;
|
||||
assert(i < MAXLOCALES);
|
||||
|
||||
if (default_keyword != NOKEYWORD) {
|
||||
return create_order(default_keyword, lang, 0);
|
||||
}
|
||||
|
||||
result = defaults[i];
|
||||
if (!result && usedefault) {
|
||||
const char * str = LOC(lang, "defaultorder");
|
||||
if (!result) {
|
||||
const char * str;
|
||||
keyword_t kwd = NOKEYWORD;
|
||||
str = config_get("orders.default");
|
||||
if (str) {
|
||||
result = defaults[i] = parse_order(str, lang);
|
||||
kwd = findkeyword(str);
|
||||
}
|
||||
else {
|
||||
usedefault = 0;
|
||||
if (kwd != NOKEYWORD) {
|
||||
result = create_order(kwd, lang, NULL);
|
||||
defaults[i] = result;
|
||||
}
|
||||
}
|
||||
return result ? copy_order(result) : 0;
|
||||
|
|
|
@ -193,7 +193,6 @@ struct param;
|
|||
bool IsImmune(const struct faction *f);
|
||||
|
||||
struct order *default_order(const struct locale *lang);
|
||||
void set_default_order(int kwd);
|
||||
|
||||
int entertainmoney(const struct region *r);
|
||||
void init_parameters(struct locale *lang);
|
||||
|
|
|
@ -172,6 +172,23 @@ static void test_forbiddenid(CuTest *tc) {
|
|||
CuAssertIntEquals(tc, 1, forbiddenid(atoi36("t")));
|
||||
}
|
||||
|
||||
static void test_default_order(CuTest *tc) {
|
||||
order *ord;
|
||||
struct locale * loc;
|
||||
|
||||
test_cleanup();
|
||||
loc = test_create_locale();
|
||||
ord = default_order(loc);
|
||||
CuAssertPtrEquals(tc, 0, ord);
|
||||
|
||||
config_set("orders.default", "work");
|
||||
ord = default_order(loc);
|
||||
CuAssertPtrNotNull(tc, ord);
|
||||
CuAssertIntEquals(tc, K_WORK, getkeyword(ord));
|
||||
CuAssertPtrEquals(tc, ord->data, default_order(loc)->data);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_config_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
|
@ -181,5 +198,6 @@ CuSuite *get_config_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_forbiddenid);
|
||||
SUITE_ADD_TEST(suite, test_getunit);
|
||||
SUITE_ADD_TEST(suite, test_read_unitid);
|
||||
SUITE_ADD_TEST(suite, test_default_order);
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/base36.h>
|
||||
#include <util/bsdstring.h>
|
||||
#include <util/event.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/language.h>
|
||||
|
|
|
@ -511,7 +511,7 @@ static void json_prefixes(cJSON *json) {
|
|||
}
|
||||
|
||||
/** disable a feature.
|
||||
* features are identified by eone of:
|
||||
* features are identified by one of:
|
||||
* 1. the keyword for their orders,
|
||||
* 2. the name of the skill they use,
|
||||
* 3. a "module.enabled" flag in the settings
|
||||
|
@ -525,13 +525,11 @@ static void disable_feature(const char *str) {
|
|||
enable_skill(sk, false);
|
||||
return;
|
||||
}
|
||||
for (k = 0; k != MAXKEYWORDS; ++k) {
|
||||
// FIXME: this loop is slow as balls.
|
||||
if (strcmp(keywords[k], str) == 0) {
|
||||
log_debug("disable keyword %s\n", str);
|
||||
enable_keyword(k, false);
|
||||
return;
|
||||
}
|
||||
k = findkeyword(str);
|
||||
if (k!=NOKEYWORD) {
|
||||
log_debug("disable keyword %s\n", str);
|
||||
enable_keyword(k, false);
|
||||
return;
|
||||
}
|
||||
_snprintf(name, sizeof(name), "%s.enabled", str);
|
||||
log_info("disable feature %s\n", name);
|
||||
|
|
|
@ -28,6 +28,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define MAXDEPTH 1024
|
||||
|
||||
bool allowed_swim(const region * src, const region * r)
|
||||
{
|
||||
if (fval(r->terrain, SWIM_INTO))
|
||||
|
|
|
@ -22,11 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MAXDEPTH 1024
|
||||
|
||||
extern int search[MAXDEPTH][2];
|
||||
extern int search_len;
|
||||
|
||||
extern struct region **path_find(struct region *start,
|
||||
const struct region *target, int maxlen,
|
||||
bool(*allowed) (const struct region *, const struct region *));
|
||||
|
|
|
@ -60,7 +60,6 @@ extern "C" {
|
|||
|
||||
struct plane *getplane(const struct region *r);
|
||||
struct plane *findplane(int x, int y);
|
||||
void init_planes(void);
|
||||
int getplaneid(const struct region *r);
|
||||
struct plane *getplanebyid(int id);
|
||||
int plane_center_x(const struct plane *pl);
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include "plane.h"
|
||||
#include "faction.h"
|
||||
#include <tests.h>
|
||||
#include <CuTest.h>
|
||||
|
||||
static void test_plane(CuTest *tc) {
|
||||
struct region *r;
|
||||
plane *pl;
|
||||
|
||||
test_cleanup();
|
||||
r = test_create_region(0, 0, 0);
|
||||
CuAssertPtrEquals(tc, 0, findplane(0, 0));
|
||||
CuAssertPtrEquals(tc, 0, getplane(r));
|
||||
CuAssertIntEquals(tc, 0, getplaneid(r));
|
||||
CuAssertPtrEquals(tc, 0, getplanebyid(0));
|
||||
CuAssertIntEquals(tc, 0, plane_center_x(0));
|
||||
CuAssertIntEquals(tc, 0, plane_center_y(0));
|
||||
CuAssertIntEquals(tc, 0, plane_width(0));
|
||||
CuAssertIntEquals(tc, 0, plane_height(0));
|
||||
CuAssertPtrEquals(tc, 0, get_homeplane());
|
||||
|
||||
pl = create_new_plane(1, "Hell", 4, 8, 40, 80, 15);
|
||||
r = test_create_region(4, 40, 0);
|
||||
CuAssertIntEquals(tc, 15, pl->flags);
|
||||
CuAssertIntEquals(tc, 4, pl->minx);
|
||||
CuAssertIntEquals(tc, 8, pl->maxx);
|
||||
CuAssertIntEquals(tc, 40, pl->miny);
|
||||
CuAssertIntEquals(tc, 80, pl->maxy);
|
||||
CuAssertPtrEquals(tc, 0, pl->attribs);
|
||||
CuAssertStrEquals(tc, "Hell", pl->name);
|
||||
CuAssertPtrEquals(tc, pl, findplane(4, 40));
|
||||
CuAssertPtrEquals(tc, pl, getplane(r));
|
||||
CuAssertPtrEquals(tc, pl, getplanebyid(1));
|
||||
CuAssertIntEquals(tc, 1, getplaneid(r));
|
||||
CuAssertIntEquals(tc, 6, plane_center_x(pl));
|
||||
CuAssertIntEquals(tc, 60, plane_center_y(pl));
|
||||
CuAssertIntEquals(tc, 5, plane_width(pl));
|
||||
CuAssertIntEquals(tc, 41, plane_height(pl));
|
||||
}
|
||||
|
||||
static void test_origin(CuTest *tc) {
|
||||
struct faction *f;
|
||||
int x, y;
|
||||
|
||||
test_cleanup();
|
||||
f = test_create_faction(0);
|
||||
x = 0;
|
||||
y = 0;
|
||||
adjust_coordinates(f, &x, &y, 0);
|
||||
CuAssertIntEquals(tc, 0, x);
|
||||
CuAssertIntEquals(tc, 0, y);
|
||||
faction_setorigin(f, 0, 10, 20);
|
||||
adjust_coordinates(f, &x, &y, 0);
|
||||
CuAssertIntEquals(tc, -10, x);
|
||||
CuAssertIntEquals(tc, -20, y);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_plane_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_plane);
|
||||
SUITE_ADD_TEST(suite, test_origin);
|
||||
return suite;
|
||||
}
|
|
@ -168,7 +168,6 @@ extern "C" {
|
|||
extern struct attrib_type at_woodcount;
|
||||
extern struct attrib_type at_deathcount;
|
||||
|
||||
void initrhash(void);
|
||||
void rhash(struct region *r);
|
||||
void runhash(struct region *r);
|
||||
|
||||
|
@ -176,10 +175,7 @@ extern "C" {
|
|||
void add_regionlist(region_list ** rl, struct region *r);
|
||||
|
||||
int deathcount(const struct region *r);
|
||||
int chaoscount(const struct region *r);
|
||||
|
||||
void deathcounts(struct region *r, int delta);
|
||||
void chaoscounts(struct region *r, int delta);
|
||||
|
||||
void setluxuries(struct region *r, const struct luxury_type *sale);
|
||||
int get_maxluxuries(void);
|
||||
|
|
|
@ -20,7 +20,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#define H_KRNL_SAVE
|
||||
|
||||
#include <stream.h>
|
||||
#include <util/gamedata.h> // FIXME: eliminate include dependency from this file
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -78,8 +77,8 @@ extern "C" {
|
|||
|
||||
void create_backup(char *file);
|
||||
|
||||
int write_game(gamedata *data);
|
||||
int read_game(gamedata *data);
|
||||
int write_game(struct gamedata *data);
|
||||
int read_game(struct gamedata *data);
|
||||
|
||||
/* test-only functions that give access to internal implementation details (BAD) */
|
||||
void _test_write_password(struct gamedata *data, const struct faction *f);
|
||||
|
|
|
@ -227,14 +227,13 @@ static void test_default_name(CuTest *tc) {
|
|||
test_cleanup();
|
||||
test_create_world();
|
||||
lang = get_or_create_locale("de");
|
||||
/* FIXME this has no real effect: default_name uses a static buffer that is initialized in some other test. This sucks. */
|
||||
locale_setstring(lang, "unitdefault", "Einheit");
|
||||
locale_setstring(lang, "unitdefault", "Zweiheit");
|
||||
|
||||
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
||||
|
||||
default_name(u, buf, sizeof(buf));
|
||||
|
||||
sprintf(compare, "Einheit %s", itoa36(u->no));
|
||||
sprintf(compare, "Zweiheit %s", itoa36(u->no));
|
||||
CuAssertStrEquals(tc, compare, buf);
|
||||
|
||||
test_cleanup();
|
||||
|
|
|
@ -998,8 +998,6 @@ static void test_long_order_buy_cast(CuTest *tc) {
|
|||
}
|
||||
|
||||
static void test_long_order_hungry(CuTest *tc) {
|
||||
// FIXME: set_default_order is a test-only function, this is a bad test.
|
||||
// see also default_order
|
||||
unit *u;
|
||||
test_cleanup();
|
||||
config_set("hunger.long", "1");
|
||||
|
@ -1007,12 +1005,11 @@ static void test_long_order_hungry(CuTest *tc) {
|
|||
fset(u, UFL_HUNGER);
|
||||
unit_addorder(u, create_order(K_MOVE, u->faction->locale, 0));
|
||||
unit_addorder(u, create_order(K_DESTROY, u->faction->locale, 0));
|
||||
set_default_order(K_WORK);
|
||||
config_set("orders.default", "work");
|
||||
update_long_order(u);
|
||||
CuAssertIntEquals(tc, K_WORK, getkeyword(u->thisorder));
|
||||
CuAssertPtrNotNull(tc, u->orders);
|
||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
||||
set_default_order(NOKEYWORD);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
|
|
|
@ -253,7 +253,6 @@ static void test_write_unit(CuTest *tc) {
|
|||
race *rc;
|
||||
struct locale *lang;
|
||||
char buffer[1024];
|
||||
/* FIXME: test emits ERROR: no translation for combat status status_aggressive in locale de */
|
||||
|
||||
test_cleanup();
|
||||
rc = rc_get_or_create("human");
|
||||
|
|
|
@ -87,6 +87,8 @@ int RunAllTests(int argc, char *argv[])
|
|||
ADD_SUITE(xerewards);
|
||||
/* kernel */
|
||||
ADD_SUITE(alliance);
|
||||
ADD_SUITE(command);
|
||||
ADD_SUITE(plane);
|
||||
ADD_SUITE(unit);
|
||||
ADD_SUITE(faction);
|
||||
ADD_SUITE(group);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "reports.h"
|
||||
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/terrain.h>
|
||||
|
@ -78,6 +79,9 @@ struct locale * test_create_locale(void) {
|
|||
if (!locale_getstring(loc, mkname("skill", skillnames[i])))
|
||||
locale_setstring(loc, mkname("skill", skillnames[i]), skillnames[i]);
|
||||
}
|
||||
for (i = 0; i != ALLIANCE_MAX; ++i) {
|
||||
locale_setstring(loc, alliance_kwd[i], alliance_kwd[i]);
|
||||
}
|
||||
for (i = 0; i != MAXDIRECTIONS; ++i) {
|
||||
locale_setstring(loc, directions[i], directions[i]);
|
||||
init_direction(loc, i, directions[i]);
|
||||
|
@ -97,6 +101,7 @@ struct locale * test_create_locale(void) {
|
|||
test_translate_param(loc, i, parameters[i]);
|
||||
}
|
||||
init_parameters(loc);
|
||||
init_keywords(loc);
|
||||
init_skills(loc);
|
||||
}
|
||||
return loc;
|
||||
|
|
|
@ -1,18 +1,34 @@
|
|||
project(util C)
|
||||
|
||||
SET(_TEST_FILES
|
||||
attrib.test.c
|
||||
base36.test.c
|
||||
bsdstring.test.c
|
||||
# crmessage.test.c
|
||||
# dice.test.c
|
||||
# event.test.c
|
||||
# filereader.test.c
|
||||
functions.test.c
|
||||
gamedata.test.c
|
||||
# goodies.test.c
|
||||
# language.test.c
|
||||
# lists.test.c
|
||||
# log.test.c
|
||||
# message.test.c
|
||||
# nrmessage.test.c
|
||||
parser.test.c
|
||||
password.test.c
|
||||
attrib.test.c
|
||||
# rand.test.c
|
||||
# resolve.test.c
|
||||
rng.test.c
|
||||
strings.test.c
|
||||
bsdstring.test.c
|
||||
functions.test.c
|
||||
log.test.c
|
||||
# translation.test.c
|
||||
umlaut.test.c
|
||||
unicode.test.c
|
||||
rng.test.c
|
||||
# xml.test.c
|
||||
)
|
||||
|
||||
SET(_FILES
|
||||
|
@ -26,7 +42,6 @@ filereader.c
|
|||
functions.c
|
||||
gamedata.c
|
||||
goodies.c
|
||||
gamedata.c
|
||||
language.c
|
||||
lists.c
|
||||
log.c
|
||||
|
|
Loading…
Reference in New Issue