1 | /* |
1 | /* |
2 | * static char *rcsid_map_c = |
2 | * static char *rcsid_map_c = |
3 | * "$Id: map.c,v 1.7 2006/03/07 13:44:42 root Exp $"; |
3 | * "$Id: map.c,v 1.11 2006/05/12 23:42:59 root 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 | |
… | |
… | |
590 | * and we only save the head of multi part objects - this is needed |
590 | * and we only save the head of multi part objects - this is needed |
591 | * in order to do map tiling properly. |
591 | * in order to do map tiling properly. |
592 | */ |
592 | */ |
593 | void save_objects (mapstruct *m, FILE *fp, FILE *fp2, int flag) { |
593 | void save_objects (mapstruct *m, FILE *fp, FILE *fp2, int flag) { |
594 | int i, j = 0,unique=0; |
594 | int i, j = 0,unique=0; |
595 | object *op, *otmp; |
595 | object *op; |
596 | /* first pass - save one-part objects */ |
596 | /* first pass - save one-part objects */ |
597 | for(i = 0; i < MAP_WIDTH(m); i++) |
597 | for(i = 0; i < MAP_WIDTH(m); i++) |
598 | for (j = 0; j < MAP_HEIGHT(m); j++) { |
598 | for (j = 0; j < MAP_HEIGHT(m); j++) { |
599 | unique=0; |
599 | unique=0; |
600 | for(op = get_map_ob (m, i, j); op; op = otmp) { |
600 | for(op = get_map_ob (m, i, j); op; op = op->above) { |
601 | otmp = op->above; |
|
|
602 | |
|
|
603 | if (QUERY_FLAG(op,FLAG_IS_FLOOR) && QUERY_FLAG(op, FLAG_UNIQUE)) |
601 | if (QUERY_FLAG(op,FLAG_IS_FLOOR) && QUERY_FLAG(op, FLAG_UNIQUE)) |
604 | unique=1; |
602 | unique=1; |
605 | |
603 | |
606 | if(op->type == PLAYER) { |
604 | if(op->type == PLAYER) { |
607 | LOG(llevDebug, "Player on map that is being saved\n"); |
605 | LOG(llevDebug, "Player on map that is being saved\n"); |
… | |
… | |
679 | |
677 | |
680 | if(m->spaces==NULL) |
678 | if(m->spaces==NULL) |
681 | fatal(OUT_OF_MEMORY); |
679 | fatal(OUT_OF_MEMORY); |
682 | } |
680 | } |
683 | |
681 | |
684 | /* Creatures and returns a map of the specific size. Used |
682 | /* Create and returns a map of the specific size. Used |
685 | * in random map code and the editor. |
683 | * in random map code and the editor. |
686 | */ |
684 | */ |
687 | mapstruct *get_empty_map(int sizex, int sizey) { |
685 | mapstruct *get_empty_map(int sizex, int sizey) { |
688 | mapstruct *m = get_linked_map(); |
686 | mapstruct *m = get_linked_map(); |
689 | m->width = sizex; |
687 | m->width = sizex; |
… | |
… | |
705 | int i=0, number_of_entries=0; |
703 | int i=0, number_of_entries=0; |
706 | const typedata *current_type; |
704 | const typedata *current_type; |
707 | |
705 | |
708 | shop_string=strdup_local(input_string); |
706 | shop_string=strdup_local(input_string); |
709 | p=shop_string; |
707 | p=shop_string; |
710 | LOG(llevDebug, "parsing %s\n", input_string); |
|
|
711 | /* 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 */ |
712 | while (p) { |
709 | while (p) { |
713 | p=strchr(p, ';'); |
710 | p=strchr(p, ';'); |
714 | number_of_entries++; |
711 | number_of_entries++; |
715 | if (p) p++; |
712 | if (p) p++; |
… | |
… | |
1150 | *****************************************************************************/ |
1147 | *****************************************************************************/ |
1151 | |
1148 | |
1152 | /* This goes through map 'm' and removed any unique items on the map. */ |
1149 | /* This goes through map 'm' and removed any unique items on the map. */ |
1153 | static void delete_unique_items(mapstruct *m) |
1150 | static void delete_unique_items(mapstruct *m) |
1154 | { |
1151 | { |
1155 | int i,j,unique=0; |
1152 | int i,j,unique; |
1156 | object *op, *next; |
1153 | object *op, *next; |
1157 | |
1154 | |
1158 | for(i=0; i<MAP_WIDTH(m); i++) |
1155 | for(i=0; i<MAP_WIDTH(m); i++) |
1159 | for(j=0; j<MAP_HEIGHT(m); j++) { |
1156 | for(j=0; j<MAP_HEIGHT(m); j++) { |
1160 | unique=0; |
1157 | unique=0; |
… | |
… | |
1703 | return 0; |
1700 | return 0; |
1704 | } |
1701 | } |
1705 | |
1702 | |
1706 | /* inform all players on the map */ |
1703 | /* inform all players on the map */ |
1707 | if (change>0) |
1704 | if (change>0) |
1708 | new_info_map(NDI_BLACK, m,"It becomes darker."); |
1705 | new_info_map(NDI_BLACK|NDI_UNIQUE, m,"It becomes darker."); |
1709 | else |
1706 | else |
1710 | new_info_map(NDI_BLACK, m,"It becomes brighter."); |
1707 | new_info_map(NDI_BLACK|NDI_UNIQUE, m,"It becomes brighter."); |
1711 | |
1708 | |
1712 | /* Do extra checking. since m->darkness is a unsigned value, |
1709 | /* Do extra checking. since m->darkness is a unsigned value, |
1713 | * we need to be extra careful about negative values. |
1710 | * we need to be extra careful about negative values. |
1714 | * In general, the checks below are only needed if change |
1711 | * In general, the checks below are only needed if change |
1715 | * is not +/-1 |
1712 | * is not +/-1 |