Samen-Definition normalisiert (mit XML/Lua).

Tests repariert.
MACHE Samen gibt es in E3 nicht.
This commit is contained in:
Enno Rehling 2017-02-23 22:30:19 +01:00
commit bd59271b71
13 changed files with 106 additions and 229 deletions

View File

@ -3,4 +3,8 @@
<item weight="10" score="100">
<construction skill="herbalism" minskill="4"/>
</item>
<resourcelimit>
<function name="produce" value="lua_produceresource"/>
<function name="limit" value="lua_limitresource"/>
</resourcelimit>
</resource>

View File

@ -3,4 +3,8 @@
<item weight="10" score="50">
<construction skill="herbalism" minskill="3"/>
</item>
<resourcelimit>
<function name="produce" value="lua_produceresource"/>
<function name="limit" value="lua_limitresource"/>
</resourcelimit>
</resource>

View File

@ -38,6 +38,45 @@ function hp_changeresource(u, delta)
return hp
end
local function mallorn_region(r)
return r:get_flag(1) -- RF_MALLORN
end
function seed_limit(r)
if mallorn_region(r) then
return 0
end
return r:get_resource("seed")
end
function seed_produce(r, n)
if not mallorn_region(r) then
local seeds = r:get_resource("seed")
if seeds>=n then
r:set_resource("seed", seeds-n)
else
r:set_resource("seed", 0)
end
end
end
function mallornseed_limit(r)
if mallorn_region(r) then
return r:get_resource("seed")
end
return 0
end
function mallornseed_produce(r, n)
if mallorn_region(r) then
local seeds = r:get_resource("seed")
if seeds>=n then
r:set_resource("seed", seeds-n)
else
r:set_resource("seed", 0)
end
end
end
function horse_limit(r)
return r:get_resource("horse")
end
@ -52,9 +91,6 @@ function horse_produce(r, n)
end
function log_limit(r)
-- if r:get_flag(1) then -- RF_MALLORN
-- return 0
-- end
return r:get_resource("tree") + r:get_resource("sapling")
end
@ -75,7 +111,7 @@ function log_produce(r, n)
end
function mallorn_limit(r)
if not r:get_flag(1) then -- RF_MALLORN
if not mallorn_region(r) then
return 0
end
return r:get_resource("tree") + r:get_resource("sapling")

View File

