Merge branch 'develop' of https://github.com/ennorehling/eressea into develop

This commit is contained in:
Enno Rehling 2015-11-26 21:13:24 +01:00
commit 097ff40823
18 changed files with 429 additions and 112 deletions

View File

@ -15,6 +15,7 @@
"modules.wormholes": true, "modules.wormholes": true,
"entertain.base": 0, "entertain.base": 0,
"entertain.perlevel": 20, "entertain.perlevel": 20,
"taxing.perlevel": 20,
"nmr.timeout": 5, "nmr.timeout": 5,
"nmr.removenewbie": 0, "nmr.removenewbie": 0,
"GiveRestriction": 3, "GiveRestriction": 3,

View File

@ -29,3 +29,6 @@ files="$files orders.$TURN"
fi fi
echo "backup turn $TURN, game $GAME, files: $files" echo "backup turn $TURN, game $GAME, files: $files"
tar cjf backup/$TURN.tar.bz2 $files tar cjf backup/$TURN.tar.bz2 $files
echo "uploading game-$GAME/$TURN.tar.bz2"
curl -n -T backup/$TURN.tar.bz2 https://dav.box.com/dav/Eressea/game-$GAME/$TURN.tar.bz2
curl -n -T eressea.db https://dav.box.com/dav/Eressea/eressea.db

View File

@ -6357,6 +6357,16 @@
<text locale="de">"$unit($unit) in $region($region): '$order($command)' - Die Einheit ist nicht der Eigentümer."</text> <text locale="de">"$unit($unit) in $region($region): '$order($command)' - Die Einheit ist nicht der Eigentümer."</text>
<text locale="en">"$unit($unit) in $region($region): '$order($command)' - The unit is not the owner."</text> <text locale="en">"$unit($unit) in $region($region): '$order($command)' - The unit is not the owner."</text>
</message> </message>
<message name="error_no_tax_skill" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
<text locale="de">"$unit($unit) in $region($region): '$order($command)' - Die Einheit ist nicht geschult im Eintreiben von Steuern."</text>
<text locale="en">"$unit($unit) in $region($region): '$order($command)' - The unit does not now how to tax."</text>
</message>
<message name="error48" section="errors"> <message name="error48" section="errors">
<type> <type>
<arg name="unit" type="unit"/> <arg name="unit" type="unit"/>

View File

@ -3,7 +3,7 @@ local function get_markets(r, result)
result = result or {} result = result or {}
for b in r.buildings do for b in r.buildings do
if b.type=="market" then if b.type == "market" and b.working and b.size == b.maxsize then
u = b.owner u = b.owner
if u~=nil then if u~=nil then
table.insert(result, u) table.insert(result, u)

View File

