From 2e09d16588f7ed44284f8934c7b405daa9f2b634 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 8 Jun 2008 00:02:24 +0000 Subject: [PATCH] more xmlreport features --- src/common/gamecode/report.c | 1 - src/common/gamecode/xmlreport.c | 71 +++++++++++++++++++++++++-------- src/common/kernel/eressea.c | 12 ++++++ src/common/kernel/eressea.h | 6 +++ src/common/kernel/item.h | 1 - src/common/kernel/reports.c | 6 +++ src/eressea/lua/faction.cpp | 15 ------- src/res/de/strings.xml | 4 ++ src/scripts/run-tests.lua | 6 +-- 9 files changed, 85 insertions(+), 37 deletions(-) diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index c862bc5fe..c5d4ddb1a 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -12,7 +12,6 @@ * prior permission by the authors of Eressea. */ -#define INDENT 0 #define ECHECK_VERSION "4.01" #include diff --git a/src/common/gamecode/xmlreport.c b/src/common/gamecode/xmlreport.c index 47adc45ff..083dcbf10 100644 --- a/src/common/gamecode/xmlreport.c +++ b/src/common/gamecode/xmlreport.c @@ -1,16 +1,11 @@ /* vi: set ts=2: - * - * - * Eressea PB(E)M host Copyright (C) 1998-2003 - * Christian Schlittchen (corwin@amber.kn-bremen.de) - * Katja Zedel (katze@felidae.kn-bremen.de) - * Henning Peters (faroul@beyond.kn-bremen.de) - * Enno Rehling (enno@eressea.de) - * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) - * - * This program may not be used, modified or distributed without - * prior permission by the authors of Eressea. - */ ++-------------------+ Enno Rehling +| Eressea PBEM host | Christian Schlittchen +| (c) 1998 - 2008 | Katja Zedel ++-------------------+ +This program may not be used, modified or distributed +without prior permission by the authors of Eressea. +*/ #include #include @@ -228,9 +223,8 @@ xml_skills(report_context * ctx, unit * u) skill_t sk = sv->id; int esk = eff_skill(u, sk, u->region); - child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "skill")); - xmlNewNsProp(child, xct->ns_atl, BAD_CAST "name", BAD_CAST skillnames[sk]); - xmlNewNsProp(child, xct->ns_atl, BAD_CAST "value", BAD_CAST itoab(esk, 10)); + child = xmlNewTextChild(node, xct->ns_atl, BAD_CAST "skill", BAD_CAST itoab(esk, 10)); + xmlNewNsProp(child, xct->ns_atl, BAD_CAST "type", BAD_CAST skillnames[sk]); } } @@ -453,6 +447,27 @@ xml_resources(report_context * ctx, const seen_region * sr) return node; } +static xmlNodePtr +xml_diplomacy(report_context * ctx, const struct ally * allies) +{ + xml_context* xct = (xml_context*)ctx->userdata; + xmlNodePtr child, node = xmlNewNode(xct->ns_atl, BAD_CAST "diplomacy"); + const struct ally * sf; + + for (sf=allies;sf;sf=sf->next) { + int i, status = sf->status; + for (i=0;helpmodes[i].name;++i) { + if (sf->faction && (status & helpmodes[i].status)==helpmodes[i].status) { + status -= helpmodes[i].status; + child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "status")); + xmlNewNsProp(child, xct->ns_xml, BAD_CAST "faction", xml_ref_faction(sf->faction)); + xmlNewNsProp(child, xct->ns_xml, BAD_CAST "status", (xmlChar*)helpmodes[i].name); + } + } + } + return node; +} + static xmlNodePtr xml_groups(report_context * ctx, const group * groups) { @@ -466,6 +481,8 @@ xml_groups(report_context * ctx, const group * groups) xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, xml_ref_group(g)); xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name", (const xmlChar *)g->name); + if (g->allies) xmlAddChild(child, xml_diplomacy(ctx, g->allies)); + child = xmlAddChild(child, xmlNewNode(xct->ns_atl, BAD_CAST "prefix")); xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", xml_ref_prefix(prefix)); } @@ -490,6 +507,8 @@ xml_faction(report_context * ctx, faction * f) xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "public"); } + if (f->allies) xmlAddChild(node, xml_diplomacy(ctx, f->allies)); + if (ctx->f==f) { xmlAddChild(node, xml_link(ctx, BAD_CAST "race", BAD_CAST f->race->_name[0])); if (f->items) xmlAddChild(node, xml_inventory(ctx, f->items, NULL)); @@ -590,13 +609,14 @@ xml_region(report_context * ctx, seen_region * sr) ship * sh = r->ships; building * b = r->buildings; + /* TODO: entertain-quota, recruits, salary, prices, curses, borders, apparitions (Schemen), spells, travelthru, messages */ xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, xml_ref_region(r)); child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "coordinate")); xmlNewNsProp(child, xct->ns_atl, BAD_CAST "x", xml_i(region_x(r, ctx->f))); xmlNewNsProp(child, xct->ns_atl, BAD_CAST "y", xml_i(region_y(r, ctx->f))); if (r->planep) { - xmlNewNsProp(child, xct->ns_atl, BAD_CAST "plane", xml_s(r->planep->name)); + xmlNewNsProp(child, xct->ns_atl, BAD_CAST "plane", (xmlChar *)r->planep->name); } child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "terrain")); @@ -670,12 +690,29 @@ report_root(report_context * ctx) const faction_list * address; region * r = ctx->first, * rend = ctx->last; xml_context* xct = (xml_context*)ctx->userdata; - xmlNodePtr xmlReport = xmlNewNode(NULL, BAD_CAST "atlantis"); + xmlNodePtr node, child, xmlReport = xmlNewNode(NULL, BAD_CAST "atlantis"); + const char * mailto = locale_string(ctx->f->locale, "mailto"); + const char * mailcmd = locale_string(ctx->f->locale, "mailcmd"); + char zText[128]; + /* TODO: locale, age, options, messages */ xct->ns_xml = xmlNewNs(xmlReport, XML_XML_NAMESPACE, BAD_CAST "xml"); xct->ns_atl = xmlNewNs(xmlReport, XML_ATL_NAMESPACE, NULL); xmlSetNs(xmlReport, xct->ns_atl); + node = xmlAddChild(xmlReport, xmlNewNode(xct->ns_atl, BAD_CAST "server")); + if (mailto) { + snprintf(zText, sizeof(zText), "mailto:%s?subject=%s", mailto, mailcmd); + child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "delivery")); + xmlNewNsProp(child, xct->ns_atl, BAD_CAST "method", BAD_CAST "mail"); + xmlNewNsProp(child, xct->ns_atl, BAD_CAST "href", BAD_CAST zText); + } + xmlNewTextChild(node, xct->ns_atl, BAD_CAST "game", (xmlChar *)global.gamename); + strftime(zText, sizeof(zText), "%Y-%m-%dT%H:%M:%SZ", gmtime(&ctx->report_time)); + xmlNewTextChild(node, xct->ns_atl, BAD_CAST "time", (xmlChar *)zText); + xmlNewTextChild(node, xct->ns_atl, BAD_CAST "turn", (xmlChar *)itoab(turn, 10)); + + for (address=ctx->addresses;address;address=address->next) { xmlAddChild(xmlReport, xml_faction(ctx, address->data)); } diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index cfa0c77ad..399cd7e76 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -238,6 +238,18 @@ old_race(const struct race * rc) return NORACE; } +helpmode helpmodes[] = { + { "all", HELP_ALL }, + { "money", HELP_MONEY }, + { "fight", HELP_FIGHT }, + { "observe", HELP_OBSERVE }, + { "give", HELP_GIVE }, + { "guard", HELP_GUARD }, + { "stealth", HELP_FSTEALTH }, + { "travel", HELP_TRAVEL }, + { NULL, 0 } +}; + const char *directions[MAXDIRECTIONS+2] = { "northwest", diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index 3d23b9dac..c063e6ce6 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -409,6 +409,12 @@ extern struct order * default_order(const struct locale * lang); extern int entertainmoney(const struct region * r); extern void plagues(struct region * r, boolean ismagic); +typedef struct helpmode { + const char * name; + int status; +} helpmode; + +extern struct helpmode helpmodes[]; extern struct attrib_type at_guard; extern void free_gamedata(void); diff --git a/src/common/kernel/item.h b/src/common/kernel/item.h index e3a8a433a..3fc40b7ea 100644 --- a/src/common/kernel/item.h +++ b/src/common/kernel/item.h @@ -327,7 +327,6 @@ int change_money(struct unit *, int); int res_changeitem(struct unit * u, const resource_type * rtype, int delta); extern struct attrib_type at_showitem; /* show this potion's description */ -extern struct attrib_type at_seenitem; /* knows this potion's description, no need to reshow */ extern void register_resources(void); extern void init_resources(void); diff --git a/src/common/kernel/reports.c b/src/common/kernel/reports.c index a03b7c49e..f13ae29ef 100644 --- a/src/common/kernel/reports.c +++ b/src/common/kernel/reports.c @@ -351,11 +351,17 @@ report_resources(const seen_region * sr, resource_report * result, int size, con if (r->land) { int peasants = rpeasants(r); + int money = rmoney(r); int horses = rhorses(r); int trees = rtrees(r, 2); int saplings = rtrees(r, 1); boolean mallorn = fval(r, RF_MALLORN)!=0; + if (money) { + if (n>=size) return -1; + report_resource(result+n, "rm_money", peasants, -1); + ++n; + } if (peasants) { if (n>=size) return -1; report_resource(result+n, "rm_peasant", peasants, -1); diff --git a/src/eressea/lua/faction.cpp b/src/eressea/lua/faction.cpp index a4e8c1c41..dff65a36e 100644 --- a/src/eressea/lua/faction.cpp +++ b/src/eressea/lua/faction.cpp @@ -107,21 +107,6 @@ operator==(const faction& a, const faction&b) return a.no==b.no; } -static struct helpmode { - const char * name; - int status; -} helpmodes[] = { - { "money", HELP_MONEY }, - { "fight", HELP_FIGHT }, - { "observe", HELP_OBSERVE }, - { "give", HELP_GIVE }, - { "guard", HELP_GUARD }, - { "stealth", HELP_FSTEALTH }, - { "travel", HELP_TRAVEL }, - { "all", HELP_ALL }, - { NULL, 0 } -}; - static int faction_getpolicy(const faction& a, const faction& b, const char * flag) { diff --git a/src/res/de/strings.xml b/src/res/de/strings.xml index 8f1f735f4..62b0dac9a 100644 --- a/src/res/de/strings.xml +++ b/src/res/de/strings.xml @@ -6742,6 +6742,10 @@ Bauern peasants + + Silber + silver + Laen laen diff --git a/src/scripts/run-tests.lua b/src/scripts/run-tests.lua index 2766798a8..583b6a627 100644 --- a/src/scripts/run-tests.lua +++ b/src/scripts/run-tests.lua @@ -116,7 +116,7 @@ end function test_hse() read_game("50.dat", "binary") - f = get_faction(atoi36("7scs")) + f = get_faction(atoi36("8h7f")) f.options = f.options + 8192 init_reports() write_report(f) @@ -215,8 +215,8 @@ run_scripts() -- test_free() -- test_bmark() -- test_realloc() -test_xml() --- test_hse() +-- test_xml() +test_hse() -- test_reorder() -- test_tunnels() -- test_md5()