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.12 by root, Mon Aug 28 16:52:51 2006 UTC vs.
Revision 1.14 by root, Wed Aug 30 06:06:26 2006 UTC

1/* 1/*
2 * static char *rcsid_map_c = 2 * static char *rcsid_map_c =
3 * "$Id: map.C,v 1.12 2006/08/28 16:52:51 root Exp $"; 3 * "$Id: map.C,v 1.14 2006/08/30 06:06:26 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
949 m->winddir = atoi(value); 949 m->winddir = atoi(value);
950 } else if (!strcmp(key, "sky")) { 950 } else if (!strcmp(key, "sky")) {
951 m->sky = atoi(value); 951 m->sky = atoi(value);
952 } else if (!strcmp(key, "nosmooth")) { 952 } else if (!strcmp(key, "nosmooth")) {
953 m->nosmooth = atoi(value); 953 m->nosmooth = atoi(value);
954 } else if (!strcmp(key, "safe_map")) {
955 m->safe_map = atoi(value);
956 } 954 }
957 else if (!strncmp(key,"tile_path_", 10)) { 955 else if (!strncmp(key,"tile_path_", 10)) {
958 int tile=atoi(key+10); 956 int tile=atoi(key+10);
959 957
960 if (tile<1 || tile>4) { 958 if (tile<1 || tile>4) {
1017 * MAP_STYLE: style map - don't add active objects, don't add to server 1015 * MAP_STYLE: style map - don't add active objects, don't add to server
1018 * managed map list. 1016 * managed map list.
1019 */ 1017 */
1020 1018
1021mapstruct *load_original_map(const char *filename, int flags) { 1019mapstruct *load_original_map(const char *filename, int flags) {
1022 FILE *fp;
1023 mapstruct *m; 1020 mapstruct *m;
1024 int comp;
1025 char pathname[MAX_BUF]; 1021 char pathname[MAX_BUF];
1026 1022
1027 LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags); 1023 LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags);
1028 if (flags & MAP_PLAYER_UNIQUE) 1024 if (flags & MAP_PLAYER_UNIQUE)
1029 strcpy(pathname, filename); 1025 strcpy(pathname, filename);
1030 else if (flags & MAP_OVERLAY) 1026 else if (flags & MAP_OVERLAY)
1031 strcpy(pathname, create_overlay_pathname(filename)); 1027 strcpy(pathname, create_overlay_pathname(filename));
1032 else 1028 else
1033 strcpy(pathname, create_pathname(filename)); 1029 strcpy(pathname, create_pathname(filename));
1034 1030
1035 if((fp=open_and_uncompress(pathname, 0, &comp))==NULL) {
1036 LOG(llevError, "Can't open %s: %s\n", pathname, strerror_local(errno));
1037 return (NULL);
1038 }
1039
1040 object_thawer thawer (fp, filename); 1031 object_thawer thawer (pathname);
1032
1033 if (!thawer)
1034 return 0;
1041 1035
1042 m = get_linked_map(); 1036 m = get_linked_map();
1043 1037
1044 strcpy (m->path, filename); 1038 strcpy (m->path, filename);
1045 if (load_map_header(thawer, m)) { 1039 if (load_map_header(thawer, m)) {
1051 1045
1052 allocate_map(m); 1046 allocate_map(m);
1053 1047
1054 m->in_memory=MAP_LOADING; 1048 m->in_memory=MAP_LOADING;
1055 load_objects (m, thawer, flags & (MAP_BLOCK|MAP_STYLE)); 1049 load_objects (m, thawer, flags & (MAP_BLOCK|MAP_STYLE));
1056 close_and_delete(fp, comp); 1050
1057 m->in_memory=MAP_IN_MEMORY; 1051 m->in_memory=MAP_IN_MEMORY;
1058 if (!MAP_DIFFICULTY(m)) 1052 if (!MAP_DIFFICULTY(m))
1059 MAP_DIFFICULTY(m)=calculate_difficulty(m); 1053 MAP_DIFFICULTY(m)=calculate_difficulty(m);
1060 set_map_reset_time(m); 1054 set_map_reset_time(m);
1061 m->instantiate (); 1055 m->instantiate ();
1067 * Return the map object we load into (this can change from the passed 1061 * Return the map object we load into (this can change from the passed
1068 * option if we can't find the original map) 1062 * option if we can't find the original map)
1069 */ 1063 */
1070 1064
1071static mapstruct *load_temporary_map(mapstruct *m) { 1065static mapstruct *load_temporary_map(mapstruct *m) {
1072 FILE *fp;
1073 int comp; 1066 int comp;
1074 char buf[MAX_BUF]; 1067 char buf[MAX_BUF];
1075 1068
1076 if (!m->tmpname) { 1069 if (!m->tmpname) {
1077 LOG(llevError, "No temporary filename for map %s\n", m->path); 1070 LOG(llevError, "No temporary filename for map %s\n", m->path);
1081 if(m==NULL) return NULL; 1074 if(m==NULL) return NULL;
1082 fix_auto_apply(m); /* Chests which open as default */ 1075 fix_auto_apply(m); /* Chests which open as default */
1083 return m; 1076 return m;
1084 } 1077 }
1085 1078
1086 if((fp=open_and_uncompress(m->tmpname,0, &comp))==NULL) { 1079 object_thawer thawer (m->tmpname);
1087 LOG(llevError, "Cannot open %s: %s\n",m->tmpname, strerror_local(errno)); 1080
1081 if (!thawer)
1082 {
1088 strcpy(buf, m->path); 1083 strcpy (buf, m->path);
1089 delete_map(m); 1084 delete_map (m);
1090 m = load_original_map(buf, 0); 1085 m = load_original_map (buf, 0);
1091 if(m==NULL) return NULL; 1086 if (!m) return NULL;
1092 fix_auto_apply(m); /* Chests which open as default */ 1087 fix_auto_apply (m); /* Chests which open as default */
1093 return m; 1088 return m;
1094 } 1089 }
1095
1096 object_thawer thawer (fp, m->tmpname);
1097 1090
1098 if (load_map_header(thawer, m)) { 1091 if (load_map_header(thawer, m)) {
1099 LOG(llevError,"Error loading map header for %s (%s)\n", 1092 LOG(llevError,"Error loading map header for %s (%s)\n",
1100 m->path, m->tmpname); 1093 m->path, m->tmpname);
1101 delete_map(m); 1094 delete_map(m);
1104 } 1097 }
1105 allocate_map(m); 1098 allocate_map(m);
1106 1099
1107 m->in_memory=MAP_LOADING; 1100 m->in_memory=MAP_LOADING;
1108 load_objects (m, thawer, 0); 1101 load_objects (m, thawer, 0);
1109 close_and_delete(fp, comp); 1102
1110 m->in_memory=MAP_IN_MEMORY; 1103 m->in_memory=MAP_IN_MEMORY;
1111 INVOKE_MAP (SWAPIN, m); 1104 INVOKE_MAP (SWAPIN, m);
1112 return m; 1105 return m;
1113} 1106}
1114 1107
1117 * Return the map object we load into (this can change from the passed 1110 * Return the map object we load into (this can change from the passed
1118 * option if we can't find the original map) 1111 * option if we can't find the original map)
1119 */ 1112 */
1120 1113
1121mapstruct *load_overlay_map(const char *filename, mapstruct *m) { 1114mapstruct *load_overlay_map(const char *filename, mapstruct *m) {
1122 FILE *fp;
1123 int comp;
1124 char pathname[MAX_BUF]; 1115 char pathname[MAX_BUF];
1125 1116
1126 strcpy(pathname, create_overlay_pathname(filename)); 1117 strcpy(pathname, create_overlay_pathname(filename));
1127 1118
1128 if((fp=open_and_uncompress(pathname, 0, &comp))==NULL) {
1129/* LOG(llevDebug,"Can't open overlay %s\n", pathname);*/
1130 return m;
1131 }
1132
1133 object_thawer thawer (fp, pathname); 1119 object_thawer thawer (pathname);
1120
1121 if (!thawer)
1122 return m;
1134 1123
1135 if (load_map_header(thawer, m)) { 1124 if (load_map_header(thawer, m)) {
1136 LOG(llevError,"Error loading map header for overlay %s (%s)\n", 1125 LOG(llevError,"Error loading map header for overlay %s (%s)\n",
1137 m->path, pathname); 1126 m->path, pathname);
1138 delete_map(m); 1127 delete_map(m);
1141 } 1130 }
1142 /*allocate_map(m);*/ 1131 /*allocate_map(m);*/
1143 1132
1144 m->in_memory=MAP_LOADING; 1133 m->in_memory=MAP_LOADING;
1145 load_objects (m, thawer, MAP_OVERLAY); 1134 load_objects (m, thawer, MAP_OVERLAY);
1146 close_and_delete(fp, comp); 1135
1147 m->in_memory=MAP_IN_MEMORY; 1136 m->in_memory=MAP_IN_MEMORY;
1148 return m; 1137 return m;
1149} 1138}
1150 1139
1151/****************************************************************************** 1140/******************************************************************************
1180/* 1169/*
1181 * Loads unique objects from file(s) into the map which is in memory 1170 * Loads unique objects from file(s) into the map which is in memory
1182 * m is the map to load unique items into. 1171 * m is the map to load unique items into.
1183 */ 1172 */
1184static void load_unique_objects(mapstruct *m) { 1173static void load_unique_objects(mapstruct *m) {
1185 FILE *fp;
1186 int comp,count; 1174 int count;
1187 char firstname[MAX_BUF]; 1175 char firstname[MAX_BUF];
1188 1176
1189 for (count=0; count<10; count++) { 1177 for (count=0; count<10; count++) {
1190 sprintf(firstname, "%s.v%02d", create_items_path(m->path), count); 1178 sprintf(firstname, "%s.v%02d", create_items_path(m->path), count);
1191 if (!access(firstname, R_OK)) break; 1179 if (!access(firstname, R_OK)) break;
1192 } 1180 }
1193 /* If we get here, we did not find any map */ 1181 /* If we get here, we did not find any map */
1194 if (count==10) return; 1182 if (count==10) return;
1195 1183
1196 if ((fp=open_and_uncompress(firstname, 0, &comp))==NULL) {
1197 /* There is no expectation that every map will have unique items, but this
1198 * is debug output, so leave it in.
1199 */
1200 LOG(llevDebug, "Can't open unique items file for %s\n", create_items_path(m->path));
1201 return;
1202 }
1203
1204 object_thawer thawer (fp, firstname); 1184 object_thawer thawer (firstname);
1205 1185
1206 m->in_memory=MAP_LOADING; 1186 m->in_memory=MAP_LOADING;
1207 if (m->tmpname == NULL) /* if we have loaded unique items from */ 1187 if (m->tmpname == NULL) /* if we have loaded unique items from */
1208 delete_unique_items(m); /* original map before, don't duplicate them */ 1188 delete_unique_items(m); /* original map before, don't duplicate them */
1209 load_object(thawer, NULL, LO_NOREAD,0); 1189 load_object(thawer, NULL, LO_NOREAD,0);
1210 load_objects (m, thawer, 0); 1190 load_objects (m, thawer, 0);
1211 close_and_delete(fp, comp); 1191
1212 m->in_memory=MAP_IN_MEMORY; 1192 m->in_memory=MAP_IN_MEMORY;
1213} 1193}
1214 1194
1215 1195
1216/* 1196/*
1329 fprintf (fp, "winddir %d\n", m->winddir); 1309 fprintf (fp, "winddir %d\n", m->winddir);
1330 if (m->sky) 1310 if (m->sky)
1331 fprintf (fp, "sky %d\n", m->sky); 1311 fprintf (fp, "sky %d\n", m->sky);
1332 if (m->nosmooth) 1312 if (m->nosmooth)
1333 fprintf (fp, "nosmooth %d\n", m->nosmooth); 1313 fprintf (fp, "nosmooth %d\n", m->nosmooth);
1334 if (m->safe_map)
1335 fprintf (fp, "safe_map %d\n", m->safe_map);
1336 1314
1337 /* Save any tiling information, except on overlays */ 1315 /* Save any tiling information, except on overlays */
1338 if (flag != 2) 1316 if (flag != 2)
1339 for (i = 0; i < 4; i++) 1317 for (i = 0; i < 4; i++)
1340 if (m->tile_path[i]) 1318 if (m->tile_path[i])

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines