- food and taxes rule-fixes and tests.

- region owner fixes
- building size fixes (bt_castle must die)
This commit is contained in:
Enno Rehling 2009-06-14 11:14:24 +00:00
parent cd0bc2b5e8
commit 1e4b799477
9 changed files with 139 additions and 52 deletions

View File

@ -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);
}
}
}

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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)

View File

@ -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);

View File

@ -15,7 +15,15 @@
<item name="seaserpenthead" amount="1"/>
</set>
<set name="dwarf_0">
<set name="goblin_1">
<skill name="melee" level="7"/>
<skill name="stamina" level="3"/>
<item name="sword" amount="1"/>
<item name="shield" amount="1"/>
<item name="chainmail" amount="1"/>
</set>
<set name="troll_1">
<skill name="melee" level="7"/>
<skill name="stamina" level="3"/>
<item name="sword" amount="1"/>
@ -23,14 +31,15 @@
<item name="plate" amount="1"/>
</set>
<set name="halfling_0">
<skill name="crossbow" level="7"/>
<set name="front_1">
<skill name="melee" level="7"/>
<skill name="stamina" level="3"/>
<item name="crossbow" amount="1"/>
<item name="sword" amount="1"/>
<item name="shield" amount="1"/>
<item name="plate" amount="1"/>
</set>
<set name="dwarf_1">
<set name="front_2">
<skill name="melee" level="7"/>
<skill name="stamina" level="3"/>
<item name="sword" amount="1"/>
@ -38,7 +47,14 @@
<item name="plate" amount="1"/>
</set>
<set name="halfling_1">
<set name="rear_1">
<skill name="crossbow" level="7"/>
<skill name="stamina" level="3"/>
<item name="crossbow" amount="1"/>
<item name="shield" amount="1"/>
</set>
<set name="rear_2">
<skill name="crossbow" level="7"/>
<skill name="stamina" level="3"/>
<item name="crossbow" amount="1"/>

View File

@ -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