diff --git a/conf/e2/config.json b/conf/e2/config.json index fa8566eab..217cfffe9 100644 --- a/conf/e2/config.json +++ b/conf/e2/config.json @@ -11,6 +11,7 @@ "settings": { "game.id": 2, "game.name": "Eressea", + "orders.default": "work", "NewbieImmunity": 8, "modules.wormholes": true, "entertain.base": 0, diff --git a/conf/e2/config.xml b/conf/e2/config.xml index d1eac12d8..5516fd601 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -67,9 +67,5 @@ ERESSEA 2 BEFEHLE ERESSEA 2 ORDERS - - ARBEITEN - WORK - diff --git a/conf/e3/config.json b/conf/e3/config.json index a1fc05b74..c9a86c8da 100644 --- a/conf/e3/config.json +++ b/conf/e3/config.json @@ -27,6 +27,7 @@ "settings": { "game.id": 3, "game.name": "E3", + "orders.default": "work", "database.gameid": 7, "NewbieImmunity": 4, "modules.astralspace": false, diff --git a/conf/e3/config.xml b/conf/e3/config.xml index 0531f69d2..04af3858d 100644 --- a/conf/e3/config.xml +++ b/conf/e3/config.xml @@ -59,9 +59,5 @@ ERESSEA 3 BEFEHLE ERESSEA 3 ORDERS - - ARBEITEN - WORK - diff --git a/conf/e4/config.json b/conf/e4/config.json index 345558dff..7a73de86f 100644 --- a/conf/e4/config.json +++ b/conf/e4/config.json @@ -27,6 +27,7 @@ "settings": { "game.id": 4, "game.name": "Deveron", + "orders.default": "work", "database.gameid": 7, "NewbieImmunity": 4, "modules.astralspace": false, diff --git a/conf/e4/config.xml b/conf/e4/config.xml index ffa1c5df8..2def4f1a8 100644 --- a/conf/e4/config.xml +++ b/conf/e4/config.xml @@ -60,9 +60,5 @@ ERESSEA 4 BEFEHLE ERESSEA 4 ORDERS - - ARBEITEN - WORK - diff --git a/res/eressea/strings.xml b/res/eressea/strings.xml index 6b6cf8903..b7db0eb4b 100644 --- a/res/eressea/strings.xml +++ b/res/eressea/strings.xml @@ -284,10 +284,6 @@ getting it after the second turn, please make one of your units give the order OPTION COMPUTER. - - ARBEITEN - WORK - Tempel temple diff --git a/src/battle.c b/src/battle.c index 217f73c34..9d6448be4 100644 --- a/src/battle.c +++ b/src/battle.c @@ -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 { diff --git a/src/bind_storage.c b/src/bind_storage.c index 0255b2982..5dfca8c89 100644 --- a/src/bind_storage.c +++ b/src/bind_storage.c @@ -17,6 +17,7 @@ without prior permission by the authors of Eressea. #include #include +#include #include #include diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index fd8496f89..9e829d4f4 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -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 diff --git a/src/kernel/alliance.c b/src/kernel/alliance.c index 56754c491..08f93b626 100644 --- a/src/kernel/alliance.c +++ b/src/kernel/alliance.c @@ -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); diff --git a/src/kernel/alliance.h b/src/kernel/alliance.h index b96342397..2c5b0d677 100644 --- a/src/kernel/alliance.h +++ b/src/kernel/alliance.h @@ -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) diff --git a/src/kernel/alliance.test.c b/src/kernel/alliance.test.c index 1b708b017..8432f1692 100644 --- a/src/kernel/alliance.test.c +++ b/src/kernel/alliance.test.c @@ -1,6 +1,9 @@ #include #include #include +#include +#include +#include #include "alliance.h" #include #include @@ -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; } diff --git a/src/kernel/building.c b/src/kernel/building.c index e7c60ea9a..c6d7f7af2 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -39,6 +39,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include diff --git a/src/kernel/command.c b/src/kernel/command.c index ac359a4cf..0642be060 100644 --- a/src/kernel/command.c +++ b/src/kernel/command.c @@ -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; diff --git a/src/kernel/command.h b/src/kernel/command.h index 54d8fb25c..70b03a3a6 100644 --- a/src/kernel/command.h +++ b/src/kernel/command.h @@ -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); diff --git a/src/kernel/command.test.c b/src/kernel/command.test.c new file mode 100644 index 000000000..edf521c81 --- /dev/null +++ b/src/kernel/command.test.c @@ -0,0 +1,57 @@ +/* + +-------------------+ Christian Schlittchen + | | Enno Rehling + | Eressea PBEM host | Katja Zedel + | (c) 1998 - 2003 | Henning Peters + | | Ingo Wilken + +-------------------+ Stefan Reich + + 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 +#include + +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; +} \ No newline at end of file diff --git a/src/kernel/config.c b/src/kernel/config.c index d3093c58e..56d995bdc 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -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; diff --git a/src/kernel/config.h b/src/kernel/config.h index 34bd91e9b..081a96e61 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -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); diff --git a/src/kernel/config.test.c b/src/kernel/config.test.c index 30b7cef90..d5b46581c 100644 --- a/src/kernel/config.test.c +++ b/src/kernel/config.test.c @@ -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; } diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 17797491f..c1429f4f3 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -40,6 +40,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index aac4bce10..721e6e60f 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -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); diff --git a/src/kernel/pathfinder.c b/src/kernel/pathfinder.c index 683da5699..8ae9bf128 100644 --- a/src/kernel/pathfinder.c +++ b/src/kernel/pathfinder.c @@ -28,6 +28,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#define MAXDEPTH 1024 + bool allowed_swim(const region * src, const region * r) { if (fval(r->terrain, SWIM_INTO)) diff --git a/src/kernel/pathfinder.h b/src/kernel/pathfinder.h index b7ab0f779..81692e835 100644 --- a/src/kernel/pathfinder.h +++ b/src/kernel/pathfinder.h @@ -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 *)); diff --git a/src/kernel/plane.h b/src/kernel/plane.h index 926ffb4e2..051c05b69 100644 --- a/src/kernel/plane.h +++ b/src/kernel/plane.h @@ -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); diff --git a/src/kernel/plane.test.c b/src/kernel/plane.test.c new file mode 100644 index 000000000..a479a34be --- /dev/null +++ b/src/kernel/plane.test.c @@ -0,0 +1,67 @@ +#include +#include +#include "plane.h" +#include "faction.h" +#include +#include + +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; +} diff --git a/src/kernel/region.h b/src/kernel/region.h index 411fa5580..70d998a0e 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -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); diff --git a/src/kernel/save.h b/src/kernel/save.h index 3d47fe612..3cd443926 100644 --- a/src/kernel/save.h +++ b/src/kernel/save.h @@ -20,7 +20,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define H_KRNL_SAVE #include -#include // 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); diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index 807a27327..dc0484bf7 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -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(); diff --git a/src/laws.test.c b/src/laws.test.c index 4d001948a..9bb4bc8ef 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -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(); } diff --git a/src/reports.test.c b/src/reports.test.c index 29adb0915..ebfe794cb 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -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"); diff --git a/src/test_eressea.c b/src/test_eressea.c index 50ff37d19..4ea68180c 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -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); diff --git a/src/tests.c b/src/tests.c index fcb34040c..120d62e12 100644 --- a/src/tests.c +++ b/src/tests.c @@ -6,6 +6,7 @@ #include "reports.h" #include +#include #include #include #include @@ -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; diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 3d5032462..46dce6801 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -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