From 4b4125e234cb727c70822e0a1fce0688c357741e Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 19 Mar 2015 16:15:47 -0400 Subject: Implemented a simple AI --- src/world.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/world.cpp') 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) { if (!xmlStrcmp(mapNode->name, (const xmlChar*) "environment")) { - xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1); + xmlChar* key = xmlNodeGetContent(mapNode); int* mapdata = (int*) malloc(MAP_WIDTH*MAP_HEIGHT*sizeof(int)); mapdata[0] = atoi(strtok((char*) key, ",\n")); for (int i=1; i<(MAP_WIDTH*MAP_HEIGHT); i++) @@ -85,6 +85,22 @@ World::World(const char* filename) data.position.second = atoi((char*) yKey); xmlFree(yKey); + for (xmlNodePtr entityNode = mapNode->xmlChildrenNode; entityNode != NULL; entityNode = entityNode->next) + { + if (!xmlStrcmp(entityNode->name, (xmlChar*) "item")) + { + xmlChar* itemIdKey = xmlGetProp(entityNode, (const xmlChar*) "id"); + if (itemIdKey == 0) exit(2); + std::string itemId = (char*) itemIdKey; + xmlFree(itemIdKey); + + xmlChar* itemIdVal = xmlNodeGetContent(entityNode); + if (itemIdVal == 0) exit(2); + data.items[itemId] = atoi((char*) itemIdVal); + xmlFree(itemIdVal); + } + } + map.addEntity(data); } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "adjacent")) { -- cgit 1.4.1