From cc77ce6f20627a5c2e30965d081704d05c702e9a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 10 Sep 2019 06:39:04 +0200 Subject: [PATCH] =?UTF-8?q?Tests=20f=C3=BCr=20Einheiten=20mit=20Pferden.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tests/e2/horses.lua | 118 ++++++++++++++++++++++++++++++++++++ scripts/tests/e2/init.lua | 1 + src/bind_faction.c | 19 ++++++ 3 files changed, 138 insertions(+) create mode 100644 scripts/tests/e2/horses.lua diff --git a/scripts/tests/e2/horses.lua b/scripts/tests/e2/horses.lua new file mode 100644 index 000000000..7d7a67c66 --- /dev/null +++ b/scripts/tests/e2/horses.lua @@ -0,0 +1,118 @@ +require "lunit" + +module("tests.e2.capacity", package.seeall, lunit.testcase) + +function setup() + eressea.free_game() + eressea.settings.set("rules.food.flags", "4") + eressea.settings.set("nmr.timeout", "0") + eressea.settings.set("NewbieImmunity", "0") +end + +function test_walk() + local r1 = region.create(0, 0, "plain") + local r2 = region.create(1, 0, "plain") + local f = faction.create("human", "pirate@eressea.de", "de") + local u1 = unit.create(f, r1, 1) + local u2 = unit.create(f, r1, 2) + local u3 = unit.create(f, r1, 1) + u1:add_item("money", 540) + u1:add_order("NACH O") + u2:add_item("money", 1080) + u2:add_order("NACH O") + u3:add_item("money", 541) + u3:add_order("NACH O") + process_orders() + assert_equal(r2, u1.region) + assert_equal(r2, u2.region) + assert_equal(r1, u3.region) +end + +function test_lead_horses() + local r1 = region.create(0, 0, "plain") + local r2 = region.create(1, 0, "plain") + local r3 = region.create(2, 0, "plain") + local f = faction.create("human") + -- walk (don't ride) a horse to the next region: + local u1 = unit.create(f, r1, 1) + u1:add_item("horse", 1) + u1:add_item("money", 2540) + u1:add_order("NACH O O") + -- too heavy to move: + local u2 = unit.create(f, r1, 1) + u2:add_item("horse", 1) + u2:add_item("money", 2541) + u2:add_order("NACH O O") + -- too many horses: + local u3 = unit.create(f, r1, 1) + u3:add_item("horse", 2) + u3:add_item("money", 2540) + u3:add_order("NACH O O") + -- riders can lead 4 extra horses per level: + local u4 = unit.create(f, r1, 1) + u4:set_skill("riding", 1) + u4:add_item("horse", 5) + u4:add_item("money", 540+2000*5) + u4:add_order("NACH O O") + + process_orders() + assert_equal(r2, u1.region) + assert_equal(r1, u2.region) + assert_equal(r1, u3.region) + assert_equal(r2, u4.region) +end + +function test_ride_horses() + local r0 = region.create(0, 0, "plain") + local r1 = region.create(1, 0, "plain") + local r2 = region.create(2, 0, "plain") + local r3 = region.create(3, 0, "plain") + local f = faction.create("human") + -- ride a horse two regions: + local u1 = unit.create(f, r0, 1) + u1:set_skill("riding", 1) + u1:add_item("horse", 1) + u1:add_item("money", 1000) + u1:add_order("NACH O O O") + -- too heavy to ride, walk the horse: + local u2 = unit.create(f, r0, 1) + u2:set_skill("riding", 1) + u2:add_item("horse", 1) + u2:add_item("money", 2001) + u2:add_order("NACH O O O") + + process_orders() + -- mit 20 GE beladenes Pferd kommt 2 Regionen weit: + assert_equal(r2, u1.region) + -- überladenes Pferd kommt nur eine Region weit, zu Fuss: + assert_equal(r1, u2.region) +end + +function test_rider_leads_horses() + local r0 = region.create(0, 0, "plain") + local r1 = region.create(1, 0, "plain") + local r2 = region.create(2, 0, "plain") + local r3 = region.create(3, 0, "plain") + local f = faction.create("human") + -- lead 1 extra horse per level while riding: + local u1 = unit.create(f, r0, 1) + u1:set_skill("riding", 1) + u1:add_item("horse", 2) + u1:add_order("NACH O O O") + -- too heavy to ride, walk the horses: + local u2 = unit.create(f, r0, 1) + u2:set_skill("riding", 1) + u2:add_item("horse", 2) + u2:add_item("money", 2000 * 2) + u2:add_order("NACH O O") + -- too many horses, but can walk: + local u3 = unit.create(f, r0, 1) + u3:set_skill("riding", 1) + u3:add_item("horse", 5) + u3:add_order("NACH O O") + + process_orders() + assert_equal(r2, u1.region) + assert_equal(r1, u2.region) + assert_equal(r1, u3.region) +end diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 420ba3e06..d4fd0d4e8 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -1,3 +1,4 @@ +require 'tests.e2.horses' require 'tests.e2.quit' require 'tests.e2.movement' require 'tests.e2.astral' diff --git a/src/bind_faction.c b/src/bind_faction.c index 518dddc27..cfadbc6ab 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -34,6 +34,7 @@ without prior permission by the authors of Eressea. #include #include #include +#include #include #include "attributes/key.h" @@ -261,6 +262,23 @@ static int tolua_faction_setkey(lua_State * L) return 0; } +static int tolua_faction_debug_messages(lua_State * L) +{ + faction *self = (faction *)tolua_tousertype(L, 1, NULL); + int i = 1; + mlist *ml; + if (!self->msgs) { + return 0; + } + lua_newtable(L); + for (ml = self->msgs->begin; ml; ml = ml->next, ++i) { + char buf[80]; + nr_render(ml->msg, default_locale, buf, sizeof(buf), NULL); + puts(buf); + } + return 1; +} + static int tolua_faction_get_messages(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, NULL); @@ -592,6 +610,7 @@ void tolua_faction_open(lua_State * L) /* tech debt hack, siehe https://paper.dropbox.com/doc/Weihnachten-2015-5tOx5r1xsgGDBpb0gILrv#:h=Probleme-mit-Tests-(Nachtrag-0 */ tolua_function(L, TOLUA_CAST "count_msg_type", tolua_faction_count_msg_type); tolua_variable(L, TOLUA_CAST "messages", tolua_faction_get_messages, NULL); + tolua_function(L, TOLUA_CAST "debug_messages", tolua_faction_debug_messages); tolua_function(L, TOLUA_CAST "get_key", tolua_faction_getkey); tolua_function(L, TOLUA_CAST "set_key", tolua_faction_setkey);