forked from github/server
seed normalization (broken)
This commit is contained in:
parent
5e2903258c
commit
f06d86007c
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
<?xml version="1.0"?>
|
||||
<resource name="seed" limited="yes">
|
||||
<item weight="10" score="50"/>
|
||||
<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>
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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,63 @@ 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)
|
||||
assert_equal(get_ship(fortytwo), s)
|
||||
assert_equal(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()
|
||||
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_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")
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
|
||||
#include <attributes/attributes.h>
|
||||
#include <triggers/triggers.h>
|
||||
#include <items/itemtypes.h>
|
||||
|
||||
#include <util/log.h>
|
||||
#include <util/unicode.h>
|
||||
|
|
|
@ -7,8 +7,6 @@ xerewards.test.c
|
|||
SET(_FILES
|
||||
artrewards.c
|
||||
demonseye.c
|
||||
itemtypes.c
|
||||
seed.c
|
||||
speedsail.c
|
||||
weapons.c
|
||||
xerewards.c
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue