From de7248fb5a6ecc1fefa11a396394cfa6ac48dedb Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 13 Jul 2018 22:45:17 +0200 Subject: [PATCH 1/3] BUG 2457: Einheiten werden bei Durchreise nicht angezeigt. --- clibs | 2 +- src/reports.c | 6 ++- src/reports.test.c | 112 +++++++++++++++++++++++++++------------------ storage | 2 +- 4 files changed, 74 insertions(+), 48 deletions(-) diff --git a/clibs b/clibs index f9842e07a..d86c85254 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit f9842e07a442c5453c270badf25ab72633b4edf5 +Subproject commit d86c8525489d7f11b7ba13e101bb59ecf160b871 diff --git a/src/reports.c b/src/reports.c index 06f6b0084..c30587534 100644 --- a/src/reports.c +++ b/src/reports.c @@ -2446,8 +2446,10 @@ bool visible_unit(const unit *u, const faction *f, int stealthmod, seen_mode mod return true; } else { - if (stealthmod > INT_MIN && (mode == seen_lighthouse || mode >= seen_unit)) { - return cansee(f, u->region, u, stealthmod); + if (stealthmod > INT_MIN && mode >= seen_lighthouse) { + if (mode != seen_travel || u->building || u->ship || is_guard(u)) { + return cansee(f, u->region, u, stealthmod); + } } } return false; diff --git a/src/reports.test.c b/src/reports.test.c index 2b22782ae..120af4118 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -1,7 +1,7 @@ #include #include "reports.h" -#include "kernel/calendar.h" +#include "guard.h" #include "keyword.h" #include "lighthouse.h" #include "laws.h" @@ -10,28 +10,29 @@ #include "spy.h" #include "travelthru.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "kernel/ally.h" +#include "kernel/calendar.h" +#include "kernel/config.h" +#include "kernel/building.h" +#include "kernel/faction.h" +#include "kernel/item.h" +#include "kernel/race.h" +#include "kernel/region.h" +#include "kernel/ship.h" +#include "kernel/terrain.h" +#include "kernel/unit.h" +#include "kernel/spell.h" +#include "kernel/spellbook.h" +#include "kernel/terrain.h" -#include -#include -#include -#include +#include "util/attrib.h" +#include "util/language.h" +#include "util/lists.h" +#include "util/message.h" -#include -#include -#include +#include "attributes/attributes.h" +#include "attributes/key.h" +#include "attributes/otherfaction.h" #include #include @@ -824,38 +825,61 @@ static void test_newbie_warning(CuTest *tc) { } static void test_visible_unit(CuTest *tc) { - unit *u2; + unit *u; faction *f; ship *sh; + building *b; + race *rc; test_setup(); f = test_create_faction(NULL); - u2 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); - sh = test_create_ship(u2->region, NULL); + rc = test_create_race("smurf"); + rc->flags |= RCF_UNARMEDGUARD; + u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, NULL)); - CuAssertTrue(tc, cansee(f, u2->region, u2, 0)); - CuAssertTrue(tc, visible_unit(u2, f, 0, seen_unit)); - CuAssertTrue(tc, visible_unit(u2, f, 0, seen_spell)); - CuAssertTrue(tc, visible_unit(u2, f, 0, seen_battle)); - CuAssertTrue(tc, !visible_unit(u2, f, 0, seen_travel)); - CuAssertTrue(tc, !visible_unit(u2, f, 0, seen_none)); - CuAssertTrue(tc, !visible_unit(u2, f, 0, seen_neighbour)); + CuAssertTrue(tc, cansee(f, u->region, u, 0)); + CuAssertTrue(tc, visible_unit(u, f, 0, seen_unit)); + CuAssertTrue(tc, visible_unit(u, f, 0, seen_spell)); + CuAssertTrue(tc, visible_unit(u, f, 0, seen_battle)); + CuAssertTrue(tc, !visible_unit(u, f, 0, seen_travel)); + CuAssertTrue(tc, !visible_unit(u, f, 0, seen_none)); + CuAssertTrue(tc, !visible_unit(u, f, 0, seen_neighbour)); - CuAssertTrue(tc, visible_unit(u2, f, 0, seen_lighthouse)); - CuAssertTrue(tc, !visible_unit(u2, f, -2, seen_lighthouse)); - u2->ship = sh; - CuAssertTrue(tc, visible_unit(u2, f, -2, seen_lighthouse)); - u2->ship = NULL; + CuAssertTrue(tc, visible_unit(u, f, 0, seen_lighthouse)); + CuAssertTrue(tc, !visible_unit(u, f, -2, seen_lighthouse)); - set_level(u2, SK_STEALTH, 1); - CuAssertTrue(tc, !cansee(f, u2->region, u2, 0)); - CuAssertTrue(tc, cansee(f, u2->region, u2, 1)); + u->ship = sh = test_create_ship(u->region, NULL); + CuAssertTrue(tc, visible_unit(u, f, -2, seen_travel)); + CuAssertTrue(tc, visible_unit(u, f, -2, seen_lighthouse)); + u->ship = NULL; - u2->ship = sh; - CuAssertTrue(tc, visible_unit(u2, f, -2, seen_lighthouse)); - u2->ship = NULL; - CuAssertTrue(tc, visible_unit(u2, f, 1, seen_spell)); - CuAssertTrue(tc, visible_unit(u2, f, 1, seen_battle)); + setguard(u, true); + CuAssertTrue(tc, is_guard(u)); + CuAssertTrue(tc, visible_unit(u, f, -2, seen_travel)); + CuAssertTrue(tc, visible_unit(u, f, -2, seen_lighthouse)); + setguard(u, false); + + u->building = b = test_create_building(u->region, NULL); + CuAssertTrue(tc, visible_unit(u, f, -2, seen_travel)); + CuAssertTrue(tc, visible_unit(u, f, -2, seen_lighthouse)); + u->building = NULL; + + set_level(u, SK_STEALTH, 1); + CuAssertTrue(tc, !cansee(f, u->region, u, 0)); + CuAssertTrue(tc, cansee(f, u->region, u, 1)); + + u->ship = sh; + CuAssertTrue(tc, visible_unit(u, f, -2, seen_lighthouse)); + CuAssertTrue(tc, visible_unit(u, f, -2, seen_travel)); + u->ship = NULL; + + u->building = b; + CuAssertTrue(tc, visible_unit(u, f, -2, seen_lighthouse)); + CuAssertTrue(tc, visible_unit(u, f, -2, seen_travel)); + u->building = NULL; + + CuAssertTrue(tc, visible_unit(u, f, 1, seen_spell)); + CuAssertTrue(tc, visible_unit(u, f, 1, seen_battle)); test_teardown(); } diff --git a/storage b/storage index 5623ee652..0ef4b39e3 160000 --- a/storage +++ b/storage @@ -1 +1 @@ -Subproject commit 5623ee6527e97af20c7d8efc03800b6fe1579744 +Subproject commit 0ef4b39e39d8146d6ca323500a285c53843db988 From ced21cc336971286f72bce5d047624b52768ecce Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 13 Jul 2018 23:37:45 +0200 Subject: [PATCH 2/3] BUG 2459 Regionen recycling macht ein Reset der Rohstoffe. --- src/gmtool.c | 29 +++++++++++++----- src/kernel/region.c | 73 ++++++++++++++++++++++++--------------------- src/kernel/region.h | 1 + 3 files changed, 62 insertions(+), 41 deletions(-) diff --git a/src/gmtool.c b/src/gmtool.c index e13701f6f..ce4c0129e 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -531,17 +531,32 @@ static void statusline(WINDOW * win, const char *str) } static void reset_region(region *r) { + unit **up = &r->units; + bool players = false; + set_chaoscount(r, 0); r->flags = 0; a_removeall(&r->attribs, NULL); - while (r->units) { - remove_unit(&r->units, r->units); + while (*up) { + unit *u = *up; + if (is_monsters(u->faction)) { + remove_unit(up, u); + } + else { + players = true; + up = &u->next; + } } - while (r->ships) { - remove_ship(&r->ships, r->ships); - } - while (r->buildings) { - remove_building(&r->buildings, r->buildings); + if (!players) { + while (r->ships) { + remove_ship(&r->ships, r->ships); + } + while (r->buildings) { + remove_building(&r->buildings, r->buildings); + } + if (r->land) { + init_region(r); + } } } diff --git a/src/kernel/region.c b/src/kernel/region.c index 68b47d7a2..7cb52c201 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -1048,6 +1048,43 @@ int fix_demand(region * rd) { return -1; } +void init_region(region *r) +{ + static int changed; + static const terrain_type *t_plain; + const terrain_type * terrain = r->terrain; + int horses = 0, trees = 0; + if (terrain_changed(&changed)) { + t_plain = get_terrain(terrainnames[T_PLAIN]); + } + if (terrain->size>0) { + horses = rng_int() % (terrain->size / 50); + trees = terrain->size * (30 + rng_int() % 40) / 1000; + } + if (t_plain && terrain == t_plain) { + rsethorses(r, horses); + if (chance(0.4)) { + rsettrees(r, 2, trees); + } + } + else if (trees>0 && chance(0.2)) { + rsettrees(r, 2, trees); + } + else { + rsettrees(r, 2, 0); + } + rsettrees(r, 1, rtrees(r, 2) / 4); + rsettrees(r, 0, rtrees(r, 2) / 8); + + if (!fval(r, RF_CHAOTIC)) { + int peasants; + peasants = (region_maxworkers(r) * (20 + dice(6, 10))) / 100; + rsetpeasants(r, MAX(100, peasants)); + rsetmoney(r, rpeasants(r) * ((wage(r, NULL, NULL, + INT_MAX) + 1) + rng_int() % 5)); + } +} + void terraform_region(region * r, const terrain_type * terrain) { /* Resourcen, die nicht mehr vorkommen können, löschen */ @@ -1195,40 +1232,8 @@ void terraform_region(region * r, const terrain_type * terrain) else freset(r, RF_MALLORN); } - } - - if (oldterrain == NULL || terrain->size != oldterrain->size) { - static int changed; - static const terrain_type *t_plain; - int horses = 0, trees = 0; - if (terrain_changed(&changed)) { - t_plain = get_terrain(terrainnames[T_PLAIN]); - } - if (terrain->size>0) { - horses = rng_int() % (terrain->size / 50); - trees = terrain->size * (30 + rng_int() % 40) / 1000; - } - if (t_plain && terrain == t_plain) { - rsethorses(r, horses); - if (chance(0.4)) { - rsettrees(r, 2, trees); - } - } - else if (trees>0 && chance(0.2)) { - rsettrees(r, 2, trees); - } - else { - rsettrees(r, 2, 0); - } - rsettrees(r, 1, rtrees(r, 2) / 4); - rsettrees(r, 0, rtrees(r, 2) / 8); - - if (!fval(r, RF_CHAOTIC)) { - int peasants; - peasants = (region_maxworkers(r) * (20 + dice(6, 10))) / 100; - rsetpeasants(r, MAX(100, peasants)); - rsetmoney(r, rpeasants(r) * ((wage(r, NULL, NULL, - INT_MAX) + 1) + rng_int() % 5)); + if (oldterrain == NULL || terrain->size != oldterrain->size) { + init_region(r); } } } diff --git a/src/kernel/region.h b/src/kernel/region.h index 9543658d9..bf932e9c3 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -228,6 +228,7 @@ extern "C" { struct region *new_region(int x, int y, struct plane *pl, int uid); void remove_region(region ** rlist, region * r); void terraform_region(struct region *r, const struct terrain_type *terrain); + void init_region(struct region *r); bool pnormalize(int *x, int *y, const struct plane *pl); extern const int delta_x[MAXDIRECTIONS]; From e9bded4a87a0b83ea5e4d2ba284470e55ea7fee0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 31 Jul 2018 10:12:54 +0200 Subject: [PATCH 3/3] BUG 2469 wrong default quantity for construction reqs --- src/creport.c | 1 + src/economy.c | 1 - src/exparse.c | 1 + src/report.c | 1 + 4 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/creport.c b/src/creport.c index eeaa563bb..91d56ca3b 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1529,6 +1529,7 @@ static void report_itemtype(FILE *F, faction *f, const item_type *itype) { fprintf(F, "\"%s\"\n", translate(ch, LOC(f->locale, ch))); m++; } + assert(!m->rtype); } } diff --git a/src/economy.c b/src/economy.c index 5fbb0111c..3bb7b1066 100644 --- a/src/economy.c +++ b/src/economy.c @@ -1252,7 +1252,6 @@ static void create_potion(unit * u, const item_type * itype, int want) /* something missing from the list of materials */ ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder, itype->construction, want)); - return; break; default: i_change(&u->items, itype, built); diff --git a/src/exparse.c b/src/exparse.c index 07acb090e..9f49459a9 100644 --- a/src/exparse.c +++ b/src/exparse.c @@ -625,6 +625,7 @@ static void handle_requirement(parseinfo *pi, const XML_Char *el, const XML_Char assert(nreqs < MAX_REQUIREMENTS); req = reqs + nreqs; + req->number = 1; for (i = 0; attr[i]; i += 2) { if (xml_strcmp(attr[i], "type") == 0) { req->rtype = rt_get_or_create(attr[i + 1]); diff --git a/src/report.c b/src/report.c index 2a0e9eb3a..407c0c767 100644 --- a/src/report.c +++ b/src/report.c @@ -2212,6 +2212,7 @@ report_plaintext(const char *filename, report_context * ctx, if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } + assert(!rm->rtype); } *bufp = 0; centre(out, buf, true);