diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index 6618b9375..6ee805560 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -3263,6 +3263,11 @@ produce(void) assert(rmoney(r) >= 0); assert(rpeasants(r) >= 0); + if (r->land && rule_taxation==1) { + /* new taxation rules, region owners make money based on morale and building */ + peasant_taxes(r); + } + buyorders = 0; sellorders = 0; working = 0; @@ -3387,10 +3392,5 @@ produce(void) assert(rmoney(r) >= 0); assert(rpeasants(r) >= 0); - - if (r->land && rule_taxation==1) { - /* new taxation rules, region owners make money based on morale and building */ - peasant_taxes(r); - } } } diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 65a34e007..1172471f1 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -199,17 +199,24 @@ get_food(region *r) for (u = r->units; u; u = u->next) { int need = lifestyle(u); + static int food_rules = -1; + + if (food_rules<0) { + food_rules = get_param_int(global.parameters, "rules.economy.food", 0); + } /* Erstmal zurücksetzen */ freset(u, UFL_HUNGER); - /* if the region is owned, and the owner is nice, then we'll get - * food from the peasants */ - if (owner!=NULL && (get_alliance(owner, u->faction) & HELP_MONEY)) { - int rm = rmoney(r); - int use = MIN(rm, need); - rsetmoney(r, rm-use); - need -= use; + if (food_rules&1) { + /* if the region is owned, and the owner is nice, then we'll get + * food from the peasants */ + if (owner!=NULL && (get_alliance(owner, u->faction) & HELP_MONEY)) { + int rm = rmoney(r); + int use = MIN(rm, need); + rsetmoney(r, rm-use); + need -= use; + } } need -= get_money(u); @@ -2940,6 +2947,22 @@ static double rc_popularity(const struct race * rc) return 1.0/(pop-MORALE_COOLDOWN); /* 10 turns average */ } +void update_owners(region * r) +{ + building * blargest = NULL; + blargest = largestbuilding(r, &is_tax_building, false); + if (blargest) { + /* region owners update? */ + faction * f = region_get_owner(r); + unit * u = buildingowner(r, blargest); + if (u==NULL) { + region_set_owner(r, NULL, turn); + } else if (u->faction!=f) { + region_set_owner(r, u->faction, turn); + } + } +} + static void age_region(region * r) { a_age(&r->attribs); @@ -3008,7 +3031,6 @@ ageing(void) building ** bp; unit ** up; ship ** sp; - building * blargest = NULL; age_region(r); @@ -3035,17 +3057,7 @@ ageing(void) if (b==*bp) bp = &b->next; } - blargest = largestbuilding(r, &is_tax_building, false); - if (blargest) { - /* region owners update? */ - faction * f = region_get_owner(r); - unit * u = buildingowner(r, blargest); - if (u==NULL) { - region_set_owner(r, NULL, turn); - } else if (u->faction!=f) { - region_set_owner(r, f, turn); - } - } + update_owners(r); } } diff --git a/src/common/gamecode/laws.h b/src/common/gamecode/laws.h index 2ddb63f0d..928bf8ed0 100644 --- a/src/common/gamecode/laws.h +++ b/src/common/gamecode/laws.h @@ -32,6 +32,7 @@ void demographics(void); void last_orders(void); void find_address(void); void update_guards(void); +void update_owners(struct region * r); void update_subscriptions(void); extern void deliverMail(struct faction * f, struct region * r, struct unit * u, const char *s, struct unit * receiver); diff --git a/src/common/kernel/building.c b/src/common/kernel/building.c index f9b307988..050baad21 100644 --- a/src/common/kernel/building.c +++ b/src/common/kernel/building.c @@ -553,23 +553,24 @@ buildingeffsize(const building * b, boolean img) { int i = b->size, n = 0; const construction * cons; - static const struct building_type * bt_castle; - if (!bt_castle) bt_castle = bt_find("castle"); - assert(bt_castle); + const struct building_type * btype = NULL; if (b==NULL) return 0; - if (b->type!=bt_castle) { - if (img) { - const attrib * a = a_find(b->attribs, &at_icastle); - if (!a || a->data.v != bt_castle) return 0; - } else return 0; + btype = b->type; + if (img) { + const attrib * a = a_find(b->attribs, &at_icastle); + if (a) { + btype = (const struct building_type *)a->data.v; + } + } + cons = btype->construction; + if (!cons || !cons->improvement) { + return 0; } - cons = bt_castle->construction; - assert(cons); while (cons && cons->maxsize != -1 && i>=cons->maxsize) { - i-=cons->maxsize; + i -= cons->maxsize; cons = cons->improvement; ++n; } diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 3eb840e88..be3c23c9c 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -1674,23 +1674,21 @@ cstring(const char *s) } building * -largestbuilding (const region * r, boolean (*eval)(const struct building *), boolean imaginary) +largestbuilding(const region * r, boolean (*eval)(const struct building *), boolean imaginary) { - static const building_type * btype = NULL; building *b, *best = NULL; /* durch die verw. von '>' statt '>=' werden die aelteren burgen * bevorzugt. */ for (b = rbuildings(r); b; b = b->next) { - if (b->type!=btype) { - if (imaginary) { - const attrib * a = a_find(b->attribs, &at_icastle); - if (!a) continue; - if (eval && !eval(b)) continue; - } else continue; + if (eval && !eval(b)) continue; + if (!imaginary) { + const attrib * a = a_find(b->attribs, &at_icastle); + if (a) continue; } - if (best==NULL || b->size > best->size) + if (best==NULL || b->size > best->size) { best = b; + } } return best; } diff --git a/src/eressea/tolua/bind_building.c b/src/eressea/tolua/bind_building.c index e639086fc..f498baeb4 100644 --- a/src/eressea/tolua/bind_building.c +++ b/src/eressea/tolua/bind_building.c @@ -83,6 +83,20 @@ static int tolua_building_set_name(lua_State* tolua_S) return 0; } +static int tolua_building_get_size(lua_State* tolua_S) +{ + building* self = (building*) tolua_tousertype(tolua_S, 1, 0); + tolua_pushnumber(tolua_S, self->size); + return 1; +} + +static int tolua_building_set_size(lua_State* tolua_S) +{ + building* self = (building*)tolua_tousertype(tolua_S, 1, 0); + self->size = (int)tolua_tonumber(tolua_S, 2, 0); + return 0; +} + static int tolua_building_get_units(lua_State* tolua_S) { @@ -146,6 +160,7 @@ tolua_building_open(lua_State* tolua_S) tolua_variable(tolua_S, "name", tolua_building_get_name, tolua_building_set_name); tolua_variable(tolua_S, "units", tolua_building_get_units, NULL); tolua_variable(tolua_S, "region", tolua_building_get_region, tolua_building_set_region); + tolua_variable(tolua_S, "size", tolua_building_get_size, tolua_building_set_size); tolua_function(tolua_S, "add_action", tolua_building_addaction); #ifdef TODO .property("type", &building_gettype) diff --git a/src/eressea/tolua/bindings.c b/src/eressea/tolua/bindings.c index 217524fc5..5f914ab96 100644 --- a/src/eressea/tolua/bindings.c +++ b/src/eressea/tolua/bindings.c @@ -332,6 +332,16 @@ tolua_update_scores(lua_State * tolua_S) return 0; } +static int +tolua_update_owners(lua_State * tolua_S) +{ + region * r; + for (r=regions;r;r=r->next) { + update_owners(r); + } + return 0; +} + static int tolua_update_subscriptions(lua_State * tolua_S) { @@ -927,6 +937,7 @@ tolua_eressea_open(lua_State* tolua_S) tolua_function(tolua_S, "update_subscriptions", tolua_update_subscriptions); tolua_function(tolua_S, "update_scores", tolua_update_scores); + tolua_function(tolua_S, "update_owners", tolua_update_owners); tolua_function(tolua_S, "learn_skill", tolua_learn_skill); diff --git a/src/res/e2k9/equipment.xml b/src/res/e2k9/equipment.xml index b186f36e6..b51850131 100644 --- a/src/res/e2k9/equipment.xml +++ b/src/res/e2k9/equipment.xml @@ -15,7 +15,15 @@ - + + + + + + + + + @@ -23,14 +31,15 @@ - - + + - + + - + @@ -38,7 +47,14 @@ - + + + + + + + + diff --git a/src/scripts/tests.lua b/src/scripts/tests.lua index b0baf418a..49ceff53c 100644 --- a/src/scripts/tests.lua +++ b/src/scripts/tests.lua @@ -345,6 +345,24 @@ local function spells_csv() fail = 1 end +function test_taxes() + free_game() + local r = region.create(0, 0, "plain") + r.peasants = 1000 + r:set_resource("money", 5000) + local f = faction.create("enno@eressea.de", "human", "de") + local u = unit.create(f, r, 1) + u:add_item("money", u.number * 10) + u:clear_orders() + u:add_order("LERNE Wahrnehmung") + local b = building.create(r, "watch") + b.size = 4 + u.building = b + update_owners() + process_orders() + assert(u:get_item("money")==50) +end + function test_market() free_game() local r @@ -385,6 +403,19 @@ function test_work() assert(u:get_item("money")>=10) end +function test_upkeep() + free_game() + local r = region.create(0, 0, "plain") + local f = faction.create("enno@eressea.de", "human", "de") + f.id = 42 + local u = unit.create(f, r, 5) + u:add_item("money", u.number * 11) + u:clear_orders() + u:add_order("LERNE Waffenbau") + process_orders() + assert(u:get_item("money")==u.number) +end + function test_herbalism() free_game() local r = region.create(0, 0, "plain") @@ -441,12 +472,14 @@ tests = { ["spells"] = test_spells, ["herbalism"] = test_herbalism, ["storage"] = test_storage, + ["taxes"] = test_taxes, + ["upkeep"] = test_upkeep, ["work"] = test_work, ["market"] = test_market } mytests = { - ["work"] = test_work, - ["herbalism"] = test_herbalism + ["upkeep"] = test_upkeep, + ["taxes"] = test_taxes } fail = 0 for k, v in pairs(mytests) do