--- deliantra/server/common/map.c 2006/02/22 18:01:21 1.1.1.2 +++ deliantra/server/common/map.c 2006/08/13 17:16:00 1.14 @@ -40,6 +40,9 @@ extern int nrofallocobjects,nroffreeobjects; +void (*load_original_map_callback)(mapstruct *map); +void (*load_temporary_map_callback)(mapstruct *map); +void (*clean_temporary_map_callback)(mapstruct *map); /* * Returns the mapstruct which has a name matching the given argument. @@ -589,14 +592,12 @@ */ void save_objects (mapstruct *m, FILE *fp, FILE *fp2, int flag) { int i, j = 0,unique=0; - object *op, *otmp; + object *op; /* first pass - save one-part objects */ for(i = 0; i < MAP_WIDTH(m); i++) for (j = 0; j < MAP_HEIGHT(m); j++) { unique=0; - for(op = get_map_ob (m, i, j); op; op = otmp) { - otmp = op->above; - + for(op = get_map_ob (m, i, j); op; op = op->above) { if (QUERY_FLAG(op,FLAG_IS_FLOOR) && QUERY_FLAG(op, FLAG_UNIQUE)) unique=1; @@ -678,7 +679,7 @@ fatal(OUT_OF_MEMORY); } -/* Creatures and returns a map of the specific size. Used +/* Create and returns a map of the specific size. Used * in random map code and the editor. */ mapstruct *get_empty_map(int sizex, int sizey) { @@ -704,7 +705,6 @@ shop_string=strdup_local(input_string); p=shop_string; - LOG(llevDebug, "parsing %s\n", input_string); /* first we'll count the entries, we'll need that for allocating the array shortly */ while (p) { p=strchr(p, ';'); @@ -1051,6 +1051,8 @@ if (!MAP_DIFFICULTY(m)) MAP_DIFFICULTY(m)=calculate_difficulty(m); set_map_reset_time(m); + if (load_original_map_callback) + load_original_map_callback(m); return (m); } @@ -1100,6 +1102,8 @@ load_objects (m, fp, 0); close_and_delete(fp, comp); m->in_memory=MAP_IN_MEMORY; + if (load_temporary_map_callback) + load_temporary_map_callback(m); return m; } @@ -1145,7 +1149,7 @@ /* This goes through map 'm' and removed any unique items on the map. */ static void delete_unique_items(mapstruct *m) { - int i,j,unique=0; + int i,j,unique; object *op, *next; for(i=0; ipath); m->in_memory = MAP_SAVING; + unlink (filename); // do not overwrite backups if done via hardlinks + /* Compress if it isn't a temporary save. Do compress if unique */ if (m->compressed && (m->unique || m->template || flag)) { char buf[MAX_BUF]; @@ -1613,52 +1619,58 @@ */ int calculate_difficulty(mapstruct *m) { - object *op; - archetype *at; - int x,y; - int diff=0; - int i; - sint64 exp_pr_sq, total_exp=0; + object *op; + archetype *at; + int x, y, i, diff; + long monster_cnt = 0; + double avgexp = 0; + sint64 total_exp = 0; - if (MAP_DIFFICULTY(m)) { - LOG(llevDebug, "Using stored map difficulty: %d\n", MAP_DIFFICULTY(m)); - return MAP_DIFFICULTY(m); + if (MAP_DIFFICULTY (m)) + { + LOG(llevDebug, "Using stored map difficulty: %d\n", MAP_DIFFICULTY (m)); + return MAP_DIFFICULTY (m); } - for(x=0;xabove) { - if(QUERY_FLAG(op,FLAG_MONSTER)) - total_exp+=op->stats.exp; - if(QUERY_FLAG(op,FLAG_GENERATOR)) { - total_exp+=op->stats.exp; - at=type_to_archetype(GENERATE_TYPE(op)); - if(at!=NULL) - total_exp+=at->clone.stats.exp*8; - } - } -#ifdef NEWCALC - (int)exp_pr_sq=((double)1000*total_exp)/(m->map_object->x*m->map_object->y+1); - for(i=20;i>0;i--) - if(exp_pr_sq>level_exp(i,1.0)) { - diff=i; - break; - } -#else - exp_pr_sq=((double)1000*total_exp)/(MAP_WIDTH(m)*MAP_HEIGHT(m)+1); - diff=20; - for(i=1;i<20;i++) - if(exp_pr_sq<=level_exp(i,1.0)) { - diff=i; - break; - } -#endif - return diff; + for(x = 0; x < MAP_WIDTH(m); x++) + for(y = 0; y < MAP_HEIGHT(m); y++) + for(op = get_map_ob(m, x, y); op != NULL; op = op->above) + { + if(QUERY_FLAG (op, FLAG_MONSTER)) + { + total_exp += op->stats.exp; + monster_cnt++; + } + + if(QUERY_FLAG (op, FLAG_GENERATOR)) + { + total_exp += op->stats.exp; + at = type_to_archetype(GENERATE_TYPE (op)); + + if(at != NULL) + total_exp += at->clone.stats.exp * 8; + + monster_cnt++; + } + } + + avgexp = (double) total_exp / monster_cnt; + + for (i = 1; i <= settings.max_level; i++) + { + if ((level_exp (i, 1) - level_exp (i - 1, 1)) > (100 * avgexp)) + { + /* LOG(llevDebug, "Calculated difficulty for map: %s: %d\n", m->name, i); */ + return i; + } + } } void clean_tmp_map(mapstruct *m) { if(m->tmpname == NULL) return; + if (clean_temporary_map_callback) + clean_temporary_map_callback (m); (void) unlink(m->tmpname); } @@ -1696,9 +1708,9 @@ /* inform all players on the map */ if (change>0) - new_info_map(NDI_BLACK, m,"It becomes darker."); + new_info_map(NDI_BLACK|NDI_UNIQUE, m,"It becomes darker."); else - new_info_map(NDI_BLACK, m,"It becomes brighter."); + new_info_map(NDI_BLACK|NDI_UNIQUE, m,"It becomes brighter."); /* Do extra checking. since m->darkness is a unsigned value, * we need to be extra careful about negative values. @@ -1953,12 +1965,6 @@ */ if (!m) return 0; - /* Simple case - coordinates are within this local - * map. - */ - if ( x>=0 && x=0 && y < MAP_HEIGHT(m)) - return 0; - if (x<0) { if (!m->tile_path[3]) return 1; if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) { @@ -1987,7 +1993,11 @@ } return (out_of_map(m->tile_map[2], x, y - MAP_HEIGHT(m))); } - return 1; + + /* Simple case - coordinates are within this local + * map. + */ + return 0; } /* This is basically the same as out_of_map above, but @@ -2001,13 +2011,6 @@ mapstruct *get_map_from_coord(mapstruct *m, sint16 *x, sint16 *y) { - /* Simple case - coordinates are within this local - * map. - */ - - if (*x>=0 && *x=0 && *y < MAP_HEIGHT(m)) - return m; - if (*x<0) { if (!m->tile_path[3]) return NULL; if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) @@ -2040,7 +2043,12 @@ *y -= MAP_HEIGHT(m); return (get_map_from_coord(m->tile_map[2], x, y)); } - return NULL; /* Shouldn't get here */ + + /* Simple case - coordinates are within this local + * map. + */ + + return m; } /**