Merge branch 'master' into develop

This commit is contained in:
Enno Rehling 2019-07-06 17:34:39 +02:00
commit d90bb35fd3
10 changed files with 87 additions and 7 deletions

View File

@ -5196,6 +5196,12 @@
</type> </type>
</message> </message>
<message name="transfer_unit" section="economy">
<type>
<arg name="unit" type="unit"/>
</type>
</message>
<message name="receive_person" section="economy"> <message name="receive_person" section="economy">
<type> <type>
<arg name="unit" type="unit"/> <arg name="unit" type="unit"/>

View File

@ -38,6 +38,9 @@ msgstr "\"$unit($mage) verwandelt $unit($target) in $race($race,0).\""
msgid "give_person" msgid "give_person"
msgstr "\"$unit($unit) übergibt $int($amount) Person$if($eq($amount,1),\"\",\"en\") an $unit($target).\"" 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" msgid "rust_effect_2"
msgstr "\"$unit($mage) ruft ein fürchterliches Unwetter über seine Feinde. Der magischen Regen lässt alles Eisen rosten.\"" msgstr "\"$unit($mage) ruft ein fürchterliches Unwetter über seine Feinde. Der magischen Regen lässt alles Eisen rosten.\""

View File

@ -38,6 +38,9 @@ msgstr "\"$unit($mage) tranforms $unit($target) to $race($race,0).\""
msgid "give_person" msgid "give_person"
msgstr "\"$unit($unit) transfers $int($amount) person$if($eq($amount,1),\"\",\"s\") to $unit($target).\"" 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" msgid "rust_effect_2"
msgstr "\"$unit($mage) calls forth a terrible torment over the enemy. The magical rain makes all iron rusty.\"" msgstr "\"$unit($mage) calls forth a terrible torment over the enemy. The magical rain makes all iron rusty.\""

View File

@ -1,3 +1,4 @@
-- require 'tests.e2.quit'
require 'tests.e2.movement' require 'tests.e2.movement'
require 'tests.e2.astral' require 'tests.e2.astral'
require 'tests.e2.spells' require 'tests.e2.spells'

21
scripts/tests/e2/quit.lua Normal file
View File

@ -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

View File

@ -1,4 +1,5 @@
-- new tests 2014-06-11 -- new tests 2014-06-11
require 'tests.laws'
require 'tests.faction' require 'tests.faction'
require 'tests.locale' require 'tests.locale'
require 'tests.movement' require 'tests.movement'
@ -6,6 +7,5 @@ require 'tests.pool'
require 'tests.regions' require 'tests.regions'
require 'tests.settings' require 'tests.settings'
require 'tests.study' require 'tests.study'
require 'tests.laws'
require 'tests.bindings' require 'tests.bindings'
require 'tests.hunger' require 'tests.hunger'

View File

