xmlreport:

- coordinates
- terrain names
This commit is contained in:
Enno Rehling 2008-06-06 23:35:37 +00:00
parent b5bffaf75e
commit 6e5d930778
2 changed files with 89 additions and 5 deletions

View File

@ -246,6 +246,36 @@ report_faction(report_context * ctx, faction * f)
return node; return node;
} }
static xmlNodePtr
xml_building(report_context * ctx, seen_region * sr, building * b)
{
xml_context* xct = (xml_context*)ctx->userdata;
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "building");
char idbuf[20];
snprintf(idbuf, sizeof(idbuf), "bldg_%d", b->no);
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, (xmlChar *)idbuf);
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);
return node;
}
static xmlNodePtr
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_atl, BAD_CAST "key", BAD_CAST itoa36(sh->no));
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name", (const xmlChar *)sh->name);
return node;
}
static xmlNodePtr static xmlNodePtr
report_region(report_context * ctx, seen_region * sr) report_region(report_context * ctx, seen_region * sr)
{ {
@ -256,20 +286,22 @@ report_region(report_context * ctx, seen_region * sr)
char region_id[20]; char region_id[20];
int stealthmod = stealth_modifier(sr->mode); int stealthmod = stealth_modifier(sr->mode);
unit * u; unit * u;
ship * sh = r->ships;
building * b = r->buildings;
sprintf(region_id, "region_%u", r->uid); 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, BAD_CAST region_id);
child = xmlNewNode(xct->ns_atl, BAD_CAST "coordinate"); child = xmlNewNode(xct->ns_atl, BAD_CAST "coordinate");
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "x", xml_i(r->x)); 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(r->y)); xmlNewNsProp(child, xct->ns_atl, BAD_CAST "y", xml_i(region_y(r, ctx->f)));
if (r->planep) { if (r->planep) {
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "plane", xml_s(r->planep->name)); xmlNewNsProp(child, xct->ns_atl, BAD_CAST "plane", xml_s(r->planep->name));
} }
xmlAddChild(node, child); xmlAddChild(node, child);
child = xmlNewNode(xct->ns_atl, BAD_CAST "terrain"); child = xmlNewNode(xct->ns_atl, BAD_CAST "terrain");
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (xmlChar *)r->terrain->_name); xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (xmlChar *)terrain_name(r));
xmlAddChild(node, child); xmlAddChild(node, child);
if (r->land!=NULL) { if (r->land!=NULL) {
@ -288,6 +320,49 @@ report_region(report_context * ctx, seen_region * sr)
xmlAddChild(node, xml_unit(ctx, u, sr->mode)); xmlAddChild(node, xml_unit(ctx, u, sr->mode));
} }
} }
/* report all units. they are pre-sorted in an efficient manner */
u = r->units;
while (b) {
while (b && (!u || u->building!=b)) {
child = xml_building(ctx, sr, b);
xmlAddChild(node, child);
b = b->next;
}
if (b) {
child = xml_building(ctx, sr, b);
xmlAddChild(node, child);
while (u && u->building==b) {
xmlAddChild(child, xml_unit(ctx, u, sr->mode));
u = u->next;
}
b = b->next;
}
}
while (u && !u->ship) {
if (stealthmod>INT_MIN) {
if (u->faction == ctx->f || cansee(ctx->f, r, u, stealthmod)) {
xmlAddChild(node, xml_unit(ctx, u, sr->mode));
}
}
u = u->next;
}
while (sh) {
while (sh && (!u || u->ship!=sh)) {
child = xml_ship(ctx, sr, sh);
xmlAddChild(node, child);
sh = sh->next;
}
if (sh) {
child = xml_ship(ctx, sr, sh);
xmlAddChild(node, child);
while (u && u->ship==sh) {
xmlAddChild(child, xml_unit(ctx, u, sr->mode));
u = u->next;
}
sh = sh->next;
}
}
return node; return node;
} }

View File

@ -116,7 +116,15 @@ end
function test_hse() function test_hse()
read_game("50.dat", "binary") read_game("50.dat", "binary")
f = get_faction(atoi36("8h7f")) f = get_faction(atoi36("7scs"))
f.options = f.options + 8192
init_reports()
write_report(f)
end
function test_xml()
read_game("572.dat", "binary")
f = get_faction(atoi36("ioen"))
f.options = f.options + 8192 f.options = f.options + 8192
init_reports() init_reports()
write_report(f) write_report(f)
@ -202,7 +210,8 @@ run_scripts()
-- test_free() -- test_free()
-- test_bmark() -- test_bmark()
-- test_realloc() -- test_realloc()
test_hse() test_xml()
-- test_hse()
-- test_reorder() -- test_reorder()
-- test_tunnels() -- test_tunnels()
-- test_md5() -- test_md5()