diff --git a/res/core/resources/mallornseed.xml b/res/core/resources/mallornseed.xml index 7a5a0310f..01b8a3416 100644 --- a/res/core/resources/mallornseed.xml +++ b/res/core/resources/mallornseed.xml @@ -3,4 +3,8 @@ + + + + diff --git a/res/core/resources/seed.xml b/res/core/resources/seed.xml index 99f5f5804..2bda26eeb 100644 --- a/res/core/resources/seed.xml +++ b/res/core/resources/seed.xml @@ -3,4 +3,8 @@ + + + + diff --git a/scripts/eressea/resources.lua b/scripts/eressea/resources.lua index 94908c1ab..2829d00c7 100644 --- a/scripts/eressea/resources.lua +++ b/scripts/eressea/resources.lua @@ -38,8 +38,47 @@ 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") + return r:get_resource("horse") end function horse_produce(r, n) @@ -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") diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 96673bfd3..03ae5db85 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -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") -- 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) -- 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") diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua index c4a53da76..de94ea34f 100644 --- a/scripts/tests/e2/e2features.lua +++ b/scripts/tests/e2/e2features.lua @@ -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") diff --git a/src/eressea.c b/src/eressea.c index dead153cb..07ea132a8 100755 --- a/src/eressea.c +++ b/src/eressea.c @@ -21,7 +21,10 @@ #include #include #include -#include +#include +#include +#include + #include #include #include @@ -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 diff --git a/src/gmtool.c b/src/gmtool.c index 5a0cd576c..3551c3436 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -47,7 +47,6 @@ #include #include -#include #include #include diff --git a/src/items/CMakeLists.txt b/src/items/CMakeLists.txt index 0a2c581b4..b2bf2dfe5 100644 --- a/src/items/CMakeLists.txt +++ b/src/items/CMakeLists.txt @@ -7,8 +7,6 @@ xerewards.test.c SET(_FILES artrewards.c demonseye.c -itemtypes.c -seed.c speedsail.c weapons.c xerewards.c diff --git a/src/items/itemtypes.c b/src/items/itemtypes.c deleted file mode 100644 index 930829668..000000000 --- a/src/items/itemtypes.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - +-------------------+ Christian Schlittchen - | | Enno Rehling - | Eressea PBEM host | Katja Zedel - | (c) 1998 - 2003 | Henning Peters - | | Ingo Wilken - +-------------------+ Stefan Reich - - This program may not be used, modified or distributed - without prior permission by the authors of Eressea. - */ - -#include -#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(); -} diff --git a/src/items/itemtypes.h b/src/items/itemtypes.h deleted file mode 100644 index ec705c55b..000000000 --- a/src/items/itemtypes.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - +-------------------+ Christian Schlittchen - | | Enno Rehling - | Eressea PBEM host | Katja Zedel - | (c) 1998 - 2003 | Henning Peters - | | Ingo Wilken - +-------------------+ Stefan Reich - - 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 diff --git a/src/items/seed.c b/src/items/seed.c deleted file mode 100644 index 334c6a05d..000000000 --- a/src/items/seed.c +++ /dev/null @@ -1,93 +0,0 @@ -/* -Copyright (c) 1998-2015, Enno Rehling -Katja Zedel - -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 - -#include "seed.h" - -/* kernel includes */ -#include -#include -#include -#include - -/* util includes */ -#include -#include - -/* libc includes */ -#include -#include - -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; - } -} diff --git a/src/items/seed.h b/src/items/seed.h deleted file mode 100644 index c853adfde..000000000 --- a/src/items/seed.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright (c) 1998-2015, Enno Rehling -Katja Zedel - -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 diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 9ba05e101..27adba598 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -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; @@ -1089,6 +1089,7 @@ static int parse_resources(xmlDocPtr doc) } xmlFree(propValue); } + } } xmlXPathFreeObject(result); /* reading eressea/resources/resource/resourcelimit/function */ @@ -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; }