ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/map.c
(Generate patch)

Comparing deliantra/server/common/map.c (file contents):
Revision 1.4 by elmex, Wed Feb 22 18:53:48 2006 UTC vs.
Revision 1.8 by root, Mon Mar 20 23:07:50 2006 UTC

1/* 1/*
2 * static char *rcsid_map_c = 2 * static char *rcsid_map_c =
3 * "$Id: map.c,v 1.4 2006/02/22 18:53:48 elmex 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
41extern int nrofallocobjects,nroffreeobjects; 41extern int nrofallocobjects,nroffreeobjects;
42 42
43void (*load_original_map_callback)(mapstruct *map);
44void (*load_temporary_map_callback)(mapstruct *map);
45void (*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 */
684mapstruct *get_empty_map(int sizex, int sizey) { 687mapstruct *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. */
1146static void delete_unique_items(mapstruct *m) 1153static 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
1659void clean_tmp_map(mapstruct *m) { 1666void 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
1665void free_all_maps(void) 1674void free_all_maps(void)
1666{ 1675{
2037 */ 2046 */
2038 2047
2039 return m; 2048 return m;
2040} 2049}
2041 2050
2042// return wether map2 is adjacent to map1 and store their distance
2043// in dx/dy if yes.
2044static int adjacent_map (mapstruct *map1, mapstruct *map2, int *dx, int *dy)
2045{
2046 if (!map1 || !map2)
2047 return 0;
2048
2049 else if (map1 == map2)
2050 *dx = *dy = 0;
2051
2052 else if (map1->tile_map[0] == map2) // up
2053 (*dx = 0), (*dy = -MAP_HEIGHT (map2));
2054 else if (map1->tile_map[1] == map2) // right
2055 (*dx = MAP_WIDTH (map2)), (*dy = 0);
2056 else if (map1->tile_map[2] == map2) // down
2057 (*dx = 0), (*dy = MAP_HEIGHT (map2));
2058 else if (map1->tile_map[3] == map2) // left
2059 (*dx = -MAP_WIDTH (map2)), (*dy = 0);
2060
2061 else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[1] == map2) // up right
2062 (*dx = MAP_WIDTH (map2)), (*dy = -MAP_HEIGHT (map1->tile_map[0]));
2063 else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[3] == map2) // up left
2064 (*dx = -MAP_WIDTH (map2)), (*dy = -MAP_HEIGHT (map1->tile_map[0]));
2065 else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[0] == map2) // right up
2066 (*dx = MAP_HEIGHT (map1->tile_map[1])), (*dy = -MAP_WIDTH (map2));
2067 else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[2] == map2) // right down
2068 (*dx = MAP_HEIGHT (map1->tile_map[1])), (*dy = MAP_WIDTH (map2));
2069 else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[1] == map2) // down right
2070 (*dx = MAP_WIDTH (map2)), (*dy = MAP_HEIGHT (map1->tile_map[2]));
2071 else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[3] == map2) // down left
2072 (*dx = -MAP_WIDTH (map2)), (*dy = MAP_HEIGHT (map1->tile_map[2]));
2073 else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[0] == map2) // left up
2074 (*dx = -MAP_HEIGHT (map1->tile_map[3])), (*dy = -MAP_WIDTH (map2));
2075 else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[2] == map2) // left down
2076 (*dx = MAP_HEIGHT (map1->tile_map[3])), (*dy = MAP_WIDTH (map2));
2077
2078 else // not "adjacent" enough
2079 return 0;
2080
2081 return 1;
2082}
2083
2084/** 2051/**
2085 * Return whether map2 is adjacent to map1. If so, store the distance from 2052 * Return whether map2 is adjacent to map1. If so, store the distance from
2086 * map1 to map2 in dx/dy. 2053 * map1 to map2 in dx/dy.
2087 */ 2054 */
2088static int adjacent_map(const mapstruct *map1, const mapstruct *map2, int *dx, int *dy) { 2055static int adjacent_map(const mapstruct *map1, const mapstruct *map2, int *dx, int *dy) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines