1 | /* |
1 | /* |
2 | * static char *rcsid_map_c = |
2 | * static char *rcsid_map_c = |
3 | * "$Id: map.c,v 1.5 2006/02/22 19:08:43 root Exp $"; |
3 | * "$Id: map.c,v 1.9 2006/03/28 06:54:31 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 | |
… | |
… | |
38 | #include "path.h" |
38 | #include "path.h" |
39 | |
39 | |
40 | |
40 | |
41 | extern int nrofallocobjects,nroffreeobjects; |
41 | extern int nrofallocobjects,nroffreeobjects; |
42 | |
42 | |
|
|
43 | void (*load_original_map_callback)(mapstruct *map); |
|
|
44 | void (*load_temporary_map_callback)(mapstruct *map); |
|
|
45 | void (*clean_temporary_map_callback)(mapstruct *map); |
43 | |
46 | |
44 | /* |
47 | /* |
45 | * Returns the mapstruct which has a name matching the given argument. |
48 | * Returns the mapstruct which has a name matching the given argument. |
46 | * return NULL if no match is found. |
49 | * return NULL if no match is found. |
47 | */ |
50 | */ |
… | |
… | |
587 | * 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 |
588 | * in order to do map tiling properly. |
591 | * in order to do map tiling properly. |
589 | */ |
592 | */ |
590 | void save_objects (mapstruct *m, FILE *fp, FILE *fp2, int flag) { |
593 | void save_objects (mapstruct *m, FILE *fp, FILE *fp2, int flag) { |
591 | int i, j = 0,unique=0; |
594 | int i, j = 0,unique=0; |
592 | object *op, *otmp; |
595 | object *op; |
593 | /* first pass - save one-part objects */ |
596 | /* first pass - save one-part objects */ |
594 | for(i = 0; i < MAP_WIDTH(m); i++) |
597 | for(i = 0; i < MAP_WIDTH(m); i++) |
595 | for (j = 0; j < MAP_HEIGHT(m); j++) { |
598 | for (j = 0; j < MAP_HEIGHT(m); j++) { |
596 | unique=0; |
599 | unique=0; |
597 | for(op = get_map_ob (m, i, j); op; op = otmp) { |
600 | for(op = get_map_ob (m, i, j); op; op = op->above) { |
598 | otmp = op->above; |
|
|
599 | |
|
|
600 | 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)) |
601 | unique=1; |
602 | unique=1; |
602 | |
603 | |
603 | if(op->type == PLAYER) { |
604 | if(op->type == PLAYER) { |
604 | LOG(llevDebug, "Player on map that is being saved\n"); |
605 | LOG(llevDebug, "Player on map that is being saved\n"); |
… | |
… | |
676 | |
677 | |
677 | if(m->spaces==NULL) |
678 | if(m->spaces==NULL) |
678 | fatal(OUT_OF_MEMORY); |
679 | fatal(OUT_OF_MEMORY); |
679 | } |
680 | } |
680 | |
681 | |
681 | /* Creatures and returns a map of the specific size. Used |
682 | /* Create and returns a map of the specific size. Used |
682 | * in random map code and the editor. |
683 | * in random map code and the editor. |
683 | */ |
684 | */ |
684 | mapstruct *get_empty_map(int sizex, int sizey) { |
685 | mapstruct *get_empty_map(int sizex, int sizey) { |
685 | mapstruct *m = get_linked_map(); |
686 | mapstruct *m = get_linked_map(); |
686 | m->width = sizex; |
687 | m->width = sizex; |
… | |
… | |
1049 | close_and_delete(fp, comp); |
1050 | close_and_delete(fp, comp); |
1050 | m->in_memory=MAP_IN_MEMORY; |
1051 | m->in_memory=MAP_IN_MEMORY; |
1051 | if (!MAP_DIFFICULTY(m)) |
1052 | if (!MAP_DIFFICULTY(m)) |
1052 | MAP_DIFFICULTY(m)=calculate_difficulty(m); |
1053 | MAP_DIFFICULTY(m)=calculate_difficulty(m); |
1053 | set_map_reset_time(m); |
1054 | set_map_reset_time(m); |
|
|
1055 | if (load_original_map_callback) |
|
|
1056 | load_original_map_callback(m); |
1054 | return (m); |
1057 | return (m); |
1055 | } |
1058 | } |
1056 | |
1059 | |
1057 | /* |
1060 | /* |
1058 | * Loads a map, which has been loaded earlier, from file. |
1061 | * Loads a map, which has been loaded earlier, from file. |
… | |
… | |
1098 | |
1101 | |
1099 | m->in_memory=MAP_LOADING; |
1102 | m->in_memory=MAP_LOADING; |
1100 | load_objects (m, fp, 0); |
1103 | load_objects (m, fp, 0); |
1101 | close_and_delete(fp, comp); |
1104 | close_and_delete(fp, comp); |
1102 | m->in_memory=MAP_IN_MEMORY; |
1105 | m->in_memory=MAP_IN_MEMORY; |
|
|
1106 | if (load_temporary_map_callback) |
|
|
1107 | load_temporary_map_callback(m); |
1103 | return m; |
1108 | return m; |
1104 | } |
1109 | } |
1105 | |
1110 | |
1106 | /* |
1111 | /* |
1107 | * Loads a map, which has been loaded earlier, from file. |
1112 | * Loads a map, which has been loaded earlier, from file. |
… | |
… | |
1143 | *****************************************************************************/ |
1148 | *****************************************************************************/ |
1144 | |
1149 | |
1145 | /* This goes through map 'm' and removed any unique items on the map. */ |
1150 | /* This goes through map 'm' and removed any unique items on the map. */ |
1146 | static void delete_unique_items(mapstruct *m) |
1151 | static void delete_unique_items(mapstruct *m) |
1147 | { |
1152 | { |
1148 | int i,j,unique=0; |
1153 | int i,j,unique; |
1149 | object *op, *next; |
1154 | object *op, *next; |
1150 | |
1155 | |
1151 | for(i=0; i<MAP_WIDTH(m); i++) |
1156 | for(i=0; i<MAP_WIDTH(m); i++) |
1152 | for(j=0; j<MAP_HEIGHT(m); j++) { |
1157 | for(j=0; j<MAP_HEIGHT(m); j++) { |
1153 | unique=0; |
1158 | unique=0; |
… | |
… | |
1657 | } |
1662 | } |
1658 | |
1663 | |
1659 | void clean_tmp_map(mapstruct *m) { |
1664 | void clean_tmp_map(mapstruct *m) { |
1660 | if(m->tmpname == NULL) |
1665 | if(m->tmpname == NULL) |
1661 | return; |
1666 | return; |
|
|
1667 | if (clean_temporary_map_callback) |
|
|
1668 | clean_temporary_map_callback (m); |
1662 | (void) unlink(m->tmpname); |
1669 | (void) unlink(m->tmpname); |
1663 | } |
1670 | } |
1664 | |
1671 | |
1665 | void free_all_maps(void) |
1672 | void free_all_maps(void) |
1666 | { |
1673 | { |