@ -438,10 +438,9 @@ function test_recruit()
u:add_item("money", 110*n+20)
u:add_order("REKRUTIERE " .. n)
process_orders()
assert(u.number == n+1)
assert_equal(n+1, u.number)
local p = r:get_resource("peasant")
assert(p<200 and p>=200-n)
-- assert(u:get_item("money")==10)
assert_true(p<200 and p>=200-n)
end
function test_produce()
@ -468,7 +467,7 @@ function test_work()
u:clear_orders()
u:add_order("ARBEITEN")
process_orders()
assert(u:get_item("money")>=10)
assert_equal(20, u:get_item("money"))
end
function test_upkeep()
@ -480,7 +479,7 @@ function test_upkeep()
u:clear_orders()
u:add_order("LERNE Waffenbau")
process_orders()
assert(u:get_item("money")==u.number)
assert_equal(u:get_item("money"), u.number)
end
function test_id()
@ -488,50 +487,39 @@ function test_id()
local f = faction.create("noreply11@eressea.de", "human", "de")
f.id = atoi36("42")
assert(get_faction(42)~=f)
assert(get_faction("42")==f)
assert(get_faction(atoi36("42"))==f)
assert_not_equal(f, get_faction(42))
assert_equal(f, get_faction("42"))
assert_equal(f, get_faction(atoi36("42")))
local u = unit.create(f, r, 1)
u.id = atoi36("42")
assert(get_unit(42)~=u)
assert(get_unit("42")==u)
assert(get_unit(atoi36("42"))==u)
assert_not_equal(get_unit(42), u)
assert_equal(get_unit("42"), u)
assert_equal(get_unit(atoi36("42")), u)
local b = building.create(r, "castle")
-- <not working> b.id = atoi36("42")
local fortytwo = itoa36(b.id)
assert(get_building(fortytwo)==b)
assert(get_building(atoi36(fortytwo))==b)
assert_equal(get_building(fortytwo), b)
assert_equal(get_building(atoi36(fortytwo)), b)
local s = _test_create_ship(r)
assert_not_nil(s)
-- <not working> s.id = atoi36("42")
local fortytwo = itoa36(s.id)
assert(get_ship(fortytwo)==s)
assert(get_ship(atoi36(fortytwo))==s)
end
function test_herbalism()
local r = region.create(0, 0, "plain")
local f = faction.create("noreply12@eressea.de", "human", "de")
local u = unit.create(f, r, 1)
u:add_item("money", u.number * 100)
u:set_skill("herbalism", 5)
u:clear_orders()
u:add_order("MACHE Samen")
process_orders()
assert_equal(get_ship(fortytwo), s)
assert_equal(get_ship(atoi36(fortytwo)), s)
end
function test_mallorn()
local r = region.create(0, 0, "plain")
r:set_flag(1, false) -- not mallorn
r:set_resource("tree", 100)
assert(r:get_resource("tree")==100)
assert_equal(100, r:get_resource("tree"))
local m = region.create(0, 0, "plain")
m:set_flag(1, true) -- mallorn
m:set_resource("tree", 100)
assert(m:get_resource("tree")==100)
assert_equal(100, m:get_resource("tree"))
local f = faction.create("noreply13@eressea.de", "human", "de")

View File