@ -59,28 +59,6 @@ function disable_test_bug_1738_build_castle_e3()
assert_equal(c.size, 250) assert_equal(c.size, 250)
end end
function disable_test_market_action()
local f = faction.create("noreply@eressea.de", "human", "de")
local x, y, r
for x=0,2 do
for y=0,2 do
r = region.create(x, y, "plain")
r.luxury = "balm"
r.herb = "h2"
r:set_resource("peasant", 5000)
end
end
r = get_region(1, 1)
local u = unit.create(f, r, 1)
b = building.create(r, "market")
b.size = 10
u.building = b
update_owners()
process.markets()
assert_equal(35, u:get_item("balm"))
assert_equal(70, u:get_item("h2"))
end
function disable_test_alliance() function disable_test_alliance()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f1 = faction.create("noreply@eressea.de", "human", "de") local f1 = faction.create("noreply@eressea.de", "human", "de")
@ -345,43 +323,204 @@ function test_region_owner_cannot_leave_castle()
assert_equal(b1, u.building, "region owner has left the building") -- region owners may not leave assert_equal(b1, u.building, "region owner has left the building") -- region owners may not leave
end end
function test_market() function reset_items(u)
-- if i am the only trader around, i should be getting all the herbs from all 7 regions for i in u.items do
u:add_item(i, u:get_item(i))
end
u:add_item("money", u.number * 10000)
end
function market_fixture()
local herb_multi = 500 -- from rc_herb_trade() local herb_multi = 500 -- from rc_herb_trade()
local r, idx local r
local herbnames = { 'h0', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7', 'h8' } local herbnames = { 'h0', 'h1', 'h2', 'h3', 'h4', 'h5' }
idx = 1 local herbtable = {}
for _, name in pairs(herbnames) do
herbtable[name] = name
end
local luxurynames = { 'balm', 'jewel', 'myrrh', 'oil', 'silk', 'incense' } -- no spice in E3
local luxurytable = {}
for _, name in pairs(luxurynames) do
luxurytable[name] = name
end
for x = -1, 1 do for y = -1, 1 do for x = -1, 1 do for y = -1, 1 do
r = region.create(x, y, "plain") r = region.create(x, y, "plain")
r:set_resource("peasant", herb_multi * 9 + 50) -- 10 herbs per region r:set_resource("peasant", 1)
r.herb = herbnames[idx]
idx = idx+1
end end end end
r = get_region(0, 0) r = get_region(0, 0)
local b = building.create(r, "market") local b = building.create(r, "market")
b.size = 10 b.size = 10
local f = faction.create("noreply@eressea.de", "human", "de") b.working = true
local f = faction.create("market1@eressea.de", "human", "de")
f.id = 42 f.id = 42
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
u.building = b u.building = b
u:add_item("money", u.number * 10000)
for i = 0, 5 do r.herb = herbnames[6]
r.luxury = luxurynames[6]
r:set_resource("peasant", herb_multi * 9 + 50) -- 10 herbs per region
for i = 0, 4 do
local rn = r:next(i) local rn = r:next(i)
rn.name = luxurynames[i+1]
rn.herb = herbnames[i+1]
rn.luxury = luxurynames[i+1]
rn:set_resource("peasant", herb_multi * 9 + 50) -- 10 herbs per region
unit.create(f, rn, 1)
end end
b.working = true
eressea.process.markets() reset_items(u)
u:add_item("money", -u:get_item("money")) -- now we only have herbs return r, u, b, herbnames, luxurynames, herbtable, luxurytable
local len = 0 end
for i in u.items do
local function test_items(u, names, amount)
local len = 0
for i in u.items do
if names[i] ~= nil then
len = len + 1 len = len + 1
end
end
if amount > 0 then
assert_not_equal(0, len, "trader did not get any items")
else
assert_equal(0, len, "trader should not have items")
end
for _, name in pairs(names) do
local n = u:get_item(name)
if n>0 then
if amount == 0 then
assert_equal(0, n, 'trader should have no ' .. name)
else
assert_equal(amount, n, 'trader has ' .. n .. ' instead of ' .. amount .. ' ' .. name)
end
end
end
end
function test_market_regions()
-- if i am the only trader around, i should be getting all the herbs from all 7 regions
local r, u, b, herbnames, luxurynames, herbtable, luxurytable = market_fixture()
eressea.process.markets()
test_items(u, herbtable, 10)
test_items(u, luxurytable, 5)
end
function test_multiple_markets()
local r, u1, b, herbnames, luxurynames, herbtable, luxurytable = market_fixture()
local r2 = get_region(1,0)
local f = faction.create("multim@eressea.de", "human", "de")
local u2 = unit.create(f, r2, 1)
local b2 = building.create(r2, "market")
b2.size = 10
b2.working = true
reset_items(u2)
u2.building = b2
eressea.process.markets()
for _, i in pairs(luxurytable) do
assert_equal(5, u1:get_item(i)+u2:get_item(i), "not enough " .. i )
end
for _, i in pairs(herbtable) do
assert_equal(10, u1:get_item(i)+u2:get_item(i), "not enough " .. i )
end
assert_equal(5, u1:get_item('silk')) -- uncontested
end
function test_market()
local r = region.create(0, 0, "plain")
local f1 = faction.create("market2@eressea.de", "human", "de")
local u1 = unit.create(f1, r, 1)
local b = building.create(r, "market")
eressea.settings.set("rules.peasants.growth", "0")
b.size = 10
u1.building = b
u1:add_item("money", 10000)
r.herb = "h0"
r.luxury = "balm"
r:set_resource("peasant", 1050)
process_orders()
assert_equal(3, u1:get_item("h0"))
assert_equal(2, u1:get_item("balm"))
local function reset_items()
for i in u1.items do
u1:add_item(i, -1 * u1:get_item(i))
end end
assert_not_equal(0, len, "trader did not get any herbs") u1:add_item("money", u1.number * 10000)
for idx, name in pairs(herbnames) do -- eressea.game.reset()
local n = u:get_item(name) f1.lastturn=get_turn()
if n>0 then assert_not_equal(nil, factions())
assert_equal(10, n, 'trader did not get exaxtly 10 herbs') local idx = 0
end for f in factions() do
assert_equal(1,1,"fac".. f.email)
idx = idx + 1
end end
assert_not_equal(0, idx)
end
reset_items()
b.size = 1
eressea.process.markets()
assert_equal(0, u1:get_item("h0"))
b.size = 10
reset_items()
r:set_resource("peasant", 2100)
eressea.process.markets()
assert_equal(5, u1:get_item("h0"))
assert_equal(3, u1:get_item("balm"))
reset_items()
r:set_resource("peasant", 1049)
eressea.process.markets()
assert_equal(2, u1:get_item("h0"))
assert_equal(1, u1:get_item("balm"))
reset_items()
r:set_resource("peasant", 550)
eressea.process.markets()
assert_equal(2, u1:get_item("h0"))
assert_equal(1, u1:get_item("balm"))
reset_items()
r:set_resource("peasant", 549)
eressea.process.markets()
assert_equal(1, u1:get_item("h0"))
assert_equal(1, u1:get_item("balm"))
reset_items()
r:set_resource("peasant", 50)
eressea.process.markets()
assert_equal(1, u1:get_item("h0"))
assert_equal(1, u1:get_item("balm"))
reset_items()
r:set_resource("peasant", 49)
eressea.process.markets()
assert_equal(0, u1:get_item("h0"))
r:set_resource("peasant", 1050)
reset_items()
u1:add_item("money", -1 * u1:get_item("money"))
assert_equal(0, u1:get_item("money"))
process_orders() -- process_orders to update maintenance
assert_equal(0, u1:get_item("h0"))
process_orders()
eressea.settings.set("rules.peasants.growth", "1")
end end
function test_market_gives_items() function test_market_gives_items()
@ -393,7 +532,7 @@ function test_market_gives_items()
r = get_region(0, 0) r = get_region(0, 0)
local b = building.create(r, "market") local b = building.create(r, "market")
b.size = 10 b.size = 10
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("market0@eressea.de", "human", "de")
f.id = 42 f.id = 42
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
u.building = b u.building = b
@ -789,3 +928,36 @@ function test_volcanooutbreak_message()
assert_not_equal("", msg:render("de")) assert_not_equal("", msg:render("de"))
assert_not_equal("", msg:render("en")) assert_not_equal("", msg:render("en"))
end end
function test_bug2083()
local herb_multi = 500 -- from rc_herb_trade()
local r = region.create(0,0,"plain")
r:set_resource("peasant", 2000)
r.luxury = "balm"
local f = faction.create("2083@eressea.de", "human", "de")
local u = unit.create(f, r, 1)
u:set_skill("building", 8)
u:add_item("stone", 100)
u:add_item("log", 100)
u:add_item("iron", 100)
u:add_item("money", 10000)
u:clear_orders()
u:add_order("MACHE Markt")
process_orders()
-- this is a bit weird, but the bug was caused by market code
-- being called in two places. We want to make sure this doesn't happen
for k, v in pairs(rules) do
set_key("xm09", true)
if 'table' == type(v) then
cb = v['update']
if 'function' == type(cb) then
cb()
end
end
end
assert_equal(0, u:get_item("balm"))
end

View File

@ -112,6 +112,13 @@ static int tolua_building_set_name(lua_State * L)
return 0; return 0;
} }
static int tolua_building_get_maxsize(lua_State * L)
{
building *self = (building *)tolua_tousertype(L, 1, 0);
lua_pushinteger(L, self->type->maxsize);
return 1;
}
static int tolua_building_get_size(lua_State * L) static int tolua_building_get_size(lua_State * L)
{ {
building *self = (building *)tolua_tousertype(L, 1, 0); building *self = (building *)tolua_tousertype(L, 1, 0);
@ -247,6 +254,7 @@ void tolua_building_open(lua_State * L)
tolua_variable(L, TOLUA_CAST "units", tolua_building_get_units, NULL); tolua_variable(L, TOLUA_CAST "units", tolua_building_get_units, NULL);
tolua_variable(L, TOLUA_CAST "region", tolua_building_get_region, tolua_variable(L, TOLUA_CAST "region", tolua_building_get_region,
tolua_building_set_region); tolua_building_set_region);
tolua_variable(L, TOLUA_CAST "maxsize", tolua_building_get_maxsize, NULL);
tolua_variable(L, TOLUA_CAST "size", tolua_building_get_size, tolua_variable(L, TOLUA_CAST "size", tolua_building_get_size,
tolua_building_set_size); tolua_building_set_size);
tolua_function(L, TOLUA_CAST "get_typename", tolua_building_get_typename); tolua_function(L, TOLUA_CAST "get_typename", tolua_building_get_typename);

View File

@ -2418,13 +2418,11 @@ static void breedtrees(unit * u, int raw)
static void breedhorses(unit * u) static void breedhorses(unit * u)
{ {
int n, c, breed = 0; int n, c, breed = 0;
struct building *b = inside_building(u);
const struct building_type *btype = building_is_active(b) ? b->type : NULL;
const struct resource_type *rhorse = get_resourcetype(R_HORSE); const struct resource_type *rhorse = get_resourcetype(R_HORSE);
int horses, effsk; int horses, effsk;
assert(rhorse && rhorse->itype); assert(rhorse && rhorse->itype);
if (btype != bt_find("stables")) { if (!active_building(u, bt_find("stables"))) {
cmistake(u, u->thisorder, 122, MSG_PRODUCE); cmistake(u, u->thisorder, 122, MSG_PRODUCE);
return; return;
} }
@ -2921,7 +2919,7 @@ static void expandloot(region * r, request * lootorders)
} }
} }
static void expandtax(region * r, request * taxorders) void expandtax(region * r, request * taxorders)
{ {
unit *u; unit *u;
unsigned int i; unsigned int i;
@ -2954,6 +2952,11 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders)
request *o; request *o;
int max; int max;
keyword_t kwd; keyword_t kwd;
static int taxperlevel = 0;
if (!taxperlevel) {
taxperlevel = config_get_int("taxing.perlevel", 0);
}
kwd = init_order(ord); kwd = init_order(ord);
assert(kwd == K_TAX); assert(kwd == K_TAX);
@ -2979,6 +2982,12 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders)
return; return;
} }
if (effskill(u, SK_TAXING, 0) <= 0) {
ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "error_no_tax_skill", ""));
return;
}
max = getint(); max = getint();
if (max <= 0) { if (max <= 0) {
@ -2988,7 +2997,7 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders)
u->wants = _min(income(u), max); u->wants = _min(income(u), max);
} }
else { else {
u->wants = _min(n * effskill(u, SK_TAXING, 0) * 20, max); u->wants = _min(n * effskill(u, SK_TAXING, 0) * taxperlevel, max);
} }
u2 = is_guarded(r, u, GUARD_TAX); u2 = is_guarded(r, u, GUARD_TAX);

