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.13 by elmex, Tue Aug 29 09:35: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.13 2006/08/29 09:35:51 elmex 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
1015 * 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
1016 * managed map list. 1016 * managed map list.
1017 */ 1017 */
1018 1018
1019mapstruct *load_original_map(const char *filename, int flags) { 1019mapstruct *load_original_map(const char *filename, int flags) {
1020 FILE *fp;
1021 mapstruct *m; 1020 mapstruct *m;
1022 int comp;
1023 char pathname[MAX_BUF]; 1021 char pathname[MAX_BUF];
1024 1022
1025 LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags); 1023 LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags);
1026 if (flags & MAP_PLAYER_UNIQUE) 1024 if (flags & MAP_PLAYER_UNIQUE)
1027 strcpy(pathname, filename); 1025 strcpy(pathname, filename);
1028 else if (flags & MAP_OVERLAY) 1026 else if (flags & MAP_OVERLAY)
1029 strcpy(pathname, create_overlay_pathname(filename)); 1027 strcpy(pathname, create_overlay_pathname(filename));
1030 else 1028 else
1031 strcpy(pathname, create_pathname(filename)); 1029 strcpy(pathname, create_pathname(filename));
1032 1030
1033 if((fp=open_and_uncompress(pathname, 0, &comp))==NULL) {
1034 LOG(llevError, "Can't open %s: %s\n", pathname, strerror_local(errno));
1035 return (NULL);
1036 }
1037
1038 object_thawer thawer (fp, filename); 1031 object_thawer thawer (pathname);
1032
1033 if (!thawer)
1034 return 0;
1039 1035
1040 m = get_linked_map(); 1036 m = get_linked_map();
1041 1037
1042 strcpy (m->path, filename); 1038 strcpy (m->path, filename);
1043 if (load_map_header(thawer, m)) { 1039 if (load_map_header(thawer, m)) {
1049 1045
1050 allocate_map(m); 1046 allocate_map(m);
1051 1047
1052 m->in_memory=MAP_LOADING; 1048 m->in_memory=MAP_LOADING;
1053 load_objects (m, thawer, flags & (MAP_BLOCK|MAP_STYLE)); 1049 load_objects (m, thawer, flags & (MAP_BLOCK|MAP_STYLE));
1054 close_and_delete(fp, comp); 1050
1055 m->in_memory=MAP_IN_MEMORY; 1051 m->in_memory=MAP_IN_MEMORY;
1056 if (!MAP_DIFFICULTY(m)) 1052 if (!MAP_DIFFICULTY(m))
1057 MAP_DIFFICULTY(m)=calculate_difficulty(m); 1053 MAP_DIFFICULTY(m)=calculate_difficulty(m);
1058 set_map_reset_time(m); 1054 set_map_reset_time(m);
1059 m->instantiate (); 1055 m->instantiate ();
1065 * 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
1066 * option if we can't find the original map) 1062 * option if we can't find the original map)
1067 */ 1063 */
1068 1064
1069static mapstruct *load_temporary_map(mapstruct *m) { 1065static mapstruct *load_temporary_map(mapstruct *m) {
1070 FILE *fp;
1071 int comp; 1066 int comp;
1072 char buf[MAX_BUF]; 1067 char buf[MAX_BUF];
1073 1068
1074 if (!m->tmpname) { 1069 if (!m->tmpname) {
1075 LOG(llevError, "No temporary filename for map %s\n", m->path); 1070 LOG(llevError, "No temporary filename for map %s\n", m->path);
1079 if(m==NULL) return NULL; 1074 if(m==NULL) return NULL;
1080 fix_auto_apply(m); /* Chests which open as default */ 1075 fix_auto_apply(m); /* Chests which open as default */
1081 return m; 1076 return m;
1082 } 1077 }
1083 1078
1084 if((fp=open_and_uncompress(m->tmpname,0, &comp))==NULL) { 1079 object_thawer thawer (m->tmpname);
1085 LOG(llevError, "Cannot open %s: %s\n",m->tmpname, strerror_local(errno)); 1080
1081 if (!thawer)
1082 {
1086 strcpy(buf, m->path); 1083 strcpy (buf, m->path);
1087 delete_map(m); 1084 delete_map (m);
1088 m = load_original_map(buf, 0); 1085 m = load_original_map (buf, 0);
1089 if(m==NULL) return NULL; 1086 if (!m) return NULL;
1090 fix_auto_apply(m); /* Chests which open as default */ 1087 fix_auto_apply (m); /* Chests which open as default */
1091 return m; 1088 return m;
1092 } 1089 }
1093
1094 object_thawer thawer (fp, m->tmpname);
1095 1090
1096 if (load_map_header(thawer, m)) { 1091 if (load_map_header(thawer, m)) {
1097 LOG(llevError,"Error loading map header for %s (%s)\n", 1092 LOG(llevError,"Error loading map header for %s (%s)\n",
1098 m->path, m->tmpname); 1093 m->path, m->tmpname);
1099 delete_map(m); 1094 delete_map(m);
1102 } 1097 }
1103 allocate_map(m); 1098 allocate_map(m);
1104 1099
1105 m->in_memory=MAP_LOADING; 1100 m->in_memory=MAP_LOADING;
1106 load_objects (m, thawer, 0); 1101 load_objects (m, thawer, 0);
1107 close_and_delete(fp, comp); 1102
1108 m->in_memory=MAP_IN_MEMORY; 1103 m->in_memory=MAP_IN_MEMORY;
1109 INVOKE_MAP (SWAPIN, m); 1104 INVOKE_MAP (SWAPIN, m);
1110 return m; 1105 return m;
1111} 1106}
1112 1107
1115 * 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
1116 * option if we can't find the original map) 1111 * option if we can't find the original map)
1117 */ 1112 */
1118 1113
1119mapstruct *load_overlay_map(const char *filename, mapstruct *m) { 1114mapstruct *load_overlay_map(const char *filename, mapstruct *m) {
1120 FILE *fp;
1121 int comp;
1122 char pathname[MAX_BUF]; 1115 char pathname[MAX_BUF];
1123 1116
1124 strcpy(pathname, create_overlay_pathname(filename)); 1117 strcpy(pathname, create_overlay_pathname(filename));
1125 1118
1126 if((fp=open_and_uncompress(pathname, 0, &comp))==NULL) {
1127/* LOG(llevDebug,"Can't open overlay %s\n", pathname);*/
1128 return m;
1129 }
1130
1131 object_thawer thawer (fp, pathname); 1119 object_thawer thawer (pathname);
1120
1121 if (!thawer)
1122 return m;
1132 1123
1133 if (load_map_header(thawer, m)) { 1124 if (load_map_header(thawer, m)) {
1134 LOG(llevError,"Error loading map header for overlay %s (%s)\n", 1125 LOG(llevError,"Error loading map header for overlay %s (%s)\n",
1135 m->path, pathname); 1126 m->path, pathname);
1136 delete_map(m); 1127 delete_map(m);
1139 } 1130 }
1140 /*allocate_map(m);*/ 1131 /*allocate_map(m);*/
1141 1132
1142 m->in_memory=MAP_LOADING; 1133 m->in_memory=MAP_LOADING;
1143 load_objects (m, thawer, MAP_OVERLAY); 1134 load_objects (m, thawer, MAP_OVERLAY);
1144 close_and_delete(fp, comp); 1135
1145 m->in_memory=MAP_IN_MEMORY; 1136 m->in_memory=MAP_IN_MEMORY;
1146 return m; 1137 return m;
1147} 1138}
1148 1139
1149/****************************************************************************** 1140/******************************************************************************
1178/* 1169/*
1179 * 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
1180 * m is the map to load unique items into. 1171 * m is the map to load unique items into.
1181 */ 1172 */
1182static void load_unique_objects(mapstruct *m) { 1173static void load_unique_objects(mapstruct *m) {
1183 FILE *fp;
1184 int comp,count; 1174 int count;
1185 char firstname[MAX_BUF]; 1175 char firstname[MAX_BUF];
1186 1176
1187 for (count=0; count<10; count++) { 1177 for (count=0; count<10; count++) {
1188 sprintf(firstname, "%s.v%02d", create_items_path(m->path), count); 1178 sprintf(firstname, "%s.v%02d", create_items_path(m->path), count);
1189 if (!access(firstname, R_OK)) break; 1179 if (!access(firstname, R_OK)) break;
1190 } 1180 }
1191 /* If we get here, we did not find any map */ 1181 /* If we get here, we did not find any map */
1192 if (count==10) return; 1182 if (count==10) return;
1193 1183
1194 if ((fp=open_and_uncompress(firstname, 0, &comp))==NULL) {
1195 /* There is no expectation that every map will have unique items, but this
1196 * is debug output, so leave it in.
1197 */
1198 LOG(llevDebug, "Can't open unique items file for %s\n", create_items_path(m->path));
1199 return;
1200 }
1201
1202 object_thawer thawer (fp, firstname); 1184 object_thawer thawer (firstname);
1203 1185
1204 m->in_memory=MAP_LOADING; 1186 m->in_memory=MAP_LOADING;
1205 if (m->tmpname == NULL) /* if we have loaded unique items from */ 1187 if (m->tmpname == NULL) /* if we have loaded unique items from */
1206 delete_unique_items(m); /* original map before, don't duplicate them */ 1188 delete_unique_items(m); /* original map before, don't duplicate them */
1207 load_object(thawer, NULL, LO_NOREAD,0); 1189 load_object(thawer, NULL, LO_NOREAD,0);
1208 load_objects (m, thawer, 0); 1190 load_objects (m, thawer, 0);
1209 close_and_delete(fp, comp); 1191
1210 m->in_memory=MAP_IN_MEMORY; 1192 m->in_memory=MAP_IN_MEMORY;
1211} 1193}
1212 1194
1213 1195
1214/* 1196/*

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines