X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vrlugburz;a=blobdiff_plain;f=src%2Flevel.c;fp=src%2Flevel.c;h=ced5b690dd071c7abd89d388aa69dd08ddc70ff7;hp=566b1c300015e88774ef92f05ff426bf473761f4;hb=8de1d701e4e9a45e7ed69ccf1fc298514fed5d8f;hpb=76c3689b01d18e5949e91d0658deb278714f882b diff --git a/src/level.c b/src/level.c index 566b1c3..ced5b69 100644 --- a/src/level.c +++ b/src/level.c @@ -19,6 +19,7 @@ int init_level(struct level *lvl, int xsz, int ysz) lvl->width = xsz; lvl->height = ysz; lvl->cell_size = DEF_CELL_SIZE; + lvl->px = lvl->py = -1; return 0; } @@ -37,13 +38,6 @@ int load_level(struct level *lvl, const char *fname) struct cell *cell; float *vecptr; - lvl->fname = strdup(fname); - if((lvl->dirname = malloc(strlen(fname) + 1))) { -#ifndef LEVEL_EDITOR - path_dir(lvl->fname, lvl->dirname); -#endif - } - if(!(ts = ts_load(fname))) { fprintf(stderr, "failed to load level: %s\n", fname); return -1; @@ -63,6 +57,14 @@ int load_level(struct level *lvl, const char *fname) ts_free_tree(ts); return -1; } + + lvl->fname = strdup(fname); + if((lvl->dirname = malloc(strlen(fname) + 1))) { +#ifndef LEVEL_EDITOR + path_dir(lvl->fname, lvl->dirname); +#endif + } + lvl->cell_size = ts_get_attr_num(ts, "cellsize", DEF_CELL_SIZE); if((vecptr = ts_get_attr_vec(ts, "player", 0))) { @@ -147,6 +149,20 @@ int save_level(struct level *lvl, const char *fname) ts_set_valuei(&attr->val, lvl->width); ts_add_attr(root, attr); + if(lvl->cell_size && (attr = ts_alloc_attr())) { + ts_set_attr_name(attr, "cellsize"); + ts_set_valuef(&attr->val, lvl->cell_size); + ts_add_attr(root, attr); + } + + if(lvl->px >= 0 && lvl->px < lvl->width && lvl->py >= 0 && lvl->py < lvl->height) { + if((attr = ts_alloc_attr())) { + ts_set_attr_name(attr, "player"); + ts_set_valueiv(&attr->val, 2, lvl->px, lvl->py); + ts_add_attr(root, attr); + } + } + for(i=0; iheight; i++) { for(j=0; jwidth; j++) { cell = lvl->cells + i * lvl->width + j;