summary refs log tree commit diff stats
path: root/tools/mapedit/src/world.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mapedit/src/world.cpp')
-rw-r--r--tools/mapedit/src/world.cpp397
1 files changed, 150 insertions, 247 deletions
diff --git a/tools/mapedit/src/world.cpp b/tools/mapedit/src/world.cpp index 043cf8a..01225cf 100644 --- a/tools/mapedit/src/world.cpp +++ b/tools/mapedit/src/world.cpp
@@ -36,43 +36,43 @@ World::World(std::string filename)
36 throw MapLoadException(filename); 36 throw MapLoadException(filename);
37 } 37 }
38 38
39 xmlChar* nextmapKey = xmlGetProp(top, (xmlChar*) "nextmap");
40 if (nextmapKey != 0)
41 {
42 nextMapID = atoi((char*) nextmapKey);
43 }
44 xmlFree(nextmapKey);
45
46 xmlChar* lastmapKey = xmlGetProp(top, (xmlChar*) "lastmap");
47 if (lastmapKey != 0)
48 {
49 lastmap = atoi((char*) lastmapKey);
50 }
51 xmlFree(lastmapKey);
52
53 xmlChar* startxKey = xmlGetProp(top, (xmlChar*) "startx");
54 if (startxKey == 0) throw MapLoadException(filename);
55 startingPosition.first = atoi((char*) startxKey);
56 xmlFree(startxKey);
57
58 xmlChar* startyKey = xmlGetProp(top, (xmlChar*) "starty");
59 if (startyKey == 0) throw MapLoadException(filename);
60 startingPosition.second = atoi((char*) startyKey);
61 xmlFree(startyKey);
62
63 xmlChar* startmapKey = xmlGetProp(top, (xmlChar*) "startmap");
64 if (startxKey == 0) throw MapLoadException(filename);
65 startingMap = atoi((char*) startmapKey);
66 xmlFree(startmapKey);
67
39 for (xmlNodePtr node = top->xmlChildrenNode; node != NULL; node = node->next) 68 for (xmlNodePtr node = top->xmlChildrenNode; node != NULL; node = node->next)
40 { 69 {
41 if (!xmlStrcmp(node->name, (const xmlChar*) "nextmapid")) 70 if (!xmlStrcmp(node->name, (const xmlChar*) "root"))
42 {
43 xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
44 if (key != 0)
45 {
46 nextMapID = atoi((char*) key);
47 }
48 xmlFree(key);
49 } else if (!xmlStrcmp(node->name, (const xmlChar*) "lastmap"))
50 { 71 {
51 xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1); 72 xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
52 if (key != 0) 73 if (key == 0) throw MapLoadException(filename);
53 { 74 rootChildren.push_back(atoi((char*) key));
54 lastmap = atoi((char*) key);
55 }
56 xmlFree(key); 75 xmlFree(key);
57 } else if (!xmlStrcmp(node->name, (const xmlChar*) "root"))
58 {
59 xmlChar* key = xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
60 if (key != 0)
61 {
62 rootChildren.push_back(atoi((char*) key));
63 }
64 xmlFree(key);
65 } else if (!xmlStrcmp(node->name, (const xmlChar*) "startpos"))
66 {
67 xmlChar* idKey = xmlGetProp(node, (xmlChar*) "id");
68 if (idKey == 0) throw MapLoadException(filename);
69 startingMap = atoi((char*) idKey);
70 xmlFree(idKey);
71
72 xmlChar* posKey = xmlGetProp(node, (xmlChar*) "pos");
73 if (posKey == 0) throw MapLoadException(filename);
74 sscanf((char*) posKey, "%d,%d", &startingPosition.first, &startingPosition.second);
75 xmlFree(posKey);
76 } else if (!xmlStrcmp(node->name, (const xmlChar*) "map")) 76 } else if (!xmlStrcmp(node->name, (const xmlChar*) "map"))
77 { 77 {
78 xmlChar* idKey = xmlGetProp(node, (xmlChar*) "id"); 78 xmlChar* idKey = xmlGetProp(node, (xmlChar*) "id");
@@ -82,18 +82,21 @@ World::World(std::string filename)
82 82
83 auto map = std::make_shared<Map>(id, this); 83 auto map = std::make_shared<Map>(id, this);
84 84
85 xmlChar* expandKey = xmlGetProp(node, (xmlChar*) "expanded");
86 if ((expandKey != 0) && (!xmlStrcmp(expandKey, (const xmlChar*) "true")))
87 {
88 map->setExpanded(true);
89 }
90 xmlFree(expandKey);
91
92 xmlChar* titleKey = xmlGetProp(node, (xmlChar*) "title");
93 if (titleKey == 0) throw MapLoadException(filename);
94 map->setTitle((char*) titleKey, false);
95 xmlFree(titleKey);
96
85 for (xmlNodePtr mapNode = node->xmlChildrenNode; mapNode != NULL; mapNode = mapNode->next) 97 for (xmlNodePtr mapNode = node->xmlChildrenNode; mapNode != NULL; mapNode = mapNode->next)
86 { 98 {
87 if (!xmlStrcmp(mapNode->name, (const xmlChar*) "name")) 99 if (!xmlStrcmp(mapNode->name, (const xmlChar*) "environment"))
88 {
89 xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1);
90 if (key != 0)
91 {
92 map->setTitle((char*) key, false);
93 }
94
95 xmlFree(key);
96 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "environment"))
97 { 100 {
98 xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1); 101 xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1);
99 int* mapdata = (int*) malloc(MAP_WIDTH*MAP_HEIGHT*sizeof(int)); 102 int* mapdata = (int*) malloc(MAP_WIDTH*MAP_HEIGHT*sizeof(int));
@@ -104,88 +107,50 @@ World::World(std::string filename)
104 } 107 }
105 map->setMapdata(mapdata, false); 108 map->setMapdata(mapdata, false);
106 xmlFree(key); 109 xmlFree(key);
107 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "leftmap")) 110 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "entity"))
108 { 111 {
109 xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type"); 112 auto data = std::make_shared<MapObjectEntry>();
110 if (typeKey == 0) throw MapLoadException(filename);
111 map->setLeftMoveType(Map::moveTypeForShort((char*) typeKey), false);
112 xmlFree(typeKey);
113 113
114 if (Map::moveTypeTakesMap(map->getLeftMoveType())) 114 xmlChar* typeKey = xmlGetProp(mapNode, (const xmlChar*) "type");
115 {
116 xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map");
117 if (idKey == 0) throw MapLoadException(filename);
118 map->setLeftMoveMapID(atoi((char*) idKey), false);
119 xmlFree(idKey);
120 }
121 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "rightmap"))
122 {
123 xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type");
124 if (typeKey == 0) throw MapLoadException(filename); 115 if (typeKey == 0) throw MapLoadException(filename);
125 map->setRightMoveType(Map::moveTypeForShort((char*) typeKey), false); 116 data->object = MapObject::getAllObjects().at((char*) typeKey).get();
126 xmlFree(typeKey); 117 xmlFree(typeKey);
127 118
128 if (Map::moveTypeTakesMap(map->getRightMoveType())) 119 xmlChar* xKey = xmlGetProp(mapNode, (const xmlChar*) "x");
129 { 120 if (xKey == 0) throw MapLoadException(filename);
130 xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map"); 121 data->position.first = atoi((char*) xKey);
131 if (idKey == 0) throw MapLoadException(filename); 122 xmlFree(xKey);
132 map->setRightMoveMapID(atoi((char*) idKey), false);
133 xmlFree(idKey);
134 }
135 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "upmap"))
136 {
137 xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type");
138 if (typeKey == 0) throw MapLoadException(filename);
139 map->setUpMoveType(Map::moveTypeForShort((char*) typeKey), false);
140 xmlFree(typeKey);
141 123
142 if (Map::moveTypeTakesMap(map->getUpMoveType())) 124 xmlChar* yKey = xmlGetProp(mapNode, (const xmlChar*) "y");
143 { 125 if (yKey == 0) throw MapLoadException(filename);
144 xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map"); 126 data->position.second = atoi((char*) yKey);
145 if (idKey == 0) throw MapLoadException(filename); 127 xmlFree(yKey);
146 map->setUpMoveMapID(atoi((char*) idKey), false); 128
147 xmlFree(idKey); 129 map->addObject(data, false);
148 } 130 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "adjacent"))
149 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "downmap"))
150 { 131 {
151 xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type"); 132 Map::MoveDir direction;
133 Map::MoveType moveType;
134 int mapId = 0;
135
136 xmlChar* dirKey = xmlGetProp(mapNode, (const xmlChar*) "dir");
137 if (dirKey == 0) throw MapLoadException(filename);
138 direction = Map::moveDirForShort((char*) dirKey);
139 xmlFree(dirKey);
140
141 xmlChar* typeKey = xmlGetProp(mapNode, (const xmlChar*) "type");
152 if (typeKey == 0) throw MapLoadException(filename); 142 if (typeKey == 0) throw MapLoadException(filename);
153 map->setDownMoveType(Map::moveTypeForShort((char*) typeKey), false); 143 moveType = Map::moveTypeForShort((char*) typeKey);
154 xmlFree(typeKey); 144 xmlFree(typeKey);
155 145
156 if (Map::moveTypeTakesMap(map->getDownMoveType())) 146 xmlChar* mapIdKey = xmlGetProp(mapNode, (const xmlChar*) "map");
147 if (mapIdKey != 0)
157 { 148 {
158 xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map"); 149 mapId = atoi((char*) mapIdKey);
159 if (idKey == 0) throw MapLoadException(filename);
160 map->setDownMoveMapID(atoi((char*) idKey), false);
161 xmlFree(idKey);
162 } 150 }
163 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "entities")) 151 xmlFree(mapIdKey);
164 {
165 for (xmlNodePtr entityNode = mapNode->xmlChildrenNode; entityNode != NULL; entityNode = entityNode->next)
166 {
167 if (!xmlStrcmp(entityNode->name, (const xmlChar*) "entity"))
168 {
169 auto data = std::make_shared<MapObjectEntry>();
170 152
171 for (xmlNodePtr entityDataNode = entityNode->xmlChildrenNode; entityDataNode != NULL; entityDataNode = entityDataNode->next) 153 map->setAdjacent(direction, moveType, mapId, false);
172 {
173 if (!xmlStrcmp(entityDataNode->name, (const xmlChar*) "entity-type"))
174 {
175 xmlChar* key = xmlNodeListGetString(doc, entityDataNode->xmlChildrenNode, 1);
176 data->object = MapObject::getAllObjects().at((char*) key).get();
177 xmlFree(key);
178 } else if (!xmlStrcmp(entityDataNode->name, (const xmlChar*) "entity-position"))
179 {
180 xmlChar* key = xmlNodeListGetString(doc, entityDataNode->xmlChildrenNode, 1);
181 sscanf((char*) key, "%d,%d", &data->position.first, &data->position.second);
182 xmlFree(key);
183 }
184 }
185
186 map->addObject(data, false);
187 }
188 }
189 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "child")) 154 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "child"))
190 { 155 {
191 xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1); 156 xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1);
@@ -194,13 +159,6 @@ World::World(std::string filename)
194 map->addChild(atoi((char*) key)); 159 map->addChild(atoi((char*) key));
195 } 160 }
196 xmlFree(key); 161 xmlFree(key);
197 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "expanded"))
198 {
199 xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1);
200 if ((key != 0) && ((char) key[0] == '1'))
201 {
202 map->setExpanded(true);
203 }
204 } 162 }
205 } 163 }
206 164
@@ -266,16 +224,24 @@ void World::save(std::string name, wxTreeCtrl* mapTree)
266 rc = xmlTextWriterStartElement(writer, (xmlChar*) "world"); 224 rc = xmlTextWriterStartElement(writer, (xmlChar*) "world");
267 if (rc < 0) throw MapWriteException(name); 225 if (rc < 0) throw MapWriteException(name);
268 226
269 // <nextmapid/> 227 // nextmap=
270 std::ostringstream nextMap_out; 228 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "nextmap", "%d", nextMapID);
271 nextMap_out << nextMapID; 229 if (rc < 0) throw MapWriteException(name);
272 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "nextmapid", (xmlChar*) nextMap_out.str().c_str()); 230
231 // lastmap=
232 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "lastmap", "%d", lastmap);
233 if (rc < 0) throw MapWriteException(name);
234
235 // startx=
236 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "startx", "%d", startingPosition.first);
273 if (rc < 0) throw MapWriteException(name); 237 if (rc < 0) throw MapWriteException(name);
274 238
275 // <lastmap/> 239 // starty=
276 std::ostringstream lastMap_out; 240 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "starty", "%d", startingPosition.second);
277 lastMap_out << lastmap; 241 if (rc < 0) throw MapWriteException(name);
278 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "lastmap", (xmlChar*) lastMap_out.str().c_str()); 242
243 // startmap=
244 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "startmap", "%d", startingMap);
279 if (rc < 0) throw MapWriteException(name); 245 if (rc < 0) throw MapWriteException(name);
280 246
281 // ASSUMPTION: There will always be at least one child of the invisible root element. i.e. you cannot delete to zero maps. 247 // ASSUMPTION: There will always be at least one child of the invisible root element. i.e. you cannot delete to zero maps.
@@ -285,28 +251,10 @@ void World::save(std::string name, wxTreeCtrl* mapTree)
285 { 251 {
286 // <root> 252 // <root>
287 MapPtrCtr* ctl = (MapPtrCtr*) mapTree->GetItemData(it); 253 MapPtrCtr* ctl = (MapPtrCtr*) mapTree->GetItemData(it);
288 std::ostringstream rootid_out; 254 rc = xmlTextWriterWriteFormatElement(writer, (xmlChar*) "root", "%d", ctl->map->getID());
289 rootid_out << ctl->map->getID();
290 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "root", (xmlChar*) rootid_out.str().c_str());
291 if (rc < 0) throw MapWriteException(name); 255 if (rc < 0) throw MapWriteException(name);
292 } 256 }
293 257
294 // <startpos/>
295 rc = xmlTextWriterStartElement(writer, (xmlChar*) "startpos");
296 if (rc < 0) throw MapWriteException(name);
297
298 // id=
299 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "id", "%d", startingMap);
300 if (rc < 0) throw MapWriteException(name);
301
302 // pos=
303 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "pos", "%d,%d", startingPosition.first, startingPosition.second);
304 if (rc < 0) throw MapWriteException(name);
305
306 // </startpos>
307 rc = xmlTextWriterEndElement(writer);
308 if (rc < 0) throw MapWriteException(name);
309
310 for (auto mapPair : maps) 258 for (auto mapPair : maps)
311 { 259 {
312 Map& map = *mapPair.second; 260 Map& map = *mapPair.second;
@@ -318,16 +266,33 @@ void World::save(std::string name, wxTreeCtrl* mapTree)
318 if (rc < 0) throw MapWriteException(name); 266 if (rc < 0) throw MapWriteException(name);
319 267
320 // id= 268 // id=
321 std::ostringstream id_out; 269 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "id", "%d", map.getID());
322 id_out << map.getID();
323 rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "id", (xmlChar*) id_out.str().c_str());
324 if (rc < 0) throw MapWriteException(name); 270 if (rc < 0) throw MapWriteException(name);
325 271
326 // <name/> 272 // expanded=
327 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "name", (xmlChar*) map.getTitle().c_str()); 273 wxTreeItemId node = map.getTreeItemId();
274 if (mapTree->IsExpanded(node))
275 {
276 rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "expanded", (xmlChar*) "true");
277 if (rc < 0) throw MapWriteException(name);
278 } else {
279 rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "expanded", (xmlChar*) "false");
280 if (rc < 0) throw MapWriteException(name);
281 }
282
283 // title=
284 rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "name", (xmlChar*) map.getTitle().c_str());
328 if (rc < 0) throw MapWriteException(name); 285 if (rc < 0) throw MapWriteException(name);
329 286
330 // <environment/> 287 // <environment
288 rc = xmlTextWriterStartElement(writer, (xmlChar*) "environment");
289 if (rc < 0) throw MapWriteException(name);
290
291 // type=
292 rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "type", (xmlChar*) "0");
293 if (rc < 0) throw MapWriteException(name);
294
295 // >
331 std::ostringstream mapdata_out; 296 std::ostringstream mapdata_out;
332 for (int y=0; y<MAP_HEIGHT; y++) 297 for (int y=0; y<MAP_HEIGHT; y++)
333 { 298 {
@@ -341,113 +306,60 @@ void World::save(std::string name, wxTreeCtrl* mapTree)
341 306
342 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "environment", (xmlChar*) mapdata_out.str().c_str()); 307 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "environment", (xmlChar*) mapdata_out.str().c_str());
343 if (rc < 0) throw MapWriteException(name); 308 if (rc < 0) throw MapWriteException(name);
344
345 // <leftmap/>
346 rc = xmlTextWriterStartElement(writer, (xmlChar*) "leftmap");
347 if (rc < 0) throw MapWriteException(name);
348 309
349 // type= 310 // </environment>
350 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getLeftMoveType()).c_str());
351 if (rc < 0) throw MapWriteException(name);
352
353 if (Map::moveTypeTakesMap(map.getLeftMoveType()))
354 {
355 // map=
356 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getLeftMoveMapID());
357 if (rc < 0) throw MapWriteException(name);
358 }
359
360 // </leftmap>
361 rc = xmlTextWriterEndElement(writer); 311 rc = xmlTextWriterEndElement(writer);
362 if (rc < 0) throw MapWriteException(name); 312 if (rc < 0) throw MapWriteException(name);
363 313
364 // <rightmap/> 314 for (auto object : map.getObjects())
365 rc = xmlTextWriterStartElement(writer, (xmlChar*) "rightmap");
366 if (rc < 0) throw MapWriteException(name);
367
368 // type=
369 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getRightMoveType()).c_str());
370 if (rc < 0) throw MapWriteException(name);
371
372 if (Map::moveTypeTakesMap(map.getRightMoveType()))
373 { 315 {
374 // map= 316 // <entity>
375 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getRightMoveMapID()); 317 rc = xmlTextWriterStartElement(writer, (xmlChar*) "entity");
376 if (rc < 0) throw MapWriteException(name); 318 if (rc < 0) throw MapWriteException(name);
377 }
378
379 // </rightmap>
380 rc = xmlTextWriterEndElement(writer);
381 if (rc < 0) throw MapWriteException(name);
382 319
383 // <upmap/> 320 // type=
384 rc = xmlTextWriterStartElement(writer, (xmlChar*) "upmap"); 321 rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "type", (xmlChar*) object->object->getType().c_str());
385 if (rc < 0) throw MapWriteException(name);
386
387 // type=
388 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getUpMoveType()).c_str());
389 if (rc < 0) throw MapWriteException(name);
390
391 if (Map::moveTypeTakesMap(map.getUpMoveType()))
392 {
393 // map=
394 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getUpMoveMapID());
395 if (rc < 0) throw MapWriteException(name); 322 if (rc < 0) throw MapWriteException(name);
396 }
397
398 // </upmap>
399 rc = xmlTextWriterEndElement(writer);
400 if (rc < 0) throw MapWriteException(name);
401 323
402 // <downmap/> 324 // x=
403 rc = xmlTextWriterStartElement(writer, (xmlChar*) "downmap"); 325 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "x", "%d", object->position.first);
404 if (rc < 0) throw MapWriteException(name); 326 if (rc < 0) throw MapWriteException(name);
405 327
406 // type= 328 // y=
407 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getDownMoveType()).c_str()); 329 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "y", "%d", object->position.second);
408 if (rc < 0) throw MapWriteException(name); 330 if (rc < 0) throw MapWriteException(name);
409 331
410 if (Map::moveTypeTakesMap(map.getDownMoveType())) 332 // </entity>
411 { 333 rc = xmlTextWriterEndElement(writer);
412 // map=
413 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getDownMoveMapID());
414 if (rc < 0) throw MapWriteException(name); 334 if (rc < 0) throw MapWriteException(name);
415 } 335 }
416 336
417 // </downmap> 337 for (auto adjacent : map.getAdjacents())
418 rc = xmlTextWriterEndElement(writer);
419 if (rc < 0) throw MapWriteException(name);
420
421 // <entities>
422 rc = xmlTextWriterStartElement(writer, (xmlChar*) "entities");
423 if (rc < 0) throw MapWriteException(name);
424
425 for (auto object : map.getObjects())
426 { 338 {
427 // <entity> 339 // <adjacent>
428 rc = xmlTextWriterStartElement(writer, (xmlChar*) "entity"); 340 rc = xmlTextWriterStartElement(writer, (xmlChar*) "adjacent");
429 if (rc < 0) throw MapWriteException(name); 341 if (rc < 0) throw MapWriteException(name);
430 342
431 // <entity-type/> 343 // dir=
432 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "entity-type", (xmlChar*) object->object->getType().c_str()); 344 rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "dir", (xmlChar*) Map::shortForMoveDir(adjacent.first).c_str());
433 if (rc < 0) throw MapWriteException(name); 345 if (rc < 0) throw MapWriteException(name);
434 346
435 // <entity-position/> 347 // type=
436 std::ostringstream entpos_out; 348 rc = xmlTextWriterWriteAttribute(writer, (xmlChar*) "type", (xmlChar*) Map::shortForMoveType(adjacent.second.type).c_str());
437 entpos_out << object->position.first << "," << object->position.second;
438 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "entity-position", (xmlChar*) entpos_out.str().c_str());
439 if (rc < 0) throw MapWriteException(name); 349 if (rc < 0) throw MapWriteException(name);
440 350
441 // </entity> 351 // map=
352 if (Map::moveTypeTakesMap(adjacent.second.type))
353 {
354 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", adjacent.second.map);
355 if (rc < 0) throw MapWriteException(name);
356 }
357
358 // </adjacent>
442 rc = xmlTextWriterEndElement(writer); 359 rc = xmlTextWriterEndElement(writer);
443 if (rc < 0) throw MapWriteException(name); 360 if (rc < 0) throw MapWriteException(name);
444 } 361 }
445
446 // </entities>
447 rc = xmlTextWriterEndElement(writer);
448 if (rc < 0) throw MapWriteException(name);
449 362
450 wxTreeItemId node = map.getTreeItemId();
451 if (mapTree->ItemHasChildren(node)) 363 if (mapTree->ItemHasChildren(node))
452 { 364 {
453 wxTreeItemIdValue cookie2; 365 wxTreeItemIdValue cookie2;
@@ -455,16 +367,7 @@ void World::save(std::string name, wxTreeCtrl* mapTree)
455 { 367 {
456 // <child/> 368 // <child/>
457 MapPtrCtr* ctl = (MapPtrCtr*) mapTree->GetItemData(it); 369 MapPtrCtr* ctl = (MapPtrCtr*) mapTree->GetItemData(it);
458 std::ostringstream childid_out; 370 rc = xmlTextWriterWriteFormatElement(writer, (xmlChar*) "child", "%d", ctl->map->getID());
459 childid_out << ctl->map->getID();
460 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "child", (xmlChar*) childid_out.str().c_str());
461 if (rc < 0) throw MapWriteException(name);
462 }
463
464 if (mapTree->IsExpanded(node))
465 {
466 // <expanded/>
467 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "expanded", (xmlChar*) "1");
468 if (rc < 0) throw MapWriteException(name); 371 if (rc < 0) throw MapWriteException(name);
469 } 372 }
470 } 373 }