diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-19 16:15:47 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-19 16:15:47 -0400 |
| commit | 4b4125e234cb727c70822e0a1fce0688c357741e (patch) | |
| tree | 5b446ebe6f0454304d4202368bd18fba3f629d3d /src/world.cpp | |
| parent | 281bdf956a646fd8c9944e9a44f867c984792216 (diff) | |
| download | therapy-4b4125e234cb727c70822e0a1fce0688c357741e.tar.gz therapy-4b4125e234cb727c70822e0a1fce0688c357741e.tar.bz2 therapy-4b4125e234cb727c70822e0a1fce0688c357741e.zip | |
Implemented a simple AI
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 | { |
