diff --git a/scripts/eressea/ents.lua b/scripts/eressea/ents.lua index 761c2d48f..c764d8e0a 100644 --- a/scripts/eressea/ents.lua +++ b/scripts/eressea/ents.lua @@ -16,7 +16,7 @@ end local function repair_ents(r) for u in r.units do if u.faction.id==666 and u.race == "undead" and u.name == "Wütende Ents" then - print("ent repair", u) + eressea.log.info("ent repair: " .. tostring(u)) u.race = "ent" end end diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 2f69f6a71..a1ad73422 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -1,3 +1,4 @@ +require 'tests.e2.undead' require 'tests.e2.shiplanding' require 'tests.e2.e2features' require 'tests.e2.movement' diff --git a/scripts/tests/e2/undead.lua b/scripts/tests/e2/undead.lua new file mode 100644 index 000000000..9f3f67f13 --- /dev/null +++ b/scripts/tests/e2/undead.lua @@ -0,0 +1,31 @@ +require "lunit" + +module("tests.e2.undead", package.seeall, lunit.testcase) + +function setup() + eressea.free_game() +end + +function test_undead_give_item() + local r1 = region.create(0, 0, "plain") + local f1 = faction.create("hodor@eressea.de", "human", "de") + local u1 = unit.create(f1, r1, 1) + u1.race = "undead" + u1:clear_orders() + u1:add_item("log", 1) + u1:add_order("GIB 0 1 Holz") + process_orders() + assert_equal(0, u1:get_item("log")) +end + +function test_undead_dont_give_person() + local r1 = region.create(0, 0, "plain") + local f1 = faction.create("hodor@eressea.de", "human", "de") + local u1 = unit.create(f1, r1, 2) + u1.race = "undead" + u1:clear_orders() + u1:add_item("log", 1) + u1:add_order("GIB 0 1 Person") + process_orders() + assert_equal(2, u1.number) +end diff --git a/src/monsters.c b/src/monsters.c index 85e043eed..d81ba7f81 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -74,6 +74,16 @@ #define DRAGON_RANGE 20 /* Max. Distanz zum nächsten Drachenziel */ #define MAXILLUSION_TEXTS 3 +static void give_peasants(unit *u, const item_type *itype, int reduce) { + char buf[64]; + slprintf(buf, sizeof(buf), "%s 0 %d %s", LOC(u->faction->locale, keyword(K_GIVE)), reduce, LOC(u->faction->locale, itype->rtype->_name)); + unit_addorder(u, parse_order(buf, u->faction->locale)); +} + +static float monster_attack_chance(void) { + return get_param_flt(global.parameters, "rules.monsters.attack_chance", 0.4f); +} + static void reduce_weight(unit * u) { int capacity, weight = 0; @@ -89,9 +99,11 @@ static void reduce_weight(unit * u) while (*itmp != NULL) { item *itm = *itmp; const item_type *itype = itm->type; - weight += itm->number * itype->weight; if (itype->flags & ITF_VEHICLE) { - give_item(itm->number, itm->type, u, NULL, NULL); + give_peasants(u, itm->type, itm->number); + } + else { + weight += itm->number * itype->weight; } if (*itmp == itm) itmp = &itm->next; @@ -109,7 +121,7 @@ static void reduce_weight(unit * u) && itype->rtype->atype == 0) { if (itype->capacity < itype->weight) { int reduce = _min(itm->number, -((capacity - weight) / itype->weight)); - give_item(reduce, itm->type, u, NULL, NULL); + give_peasants(u, itm->type, reduce); weight -= reduce * itype->weight; } } @@ -124,7 +136,7 @@ static void reduce_weight(unit * u) weight += itm->number * itype->weight; if (itype->capacity < itype->weight) { int reduce = _min(itm->number, -((capacity - weight) / itype->weight)); - give_item(reduce, itm->type, u, NULL, NULL); + give_peasants(u, itm->type, reduce); weight -= reduce * itype->weight; } if (*itmp == itm) @@ -132,10 +144,6 @@ static void reduce_weight(unit * u) } } -static float monster_attack_chance(void) { - return get_param_flt(global.parameters, "rules.monsters.attack_chance", 0.4f); -} - static order *monster_attack(unit * u, const unit * target) { if (u->region != target->region) @@ -665,8 +673,6 @@ static order *plan_dragon(unit * u) bool move = false; order *long_order = NULL; - reduce_weight(u); - if (ta == NULL) { move |= (r->land == 0 || r->land->peasants == 0); /* when no peasants, move */ move |= (r->land == 0 || r->land->money == 0); /* when no money, move */ @@ -717,6 +723,9 @@ static order *plan_dragon(unit * u) default: break; } + if (long_order) { + reduce_weight(u); + } if (rng_int() % 100 < 15) { const struct locale *lang = u->faction->locale; /* do a growl */