View File

@ -45,6 +45,7 @@ extern "C" {
struct faction; struct faction;
struct order; struct order;
struct message; struct message;
struct request;
int income(const struct unit *u); int income(const struct unit *u);
@ -59,6 +60,8 @@ extern "C" {
int recruit_archetypes(void); int recruit_archetypes(void);
int give_control_cmd(struct unit *u, struct order *ord); int give_control_cmd(struct unit *u, struct order *ord);
void give_control(struct unit * u, struct unit * u2); void give_control(struct unit * u, struct unit * u2);
void tax_cmd(struct unit * u, struct order *ord, struct request ** taxorders);
void expandtax(struct region * r, struct request * taxorders);
struct message * check_steal(const struct unit * u, struct order *ord); struct message * check_steal(const struct unit * u, struct order *ord);

View File

@ -19,6 +19,7 @@
#include <CuTest.h> #include <CuTest.h>
#include <tests.h> #include <tests.h>
#include <assert.h>
static void test_give_control_building(CuTest * tc) static void test_give_control_building(CuTest * tc)
{ {
@ -169,6 +170,79 @@ static void test_normals_recruit(CuTest * tc) {
test_cleanup(); test_cleanup();
} }
typedef struct request {
struct request *next;
struct unit *unit;
struct order *ord;
int qty;
int no;
union {
bool goblin; /* stealing */
const struct luxury_type *ltype; /* trading */
} type;
} request;
static void test_tax_cmd(CuTest *tc) {
order *ord;
faction *f;
region *r;
unit *u;
item_type *sword, *silver;
request *taxorders = 0;
test_cleanup();
config_set("taxing.perlevel", "20");
test_create_world();
f = test_create_faction(NULL);
r = findregion(0, 0);
assert(r && f);
u = test_create_unit(f, r);
ord = create_order(K_TAX, f->locale, "");
assert(ord);
tax_cmd(u, ord, &taxorders);
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error48"));
test_clear_messages(u->faction);
silver = get_resourcetype(R_SILVER)->itype;
sword = it_get_or_create(rt_get_or_create("sword"));
new_weapontype(sword, 0, 0.0, NULL, 0, 0, 0, SK_MELEE, 1);
i_change(&u->items, sword, 1);
set_level(u, SK_MELEE, 1);
tax_cmd(u, ord, &taxorders);
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error_no_tax_skill"));
test_clear_messages(u->faction);
set_level(u, SK_TAXING, 1);
tax_cmd(u, ord, &taxorders);
CuAssertPtrEquals(tc, 0, test_find_messagetype(u->faction->msgs, "error_no_tax_skill"));
CuAssertPtrNotNull(tc, taxorders);
r->land->money = 11;
expandtax(r, taxorders);
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "income"));
/* taxing is in multiples of 10 */
CuAssertIntEquals(tc, 10, i_get(u->items, silver));
test_clear_messages(u->faction);
i_change(&u->items, silver, -i_get(u->items, silver));
r->land->money = 1000;
taxorders = 0;
tax_cmd(u, ord, &taxorders);
expandtax(r, taxorders);
CuAssertIntEquals(tc, 20, i_get(u->items, silver));
test_clear_messages(u->faction);
free_order(ord);
test_cleanup();
}
CuSuite *get_economy_suite(void) CuSuite *get_economy_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
@ -179,5 +253,6 @@ CuSuite *get_economy_suite(void)
SUITE_ADD_TEST(suite, test_steal_nosteal); SUITE_ADD_TEST(suite, test_steal_nosteal);
SUITE_ADD_TEST(suite, test_normals_recruit); SUITE_ADD_TEST(suite, test_normals_recruit);
SUITE_ADD_TEST(suite, test_heroes_dont_recruit); SUITE_ADD_TEST(suite, test_heroes_dont_recruit);
SUITE_ADD_TEST(suite, test_tax_cmd);
return suite; return suite;
} }

