-static int load_tileset(struct level *lvl, struct ts_node *tsn)
-{
- static const char *tile_types[] = {"empty", "straight", "corner", "door", 0};
-
- int i;
- char *path;
- const char *str;
- struct ts_node *node;
- struct tile *tile;
-
- node = tsn->child_list;
- while(node) {
- if(strcmp(node->name, "tile") == 0) {
- if(!(tile = calloc(1, sizeof *tile))) {
- fprintf(stderr, "failed to allocate tile\n");
- return -1;
- }
- if((str = ts_get_attr_str(node, "name", 0))) {
- tile->name = strdup(str);
- }
- if((str = ts_get_attr_str(node, "type", 0))) {
- for(i=0; tile_types[i]; i++) {
- if(strcmp(str, tile_types[i]) == 0) {
- tile->type = i;
- break;
- }
- }
- }
- if((str = ts_get_attr_str(node, "scene", 0))) {
- if(lvl->dirname) {
- path = alloca(strlen(lvl->dirname) + strlen(str) + 2);
- combine_path(lvl->dirname, str, path);
- } else {
- path = (char*)str;
- }
- load_scenefile(&tile->scn, path);
- }
-
- if(tile->name && tile->scn.meshlist) { /* valid tile */
- tile->next = lvl->tiles;
- lvl->tiles = tile;
- } else {
- fprintf(stderr, "load_tileset: skipping invalid tile: %s\n",
- tile->name ? tile->name : "missing tile name");
- free(tile);
- }
- }
- node = node->next;
- }
-
- return 0;
-}
-
-struct tile *find_level_tile(struct level *lvl, int type)