Tests für Einheiten mit Pferden.

This commit is contained in:
Enno Rehling 2019-09-10 06:39:04 +02:00
parent 007721991d
commit cc77ce6f20
3 changed files with 138 additions and 0 deletions

118
scripts/tests/e2/horses.lua Normal file
View file

@ -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

View file

@ -1,3 +1,4 @@
require 'tests.e2.horses'
require 'tests.e2.quit'
require 'tests.e2.movement'
require 'tests.e2.astral'

View file

@ -34,6 +34,7 @@ without prior permission by the authors of Eressea.
#include <util/log.h>
#include <util/macros.h>
#include <util/message.h>
#include <util/nrmessage.h>
#include <util/password.h>
#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);