From 93e34d979d7ef19013725b9cd4fb383215b06203 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 2 Jun 2009 12:22:20 +0000 Subject: [PATCH] - displaying markets in the report. --- src/common/gamecode/creport.c | 16 +++++++++++++++- src/common/gamecode/market.c | 9 --------- src/common/gamecode/report.c | 28 ++++++++++++++++++++++++++-- src/common/kernel/battle.c | 3 ++- src/common/kernel/eressea.c | 9 +++++++++ src/common/kernel/eressea.h | 2 +- src/common/kernel/region.c | 10 ++++++++++ src/common/kernel/region.h | 2 ++ src/res/messages.xml | 8 ++++++++ 9 files changed, 73 insertions(+), 14 deletions(-) diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index 5bb821279..27563403f 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -1157,7 +1157,21 @@ cr_output_region(FILE * F, report_context * ctx, seen_region * sr) if (sr->mode>=see_unit) { /* trade */ - if (rpeasants(r)/TRADE_FRACTION > 0) { + if (markets_module() && r->land) { + const item_type * lux = r_luxury(r); + const item_type * herb = r->land->herbtype; + if (lux || herb) { + fputs("PREISE\n", F); + if (lux) { + const char * ch = resourcename(lux->rtype, 0); + fprintf(F, "%d;%s\n", 1, add_translation(ch, locale_string(f->locale, ch))); + } + if (herb) { + const char * ch = resourcename(herb->rtype, 0); + fprintf(F, "%d;%s\n", 1, add_translation(ch, locale_string(f->locale, ch))); + } + } + } else if (rpeasants(r)/TRADE_FRACTION > 0) { struct demand * dmd = r->land->demands; fputs("PREISE\n", F); while (dmd) { diff --git a/src/common/gamecode/market.c b/src/common/gamecode/market.c index 99a6bc22c..f85b302ce 100644 --- a/src/common/gamecode/market.c +++ b/src/common/gamecode/market.c @@ -59,15 +59,6 @@ free_market(attrib * a) a->data.v = 0; } -const item_type * r_luxury(region * r) -{ - struct demand * dmd; - for (dmd=r->land->demands;dmd;dmd=dmd->next) { - if (dmd->value==0) return dmd->type->itype; - } - return NULL; -} - attrib_type at_market = { "script", NULL, free_market, NULL, diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 1be4699f3..8aaf4338d 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -1882,6 +1882,19 @@ nr_building(FILE *F, const seen_region * sr, const building * b, const faction * nr_curses(F, f, b, TYP_BUILDING, 4); } +static void nr_paragraph(FILE * F, message * m, faction * f) +{ + int bytes; + char buf[4096], * bufp = buf; + size_t size = sizeof(buf) - 1; + + bytes = (int)nr_render(m, f->locale, bufp, size, f); + if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER(); + msg_release(m); + + rparagraph(F, buf, 0, 0, 0); +} + int report_plaintext(const char * filename, report_context * ctx, const char * charset) { @@ -2169,9 +2182,20 @@ report_plaintext(const char * filename, report_context * ctx, const char * chars if (sr->mode==see_unit) { anyunits = 1; describe(F, sr, f); - if (!fval(r->terrain, SEA_REGION) && rpeasants(r)/TRADE_FRACTION > 0) { + if (markets_module() && r->land) { + const item_type * lux = r_luxury(r); + const item_type * herb = r->land->herbtype; + message * m = msg_message("nr_market_info", "product herb", + lux->rtype, herb?herb->rtype:0); + rnl(F); - prices(F, r, f); + nr_paragraph(F, m, f); + // + } else { + if (!fval(r->terrain, SEA_REGION) && rpeasants(r)/TRADE_FRACTION > 0) { + rnl(F); + prices(F, r, f); + } } guards(F, r, f); durchreisende(F, r, f); diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index c54548b57..d490addbe 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -822,7 +822,8 @@ select_armor(troop t, boolean shield) return a->atype; } } - } return NULL; + } + return NULL; } diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index c9ce8c7df..9bc46ec18 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -3052,6 +3052,15 @@ int rule_give(void) return value; } +int markets_module(void) +{ + static int value = -1; + if (value<0) { + value = get_param_int(global.parameters, "modules.markets", 0); + } + return value; +} + /** releases all memory associated with the game state. * call this function before calling read_game() to load a new game * if you have a previously loaded state in memory. diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index fc3944a86..347ebca98 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -336,7 +336,7 @@ extern int lifestyle(const struct unit*); extern int besieged(const struct unit * u); extern int maxworkingpeasants(const struct region * r); extern boolean has_horses(const struct unit * u); - +extern int markets_module(void); extern int wage(const struct region *r, const struct faction *f, const struct race * rc); extern int maintenance_cost(const struct unit * u); extern struct message * movement_error(struct unit * u, const char * token, struct order * ord, int error_code); diff --git a/src/common/kernel/region.c b/src/common/kernel/region.c index 8e1e1b4f1..72038127f 100644 --- a/src/common/kernel/region.c +++ b/src/common/kernel/region.c @@ -791,6 +791,16 @@ r_setdemand(region * r, const luxury_type * ltype, int value) d->value = value; } +const item_type * +r_luxury(region * r) +{ + struct demand * dmd; + for (dmd=r->land->demands;dmd;dmd=dmd->next) { + if (dmd->value==0) return dmd->type->itype; + } + return NULL; +} + int r_demand(const region * r, const luxury_type * ltype) { diff --git a/src/common/kernel/region.h b/src/common/kernel/region.h index dcefd7ae3..9a4bccbca 100644 --- a/src/common/kernel/region.h +++ b/src/common/kernel/region.h @@ -265,6 +265,8 @@ void region_setinfo(struct region * self, const char * name); int region_getresource(const struct region * r, const struct resource_type * rtype); void region_setresource(struct region * r, const struct resource_type * rtype, int value); +extern const struct item_type * r_luxury(struct region * r); + #ifdef __cplusplus } #endif diff --git a/src/res/messages.xml b/src/res/messages.xml index 0d167a5b1..55f37f1ec 100644 --- a/src/res/messages.xml +++ b/src/res/messages.xml @@ -862,6 +862,14 @@ "Le marché local offre la $resource($product,0) au prix de $int($price) écus." "The local market offers $resource($product,0) at a price of $int($price) silver." + + + + + + "Auf dem Markt werden $resource($product,0) und $resource($herb,0) feilgeboten." + "The local market offers $resource($product,0) and $resource($herb,0)." +