test giving stuff to 0.

This commit is contained in:
Enno Rehling 2017-03-03 18:02:43 +01:00
parent 681a4bdaa8
commit a265bc9cdb
2 changed files with 33 additions and 5 deletions

View File

@ -23,7 +23,6 @@ end
function test_goblins() function test_goblins()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
assert(r)
local f1 = faction.create("goblin@eressea.de", "goblin", "de") local f1 = faction.create("goblin@eressea.de", "goblin", "de")
local f2 = faction.create("dwarf@eressea.de", "dwarf", "de") local f2 = faction.create("dwarf@eressea.de", "dwarf", "de")
local f3 = faction.create("elf@eressea.de", "elf", "de") local f3 = faction.create("elf@eressea.de", "elf", "de")
@ -51,3 +50,27 @@ function test_goblins()
ud:add_order("ATTACKIERE " .. itoa36(u3.id)) ud:add_order("ATTACKIERE " .. itoa36(u3.id))
process_orders() process_orders()
end end
function test_make_horse()
eressea.settings.set("rules.horses.growth", "0")
local r = region.create(0, 0, "plain")
local f = faction.create("horses@eressea.de", "human", "de")
local u = unit.create(f, r, 1)
u:set_skill("training", 4)
r:set_resource("horse", 100)
u:add_order("MACHE 1 PFERD")
process_orders()
assert_equal(1, u:get_item("horse"))
assert_equal(99, r:get_resource("horse"))
u:clear_orders()
u:add_order("MACHE 1 STREITROSS")
u:add_item("money", 200)
u:add_item("iron", 1)
process_orders()
assert_equal(1, u:get_item("charger"))
assert_equal(0, u:get_item("horse"))
assert_equal(0, u:get_item("iron"))
assert_equal(0, u:get_item("money"))
assert_equal(99, r:get_resource("horse"))
end

View File

@ -333,7 +333,7 @@ int peasant_luck_effect(int peasants, int luck, int maxp, double variance)
#endif #endif
static void peasants(region * r) static void peasants(region * r, int rule)
{ {
int peasants = rpeasants(r); int peasants = rpeasants(r);
int money = rmoney(r); int money = rmoney(r);
@ -341,7 +341,7 @@ static void peasants(region * r)
int n, satiated; int n, satiated;
int dead = 0; int dead = 0;
if (peasants > 0 && config_get_int("rules.peasants.growth", 1)) { if (peasants > 0 && rule > 0) {
int luck = 0; int luck = 0;
double fraction = peasants * peasant_growth_factor(); double fraction = peasants * peasant_growth_factor();
int births = RAND_ROUND(fraction); int births = RAND_ROUND(fraction);
@ -812,6 +812,8 @@ void demographics(void)
static int last_weeks_season = -1; static int last_weeks_season = -1;
static int current_season = -1; static int current_season = -1;
int plant_rules = config_get_int("rules.grow.formula", 2); int plant_rules = config_get_int("rules.grow.formula", 2);
int horse_rules = config_get_int("rules.horses.growth", 1);
int peasant_rules = config_get_int("rules.peasants.growth", 1);
const struct building_type *bt_harbour = bt_find("harbour"); const struct building_type *bt_harbour = bt_find("harbour");
if (current_season < 0) { if (current_season < 0) {
@ -843,7 +845,8 @@ void demographics(void)
* und gewandert sind */ * und gewandert sind */
calculate_emigration(r); calculate_emigration(r);
peasants(r); peasants(r, peasant_rules);
if (r->age > 20) { if (r->age > 20) {
double mwp = MAX(region_maxworkers(r), 1); double mwp = MAX(region_maxworkers(r), 1);
double prob = double prob =
@ -854,7 +857,9 @@ void demographics(void)
plagues(r); plagues(r);
} }
} }
horses(r); if (horse_rules > 0) {
horses(r);
}
if (plant_rules == 2) { /* E2 */ if (plant_rules == 2) { /* E2 */
growing_trees(r, current_season, last_weeks_season); growing_trees(r, current_season, last_weeks_season);
growing_herbs(r, current_season, last_weeks_season); growing_herbs(r, current_season, last_weeks_season);