From b68e2a983e70ba0a52f12bfe826bb44b92cfcbac Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Feb 2015 22:31:50 +0100 Subject: [PATCH 1/3] added tests to make sure volcanooutbreak and spyreport are no longer empty messages. --- scripts/tests/e3/rules.lua | 23 +++++++++++++++++++++++ src/bind_message.c | 18 ++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index 193551ea9..ca7eec88e 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -779,3 +779,26 @@ function test_weightless_silver() u1:add_item("money", 540) assert_equal(1000, u1.weight) end + +function test_spyreport_message() + local r1 = region.create(1, 2, "plain") + local f1 = faction.create("noreply@eressea.de", "human", "de") + local u1 = unit.create(f1, r1, 1) + local u2 = unit.create(f1, r1, 1) + msg = message.create("spyreport") + msg:set_unit("spy", u1) + msg:set_unit("target", u2) + msg:set_string("status", "hodor") + assert_not_equal("", msg:render("de")) + assert_not_equal("", msg:render("en")) +end + +function test_volcanooutbreak_message() + local r1 = region.create(1, 0, "plain") + local r2 = region.create(1, 1, "plain") + msg = message.create("volcanooutbreak") + msg:set_region("regionn", r1) + msg:set_region("regionv", r2) + assert_not_equal("", msg:render("de")) + assert_not_equal("", msg:render("en")) +end diff --git a/src/bind_message.c b/src/bind_message.c index 24439804d..75ff5821b 100644 --- a/src/bind_message.c +++ b/src/bind_message.c @@ -11,7 +11,9 @@ #include /* util includes */ +#include #include +#include /* lua includes */ #include @@ -307,6 +309,21 @@ static int tolua_msg_send_faction(lua_State * L) return 0; } +static int tolua_msg_render(lua_State * L) +{ + lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0); + const char * lname = tolua_tostring(L, 2, 0); + const struct locale * lang = lname ? get_locale(lname) : default_locale; + char name[64]; + + if (lmsg->msg == NULL) { + lmsg->msg = msg_create(lmsg->mtype, lmsg->args); + } + nr_render(lmsg->msg, lang, name, sizeof(name), NULL); + lua_pushstring(L, name); + return 1; +} + void tolua_message_open(lua_State * L) { /* register user types */ @@ -321,6 +338,7 @@ void tolua_message_open(lua_State * L) NULL); tolua_beginmodule(L, TOLUA_CAST "message"); { + tolua_function(L, TOLUA_CAST "render", tolua_msg_render); tolua_function(L, TOLUA_CAST "set", tolua_msg_set); tolua_function(L, TOLUA_CAST "set_unit", tolua_msg_set_unit); tolua_function(L, TOLUA_CAST "set_region", tolua_msg_set_region); From b9a41bc39fa4427bf51cbf73264822d7a0162dca Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 9 Apr 2015 15:59:00 +0200 Subject: [PATCH 2/3] fixing the trollbelt multiplier. it was multiplying the weight of the unit, too, leading to far too big bonuses. https://bugs.eressea.de/view.php?id=1510 --- src/move.c | 2 +- src/move.h | 8 -------- src/reports.c | 2 ++ 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/move.c b/src/move.c index 14c305c11..4468060ae 100644 --- a/src/move.c +++ b/src/move.c @@ -315,7 +315,7 @@ int walkingcapacity(const struct unit *u) } if (rbelt) { int tmp = i_get(u->items, rbelt->itype); - n += _min(people, tmp) * (STRENGTHMULTIPLIER - 1) * personcapacity(u); + n += _min(people, tmp) * (STRENGTHMULTIPLIER - 1) * u_race(u)->capacity; } return n; diff --git a/src/move.h b/src/move.h index e3caf1fa9..5a8b0e9f0 100644 --- a/src/move.h +++ b/src/move.h @@ -39,14 +39,6 @@ extern "C" { #define MV_SWIM (1<<8) /* kann schwimmen */ #define MV_WALK (1<<9) /* kann über Land gehen */ - /* Die tragekapaz. ist hardcodiert mit defines, da es bis jetzt sowieso nur 2 - ** objekte gibt, die etwas tragen. */ -#define SILVERWEIGHT 1 -#define SCALEWEIGHT 100 /* Faktor, um den die Anzeige von gewichten - * * skaliert wird */ -#define HORSECAPACITY 7000 -#define WAGONCAPACITY 14000 - #define HORSESNEEDED 2 /* ein mensch wiegt 10, traegt also 5, ein pferd wiegt 50, traegt also 20. ein diff --git a/src/reports.c b/src/reports.c index 3ad08371b..1dc779ff6 100644 --- a/src/reports.c +++ b/src/reports.c @@ -70,6 +70,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "move.h" +#define SCALEWEIGHT 100 /* Faktor, um den die Anzeige von Gewichten skaliert wird */ + bool nocr = false; bool nonr = false; bool noreports = false; From ae9fb399f30b0e71b01fd47de9b94cbe04f329ae Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 14 Apr 2015 02:32:01 +0200 Subject: [PATCH 3/3] unit tests walkingcapacity, configurable trollbelt effect --- src/kernel/config.h | 1 - src/move.c | 7 +++++-- src/move.h | 1 + src/move.test.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ src/tests.c | 5 +++++ 5 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/kernel/config.h b/src/kernel/config.h index caffedb9e..4ca76871c 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -85,7 +85,6 @@ extern "C" { * von struct unitname, etc. zurückgegeben werden. ohne die 0 */ #define BAGCAPACITY 20000 /* soviel paßt in einen Bag of Holding */ -#define STRENGTHMULTIPLIER 50 /* multiplier for trollbelt */ /* ----------------- Befehle ----------------------------------- */ diff --git a/src/move.c b/src/move.c index 4468060ae..27483d5d4 100644 --- a/src/move.c +++ b/src/move.c @@ -314,8 +314,11 @@ int walkingcapacity(const struct unit *u) } } if (rbelt) { - int tmp = i_get(u->items, rbelt->itype); - n += _min(people, tmp) * (STRENGTHMULTIPLIER - 1) * u_race(u)->capacity; + int belts = i_get(u->items, rbelt->itype); + if (belts) { + int multi = get_param_flt(global.parameters, "rules.trollbelt.multiplier", STRENGTHMULTIPLIER); + n += _min(people, belts) * (multi - 1) * u_race(u)->capacity; + } } return n; diff --git a/src/move.h b/src/move.h index 5a8b0e9f0..11e6b3954 100644 --- a/src/move.h +++ b/src/move.h @@ -40,6 +40,7 @@ extern "C" { #define MV_WALK (1<<9) /* kann über Land gehen */ #define HORSESNEEDED 2 +#define STRENGTHMULTIPLIER 50 /* multiplier for trollbelt */ /* ein mensch wiegt 10, traegt also 5, ein pferd wiegt 50, traegt also 20. ein ** wagen wird von zwei pferden gezogen und traegt total 140, davon 40 die diff --git a/src/move.test.c b/src/move.test.c index dbb82e571..4e2b5f41e 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -2,18 +2,22 @@ #include #include "move.h" +#include #include #include #include #include #include #include +#include #include +#include #include #include #include +#include static void test_ship_not_allowed_in_coast(CuTest * tc) { @@ -167,9 +171,54 @@ static void test_building_type_exists(CuTest * tc) CuAssertTrue(tc, !buildingtype_exists(r, btype2, false)); } +static void test_walkingcapacity(CuTest *tc) { + region *r; + unit *u; + int cap; + const struct item_type *itype; + + test_cleanup(); + test_create_world(); + + r = findregion(0, 0); + u = test_create_unit(test_create_faction(0), r); + cap = u->number * (u->_race->capacity + u->_race->weight); + CuAssertIntEquals(tc, cap, walkingcapacity(u)); + scale_number(u, 2); + cap = u->number * (u->_race->capacity + u->_race->weight); + CuAssertIntEquals(tc, cap, walkingcapacity(u)); + + itype = it_find("horse"); + assert(itype); + i_change(&u->items, itype, 1); + cap += itype->capacity; + CuAssertIntEquals(tc, cap, walkingcapacity(u)); + i_change(&u->items, itype, 1); + cap += itype->capacity; + CuAssertIntEquals(tc, cap, walkingcapacity(u)); + + itype = it_find("cart"); + assert(itype); + i_change(&u->items, itype, 1); + CuAssertIntEquals(tc, cap, walkingcapacity(u)); + set_level(u, SK_RIDING, 1); + cap += itype->capacity; + CuAssertIntEquals(tc, cap, walkingcapacity(u)); + + itype = test_create_itemtype("trollbelt"); + assert(itype); + i_change(&u->items, itype, 1); + CuAssertIntEquals(tc, cap + (STRENGTHMULTIPLIER-1) * u->_race->capacity, walkingcapacity(u)); + set_param(&global.parameters, "rules.trollbelt.multiplier", "5"); + CuAssertIntEquals(tc, cap + 4 * u->_race->capacity, walkingcapacity(u)); + + test_cleanup(); +} + CuSuite *get_move_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_walkingcapacity); SUITE_ADD_TEST(suite, test_building_type_exists); SUITE_ADD_TEST(suite, test_ship_not_allowed_in_coast); SUITE_ADD_TEST(suite, test_ship_allowed_without_harbormaster); diff --git a/src/tests.c b/src/tests.c index 07dcef979..ed554915b 100644 --- a/src/tests.c +++ b/src/tests.c @@ -175,6 +175,11 @@ void test_create_world(void) itype->weight = 5000; itype->capacity = 7000; + itype = test_create_itemtype("cart"); + itype->flags |= ITF_BIG | ITF_VEHICLE; + itype->weight = 4000; + itype->capacity = 14000; + test_create_itemtype("iron"); test_create_itemtype("stone");