1 | /* |
1 | /* |
2 | * static char *rcsid_map_c = |
2 | * static char *rcsid_map_c = |
3 | * "$Id: map.c,v 1.12 2006/05/17 18:32:50 root Exp $"; |
3 | * "$Id: map.c,v 1.12.2.2 2006/08/10 20:18:02 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 | |
… | |
… | |
1617 | * have a difficulty set than using this function - human calculation |
1617 | * have a difficulty set than using this function - human calculation |
1618 | * is much better than this functions guesswork. |
1618 | * is much better than this functions guesswork. |
1619 | */ |
1619 | */ |
1620 | |
1620 | |
1621 | int calculate_difficulty(mapstruct *m) { |
1621 | int calculate_difficulty(mapstruct *m) { |
1622 | object *op; |
1622 | object *op; |
1623 | archetype *at; |
1623 | archetype *at; |
1624 | int x,y; |
1624 | int x, y, i, diff; |
1625 | int diff=0; |
1625 | long monster_cnt = 0; |
1626 | int i; |
1626 | double avgexp = 0; |
1627 | sint64 exp_pr_sq, total_exp=0; |
1627 | sint64 total_exp = 0; |
1628 | |
1628 | |
1629 | if (MAP_DIFFICULTY(m)) { |
1629 | if (MAP_DIFFICULTY (m)) |
|
|
1630 | { |
1630 | LOG(llevDebug, "Using stored map difficulty: %d\n", MAP_DIFFICULTY(m)); |
1631 | LOG(llevDebug, "Using stored map difficulty: %d\n", MAP_DIFFICULTY (m)); |
1631 | return MAP_DIFFICULTY(m); |
1632 | return MAP_DIFFICULTY (m); |
1632 | } |
|
|
1633 | |
|
|
1634 | for(x=0;x<MAP_WIDTH(m);x++) |
|
|
1635 | for(y=0;y<MAP_HEIGHT(m);y++) |
|
|
1636 | for(op=get_map_ob(m,x,y);op!=NULL;op=op->above) { |
|
|
1637 | if(QUERY_FLAG(op,FLAG_MONSTER)) |
|
|
1638 | total_exp+=op->stats.exp; |
|
|
1639 | if(QUERY_FLAG(op,FLAG_GENERATOR)) { |
|
|
1640 | total_exp+=op->stats.exp; |
|
|
1641 | at=type_to_archetype(GENERATE_TYPE(op)); |
|
|
1642 | if(at!=NULL) |
|
|
1643 | total_exp+=at->clone.stats.exp*8; |
|
|
1644 | } |
|
|
1645 | } |
1633 | } |
1646 | #ifdef NEWCALC |
1634 | |
1647 | (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++) |
1648 | for(i=20;i>0;i--) |
1636 | for(y = 0; y < MAP_HEIGHT(m); y++) |
1649 | if(exp_pr_sq>level_exp(i,1.0)) { |
1637 | for(op = get_map_ob(m, x, y); op != NULL; op = op->above) |
1650 | diff=i; |
1638 | { |
1651 | break; |
1639 | if(QUERY_FLAG (op, FLAG_MONSTER)) |
1652 | } |
1640 | { |
1653 | #else |
1641 | total_exp += op->stats.exp; |
1654 | exp_pr_sq=((double)1000*total_exp)/(MAP_WIDTH(m)*MAP_HEIGHT(m)+1); |
1642 | monster_cnt++; |
1655 | diff=20; |
1643 | } |
1656 | for(i=1;i<20;i++) |
1644 | |
1657 | if(exp_pr_sq<=level_exp(i,1.0)) { |
1645 | if(QUERY_FLAG (op, FLAG_GENERATOR)) |
1658 | diff=i; |
1646 | { |
1659 | break; |
1647 | total_exp += op->stats.exp; |
1660 | } |
1648 | at = type_to_archetype(GENERATE_TYPE (op)); |
1661 | #endif |
1649 | |
1662 | 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(llevDebug, "Calculated difficulty for map: %s: %d\n", m->name, i); */ |
|
|
1664 | return i; |
|
|
1665 | } |
|
|
1666 | } |
1663 | } |
1667 | } |
1664 | |
1668 | |
1665 | void clean_tmp_map(mapstruct *m) { |
1669 | void clean_tmp_map(mapstruct *m) { |
1666 | if(m->tmpname == NULL) |
1670 | if(m->tmpname == NULL) |
1667 | return; |
1671 | return; |