diff --git a/res/core/messages.xml b/res/core/messages.xml
index 4de8b0299..fb6cd45bd 100644
--- a/res/core/messages.xml
+++ b/res/core/messages.xml
@@ -5196,6 +5196,12 @@
+
+
+
+
+
+
diff --git a/res/translations/messages.de.po b/res/translations/messages.de.po
index 5623069d4..21586ac31 100644
--- a/res/translations/messages.de.po
+++ b/res/translations/messages.de.po
@@ -38,6 +38,9 @@ msgstr "\"$unit($mage) verwandelt $unit($target) in $race($race,0).\""
msgid "give_person"
msgstr "\"$unit($unit) übergibt $int($amount) Person$if($eq($amount,1),\"\",\"en\") an $unit($target).\""
+msgid "transfer_unit"
+msgstr "\"$unit($unit) schließt sich unserer Partei an.\""
+
msgid "rust_effect_2"
msgstr "\"$unit($mage) ruft ein fürchterliches Unwetter über seine Feinde. Der magischen Regen lässt alles Eisen rosten.\""
diff --git a/res/translations/messages.en.po b/res/translations/messages.en.po
index 1f1db551c..095a83212 100644
--- a/res/translations/messages.en.po
+++ b/res/translations/messages.en.po
@@ -38,6 +38,9 @@ msgstr "\"$unit($mage) tranforms $unit($target) to $race($race,0).\""
msgid "give_person"
msgstr "\"$unit($unit) transfers $int($amount) person$if($eq($amount,1),\"\",\"s\") to $unit($target).\""
+msgid "transfer_unit"
+msgstr "\"$unit($unit) joins our faction.\""
+
msgid "rust_effect_2"
msgstr "\"$unit($mage) calls forth a terrible torment over the enemy. The magical rain makes all iron rusty.\""
diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua
index fde840f98..a7f6d8033 100644
--- a/scripts/tests/e2/init.lua
+++ b/scripts/tests/e2/init.lua
@@ -1,3 +1,4 @@
+-- require 'tests.e2.quit'
require 'tests.e2.movement'
require 'tests.e2.astral'
require 'tests.e2.spells'
diff --git a/scripts/tests/e2/quit.lua b/scripts/tests/e2/quit.lua
new file mode 100644
index 000000000..437494833
--- /dev/null
+++ b/scripts/tests/e2/quit.lua
@@ -0,0 +1,21 @@
+require "lunit"
+
+module("tests.e2.quit", package.seeall, lunit.testcase)
+
+function test_quit_faction()
+ local r = region.create(0, 0, "plain")
+ local f1 = faction.create("human")
+ f1.password = "steamedhams"
+ local f2 = faction.create("human")
+ local u1 = unit.create(f1, r, 10)
+ local u2 = unit.create(f2, r, 10)
+ local u3 = unit.create(f1, r, 10)
+ u1:clear_orders()
+ u2:clear_orders()
+ u1:add_order("STIRB steamedhams PARTEI " .. itoa36(f2.id))
+ u2:add_order("KONTAKTIERE " .. itoa36(u1.id))
+ process_orders()
+ assert_equal(f2, u1.faction)
+ assert_equal(f2, u2.faction)
+ assert_equal(f2, u3.faction)
+end
diff --git a/scripts/tests/init.lua b/scripts/tests/init.lua
index a01e1c75c..2c0786347 100644
--- a/scripts/tests/init.lua
+++ b/scripts/tests/init.lua
@@ -1,4 +1,5 @@
-- new tests 2014-06-11
+require 'tests.laws'
require 'tests.faction'
require 'tests.locale'
require 'tests.movement'
@@ -6,6 +7,5 @@ require 'tests.pool'
require 'tests.regions'
require 'tests.settings'
require 'tests.study'
-require 'tests.laws'
require 'tests.bindings'
require 'tests.hunger'
diff --git a/src/kernel/faction.c b/src/kernel/faction.c
index e3f53fd2c..8df0b3a76 100755
--- a/src/kernel/faction.c
+++ b/src/kernel/faction.c
@@ -216,6 +216,7 @@ faction *addfaction(const char *email, const char *password,
const struct race * frace, const struct locale * loc)
{
faction *f = calloc(1, sizeof(faction));
+ const char *fname;
char buf[128];
if (!f) abort();
@@ -255,7 +256,8 @@ faction *addfaction(const char *email, const char *password,
addlist(&factions, f);
fhash(f);
- slprintf(buf, sizeof(buf), "%s %s", LOC(loc, "factiondefault"), itoa36(f->no));
+ fname = LOC(loc, "factiondefault");
+ slprintf(buf, sizeof(buf), "%s %s", fname ? fname : "faction", itoa36(f->no));
f->name = str_strdup(buf);
if (!f->race) {
diff --git a/src/laws.c b/src/laws.c
index e8200c262..a07c7d517 100644
--- a/src/laws.c
+++ b/src/laws.c
@@ -947,6 +947,8 @@ void transfer_faction(faction *fsrc, faction *fdst) {
int skill_count[MAXSKILLS];
int skill_limit[MAXSKILLS];
+ assert(fsrc != fdst);
+
for (sk = 0; sk != MAXSKILLS; ++sk) {
skill_limit[sk] = faction_skill_limit(fdst, sk);
}
@@ -963,7 +965,10 @@ void transfer_faction(faction *fsrc, faction *fdst) {
}
}
- for (u = fsrc->units; u != NULL; u = u->nextF) {
+ u = fsrc->units;
+ while (u) {
+ unit *unext = u->nextF;
+
if (u_race(u) == fdst->race) {
u->flags &= ~UFL_HERO;
if (give_unit_allowed(u) == 0) {
@@ -978,12 +983,15 @@ void transfer_faction(faction *fsrc, faction *fdst) {
}
}
if (i != u->skill_size) {
+ u = u->nextF;
continue;
}
}
+ ADDMSG(&fdst->msgs, msg_message("transfer_unit", "unit", u));
u_setfaction(u, fdst);
}
}
+ u = unext;
}
}
@@ -1003,6 +1011,7 @@ int quit_cmd(unit * u, struct order *ord)
param_t p;
p = getparam(f->locale);
if (p == P_FACTION) {
+#ifdef QUIT_WITH_TRANSFER
faction *f2 = getfaction();
if (f2 == NULL) {
cmistake(u, ord, 66, MSG_EVENT);
@@ -1015,17 +1024,23 @@ int quit_cmd(unit * u, struct order *ord)
else {
unit *u2;
for (u2 = u->region->units; u2; u2 = u2->next) {
- if (u2->faction == f2 && ucontact(u2, u)) {
- transfer_faction(u->faction, u2->faction);
- break;
+ if (u2->faction == f2) {
+ if (ucontact(u2, u)) {
+ transfer_faction(u->faction, u2->faction);
+ break;
+ }
}
}
if (u2 == NULL) {
/* no target unit found */
- cmistake(u, ord, 0, MSG_EVENT);
+ cmistake(u, ord, 40, MSG_EVENT);
flags = 0;
}
}
+#else
+ log_error("faction %s: QUIT FACTION is disabled.", factionname(f));
+ flags = 0;
+#endif
}
}
f->flags |= flags;
diff --git a/src/laws.h b/src/laws.h
index 1f9632c60..4738f56b8 100755
--- a/src/laws.h
+++ b/src/laws.h
@@ -93,6 +93,7 @@ extern "C" {
int reserve_cmd(struct unit *u, struct order *ord);
int reserve_self(struct unit *u, struct order *ord);
int claim_cmd(struct unit *u, struct order *ord);
+ void transfer_faction(struct faction *fsrc, struct faction *fdst);
void nmr_warnings(void);
bool nmr_death(const struct faction * f, int turn, int timeout);
diff --git a/src/laws.test.c b/src/laws.test.c
index 33742f427..adda8f5ab 100644
--- a/src/laws.test.c
+++ b/src/laws.test.c
@@ -1891,6 +1891,7 @@ static void test_quit(CuTest *tc) {
test_teardown();
}
+#ifdef QUIT_WITH_TRANSFER
/**
* Gifting units to another faction upon voluntary death (QUIT).
*/
@@ -2012,6 +2013,30 @@ static void test_quit_transfer_hero(CuTest *tc) {
test_teardown();
}
+static void test_transfer_faction(CuTest *tc) {
+ faction *f1, *f2;
+ unit *u1, *u2, *u3, *u4;
+ region *r;
+
+ test_setup();
+ r = test_create_plain(0, 0);
+ f1 = test_create_faction(NULL);
+ f2 = test_create_faction(NULL);
+ u1 = test_create_unit(f1, r);
+ u2 = test_create_unit(f1, r);
+ u_setrace(u2, test_create_race("smurf"));
+ u3 = test_create_unit(f2, r);
+ u4 = test_create_unit(f1, r);
+ transfer_faction(f1, f2);
+ CuAssertPtrEquals(tc, f2, u1->faction);
+ CuAssertPtrEquals(tc, f1, u2->faction);
+ CuAssertPtrEquals(tc, f2, u3->faction);
+ CuAssertPtrEquals(tc, f2, u4->faction);
+
+ test_teardown();
+}
+#endif
+
CuSuite *get_laws_suite(void)
{
CuSuite *suite = CuSuiteNew();
@@ -2088,10 +2113,13 @@ CuSuite *get_laws_suite(void)
SUITE_ADD_TEST(suite, test_long_orders);
SUITE_ADD_TEST(suite, test_long_order_on_ocean);
SUITE_ADD_TEST(suite, test_quit);
+#ifdef QUIT_WITH_TRANSFER
SUITE_ADD_TEST(suite, test_quit_transfer);
SUITE_ADD_TEST(suite, test_quit_transfer_limited);
SUITE_ADD_TEST(suite, test_quit_transfer_migrants);
SUITE_ADD_TEST(suite, test_quit_transfer_hero);
+ SUITE_ADD_TEST(suite, test_transfer_faction);
+#endif
return suite;
}