View File

@ -642,10 +642,31 @@ region *building_getregion(const building * b)
return b->region; return b->region;
} }
bool building_is_active(const struct building *b) { bool
return b && fval(b, BLD_WORKING); buildingtype_exists(const region * r, const building_type * bt, bool working)
{
building *b;
for (b = rbuildings(r); b; b = b->next) {
if (b->type == bt && b->size >= bt->maxsize && (!working || fval(b, BLD_WORKING)))
return true;
}
return false;
} }
bool building_is_active(const struct building *b) {
return b && fval(b, BLD_WORKING) && b->size >= b->type->maxsize;
}
building *active_building(const unit *u, const struct building_type *btype) {
if (u->building && u->building->type == btype && building_is_active(u->building)) {
return inside_building(u);
}
return 0;
}
void building_setregion(building * b, region * r) void building_setregion(building * b, region * r)
{ {
building **blist = &b->region->buildings; building **blist = &b->region->buildings;

View File

@ -166,7 +166,10 @@ extern "C" {
extern void building_set_owner(struct unit * u); extern void building_set_owner(struct unit * u);
extern void building_update_owner(struct building * bld); extern void building_update_owner(struct building * bld);
bool buildingtype_exists(const struct region *r,
const struct building_type *bt, bool working);
bool building_is_active(const struct building *b); bool building_is_active(const struct building *b);
struct building *active_building(const struct unit *u, const struct building_type *btype);
#ifdef WDW_PYRAMID #ifdef WDW_PYRAMID
extern int wdw_pyramid_level(const struct building *b); extern int wdw_pyramid_level(const struct building *b);

View File

@ -6,10 +6,13 @@
#include <kernel/building.h> #include <kernel/building.h>
#include <kernel/unit.h> #include <kernel/unit.h>
#include <util/language.h>
#include <CuTest.h> #include <CuTest.h>
#include <tests.h> #include <tests.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
static void test_register_building(CuTest * tc) static void test_register_building(CuTest * tc)
{ {
@ -382,16 +385,76 @@ static void test_btype_defaults(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
static void test_active_building(CuTest *tc) { static void test_buildingtype_exists(CuTest * tc)
{
region *r;
building *b; building *b;
building_type *btype, *btype2;
test_cleanup(); test_cleanup();
b = test_create_building(test_create_region(0, 0, 0), 0); test_create_world();
btype2 = bt_get_or_create("castle");
assert(btype2);
btype = test_create_buildingtype("Hodor");
btype->maxsize = 10;
r = findregion(-1, 0);
b = new_building(btype, r, default_locale);
b->size = 10;
CuAssertPtrNotNull(tc, b);
CuAssertTrue(tc, !buildingtype_exists(r, NULL, false));
CuAssertTrue(tc, !buildingtype_exists(r, btype2, false));
CuAssertTrue(tc, buildingtype_exists(r, btype, false));
b->size = 9;
fset(b, BLD_WORKING);
CuAssertTrue(tc, !buildingtype_exists(r, btype, false));
btype->maxsize = 0;
freset(b, BLD_WORKING);
CuAssertTrue(tc, buildingtype_exists(r, btype, false));
btype->maxsize = 10;
b->size = 10;
fset(b, BLD_WORKING);
CuAssertTrue(tc, buildingtype_exists(r, btype, true));
freset(b, BLD_WORKING);
CuAssertTrue(tc, !buildingtype_exists(r, btype, true));
}
static void test_active_building(CuTest *tc) {
building *b;
region *r;
unit *u;
building_type *btype;
test_cleanup();
btype = test_create_buildingtype("castle");
assert(btype && btype->maxsize == -1);
b = test_create_building(r = test_create_region(0, 0, 0), btype);
u = test_create_unit(test_create_faction(0), r);
CuAssertIntEquals(tc, false, building_is_active(b)); CuAssertIntEquals(tc, false, building_is_active(b));
CuAssertPtrEquals(tc, NULL, active_building(u, btype));
b->flags |= BLD_WORKING; b->flags |= BLD_WORKING;
CuAssertIntEquals(tc, true, building_is_active(b)); CuAssertIntEquals(tc, true, building_is_active(b));
CuAssertPtrEquals(tc, NULL, active_building(u, btype));
u_set_building(u, b);
CuAssertIntEquals(tc, true, building_is_active(b));
CuAssertPtrNotNull(tc, active_building(u, btype) );
btype->maxsize = 10;
b->size = btype->maxsize;
CuAssertIntEquals(tc, true, building_is_active(b));
CuAssertPtrNotNull(tc, active_building(u, btype) );
b->size = 9;
CuAssertIntEquals(tc, false, building_is_active(b));
CuAssertPtrEquals(tc, NULL, active_building(u, btype));
btype->maxsize = -1;
b->flags &= ~BLD_WORKING; b->flags &= ~BLD_WORKING;
CuAssertIntEquals(tc, false, building_is_active(b)); CuAssertIntEquals(tc, false, building_is_active(b));
CuAssertPtrEquals(tc, NULL, active_building(u, btype));
test_cleanup(); test_cleanup();
} }
@ -432,6 +495,7 @@ CuSuite *get_building_suite(void)
SUITE_ADD_TEST(suite, test_buildingowner_goes_to_same_faction_after_leave); SUITE_ADD_TEST(suite, test_buildingowner_goes_to_same_faction_after_leave);
SUITE_ADD_TEST(suite, test_buildingowner_goes_to_empty_unit_after_leave); SUITE_ADD_TEST(suite, test_buildingowner_goes_to_empty_unit_after_leave);
SUITE_ADD_TEST(suite, test_active_building); SUITE_ADD_TEST(suite, test_active_building);
SUITE_ADD_TEST(suite, test_buildingtype_exists);
SUITE_ADD_TEST(suite, test_safe_building); SUITE_ADD_TEST(suite, test_safe_building);
return suite; return suite;
} }

View File

@ -3531,9 +3531,7 @@ void monthly_healing(void)
if (u->hp < umhp) { if (u->hp < umhp) {
double maxheal = _max(u->number, umhp / 20.0); double maxheal = _max(u->number, umhp / 20.0);
int addhp; int addhp;
struct building *b = inside_building(u); if (active_building(u, bt_find("inn"))) {
const struct building_type *btype = building_is_active(b) ? b->type : NULL;
if (btype == bt_find("inn")) {
p *= 1.5; p *= 1.5;
} }
/* pro punkt 5% höher */ /* pro punkt 5% höher */

View File

@ -36,9 +36,9 @@ static unsigned int get_markets(region * r, unit ** results, size_t size)
if (!btype) if (!btype)
return 0; return 0;
for (b = r->buildings; n < size && b; b = b->next) { for (b = r->buildings; n < size && b; b = b->next) {
if (b->type == btype && (b->flags & BLD_WORKING) if (b->type == btype && building_is_active(b)) {
&& b->size >= b->type->maxsize) {
unit *u = building_owner(b); unit *u = building_owner(b);
/* I decided to omit check for inside_building(u) */
unsigned int i; unsigned int i;
for (i = 0; u && i != n; ++i) { for (i = 0; u && i != n; ++i) {
/* only one market per faction */ /* only one market per faction */

View File

@ -1685,21 +1685,7 @@ unit *owner_buildingtyp(const region * r, const building_type * bt)
return NULL; return NULL;
} }
bool
buildingtype_exists(const region * r, const building_type * bt, bool working)
{
building *b;
for (b = rbuildings(r); b; b = b->next) {
if (b->type == bt && b->size >= bt->maxsize && (!working || fval(b, BLD_WORKING)))
return true;
}
return false;
}
/* Prüft, ob Ablegen von einer Küste in eine der erlaubten Richtungen erfolgt. */ /* Prüft, ob Ablegen von einer Küste in eine der erlaubten Richtungen erfolgt. */
bool can_takeoff(const ship * sh, const region * from, const region * to) bool can_takeoff(const ship * sh, const region * from, const region * to)
{ {
if (!fval(from->terrain, SEA_REGION) && sh->coast != NODIRECTION) { if (!fval(from->terrain, SEA_REGION) && sh->coast != NODIRECTION) {

View File

@ -69,8 +69,6 @@ extern "C" {
struct region *to, struct region_list *route); struct region *to, struct region_list *route);
int walkingcapacity(const struct unit *u); int walkingcapacity(const struct unit *u);
void follow_unit(struct unit *u); void follow_unit(struct unit *u);
bool buildingtype_exists(const struct region *r,
const struct building_type *bt, bool working);
struct unit *owner_buildingtyp(const struct region *r, struct unit *owner_buildingtyp(const struct region *r,
const struct building_type *bt); const struct building_type *bt);
bool move_blocked(const struct unit *u, const struct region *src, bool move_blocked(const struct unit *u, const struct region *src,

View File

@ -158,27 +158,6 @@ static void test_ship_has_harbormaster_ally(CuTest * tc) {
test_cleanup(); test_cleanup();
} }
static void test_building_type_exists(CuTest * tc)
{
region *r;
building *b;
building_type *btype, *btype2;
test_cleanup();
test_create_world();
btype2 = bt_get_or_create("lighthouse");
btype = bt_get_or_create("castle");
r = findregion(-1, 0);
b = new_building(btype, r, default_locale);
CuAssertPtrNotNull(tc, b);
CuAssertTrue(tc, !buildingtype_exists(r, NULL, false));
CuAssertTrue(tc, buildingtype_exists(r, btype, false));
CuAssertTrue(tc, !buildingtype_exists(r, btype2, false));
}
static void test_walkingcapacity(CuTest *tc) { static void test_walkingcapacity(CuTest *tc) {
region *r; region *r;
unit *u; unit *u;
@ -367,7 +346,6 @@ CuSuite *get_move_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_walkingcapacity); SUITE_ADD_TEST(suite, test_walkingcapacity);
SUITE_ADD_TEST(suite, test_building_type_exists);
SUITE_ADD_TEST(suite, test_ship_not_allowed_in_coast); SUITE_ADD_TEST(suite, test_ship_not_allowed_in_coast);
SUITE_ADD_TEST(suite, test_ship_allowed_without_harbormaster); SUITE_ADD_TEST(suite, test_ship_allowed_without_harbormaster);
SUITE_ADD_TEST(suite, test_ship_blocked_by_harbormaster); SUITE_ADD_TEST(suite, test_ship_blocked_by_harbormaster);

View File

@ -176,13 +176,6 @@ static int study_days(unit * student, skill_t sk)
return student->number * speed; return student->number * speed;
} }
static building *active_building(const unit *u, const struct building_type *btype) {
if (u->building && u->building->type == btype && building_is_active(u->building)) {
return inside_building(u);
}
return 0;
}
static int static int
teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk, teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk,
bool report, int *academy) bool report, int *academy)
@ -547,8 +540,6 @@ int study_cmd(unit * u, order * ord)
skill_t sk; skill_t sk;
int maxalchemy = 0; int maxalchemy = 0;
int speed_rule = (study_rule_t)config_get_int("study.speedup", 0); int speed_rule = (study_rule_t)config_get_int("study.speedup", 0);
struct building *b = inside_building(u);
const struct building_type *btype = building_is_active(b) ? b->type : NULL;
bool learn_newskills = config_get_int("study.newskills", 1) != 0; bool learn_newskills = config_get_int("study.newskills", 1) != 0;
if (!unit_can_study(u)) { if (!unit_can_study(u)) {
@ -601,10 +592,7 @@ int study_cmd(unit * u, order * ord)
return 0; return 0;
} }
/* Akademie: */ /* Akademie: */
b = inside_building(u); if (active_building(u, bt_find("academy"))) {
btype = building_is_active(b) ? b->type : NULL;
if (btype && btype == bt_find("academy")) {
studycost = _max(50, studycost * 2); studycost = _max(50, studycost * 2);
} }