diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index 2da386dc7..9b87e1c9e 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -374,7 +374,7 @@ do_recruiting(recruitment * recruits, int available) for (req=rec->requests;req;req=req->next) { unit * u = req->unit; - const race * rc = u->faction->race; + const race * rc = u->race; /* race is set in recruit() */ int number, dec; float multi = 2.0F * rc->recruit_multi; @@ -486,6 +486,8 @@ recruit(unit * u, struct order * ord, request ** recruitorders) const struct race * rc = f->race; const char * str; + if (fval(u, UFL_RECRUITING)) rc = u->race; + init_tokens(ord); skip_token(); n = getuint(); @@ -575,7 +577,7 @@ recruit(unit * u, struct order * ord, request ** recruitorders) /* snotlinge sollten hiermit bereits abgefangen werden, die * parteirasse ist uruk oder ork*/ if (u->race != rc) { - if (u->number != 0) { + if (fval(u, UFL_RECRUITING) || u->number>0) { cmistake(u, ord, 139, MSG_EVENT); return; } @@ -606,6 +608,7 @@ recruit(unit * u, struct order * ord, request ** recruitorders) cmistake(u, ord, 142, MSG_EVENT); return; } + fset(u, UFL_RECRUITING); o = (request *) calloc(1, sizeof(request)); o->qty = n; o->unit = u; diff --git a/src/common/kernel/unit.h b/src/common/kernel/unit.h index f2967b243..7bdfd0260 100644 --- a/src/common/kernel/unit.h +++ b/src/common/kernel/unit.h @@ -62,6 +62,7 @@ struct item; #define UFL_STEALTH (1<<26) #define UFL_GUARD (1<<27) #define UFL_GROUP (1<<28) +#define UFL_RECRUITING (1<<29) /* unit is recruiting, and cannot change race */ /* Flags, die gespeichert werden sollen: */ #define UFL_SAVEMASK (UFL_MOVED | UFL_NOAID | UFL_OWNER | UFL_PARTEITARNUNG | UFL_LOCKED | UFL_HUNGER | UFL_TAKEALL | UFL_GUARD | UFL_STEALTH | UFL_GROUP | UFL_HERO) diff --git a/src/scripts/tests.lua b/src/scripts/tests.lua index d5d3d26b8..97a4ee851 100644 --- a/src/scripts/tests.lua +++ b/src/scripts/tests.lua @@ -227,6 +227,23 @@ function test_events() assert(fail==0) end +local function test_recruit2() + free_game() + local r = region.create(0, 0, "plain") + local f = faction.create("enno@eressea.de", "human", "de") + local u = unit.create(f, r) + u.number = 1 + u:add_item("money", 2000) + u:clear_orders() + u:add_order("MACHE TEMP 1") + u:add_order("REKRUTIERE 1 Elf") + u:add_order("REKRUTIERE 1 mensch") + u:add_order("REKRUTIERE 1") + process_orders() + print(u:get_item("money")) + print(u.number) +end + local function test_recruit() free_game() local r = region.create(0, 0, "plain") @@ -525,6 +542,7 @@ tests = { ["produce"] = test_produce, ["rename"] = test_rename, ["recruit"] = test_recruit, + ["recruit2"] = test_recruit2, ["spells"] = test_spells, ["herbalism"] = test_herbalism, ["storage"] = test_storage, @@ -535,12 +553,10 @@ tests = { ["market"] = test_market } mytests = { - ["leave"] = test_leave, - ["taxes"] = test_taxes, - ["market"] = test_market + ["recruit2"] = test_recruit2 } fail = 0 -for k, v in pairs(tests) do +for k, v in pairs(mytests) do local status, err = pcall(v) if not status then fail = fail + 1