From a31de0da4f6be86786a4c0169ed61004052ff7b9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 11 Mar 2017 17:22:40 +0100 Subject: [PATCH 01/25] BUG 2306: TRANSLATIONS Plural/Singular mixup. https://bugs.eressea.de/view.php?id=2306 --- src/creport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/creport.c b/src/creport.c index d16f87f22..21e3f6d0b 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1096,10 +1096,10 @@ static char *cr_output_resource(char *buf, const resource_type *rtype, { const char *name, *tname; assert(rtype); - name = resourcename(rtype, 1); + name = resourcename(rtype, NMF_PLURAL); assert(name); buf += sprintf(buf, "RESOURCE %u\n", hashstring(rtype->_name)); - tname = LOC(loc, rtype->_name); + tname = LOC(loc, name); assert(tname); tname = translate(name, tname); assert(tname); From 49140f131e6a92177b267a24bead97d56ddda95c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 17 Mar 2017 20:30:07 +0100 Subject: [PATCH 02/25] allow PROMOTION and PROMOTE alternatives. German already allows this, and my ECheck change made it necessary for English, too: https://bugs.eressea.de/view.php?id=2280 --- conf/keywords.json | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/keywords.json b/conf/keywords.json index 7117217d7..4c9fa905d 100644 --- a/conf/keywords.json +++ b/conf/keywords.json @@ -2,6 +2,7 @@ "keywords": { "en" : { "grow": [ "GROW", "BREED", "PLANT" ], + "promote": ["PROMOTE", "PROMOTION" ], "combat": [ "COMBAT", "FIGHT" ] }, "de": { From 27d66adc74f92ba7418456a8fbd96bd5b28a362b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 18 Mar 2017 21:33:47 +0100 Subject: [PATCH 03/25] eliminate duplicate keyword warning --- res/core/en/strings.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/res/core/en/strings.xml b/res/core/en/strings.xml index 063194c5d..d1f744df1 100644 --- a/res/core/en/strings.xml +++ b/res/core/en/strings.xml @@ -1502,9 +1502,6 @@ PREFIX - - PROMOTION - CLAIM From f941c5552ff112592e82d473403146619e304260 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 23 Mar 2017 19:32:17 +0100 Subject: [PATCH 04/25] remove RF_SELECT code from split_allocations. the flag was only ever written, never read. --- src/economy.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/economy.c b/src/economy.c index ce174dd09..e3a6dc18d 100644 --- a/src/economy.c +++ b/src/economy.c @@ -1170,7 +1170,6 @@ static allocate_function get_allocator(const struct resource_type *rtype) void split_allocations(region * r) { allocation_list **p_alist = &allocations; - freset(r, RF_SELECT); while (*p_alist) { allocation_list *alist = *p_alist; const resource_type *rtype = alist->type; @@ -1178,7 +1177,6 @@ void split_allocations(region * r) const item_type *itype = resource2item(rtype); allocation **p_al = &alist->data; - freset(r, RF_SELECT); alloc(rtype, r, alist->data); while (*p_al) { @@ -1187,7 +1185,6 @@ void split_allocations(region * r) assert(itype || !"not implemented for non-items"); i_change(&al->unit->items, itype, al->get); produceexp(al->unit, itype->construction->skill, al->unit->number); - fset(r, RF_SELECT); } if (al->want == INT_MAX) al->want = al->get; From b44c5e54bfb892d304e80c97290596ac55dfc633 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 25 Mar 2017 10:37:13 +0100 Subject: [PATCH 05/25] =?UTF-8?q?Neuer=20Befehlespr=C3=A4fix:=20!=20zur=20?= =?UTF-8?q?Unterdr=C3=BCckung=20von=20Fehlern.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tests/laws.lua | 1 + scripts/tests/orders.lua | 12 +++++++ src/kernel/messages.c | 19 +++++++---- src/kernel/messages.test.c | 18 ++++++++++ src/kernel/order.c | 24 +++++++++---- src/kernel/order.h | 1 + src/kernel/order.test.c | 70 +++++++++++++++++++++++++++++++------- src/monsters.c | 10 ++---- src/piracy.c | 3 ++ src/piracy.test.c | 1 + 10 files changed, 125 insertions(+), 34 deletions(-) diff --git a/scripts/tests/laws.lua b/scripts/tests/laws.lua index 8b64ffb7f..3a724a440 100644 --- a/scripts/tests/laws.lua +++ b/scripts/tests/laws.lua @@ -16,6 +16,7 @@ function setup() "attack" : "ATTACKIERE", "maketemp" : "MACHETEMP", "end" : "ENDE", + "use" : "BENUTZEN", "recruit" : "REKRUTIERE" } }, diff --git a/scripts/tests/orders.lua b/scripts/tests/orders.lua index d88a59293..af0919640 100644 --- a/scripts/tests/orders.lua +++ b/scripts/tests/orders.lua @@ -20,6 +20,18 @@ function setup() eressea.settings.set("NewbieImmunity", "0") end +function test_no_errors() + turn_begin() + u:add_order("!BENUTZEN 23 Yanxspirit") + turn_process() + assert_equal(0, f:count_msg_type('error43')) + u:clear_orders() + u:add_order("BENUTZEN 23 Yanxspirit") + turn_process() + assert_equal(1, f:count_msg_type('error43')) + turn_end() +end + function test_learn() u:add_order("LERNEN Hiebwaffen") _G.process_orders() diff --git a/src/kernel/messages.c b/src/kernel/messages.c index f74e9c0d7..a157e276c 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -86,9 +86,6 @@ struct message *msg_feedback(const struct unit *u, struct order *ord, variant var; memset(args, 0, sizeof(args)); - if (ord == NULL) - ord = u->thisorder; - if (!mtype) { log_warning("trying to create message of unknown type \"%s\"\n", name); if (!mt_find("missing_feedback")) { @@ -248,8 +245,12 @@ void addmessage(region * r, faction * f, const char *s, msg_t mtype, int level) message * msg_error(const unit * u, struct order *ord, int mno) { static char msgname[20]; - if (fval(u->faction, FFL_NPC)) - return 0; + if (ord && ord->_noerror) { + return NULL; + } + if (fval(u->faction, FFL_NPC)) { + return NULL; + } sprintf(msgname, "error%d", mno); return msg_feedback(u, ord, msgname, ""); } @@ -259,7 +260,9 @@ message * cmistake(const unit * u, struct order *ord, int mno, int mtype) message * result; UNUSED_ARG(mtype); result = msg_error(u, ord, mno); - ADDMSG(&u->faction->msgs, result); + if (result) { + ADDMSG(&u->faction->msgs, result); + } return result; } @@ -267,7 +270,9 @@ void syntax_error(const struct unit *u, struct order *ord) { message * result; result = msg_error(u, ord, 10); - ADDMSG(&u->faction->msgs, result); + if (result) { + ADDMSG(&u->faction->msgs, result); + } } void free_messagelist(mlist *msgs) diff --git a/src/kernel/messages.test.c b/src/kernel/messages.test.c index 7b0f2dd5e..9cc3a138b 100644 --- a/src/kernel/messages.test.c +++ b/src/kernel/messages.test.c @@ -1,6 +1,9 @@ #include #include "messages.h" +#include "unit.h" +#include "order.h" + #include #include @@ -68,11 +71,26 @@ static void test_merge_split(CuTest *tc) { test_cleanup(); } +static void test_noerror(CuTest *tc) { + unit *u; + struct locale *lang; + + test_setup(); + lang = test_create_locale(); + u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); + u->thisorder = parse_order("!@move", lang); + CuAssertTrue(tc, u->thisorder->_persistent); + CuAssertTrue(tc, u->thisorder->_noerror); + CuAssertPtrEquals(tc, NULL, msg_error(u, u->thisorder, 100)); + test_cleanup(); +} + CuSuite *get_messages_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_missing_message); SUITE_ADD_TEST(suite, test_merge_split); SUITE_ADD_TEST(suite, test_message); + SUITE_ADD_TEST(suite, test_noerror); return suite; } diff --git a/src/kernel/order.c b/src/kernel/order.c index 776190b67..9e7a45991 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -99,6 +99,15 @@ char* get_command(const order *ord, char *sbuffer, size_t size) { keyword_t kwd = ORD_KEYWORD(ord); int bytes; + if (ord->_noerror) { + if (size > 0) { + *bufp++ = '!'; + --size; + } + else { + WARN_STATIC_BUFFER(); + } + } if (ord->_persistent) { if (size > 0) { *bufp++ = '@'; @@ -159,6 +168,7 @@ order *copy_order(const order * src) order *ord = (order *)malloc(sizeof(order)); ord->next = NULL; ord->_persistent = src->_persistent; + ord->_noerror = src->_noerror; ord->data = src->data; ++ord->data->_refcount; return ord; @@ -280,7 +290,7 @@ void close_orders(void) { } static order *create_order_i(keyword_t kwd, const char *sptr, bool persistent, - const struct locale *lang) + bool noerror, const struct locale *lang) { order *ord = NULL; int lindex; @@ -313,6 +323,7 @@ static order *create_order_i(keyword_t kwd, const char *sptr, bool persistent, ord = (order *)malloc(sizeof(order)); ord->_persistent = persistent; + ord->_noerror = noerror; ord->next = NULL; ord->data = create_data(kwd, sptr, lindex); @@ -373,7 +384,7 @@ order *create_order(keyword_t kwd, const struct locale * lang, else { zBuffer[0] = 0; } - return create_order_i(kwd, zBuffer, false, lang); + return create_order_i(kwd, zBuffer, false, false, lang); } order *parse_order(const char *s, const struct locale * lang) @@ -386,11 +397,12 @@ order *parse_order(const char *s, const struct locale * lang) if (*s != 0) { keyword_t kwd; const char *sptr; - bool persistent = false; + bool persistent = false, noerror = false; const char * p; - while (*s == '@') { - persistent = true; + while (*s == '!' || *s=='@') { + if (*s=='!') noerror = true; + else if (*s == '@') persistent = true; ++s; } sptr = s; @@ -407,7 +419,7 @@ order *parse_order(const char *s, const struct locale * lang) if (kwd != NOKEYWORD) { while (isspace(*(unsigned char *)sptr)) ++sptr; s = sptr; - return create_order_i(kwd, s, persistent, lang); + return create_order_i(kwd, s, persistent, noerror, lang); } } return NULL; diff --git a/src/kernel/order.h b/src/kernel/order.h index 7f4b00a5e..bf4d02982 100644 --- a/src/kernel/order.h +++ b/src/kernel/order.h @@ -37,6 +37,7 @@ extern "C" { /* do not access this data: */ struct order_data *data; bool _persistent; + bool _noerror; } order; /* constructor */ diff --git a/src/kernel/order.test.c b/src/kernel/order.test.c index f5eb51c6f..876d75b1e 100644 --- a/src/kernel/order.test.c +++ b/src/kernel/order.test.c @@ -14,14 +14,13 @@ static void test_create_order(CuTest *tc) { order *ord; struct locale * lang; - test_cleanup(); - lang = get_or_create_locale("en"); + test_setup(); + lang = test_create_locale(); - locale_setstring(lang, "keyword::move", "MOVE"); ord = create_order(K_MOVE, lang, "NORTH"); CuAssertPtrNotNull(tc, ord); CuAssertIntEquals(tc, K_MOVE, getkeyword(ord)); - CuAssertStrEquals(tc, "MOVE NORTH", get_command(ord, cmd, sizeof(cmd))); + CuAssertStrEquals(tc, "move NORTH", get_command(ord, cmd, sizeof(cmd))); CuAssertIntEquals(tc, K_MOVE, init_order(ord)); CuAssertStrEquals(tc, "NORTH", getstrtoken()); @@ -34,19 +33,44 @@ static void test_parse_order(CuTest *tc) { order *ord; struct locale * lang; - test_cleanup(); - lang = get_or_create_locale("en"); + test_setup(); + lang = test_create_locale(); - locale_setstring(lang, "keyword::move", "MOVE"); - init_keyword(lang, K_MOVE, "MOVE"); ord = parse_order("MOVE NORTH", lang); CuAssertPtrNotNull(tc, ord); + CuAssertTrue(tc, !ord->_noerror); + CuAssertTrue(tc, !ord->_persistent); CuAssertIntEquals(tc, K_MOVE, getkeyword(ord)); - CuAssertStrEquals(tc, "MOVE NORTH", get_command(ord, cmd, sizeof(cmd))); + CuAssertStrEquals(tc, "move NORTH", get_command(ord, cmd, sizeof(cmd))); CuAssertIntEquals(tc, K_MOVE, init_order(ord)); CuAssertStrEquals(tc, "NORTH", getstrtoken()); free_order(ord); + + ord = parse_order("!MOVE NORTH", lang); + CuAssertPtrNotNull(tc, ord); + CuAssertTrue(tc, ord->_noerror); + CuAssertTrue(tc, !ord->_persistent); + free_order(ord); + + ord = parse_order("@MOVE NORTH", lang); + CuAssertPtrNotNull(tc, ord); + CuAssertTrue(tc, !ord->_noerror); + CuAssertTrue(tc, ord->_persistent); + free_order(ord); + + ord = parse_order("@!MOVE NORTH", lang); + CuAssertPtrNotNull(tc, ord); + CuAssertTrue(tc, ord->_noerror); + CuAssertTrue(tc, ord->_persistent); + free_order(ord); + + ord = parse_order("!@MOVE NORTH", lang); + CuAssertPtrNotNull(tc, ord); + CuAssertTrue(tc, ord->_noerror); + CuAssertTrue(tc, ord->_persistent); + free_order(ord); + test_cleanup(); } @@ -81,7 +105,7 @@ static void test_parse_make_temp(CuTest *tc) { lang = get_or_create_locale("en"); locale_setstring(lang, keyword(K_MAKE), "MAKE"); locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP"); - locale_setstring(lang, "TEMP", "TEMP"); + locale_setstring(lang, parameters[P_TEMP], "TEMP"); init_locale(lang); ord = parse_order("M T herp", lang); @@ -156,9 +180,9 @@ static void test_replace_order(CuTest *tc) { struct locale * lang; test_cleanup(); - lang = get_or_create_locale("en"); - orig = create_order(K_MAKE, lang, 0); - repl = create_order(K_ALLY, lang, 0); + lang = test_create_locale(); + orig = create_order(K_MAKE, lang, NULL); + repl = create_order(K_ALLY, lang, NULL); replace_order(&orders, orig, repl); CuAssertPtrEquals(tc, 0, orders); orders = orig; @@ -171,6 +195,25 @@ static void test_replace_order(CuTest *tc) { test_cleanup(); } +static void test_get_command(CuTest *tc) { + struct locale * lang; + order *ord; + char buf[64]; + + test_setup(); + lang = test_create_locale(); + ord = create_order(K_MAKE, lang, "iron"); + CuAssertStrEquals(tc, "make iron", get_command(ord, buf, sizeof(buf))); + ord->_noerror = true; + CuAssertStrEquals(tc, "!make iron", get_command(ord, buf, sizeof(buf))); + ord->_persistent = true; + CuAssertStrEquals(tc, "!@make iron", get_command(ord, buf, sizeof(buf))); + ord->_noerror = false; + CuAssertStrEquals(tc, "@make iron", get_command(ord, buf, sizeof(buf))); + free_order(ord); + test_cleanup(); +} + CuSuite *get_order_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -183,5 +226,6 @@ CuSuite *get_order_suite(void) SUITE_ADD_TEST(suite, test_replace_order); SUITE_ADD_TEST(suite, test_skip_token); SUITE_ADD_TEST(suite, test_getstrtoken); + SUITE_ADD_TEST(suite, test_get_command); return suite; } diff --git a/src/monsters.c b/src/monsters.c index 0d9857024..4edaeedea 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -493,18 +493,12 @@ static order *make_movement_order(unit * u, const region * target, int moves, if (plan == NULL) return NULL; - bytes = - (int)strlcpy(bufp, - (const char *)LOC(u->faction->locale, keyword(K_MOVE)), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - while (position != moves && plan[position + 1]) { region *prev = plan[position]; region *next = plan[++position]; direction_t dir = reldirection(prev, next); assert(dir != NODIRECTION && dir != D_SPECIAL); - if (size > 1) { + if (size > 1 && bufp != zOrder) { *bufp++ = ' '; --size; } @@ -516,7 +510,7 @@ static order *make_movement_order(unit * u, const region * target, int moves, } *bufp = 0; - return parse_order(zOrder, u->faction->locale); + return create_order(K_MOVE, u->faction->locale, zOrder); } void random_growl(const unit *u, region *target, int rand) diff --git a/src/piracy.c b/src/piracy.c index 80b1dd47a..3025d484c 100644 --- a/src/piracy.c +++ b/src/piracy.c @@ -66,6 +66,8 @@ static attrib *mk_piracy(const faction * pirate, const faction * target, } static bool validate_pirate(unit *u, order *ord) { + assert(u); + assert(ord); if (fval(u_race(u), RCF_SWIM | RCF_FLY)) return true; if (!u->ship) { @@ -128,6 +130,7 @@ void piracy_cmd(unit * u) int saff = 0; int *il; + assert(u->thisorder); if (!validate_pirate(u, u->thisorder)) { return; } diff --git a/src/piracy.test.c b/src/piracy.test.c index 40e66af18..33860e03f 100644 --- a/src/piracy.test.c +++ b/src/piracy.test.c @@ -137,6 +137,7 @@ static void test_piracy_cmd_errors(CuTest * tc) { u_set_ship(u, test_create_ship(u->region, st_boat)); u2 = test_create_unit(u->faction, u->region); + u2->thisorder = create_order(K_PIRACY, f->locale, ""); u_set_ship(u2, u->ship); test_clear_messages(f); From 868f4e6cef80afb4e4ee7d7a2d9b9f578a142450 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 25 Mar 2017 11:36:29 +0100 Subject: [PATCH 06/25] also apply noerror rules to msg_feedback. --- src/kernel/messages.c | 77 ++++++++++++++++++++------------------ src/kernel/messages.test.c | 1 + 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/kernel/messages.c b/src/kernel/messages.c index a157e276c..d3cd4f99b 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -78,14 +78,15 @@ variant v) struct message *msg_feedback(const struct unit *u, struct order *ord, const char *name, const char *sig, ...) { - va_list marker; const message_type *mtype = mt_find(name); - char paramname[64]; - const char *ic = sig; variant args[16]; variant var; memset(args, 0, sizeof(args)); + if (ord && ord->_noerror) { + return NULL; + } + if (!mtype) { log_warning("trying to create message of unknown type \"%s\"\n", name); if (!mt_find("missing_feedback")) { @@ -103,41 +104,46 @@ struct message *msg_feedback(const struct unit *u, struct order *ord, var.v = (void *)ord; arg_set(args, mtype, "command", var); - va_start(marker, sig); - while (*ic && !isalnum(*ic)) - ic++; - while (*ic) { - char *oc = paramname; - int i; + if (sig) { + const char *ic = sig; + va_list marker; - while (isalnum(*ic)) - *oc++ = *ic++; - *oc = '\0'; - - for (i = 0; i != mtype->nparameters; ++i) { - if (!strcmp(paramname, mtype->pnames[i])) - break; - } - if (i != mtype->nparameters) { - if (mtype->types[i]->vtype == VAR_VOIDPTR) { - args[i].v = va_arg(marker, void *); - } - else if (mtype->types[i]->vtype == VAR_INT) { - args[i].i = va_arg(marker, int); - } - else { - assert(!"unknown variant type"); - } - } - else { - log_error("invalid parameter %s for message type %s\n", paramname, mtype->name); - assert(!"program aborted."); - } + va_start(marker, sig); while (*ic && !isalnum(*ic)) ic++; - } - va_end(marker); + while (*ic) { + char paramname[64]; + char *oc = paramname; + int i; + while (isalnum(*ic)) + *oc++ = *ic++; + *oc = '\0'; + + for (i = 0; i != mtype->nparameters; ++i) { + if (!strcmp(paramname, mtype->pnames[i])) + break; + } + if (i != mtype->nparameters) { + if (mtype->types[i]->vtype == VAR_VOIDPTR) { + args[i].v = va_arg(marker, void *); + } + else if (mtype->types[i]->vtype == VAR_INT) { + args[i].i = va_arg(marker, int); + } + else { + assert(!"unknown variant type"); + } + } + else { + log_error("invalid parameter %s for message type %s\n", paramname, mtype->name); + assert(!"program aborted."); + } + while (*ic && !isalnum(*ic)) + ic++; + } + va_end(marker); + } return msg_create(mtype, args); } @@ -245,9 +251,6 @@ void addmessage(region * r, faction * f, const char *s, msg_t mtype, int level) message * msg_error(const unit * u, struct order *ord, int mno) { static char msgname[20]; - if (ord && ord->_noerror) { - return NULL; - } if (fval(u->faction, FFL_NPC)) { return NULL; } diff --git a/src/kernel/messages.test.c b/src/kernel/messages.test.c index 9cc3a138b..cd301756d 100644 --- a/src/kernel/messages.test.c +++ b/src/kernel/messages.test.c @@ -82,6 +82,7 @@ static void test_noerror(CuTest *tc) { CuAssertTrue(tc, u->thisorder->_persistent); CuAssertTrue(tc, u->thisorder->_noerror); CuAssertPtrEquals(tc, NULL, msg_error(u, u->thisorder, 100)); + CuAssertPtrEquals(tc, NULL, msg_feedback(u, u->thisorder, "error_unit_not_found", NULL)); test_cleanup(); } From 733c754e0f1cca7bb656cb5a92550ac962f48ce0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 25 Mar 2017 14:15:01 +0100 Subject: [PATCH 07/25] rename some configuration options. add them to the valid keys for eressea.ini, too. --- conf/e2/config.json | 4 +--- conf/e3/config.json | 4 +--- src/creport.c | 2 +- src/gmtool.c | 4 ++-- src/main.c | 2 ++ 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/conf/e2/config.json b/conf/e2/config.json index f9f9b2df0..46ee01497 100644 --- a/conf/e2/config.json +++ b/conf/e2/config.json @@ -21,9 +21,7 @@ "GiveRestriction": 3, "hunger.long": true, "init_spells": 0, - "world.era": 2, - "seed.population.min": 8, - "seed.population.max": 8, + "game.era": 2, "rules.reserve.twophase": true, "rules.give.max_men": -1, "rules.check_overload": false, diff --git a/conf/e3/config.json b/conf/e3/config.json index a42961e03..beb45f35d 100644 --- a/conf/e3/config.json +++ b/conf/e3/config.json @@ -51,9 +51,7 @@ "recruit.allow_merge": true, "study.expensivemigrants": true, "study.speedup": 2, - "world.era": 3, - "seed.population.min": 8, - "seed.population.max": 8, + "game.era": 3, "rules.reserve.twophase": true, "rules.owners.force_leave": false, "rules.wage.function": 2, diff --git a/src/creport.c b/src/creport.c index 14e6e8faa..113bb70ca 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1501,7 +1501,7 @@ report_computer(const char *filename, report_context * ctx, const char *bom) static int rc_cache; if (era < 0) { - era = config_get_int("world.era", 1); + era = config_get_int("game.era", 1); } if (F == NULL) { perror(filename); diff --git a/src/gmtool.c b/src/gmtool.c index 148aafe6d..674e139f7 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -902,8 +902,8 @@ static void handlekey(state * st, int c) new_players = read_newfactions(sbuffer); } cnormalize(&st->cursor, &nx, &ny); - minpop = config_get_int("seed.population.min", 8); - maxpop = config_get_int("seed.population.max", minpop); + minpop = config_get_int("editor.population.min", 8); + maxpop = config_get_int("editor.population.max", minpop); if (maxpop > minpop) { n = rng_int() % (maxpop - minpop) + minpop; } diff --git a/src/main.c b/src/main.c index a9a8339d4..7b1c62c38 100644 --- a/src/main.c +++ b/src/main.c @@ -82,9 +82,11 @@ static const char * valid_keys[] = { "game.memcheck", "game.email", "game.mailcmd", + "game.era", "game.sender", "editor.color", "editor.codepage", + "editor.population.", "lua.", NULL }; From ce0c6a0d32abf597b132685ce0c227a624e1f7ff Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 25 Mar 2017 18:35:00 +0100 Subject: [PATCH 08/25] pdcurses version 3.4 warning suppression. --- src/platform.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/platform.h b/src/platform.h index 6ccbb8d6d..a56328485 100644 --- a/src/platform.h +++ b/src/platform.h @@ -1,5 +1,7 @@ #pragma once +#define _LP64 0 /* fix a warning in pdcurses 3.4 */ + #ifndef UNILIB_H #define UNILIB_H From d238e1819159513852d4aff18914b136d6ae83f9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 25 Mar 2017 18:36:27 +0100 Subject: [PATCH 09/25] fix duplicate definition --- src/platform.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/platform.h b/src/platform.h index a56328485..104ff28d7 100644 --- a/src/platform.h +++ b/src/platform.h @@ -1,6 +1,8 @@ #pragma once +#ifndef _LP64 #define _LP64 0 /* fix a warning in pdcurses 3.4 */ +#endif #ifndef UNILIB_H #define UNILIB_H From 8b87eb608f8273e96e31578f560e2f6929cf920b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 25 Mar 2017 18:35:00 +0100 Subject: [PATCH 10/25] pdcurses version 3.4 warning suppression. --- src/platform.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/platform.h b/src/platform.h index 6ccbb8d6d..a56328485 100644 --- a/src/platform.h +++ b/src/platform.h @@ -1,5 +1,7 @@ #pragma once +#define _LP64 0 /* fix a warning in pdcurses 3.4 */ + #ifndef UNILIB_H #define UNILIB_H From afd1cb4039da0db0f092cdcc07bea2582a0795ad Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 18 Mar 2017 10:33:52 +0100 Subject: [PATCH 11/25] cherry-pick test for mine and smithy --- scripts/tests/economy.lua | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/scripts/tests/economy.lua b/scripts/tests/economy.lua index fe1574887..a1bfa3bb6 100644 --- a/scripts/tests/economy.lua +++ b/scripts/tests/economy.lua @@ -11,6 +11,46 @@ function setup() eressea.settings.set("rules.encounters", "0") end +function test_mine_bonus() + local r = region.create(0, 0, "mountain") + r:set_resource("iron", 100) + local level = r:get_resourcelevel("iron") + assert_equal(1, level) + local u = unit.create(faction.create("human"), r) + u.number = 10 + u:set_skill("mining", 1) + u:add_order("MACHE EISEN") + process_orders() + assert_equal(10, u:get_item("iron")) + assert_equal(90, r:get_resource("iron")) + + u.building = building.create(r, "mine") + u.building.size = 10 + u:add_item("money", 500) -- maintenance + process_orders() + assert_equal(30, u:get_item("iron")) + assert_equal(80, r:get_resource("iron")) +end + +function test_smithy_bonus() + local r = region.create(0, 0, "mountain") + local u = unit.create(faction.create("human"), r) + u:set_skill("weaponsmithing", 5) + u:add_item("iron", 20) + u:add_order("MACHE SCHWERT") + process_orders() + assert_equal(1, u:get_item('sword')) + assert_equal(19, u:get_item('iron')) + + u.building = building.create(r, "smithy") + u.building.size = 10 + u:add_item("money", 300) -- maintenance + u:add_item("log", 1) -- maintenance + process_orders() + assert_equal(3, u:get_item('sword')) + assert_equal(18, u:get_item('iron')) +end + function test_no_guards() local r = region.create(0, 0, "plain") r:set_resource("tree", 100) From ec375baa03e1b81ebda5f19cddf1acd430ba2455 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 18 Mar 2017 08:00:35 +0100 Subject: [PATCH 12/25] Zwergenbonus gibt es nur in E2 --- scripts/tests/e2/e2features.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua index cba363d83..2f8764119 100644 --- a/scripts/tests/e2/e2features.lua +++ b/scripts/tests/e2/e2features.lua @@ -39,6 +39,29 @@ function test_herbalism() assert_equal(98, r:get_resource("seed")) end +function test_dwarf_bonus() + local r = region.create(0, 0, "mountain") + r:set_resource("iron", 100) + local level = r:get_resourcelevel("iron") + assert_equal(1, level) + local u = unit.create(faction.create('test@example.com', "dwarf"), r) + assert_equal("dwarf", u.faction.race) + assert_equal("dwarf", u.race) + u.faction.name = "Zwerge" + u.number = 10 + u:set_skill("mining", 1) + u:add_order("MACHE EISEN") + process_orders() + assert_equal(30, u:get_item("iron")) + assert_equal(82, r:get_resource("iron")) + u.building = building.create(r, "mine") + u.building.size = 10 + u:add_item("money", 500) -- maintenance + process_orders() + assert_equal(70, u:get_item("iron")) + assert_equal(70, r:get_resource("iron")) +end + function test_build_harbour() -- try to reproduce mantis bug 2221 local r = region.create(0, 0, "plain") From 10edb1d3e9ec12300f05c36c98647841f719ae1e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 27 Feb 2017 19:35:14 +0100 Subject: [PATCH 13/25] enable process_orders to be done in steps. by checking before turn_end(), we can sense temporary attributes and curses on a unit before they age away. --- src/bind_unit.c | 19 +++++++++++++++++ src/bindings.c | 53 +++++++++++++++++++---------------------------- src/laws.c | 49 +++++++++++++++++++++++++++++++++++++++++-- src/laws.h | 4 +++- src/util/attrib.c | 16 +++++++++++--- src/util/attrib.h | 18 ++++++++-------- 6 files changed, 112 insertions(+), 47 deletions(-) diff --git a/src/bind_unit.c b/src/bind_unit.c index c8ac2b362..0358e1938 100755 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -26,6 +26,7 @@ without prior permission by the authors of Eressea. /* kernel includes */ #include #include +#include #include #include #include @@ -770,6 +771,21 @@ static int tolua_unit_get_orders(lua_State * L) return 1; } +static int tolua_unit_is_cursed(lua_State *L) { + unit *self = (unit *)tolua_tousertype(L, 1, 0); + const char *name = tolua_tostring(L, 2, 0); + lua_pushboolean(L, self->attribs && curse_active(get_curse(self->attribs, ct_find(name)))); + return 1; +} + +static int tolua_unit_has_attrib(lua_State *L) { + unit *self = (unit *)tolua_tousertype(L, 1, 0); + const char *name = tolua_tostring(L, 2, 0); + attrib * a = a_find(self->attribs, at_find(name)); + lua_pushboolean(L, a != NULL); + return 1; +} + static int tolua_unit_get_flag(lua_State * L) { unit *self = (unit *)tolua_tousertype(L, 1, 0); @@ -956,6 +972,9 @@ void tolua_unit_open(lua_State * L) tolua_function(L, TOLUA_CAST "clear_orders", &tolua_unit_clear_orders); tolua_variable(L, TOLUA_CAST "orders", &tolua_unit_get_orders, 0); + tolua_function(L, TOLUA_CAST "is_cursed", &tolua_unit_is_cursed); + tolua_function(L, TOLUA_CAST "has_attrib", &tolua_unit_has_attrib); + /* key-attributes for named flags: */ tolua_function(L, TOLUA_CAST "set_flag", &tolua_unit_set_flag); tolua_function(L, TOLUA_CAST "get_flag", &tolua_unit_get_flag); diff --git a/src/bindings.c b/src/bindings.c index 18261a507..1d6270b35 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -480,44 +480,30 @@ static int tolua_write_reports(lua_State * L) return 1; } -static void reset_game(void) -{ - region *r; - faction *f; - for (r = regions; r; r = r->next) { - unit *u; - building *b; - r->flags &= RF_SAVEMASK; - for (u = r->units; u; u = u->next) { - u->flags &= UFL_SAVEMASK; - } - for (b = r->buildings; b; b = b->next) { - b->flags &= BLD_SAVEMASK; - } - if (r->land && r->land->ownership && r->land->ownership->owner) { - faction *owner = r->land->ownership->owner; - if (owner == get_monsters()) { - /* some compat-fix, i believe. */ - owner = update_owners(r); - } - if (owner) { - fset(r, RF_GUARDED); - } - } - } - for (f = factions; f; f = f->next) { - f->flags &= FFL_SAVEMASK; - } -} - static int tolua_process_orders(lua_State * L) { - ++turn; - reset_game(); processorders(); return 0; } +static int tolua_turn_begin(lua_State * L) +{ + turn_begin(); + return 0; +} + +static int tolua_turn_process(lua_State * L) +{ + turn_process(); + return 0; +} + +static int tolua_turn_end(lua_State * L) +{ + turn_end(); + return 0; +} + static int tolua_write_passwords(lua_State * L) { int result = writepasswd(); @@ -1063,6 +1049,9 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile) tolua_function(L, TOLUA_CAST "factions", tolua_get_factions); tolua_function(L, TOLUA_CAST "regions", tolua_get_regions); tolua_function(L, TOLUA_CAST "read_turn", tolua_read_turn); + tolua_function(L, TOLUA_CAST "turn_begin", tolua_turn_begin); + tolua_function(L, TOLUA_CAST "turn_process", tolua_turn_process); + tolua_function(L, TOLUA_CAST "turn_end", tolua_turn_end); tolua_function(L, TOLUA_CAST "process_orders", tolua_process_orders); tolua_function(L, TOLUA_CAST "init_reports", tolua_init_reports); tolua_function(L, TOLUA_CAST "write_reports", tolua_write_reports); diff --git a/src/laws.c b/src/laws.c index 3d996971b..1c71f1192 100644 --- a/src/laws.c +++ b/src/laws.c @@ -4194,16 +4194,54 @@ void init_processor(void) } } -void processorders(void) +static void reset_game(void) +{ + region *r; + faction *f; + for (r = regions; r; r = r->next) { + unit *u; + building *b; + r->flags &= RF_SAVEMASK; + for (u = r->units; u; u = u->next) { + u->flags &= UFL_SAVEMASK; + } + for (b = r->buildings; b; b = b->next) { + b->flags &= BLD_SAVEMASK; + } + if (r->land && r->land->ownership && r->land->ownership->owner) { + faction *owner = r->land->ownership->owner; + if (owner == get_monsters()) { + /* some compat-fix, i believe. */ + owner = update_owners(r); + } + if (owner) { + fset(r, RF_GUARDED); + } + } + } + for (f = factions; f; f = f->next) { + f->flags &= FFL_SAVEMASK; + } +} + +void turn_begin(void) +{ + ++turn; + reset_game(); +} + +void turn_process(void) { init_processor(); process(); - /*************************************************/ if (config_get_int("modules.markets", 0)) { do_markets(); } +} +void turn_end(void) +{ log_info(" - Attribute altern"); ageing(); remove_empty_units(); @@ -4218,6 +4256,13 @@ void processorders(void) update_spells(); } +void processorders(void) +{ + turn_begin(); + turn_process(); + turn_end(); +} + void update_subscriptions(void) { FILE *F; diff --git a/src/laws.h b/src/laws.h index f05c11ab4..090d2b978 100755 --- a/src/laws.h +++ b/src/laws.h @@ -53,8 +53,10 @@ extern "C" { int enter_building(struct unit *u, struct order *ord, int id, bool report); int enter_ship(struct unit *u, struct order *ord, int id, bool report); - /* eressea-specific. put somewhere else, please. */ void processorders(void); + void turn_begin(void); + void turn_process(void); + void turn_end(void); void new_units(void); void defaultorders(void); diff --git a/src/util/attrib.c b/src/util/attrib.c index fda143168..993f634d2 100644 --- a/src/util/attrib.c +++ b/src/util/attrib.c @@ -179,7 +179,17 @@ void at_register(attrib_type * at) at_hash[at->hashkey % MAXATHASH] = at; } -static attrib_type *at_find(unsigned int hk) +struct attrib_type *at_find(const char *name) { + attrib_type *find; + unsigned int hash = __at_hashkey(name); + find = at_hash[hash % MAXATHASH]; + while (find && hash != find->hashkey) { + find = find->nexthash; + } + return find; +} + +static attrib_type *at_find_key(unsigned int hk) { const char *translate[3][2] = { { "zielregion", "targetregion" }, /* remapping: from 'zielregion, heute targetregion */ @@ -193,7 +203,7 @@ static attrib_type *at_find(unsigned int hk) int i = 0; while (translate[i][0]) { if (__at_hashkey(translate[i][0]) == hk) - return at_find(__at_hashkey(translate[i][1])); + return at_find_key(__at_hashkey(translate[i][1])); ++i; } } @@ -408,7 +418,7 @@ void at_deprecate(const char * name, int(*reader)(attrib *, void *, struct gamed static int a_read_i(gamedata *data, attrib ** attribs, void *owner, unsigned int key) { int retval = AT_READ_OK; int(*reader)(attrib *, void *, struct gamedata *) = 0; - attrib_type *at = at_find(key); + attrib_type *at = at_find_key(key); attrib * na = 0; if (at) { diff --git a/src/util/attrib.h b/src/util/attrib.h index 601a6f32a..6043a960f 100644 --- a/src/util/attrib.h +++ b/src/util/attrib.h @@ -65,19 +65,19 @@ extern "C" { unsigned int hashkey; } attrib_type; - extern void at_register(attrib_type * at); - extern void at_deprecate(const char * name, int(*reader)(attrib *, void *, struct gamedata *)); + void at_register(attrib_type * at); + void at_deprecate(const char * name, int(*reader)(attrib *, void *, struct gamedata *)); + struct attrib_type *at_find(const char *name); void write_attribs(struct storage *store, struct attrib *alist, const void *owner); int read_attribs(struct gamedata *store, struct attrib **alist, void *owner); - extern attrib *a_select(attrib * a, const void *data, - bool(*compare) (const attrib *, const void *)); - extern attrib *a_find(attrib * a, const attrib_type * at); - extern attrib *a_add(attrib ** pa, attrib * at); - extern int a_remove(attrib ** pa, attrib * at); - extern void a_removeall(attrib ** a, const attrib_type * at); - extern attrib *a_new(const attrib_type * at); + attrib *a_select(attrib * a, const void *data, bool(*compare) (const attrib *, const void *)); + attrib *a_find(attrib * a, const attrib_type * at); + attrib *a_add(attrib ** pa, attrib * at); + int a_remove(attrib ** pa, attrib * at); + void a_removeall(attrib ** a, const attrib_type * at); + attrib *a_new(const attrib_type * at); int a_age(attrib ** attribs, void *owner); int a_read_orig(struct gamedata *data, attrib ** attribs, void *owner); From dcf1c7138b63e9401f7271ca3161586adc766a3d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 22 Mar 2017 20:37:09 +0100 Subject: [PATCH 14/25] make region:set_resource do the right thing also for adamantium --- scripts/tests/common.lua | 98 +++++++++++++++++---------------- scripts/tests/e2/adamantium.lua | 56 +++++++++++++++++++ scripts/tests/e2/init.lua | 1 + src/bind_region.c | 2 +- src/economy.c | 10 +++- src/economy.test.c | 10 ++-- src/kernel/region.c | 33 +++++++---- src/kernel/region.test.c | 27 +++++++++ src/kernel/resources.c | 32 +++++++---- src/kernel/resources.h | 6 +- src/kernel/save.c | 8 +-- src/modules/autoseed.c | 14 ----- src/report.test.c | 3 +- src/reports.c | 9 +-- 14 files changed, 205 insertions(+), 104 deletions(-) create mode 100644 scripts/tests/e2/adamantium.lua diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 03ae5db85..b8156a777 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -5,6 +5,10 @@ local function _test_create_ship(r) return s end +local function create_faction(race) + return faction.create(race .. '@eressea.de', race, "de") +end + local function one_unit(r, f) local u = unit.create(f, r, 1) u:add_item("money", u.number * 100) @@ -17,8 +21,8 @@ local function two_units(r, f1, f2) end local function two_factions() - local f1 = faction.create("one@eressea.de", "human", "de") - local f2 = faction.create("two@eressea.de", "elf", "de") + local f1 = create_faction('human') + local f2 = create_faction('elf') return f1, f2 end @@ -44,7 +48,7 @@ end function test_flags() local r = region.create(0, 0, "plain") - local f = faction.create("flags@eressea.de", "halfling", "de") + local f = create_faction('halfling') local u = unit.create(f, r, 1) local no = itoa36(f.id) local flags = 50332673 @@ -62,7 +66,7 @@ function test_elvenhorse_requires_riding_5() local r = region.create(0, 0, "plain") region.create(1, 0, "plain") local goal = region.create(2, 0, "plain") - local f = faction.create("riding@eressea.de", "halfling", "de") + local f = create_faction('halfling') local u = unit.create(f, r, 1) u:add_item("elvenhorse", 1) u:set_skill("riding", 6)-- halfling has -1 modifier @@ -76,7 +80,7 @@ function test_cannot_ride_elvenhorse_without_enough_skill() local r = region.create(0, 0, "plain") local goal = region.create(1, 0, "plain") region.create(2, 0, "plain") - local f = faction.create("elvenhorse@eressea.de", "halfling", "de") + local f = create_faction('halfling') local u = unit.create(f, r, 1) u:add_item("elvenhorse", 1) u:set_skill("riding", 5) -- halfling has -1 modifier @@ -96,7 +100,7 @@ end function test_demon_food() local r = region.create(0, 0, "plain") - local f = faction.create("demonfood@eressea.de", "demon", "de") + local f = create_faction('demon') local u = unit.create(f, r, 1) local p = r:get_resource("peasant") r:set_resource("peasant", 2000) @@ -136,7 +140,7 @@ function test_plane() local nx, ny = plane.normalize(pl, 4, 4) assert_equal(nx, -3, "normalization failed") assert_equal(ny, -3, "normalization failed") - local f = faction.create("plan@eressea.de", "human", "de") + local f = create_faction('human') f.id = atoi36("tpla") local r, x, y for x = -3, 3 do for y = -3, 3 do @@ -155,7 +159,7 @@ end function test_read_write() local r = region.create(0, 0, "plain") - local f = faction.create("readwrite@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r) u.number = 2 local fno = f.id @@ -184,7 +188,7 @@ end function test_descriptions() local info = "Descriptions can be very long. Bug 1984 behauptet, dass es Probleme gibt mit Beschreibungen die laenger als 120 Zeichen sind. This description is longer than 120 characters." local r = region.create(0, 0, "plain") - local f = faction.create("descriptions@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r, 1) local s = _test_create_ship(r) local b = building.create(r, "castle") @@ -236,7 +240,7 @@ end function test_faction() local r = region.create(0, 0, "plain") - local f = faction.create("testfaction@eressea.de", "human", "de") + local f = create_faction('human') assert(f) f.info = "Spazz" assert(f.info=="Spazz") @@ -259,7 +263,7 @@ end function test_unit() local r = region.create(0, 0, "plain") - local f = faction.create("testunit@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r) u.number = 20 u.name = "Enno" @@ -292,7 +296,7 @@ end function test_building() local u - local f = faction.create("testbuilding@eressea.de", "human", "de") + local f = create_faction('human') local r = region.create(0, 0, "plain") local b = building.create(r, "castle") u = unit.create(f, r) @@ -318,7 +322,7 @@ end function test_message() local r = region.create(0, 0, "plain") - local f = faction.create("testmessage@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r) local msg = message.create("item_create_spell") msg:set_unit("mage", u) @@ -346,7 +350,7 @@ function test_events() plain = region.create(0, 0, "plain") skill = 8 - f = faction.create("noreply2@eressea.de", "elf", "de") + f = create_faction('elf') f.age = 20 u = unit.create(f, plain) @@ -356,7 +360,7 @@ function test_events() u:add_order("NUMMER PARTEI test") u:add_handler("message", msg_handler) msg = "BOTSCHAFT EINHEIT " .. itoa36(u.id) .. " Du~Elf~stinken" - f = faction.create("noreply3@eressea.de", "elf", "de") + f = create_faction('elf') f.age = 20 u = unit.create(f, plain) @@ -371,7 +375,7 @@ end function test_renumber_ship() local r = region.create(0, 0, "plain") - local f = faction.create("noreply4@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r) local s = ship.create(r, config.ships[1]) u.ship = s @@ -386,7 +390,7 @@ end function test_recruit2() local r = region.create(0, 0, "plain") - local f = faction.create("noreply4@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r) u.number = 1 u:add_item("money", 2000) @@ -401,7 +405,7 @@ end function test_guard() region.create(1, 0, "plain") local r = region.create(0, 0, "plain") - local f1 = faction.create("noreply5@eressea.de", "human", "de") + local f1 = create_faction('human') f1.age = 20 local u1 = unit.create(f1, r, 10) u1:add_item("sword", 10) @@ -411,7 +415,7 @@ function test_guard() u1:add_order("NACH O") u1.name="Kalle Pimp" - local f2 = faction.create("noreply6@eressea.de", "human", "de") + local f2 = create_faction('human') f2.age = 20 local u2 = unit.create(f2, r, 1) local u3 = unit.create(f2, r, 1) @@ -429,7 +433,7 @@ end function test_recruit() local r = region.create(0, 0, "plain") - local f = faction.create("noreply7@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r) u.number = 1 local n = 3 @@ -445,7 +449,7 @@ end function test_produce() local r = region.create(0, 0, "plain") - local f = faction.create("noreply8@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r, 1) u:clear_orders() local sword = config.get_resource('sword') @@ -460,7 +464,7 @@ end function test_work() local r = region.create(0, 0, "plain") - local f = faction.create("noreply9@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r, 1) u:add_item("money", u.number * 10) -- humans cost 10 u:set_skill("herbalism", 5) @@ -473,7 +477,7 @@ end function test_upkeep() eressea.settings.set("rules.food.flags", "0") local r = region.create(0, 0, "plain") - local f = faction.create("noreply10@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r, 5) u:add_item("money", u.number * 11) u:clear_orders() @@ -485,7 +489,7 @@ end function test_id() local r = region.create(0, 0, "plain") - local f = faction.create("noreply11@eressea.de", "human", "de") + local f = create_faction('human') f.id = atoi36("42") assert_not_equal(f, get_faction(42)) assert_equal(f, get_faction("42")) @@ -521,7 +525,7 @@ function test_mallorn() m:set_resource("tree", 100) assert_equal(100, m:get_resource("tree")) - local f = faction.create("noreply13@eressea.de", "human", "de") + local f = create_faction('human') local u1 = unit.create(f, r, 1) u1:add_item("money", u1.number * 100) @@ -558,7 +562,7 @@ function test_coordinate_translation() local pl = plane.create(1, 500, 500, 1001, 1001) -- astralraum local pe = plane.create(1, -8761, 3620, 23, 23) -- eternath local r = region.create(1000, 1000, "plain") - local f = faction.create("noreply14@eressea.de", "human", "de") + local f = create_faction('human') assert_not_equal(nil, r) assert_equal(r.x, 1000) assert_equal(r.y, 1000) @@ -604,8 +608,8 @@ end function test_building_other() local r = region.create(0,0, "plain") - local f1 = faction.create("noreply17@eressea.de", "human", "de") - local f2 = faction.create("noreply18@eressea.de", "human", "de") + local f1 = create_faction('human') + local f2 = create_faction('human') local b = building.create(r, "castle") b.size = 10 local u1 = unit.create(f1, r, 3) @@ -632,7 +636,7 @@ end local function _test_create_laen() eressea.settings.set("rules.terraform.all", "1") local r = region.create(0,0, "mountain") - local f1 = faction.create("noreply19@eressea.de", "human", "de") + local f1 = create_faction('human') local u1 = unit.create(f1, r, 1) r:set_resource("laen", 50) return r, u1 @@ -671,7 +675,7 @@ end function test_mine() local r = region.create(0,0, "mountain") - local f1 = faction.create("noreply20@eressea.de", "human", "de") + local f1 = create_faction('human') local u1 = unit.create(f1, r, 1) u1:add_item("money", 1000) @@ -692,9 +696,9 @@ end function test_guard_resources() -- this is not quite http://bugs.eressea.de/view.php?id=1756 local r = region.create(0,0, "mountain") - local f1 = faction.create("noreply21@eressea.de", "human", "de") + local f1 = create_faction('human') f1.age=20 - local f2 = faction.create("noreply22@eressea.de", "human", "de") + local f2 = create_faction('human') f2.age=20 local u1 = unit.create(f1, r, 1) u1:add_item("money", 100) @@ -722,7 +726,7 @@ end function test_hero_hero_transfer() local r = region.create(0,0, "mountain") - local f = faction.create("noreply23@eressea.de", "human", "de") + local f = create_faction('human') f.age=20 local UFL_HERO = 128 @@ -743,7 +747,7 @@ end function test_hero_normal_transfer() local r = region.create(0,0, "mountain") - local f = faction.create("noreply24@eressea.de", "human", "de") + local f = create_faction('human') f.age=20 local UFL_HERO = 128 @@ -762,7 +766,7 @@ end function test_expensive_skills_cost_money() local r = region.create(0,0, "mountain") - local f = faction.create("noreply25@eressea.de", "elf", "de") + local f = create_faction('elf') local u = unit.create(f, r, 1) u:add_item("money", 10000) u:clear_orders() @@ -775,7 +779,7 @@ end function test_food_is_consumed() local r = region.create(0, 0, "plain") - local f = faction.create("noreply26@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r, 1) u:add_item("money", 100) u:clear_orders() @@ -787,7 +791,7 @@ end function test_food_can_override() local r = region.create(0, 0, "plain") - local f = faction.create("noreply27@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r, 1) u:add_item("money", 100) u:clear_orders() @@ -799,7 +803,7 @@ end function test_swim_and_survive() local r = region.create(0, 0, "plain") - local f = faction.create("noreply28@eressea.de", "human", "de") + local f = create_faction('human') f.nam = "chaos" local u = unit.create(f, r, 1) process_orders() @@ -813,7 +817,7 @@ end function test_swim_and_die() local r = region.create(0, 0, "plain") - local f = faction.create("noreply29@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r, 1) local uid = u.id process_orders() @@ -828,7 +832,7 @@ function test_ride_with_horse() region.create(1, 0, "plain") region.create(2, 0, "plain") local r = region.create(0, 0, "plain") - local f = faction.create("noreply30@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r, 1) u:add_item("horse", 1) local horse_cfg = config.get_resource("horse") @@ -851,7 +855,7 @@ function test_ride_with_horses_and_cart() region.create(1, 0, "plain") region.create(2, 0, "plain") local r = region.create(0, 0, "plain") - local f = faction.create("noreply31@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r, 1) local horse_cfg = config.get_resource("horse") local cart_cfg = config.get_resource("cart") @@ -904,7 +908,7 @@ function test_walk_and_carry_the_cart() region.create(1, 0, "plain") local r = region.create(2, 0, "plain") local r = region.create(0, 0, "plain") - local f = faction.create("noreply32@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r, 10) u:add_item("cart", 1) @@ -925,7 +929,7 @@ end function test_bug_1795_limit() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = create_faction('human') local u1 = one_unit(r,f) u1:add_item("money", 100000000) u1:add_order("REKRUTIEREN 9999") @@ -940,7 +944,7 @@ end function test_bug_1795_demons() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "demon", "de") + local f = create_faction('demon') local u1 = one_unit(r,f) r:set_resource("peasant", 2000) local peasants = r:get_resource("peasant") @@ -966,7 +970,7 @@ end function test_parser() local r = region.create(0, 0, "mountain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r, 1) local filename = "orders.txt" @@ -991,7 +995,7 @@ end function test_prefix() local r0 = region.create(0, 0, "plain") - local f1 = faction.create("noreply@eressea.de", "human", "de") + local f1 = create_faction('human') local u1 = unit.create(f1, r0, 1) set_order(u1, "PRAEFIX See") @@ -1018,7 +1022,7 @@ end function test_recruit() local r = region.create(0, 0, "plain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = create_faction('human') local u = unit.create(f, r, 1) u:add_item("money", 1000) diff --git a/scripts/tests/e2/adamantium.lua b/scripts/tests/e2/adamantium.lua new file mode 100644 index 000000000..2818db4e8 --- /dev/null +++ b/scripts/tests/e2/adamantium.lua @@ -0,0 +1,56 @@ +require "lunit" + +module("tests.e2.adamantium", package.seeall, lunit.testcase ) + +function setup() + eressea.free_game() + eressea.settings.set("nmr.timeout", "0") + eressea.settings.set("rules.food.flags", "4") + eressea.settings.set("rules.ship.storms", "0") + eressea.settings.set("rules.encounters", "0") +end + +local function create_faction(race) + return faction.create(race .. '@eressea.de', race, "de") +end + +local function _test_create_adamantium() + eressea.settings.set("rules.terraform.all", "1") + local r = region.create(0,0, "mountain") + local f1 = create_faction('human') + local u1 = unit.create(f1, r, 1) + r:set_resource("adamantium", 50) + assert_equal(50, r:get_resource("adamantium")) + return r, u1 +end + +function test_adamantium1() + local r, u1 = _test_create_adamantium() + + u1:add_item("money", 1000) + u1:set_skill("mining", 14) + u1:clear_orders() + u1:add_order("MACHEN Adamantium") + + process_orders() + assert_equal(0, u1:get_item("adamantium")) +end + +function test_adamantium2() + local r, u1 = _test_create_adamantium() + + u1:add_item("money", 1000) + u1:set_skill("mining", 15) + u1:clear_orders() + u1:add_order("MACHEN Adamantium") + + local b = building.create(r, "mine") + b.size = 10 + u1.building = b + local adamantium = r:get_resource("adamantium") + + process_orders() + assert_equal(1, u1:get_item("adamantium")) + assert_equal(adamantium - 1, r:get_resource("adamantium")) +end + diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 25e21f3e5..991014287 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -1,3 +1,4 @@ +require 'tests.e2.adamantium' require 'tests.e2.undead' require 'tests.e2.shiplanding' require 'tests.e2.e2features' diff --git a/src/bind_region.c b/src/bind_region.c index 51a5bedd4..f0c2ba87b 100644 --- a/src/bind_region.c +++ b/src/bind_region.c @@ -330,7 +330,7 @@ static int tolua_region_get_resourcelevel(lua_State * L) if (rtype != NULL) { const rawmaterial *rm; for (rm = r->resources; rm; rm = rm->next) { - if (rm->type->rtype == rtype) { + if (rm->rtype == rtype) { lua_pushinteger(L, rm->level); return 1; } diff --git a/src/economy.c b/src/economy.c index 248344e47..c210ee643 100644 --- a/src/economy.c +++ b/src/economy.c @@ -1091,7 +1091,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) avail = MIN(avail, nreq); if (need > 0) { int use = 0; - for (al = alist; al; al = al->next) + for (al = alist; al; al = al->next) { if (!fval(al, AFL_DONE)) { if (avail > 0) { int want = required(al->want - al->get, al->save); @@ -1106,9 +1106,13 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) al->get = MIN(al->want, al->get + x * al->save.sa[1] / al->save.sa[0]); } } + } if (use) { - assert(use <= rm->amount); - rm->type->use(rm, r, use); + rawmaterial_type *raw = rmt_get(rm->rtype); + if (raw && raw->use) { + assert(use <= rm->amount); + raw->use(rm, r, use); + } } assert(avail == 0 || nreq == 0); } diff --git a/src/economy.test.c b/src/economy.test.c index 7534afe7e..b77c69a86 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -382,13 +382,13 @@ static void test_make_item(CuTest *tc) { rmt_create(rtype); rdata = rtype->limit = calloc(1, sizeof(resource_limit)); add_resource(u->region, 1, 300, 150, rtype); - u->region->resources->amount = 300; /* there are 300 stones at level 1 */ + CuAssertIntEquals(tc, 300, region_getresource(u->region, rtype)); set_level(u, SK_ALCHEMY, 10); make_item(u, itype, 10); split_allocations(u->region); CuAssertIntEquals(tc, 11, get_item(u, itype)); - CuAssertIntEquals(tc, 290, u->region->resources->amount); /* used 10 stones to make 10 stones */ + CuAssertIntEquals(tc, 290, region_getresource(u->region, rtype)); /* used 10 stones to make 10 stones */ rdata->modifiers = calloc(2, sizeof(resource_mod)); rdata->modifiers[0].flags = RMF_SAVEMATERIAL; @@ -398,18 +398,18 @@ static void test_make_item(CuTest *tc) { make_item(u, itype, 10); split_allocations(u->region); CuAssertIntEquals(tc, 21, get_item(u, itype)); - CuAssertIntEquals(tc, 284, u->region->resources->amount); /* 60% saving = 6 stones make 10 stones */ + CuAssertIntEquals(tc, 284, region_getresource(u->region, rtype)); /* 60% saving = 6 stones make 10 stones */ make_item(u, itype, 1); split_allocations(u->region); CuAssertIntEquals(tc, 22, get_item(u, itype)); - CuAssertIntEquals(tc, 283, u->region->resources->amount); /* no free lunches */ + CuAssertIntEquals(tc, 283, region_getresource(u->region, rtype)); /* no free lunches */ rdata->modifiers[0].value = frac_make(1, 2); make_item(u, itype, 6); split_allocations(u->region); CuAssertIntEquals(tc, 28, get_item(u, itype)); - CuAssertIntEquals(tc, 280, u->region->resources->amount); /* 50% saving = 3 stones make 6 stones */ + CuAssertIntEquals(tc, 280, region_getresource(u->region, rtype)); /* 50% saving = 3 stones make 6 stones */ rdata->modifiers[0].flags = RMF_REQUIREDBUILDING; rdata->modifiers[0].race = NULL; diff --git a/src/kernel/region.c b/src/kernel/region.c index aefffa875..5223d8bf8 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -823,7 +823,7 @@ void region_setresource(region * r, const resource_type * rtype, int value) { rawmaterial *rm = r->resources; while (rm) { - if (rm->type->rtype == rtype) { + if (rm->rtype == rtype) { rm->amount = value; break; } @@ -837,14 +837,27 @@ void region_setresource(region * r, const resource_type * rtype, int value) else if (rtype == get_resourcetype(R_HORSE)) rsethorses(r, value); else { - int i; - for (i = 0; r->terrain->production[i].type; ++i) { - const terrain_production *production = r->terrain->production + i; - if (production->type == rtype) { - add_resource(r, 1, value, dice_rand(production->divisor), rtype); - break; + rawmaterial *rm; + if (r->terrain->production) { + int i; + for (i = 0; r->terrain->production[i].type; ++i) { + const terrain_production *production = r->terrain->production + i; + if (production->type == rtype) { + add_resource(r, 1, value, dice_rand(production->divisor), rtype); + return; + } } } + /* adamantium etc are not usually terraformed: */ + for (rm = r->resources; rm; rm = rm->next) { + if (rm->rtype == rtype) { + rm->amount = value; + return; + } + } + if (!rm) { + add_resource(r, 1, value, 150, rtype); + } } } } @@ -853,7 +866,7 @@ int region_getresource(const region * r, const resource_type * rtype) { const rawmaterial *rm; for (rm = r->resources; rm; rm = rm->next) { - if (rm->type->rtype == rtype) { + if (rm->rtype == rtype) { return rm->amount; } } @@ -1044,8 +1057,8 @@ void terraform_region(region * r, const terrain_type * terrain) if (terrain->production != NULL) { int i; for (i = 0; terrain->production[i].type; ++i) { - if (rm->type->rtype == terrain->production[i].type) { - rtype = rm->type->rtype; + if (rm->rtype == terrain->production[i].type) { + rtype = rm->rtype; break; } } diff --git a/src/kernel/region.test.c b/src/kernel/region.test.c index 892b37a8e..879faad50 100644 --- a/src/kernel/region.test.c +++ b/src/kernel/region.test.c @@ -1,6 +1,7 @@ #include #include "region.h" +#include "resources.h" #include "building.h" #include "unit.h" #include "terrain.h" @@ -52,10 +53,36 @@ static void test_region_get_owner(CuTest *tc) { test_cleanup(); } +static void test_region_getset_resource(CuTest *tc) { + region *r; + item_type *itype; + + test_setup(); + init_resources(); + itype = test_create_itemtype("iron"); + itype->construction = calloc(1, sizeof(construction)); + rmt_create(itype->rtype); + r = test_create_region(0, 0, NULL); + + region_setresource(r, itype->rtype, 50); + CuAssertIntEquals(tc, 50, region_getresource(r, itype->rtype)); + + region_setresource(r, get_resourcetype(R_HORSE), 10); + CuAssertIntEquals(tc, 10, region_getresource(r, get_resourcetype(R_HORSE))); + CuAssertIntEquals(tc, 10, rhorses(r)); + + region_setresource(r, get_resourcetype(R_PEASANT), 10); + CuAssertIntEquals(tc, 10, region_getresource(r, get_resourcetype(R_PEASANT))); + CuAssertIntEquals(tc, 10, rpeasants(r)); + + test_cleanup(); +} + CuSuite *get_region_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_terraform); + SUITE_ADD_TEST(suite, test_region_getset_resource); SUITE_ADD_TEST(suite, test_region_get_owner); return suite; } diff --git a/src/kernel/resources.c b/src/kernel/resources.c index a3f86aac6..8945e34c2 100644 --- a/src/kernel/resources.c +++ b/src/kernel/resources.c @@ -36,8 +36,10 @@ void update_resources(region * r) { struct rawmaterial *res = r->resources; while (res) { - if (res->type->update) - res->type->update(res, r); + struct rawmaterial_type *raw = rmt_get(res->rtype); + if (raw && raw->update) { + raw->update(res, r); + } res = res->next; } } @@ -55,7 +57,7 @@ static void update_resource(struct rawmaterial *res, double modifier) assert(res->amount > 0); } -void +struct rawmaterial * add_resource(region * r, int level, int base, int divisor, const resource_type * rtype) { @@ -66,11 +68,11 @@ const resource_type * rtype) rm->level = level; rm->startlevel = level; rm->base = base; + rm->amount = base; rm->divisor = divisor; rm->flags = 0; - rm->type = rmt_get(rtype); - update_resource(rm, 1.0); - rm->type->terraform(rm, r); + rm->rtype = rtype; + return rm; } void terraform_resources(region * r) @@ -87,7 +89,7 @@ void terraform_resources(region * r) const resource_type *rtype = production->type; for (rm = r->resources; rm; rm = rm->next) { - if (rm->type->rtype == rtype) + if (rm->rtype == rtype) break; } if (rm) { @@ -95,9 +97,16 @@ void terraform_resources(region * r) } if (terraform_all || chance(production->chance)) { - add_resource(r, dice_rand(production->startlevel), + rawmaterial *rm; + rawmaterial_type *raw; + rm = add_resource(r, dice_rand(production->startlevel), dice_rand(production->base), dice_rand(production->divisor), production->type); + update_resource(rm, 1.0); + raw = rmt_get(rm->rtype); + if (raw && raw->terraform) { + raw->terraform(rm, r); + } } } } @@ -142,7 +151,7 @@ static int visible_default(const rawmaterial * res, int skilllevel) /* resources are visible, if skill equals minimum skill to mine them * plus current level of difficulty */ { - const struct item_type *itype = res->type->rtype->itype; + const struct item_type *itype = res->rtype->itype; if (res->level <= 1 && res->level + itype->construction->minskill <= skilllevel + 1) { assert(res->amount > 0); @@ -166,7 +175,7 @@ static void use_default(rawmaterial * res, const region * r, int amount) int i; for (i = 0; r->terrain->production[i].type; ++i) { - if (res->type->rtype == r->terrain->production[i].type) + if (res->rtype == r->terrain->production[i].type) break; } @@ -178,8 +187,9 @@ static void use_default(rawmaterial * res, const region * r, int amount) struct rawmaterial *rm_get(region * r, const struct resource_type *rtype) { struct rawmaterial *rm = r->resources; - while (rm && rm->type->rtype != rtype) + while (rm && rm->rtype != rtype) { rm = rm->next; + } return rm; } diff --git a/src/kernel/resources.h b/src/kernel/resources.h index d7c0e5bfd..04e122f76 100644 --- a/src/kernel/resources.h +++ b/src/kernel/resources.h @@ -24,7 +24,7 @@ extern "C" { }; typedef struct rawmaterial { - const struct rawmaterial_type *type; + const struct resource_type *rtype; #ifdef LOMEM int amount:16; int level:8; @@ -79,8 +79,8 @@ extern "C" { struct rawmaterial_type *rmt_find(const char *str); struct rawmaterial_type *rmt_get(const struct resource_type *); - void add_resource(struct region *r, int level, int base, int divisor, - const struct resource_type *rtype); + struct rawmaterial *add_resource(struct region *r, int level, + int base, int divisor, const struct resource_type *rtype); struct rawmaterial_type *rmt_create(struct resource_type *rtype); #ifdef __cplusplus diff --git a/src/kernel/save.c b/src/kernel/save.c index 8316121f3..e1d6178fb 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -955,11 +955,11 @@ static region *readregion(struct gamedata *data, int x, int y) if (strcmp(name, "end") == 0) break; res = malloc(sizeof(rawmaterial)); - res->type = rmt_find(name); - if (res->type == NULL) { + res->rtype = rt_find(name); + if (!res->rtype || !res->rtype->raw) { log_error("invalid resourcetype %s in data.", name); } - assert(res->type != NULL); + assert(res->rtype); READ_INT(data->store, &n); res->level = n; READ_INT(data->store, &n); @@ -1068,7 +1068,7 @@ void writeregion(struct gamedata *data, const region * r) WRITE_INT(data->store, rhorses(r)); while (res) { - WRITE_TOK(data->store, res->type->rtype->_name); + WRITE_TOK(data->store, res->rtype->_name); WRITE_INT(data->store, res->level); WRITE_INT(data->store, res->amount); WRITE_INT(data->store, res->startlevel); diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index 1e2d2d23f..ffab4ca46 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -81,20 +81,6 @@ const terrain_type *random_terrain(const terrain_type * terrains[], return terrain; } -int seed_adamantium(region * r, int base) -{ - const resource_type *rtype = rt_find("adamantium"); - rawmaterial *rm; - for (rm = r->resources; rm; rm = rm->next) { - if (rm->type->rtype == rtype) - break; - } - if (!rm) { - add_resource(r, 1, base, 150, rtype); - } - return 0; -} - static int count_demand(const region * r) { struct demand *dmd; diff --git a/src/report.test.c b/src/report.test.c index 3c6a09ae1..2bdbebb7c 100644 --- a/src/report.test.c +++ b/src/report.test.c @@ -95,8 +95,7 @@ static void test_report_region(CuTest *tc) { mstream_init(&out); r = test_create_region(0, 0, 0); - add_resource(r, 1, 100, 10, rt_stone); - r->resources->amount = 135; + add_resource(r, 1, 135, 10, rt_stone); CuAssertIntEquals(tc, 1, r->resources->level); r->land->peasants = 5; r->land->horses = 7; diff --git a/src/reports.c b/src/reports.c index c23809a32..fe1f59775 100644 --- a/src/reports.c +++ b/src/reports.c @@ -448,12 +448,13 @@ const faction * viewer, bool see_unit) rawmaterial *res = r->resources; while (res) { int maxskill = 0; - const item_type *itype = resource2item(res->type->rtype); + const item_type *itype = resource2item(res->rtype); int minskill = itype->construction->minskill; skill_t skill = itype->construction->skill; int level = res->level + minskill - 1; int visible = -1; - if (res->type->visible == NULL) { + rawmaterial_type *raw = rmt_get(res->rtype); + if (raw->visible == NULL) { visible = res->amount; level = res->level + minskill - 1; } @@ -464,7 +465,7 @@ const faction * viewer, bool see_unit) int s = effskill(u, skill, 0); if (s > maxskill) { maxskill = s; - visible = res->type->visible(res, maxskill); + visible = raw->visible(res, maxskill); } } } @@ -472,7 +473,7 @@ const faction * viewer, bool see_unit) if (level >= 0 && visible >= 0) { if (n >= size) return -1; - report_resource(result + n, res->type->rtype, visible, level); + report_resource(result + n, res->rtype, visible, level); n++; } res = res->next; From bd40de1142ef1955de50d352bc2c13cc0129dcf9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 26 Mar 2017 17:38:45 +0200 Subject: [PATCH 15/25] additional testing for production rules. --- scripts/tests/e2/items.lua | 115 ++++++++++++++++++++ scripts/tests/e3/init.lua | 1 + scripts/tests/e3/production.lua | 179 ++++++++++++++++++++++++++++++++ scripts/tests/items.lua | 140 +++++++++++++++++++++++++ 4 files changed, 435 insertions(+) create mode 100644 scripts/tests/e2/items.lua create mode 100644 scripts/tests/e3/production.lua create mode 100644 scripts/tests/items.lua diff --git a/scripts/tests/e2/items.lua b/scripts/tests/e2/items.lua new file mode 100644 index 000000000..9bc747650 --- /dev/null +++ b/scripts/tests/e2/items.lua @@ -0,0 +1,115 @@ +require "lunit" + +module("tests.e2.items", package.seeall, lunit.testcase ) + +function setup() + eressea.free_game() + eressea.settings.set("nmr.timeout", "0") + eressea.settings.set("rules.food.flags", "4") + eressea.settings.set("rules.ship.storms", "0") + eressea.settings.set("rules.encounters", "0") + eressea.settings.set("magic.regeneration.enable", "0") +end + +function test_meow() + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:add_item("aoc", 1) + u:clear_orders() + u:add_order("BENUTZEN 1 Katzenamulett") + turn_begin() + turn_process() + assert_equal(1, u:get_item("aoc")) + assert_equal(1, r:count_msg_type('meow')) + turn_end() +end + +function test_aurapotion50() + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:add_item("aurapotion50", 1) + u:set_skill('magic', 10); + u.magic = 'gwyrrd' + u.aura = 0 + u:clear_orders() + u:add_order("BENUTZEN 1 Auratrank") + turn_begin() + turn_process() + assert_equal(0, u:get_item("aurapotion50")) + assert_equal(1, f:count_msg_type('aurapotion50')) + assert_equal(50, u.aura) + turn_end() +end + +function test_bagpipe() + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:add_item("bagpipeoffear", 1) + u:clear_orders() + u:add_order("BENUTZEN 1 Dudelsack") + process_orders() + assert_equal(1, u:get_item("bagpipeoffear")) + assert_equal(1, f:count_msg_type('bagpipeoffear_faction')) + assert_equal(1, r:count_msg_type('bagpipeoffear_region')) +end + +function test_speedsail() + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u.ship = ship.create(r, "boat") + u:add_item("speedsail", 2) + u:clear_orders() + u:add_order("BENUTZEN 1 Sonnensegel") + process_orders() + assert_equal(1, u:get_item("speedsail")) + assert_equal(1, f:count_msg_type('use_speedsail')) +end + +function test_foolpotion() + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + turn_begin() + u:add_item("p7", 1) + u:clear_orders() + u:add_order("BENUTZEN 1 Dumpfbackenbrot 4242") + turn_process() + assert_equal(1, u:get_item("p7")) + assert_equal(1, f:count_msg_type('feedback_unit_not_found')) + local u2 = unit.create(f, r, 1) + + u:clear_orders() + u:add_order("BENUTZEN 1 Dumpfbackenbrot " .. itoa36(u2.id)) + turn_process() + assert_equal(1, u:get_item("p7")) + assert_equal(1, f:count_msg_type('error64')) + + u:set_skill("stealth", 1); + turn_process() + assert_equal(0, u:get_item("p7")) + assert_equal(1, f:count_msg_type('givedumb')) + turn_end() +end + +function test_snowman() + local r = region.create(0, 0, "glacier") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:add_item("snowman", 1) + u:clear_orders() + u:add_order("BENUTZEN 1 Schneemann") + process_orders() + for u2 in r.units do + if u2.id~=u.id then + assert_equal("snowman", u2.race) + assert_equal(1000, u2.hp) + u = nil + break + end + end + assert_equal(nil, u) +end diff --git a/scripts/tests/e3/init.lua b/scripts/tests/e3/init.lua index 4501e35eb..aa253157e 100644 --- a/scripts/tests/e3/init.lua +++ b/scripts/tests/e3/init.lua @@ -1,3 +1,4 @@ +require 'tests.e3.production' require 'tests.e3.castles' require 'tests.e3.stealth' require 'tests.e3.spells' diff --git a/scripts/tests/e3/production.lua b/scripts/tests/e3/production.lua new file mode 100644 index 000000000..696035255 --- /dev/null +++ b/scripts/tests/e3/production.lua @@ -0,0 +1,179 @@ +require "lunit" + +module("tests.e3.production", package.seeall, lunit.testcase ) + +function setup() + eressea.game.reset() + eressea.settings.set("rules.food.flags", "4") -- food is free + eressea.settings.set("NewbieImmunity", "0") +end + +local function create_faction(race) + return faction.create(race .. '@eressea.de', race, "de") +end + +function test_laen_needs_mine() + -- some resources require a building + -- i.e. you cannot create laen without a mine + local r = region.create(0, 0, "mountain") + local f = create_faction('human') + local u = unit.create(f, r, 1) + + turn_begin() + r:set_resource('laen', 100) + u:add_order("MACHE Laen") + u:set_skill('mining', 7) + turn_process() + assert_equal(0, u:get_item('laen')) + assert_equal(100, r:get_resource('laen')) + assert_equal(1, f:count_msg_type("error104")) -- requires building + + u.building = building.create(u.region, "mine") + u.building.working = true + u.building.size = 10 + turn_process() + assert_equal(1, u:get_item('laen')) + assert_equal(99, r:get_resource('laen')) + + turn_end() +end + +function bad_test_mine_laen_bonus() + -- some buildings grant a bonus on the production skill + -- i.e. a mine adds +1 to mining + local r = region.create(0, 0, 'mountain') + local f = create_faction('human') + local u = unit.create(f, r, 1) + + turn_begin() + r:set_resource('laen', 100) + assert_equal(100, r:get_resource('laen')) + u:add_order("MACHE Laen") + u:set_skill('mining', 6) + u.building = building.create(u.region, "mine") + u.building.working = true + u.building.size = 10 + u.number = 2 + turn_process() -- T6 is not enough for laen + assert_equal(0, u:get_item('laen')) + assert_equal(100, r:get_resource('laen')) + assert_equal(1, f:count_msg_type("manufacture_skills")) + + u:set_skill('mining', 13) + turn_process() -- T13 is enough, the +1 produces one extra Laen + assert_equal(4, u:get_item('laen')) -- FAIL (3) + assert_equal(96, r:get_resource('laen')) + + turn_end() +end + +function test_mine_iron_bonus() + -- some buildings grant a bonus on the production skill + -- i.e. a mine adds +1 to mining iron + -- + local r = region.create(0, 0, 'mountain') + local f = create_faction('human') + local u = unit.create(f, r, 1) + + turn_begin() + r:set_resource('iron', 100) + assert_equal(100, r:get_resource('iron')) + u:add_order("MACHE Eisen") + u:set_skill('mining', 1) + u.building = building.create(u.region, "mine") + u.building.working = false + u.building.size = 10 + u.number = 2 + turn_process() -- iron can be made without a working mine + assert_equal(2, u:get_item('iron')) + assert_equal(98, r:get_resource('iron')) + + u.building.working = true + turn_process() + assert_equal(6, u:get_item('iron')) + assert_equal(96, r:get_resource('iron')) + + turn_end() +end + +function test_quarry_bonus() + -- a quarry grants +1 to quarrying, and saves 50% stone + -- + local r = region.create(0, 0, 'mountain') + local f = create_faction('human') + local u = unit.create(f, r, 1) + + turn_begin() + r:set_resource('stone', 100) + assert_equal(100, r:get_resource('stone')) + u:add_order("MACHE Stein") + u:set_skill('quarrying', 1) + u.number = 2 + u.building = building.create(u.region, 'quarry') + u.building.working = false + u.building.size = 10 + turn_process() + assert_equal(2, u:get_item('stone')) + assert_equal(98, r:get_resource('stone')) + + u.building.working = true + turn_process() + assert_equal(6, u:get_item('stone')) + assert_equal(96, r:get_resource('stone')) + + turn_end() +end + +function test_smithy_bonus_iron() +-- a smithy adds +1 to weaponsmithing, and saves 50% iron + local r = region.create(0, 0, 'mountain') + local f = create_faction('human') + local u = unit.create(f, r, 1) + + turn_begin() + u.building = building.create(u.region, 'smithy') + u.building.working = false + u.building.size = 10 + u:set_skill('weaponsmithing', 5) -- needs 3 + u:add_item('iron', 100) + u:add_order("MACHE Schwert") + turn_process() -- building disabled + assert_equal(1, u:get_item('sword')) + assert_equal(99, u:get_item('iron')) + + u.building.working = true + turn_process() -- building active + assert_equal(3, u:get_item('sword')) + assert_equal(98, u:get_item('iron')) + + turn_end() +end + +function test_smithy_bonus_mixed() +-- a smithy adds +1 to weaponsmithing, and saves 50% iron +-- it does not save any other resource, though. + local r = region.create(0, 0, 'mountain') + local f = create_faction('human') + local u = unit.create(f, r, 1) + + turn_begin() + u.building = building.create(u.region, 'smithy') + u.building.working = false + u.building.size = 10 + u:set_skill('weaponsmithing', 5) -- needs 3 + u:add_item('iron', 100) + u:add_item('log', 100) + u:add_order("MACHE Kriegsaxt") + turn_process() -- building disabled + assert_equal(1, u:get_item('axe')) + assert_equal(99, u:get_item('iron')) + assert_equal(99, u:get_item('log')) + + u.building.working = true + turn_process() -- building active + assert_equal(3, u:get_item('axe')) + assert_equal(98, u:get_item('iron')) + assert_equal(97, u:get_item('log')) + + turn_end() +end diff --git a/scripts/tests/items.lua b/scripts/tests/items.lua new file mode 100644 index 000000000..48f466409 --- /dev/null +++ b/scripts/tests/items.lua @@ -0,0 +1,140 @@ +require "lunit" + +module("tests.items", package.seeall, lunit.testcase ) + +function setup() + eressea.free_game() + eressea.settings.set("nmr.timeout", "0") + eressea.settings.set("rules.food.flags", "4") + eressea.settings.set("rules.ship.storms", "0") + eressea.settings.set("rules.encounters", "0") + eressea.settings.set("magic.regeneration.enable", "0") +end + +function test_mistletoe() + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:add_item('mistletoe', 2) + u:clear_orders() + u:add_order("BENUTZEN 1 Mistelzweig") + process_orders() + assert_equal(1, u:get_item('mistletoe')) + assert_equal(1, f:count_msg_type('use_item')) + u.number = 2 + process_orders() + assert_equal(1, u:get_item('mistletoe')) + assert_equal(1, f:count_msg_type('use_singleperson')) +end + +function test_dreameye() + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:add_item("dreameye", 2) + u:clear_orders() + u:add_order("BENUTZEN 1 Traumauge") + assert_false(u:is_cursed('skillmod')) + turn_begin() + turn_process() + assert_true(u:is_cursed('skillmod')) + assert_equal(1, u:get_item("dreameye")) + assert_equal(1, f:count_msg_type('use_tacticcrystal')) + turn_end() + assert_false(u:is_cursed('skillmod')) +end + +function test_manacrystal() + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:add_item("manacrystal", 2) + u:clear_orders() + u.magic = "gwyrrd" + u:set_skill('magic', 1) + u.aura = 0 + u:add_order("BENUTZEN 1 Astralkristall") + turn_begin() + turn_process() + assert_equal(1, u:get_item("manacrystal")) + assert_equal(25, u.aura) + assert_equal(1, f:count_msg_type('manacrystal_use')) + turn_end() +end + +function test_skillpotion() + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:add_item("skillpotion", 2) + u:clear_orders() + u:add_order("BENUTZEN 1 Talenttrunk") + process_orders() + assert_equal(1, u:get_item("skillpotion")) + assert_equal(1, f:count_msg_type('skillpotion_use')) +end + +function test_studypotion() + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:add_item("studypotion", 2) + u:clear_orders() + u:add_order("LERNE Unterhaltung") + u:add_order("BENUTZEN 1 Lerntrank") + process_orders() + assert_equal(1, u:get_item("studypotion")) +end + +function test_antimagic() + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:add_item("antimagic", 2) + u:clear_orders() + u:add_order("BENUTZEN 1 Antimagiekristall") + process_orders() + assert_equal(1, r:count_msg_type('use_antimagiccrystal')) + assert_equal(1, u:get_item("antimagic")) +end + +function test_ointment() + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + local hp = u.hp + u.hp = 1 + u:add_item("ointment", 1) + u:clear_orders() + u:add_order("BENUTZEN 1 Wundsalbe") + process_orders() + assert_equal(0, u:get_item("ointment")) + assert_equal(1, f:count_msg_type('usepotion')) + assert_equal(hp, u.hp) +end + +function test_bloodpotion_demon() + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "demon", "de") + local u = unit.create(f, r, 1) + u:add_item("peasantblood", 1) + u:clear_orders() + u:add_order("BENUTZEN 1 Bauernblut") + process_orders() + assert_equal(0, u:get_item("peasantblood")) + assert_equal(1, f:count_msg_type('usepotion')) + assert_equal("demon", u.race) +end + +function test_bloodpotion_other() + local r = region.create(0, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:add_item("peasantblood", 1) + u:clear_orders() + u:add_order("BENUTZEN 1 Bauernblut") + process_orders() + assert_equal(0, u:get_item("peasantblood")) + assert_equal(1, f:count_msg_type('usepotion')) + assert_equal("smurf", u.race) +end From 39a5b5575346981adcd509dfebc629ad6da9ffcb Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 26 Mar 2017 17:40:13 +0200 Subject: [PATCH 16/25] bugfix? mine grants +1 to laen production. not certain that this is actually a bug. --- res/core/resources/laen.xml | 1 + scripts/tests/e3/production.lua | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/res/core/resources/laen.xml b/res/core/resources/laen.xml index 30531c0fe..5fbe86549 100644 --- a/res/core/resources/laen.xml +++ b/res/core/resources/laen.xml @@ -4,6 +4,7 @@ + diff --git a/scripts/tests/e3/production.lua b/scripts/tests/e3/production.lua index 696035255..85fdeb638 100644 --- a/scripts/tests/e3/production.lua +++ b/scripts/tests/e3/production.lua @@ -38,7 +38,7 @@ function test_laen_needs_mine() turn_end() end -function bad_test_mine_laen_bonus() +function test_mine_laen_bonus() -- some buildings grant a bonus on the production skill -- i.e. a mine adds +1 to mining local r = region.create(0, 0, 'mountain') From 588914bc365e4aa45f82ddb49268448957349ecc Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 26 Mar 2017 17:41:53 +0200 Subject: [PATCH 17/25] fix duplicate _LP64 define --- src/platform.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/platform.h b/src/platform.h index a56328485..104ff28d7 100644 --- a/src/platform.h +++ b/src/platform.h @@ -1,6 +1,8 @@ #pragma once +#ifndef _LP64 #define _LP64 0 /* fix a warning in pdcurses 3.4 */ +#endif #ifndef UNILIB_H #define UNILIB_H From 89a20824e34d02c4a8c16078160ef4961bcaaf01 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 26 Mar 2017 17:46:55 +0200 Subject: [PATCH 18/25] backwards compat for old rm_iron etc. tokens in save --- src/kernel/save.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/kernel/save.c b/src/kernel/save.c index e1d6178fb..c9bdb2f2e 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -956,6 +956,9 @@ static region *readregion(struct gamedata *data, int x, int y) break; res = malloc(sizeof(rawmaterial)); res->rtype = rt_find(name); + if (!res->rtype && strncmp("rm_", name, 3) == 0) { + res->rtype = rt_find(name + 3); + } if (!res->rtype || !res->rtype->raw) { log_error("invalid resourcetype %s in data.", name); } From 406f8ca3e6c9f7a348222266c35476ac7ab14b23 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 26 Mar 2017 20:25:01 +0200 Subject: [PATCH 19/25] BUG 2315: always use plural for resources --- src/creport.c | 2 +- src/creport.test.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/creport.c b/src/creport.c index 21e3f6d0b..dc897e055 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1184,7 +1184,7 @@ void cr_output_resources(stream *out, const faction * f, const region *r, bool s } for (n = 0; n < size; ++n) { if (result[n].level >= 0 && result[n].number >= 0) { - const char * name = resourcename(result[n].rtype, result[n].number != 1); + const char * name = resourcename(result[n].rtype, 1); assert(name); stream_printf(out, "%d;%s\n", result[n].number, crtag(name)); } diff --git a/src/creport.test.c b/src/creport.test.c index 46e6e6967..e87de235e 100644 --- a/src/creport.test.c +++ b/src/creport.test.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -52,8 +53,15 @@ static void test_cr_unit(CuTest *tc) { static void setup_resources(void) { struct locale *lang; + item_type *itype; test_setup(); + itype = it_get_or_create(rt_get_or_create("stone")); + itype->rtype->flags = RTF_LIMITED | RTF_POOLED; + itype->construction = calloc(1, sizeof(construction)); + itype->construction->skill = SK_QUARRYING; + itype->construction->minskill = 1; + rmt_create(itype->rtype); init_resources(); lang = get_or_create_locale("de"); /* CR tags are translated from this */ locale_setstring(lang, "money", "Silber"); @@ -62,6 +70,8 @@ static void setup_resources(void) { locale_setstring(lang, "horse_p", "Pferde"); locale_setstring(lang, "peasant", "Bauer"); locale_setstring(lang, "peasant_p", "Bauern"); + locale_setstring(lang, "stone", "Stein"); + locale_setstring(lang, "stone_p", "Steine"); locale_setstring(lang, "tree", "Blume"); locale_setstring(lang, "tree_p", "Blumen"); locale_setstring(lang, "sapling", "Schoessling"); @@ -77,25 +87,31 @@ static void test_cr_resources(CuTest *tc) { char line[1024]; faction *f; region *r; - + unit *u; + setup_resources(); f = test_create_faction(0); r = test_create_region(0, 0, 0); + u = test_create_unit(f, r); + set_level(u, SK_QUARRYING, 1); r->land->horses = 1; r->land->peasants = 200; r->land->money = 300; rsettrees(r, 0, 1); rsettrees(r, 1, 2); rsettrees(r, 2, 3); + region_setresource(r, get_resourcetype(R_STONE), 1); mstream_init(&strm); - cr_output_resources(&strm, f, r, false); + cr_output_resources(&strm, f, r, true); strm.api->rewind(strm.handle); CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertStrEquals(tc, "3;Baeume", line); CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertStrEquals(tc, "2;Schoesslinge", line); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertStrEquals(tc, "1;Steine", line); CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9)); @@ -132,6 +148,15 @@ static void test_cr_resources(CuTest *tc) { CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertStrEquals(tc, "1;number", line); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9)); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertStrEquals(tc, "\"Steine\";type", line); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertStrEquals(tc, "1;skill", line); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertStrEquals(tc, "1;number", line); + mstream_done(&strm); test_cleanup(); } From 4b0b5e821597f54953cf9ab331597458d4fda337 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 26 Mar 2017 17:41:53 +0200 Subject: [PATCH 20/25] fix duplicate _LP64 define --- src/platform.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/platform.h b/src/platform.h index a56328485..104ff28d7 100644 --- a/src/platform.h +++ b/src/platform.h @@ -1,6 +1,8 @@ #pragma once +#ifndef _LP64 #define _LP64 0 /* fix a warning in pdcurses 3.4 */ +#endif #ifndef UNILIB_H #define UNILIB_H From e114aa2854ad353678d65c5d92bc02f6773f7068 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 26 Mar 2017 20:32:09 +0200 Subject: [PATCH 21/25] also add +1 when producing adamantium in mines --- res/adamantium.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/res/adamantium.xml b/res/adamantium.xml index bb94dfc12..13d08ca99 100644 --- a/res/adamantium.xml +++ b/res/adamantium.xml @@ -6,6 +6,7 @@ + From c835c119ca7bfcb00953c083547764e7cce3b3a6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 26 Mar 2017 20:25:01 +0200 Subject: [PATCH 22/25] BUG 2315: always use plural for resources --- src/creport.c | 2 +- src/creport.test.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/creport.c b/src/creport.c index 21e3f6d0b..dc897e055 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1184,7 +1184,7 @@ void cr_output_resources(stream *out, const faction * f, const region *r, bool s } for (n = 0; n < size; ++n) { if (result[n].level >= 0 && result[n].number >= 0) { - const char * name = resourcename(result[n].rtype, result[n].number != 1); + const char * name = resourcename(result[n].rtype, 1); assert(name); stream_printf(out, "%d;%s\n", result[n].number, crtag(name)); } diff --git a/src/creport.test.c b/src/creport.test.c index 46e6e6967..e87de235e 100644 --- a/src/creport.test.c +++ b/src/creport.test.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -52,8 +53,15 @@ static void test_cr_unit(CuTest *tc) { static void setup_resources(void) { struct locale *lang; + item_type *itype; test_setup(); + itype = it_get_or_create(rt_get_or_create("stone")); + itype->rtype->flags = RTF_LIMITED | RTF_POOLED; + itype->construction = calloc(1, sizeof(construction)); + itype->construction->skill = SK_QUARRYING; + itype->construction->minskill = 1; + rmt_create(itype->rtype); init_resources(); lang = get_or_create_locale("de"); /* CR tags are translated from this */ locale_setstring(lang, "money", "Silber"); @@ -62,6 +70,8 @@ static void setup_resources(void) { locale_setstring(lang, "horse_p", "Pferde"); locale_setstring(lang, "peasant", "Bauer"); locale_setstring(lang, "peasant_p", "Bauern"); + locale_setstring(lang, "stone", "Stein"); + locale_setstring(lang, "stone_p", "Steine"); locale_setstring(lang, "tree", "Blume"); locale_setstring(lang, "tree_p", "Blumen"); locale_setstring(lang, "sapling", "Schoessling"); @@ -77,25 +87,31 @@ static void test_cr_resources(CuTest *tc) { char line[1024]; faction *f; region *r; - + unit *u; + setup_resources(); f = test_create_faction(0); r = test_create_region(0, 0, 0); + u = test_create_unit(f, r); + set_level(u, SK_QUARRYING, 1); r->land->horses = 1; r->land->peasants = 200; r->land->money = 300; rsettrees(r, 0, 1); rsettrees(r, 1, 2); rsettrees(r, 2, 3); + region_setresource(r, get_resourcetype(R_STONE), 1); mstream_init(&strm); - cr_output_resources(&strm, f, r, false); + cr_output_resources(&strm, f, r, true); strm.api->rewind(strm.handle); CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertStrEquals(tc, "3;Baeume", line); CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertStrEquals(tc, "2;Schoesslinge", line); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertStrEquals(tc, "1;Steine", line); CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9)); @@ -132,6 +148,15 @@ static void test_cr_resources(CuTest *tc) { CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertStrEquals(tc, "1;number", line); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9)); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertStrEquals(tc, "\"Steine\";type", line); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertStrEquals(tc, "1;skill", line); + CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); + CuAssertStrEquals(tc, "1;number", line); + mstream_done(&strm); test_cleanup(); } From 7c19746d84277de74901e665b53f93a97f59e56d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 26 Mar 2017 20:33:48 +0200 Subject: [PATCH 24/25] adjust adamantium test to new rule. --- scripts/tests/e2/adamantium.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/tests/e2/adamantium.lua b/scripts/tests/e2/adamantium.lua index 2818db4e8..8bbccdd19 100644 --- a/scripts/tests/e2/adamantium.lua +++ b/scripts/tests/e2/adamantium.lua @@ -50,7 +50,7 @@ function test_adamantium2() local adamantium = r:get_resource("adamantium") process_orders() - assert_equal(1, u1:get_item("adamantium")) - assert_equal(adamantium - 1, r:get_resource("adamantium")) + assert_equal(2, u1:get_item("adamantium")) + assert_equal(adamantium - 2, r:get_resource("adamantium")) end From 7ee5a3624e4177b13ea63565cd63449fa4a3aa2f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 27 Mar 2017 08:57:35 +0200 Subject: [PATCH 25/25] allow game.start in ini file --- src/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.c b/src/main.c index 7b1c62c38..e67982108 100644 --- a/src/main.c +++ b/src/main.c @@ -75,6 +75,7 @@ static void load_inifile(void) static const char * valid_keys[] = { "game.id", "game.name", + "game.start", "game.locale", "game.verbose", "game.report",