forked from github/server
- food and taxes rule-fixes and tests.
- region owner fixes - building size fixes (bt_castle must die)
This commit is contained in:
parent
cd0bc2b5e8
commit
1e4b799477
9 changed files with 139 additions and 52 deletions
|
@ -3263,6 +3263,11 @@ produce(void)
|
||||||
assert(rmoney(r) >= 0);
|
assert(rmoney(r) >= 0);
|
||||||
assert(rpeasants(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;
|
buyorders = 0;
|
||||||
sellorders = 0;
|
sellorders = 0;
|
||||||
working = 0;
|
working = 0;
|
||||||
|
@ -3387,10 +3392,5 @@ produce(void)
|
||||||
|
|
||||||
assert(rmoney(r) >= 0);
|
assert(rmoney(r) >= 0);
|
||||||
assert(rpeasants(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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,17 +199,24 @@ get_food(region *r)
|
||||||
|
|
||||||
for (u = r->units; u; u = u->next) {
|
for (u = r->units; u; u = u->next) {
|
||||||
int need = lifestyle(u);
|
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 */
|
/* Erstmal zurücksetzen */
|
||||||
freset(u, UFL_HUNGER);
|
freset(u, UFL_HUNGER);
|
||||||
|
|
||||||
/* if the region is owned, and the owner is nice, then we'll get
|
if (food_rules&1) {
|
||||||
* food from the peasants */
|
/* if the region is owned, and the owner is nice, then we'll get
|
||||||
if (owner!=NULL && (get_alliance(owner, u->faction) & HELP_MONEY)) {
|
* food from the peasants */
|
||||||
int rm = rmoney(r);
|
if (owner!=NULL && (get_alliance(owner, u->faction) & HELP_MONEY)) {
|
||||||
int use = MIN(rm, need);
|
int rm = rmoney(r);
|
||||||
rsetmoney(r, rm-use);
|
int use = MIN(rm, need);
|
||||||
need -= use;
|
rsetmoney(r, rm-use);
|
||||||
|
need -= use;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
need -= get_money(u);
|
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 */
|
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)
|
static void age_region(region * r)
|
||||||
{
|
{
|
||||||
a_age(&r->attribs);
|
a_age(&r->attribs);
|
||||||
|
@ -3008,7 +3031,6 @@ ageing(void)
|
||||||
building ** bp;
|
building ** bp;
|
||||||
unit ** up;
|
unit ** up;
|
||||||
ship ** sp;
|
ship ** sp;
|
||||||
building * blargest = NULL;
|
|
||||||
|
|
||||||
age_region(r);
|
age_region(r);
|
||||||
|
|
||||||
|
@ -3035,17 +3057,7 @@ ageing(void)
|
||||||
if (b==*bp) bp = &b->next;
|
if (b==*bp) bp = &b->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
blargest = largestbuilding(r, &is_tax_building, false);
|
update_owners(r);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ void demographics(void);
|
||||||
void last_orders(void);
|
void last_orders(void);
|
||||||
void find_address(void);
|
void find_address(void);
|
||||||
void update_guards(void);
|
void update_guards(void);
|
||||||
|
void update_owners(struct region * r);
|
||||||
void update_subscriptions(void);
|
void update_subscriptions(void);
|
||||||
extern void deliverMail(struct faction * f, struct region * r, struct unit * u, const char *s, struct unit * receiver);
|
extern void deliverMail(struct faction * f, struct region * r, struct unit * u, const char *s, struct unit * receiver);
|
||||||
|
|
||||||
|
|
|
@ -553,23 +553,24 @@ buildingeffsize(const building * b, boolean img)
|
||||||
{
|
{
|
||||||
int i = b->size, n = 0;
|
int i = b->size, n = 0;
|
||||||
const construction * cons;
|
const construction * cons;
|
||||||
static const struct building_type * bt_castle;
|
const struct building_type * btype = NULL;
|
||||||
if (!bt_castle) bt_castle = bt_find("castle");
|
|
||||||
assert(bt_castle);
|
|
||||||
|
|
||||||
if (b==NULL) return 0;
|
if (b==NULL) return 0;
|
||||||
|
|
||||||
if (b->type!=bt_castle) {
|
btype = b->type;
|
||||||
if (img) {
|
if (img) {
|
||||||
const attrib * a = a_find(b->attribs, &at_icastle);
|
const attrib * a = a_find(b->attribs, &at_icastle);
|
||||||
if (!a || a->data.v != bt_castle) return 0;
|
if (a) {
|
||||||
} else return 0;
|
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) {
|
while (cons && cons->maxsize != -1 && i>=cons->maxsize) {
|
||||||
i-=cons->maxsize;
|
i -= cons->maxsize;
|
||||||
cons = cons->improvement;
|
cons = cons->improvement;
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1674,23 +1674,21 @@ cstring(const char *s)
|
||||||
}
|
}
|
||||||
|
|
||||||
building *
|
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;
|
building *b, *best = NULL;
|
||||||
/* durch die verw. von '>' statt '>=' werden die aelteren burgen
|
/* durch die verw. von '>' statt '>=' werden die aelteren burgen
|
||||||
* bevorzugt. */
|
* bevorzugt. */
|
||||||
|
|
||||||
for (b = rbuildings(r); b; b = b->next) {
|
for (b = rbuildings(r); b; b = b->next) {
|
||||||
if (b->type!=btype) {
|
if (eval && !eval(b)) continue;
|
||||||
if (imaginary) {
|
if (!imaginary) {
|
||||||
const attrib * a = a_find(b->attribs, &at_icastle);
|
const attrib * a = a_find(b->attribs, &at_icastle);
|
||||||
if (!a) continue;
|
if (a) continue;
|
||||||
if (eval && !eval(b)) continue;
|
|
||||||
} else continue;
|
|
||||||
}
|
}
|
||||||
if (best==NULL || b->size > best->size)
|
if (best==NULL || b->size > best->size) {
|
||||||
best = b;
|
best = b;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return best;
|
return best;
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,20 @@ static int tolua_building_set_name(lua_State* tolua_S)
|
||||||
return 0;
|
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
|
static int
|
||||||
tolua_building_get_units(lua_State* tolua_S)
|
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, "name", tolua_building_get_name, tolua_building_set_name);
|
||||||
tolua_variable(tolua_S, "units", tolua_building_get_units, NULL);
|
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, "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);
|
tolua_function(tolua_S, "add_action", tolua_building_addaction);
|
||||||
#ifdef TODO
|
#ifdef TODO
|
||||||
.property("type", &building_gettype)
|
.property("type", &building_gettype)
|
||||||
|
|
|
@ -332,6 +332,16 @@ tolua_update_scores(lua_State * tolua_S)
|
||||||
return 0;
|
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
|
static int
|
||||||
tolua_update_subscriptions(lua_State * tolua_S)
|
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_subscriptions", tolua_update_subscriptions);
|
||||||
tolua_function(tolua_S, "update_scores", tolua_update_scores);
|
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);
|
tolua_function(tolua_S, "learn_skill", tolua_learn_skill);
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,15 @@
|
||||||
<item name="seaserpenthead" amount="1"/>
|
<item name="seaserpenthead" amount="1"/>
|
||||||
</set>
|
</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="melee" level="7"/>
|
||||||
<skill name="stamina" level="3"/>
|
<skill name="stamina" level="3"/>
|
||||||
<item name="sword" amount="1"/>
|
<item name="sword" amount="1"/>
|
||||||
|
@ -23,14 +31,15 @@
|
||||||
<item name="plate" amount="1"/>
|
<item name="plate" amount="1"/>
|
||||||
</set>
|
</set>
|
||||||
|
|
||||||
<set name="halfling_0">
|
<set name="front_1">
|
||||||
<skill name="crossbow" level="7"/>
|
<skill name="melee" level="7"/>
|
||||||
<skill name="stamina" level="3"/>
|
<skill name="stamina" level="3"/>
|
||||||
<item name="crossbow" amount="1"/>
|
<item name="sword" amount="1"/>
|
||||||
<item name="shield" amount="1"/>
|
<item name="shield" amount="1"/>
|
||||||
|
<item name="plate" amount="1"/>
|
||||||
</set>
|
</set>
|
||||||
|
|
||||||
<set name="dwarf_1">
|
<set name="front_2">
|
||||||
<skill name="melee" level="7"/>
|
<skill name="melee" level="7"/>
|
||||||
<skill name="stamina" level="3"/>
|
<skill name="stamina" level="3"/>
|
||||||
<item name="sword" amount="1"/>
|
<item name="sword" amount="1"/>
|
||||||
|
@ -38,7 +47,14 @@
|
||||||
<item name="plate" amount="1"/>
|
<item name="plate" amount="1"/>
|
||||||
</set>
|
</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="crossbow" level="7"/>
|
||||||
<skill name="stamina" level="3"/>
|
<skill name="stamina" level="3"/>
|
||||||
<item name="crossbow" amount="1"/>
|
<item name="crossbow" amount="1"/>
|
||||||
|
|
|
@ -345,6 +345,24 @@ local function spells_csv()
|
||||||
fail = 1
|
fail = 1
|
||||||
end
|
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()
|
function test_market()
|
||||||
free_game()
|
free_game()
|
||||||
local r
|
local r
|
||||||
|
@ -385,6 +403,19 @@ function test_work()
|
||||||
assert(u:get_item("money")>=10)
|
assert(u:get_item("money")>=10)
|
||||||
end
|
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()
|
function test_herbalism()
|
||||||
free_game()
|
free_game()
|
||||||
local r = region.create(0, 0, "plain")
|
local r = region.create(0, 0, "plain")
|
||||||
|
@ -441,12 +472,14 @@ tests = {
|
||||||
["spells"] = test_spells,
|
["spells"] = test_spells,
|
||||||
["herbalism"] = test_herbalism,
|
["herbalism"] = test_herbalism,
|
||||||
["storage"] = test_storage,
|
["storage"] = test_storage,
|
||||||
|
["taxes"] = test_taxes,
|
||||||
|
["upkeep"] = test_upkeep,
|
||||||
["work"] = test_work,
|
["work"] = test_work,
|
||||||
["market"] = test_market
|
["market"] = test_market
|
||||||
}
|
}
|
||||||
mytests = {
|
mytests = {
|
||||||
["work"] = test_work,
|
["upkeep"] = test_upkeep,
|
||||||
["herbalism"] = test_herbalism
|
["taxes"] = test_taxes
|
||||||
}
|
}
|
||||||
fail = 0
|
fail = 0
|
||||||
for k, v in pairs(mytests) do
|
for k, v in pairs(mytests) do
|
||||||
|
|
Loading…
Reference in a new issue