diff options
Diffstat (limited to 'src/world.cpp')
-rw-r--r-- | src/world.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/world.cpp b/src/world.cpp index 17288fa..0c61c47 100644 --- a/src/world.cpp +++ b/src/world.cpp | |||
@@ -57,7 +57,7 @@ World::World(const char* filename) | |||
57 | { | 57 | { |
58 | if (!xmlStrcmp(mapNode->name, (const xmlChar*) "environment")) | 58 | if (!xmlStrcmp(mapNode->name, (const xmlChar*) "environment")) |
59 | { | 59 | { |
60 | xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1); | 60 | xmlChar* key = xmlNodeGetContent(mapNode); |
61 | int* mapdata = (int*) malloc(MAP_WIDTH*MAP_HEIGHT*sizeof(int)); | 61 | int* mapdata = (int*) malloc(MAP_WIDTH*MAP_HEIGHT*sizeof(int)); |
62 | mapdata[0] = atoi(strtok((char*) key, ",\n")); | 62 | mapdata[0] = atoi(strtok((char*) key, ",\n")); |
63 | for (int i=1; i<(MAP_WIDTH*MAP_HEIGHT); i++) | 63 | for (int i=1; i<(MAP_WIDTH*MAP_HEIGHT); i++) |
@@ -85,6 +85,22 @@ World::World(const char* filename) | |||
85 | data.position.second = atoi((char*) yKey); | 85 | data.position.second = atoi((char*) yKey); |
86 | xmlFree(yKey); | 86 | xmlFree(yKey); |
87 | 87 | ||
88 | for (xmlNodePtr entityNode = mapNode->xmlChildrenNode; entityNode != NULL; entityNode = entityNode->next) | ||
89 | { | ||
90 | if (!xmlStrcmp(entityNode->name, (xmlChar*) "item")) | ||
91 | { | ||
92 | xmlChar* itemIdKey = xmlGetProp(entityNode, (const xmlChar*) "id"); | ||
93 | if (itemIdKey == 0) exit(2); | ||
94 | std::string itemId = (char*) itemIdKey; | ||
95 | xmlFree(itemIdKey); | ||
96 | |||
97 | xmlChar* itemIdVal = xmlNodeGetContent(entityNode); | ||
98 | if (itemIdVal == 0) exit(2); | ||
99 | data.items[itemId] = atoi((char*) itemIdVal); | ||
100 | xmlFree(itemIdVal); | ||
101 | } | ||
102 | } | ||
103 | |||
88 | map.addEntity(data); | 104 | map.addEntity(data); |
89 | } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "adjacent")) | 105 | } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "adjacent")) |
90 | { | 106 | { |