forked from github/server
parent
2b15c42eca
commit
2a098dcd30
|
@ -141,7 +141,7 @@ void do_markets(void)
|
|||
items = (item *)a->data.v;
|
||||
i_change(&items, herb, 1);
|
||||
a->data.v = items;
|
||||
/* give 1 luxury */
|
||||
/* give 1 herb */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -891,12 +891,14 @@ const item_type *
|
|||
r_luxury(region * r)
|
||||
{
|
||||
struct demand * dmd;
|
||||
if (!r->land->demands) {
|
||||
fix_demand(r);
|
||||
assert(r->land->demands);
|
||||
}
|
||||
for (dmd=r->land->demands;dmd;dmd=dmd->next) {
|
||||
if (dmd->value==0) return dmd->type->itype;
|
||||
if (r->land) {
|
||||
if (!r->land->demands) {
|
||||
fix_demand(r);
|
||||
assert(r->land->demands);
|
||||
}
|
||||
for (dmd=r->land->demands;dmd;dmd=dmd->next) {
|
||||
if (dmd->value==0) return dmd->type->itype;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -225,6 +225,44 @@ static int tolua_region_get_adj(lua_State* L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_get_luxury(lua_State* L)
|
||||
{
|
||||
region* r = (region*)tolua_tousertype(L, 1, 0);
|
||||
if (r->land) {
|
||||
const item_type * lux = r_luxury(r);
|
||||
if (lux) {
|
||||
const char * name = lux->rtype->_name[0];
|
||||
tolua_pushstring(L, name);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_region_set_herb(lua_State* L)
|
||||
{
|
||||
region* r = (region*)tolua_tousertype(L, 1, 0);
|
||||
if (r->land) {
|
||||
const char * name = tolua_tostring(L, 2, 0);
|
||||
const item_type * itype = it_find(name);
|
||||
if (itype && (itype->flags&ITF_HERB)) {
|
||||
r->land->herbtype = itype;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_region_get_herb(lua_State* L)
|
||||
{
|
||||
region* r = (region*)tolua_tousertype(L, 1, 0);
|
||||
if (r->land && r->land->herbtype) {
|
||||
const char * name = r->land->herbtype->rtype->_name[0];
|
||||
tolua_pushstring(L, name);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_region_get_next(lua_State* L)
|
||||
{
|
||||
region* self = (region*)tolua_tousertype(L, 1, 0);
|
||||
|
@ -596,13 +634,15 @@ tolua_region_open(lua_State* L)
|
|||
tolua_function(L, TOLUA_CAST "next", tolua_region_get_next);
|
||||
tolua_variable(L, TOLUA_CAST "adj", tolua_region_get_adj, NULL);
|
||||
|
||||
tolua_variable(L, TOLUA_CAST "luxury", &tolua_region_get_luxury, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "herb", &tolua_region_get_herb, &tolua_region_set_herb);
|
||||
|
||||
tolua_variable(L, TOLUA_CAST "terrain_name", &tolua_region_get_terrainname, &tolua_region_set_terrainname);
|
||||
tolua_variable(L, TOLUA_CAST "owner", &tolua_region_get_owner, &tolua_region_set_owner);
|
||||
|
||||
tolua_function(L, TOLUA_CAST "get_key", tolua_region_getkey);
|
||||
tolua_function(L, TOLUA_CAST "set_key", tolua_region_setkey);
|
||||
#if 0
|
||||
.property("herbtype", ®ion_getherbtype, ®ion_setherbtype)
|
||||
.def("add_notice", ®ion_addnotice)
|
||||
.def("add_direction", ®ion_adddirection)
|
||||
.def("move", ®ion_move)
|
||||
|
|
|
@ -39,9 +39,11 @@ without prior permission by the authors of Eressea.
|
|||
#include <kernel/save.h>
|
||||
|
||||
#include <gamecode/creport.h>
|
||||
#include <gamecode/economy.h>
|
||||
#include <gamecode/summary.h>
|
||||
#include <gamecode/laws.h>
|
||||
#include <gamecode/monster.h>
|
||||
#include <gamecode/market.h>
|
||||
|
||||
#include <spells/spells.h>
|
||||
#include <modules/autoseed.h>
|
||||
|
@ -953,6 +955,19 @@ tolua_read_xml(lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int tolua_process_markets(lua_State* L) {
|
||||
do_markets();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tolua_process_produce(lua_State* L) {
|
||||
region * r;
|
||||
for (r=regions;r;r=r->next) {
|
||||
produce(r);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
tolua_eressea_open(lua_State* L)
|
||||
{
|
||||
|
@ -969,6 +984,14 @@ tolua_eressea_open(lua_State* L)
|
|||
tolua_module(L, NULL, 0);
|
||||
tolua_beginmodule(L, NULL);
|
||||
{
|
||||
tolua_module(L, "process", 0);
|
||||
tolua_beginmodule(L, "process");
|
||||
{
|
||||
tolua_function(L, "markets", &tolua_process_markets);
|
||||
tolua_function(L, "produce", &tolua_process_produce);
|
||||
}
|
||||
tolua_endmodule(L);
|
||||
|
||||
tolua_cclass(L, TOLUA_CAST "alliance", TOLUA_CAST "alliance", TOLUA_CAST "", NULL);
|
||||
tolua_beginmodule(L, TOLUA_CAST "alliance");
|
||||
{
|
||||
|
|
|
@ -71,7 +71,7 @@ function test_rename()
|
|||
assert_equal(u:get_item("ao_healing"), 1)
|
||||
end
|
||||
|
||||
function test_blessed()
|
||||
function test_blessedharvest_lasts_n_turn()
|
||||
free_game()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
|
@ -86,15 +86,28 @@ function test_blessed()
|
|||
u:add_spell("raindance")
|
||||
u:add_spell("blessedharvest")
|
||||
u:clear_orders()
|
||||
u:add_order("ZAUBERE STUFE 3 Regentanz")
|
||||
local level = 5
|
||||
u:add_order("ZAUBERE STUFE " .. level .. " Regentanz")
|
||||
assert_equal(0, r:get_resource("money"), 0)
|
||||
|
||||
process_orders()
|
||||
assert_equal(200, r:get_resource("money"))
|
||||
u:clear_orders()
|
||||
u:add_order("ARBEITEN")
|
||||
process_orders()
|
||||
assert_equal(400, r:get_resource("money"))
|
||||
local m = 0
|
||||
local p = 100
|
||||
for i=1,level+1 do
|
||||
process_orders()
|
||||
local income = p * 12
|
||||
p = r:get_resource("peasant")
|
||||
income = income - p * 10
|
||||
m = m + income
|
||||
-- print(i, m, p, r:get_resource("money"))
|
||||
if (i>level) then
|
||||
assert_not_equal(m, r:get_resource("money"))
|
||||
else
|
||||
assert_equal(m, r:get_resource("money"))
|
||||
end
|
||||
u:clear_orders()
|
||||
u:add_order("ARBEITEN")
|
||||
-- u:add_spell("raindance")
|
||||
end
|
||||
end
|
||||
|
||||
function test_pure()
|
||||
|
|
|
@ -35,7 +35,7 @@ end
|
|||
function test_taxes()
|
||||
free_game()
|
||||
local r = region.create(0, 0, "plain")
|
||||
r.peasants = 1000
|
||||
r:set_resource("peasant", 1000)
|
||||
r:set_resource("money", 5000)
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r, 1)
|
||||
|
@ -72,11 +72,50 @@ function test_leave()
|
|||
end
|
||||
|
||||
function test_market()
|
||||
-- if i am the only trader around, i should be getting all the herbs from all 7 regions
|
||||
local herb_multi = 500 -- from rc_herb_trade()
|
||||
free_game()
|
||||
local r, idx
|
||||
local herbnames = { 'h0', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7', 'h8' }
|
||||
idx = 1
|
||||
for x = -1, 1 do for y = -1, 1 do
|
||||
r = region.create(x, y, "plain")
|
||||
r:set_resource("peasant", herb_multi * 10) -- 10 herbs per region
|
||||
r.herb = herbnames[idx]
|
||||
idx = idx+1
|
||||
end end
|
||||
r = get_region(0, 0)
|
||||
local b = building.create(r, "market")
|
||||
b.size = 10
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
f.id = 42
|
||||
local u = unit.create(f, r, 1)
|
||||
u.building = b
|
||||
u:add_item("money", u.number * 10000)
|
||||
for i = 0, 5 do
|
||||
local rn = r:next(i)
|
||||
end
|
||||
process.markets()
|
||||
u:add_item("money", -u:get_item("money")) -- now we only have herbs
|
||||
local len = 0
|
||||
for i in u.items do
|
||||
len = len + 1
|
||||
end
|
||||
assert_not_equal(0, len, "trader did not get any herbs")
|
||||
for idx, name in pairs(herbnames) do
|
||||
local n = u:get_item(name)
|
||||
if n>0 then
|
||||
assert_equal(10, n, 'trader did not get exaxtly 10 herbs')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function jest_market_gives_items()
|
||||
free_game()
|
||||
local r
|
||||
for x = -1, 1 do for y = -1, 1 do
|
||||
r = region.create(x, y, "plain")
|
||||
r.peasants = 5000
|
||||
r:set_resource("peasant", 5000)
|
||||
end end
|
||||
r = get_region(0, 0)
|
||||
local b = building.create(r, "market")
|
||||
|
|
Loading…
Reference in New Issue