xmlreport (WIP):

- buildings are done
- unit.faction.rel
This commit is contained in:
Enno Rehling 2008-06-07 09:55:57 +00:00
parent 6e5d930778
commit 8b242c0b33
6 changed files with 157 additions and 71 deletions

View file

@ -177,7 +177,7 @@ print_items(FILE * F, item * items, const struct locale * lang)
}
static void
print_curses(FILE * F, const faction * viewer, const void * obj, typ_t typ)
cr_output_curses(FILE * F, const faction * viewer, const void * obj, typ_t typ)
{
boolean header = false;
attrib *a = NULL;
@ -563,26 +563,19 @@ cr_output_messages(FILE * F, message_list *msgs, faction * f)
static void
cr_output_building(FILE * F, building * b, const unit * owner, int fno, faction *f)
{
const char * bname;
static const struct building_type * bt_illusion;
const building_type * type = b->type;
if (!bt_illusion) bt_illusion = bt_find("illusion");
const char * bname, * billusion;
fprintf(F, "BURG %d\n", b->no);
if (b->type==bt_illusion) {
const attrib * a = a_findc(b->attribs, &at_icastle);
if (a!=NULL) {
type = ((icastle_data*)a->data.v)->type;
}
bname = buildingtype(b->type, b, b->size);
if (owner!=NULL && owner->faction==f) {
report_building(b, &bname, &billusion);
if (billusion) {
fprintf(F, "\"%s\";Typ\n", add_translation(billusion, LOC(f->locale, billusion)));
if (owner && owner->faction==f) {
fprintf(F, "\"%s\";wahrerTyp\n", add_translation(bname, LOC(f->locale, bname)));
}
} else {
fprintf(F, "\"%s\";Typ\n", add_translation(bname, LOC(f->locale, bname)));
}
bname = buildingtype(type, b, b->size);
fprintf(F, "\"%s\";Typ\n", add_translation(bname, LOC(f->locale, bname)));
fprintf(F, "\"%s\";Name\n", b->name);
if (b->display && b->display[0])
fprintf(F, "\"%s\";Beschr\n", b->display);
@ -594,7 +587,7 @@ cr_output_building(FILE * F, building * b, const unit * owner, int fno, faction
fprintf(F, "%d;Partei\n", fno);
if (b->besieged)
fprintf(F, "%d;Belagerer\n", b->besieged);
print_curses(F, f, b, TYP_BUILDING);
cr_output_curses(F, f, b, TYP_BUILDING);
}
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
@ -637,7 +630,7 @@ cr_output_ship(FILE * F, const ship * sh, const unit * u, int fcaptain, const fa
if (w != NODIRECTION)
fprintf(F, "%d;Kueste\n", w);
print_curses(F, f, sh, TYP_SHIP);
cr_output_curses(F, f, sh, TYP_SHIP);
}
static void
@ -913,7 +906,7 @@ cr_output_unit(FILE * F, const region * r,
fprintf(F, "%d;%s\n", in, add_translation(ic, locale_string(f->locale, ic)));
}
print_curses(F, f, u, TYP_UNIT);
cr_output_curses(F, f, u, TYP_UNIT);
}
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
@ -1218,7 +1211,7 @@ cr_output_region(FILE * F, report_context * ctx, seen_region * sr)
if (r->land) {
print_items(F, r->land->items, f->locale);
}
print_curses(F, f, r, TYP_REGION);
cr_output_curses(F, f, r, TYP_REGION);
cr_borders(ctx->seen, r, f, sr->mode, F);
if (sr->mode==see_unit && r->planep==get_astralplane() && !is_cursed(r->attribs, C_ASTRALBLOCK, 0))
{

View file

@ -214,7 +214,7 @@ rparagraph(FILE *F, const char *str, ptrdiff_t indent, int hanging_indent, char
}
static void
report_spell(FILE * F, spell *sp, const struct locale * lang)
nr_spell(FILE * F, spell *sp, const struct locale * lang)
{
int bytes, k, itemanz, costtyp;
int dh = 0;
@ -535,7 +535,7 @@ hat_in_region(item_t it, region * r, faction * f)
}
static void
print_curses(FILE *F, const faction *viewer, const void * obj, typ_t typ, int indent)
nr_curses(FILE *F, const faction *viewer, const void * obj, typ_t typ, int indent)
{
attrib *a = NULL;
int self = 0;
@ -651,7 +651,7 @@ rps_nowrap(FILE * F, const char *s)
}
static void
report_unit(FILE * F, const faction * f, const unit * u, int indent, int mode)
nr_unit(FILE * F, const faction * f, const unit * u, int indent, int mode)
{
attrib *a_otherfaction;
char marker;
@ -686,7 +686,7 @@ report_unit(FILE * F, const faction * f, const unit * u, int indent, int mode)
rparagraph(F, buf, indent, 0, marker);
if (!isbattle) {
print_curses(F, f, u, TYP_UNIT, indent);
nr_curses(F, f, u, TYP_UNIT, indent);
}
}
@ -1105,7 +1105,7 @@ describe(FILE * F, const seen_region * sr, faction * f)
n = 0;
/* Wirkungen permanenter Sprüche */
print_curses(F, f, r, TYP_REGION,0);
nr_curses(F, f, r, TYP_REGION,0);
/* Produktionsreduktion */
a = a_find(r->attribs, &at_reduceproduction);
@ -1709,7 +1709,7 @@ list_address(FILE * F, const faction * uf, const faction_list * seenfactions)
}
static void
report_ship(FILE * F, const seen_region * sr, const ship * sh, const faction * f, const unit * captain)
nr_ship(FILE * F, const seen_region * sr, const ship * sh, const faction * f, const unit * captain)
{
const region * r = sr->r;
char buffer[8192], * bufp = buffer;
@ -1766,11 +1766,11 @@ report_ship(FILE * F, const seen_region * sr, const ship * sh, const faction * f
*bufp = 0;
rparagraph(F, buffer, 2, 0, 0);
print_curses(F, f, sh, TYP_SHIP, 4);
nr_curses(F, f, sh, TYP_SHIP, 4);
}
static void
report_building(FILE *F, const seen_region * sr, const building * b, const faction * f)
nr_building(FILE *F, const seen_region * sr, const building * b, const faction * f)
{
region * r = sr->r;
int i, bytes;
@ -1897,7 +1897,7 @@ report_building(FILE *F, const seen_region * sr, const building * b, const facti
if (sr->mode<see_lighthouse) return;
print_curses(F, f, b, TYP_BUILDING, 4);
nr_curses(F, f, b, TYP_BUILDING, 4);
}
int
@ -2114,7 +2114,7 @@ report_plaintext(const char * filename, report_context * ctx, const char * chars
centre(F, LOC(f->locale, "section_newspells"), true);
while (a && a->type==&at_reportspell) {
spell *sp = (spell *)a->data.v;
report_spell(F, sp, f->locale);
nr_spell(F, sp, f->locale);
a = a->next;
}
}
@ -2228,13 +2228,13 @@ report_plaintext(const char * filename, report_context * ctx, const char * chars
u = r->units;
while (b) {
while (b && (!u || u->building!=b)) {
report_building(F, sr, b, f);
nr_building(F, sr, b, f);
b = b->next;
}
if (b) {
report_building(F, sr, b, f);
nr_building(F, sr, b, f);
while (u && u->building==b) {
report_unit(F, f, u, 6, sr->mode);
nr_unit(F, f, u, 6, sr->mode);
u = u->next;
}
b = b->next;
@ -2243,20 +2243,20 @@ report_plaintext(const char * filename, report_context * ctx, const char * chars
while (u && !u->ship) {
if (stealthmod>INT_MIN) {
if (u->faction == f || cansee(f, r, u, stealthmod)) {
report_unit(F, f, u, 4, sr->mode);
nr_unit(F, f, u, 4, sr->mode);
}
}
u = u->next;
}
while (sh) {
while (sh && (!u || u->ship!=sh)) {
report_ship(F, sr, sh, f, NULL);
nr_ship(F, sr, sh, f, NULL);
sh = sh->next;
}
if (sh) {
report_ship(F, sr, sh, f, u);
nr_ship(F, sr, sh, f, u);
while (u && u->ship==sh) {
report_unit(F, f, u, 6, sr->mode);
nr_unit(F, f, u, 6, sr->mode);
u = u->next;
}
sh = sh->next;

View file

@ -113,8 +113,48 @@ xml_i(double number)
return (const xmlChar *)buffer;
}
static const xmlChar *
xml_ref_unit(const unit * u)
{
static char idbuf[20];
snprintf(idbuf, sizeof(idbuf), "unit_%d", u->no);
return (const xmlChar *)idbuf;
}
static const xmlChar *
xml_ref_faction(const faction * f)
{
static char idbuf[20];
snprintf(idbuf, sizeof(idbuf), "fctn_%d", f->no);
return (const xmlChar *)idbuf;
}
static const xmlChar *
xml_ref_building(const building * b)
{
static char idbuf[20];
snprintf(idbuf, sizeof(idbuf), "bldg_%d", b->no);
return (const xmlChar *)idbuf;
}
static const xmlChar *
xml_ref_ship(const ship * sh)
{
static char idbuf[20];
snprintf(idbuf, sizeof(idbuf), "shp_%d", sh->no);
return (const xmlChar *)idbuf;
}
static const xmlChar *
xml_ref_region(const region * r)
{
static char idbuf[20];
snprintf(idbuf, sizeof(idbuf), "rgn_%d", r->uid);
return (const xmlChar *)idbuf;
}
static xmlNodePtr
report_inventory(report_context * ctx, item * items, unit * u)
xml_inventory(report_context * ctx, item * items, unit * u)
{
xml_context* xct = (xml_context*)ctx->userdata;
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "items");
@ -138,19 +178,22 @@ xml_unit(report_context * ctx, unit * u, int mode)
{
xml_context* xct = (xml_context*)ctx->userdata;
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "unit");
char idbuffer[20];
static const curse_type * itemcloak_ct = 0;
static boolean init = false;
xmlNodePtr child;
snprintf(idbuffer, sizeof(idbuffer), "unit_%d", u->no);
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, (xmlChar *)idbuffer);
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);
snprintf(idbuffer, sizeof(idbuffer), "faction_%d", u->faction->no);
child = xmlNewNode(xct->ns_atl, BAD_CAST "faction");
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (xmlChar *)idbuffer);
if (ctx->f == u->faction || omniscient(ctx->f)) {
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "true");
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", xml_ref_faction(u->faction));
} else {
const faction * sf = visible_faction(ctx->f, u);
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", xml_ref_faction(sf));
}
xmlAddChild(node, child);
if (!init) {
@ -184,7 +227,7 @@ xml_unit(report_context * ctx, unit * u, int mode)
}
if (show) {
xmlAddChild(node, report_inventory(ctx, show, u));
xmlAddChild(node, xml_inventory(ctx, show, u));
}
}
@ -192,7 +235,7 @@ xml_unit(report_context * ctx, unit * u, int mode)
}
static xmlNodePtr
report_link(report_context * ctx, const xmlChar * role, const xmlChar * ref)
xml_link(report_context * ctx, const xmlChar * role, const xmlChar * ref)
{
xml_context* xct = (xml_context*)ctx->userdata;
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "link");
@ -228,35 +271,59 @@ xml_resources(report_context * ctx, const seen_region * sr)
}
static xmlNodePtr
report_faction(report_context * ctx, faction * f)
xml_faction(report_context * ctx, faction * f)
{
xml_context* xct = (xml_context*)ctx->userdata;
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "faction");
char faction_id[20];
snprintf(faction_id, sizeof(faction_id), "faction_%d", f->no);
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, (xmlChar *)faction_id);
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);
if (ctx->f==f) {
xmlAddChild(node, report_link(ctx, BAD_CAST "race", BAD_CAST f->race->_name[0]));
if (f->items) xmlAddChild(node, report_inventory(ctx, f->items, NULL));
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));
}
return node;
}
static xmlNodePtr
xml_building(report_context * ctx, seen_region * sr, building * b)
xml_building(report_context * ctx, seen_region * sr, const building * b, const unit * owner)
{
xml_context* xct = (xml_context*)ctx->userdata;
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "building");
char idbuf[20];
xmlNodePtr child;
const char * bname, * billusion;
snprintf(idbuf, sizeof(idbuf), "bldg_%d", b->no);
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, (xmlChar *)idbuf);
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);
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "size", (const xmlChar *)itoab(b->size, 10));
if (b->display && b->display[0]) {
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "descr", (const xmlChar *)b->display);
}
if (b->besieged) {
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "siege", (const xmlChar *)itoab(b->besieged, 10));
}
if (owner) xml_link(ctx, BAD_CAST "owner", xml_ref_unit(owner));
report_building(b, &bname, &billusion);
if (owner && owner->faction==ctx->f) {
child = 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);
xmlAddChild(node, child);
if (billusion) {
child = xmlNewNode(xct->ns_atl, BAD_CAST "type");
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "illusion");
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (const xmlChar *)billusion);
xmlAddChild(node, child);
}
} else {
child = xmlNewNode(xct->ns_atl, BAD_CAST "type");
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (const xmlChar *)(billusion?billusion:bname));
xmlAddChild(node, child);
}
return node;
}
@ -266,31 +333,30 @@ xml_ship(report_context * ctx, seen_region * sr, ship * sh)
{
xml_context* xct = (xml_context*)ctx->userdata;
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "ship");
char idbuf[20];
snprintf(idbuf, sizeof(idbuf), "ship_%d", sh->no);
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, (xmlChar *)idbuf);
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));
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name", (const xmlChar *)sh->name);
if (sh->display && sh->display[0]) {
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "descr", (const xmlChar *)sh->display);
}
return node;
}
static xmlNodePtr
report_region(report_context * ctx, seen_region * sr)
xml_region(report_context * ctx, seen_region * sr)
{
xml_context* xct = (xml_context*)ctx->userdata;
const region * r = sr->r;
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "region");
xmlNodePtr child;
char region_id[20];
int stealthmod = stealth_modifier(sr->mode);
unit * u;
ship * sh = r->ships;
building * b = r->buildings;
sprintf(region_id, "region_%u", r->uid);
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, BAD_CAST region_id);
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, xml_ref_region(r));
child = xmlNewNode(xct->ns_atl, BAD_CAST "coordinate");
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "x", xml_i(region_x(r, ctx->f)));
@ -307,7 +373,7 @@ report_region(report_context * ctx, seen_region * sr)
if (r->land!=NULL) {
child = xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name", (const xmlChar *)r->land->name);
if (r->land->items) {
xmlAddChild(node, report_inventory(ctx, r->land->items, NULL));
xmlAddChild(node, xml_inventory(ctx, r->land->items, NULL));
}
}
xmlAddChild(node, xml_resources(ctx, sr));
@ -325,12 +391,12 @@ report_region(report_context * ctx, seen_region * sr)
u = r->units;
while (b) {
while (b && (!u || u->building!=b)) {
child = xml_building(ctx, sr, b);
child = xml_building(ctx, sr, b, NULL);
xmlAddChild(node, child);
b = b->next;
}
if (b) {
child = xml_building(ctx, sr, b);
child = xml_building(ctx, sr, b, u);
xmlAddChild(node, child);
while (u && u->building==b) {
xmlAddChild(child, xml_unit(ctx, u, sr->mode));
@ -379,12 +445,12 @@ report_root(report_context * ctx)
xmlSetNs(xmlReport, xct->ns_atl);
for (address=ctx->addresses;address;address=address->next) {
xmlAddChild(xmlReport, report_faction(ctx, address->data));
xmlAddChild(xmlReport, xml_faction(ctx, address->data));
}
for (;r!=rend;r=r->next) {
seen_region * sr = find_seen(ctx->seen, r);
if (sr!=NULL) xmlAddChild(xmlReport, report_region(ctx, sr));
if (sr!=NULL) xmlAddChild(xmlReport, xml_region(ctx, sr));
}
return xmlReport;
};

View file

@ -295,6 +295,32 @@ report_resource(resource_report * result, const char * name, int number, int lev
result->level = level;
}
void
report_building(const struct building * b, const char ** name, const char ** illusion)
{
static int init;
static const struct building_type * bt_illusion;
if (name) {
*name = buildingtype(b->type, b, b->size);
}
if (illusion) {
*illusion = NULL;
if (!init) {
bt_illusion = bt_find("illusion");
init = 1;
}
if (bt_illusion && b->type==bt_illusion) {
const attrib * a = a_findc(b->attribs, &at_icastle);
if (a!=NULL) {
icastle_data * icastle = (icastle_data*)a->data.v;
*illusion = buildingtype(icastle->type, b, b->size);
}
}
}
}
int
report_resources(const seen_region * sr, resource_report * result, int size, const faction * viewer)
{

View file

@ -123,6 +123,7 @@ extern const char * report_kampfstatus(const struct unit * u, const struct local
int report_resources(const struct seen_region * sr, struct resource_report * result, int size, const struct faction * viewer);
int report_items(const struct item * items, struct item * result, int size, const struct unit * owner, const struct faction * viewer);
void report_item(const struct unit * owner, const struct item * i, const struct faction * viewer, const char ** name, const char ** basename, int * number, boolean singular);
void report_building(const struct building * b, const char ** btype, const char ** billusion);
extern size_t f_regionid(const struct region * r, const struct faction * f, char * buffer, size_t size);

View file

@ -108,7 +108,7 @@ attrib_type at_wdwpyramid = {
/* ----------------------------------------------------------------------- */
static void
report_spell(unit * mage, region * r, message * msg)
nr_spell(unit * mage, region * r, message * msg)
{
r_addmessage(r, NULL, msg);
if (mage && mage->region!=r) {
@ -1977,7 +1977,7 @@ sp_holyground(castorder *co)
double power = co->force;
curse * c;
message * msg = msg_message("sp_holyground_effect", "mage region", mage, r);
report_spell(mage, r, msg);
nr_spell(mage, r, msg);
msg_release(msg);
if (!ctype) ctype = ct_find("holyground");
@ -2082,7 +2082,7 @@ sp_drought(castorder *co)
/* melden, 1x pro Partei */
msg = msg_message("sp_drought_effect", "mage region", mage, r);
report_spell(mage, r, msg);
nr_spell(mage, r, msg);
msg_release(msg);
/* Wenn schon Duerre herrscht, dann setzen wir nur den Power-Level
@ -4015,7 +4015,7 @@ sp_raisepeasantmob(castorder *co)
create_curse(mage, &r->attribs, ct_find("riotzone"), cast_level, duration, anteil, 0);
msg = msg_message("sp_raisepeasantmob_effect", "mage region", mage, r);
report_spell(mage, r, msg);
nr_spell(mage, r, msg);
msg_release(msg);
return cast_level;
@ -4802,7 +4802,7 @@ sp_icastle(castorder *co)
co->order));
msg = msg_message("sp_icastle_effect", "region", r);
report_spell(mage, r, msg);
nr_spell(mage, r, msg);
msg_release(msg);
return cast_level;