diff --git a/conf/e2/config.json b/conf/e2/config.json index 1ae7f77e5..fa8566eab 100644 --- a/conf/e2/config.json +++ b/conf/e2/config.json @@ -15,6 +15,7 @@ "modules.wormholes": true, "entertain.base": 0, "entertain.perlevel": 20, + "taxing.perlevel": 20, "nmr.timeout": 5, "nmr.removenewbie": 0, "GiveRestriction": 3, diff --git a/process/backup-eressea b/process/backup-eressea index 4f1d42144..56fda9c7a 100755 --- a/process/backup-eressea +++ b/process/backup-eressea @@ -29,3 +29,6 @@ files="$files orders.$TURN" fi echo "backup turn $TURN, game $GAME, files: $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 diff --git a/res/core/messages.xml b/res/core/messages.xml index a3d7ad6e8..be040f5db 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -6357,6 +6357,16 @@ "$unit($unit) in $region($region): '$order($command)' - Die Einheit ist nicht der Eigentümer." "$unit($unit) in $region($region): '$order($command)' - The unit is not the owner." + + + + + + + "$unit($unit) in $region($region): '$order($command)' - Die Einheit ist nicht geschult im Eintreiben von Steuern." + "$unit($unit) in $region($region): '$order($command)' - The unit does not now how to tax." + + diff --git a/scripts/eressea/markets.lua b/scripts/eressea/markets.lua index 1e45e3ba3..dff83c81d 100644 --- a/scripts/eressea/markets.lua +++ b/scripts/eressea/markets.lua @@ -3,7 +3,7 @@ local function get_markets(r, result) result = result or {} 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 if u~=nil then table.insert(result, u) diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index 28b14fe10..9222042ee 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -59,28 +59,6 @@ function disable_test_bug_1738_build_castle_e3() assert_equal(c.size, 250) 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() local r = region.create(0, 0, "plain") 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 end -function test_market() - -- if i am the only trader around, i should be getting all the herbs from all 7 regions +function reset_items(u) + 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 r, idx - local herbnames = { 'h0', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7', 'h8' } - idx = 1 + local r + local herbnames = { 'h0', 'h1', 'h2', 'h3', 'h4', 'h5' } + 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 r = region.create(x, y, "plain") - r:set_resource("peasant", herb_multi * 9 + 50) -- 10 herbs per region - r.herb = herbnames[idx] - idx = idx+1 + r:set_resource("peasant", 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") + b.working = true + + local f = faction.create("market1@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 + + 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) + 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 - b.working = true - eressea.process.markets() - u:add_item("money", -u:get_item("money")) -- now we only have herbs - local len = 0 - for i in u.items do + + reset_items(u) + return r, u, b, herbnames, luxurynames, herbtable, luxurytable +end + +local function test_items(u, names, amount) + local len = 0 + for i in u.items do + if names[i] ~= nil then 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 - 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 + u1:add_item("money", u1.number * 10000) +-- eressea.game.reset() + f1.lastturn=get_turn() + assert_not_equal(nil, factions()) + local idx = 0 + for f in factions() do + assert_equal(1,1,"fac".. f.email) + idx = idx + 1 + 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 function test_market_gives_items() @@ -393,7 +532,7 @@ function test_market_gives_items() r = get_region(0, 0) local b = building.create(r, "market") b.size = 10 - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("market0@eressea.de", "human", "de") f.id = 42 local u = unit.create(f, r, 1) u.building = b @@ -789,3 +928,36 @@ function test_volcanooutbreak_message() assert_not_equal("", msg:render("de")) assert_not_equal("", msg:render("en")) 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 diff --git a/src/bind_building.c b/src/bind_building.c index b8fb07611..a3ecb5913 100644 --- a/src/bind_building.c +++ b/src/bind_building.c @@ -112,6 +112,13 @@ static int tolua_building_set_name(lua_State * L) 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) { 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 "region", tolua_building_get_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_building_set_size); tolua_function(L, TOLUA_CAST "get_typename", tolua_building_get_typename); diff --git a/src/economy.c b/src/economy.c index be26c5d57..0a360c094 100644 --- a/src/economy.c +++ b/src/economy.c @@ -2418,13 +2418,11 @@ static void breedtrees(unit * u, int raw) static void breedhorses(unit * u) { 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); int horses, effsk; assert(rhorse && rhorse->itype); - if (btype != bt_find("stables")) { + if (!active_building(u, bt_find("stables"))) { cmistake(u, u->thisorder, 122, MSG_PRODUCE); 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; unsigned int i; @@ -2954,6 +2952,11 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders) request *o; int max; keyword_t kwd; + static int taxperlevel = 0; + + if (!taxperlevel) { + taxperlevel = config_get_int("taxing.perlevel", 0); + } kwd = init_order(ord); assert(kwd == K_TAX); @@ -2979,6 +2982,12 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders) return; } + if (effskill(u, SK_TAXING, 0) <= 0) { + ADDMSG(&u->faction->msgs, + msg_feedback(u, ord, "error_no_tax_skill", "")); + return; + } + max = getint(); if (max <= 0) { @@ -2988,7 +2997,7 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders) u->wants = _min(income(u), max); } 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); diff --git a/src/economy.h b/src/economy.h index dce389556..7e399cc76 100644 --- a/src/economy.h +++ b/src/economy.h @@ -45,6 +45,7 @@ extern "C" { struct faction; struct order; struct message; + struct request; int income(const struct unit *u); @@ -59,6 +60,8 @@ extern "C" { int recruit_archetypes(void); int give_control_cmd(struct unit *u, struct order *ord); 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); diff --git a/src/economy.test.c b/src/economy.test.c index 09fa1157f..8cf337f4f 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -19,6 +19,7 @@ #include #include +#include static void test_give_control_building(CuTest * tc) { @@ -169,6 +170,79 @@ static void test_normals_recruit(CuTest * tc) { 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 *suite = CuSuiteNew(); @@ -179,5 +253,6 @@ CuSuite *get_economy_suite(void) SUITE_ADD_TEST(suite, test_steal_nosteal); SUITE_ADD_TEST(suite, test_normals_recruit); SUITE_ADD_TEST(suite, test_heroes_dont_recruit); + SUITE_ADD_TEST(suite, test_tax_cmd); return suite; } diff --git a/src/kernel/building.c b/src/kernel/building.c index 715b4de0f..4384b7f80 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -642,10 +642,31 @@ region *building_getregion(const building * b) return b->region; } -bool building_is_active(const struct building *b) { - return b && fval(b, BLD_WORKING); +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; } +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) { building **blist = &b->region->buildings; diff --git a/src/kernel/building.h b/src/kernel/building.h index 78b234f3d..4d08ae647 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -166,7 +166,10 @@ extern "C" { extern void building_set_owner(struct unit * u); 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); + struct building *active_building(const struct unit *u, const struct building_type *btype); #ifdef WDW_PYRAMID extern int wdw_pyramid_level(const struct building *b); diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index f3e66e34d..c0c355940 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -6,10 +6,13 @@ #include #include +#include + #include #include #include #include +#include static void test_register_building(CuTest * tc) { @@ -382,16 +385,76 @@ static void test_btype_defaults(CuTest *tc) { test_cleanup(); } -static void test_active_building(CuTest *tc) { +static void test_buildingtype_exists(CuTest * tc) +{ + region *r; building *b; + building_type *btype, *btype2; 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)); + CuAssertPtrEquals(tc, NULL, active_building(u, btype)); + b->flags |= BLD_WORKING; 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; CuAssertIntEquals(tc, false, building_is_active(b)); + CuAssertPtrEquals(tc, NULL, active_building(u, btype)); 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_empty_unit_after_leave); SUITE_ADD_TEST(suite, test_active_building); + SUITE_ADD_TEST(suite, test_buildingtype_exists); SUITE_ADD_TEST(suite, test_safe_building); return suite; } diff --git a/src/laws.c b/src/laws.c index 9615706a5..591e865a9 100755 --- a/src/laws.c +++ b/src/laws.c @@ -3531,9 +3531,7 @@ void monthly_healing(void) if (u->hp < umhp) { double maxheal = _max(u->number, umhp / 20.0); int addhp; - struct building *b = inside_building(u); - const struct building_type *btype = building_is_active(b) ? b->type : NULL; - if (btype == bt_find("inn")) { + if (active_building(u, bt_find("inn"))) { p *= 1.5; } /* pro punkt 5% höher */ diff --git a/src/market.c b/src/market.c index 68ef9767c..3d96c30e4 100644 --- a/src/market.c +++ b/src/market.c @@ -36,9 +36,9 @@ static unsigned int get_markets(region * r, unit ** results, size_t size) if (!btype) return 0; for (b = r->buildings; n < size && b; b = b->next) { - if (b->type == btype && (b->flags & BLD_WORKING) - && b->size >= b->type->maxsize) { + if (b->type == btype && building_is_active(b)) { unit *u = building_owner(b); + /* I decided to omit check for inside_building(u) */ unsigned int i; for (i = 0; u && i != n; ++i) { /* only one market per faction */ diff --git a/src/move.c b/src/move.c index 4b7558421..f94fbfef1 100644 --- a/src/move.c +++ b/src/move.c @@ -1685,21 +1685,7 @@ unit *owner_buildingtyp(const region * r, const building_type * bt) 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. */ - bool can_takeoff(const ship * sh, const region * from, const region * to) { if (!fval(from->terrain, SEA_REGION) && sh->coast != NODIRECTION) { diff --git a/src/move.h b/src/move.h index ad208a138..0417dcec5 100644 --- a/src/move.h +++ b/src/move.h @@ -69,8 +69,6 @@ extern "C" { struct region *to, struct region_list *route); int walkingcapacity(const 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, const struct building_type *bt); bool move_blocked(const struct unit *u, const struct region *src, diff --git a/src/move.test.c b/src/move.test.c index ed283a9fc..dbbfac5e1 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -158,27 +158,6 @@ static void test_ship_has_harbormaster_ally(CuTest * tc) { 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) { region *r; unit *u; @@ -367,7 +346,6 @@ CuSuite *get_move_suite(void) { CuSuite *suite = CuSuiteNew(); 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_allowed_without_harbormaster); SUITE_ADD_TEST(suite, test_ship_blocked_by_harbormaster); diff --git a/src/study.c b/src/study.c index a20959408..acce1b6d6 100644 --- a/src/study.c +++ b/src/study.c @@ -176,13 +176,6 @@ static int study_days(unit * student, skill_t sk) 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 teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk, bool report, int *academy) @@ -547,8 +540,6 @@ int study_cmd(unit * u, order * ord) skill_t sk; int maxalchemy = 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; if (!unit_can_study(u)) { @@ -601,10 +592,7 @@ int study_cmd(unit * u, order * ord) return 0; } /* Akademie: */ - b = inside_building(u); - btype = building_is_active(b) ? b->type : NULL; - - if (btype && btype == bt_find("academy")) { + if (active_building(u, bt_find("academy"))) { studycost = _max(50, studycost * 2); }