--- deliantra/server/common/map.C 2006/08/31 18:59:23 1.19 +++ deliantra/server/common/map.C 2006/09/08 18:26:22 1.28 @@ -1,6 +1,6 @@ /* * static char *rcsid_map_c = - * "$Id: map.C,v 1.19 2006/08/31 18:59:23 root Exp $"; + * "$Id: map.C,v 1.28 2006/09/08 18:26:22 root Exp $"; */ /* @@ -157,7 +157,7 @@ #ifndef WIN32 char *endbuf; struct stat statbuf; - int mode = 0, i; + int mode = 0; #endif if (prepend_dir) @@ -257,10 +257,8 @@ if (newmap) *newmap = mp; if (nx) *nx = newx; if (ny) *ny = newy; - retval |= mp->spaces[newx + mp->width * newy].flags; - if (retval & P_SAFE) - retval |= P_NO_MAGIC | P_NO_CLERIC; // P_SAFE does imply these + retval |= mp->spaces[newx + mp->width * newy].flags; return retval; } @@ -484,14 +482,8 @@ op->head = tmp; op->map = m; last->more = op; - if (tmp->name != op->name) { - if (op->name) free_string(op->name); - op->name = add_string(tmp->name); - } - if (tmp->title != op->title) { - if (op->title) free_string(op->title); - op->title = add_string(tmp->title); - } + op->name = tmp->name; + op->title = tmp->title; /* we could link all the parts onto tmp, and then just * call insert_ob_in_map once, but the effect is the same, * as insert_ob_in_map will call itself with each part, and @@ -502,79 +494,89 @@ } /* for objects on this space */ } - - /* * Loads (ands parses) the objects into a given map from the specified * file pointer. * mapflags is the same as we get with load_original_map */ +void +load_objects (mapstruct *m, object_thawer &fp, int mapflags) +{ + int i, j; + int unique; + object *op, *prev = NULL, *last_more = NULL, *otmp; -void load_objects (mapstruct *m, object_thawer &fp, int mapflags) { - int i,j,bufstate=LO_NEWFILE; - int unique; - object *op, *prev=NULL,*last_more=NULL, *otmp; - - op=get_object(); - op->map = m; /* To handle buttons correctly */ - - while((i = load_object (fp, op, bufstate, mapflags))) { - /* Since the loading of the map header does not load an object - * anymore, we need to pass LO_NEWFILE for the first object loaded, - * and then switch to LO_REPEAT for faster loading. - */ - bufstate = LO_REPEAT; + op = get_object (); + op->map = m; /* To handle buttons correctly */ - /* if the archetype for the object is null, means that we - * got an invalid object. Don't do anything with it - the game - * or editor will not be able to do anything with it either. - */ - if (op->arch==NULL) { - LOG(llevDebug,"Discarding object without arch: %s\n", op->name?(const char *)op->name:"(null)"); - continue; + while ((i = load_object (fp, op, mapflags))) + { + /* if the archetype for the object is null, means that we + * got an invalid object. Don't do anything with it - the game + * or editor will not be able to do anything with it either. + */ + if (op->arch == NULL) + { + LOG (llevDebug, "Discarding object without arch: %s\n", + op->name ? (const char *) op->name : "(null)"); + continue; } - switch(i) { + switch (i) + { case LL_NORMAL: /* if we are loading an overlay, put the floors on the bottom */ - if ((QUERY_FLAG(op, FLAG_IS_FLOOR) || - QUERY_FLAG(op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) - insert_ob_in_map(op,m,op,INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); + if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || + QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) + insert_ob_in_map (op, m, op, + INS_NO_MERGE | INS_NO_WALK_ON | + INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); else - insert_ob_in_map(op,m,op,INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); + insert_ob_in_map (op, m, op, + INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | + INS_MAP_LOAD); if (op->inv) - sum_weight(op); + sum_weight (op); - prev=op,last_more=op; + prev = op, last_more = op; break; case LL_MORE: - insert_ob_in_map(op,m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); - op->head=prev,last_more->more=op,last_more=op; + insert_ob_in_map (op, m, op, + INS_NO_MERGE | INS_NO_WALK_ON | + INS_ABOVE_FLOOR_ONLY); + op->head = prev, last_more->more = op, last_more = op; break; } - if (mapflags & MAP_STYLE) { - remove_from_active_list(op); - } - op=get_object(); - op->map = m; + + if (mapflags & MAP_STYLE) + remove_from_active_list (op); + + op = get_object (); + op->map = m; } - for (i=0;iwidth;i++){ - for (j=0;jheight;j++){ - unique =0; - /* check for unique items, or unique squares */ - for (otmp = get_map_ob(m, i, j); otmp; otmp = otmp->above) { - if (QUERY_FLAG(otmp, FLAG_UNIQUE) || QUERY_FLAG(otmp, FLAG_OBJ_SAVE_ON_OVL)) - unique = 1; - if (!(mapflags & (MAP_OVERLAY|MAP_PLAYER_UNIQUE) || unique)) - SET_FLAG(otmp, FLAG_OBJ_ORIGINAL); + + for (i = 0; i < m->width; i++) + { + for (j = 0; j < m->height; j++) + { + unique = 0; + /* check for unique items, or unique squares */ + for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above) + { + if (QUERY_FLAG (otmp, FLAG_UNIQUE) + || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) + unique = 1; + if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) + SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); } } } - free_object(op); - link_multipart_objects(m); + + free_object (op); + link_multipart_objects (m); } /* This saves all the objects on the map in a non destructive fashion. @@ -620,12 +622,9 @@ */ mapstruct *get_linked_map(void) { - mapstruct *map=(mapstruct *) calloc(1,sizeof(mapstruct)); + mapstruct *map = new mapstruct; mapstruct *mp; - if(map==NULL) - fatal(OUT_OF_MEMORY); - for(mp=first_map;mp!=NULL&&mp->next!=NULL;mp=mp->next); if(mp==NULL) first_map=map; @@ -705,8 +704,7 @@ } p=shop_string; strip_endline(p); - items=(shopitems *) CALLOC(number_of_entries+1, sizeof(shopitems)); - memset(items, 0, (sizeof(shopitems) * number_of_entries+1)); + items = new shopitems [number_of_entries + 1]; for (i=0; iattach = add_string (value); + m->attach = value; } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) { m->enter_x = atoi(value); } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) { @@ -1012,7 +1010,6 @@ mapstruct *m; char pathname[MAX_BUF]; - LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags); if (flags & MAP_PLAYER_UNIQUE) strcpy(pathname, filename); else if (flags & MAP_OVERLAY) @@ -1020,6 +1017,8 @@ else strcpy(pathname, create_pathname(filename)); + LOG(llevDebug, "load_original_map(%x): %s (%s)\n", flags, filename, pathname); + object_thawer thawer (pathname); if (!thawer) @@ -1055,7 +1054,6 @@ */ static mapstruct *load_temporary_map(mapstruct *m) { - int comp; char buf[MAX_BUF]; if (!m->tmpname) { @@ -1181,7 +1179,6 @@ m->in_memory=MAP_LOADING; if (m->tmpname == NULL) /* if we have loaded unique items from */ delete_unique_items(m); /* original map before, don't duplicate them */ - load_object(thawer, NULL, LO_NOREAD,0); load_objects (m, thawer, 0); m->in_memory=MAP_IN_MEMORY; @@ -1200,7 +1197,7 @@ int new_save_map (mapstruct * m, int flag) { - char filename[MAX_BUF], buf[MAX_BUF], buf_s[MAX_BUF], shop[MAX_BUF]; + char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; int i; if (flag && !*m->path) @@ -1414,7 +1411,7 @@ if (m->spaces) FREE_AND_CLEAR(m->spaces); if (m->msg) FREE_AND_CLEAR(m->msg); if (m->maplore) FREE_AND_CLEAR(m->maplore); - if (m->shopitems) FREE_AND_CLEAR(m->shopitems); + if (m->shopitems) delete [] m->shopitems; m->shopitems = 0; if (m->shoprace) FREE_AND_CLEAR(m->shoprace); if (m->buttons) free_objectlinkpt(m->buttons); @@ -1484,7 +1481,7 @@ else last->next = m->next; - free (m); + delete m; } @@ -1537,15 +1534,17 @@ else LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name)); + //eval_pv ("$x = Event::time", 1);//D if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE)))) return (NULL); + //eval_pv ("warn \"LOAD \", Event::time - $x", 1);//D fix_auto_apply(m); /* Chests which open as default */ /* If a player unique map, no extra unique object file to load. * if from the editor, likewise. */ - if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE))) + if (!(flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE))) load_unique_objects(m); if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) { @@ -1606,7 +1605,7 @@ int calculate_difficulty(mapstruct *m) { object *op; archetype *at; - int x, y, i, diff; + int x, y, i; long monster_cnt = 0; double avgexp = 0; sint64 total_exp = 0; @@ -1806,7 +1805,7 @@ if (QUERY_FLAG(tmp,FLAG_DAMNED)) flags |= P_NO_CLERIC; if (tmp->type == SAFE_GROUND) - flags |= P_SAFE | P_NO_CLERIC | P_NO_MAGIC; + flags |= P_SAFE; if (QUERY_FLAG(tmp,FLAG_BLOCKSVIEW)) flags |= P_BLOCKSVIEW;