--- deliantra/server/common/map.C 2006/09/04 11:07:59 1.22 +++ deliantra/server/common/map.C 2006/09/08 12:56:42 1.27 @@ -1,6 +1,6 @@ /* * static char *rcsid_map_c = - * "$Id: map.C,v 1.22 2006/09/04 11:07:59 root Exp $"; + * "$Id: map.C,v 1.27 2006/09/08 12:56:42 root Exp $"; */ /* @@ -157,7 +157,7 @@ #ifndef WIN32 char *endbuf; struct stat statbuf; - int mode = 0, i; + int mode = 0; #endif if (prepend_dir) @@ -496,73 +496,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; - int unique; - object *op, *prev=NULL,*last_more=NULL, *otmp; - - op=get_object(); - op->map = m; /* To handle buttons correctly */ + op = get_object (); + op->map = m; /* To handle buttons correctly */ - 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; + 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. @@ -690,8 +706,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; itmpname) { @@ -1186,7 +1199,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) @@ -1400,7 +1413,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); @@ -1523,20 +1536,17 @@ else LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name)); - //0.427459955215454 /var/crossfire/players/Saladon/_scorn_apartment_apartments - //0.414906024932861 - //0.427063941955566 - eval_pv ("$x = Event::time", 1);//D + //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 + //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))) { @@ -1597,7 +1607,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;