diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..16ec084e0 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,16 @@ +# Geplante Aenderungen in zukuenftigen Eressea-Versionen + +Als Anhaltspunkt fuer die Empfaenger der woechentlichen Testauswertungnen +will ich versuchen, die Liste meiner Aenderungen seit dem letzten Release +zu dokumentieren. + +## Version 3.12.0 + +- [other] optimierte Berechnung der Sichtbarkeit von Leuchttuermen +- [bug] Einheitenlimit bei GIB PERSON beachten +- [bug] Einheitenlimit bei ALLIANCE JOIN beachten +- [rule] Einheiten- und Personenzahl im Report beinhaltet *alle* Einheiten der Partei. +- [other] Statistik fuer Spielleiter zeigt das Parteisilber nicht mehr an. +- [other] Berechnung der Message-Ids optimiert. + + diff --git a/src/economy.test.c b/src/economy.test.c index 7163da7e1..1fca4d194 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -316,8 +316,12 @@ static void test_recruit(CuTest *tc) { f = test_create_faction(0); u = test_create_unit(f, test_create_region(0, 0, 0)); CuAssertIntEquals(tc, 1, u->number); + CuAssertIntEquals(tc, 1, f->num_people); + CuAssertIntEquals(tc, 1, f->num_units); add_recruits(u, 1, 1); CuAssertIntEquals(tc, 2, u->number); + CuAssertIntEquals(tc, 2, f->num_people); + CuAssertIntEquals(tc, 1, f->num_units); CuAssertPtrEquals(tc, u, f->units); CuAssertPtrEquals(tc, NULL, u->nextF); CuAssertPtrEquals(tc, NULL, u->prevF); diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 9b290e5da..c6afc767c 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -81,7 +81,6 @@ extern "C" { int options; struct ally *allies; /* alliedgroup and others should check sf.faction.alive before using a faction from f.allies */ struct group *groups; /* alliedgroup and others should check sf.faction.alive before using a faction from f.groups */ - int nregions; score_t score; struct alliance *alliance; int alliance_joindate; /* the turn on which the faction joined its current alliance (or left the last one) */ diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 2239cf81b..ddc8e0e4a 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -438,8 +438,13 @@ int remove_unit(unit ** ulist, unit * u) *ulist = u->next; } - if (u->faction && u->faction->units == u) { - u->faction->units = u->nextF; + if (u->faction) { + if (count_unit(u)) { + --u->faction->num_units; + } + if (u->faction->units == u) { + u->faction->units = u->nextF; + } } if (u->prevF) { u->prevF->nextF = u->nextF; @@ -1125,12 +1130,13 @@ struct building *inside_building(const struct unit *u) void u_setfaction(unit * u, faction * f) { - int cnt = u->number; if (u->faction == f) return; if (u->faction) { - --u->faction->num_units; - set_number(u, 0); + if (count_unit(u)) { + --u->faction->num_units; + u->faction->num_people -= u->number; + } join_group(u, NULL); free_orders(&u->orders); set_order(&u->thisorder, NULL); @@ -1162,14 +1168,19 @@ void u_setfaction(unit * u, faction * f) if (u->region) { update_interval(f, u->region); } - if (cnt) { - set_number(u, cnt); - } - if (f) { + if (f && count_unit(u)) { ++f->num_units; + f->num_people += u->number; } } +bool count_unit(const unit *u) +{ + const race *rc = u_race(u); + /* spells are invisible. units we cannot see do not count to our limit */ + return rc == NULL || (rc->flags & RCF_INVISIBLE) == 0; +} + void set_number(unit * u, int count) { assert(count >= 0); @@ -1178,10 +1189,10 @@ void set_number(unit * u, int count) if (count == 0) { u->flags &= ~(UFL_HERO); } - if (u->faction) { + if (u->faction && count_unit(u)) { u->faction->num_people += count - u->number; } - u->number = (unsigned short)count; + u->number = count; } void remove_skill(unit * u, skill_t sk) @@ -1484,6 +1495,8 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace, unit *u = (unit *)calloc(1, sizeof(unit)); assert(urace); + u_setrace(u, urace); + u->irace = NULL; if (f) { assert(faction_alive(f)); u_setfaction(u, f); @@ -1496,8 +1509,6 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace, } } } - u_setrace(u, urace); - u->irace = NULL; set_number(u, number); @@ -1803,7 +1814,23 @@ const struct race *u_race(const struct unit *u) void u_setrace(struct unit *u, const struct race *rc) { assert(rc); - u->_race = rc; + if (!u->faction) { + u->_race = rc; + } + else { + int n = 0; + if (count_unit(u)) { + --n; + } + u->_race = rc; + if (count_unit(u)) { + ++n; + } + if (n != 0) { + u->faction->num_units += n; + u->faction->num_people += n * u->number; + } + } } void unit_add_spell(unit * u, sc_mage * m, struct spell * sp, int level) diff --git a/src/kernel/unit.h b/src/kernel/unit.h index 14096c872..8ae13c5e2 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -130,6 +130,7 @@ extern "C" { int weight(const struct unit *u); void renumber_unit(struct unit *u, int no); + bool count_unit(const unit *u); /* unit counts towards faction.num_units and faction.num_people */ const struct race *u_irace(const struct unit *u); const struct race *u_race(const struct unit *u); diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index e1654b821..caa8a9b5c 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -519,6 +519,43 @@ static void test_heal_factor(CuTest *tc) { test_cleanup(); } +static void test_unlimited_units(CuTest *tc) { + race *rc; + faction *f; + unit *u; + + test_setup(); + f = test_create_faction(NULL); + rc = test_create_race("spell"); + rc->flags |= RCF_INVISIBLE; + CuAssertIntEquals(tc, 0, f->num_units); + CuAssertIntEquals(tc, 0, f->num_people); + u = test_create_unit(f, test_create_region(0, 0, NULL)); + CuAssertTrue(tc, count_unit(u)); + CuAssertIntEquals(tc, 1, f->num_units); + CuAssertIntEquals(tc, 1, f->num_people); + u_setfaction(u, NULL); + CuAssertIntEquals(tc, 0, f->num_units); + CuAssertIntEquals(tc, 0, f->num_people); + u_setfaction(u, f); + CuAssertIntEquals(tc, 1, f->num_units); + CuAssertIntEquals(tc, 1, f->num_people); + u_setrace(u, rc); + CuAssertTrue(tc, !count_unit(u)); + CuAssertIntEquals(tc, 0, f->num_units); + CuAssertIntEquals(tc, 0, f->num_people); + scale_number(u, 10); + CuAssertIntEquals(tc, 0, f->num_units); + CuAssertIntEquals(tc, 0, f->num_people); + u_setrace(u, f->race); + CuAssertIntEquals(tc, 1, f->num_units); + CuAssertIntEquals(tc, 10, f->num_people); + remove_unit(&u->region->units, u); + CuAssertIntEquals(tc, 0, f->num_units); + CuAssertIntEquals(tc, 0, f->num_people); + test_cleanup(); +} + CuSuite *get_unit_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -534,6 +571,7 @@ CuSuite *get_unit_suite(void) SUITE_ADD_TEST(suite, test_remove_units_with_dead_faction); SUITE_ADD_TEST(suite, test_remove_empty_units_in_region); SUITE_ADD_TEST(suite, test_names); + SUITE_ADD_TEST(suite, test_unlimited_units); SUITE_ADD_TEST(suite, test_default_name); SUITE_ADD_TEST(suite, test_skillmod); SUITE_ADD_TEST(suite, test_skill_hunger); diff --git a/src/reports.c b/src/reports.c index 1e4e43061..88f6ebb21 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1242,7 +1242,6 @@ static void prepare_lighthouse_ql(faction *f, selist *rlist) { add_seen_nb(f, rl, seen_lighthouse); } } - selist_free(rlist); } static void prepare_lighthouse(faction *f, region *r, int range) diff --git a/src/spy.c b/src/spy.c index c9667f7ee..08662ea8e 100644 --- a/src/spy.c +++ b/src/spy.c @@ -199,8 +199,6 @@ static bool can_set_factionstealth(const unit * u, const faction * f) } ru = ru->next; } - if (ru != NULL) - break; } mu = mu->nextF; } diff --git a/src/summary.c b/src/summary.c index 71bb30efc..aafdfe081 100644 --- a/src/summary.c +++ b/src/summary.c @@ -393,8 +393,6 @@ summary *make_summary(void) plang->locale = lang; } ++plang->number; - f->nregions = 0; - f->num_people = 0; if (f->units) { s->factions++; /* Problem mit Monsterpartei ... */ @@ -433,11 +431,6 @@ summary *make_summary(void) s->peasants += rpeasants(r); s->peasantmoney += rmoney(r); - /* Einheiten Info. nregions darf nur einmal pro Partei - * incrementiert werden. */ - - for (u = r->units; u; u = u->next) - freset(u->faction, FFL_SELECT); for (u = r->units; u; u = u->next) { int orace; f = u->faction; @@ -470,13 +463,8 @@ summary *make_summary(void) if (aktskill > s->maxskill) s->maxskill = aktskill; } - if (!fval(f, FFL_SELECT)) { - f->nregions++; - fset(f, FFL_SELECT); - } } - f->num_people += u->number; orace = (int)old_race(u_race(u)); if (orace >= 0) { s->poprace[orace] += u->number;