@ -2,6 +2,38 @@ require "lunit"
module("tests.e2.e2features", 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
function test_herbalism()
-- OBS: herbalism is currently an E2-only skill
local r = region.create(0, 0, "plain")
local f = faction.create("herbalism@eressea.de", "human", "de")
local u = unit.create(f, r, 1)
eressea.settings.set("rules.grow.formula", 0) -- plants do not grow
u:add_item("money", u.number * 100)
u:set_skill("herbalism", 5)
r:set_resource("seed", 100)
r:set_flag(1, false) -- regular trees
u:clear_orders()
u:add_order("MACHE Samen")
process_orders()
assert_equal(1, u:get_item("seed"))
assert_equal(99, r:get_resource("seed"))
r:set_flag(1, true) -- mallorn
u:clear_orders()
u:add_order("MACHE Mallornsamen")
process_orders()
assert_equal(1, u:get_item("mallornseed"))
assert_equal(98, r:get_resource("seed"))
end
function test_build_harbour()
-- try to reproduce mantis bug 2221
local r = region.create(0, 0, "plain")
@ -42,13 +74,6 @@ local function two_units(r, f1, f2)
return one_unit(r, f1), one_unit(r, f2)
end
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")
end
function test_learn()
eressea.settings.set("study.random_progress", "0")
local r = region.create(0, 0, "plain")

View File

@ -21,7 +21,10 @@
#include <kernel/xmlreader.h>
#include <modules/gmcmd.h>
#include <modules/xmas.h>
#include <items/itemtypes.h>
#include <items/xerewards.h>
#include <items/artrewards.h>
#include <items/weapons.h>
#include <attributes/attributes.h>
#include <util/message.h>
#include <races/races.h>
@ -81,7 +84,9 @@ void game_init(void)
#endif
wormholes_register();
register_itemtypes();
register_weapons();
register_xerewards();
register_artrewards();
#ifdef USE_LIBXML2
register_xmlreader();
#endif

View File

@ -47,7 +47,6 @@
#include <attributes/attributes.h>
#include <triggers/triggers.h>
#include <items/itemtypes.h>
#include <util/log.h>
#include <util/unicode.h>

View File

@ -7,8 +7,6 @@ xerewards.test.c
SET(_FILES
artrewards.c
demonseye.c
itemtypes.c
seed.c
speedsail.c
weapons.c
xerewards.c

View File

@ -1,33 +0,0 @@
/*
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed
without prior permission by the authors of Eressea.
*/
#include <platform.h>
#include "itemtypes.h"
#include "xerewards.h"
#include "artrewards.h"
#include "weapons.h"
#include "seed.h"
void register_itemtypes(void)
{
/* registering misc. functions */
register_weapons();
register_xerewards();
register_artrewards();
}
void init_itemtypes(void)
{
init_seed();
init_mallornseed();
}

View File

@ -1,25 +0,0 @@
/*
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed
without prior permission by the authors of Eressea.
*/
#ifndef H_ITM_ITEMS
#define H_ITM_ITEMS
#ifdef __cplusplus
extern "C" {
#endif
extern void init_itemtypes(void);
extern void register_itemtypes(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,93 +0,0 @@
/*
Copyright (c) 1998-2015, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/
#include <platform.h>
#include "seed.h"
/* kernel includes */
#include <kernel/build.h>
#include <kernel/item.h>
#include <kernel/region.h>
#include <kernel/resources.h>
/* util includes */
#include <util/attrib.h>
#include <util/functions.h>
/* libc includes */
#include <assert.h>
#include <stdlib.h>
static void produce_seeds(region * r, const resource_type * rtype, int norders)
{
assert(r->land && r->land->trees[0] >= norders);
r->land->trees[0] -= norders;
}
static int limit_seeds(const region * r, const resource_type * rtype)
{
if ((r->flags & RF_MALLORN)) {
return 0;
}
return r->land ? r->land->trees[0] : 0;
}
void init_seed(void)
{
resource_type *rtype;
rtype = rt_find("seed");
if (rtype != NULL) {
resource_limit *rdata = rtype->limit = calloc(1, sizeof(resource_limit));
rdata->limit = limit_seeds;
rdata->produce = produce_seeds;
}
}
/* mallorn */
static void
produce_mallornseeds(region * r, const resource_type * rtype, int norders)
{
assert(r->flags & RF_MALLORN);
r->land->trees[0] -= norders;
}
static int limit_mallornseeds(const region * r, const resource_type * rtype)
{
if (!(r->flags & RF_MALLORN)) {
return 0;
}
return r->land ? r->land->trees[0] : 0;
}
void init_mallornseed(void)
{
resource_type *rtype;
rtype = rt_find("mallornseed");
if (rtype != NULL) {
resource_limit *rdata = rtype->limit = calloc(1, sizeof(resource_limit));
rtype->flags |= RTF_LIMITED;
rtype->flags |= RTF_POOLED;
rdata->limit = limit_mallornseeds;
rdata->produce = produce_mallornseeds;
}
}

View File

@ -1,31 +0,0 @@
/*
Copyright (c) 1998-2015, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/
#ifndef H_ITM_SEED
#define H_ITM_SEED
#ifdef __cplusplus
extern "C" {
#endif
extern void init_seed(void);
extern void init_mallornseed(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1061,7 +1061,7 @@ static int parse_resources(xmlDocPtr doc)
/* reading eressea/resources/resource/resourcelimit/function */
result = xmlXPathEvalExpression(BAD_CAST "function", xpath);
if (result->nodesetval != NULL)
if (result->nodesetval != NULL) {
for (k = 0; k != result->nodesetval->nodeNr; ++k) {
xmlNodePtr node = result->nodesetval->nodeTab[k];
pf_generic fun;
@ -1090,6 +1090,7 @@ static int parse_resources(xmlDocPtr doc)
xmlFree(propValue);
}
}
}
xmlXPathFreeObject(result);
/* reading eressea/resources/resource/resourcelimit/function */
xpath->node = node;
@ -1118,7 +1119,6 @@ static int parse_resources(xmlDocPtr doc)
/* make sure old items (used in requirements) are available */
init_resources();
init_itemtypes();
return 0;
}