From 71fa3600f77f6e275f7576fe146268711e4eef63 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 13 Sep 2016 09:09:35 +0200 Subject: [PATCH] recalculate [first,last) after lighthouses aand trvelthru --- src/CMakeLists.txt | 2 -- src/alchemy.c | 3 ++- src/battle.c | 3 +-- src/creport.c | 1 - src/reports.c | 64 +++++++++++++++++++++++++--------------------- src/reports.h | 3 ++- 6 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f1414c851..31a434ad5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -96,7 +96,6 @@ set (ERESSEA_SRC guard.c prefix.c donations.c - seen.c eressea.c callback.c direction.c @@ -197,7 +196,6 @@ set(TESTS_SRC tests.test.c volcano.test.c reports.test.c - seen.test.c summary.test.c travelthru.test.c callback.test.c diff --git a/src/alchemy.c b/src/alchemy.c index cf4dc6f73..89b00c5f0 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -170,7 +170,8 @@ static int potion_luck(unit *u, region *r, attrib_type *atype, int amount) { } static int potion_truth(unit *u) { - fset(u, UFL_DISBELIEVES); + // TODO: this potion does nothing! + // fset(u, UFL_DISBELIEVES); return 1; } diff --git a/src/battle.c b/src/battle.c index 392b24441..e3e74ab82 100644 --- a/src/battle.c +++ b/src/battle.c @@ -23,7 +23,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "chaos.h" #include "move.h" #include "laws.h" -#include "seen.h" #include "skill.h" #include "monster.h" @@ -2884,7 +2883,7 @@ static void battle_punit(unit * u, battle * b) faction *f = bf->faction; strlist *S = 0, *x; - spunit(&S, f, u, 4, see_battle); + spunit(&S, f, u, 4, seen_battle); for (x = S; x; x = x->next) { fbattlerecord(b, f, x->s); if (bdebug && u->faction == f) { diff --git a/src/creport.c b/src/creport.c index 0cb69af43..f0d545de1 100644 --- a/src/creport.c +++ b/src/creport.c @@ -11,7 +11,6 @@ without prior permission by the authors of Eressea. #include #include #include "creport.h" -#include "seen.h" #include "travelthru.h" /* tweakable features */ diff --git a/src/reports.c b/src/reports.c index c895d98ed..8637586bc 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1372,6 +1372,31 @@ void reorder_units(region * r) } } +static region *lastregion(faction * f) +{ +#ifdef SMART_INTERVALS + return f->last->next; +#else + return NULL; +#endif +} + +static region *firstregion(faction * f) +{ +#ifdef SMART_INTERVALS + region *r = f->first; + + if (f->units == NULL) + return NULL; + if (r != NULL) + return r; + + return f->first = regions; +#else + return regions; +#endif +} + static void cb_add_seen(region *r, unit *u, void *cbdata) { unused_arg(cbdata); faction_add_seen(u->faction, r, seen_travel); @@ -1391,6 +1416,9 @@ void prepare_seen(report_context *ctx) static bool rule_region_owners; const struct building_type *bt_lighthouse = bt_find("lighthouse"); + // [fast,last) interval of regions with a unit in it + ctx->first = firstregion(f); + ctx->last = lastregion(f); if (config_changed(&config)) { rule_region_owners = config_token("rules.region_owner_pay_building", bt_lighthouse->_name); } @@ -1421,7 +1449,7 @@ void prepare_seen(report_context *ctx) if (u_race(u) != get_race(RC_SPELL) || u->number == RS_FARVISION) { faction_add_seen(f, r, seen_unit); } - if (fval(r, RF_LIGHTHOUSE) { + if (fval(r, RF_LIGHTHOUSE)) { // TODO: is the building big enough for the unit? if (u->building && u->building->type == bt_lighthouse) { /* we are in a lighthouse. add the regions we can see from here! */ @@ -1435,6 +1463,11 @@ void prepare_seen(report_context *ctx) travelthru_map(r, cb_add_seen, ctx); } } + // [fast,last) interval of seen regions (with lighthouses and travel) + // TODO: what about neighbours? when are they included? do we need + // them outside of the CR? + ctx->first = firstregion(f); + ctx->last = lastregion(f); } static void cb_set_last(region *r, unit *u, void *cbdata) { @@ -1444,40 +1477,13 @@ static void cb_set_last(region *r, unit *u, void *cbdata) { } } -static region *lastregion(faction * f) -{ -#ifdef SMART_INTERVALS - return f->last->next; -#else - return NULL; -#endif -} - -static region *firstregion(faction * f) -{ -#ifdef SMART_INTERVALS - region *r = f->first; - - if (f->units == NULL) - return NULL; - if (r != NULL) - return r; - - return f->first = regions; -#else - return regions; -#endif -} - static void prepare_report(report_context *ctx, faction *f) { ctx->f = f; ctx->report_time = time(NULL); ctx->addresses = NULL; ctx->userdata = NULL; - ctx->first = firstregion(f); - ctx->last = lastregion(f); - prepare_seen(&ctx); + prepare_seen(ctx); } static void finish_reports(report_context *ctx) { diff --git a/src/reports.h b/src/reports.h index 11ec4b580..7e35d26f4 100644 --- a/src/reports.h +++ b/src/reports.h @@ -56,7 +56,6 @@ extern "C" { void spunit(struct strlist **SP, const struct faction *f, const struct unit *u, unsigned int indent, seen_mode mode); - void prepare_seen(struct faction *f); int reports(void); int write_reports(struct faction *f, time_t ltime); int init_reports(void); @@ -75,6 +74,8 @@ extern "C" { time_t report_time; } report_context; + void prepare_seen(struct report_context *ctx); + typedef int(*report_fun) (const char *filename, report_context * ctx, const char *charset); void register_reporttype(const char *extension, report_fun write,