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.8 2006/03/20 23:07:50 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 | */ |
… | |
… | |
676 | |
679 | |
677 | if(m->spaces==NULL) |
680 | if(m->spaces==NULL) |
678 | fatal(OUT_OF_MEMORY); |
681 | fatal(OUT_OF_MEMORY); |
679 | } |
682 | } |
680 | |
683 | |
681 | /* Creatures and returns a map of the specific size. Used |
684 | /* Create and returns a map of the specific size. Used |
682 | * in random map code and the editor. |
685 | * in random map code and the editor. |
683 | */ |
686 | */ |
684 | mapstruct *get_empty_map(int sizex, int sizey) { |
687 | mapstruct *get_empty_map(int sizex, int sizey) { |
685 | mapstruct *m = get_linked_map(); |
688 | mapstruct *m = get_linked_map(); |
686 | m->width = sizex; |
689 | m->width = sizex; |
… | |
… | |
1049 | close_and_delete(fp, comp); |
1052 | close_and_delete(fp, comp); |
1050 | m->in_memory=MAP_IN_MEMORY; |
1053 | m->in_memory=MAP_IN_MEMORY; |
1051 | if (!MAP_DIFFICULTY(m)) |
1054 | if (!MAP_DIFFICULTY(m)) |
1052 | MAP_DIFFICULTY(m)=calculate_difficulty(m); |
1055 | MAP_DIFFICULTY(m)=calculate_difficulty(m); |
1053 | set_map_reset_time(m); |
1056 | set_map_reset_time(m); |
|
|
1057 | if (load_original_map_callback) |
|
|
1058 | load_original_map_callback(m); |
1054 | return (m); |
1059 | return (m); |
1055 | } |
1060 | } |
1056 | |
1061 | |
1057 | /* |
1062 | /* |
1058 | * Loads a map, which has been loaded earlier, from file. |
1063 | * Loads a map, which has been loaded earlier, from file. |
… | |
… | |
1098 | |
1103 | |
1099 | m->in_memory=MAP_LOADING; |
1104 | m->in_memory=MAP_LOADING; |
1100 | load_objects (m, fp, 0); |
1105 | load_objects (m, fp, 0); |
1101 | close_and_delete(fp, comp); |
1106 | close_and_delete(fp, comp); |
1102 | m->in_memory=MAP_IN_MEMORY; |
1107 | m->in_memory=MAP_IN_MEMORY; |
|
|
1108 | if (load_temporary_map_callback) |
|
|
1109 | load_temporary_map_callback(m); |
1103 | return m; |
1110 | return m; |
1104 | } |
1111 | } |
1105 | |
1112 | |
1106 | /* |
1113 | /* |
1107 | * Loads a map, which has been loaded earlier, from file. |
1114 | * Loads a map, which has been loaded earlier, from file. |
… | |
… | |
1143 | *****************************************************************************/ |
1150 | *****************************************************************************/ |
1144 | |
1151 | |
1145 | /* This goes through map 'm' and removed any unique items on the map. */ |
1152 | /* This goes through map 'm' and removed any unique items on the map. */ |
1146 | static void delete_unique_items(mapstruct *m) |
1153 | static void delete_unique_items(mapstruct *m) |
1147 | { |
1154 | { |
1148 | int i,j,unique=0; |
1155 | int i,j,unique; |
1149 | object *op, *next; |
1156 | object *op, *next; |
1150 | |
1157 | |
1151 | for(i=0; i<MAP_WIDTH(m); i++) |
1158 | for(i=0; i<MAP_WIDTH(m); i++) |
1152 | for(j=0; j<MAP_HEIGHT(m); j++) { |
1159 | for(j=0; j<MAP_HEIGHT(m); j++) { |
1153 | unique=0; |
1160 | unique=0; |
… | |
… | |
1657 | } |
1664 | } |
1658 | |
1665 | |
1659 | void clean_tmp_map(mapstruct *m) { |
1666 | void clean_tmp_map(mapstruct *m) { |
1660 | if(m->tmpname == NULL) |
1667 | if(m->tmpname == NULL) |
1661 | return; |
1668 | return; |
|
|
1669 | if (clean_temporary_map_callback) |
|
|
1670 | clean_temporary_map_callback (m); |
1662 | (void) unlink(m->tmpname); |
1671 | (void) unlink(m->tmpname); |
1663 | } |
1672 | } |
1664 | |
1673 | |
1665 | void free_all_maps(void) |
1674 | void free_all_maps(void) |
1666 | { |
1675 | { |