1 | /* |
1 | /* |
2 | * static char *rcsid_map_c = |
2 | * static char *rcsid_map_c = |
3 | * "$Id: map.c,v 1.9 2006/03/28 06:54:31 root Exp $"; |
3 | * "$Id: map.c,v 1.12.2.1 2006/08/10 08:26:28 elmex Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
703 | int i=0, number_of_entries=0; |
703 | int i=0, number_of_entries=0; |
704 | const typedata *current_type; |
704 | const typedata *current_type; |
705 | |
705 | |
706 | shop_string=strdup_local(input_string); |
706 | shop_string=strdup_local(input_string); |
707 | p=shop_string; |
707 | p=shop_string; |
708 | LOG(llevDebug, "parsing %s\n", input_string); |
|
|
709 | /* first we'll count the entries, we'll need that for allocating the array shortly */ |
708 | /* first we'll count the entries, we'll need that for allocating the array shortly */ |
710 | while (p) { |
709 | while (p) { |
711 | p=strchr(p, ';'); |
710 | p=strchr(p, ';'); |
712 | number_of_entries++; |
711 | number_of_entries++; |
713 | if (p) p++; |
712 | if (p) p++; |
… | |
… | |
1249 | strcpy(filename, m->tmpname); |
1248 | strcpy(filename, m->tmpname); |
1250 | } |
1249 | } |
1251 | LOG(llevDebug,"Saving map %s\n",m->path); |
1250 | LOG(llevDebug,"Saving map %s\n",m->path); |
1252 | m->in_memory = MAP_SAVING; |
1251 | m->in_memory = MAP_SAVING; |
1253 | |
1252 | |
|
|
1253 | unlink (filename); // do not overwrite backups if done via hardlinks |
|
|
1254 | |
1254 | /* Compress if it isn't a temporary save. Do compress if unique */ |
1255 | /* Compress if it isn't a temporary save. Do compress if unique */ |
1255 | if (m->compressed && (m->unique || m->template || flag)) { |
1256 | if (m->compressed && (m->unique || m->template || flag)) { |
1256 | char buf[MAX_BUF]; |
1257 | char buf[MAX_BUF]; |
1257 | strcpy(buf, uncomp[m->compressed][2]); |
1258 | strcpy(buf, uncomp[m->compressed][2]); |
1258 | strcat(buf, " > "); |
1259 | strcat(buf, " > "); |
… | |
… | |
1616 | * have a difficulty set than using this function - human calculation |
1617 | * have a difficulty set than using this function - human calculation |
1617 | * is much better than this functions guesswork. |
1618 | * is much better than this functions guesswork. |
1618 | */ |
1619 | */ |
1619 | |
1620 | |
1620 | int calculate_difficulty(mapstruct *m) { |
1621 | int calculate_difficulty(mapstruct *m) { |
1621 | object *op; |
1622 | object *op; |
1622 | archetype *at; |
1623 | archetype *at; |
1623 | int x,y; |
1624 | int x, y, i, diff; |
1624 | int diff=0; |
1625 | long monster_cnt = 0; |
1625 | int i; |
1626 | double avgexp = 0; |
1626 | sint64 exp_pr_sq, total_exp=0; |
1627 | sint64 total_exp = 0; |
1627 | |
1628 | |
1628 | if (MAP_DIFFICULTY(m)) { |
1629 | if (MAP_DIFFICULTY (m)) |
|
|
1630 | { |
1629 | LOG(llevDebug, "Using stored map difficulty: %d\n", MAP_DIFFICULTY(m)); |
1631 | LOG(llevDebug, "Using stored map difficulty: %d\n", MAP_DIFFICULTY (m)); |
1630 | return MAP_DIFFICULTY(m); |
1632 | return MAP_DIFFICULTY (m); |
1631 | } |
|
|
1632 | |
|
|
1633 | for(x=0;x<MAP_WIDTH(m);x++) |
|
|
1634 | for(y=0;y<MAP_HEIGHT(m);y++) |
|
|
1635 | for(op=get_map_ob(m,x,y);op!=NULL;op=op->above) { |
|
|
1636 | if(QUERY_FLAG(op,FLAG_MONSTER)) |
|
|
1637 | total_exp+=op->stats.exp; |
|
|
1638 | if(QUERY_FLAG(op,FLAG_GENERATOR)) { |
|
|
1639 | total_exp+=op->stats.exp; |
|
|
1640 | at=type_to_archetype(GENERATE_TYPE(op)); |
|
|
1641 | if(at!=NULL) |
|
|
1642 | total_exp+=at->clone.stats.exp*8; |
|
|
1643 | } |
|
|
1644 | } |
1633 | } |
1645 | #ifdef NEWCALC |
1634 | |
1646 | (int)exp_pr_sq=((double)1000*total_exp)/(m->map_object->x*m->map_object->y+1); |
1635 | for(x = 0; x < MAP_WIDTH(m); x++) |
1647 | for(i=20;i>0;i--) |
1636 | for(y = 0; y < MAP_HEIGHT(m); y++) |
1648 | if(exp_pr_sq>level_exp(i,1.0)) { |
1637 | for(op = get_map_ob(m, x, y); op != NULL; op = op->above) |
1649 | diff=i; |
1638 | { |
1650 | break; |
1639 | if(QUERY_FLAG (op, FLAG_MONSTER)) |
1651 | } |
1640 | { |
1652 | #else |
1641 | total_exp += op->stats.exp; |
1653 | exp_pr_sq=((double)1000*total_exp)/(MAP_WIDTH(m)*MAP_HEIGHT(m)+1); |
1642 | monster_cnt++; |
1654 | diff=20; |
1643 | } |
1655 | for(i=1;i<20;i++) |
1644 | |
1656 | if(exp_pr_sq<=level_exp(i,1.0)) { |
1645 | if(QUERY_FLAG (op, FLAG_GENERATOR)) |
1657 | diff=i; |
1646 | { |
1658 | break; |
1647 | total_exp += op->stats.exp; |
1659 | } |
1648 | at = type_to_archetype(GENERATE_TYPE (op)); |
1660 | #endif |
1649 | |
1661 | return diff; |
1650 | if(at != NULL) |
|
|
1651 | total_exp += at->clone.stats.exp * 8; |
|
|
1652 | |
|
|
1653 | monster_cnt++; |
|
|
1654 | } |
|
|
1655 | } |
|
|
1656 | |
|
|
1657 | avgexp = (double) total_exp / monster_cnt; |
|
|
1658 | |
|
|
1659 | for (i = 1; i <= settings.max_level; i++) |
|
|
1660 | { |
|
|
1661 | if ((level_exp (i, 1) - level_exp (i - 1, 1)) > (100 * avgexp)) |
|
|
1662 | { |
|
|
1663 | LOG(llevError, "Calculated difficulty for map: %s: %d\n", m->name, i); |
|
|
1664 | return i; |
|
|
1665 | } |
|
|
1666 | } |
1662 | } |
1667 | } |
1663 | |
1668 | |
1664 | void clean_tmp_map(mapstruct *m) { |
1669 | void clean_tmp_map(mapstruct *m) { |
1665 | if(m->tmpname == NULL) |
1670 | if(m->tmpname == NULL) |
1666 | return; |
1671 | return; |
… | |
… | |
1701 | return 0; |
1706 | return 0; |
1702 | } |
1707 | } |
1703 | |
1708 | |
1704 | /* inform all players on the map */ |
1709 | /* inform all players on the map */ |
1705 | if (change>0) |
1710 | if (change>0) |
1706 | new_info_map(NDI_BLACK, m,"It becomes darker."); |
1711 | new_info_map(NDI_BLACK|NDI_UNIQUE, m,"It becomes darker."); |
1707 | else |
1712 | else |
1708 | new_info_map(NDI_BLACK, m,"It becomes brighter."); |
1713 | new_info_map(NDI_BLACK|NDI_UNIQUE, m,"It becomes brighter."); |
1709 | |
1714 | |
1710 | /* Do extra checking. since m->darkness is a unsigned value, |
1715 | /* Do extra checking. since m->darkness is a unsigned value, |
1711 | * we need to be extra careful about negative values. |
1716 | * we need to be extra careful about negative values. |
1712 | * In general, the checks below are only needed if change |
1717 | * In general, the checks below are only needed if change |
1713 | * is not +/-1 |
1718 | * is not +/-1 |