@ -216,6 +216,7 @@ faction *addfaction(const char *email, const char *password,
const struct race * frace, const struct locale * loc) const struct race * frace, const struct locale * loc)
{ {
faction *f = calloc(1, sizeof(faction)); faction *f = calloc(1, sizeof(faction));
const char *fname;
char buf[128]; char buf[128];
if (!f) abort(); if (!f) abort();
@ -255,7 +256,8 @@ faction *addfaction(const char *email, const char *password,
addlist(&factions, f); addlist(&factions, f);
fhash(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); f->name = str_strdup(buf);
if (!f->race) { if (!f->race) {

View File

@ -947,6 +947,8 @@ void transfer_faction(faction *fsrc, faction *fdst) {
int skill_count[MAXSKILLS]; int skill_count[MAXSKILLS];
int skill_limit[MAXSKILLS]; int skill_limit[MAXSKILLS];
assert(fsrc != fdst);
for (sk = 0; sk != MAXSKILLS; ++sk) { for (sk = 0; sk != MAXSKILLS; ++sk) {
skill_limit[sk] = faction_skill_limit(fdst, 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) { if (u_race(u) == fdst->race) {
u->flags &= ~UFL_HERO; u->flags &= ~UFL_HERO;
if (give_unit_allowed(u) == 0) { if (give_unit_allowed(u) == 0) {
@ -978,12 +983,15 @@ void transfer_faction(faction *fsrc, faction *fdst) {
} }
} }
if (i != u->skill_size) { if (i != u->skill_size) {
u = u->nextF;
continue; continue;
} }
} }
ADDMSG(&fdst->msgs, msg_message("transfer_unit", "unit", u));
u_setfaction(u, fdst); u_setfaction(u, fdst);
} }
} }
u = unext;
} }
} }
@ -1003,6 +1011,7 @@ int quit_cmd(unit * u, struct order *ord)
param_t p; param_t p;
p = getparam(f->locale); p = getparam(f->locale);
if (p == P_FACTION) { if (p == P_FACTION) {
#ifdef QUIT_WITH_TRANSFER
faction *f2 = getfaction(); faction *f2 = getfaction();
if (f2 == NULL) { if (f2 == NULL) {
cmistake(u, ord, 66, MSG_EVENT); cmistake(u, ord, 66, MSG_EVENT);
@ -1015,17 +1024,23 @@ int quit_cmd(unit * u, struct order *ord)
else { else {
unit *u2; unit *u2;
for (u2 = u->region->units; u2; u2 = u2->next) { for (u2 = u->region->units; u2; u2 = u2->next) {
if (u2->faction == f2 && ucontact(u2, u)) { if (u2->faction == f2) {
if (ucontact(u2, u)) {
transfer_faction(u->faction, u2->faction); transfer_faction(u->faction, u2->faction);
break; break;
} }
} }
}
if (u2 == NULL) { if (u2 == NULL) {
/* no target unit found */ /* no target unit found */
cmistake(u, ord, 0, MSG_EVENT); cmistake(u, ord, 40, MSG_EVENT);
flags = 0; flags = 0;
} }
} }
#else
log_error("faction %s: QUIT FACTION is disabled.", factionname(f));
flags = 0;
#endif
} }
} }
f->flags |= flags; f->flags |= flags;

View File

@ -93,6 +93,7 @@ extern "C" {
int reserve_cmd(struct unit *u, struct order *ord); int reserve_cmd(struct unit *u, struct order *ord);
int reserve_self(struct unit *u, struct order *ord); int reserve_self(struct unit *u, struct order *ord);
int claim_cmd(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); void nmr_warnings(void);
bool nmr_death(const struct faction * f, int turn, int timeout); bool nmr_death(const struct faction * f, int turn, int timeout);

View File

@ -1891,6 +1891,7 @@ static void test_quit(CuTest *tc) {
test_teardown(); test_teardown();
} }
#ifdef QUIT_WITH_TRANSFER
/** /**
* Gifting units to another faction upon voluntary death (QUIT). * Gifting units to another faction upon voluntary death (QUIT).
*/ */
@ -2012,6 +2013,30 @@ static void test_quit_transfer_hero(CuTest *tc) {
test_teardown(); 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 *get_laws_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); 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_orders);
SUITE_ADD_TEST(suite, test_long_order_on_ocean); SUITE_ADD_TEST(suite, test_long_order_on_ocean);
SUITE_ADD_TEST(suite, test_quit); SUITE_ADD_TEST(suite, test_quit);
#ifdef QUIT_WITH_TRANSFER
SUITE_ADD_TEST(suite, test_quit_transfer); SUITE_ADD_TEST(suite, test_quit_transfer);
SUITE_ADD_TEST(suite, test_quit_transfer_limited); SUITE_ADD_TEST(suite, test_quit_transfer_limited);
SUITE_ADD_TEST(suite, test_quit_transfer_migrants); SUITE_ADD_TEST(suite, test_quit_transfer_migrants);
SUITE_ADD_TEST(suite, test_quit_transfer_hero); SUITE_ADD_TEST(suite, test_quit_transfer_hero);
SUITE_ADD_TEST(suite, test_transfer_faction);
#endif
return suite; return suite;
} }