2015-01-30 20:37:14 +01:00
|
|
|
/*
|
2010-08-08 07:07:17 +02:00
|
|
|
+-------------------+ Enno Rehling <enno@eressea.de>
|
|
|
|
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
|
|
| (c) 1998 - 2008 | Katja Zedel <katze@felidae.kn-bremen.de>
|
|
|
|
+-------------------+
|
|
|
|
This program may not be used, modified or distributed
|
|
|
|
without prior permission by the authors of Eressea.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <platform.h>
|
|
|
|
#include <kernel/config.h>
|
|
|
|
#include "xmlreport.h"
|
|
|
|
|
|
|
|
#define XML_ATL_NAMESPACE (const xmlChar *) "http://www.eressea.de/XML/2008/atlantis"
|
|
|
|
#define XML_XML_LANG (const xmlChar *) "lang"
|
|
|
|
|
|
|
|
/* modules include */
|
|
|
|
#include <modules/score.h>
|
|
|
|
|
|
|
|
/* attributes include */
|
|
|
|
#include <attributes/follow.h>
|
|
|
|
#include <attributes/racename.h>
|
|
|
|
#include <attributes/orcification.h>
|
|
|
|
#include <attributes/otherfaction.h>
|
|
|
|
#include <attributes/raceprefix.h>
|
|
|
|
|
|
|
|
/* gamecode includes */
|
|
|
|
#include "laws.h"
|
|
|
|
#include "economy.h"
|
2014-08-27 06:40:18 +02:00
|
|
|
#include "move.h"
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
/* kernel includes */
|
|
|
|
#include <kernel/alchemy.h>
|
|
|
|
#include <kernel/alliance.h>
|
2012-06-30 20:07:28 +02:00
|
|
|
#include <kernel/ally.h>
|
2010-08-08 07:07:17 +02:00
|
|
|
#include <kernel/connection.h>
|
2012-06-03 22:39:42 +02:00
|
|
|
#include <kernel/curse.h>
|
2010-08-08 07:07:17 +02:00
|
|
|
#include <kernel/building.h>
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
#include <kernel/group.h>
|
|
|
|
#include <kernel/item.h>
|
|
|
|
#include <kernel/magic.h>
|
2014-06-09 18:54:48 +02:00
|
|
|
#include <kernel/messages.h>
|
2010-08-08 07:07:17 +02:00
|
|
|
#include <kernel/order.h>
|
|
|
|
#include <kernel/plane.h>
|
|
|
|
#include <kernel/race.h>
|
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/reports.h>
|
|
|
|
#include <kernel/resources.h>
|
|
|
|
#include <kernel/ship.h>
|
|
|
|
#include <kernel/skill.h>
|
|
|
|
#include <kernel/teleport.h>
|
|
|
|
#include <kernel/terrain.h>
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
#include <kernel/save.h>
|
|
|
|
|
|
|
|
/* util includes */
|
|
|
|
#include <util/attrib.h>
|
|
|
|
#include <util/base36.h>
|
|
|
|
#include <util/goodies.h>
|
|
|
|
#include <util/language.h>
|
|
|
|
#include <util/message.h>
|
2012-05-31 04:55:17 +02:00
|
|
|
#include <quicklist.h>
|
2010-08-08 07:07:17 +02:00
|
|
|
#include <util/unicode.h>
|
|
|
|
#include <util/xml.h>
|
|
|
|
|
2014-06-10 04:04:11 +02:00
|
|
|
#ifdef USE_LIBXML2
|
2010-08-08 07:07:17 +02:00
|
|
|
/* libxml2 includes */
|
|
|
|
#include <libxml/tree.h>
|
|
|
|
#include <libxml/encoding.h>
|
|
|
|
#ifdef USE_ICONV
|
|
|
|
#include <iconv.h>
|
|
|
|
#endif
|
2014-06-10 04:04:11 +02:00
|
|
|
#endif
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
/* libc includes */
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define L10N(x) x
|
|
|
|
|
|
|
|
typedef struct xml_context {
|
|
|
|
xmlDocPtr doc;
|
|
|
|
xmlNsPtr ns_atl;
|
|
|
|
xmlNsPtr ns_xml;
|
|
|
|
} xml_context;
|
|
|
|
|
|
|
|
static xmlNodePtr
|
|
|
|
xml_link(report_context * ctx, const xmlChar * rel, const xmlChar * ref)
|
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
xml_context *xct = (xml_context *) ctx->userdata;
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "link");
|
|
|
|
|
|
|
|
xmlNewNsProp(node, xct->ns_atl, BAD_CAST "rel", rel);
|
|
|
|
xmlNewNsProp(node, xct->ns_atl, BAD_CAST "ref", ref);
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static const xmlChar *xml_ref_unit(const unit * u)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
|
|
|
static char idbuf[20];
|
2014-03-15 20:35:20 +01:00
|
|
|
_snprintf(idbuf, sizeof(idbuf), "unit_%d", u->no);
|
2010-08-08 07:07:17 +02:00
|
|
|
return (const xmlChar *)idbuf;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static const xmlChar *xml_ref_faction(const faction * f)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
|
|
|
static char idbuf[20];
|
2014-03-15 20:35:20 +01:00
|
|
|
_snprintf(idbuf, sizeof(idbuf), "fctn_%d", f->no);
|
2010-08-08 07:07:17 +02:00
|
|
|
return (const xmlChar *)idbuf;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static const xmlChar *xml_ref_group(const group * g)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
|
|
|
static char idbuf[20];
|
2014-03-15 20:35:20 +01:00
|
|
|
_snprintf(idbuf, sizeof(idbuf), "grp_%d", g->gid);
|
2010-08-08 07:07:17 +02:00
|
|
|
return (const xmlChar *)idbuf;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static const xmlChar *xml_ref_prefix(const char *str)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
|
|
|
static char idbuf[20];
|
2014-03-15 20:35:20 +01:00
|
|
|
_snprintf(idbuf, sizeof(idbuf), "pref_%s", str);
|
2010-08-08 07:07:17 +02:00
|
|
|
return (const xmlChar *)idbuf;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static const xmlChar *xml_ref_building(const building * b)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
|
|
|
static char idbuf[20];
|
2014-03-15 20:35:20 +01:00
|
|
|
_snprintf(idbuf, sizeof(idbuf), "bldg_%d", b->no);
|
2010-08-08 07:07:17 +02:00
|
|
|
return (const xmlChar *)idbuf;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static const xmlChar *xml_ref_ship(const ship * sh)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
|
|
|
static char idbuf[20];
|
2014-03-15 20:35:20 +01:00
|
|
|
_snprintf(idbuf, sizeof(idbuf), "shp_%d", sh->no);
|
2010-08-08 07:07:17 +02:00
|
|
|
return (const xmlChar *)idbuf;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static const xmlChar *xml_ref_region(const region * r)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
|
|
|
static char idbuf[20];
|
2014-03-15 20:35:20 +01:00
|
|
|
_snprintf(idbuf, sizeof(idbuf), "rgn_%d", r->uid);
|
2010-08-08 07:07:17 +02:00
|
|
|
return (const xmlChar *)idbuf;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static xmlNodePtr xml_inventory(report_context * ctx, item * items, unit * u)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
xml_context *xct = (xml_context *) ctx->userdata;
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "items");
|
2011-03-07 08:02:35 +01:00
|
|
|
item *itm;
|
|
|
|
|
|
|
|
for (itm = items; itm; itm = itm->next) {
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNodePtr child;
|
2011-03-07 08:02:35 +01:00
|
|
|
const char *name;
|
2010-08-08 07:07:17 +02:00
|
|
|
int n;
|
|
|
|
|
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "item"));
|
|
|
|
report_item(u, itm, ctx->f, NULL, &name, &n, true);
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (xmlChar *) name);
|
|
|
|
xmlNodeAddContent(child, (xmlChar *) itoab(n, 10));
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2012-05-26 09:57:13 +02:00
|
|
|
#ifdef TODO /*spellbooks */
|
2010-08-08 07:07:17 +02:00
|
|
|
static xmlNodePtr
|
2011-02-26 09:26:14 +01:00
|
|
|
xml_spells(report_context * ctx, quicklist * slist, int maxlevel)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
xml_context *xct = (xml_context *) ctx->userdata;
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNodePtr child, node = xmlNewNode(xct->ns_atl, BAD_CAST "spells");
|
2011-03-07 08:02:35 +01:00
|
|
|
quicklist *ql;
|
2011-02-26 09:26:14 +01:00
|
|
|
int qi;
|
2010-08-08 07:07:17 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
for (ql = slist, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
|
|
|
|
spell *sp = (spell *) ql_get(ql, qi);
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
if (sp->level <= maxlevel) {
|
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "spell"));
|
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "name", BAD_CAST sp->sname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
2012-05-26 09:57:13 +02:00
|
|
|
#endif
|
2010-08-08 07:07:17 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static xmlNodePtr xml_skills(report_context * ctx, unit * u)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
xml_context *xct = (xml_context *) ctx->userdata;
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNodePtr child, node = xmlNewNode(xct->ns_atl, BAD_CAST "skills");
|
2011-03-07 08:02:35 +01:00
|
|
|
skill *sv;
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
|
2011-03-07 08:02:35 +01:00
|
|
|
if (sv->level > 0) {
|
2010-08-08 07:07:17 +02:00
|
|
|
skill_t sk = sv->id;
|
|
|
|
int esk = eff_skill(u, sk, u->region);
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
child =
|
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "skill", BAD_CAST itoab(esk,
|
|
|
|
10));
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", BAD_CAST skillnames[sk]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static xmlNodePtr xml_unit(report_context * ctx, unit * u, int mode)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
xml_context *xct = (xml_context *) ctx->userdata;
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "unit");
|
2011-03-07 08:02:35 +01:00
|
|
|
static const curse_type *itemcloak_ct = 0;
|
2012-06-24 07:41:07 +02:00
|
|
|
static bool init = false;
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNodePtr child;
|
2011-03-07 08:02:35 +01:00
|
|
|
const char *str, *rcname, *rcillusion;
|
2012-06-24 07:41:07 +02:00
|
|
|
bool disclosure = (ctx->f == u->faction || omniscient(ctx->f));
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
/* TODO: hitpoints, aura, combatspells, curses */
|
|
|
|
|
|
|
|
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, xml_ref_unit(u));
|
|
|
|
xmlNewNsProp(node, xct->ns_atl, BAD_CAST "key", BAD_CAST itoa36(u->no));
|
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name", (const xmlChar *)u->name);
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "number",
|
|
|
|
(const xmlChar *)itoab(u->number, 10));
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
/* optional description */
|
|
|
|
str = u_description(u, ctx->f->locale);
|
|
|
|
if (str) {
|
2011-03-07 08:02:35 +01:00
|
|
|
child =
|
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text", (const xmlChar *)str);
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "public");
|
2011-03-07 08:02:35 +01:00
|
|
|
if (str != u->display) {
|
|
|
|
xmlNewNsProp(child, xct->ns_atl, XML_XML_LANG,
|
|
|
|
BAD_CAST locale_name(ctx->f->locale));
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* possible <guard/> info */
|
2011-03-07 08:02:35 +01:00
|
|
|
if (is_guard(u, GUARD_ALL) != 0) {
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "guard"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* siege */
|
|
|
|
if (fval(u, UFL_SIEGE)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
building *b = usiege(u);
|
2010-08-08 07:07:17 +02:00
|
|
|
if (b) {
|
|
|
|
xmlAddChild(node, xml_link(ctx, BAD_CAST "siege", xml_ref_building(b)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: temp/alias */
|
|
|
|
|
|
|
|
/* race information */
|
|
|
|
report_race(u, &rcname, &rcillusion);
|
|
|
|
if (disclosure) {
|
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "race"));
|
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "true");
|
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (const xmlChar *)rcname);
|
|
|
|
if (rcillusion) {
|
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "race"));
|
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "stealth");
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
|
|
|
(const xmlChar *)rcillusion);
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "race"));
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
|
|
|
(const xmlChar *)(rcillusion ? rcillusion : rcname));
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* group and prefix information. we only write the prefix if we really must */
|
|
|
|
if (fval(u, UFL_GROUP)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
attrib *a = a_find(u->attribs, &at_group);
|
|
|
|
if (a != NULL) {
|
|
|
|
const group *g = (const group *)a->data.v;
|
2010-08-08 07:07:17 +02:00
|
|
|
if (disclosure) {
|
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "group"));
|
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", xml_ref_group(g));
|
|
|
|
} else {
|
2011-03-07 08:02:35 +01:00
|
|
|
const char *prefix = get_prefix(g->attribs);
|
2010-08-08 07:07:17 +02:00
|
|
|
if (prefix) {
|
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "prefix"));
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
|
|
|
xml_ref_prefix(prefix));
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disclosure) {
|
2011-03-07 08:02:35 +01:00
|
|
|
unit *mage;
|
|
|
|
|
2010-08-08 07:07:17 +02:00
|
|
|
str = uprivate(u);
|
|
|
|
if (str) {
|
2011-03-07 08:02:35 +01:00
|
|
|
child =
|
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text",
|
|
|
|
(const xmlChar *)str);
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "private");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* familiar info */
|
|
|
|
mage = get_familiar_mage(u);
|
2011-03-07 08:02:35 +01:00
|
|
|
if (mage)
|
|
|
|
xmlAddChild(node, xml_link(ctx, BAD_CAST "familiar_of",
|
|
|
|
xml_ref_unit(mage)));
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
/* combat status */
|
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "status"));
|
|
|
|
xmlSetNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "combat");
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlSetNsProp(child, xct->ns_atl, BAD_CAST "value",
|
|
|
|
BAD_CAST combatstatus[u->status]);
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
if (fval(u, UFL_NOAID)) {
|
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "status"));
|
|
|
|
xmlSetNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "aid");
|
|
|
|
xmlSetNsProp(child, xct->ns_atl, BAD_CAST "value", BAD_CAST "false");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fval(u, UFL_STEALTH)) {
|
|
|
|
int i = u_geteffstealth(u);
|
2011-03-07 08:02:35 +01:00
|
|
|
if (i >= 0) {
|
2010-08-08 07:07:17 +02:00
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "status"));
|
|
|
|
xmlSetNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "stealth");
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlSetNsProp(child, xct->ns_atl, BAD_CAST "value", BAD_CAST itoab(i,
|
|
|
|
10));
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fval(u, UFL_HERO)) {
|
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "status"));
|
|
|
|
xmlSetNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "hero");
|
|
|
|
xmlSetNsProp(child, xct->ns_atl, BAD_CAST "value", BAD_CAST "true");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fval(u, UFL_HUNGER)) {
|
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "status"));
|
|
|
|
xmlSetNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "hunger");
|
|
|
|
xmlSetNsProp(child, xct->ns_atl, BAD_CAST "value", BAD_CAST "true");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skills */
|
|
|
|
if (u->skill_size) {
|
|
|
|
xmlAddChild(node, xml_skills(ctx, u));
|
|
|
|
}
|
|
|
|
|
2012-05-26 09:57:13 +02:00
|
|
|
#ifdef TODO /*spellbooks */
|
2010-08-08 07:07:17 +02:00
|
|
|
/* spells */
|
|
|
|
if (is_mage(u)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
sc_mage *mage = get_mage(u);
|
|
|
|
quicklist *slist = mage->spells;
|
2010-08-08 07:07:17 +02:00
|
|
|
if (slist) {
|
|
|
|
xmlAddChild(node, xml_spells(ctx, slist, effskill(u, SK_MAGIC)));
|
|
|
|
}
|
|
|
|
}
|
2012-05-26 09:57:13 +02:00
|
|
|
#endif
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* faction information w/ visibiility */
|
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "faction"));
|
|
|
|
if (disclosure) {
|
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "true");
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
|
|
|
xml_ref_faction(u->faction));
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
if (fval(u, UFL_ANON_FACTION)) {
|
2011-03-07 08:02:35 +01:00
|
|
|
const faction *sf = visible_faction(NULL, u);
|
2010-08-08 07:07:17 +02:00
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "faction"));
|
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "stealth");
|
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", xml_ref_faction(sf));
|
|
|
|
}
|
|
|
|
} else {
|
2011-03-07 08:02:35 +01:00
|
|
|
const faction *sf = visible_faction(ctx->f, u);
|
|
|
|
if (sf == ctx->f) {
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "stealth");
|
|
|
|
}
|
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", xml_ref_faction(sf));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the inventory */
|
|
|
|
if (u->items) {
|
|
|
|
item result[MAX_INVENTORY];
|
2011-03-07 08:02:35 +01:00
|
|
|
item *show = NULL;
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
if (!init) {
|
|
|
|
init = true;
|
|
|
|
itemcloak_ct = ct_find("itemcloak");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disclosure) {
|
|
|
|
show = u->items;
|
|
|
|
} else {
|
2012-06-24 07:41:07 +02:00
|
|
|
bool see_items = (mode >= see_unit);
|
2010-08-08 07:07:17 +02:00
|
|
|
if (see_items) {
|
|
|
|
if (itemcloak_ct && curse_active(get_curse(u->attribs, itemcloak_ct))) {
|
|
|
|
see_items = false;
|
|
|
|
} else {
|
|
|
|
see_items = effskill(u, SK_STEALTH) < 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (see_items) {
|
|
|
|
int n = report_items(u->items, result, MAX_INVENTORY, u, ctx->f);
|
2011-03-07 08:02:35 +01:00
|
|
|
assert(n >= 0);
|
|
|
|
if (n > 0)
|
|
|
|
show = result;
|
|
|
|
else
|
|
|
|
show = NULL;
|
2010-08-08 07:07:17 +02:00
|
|
|
} else {
|
|
|
|
show = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (show) {
|
|
|
|
xmlAddChild(node, xml_inventory(ctx, show, u));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static xmlNodePtr xml_resources(report_context * ctx, const seen_region * sr)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
xml_context *xct = (xml_context *) ctx->userdata;
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNodePtr node = NULL;
|
|
|
|
resource_report result[MAX_RAWMATERIALS];
|
|
|
|
int n, size = report_resources(sr, result, MAX_RAWMATERIALS, ctx->f);
|
|
|
|
|
|
|
|
if (size) {
|
|
|
|
node = xmlNewNode(xct->ns_atl, BAD_CAST "resources");
|
2011-03-07 08:02:35 +01:00
|
|
|
for (n = 0; n < size; ++n) {
|
|
|
|
if (result[n].number >= 0) {
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNodePtr child;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
2010-08-08 07:07:17 +02:00
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "resource"));
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
|
|
|
(xmlChar *) result[n].name);
|
|
|
|
if (result[n].level >= 0) {
|
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "level",
|
|
|
|
(xmlChar *) itoab(result[n].level, 10));
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNodeAddContent(child, (xmlChar *) itoab(result[n].number, 10));
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static xmlNodePtr xml_diplomacy(report_context * ctx, const struct ally *allies)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
xml_context *xct = (xml_context *) ctx->userdata;
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNodePtr child, node = xmlNewNode(xct->ns_atl, BAD_CAST "diplomacy");
|
2011-03-07 08:02:35 +01:00
|
|
|
const struct ally *sf;
|
|
|
|
|
|
|
|
for (sf = allies; sf; sf = sf->next) {
|
2010-08-08 07:07:17 +02:00
|
|
|
int i, status = sf->status;
|
2011-03-07 08:02:35 +01:00
|
|
|
for (i = 0; helpmodes[i].name; ++i) {
|
|
|
|
if (sf->faction && (status & helpmodes[i].status) == helpmodes[i].status) {
|
2010-08-08 07:07:17 +02:00
|
|
|
status -= helpmodes[i].status;
|
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "status"));
|
2011-03-07 08:02:35 +01:00
|
|
|
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);
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static xmlNodePtr xml_groups(report_context * ctx, const group * groups)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
xml_context *xct = (xml_context *) ctx->userdata;
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNodePtr child, node = xmlNewNode(xct->ns_atl, BAD_CAST "faction");
|
2011-03-07 08:02:35 +01:00
|
|
|
const group *g;
|
|
|
|
|
|
|
|
for (g = groups; g; g = g->next) {
|
|
|
|
const char *prefix = get_prefix(g->attribs);
|
2010-08-08 07:07:17 +02:00
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "group"));
|
|
|
|
xmlNewNsProp(child, xct->ns_xml, XML_XML_ID, xml_ref_group(g));
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewTextChild(child, xct->ns_atl, BAD_CAST "name",
|
|
|
|
(const xmlChar *)g->name);
|
2010-08-08 07:07:17 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
if (g->allies)
|
|
|
|
xmlAddChild(child, xml_diplomacy(ctx, g->allies));
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
if (prefix) {
|
|
|
|
child = xmlAddChild(child, xmlNewNode(xct->ns_atl, BAD_CAST "prefix"));
|
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", xml_ref_prefix(prefix));
|
|
|
|
}
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
2010-08-08 07:07:17 +02:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static xmlNodePtr xml_faction(report_context * ctx, faction * f)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
xml_context *xct = (xml_context *) ctx->userdata;
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNodePtr child, node = xmlNewNode(xct->ns_atl, BAD_CAST "faction");
|
|
|
|
|
|
|
|
/* TODO: alliance, locale */
|
|
|
|
|
|
|
|
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, xml_ref_faction(f));
|
|
|
|
xmlNewNsProp(node, xct->ns_atl, BAD_CAST "key", BAD_CAST itoa36(f->no));
|
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name", (const xmlChar *)f->name);
|
2011-03-07 08:02:35 +01:00
|
|
|
if (f->email)
|
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "email",
|
|
|
|
(const xmlChar *)f->email);
|
2010-08-08 07:07:17 +02:00
|
|
|
if (f->banner) {
|
2011-03-07 08:02:35 +01:00
|
|
|
child =
|
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text",
|
|
|
|
(const xmlChar *)f->banner);
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "public");
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
if (ctx->f == f) {
|
|
|
|
xmlAddChild(node, xml_link(ctx, BAD_CAST "race",
|
|
|
|
BAD_CAST f->race->_name[0]));
|
2010-08-08 07:07:17 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
if (f->items)
|
|
|
|
xmlAddChild(node, xml_inventory(ctx, f->items, NULL));
|
|
|
|
if (f->allies)
|
|
|
|
xmlAddChild(node, xml_diplomacy(ctx, f->allies));
|
|
|
|
if (f->groups)
|
|
|
|
xmlAddChild(node, xml_groups(ctx, f->groups));
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
/* TODO: age, options, score, prefix, magic, immigrants, heroes, nmr, groups */
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static xmlNodePtr
|
2011-03-07 08:02:35 +01:00
|
|
|
xml_building(report_context * ctx, seen_region * sr, const building * b,
|
|
|
|
const unit * owner)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
xml_context *xct = (xml_context *) ctx->userdata;
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "building");
|
|
|
|
xmlNodePtr child;
|
2011-03-07 08:02:35 +01:00
|
|
|
const char *bname, *billusion;
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, xml_ref_building(b));
|
|
|
|
xmlNewNsProp(node, xct->ns_atl, BAD_CAST "key", BAD_CAST itoa36(b->no));
|
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name", (const xmlChar *)b->name);
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "size",
|
|
|
|
(const xmlChar *)itoab(b->size, 10));
|
2010-08-08 07:07:17 +02:00
|
|
|
if (b->display && b->display[0]) {
|
2011-03-07 08:02:35 +01:00
|
|
|
child =
|
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text",
|
|
|
|
(const xmlChar *)b->display);
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "public");
|
|
|
|
}
|
|
|
|
if (b->besieged) {
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "siege",
|
|
|
|
(const xmlChar *)itoab(b->besieged, 10));
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
if (owner)
|
|
|
|
xmlAddChild(node, xml_link(ctx, BAD_CAST "owner", xml_ref_unit(owner)));
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
report_building(b, &bname, &billusion);
|
2011-03-07 08:02:35 +01:00
|
|
|
if (owner && owner->faction == ctx->f) {
|
2010-08-08 07:07:17 +02:00
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "type"));
|
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "true");
|
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (const xmlChar *)bname);
|
|
|
|
if (billusion) {
|
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "type"));
|
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "illusion");
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
|
|
|
(const xmlChar *)billusion);
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "type"));
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
|
|
|
(const xmlChar *)(billusion ? billusion : bname));
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static xmlNodePtr
|
2011-03-07 08:02:35 +01:00
|
|
|
xml_ship(report_context * ctx, const seen_region * sr, const ship * sh,
|
|
|
|
const unit * owner)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
xml_context *xct = (xml_context *) ctx->userdata;
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNodePtr child, node = xmlNewNode(xct->ns_atl, BAD_CAST "ship");
|
|
|
|
|
|
|
|
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, xml_ref_ship(sh));
|
|
|
|
xmlNewNsProp(node, xct->ns_atl, BAD_CAST "key", BAD_CAST itoa36(sh->no));
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name",
|
|
|
|
(const xmlChar *)sh->name);
|
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "size",
|
|
|
|
(const xmlChar *)itoab(sh->size, 10));
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
if (sh->damage) {
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "damage",
|
|
|
|
(const xmlChar *)itoab(sh->damage, 10));
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
if (fval(sr->r->terrain, SEA_REGION) && sh->coast != NODIRECTION) {
|
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "coast",
|
|
|
|
BAD_CAST directions[sh->coast]);
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "type"));
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
|
|
|
(const xmlChar *)sh->type->name[0]);
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
if (sh->display && sh->display[0]) {
|
2011-03-07 08:02:35 +01:00
|
|
|
child =
|
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text",
|
|
|
|
(const xmlChar *)sh->display);
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "public");
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
if (owner)
|
|
|
|
xmlAddChild(node, xml_link(ctx, BAD_CAST "owner", xml_ref_unit(owner)));
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
if ((owner && owner->faction == ctx->f) || omniscient(ctx->f)) {
|
|
|
|
int n = 0, p = 0;
|
|
|
|
getshipweight(sh, &n, &p);
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "cargo",
|
|
|
|
(const xmlChar *)itoab(n, 10));
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static xmlNodePtr xml_region(report_context * ctx, seen_region * sr)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
xml_context *xct = (xml_context *) ctx->userdata;
|
|
|
|
const region *r = sr->r;
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "region");
|
|
|
|
xmlNodePtr child;
|
|
|
|
int stealthmod = stealth_modifier(sr->mode);
|
2011-03-07 08:02:35 +01:00
|
|
|
unit *u;
|
|
|
|
ship *sh = r->ships;
|
|
|
|
building *b = r->buildings;
|
|
|
|
plane *pl = rplane(r);
|
2010-08-08 07:07:17 +02:00
|
|
|
int nx = r->x, ny = r->y;
|
|
|
|
|
|
|
|
pnormalize(&nx, &ny, pl);
|
|
|
|
adjust_coordinates(ctx->f, &nx, &ny, pl, r);
|
|
|
|
|
|
|
|
/* 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(nx));
|
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "y", xml_i(ny));
|
|
|
|
if (pl && pl->name) {
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "plane", (xmlChar *) pl->name);
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "terrain"));
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (xmlChar *) terrain_name(r));
|
2010-08-08 07:07:17 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
if (r->land != NULL) {
|
|
|
|
child =
|
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name",
|
|
|
|
(const xmlChar *)r->land->name);
|
2010-08-08 07:07:17 +02:00
|
|
|
if (r->land->items) {
|
|
|
|
xmlAddChild(node, xml_inventory(ctx, r->land->items, NULL));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (r->display && r->display[0]) {
|
2011-03-07 08:02:35 +01:00
|
|
|
child =
|
|
|
|
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text",
|
|
|
|
(const xmlChar *)r->display);
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "public");
|
|
|
|
}
|
|
|
|
child = xml_resources(ctx, sr);
|
2011-03-07 08:02:35 +01:00
|
|
|
if (child)
|
|
|
|
xmlAddChild(node, child);
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
child = xmlNewNode(xct->ns_atl, BAD_CAST "terrain");
|
2011-03-07 08:02:35 +01:00
|
|
|
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
|
|
|
(const xmlChar *)terrain_name(r));
|
2010-08-08 07:07:17 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
if (sr->mode > see_neighbour) {
|
2010-08-08 07:07:17 +02:00
|
|
|
/* report all units. they are pre-sorted in an efficient manner */
|
|
|
|
u = r->units;
|
|
|
|
while (b) {
|
2011-03-07 08:02:35 +01:00
|
|
|
while (b && (!u || u->building != b)) {
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlAddChild(node, xml_building(ctx, sr, b, NULL));
|
|
|
|
b = b->next;
|
|
|
|
}
|
|
|
|
if (b) {
|
|
|
|
child = xmlAddChild(node, xml_building(ctx, sr, b, u));
|
2011-03-07 08:02:35 +01:00
|
|
|
while (u && u->building == b) {
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlAddChild(child, xml_unit(ctx, u, sr->mode));
|
|
|
|
u = u->next;
|
|
|
|
}
|
|
|
|
b = b->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (u && !u->ship) {
|
2011-03-07 08:02:35 +01:00
|
|
|
if (stealthmod > INT_MIN) {
|
2010-08-08 07:07:17 +02:00
|
|
|
if (u->faction == ctx->f || cansee(ctx->f, r, u, stealthmod)) {
|
|
|
|
xmlAddChild(node, xml_unit(ctx, u, sr->mode));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
u = u->next;
|
|
|
|
}
|
|
|
|
while (sh) {
|
2011-03-07 08:02:35 +01:00
|
|
|
while (sh && (!u || u->ship != sh)) {
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlAddChild(node, xml_ship(ctx, sr, sh, NULL));
|
|
|
|
sh = sh->next;
|
|
|
|
}
|
|
|
|
if (sh) {
|
|
|
|
child = xmlAddChild(node, xml_ship(ctx, sr, sh, u));
|
2011-03-07 08:02:35 +01:00
|
|
|
while (u && u->ship == sh) {
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlAddChild(child, xml_unit(ctx, u, sr->mode));
|
|
|
|
u = u->next;
|
|
|
|
}
|
|
|
|
sh = sh->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static xmlNodePtr report_root(report_context * ctx)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
2011-02-25 07:29:21 +01:00
|
|
|
int qi;
|
2011-03-07 08:02:35 +01:00
|
|
|
quicklist *address;
|
|
|
|
region *r = ctx->first, *rend = ctx->last;
|
|
|
|
xml_context *xct = (xml_context *) ctx->userdata;
|
2010-08-08 07:07:17 +02:00
|
|
|
xmlNodePtr node, child, xmlReport = xmlNewNode(NULL, BAD_CAST "atlantis");
|
2011-03-07 08:02:35 +01:00
|
|
|
const char *mailto = locale_string(ctx->f->locale, "mailto");
|
|
|
|
const char *mailcmd = locale_string(ctx->f->locale, "mailcmd");
|
2010-08-08 07:07:17 +02:00
|
|
|
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) {
|
2014-03-15 20:35:20 +01:00
|
|
|
_snprintf(zText, sizeof(zText), "mailto:%s?subject=%s", mailto, mailcmd);
|
2010-08-08 07:07:17 +02:00
|
|
|
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);
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
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 (qi = 0, address = ctx->addresses; address; ql_advance(&address, &qi, 1)) {
|
|
|
|
faction *f = (faction *) ql_get(address, qi);
|
2011-02-25 07:29:21 +01:00
|
|
|
xmlAddChild(xmlReport, xml_faction(ctx, f));
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
for (; r != rend; r = r->next) {
|
|
|
|
seen_region *sr = find_seen(ctx->seen, r);
|
|
|
|
if (sr != NULL)
|
|
|
|
xmlAddChild(xmlReport, xml_region(ctx, sr));
|
2010-08-08 07:07:17 +02:00
|
|
|
}
|
|
|
|
return xmlReport;
|
2011-03-07 17:26:50 +01:00
|
|
|
}
|
2010-08-08 07:07:17 +02:00
|
|
|
|
|
|
|
/* main function of the xmlreport. creates the header and traverses all regions */
|
|
|
|
static int
|
2011-03-07 08:02:35 +01:00
|
|
|
report_xml(const char *filename, report_context * ctx, const char *encoding)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
|
|
|
xml_context xct;
|
|
|
|
xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
|
|
|
|
|
|
|
|
xct.doc = doc;
|
2011-03-07 08:02:35 +01:00
|
|
|
assert(ctx->userdata == NULL);
|
2010-08-08 07:07:17 +02:00
|
|
|
ctx->userdata = &xct;
|
|
|
|
|
|
|
|
xmlDocSetRootElement(doc, report_root(ctx));
|
|
|
|
xmlKeepBlanksDefault(0);
|
|
|
|
xmlSaveFormatFileEnc(filename, doc, "utf-8", 1);
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
|
|
|
|
ctx->userdata = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
void register_xr(void)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
2011-03-07 08:02:35 +01:00
|
|
|
register_reporttype("xml", &report_xml, 1 << O_XML);
|
2010-08-08 07:07:17 +02:00
|
|
|
#ifdef USE_ICONV
|
|
|
|
utf8 = iconv_open("UTF-8", "");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
void xmlreport_cleanup(void)
|
2010-08-08 07:07:17 +02:00
|
|
|
{
|
|
|
|
#ifdef USE_ICONV
|
|
|
|
iconv_close(utf8);
|
|
|
|
#endif
|
|
|
|
}
|