From 820264aa8214af81ce5bdb8c7e252af5079fbe55 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 15 Jul 2018 13:39:23 +0200 Subject: [PATCH] BUG 2461: Liste der Angreifer zeigt nicht alle Parteien. --- src/battle.c | 2 +- src/battle.h | 1 + src/battle.test.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++ src/reports.c | 10 +++-- 4 files changed, 112 insertions(+), 5 deletions(-) diff --git a/src/battle.c b/src/battle.c index be950af7f..38590b8a6 100644 --- a/src/battle.c +++ b/src/battle.c @@ -3323,7 +3323,7 @@ fighter * get_fighter(battle * b, const struct unit * u) return 0; } -static int join_battle(battle * b, unit * u, bool attack, fighter ** cp) +int join_battle(battle * b, unit * u, bool attack, fighter ** cp) { side *s; fighter *fc = NULL; diff --git a/src/battle.h b/src/battle.h index c9429a6b3..48fa7c63a 100644 --- a/src/battle.h +++ b/src/battle.h @@ -261,6 +261,7 @@ extern "C" { void free_battle(struct battle * b); struct fighter *make_fighter(struct battle *b, struct unit *u, struct side * s, bool attack); + int join_battle(struct battle * b, struct unit * u, bool attack, struct fighter ** cp); struct side *make_side(struct battle * b, const struct faction * f, const struct group * g, unsigned int flags, const struct faction * stealthfaction); diff --git a/src/battle.test.c b/src/battle.test.c index 56ca24ac4..7c7012e77 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -1,6 +1,8 @@ #include #include "battle.h" + +#include "reports.h" #include "skill.h" #include @@ -16,6 +18,8 @@ #include #include +#include +#include #include #include #include @@ -552,6 +556,103 @@ static void test_battle_skilldiff(CuTest *tc) test_teardown(); } +static void test_battle_report_one(CuTest *tc) +{ + battle * b = NULL; + region *r; + unit *u1, *u2; + message *m; + const char *expect; + fighter *fig; + + test_setup(); + mt_create_va(mt_new("start_battle", NULL), "factions:string", MT_NEW_END); + r = test_create_plain(0, 0); + u1 = test_create_unit(test_create_faction(NULL), r); + u2 = test_create_unit(test_create_faction(NULL), r); + b = make_battle(r); + join_battle(b, u1, true, &fig); + join_battle(b, u2, false, &fig); + faction_setname(u1->faction, "Monster"); + expect = factionname(u1->faction); + + report_battle_start(b); + CuAssertPtrNotNull(tc, m = test_find_messagetype(u1->faction->battles->msgs, "start_battle")); + CuAssertStrEquals(tc, expect, (const char *)m->parameters[0].v); + + free_battle(b); + test_teardown(); +} + +static void test_battle_report_two(CuTest *tc) +{ + battle * b = NULL; + region *r; + unit *u1, *u2; + message *m; + char expect[64]; + fighter *fig; + struct locale *lang; + + test_setup(); + lang = test_create_locale(); + locale_setstring(lang, "and", "and"); + mt_create_va(mt_new("start_battle", NULL), "factions:string", MT_NEW_END); + r = test_create_plain(0, 0); + u1 = test_create_unit(test_create_faction(NULL), r); + u1->faction->locale = lang; + u2 = test_create_unit(test_create_faction(NULL), r); + u2->faction->locale = lang; + + str_slprintf(expect, sizeof(expect), "%s and %s", factionname(u1->faction), factionname(u2->faction)); + b = make_battle(r); + join_battle(b, u1, true, &fig); + join_battle(b, u2, true, &fig); + report_battle_start(b); + + CuAssertPtrNotNull(tc, m = test_find_messagetype(u1->faction->battles->msgs, "start_battle")); + CuAssertStrEquals(tc, expect, (const char *)m->parameters[0].v); + + free_battle(b); + test_teardown(); +} + +static void test_battle_report_three(CuTest *tc) +{ + battle * b = NULL; + region *r; + unit *u1, *u2, *u3; + message *m; + char expect[64]; + fighter *fig; + struct locale *lang; + + test_setup(); + lang = test_create_locale(); + locale_setstring(lang, "and", "and"); + mt_create_va(mt_new("start_battle", NULL), "factions:string", MT_NEW_END); + r = test_create_plain(0, 0); + u1 = test_create_unit(test_create_faction(NULL), r); + u1->faction->locale = lang; + u2 = test_create_unit(test_create_faction(NULL), r); + u2->faction->locale = lang; + u3 = test_create_unit(test_create_faction(NULL), r); + u3->faction->locale = lang; + + str_slprintf(expect, sizeof(expect), "%s, %s and %s", factionname(u1->faction), factionname(u2->faction), factionname(u3->faction)); + b = make_battle(r); + join_battle(b, u1, true, &fig); + join_battle(b, u2, true, &fig); + join_battle(b, u3, true, &fig); + report_battle_start(b); + + CuAssertPtrNotNull(tc, m = test_find_messagetype(u1->faction->battles->msgs, "start_battle")); + CuAssertStrEquals(tc, expect, (const char *)m->parameters[0].v); + + free_battle(b); + test_teardown(); +} + static void test_battle_skilldiff_building(CuTest *tc) { troop ta, td; @@ -690,6 +791,9 @@ CuSuite *get_battle_suite(void) SUITE_ADD_TEST(suite, test_select_armor); SUITE_ADD_TEST(suite, test_battle_skilldiff); SUITE_ADD_TEST(suite, test_battle_skilldiff_building); + SUITE_ADD_TEST(suite, test_battle_report_one); + SUITE_ADD_TEST(suite, test_battle_report_two); + SUITE_ADD_TEST(suite, test_battle_report_three); SUITE_ADD_TEST(suite, test_defenders_get_building_bonus); SUITE_ADD_TEST(suite, test_attackers_get_no_building_bonus); SUITE_ADD_TEST(suite, test_building_bonus_respects_size); diff --git a/src/reports.c b/src/reports.c index d240ee86d..5355a1db9 100644 --- a/src/reports.c +++ b/src/reports.c @@ -2193,10 +2193,12 @@ void report_battle_start(battle * b) } } } - if (first && lastf) { - sbs_strcat(&sbs, " "); - sbs_strcat(&sbs, LOC(f->locale, "and")); - sbs_strcat(&sbs, " "); + if (lastf) { + if (first) { + sbs_strcat(&sbs, " "); + sbs_strcat(&sbs, LOC(f->locale, "and")); + sbs_strcat(&sbs, " "); + } sbs_strcat(&sbs, lastf); }