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.11 by root, Mon Aug 28 16:12:59 2006 UTC vs.
Revision 1.16 by root, Wed Aug 30 16:30:37 2006 UTC

1/* 1/*
2 * static char *rcsid_map_c = 2 * static char *rcsid_map_c =
3 * "$Id: map.C,v 1.11 2006/08/28 16:12:59 root Exp $"; 3 * "$Id: map.C,v 1.16 2006/08/30 16:30:37 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
173 * Can not use strcat because we need to cycle through 173 * Can not use strcat because we need to cycle through
174 * all the names. 174 * all the names.
175 */ 175 */
176 endbuf = buf + strlen(buf); 176 endbuf = buf + strlen(buf);
177 177
178 for (i = 0; i < NROF_COMPRESS_METHODS; i++) {
179 if (uncomp[i][0])
180 strcpy(endbuf, uncomp[i][0]);
181 else
182 *endbuf = '\0';
183 if (!stat (buf, &statbuf)) 178 if (stat (buf, &statbuf))
184 break;
185 }
186 if (i == NROF_COMPRESS_METHODS)
187 return (-1); 179 return -1;
188 if (!S_ISREG (statbuf.st_mode)) 180 if (!S_ISREG (statbuf.st_mode))
189 return (-1); 181 return (-1);
190 182
191 if (((statbuf.st_mode & S_IRGRP) && getegid() == statbuf.st_gid) || 183 if (((statbuf.st_mode & S_IRGRP) && getegid() == statbuf.st_gid) ||
192 ((statbuf.st_mode & S_IRUSR) && geteuid() == statbuf.st_uid) || 184 ((statbuf.st_mode & S_IRUSR) && geteuid() == statbuf.st_uid) ||
895 * for compatibility reasons. The new values (second) are 887 * for compatibility reasons. The new values (second) are
896 * what really should be used. 888 * what really should be used.
897 */ 889 */
898 else if (!strcmp(key,"oid")) { 890 else if (!strcmp(key,"oid")) {
899 fp.get (m, atoi(value)); 891 fp.get (m, atoi(value));
892 } else if (!strcmp(key, "attach")) {
893 m->attach = add_string (value);
900 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) { 894 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) {
901 m->enter_x = atoi(value); 895 m->enter_x = atoi(value);
902 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) { 896 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) {
903 m->enter_y = atoi(value); 897 m->enter_y = atoi(value);
904 } else if (!strcmp(key,"x") || !strcmp(key, "width")) { 898 } else if (!strcmp(key,"x") || !strcmp(key, "width")) {
947 m->winddir = atoi(value); 941 m->winddir = atoi(value);
948 } else if (!strcmp(key, "sky")) { 942 } else if (!strcmp(key, "sky")) {
949 m->sky = atoi(value); 943 m->sky = atoi(value);
950 } else if (!strcmp(key, "nosmooth")) { 944 } else if (!strcmp(key, "nosmooth")) {
951 m->nosmooth = atoi(value); 945 m->nosmooth = atoi(value);
952 } else if (!strcmp(key, "safe_map")) {
953 m->safe_map = atoi(value);
954 } 946 }
955 else if (!strncmp(key,"tile_path_", 10)) { 947 else if (!strncmp(key,"tile_path_", 10)) {
956 int tile=atoi(key+10); 948 int tile=atoi(key+10);
957 949
958 if (tile<1 || tile>4) { 950 if (tile<1 || tile>4) {
1015 * MAP_STYLE: style map - don't add active objects, don't add to server 1007 * MAP_STYLE: style map - don't add active objects, don't add to server
1016 * managed map list. 1008 * managed map list.
1017 */ 1009 */
1018 1010
1019mapstruct *load_original_map(const char *filename, int flags) { 1011mapstruct *load_original_map(const char *filename, int flags) {
1020 FILE *fp;
1021 mapstruct *m; 1012 mapstruct *m;
1022 int comp;
1023 char pathname[MAX_BUF]; 1013 char pathname[MAX_BUF];
1024 1014
1025 LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags); 1015 LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags);
1026 if (flags & MAP_PLAYER_UNIQUE) 1016 if (flags & MAP_PLAYER_UNIQUE)
1027 strcpy(pathname, filename); 1017 strcpy(pathname, filename);
1028 else if (flags & MAP_OVERLAY) 1018 else if (flags & MAP_OVERLAY)
1029 strcpy(pathname, create_overlay_pathname(filename)); 1019 strcpy(pathname, create_overlay_pathname(filename));
1030 else 1020 else
1031 strcpy(pathname, create_pathname(filename)); 1021 strcpy(pathname, create_pathname(filename));
1032 1022
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); 1023 object_thawer thawer (pathname);
1024
1025 if (!thawer)
1026 return 0;
1039 1027
1040 m = get_linked_map(); 1028 m = get_linked_map();
1041 1029
1042 strcpy (m->path, filename); 1030 strcpy (m->path, filename);
1043 if (load_map_header(thawer, m)) { 1031 if (load_map_header(thawer, m)) {
1049 1037
1050 allocate_map(m); 1038 allocate_map(m);
1051 1039
1052 m->in_memory=MAP_LOADING; 1040 m->in_memory=MAP_LOADING;
1053 load_objects (m, thawer, flags & (MAP_BLOCK|MAP_STYLE)); 1041 load_objects (m, thawer, flags & (MAP_BLOCK|MAP_STYLE));
1054 close_and_delete(fp, comp); 1042
1055 m->in_memory=MAP_IN_MEMORY; 1043 m->in_memory=MAP_IN_MEMORY;
1056 if (!MAP_DIFFICULTY(m)) 1044 if (!MAP_DIFFICULTY(m))
1057 MAP_DIFFICULTY(m)=calculate_difficulty(m); 1045 MAP_DIFFICULTY(m)=calculate_difficulty(m);
1058 set_map_reset_time(m); 1046 set_map_reset_time(m);
1059 INVOKE_MAP (INSTANTIATE, m); 1047 m->instantiate ();
1060 return (m); 1048 return (m);
1061} 1049}
1062 1050
1063/* 1051/*
1064 * Loads a map, which has been loaded earlier, from file. 1052 * Loads a map, which has been loaded earlier, from file.
1065 * Return the map object we load into (this can change from the passed 1053 * Return the map object we load into (this can change from the passed
1066 * option if we can't find the original map) 1054 * option if we can't find the original map)
1067 */ 1055 */
1068 1056
1069static mapstruct *load_temporary_map(mapstruct *m) { 1057static mapstruct *load_temporary_map(mapstruct *m) {
1070 FILE *fp;
1071 int comp; 1058 int comp;
1072 char buf[MAX_BUF]; 1059 char buf[MAX_BUF];
1073 1060
1074 if (!m->tmpname) { 1061 if (!m->tmpname) {
1075 LOG(llevError, "No temporary filename for map %s\n", m->path); 1062 LOG(llevError, "No temporary filename for map %s\n", m->path);
1079 if(m==NULL) return NULL; 1066 if(m==NULL) return NULL;
1080 fix_auto_apply(m); /* Chests which open as default */ 1067 fix_auto_apply(m); /* Chests which open as default */
1081 return m; 1068 return m;
1082 } 1069 }
1083 1070
1084 if((fp=open_and_uncompress(m->tmpname,0, &comp))==NULL) { 1071 object_thawer thawer (m->tmpname);
1085 LOG(llevError, "Cannot open %s: %s\n",m->tmpname, strerror_local(errno)); 1072
1073 if (!thawer)
1074 {
1086 strcpy(buf, m->path); 1075 strcpy (buf, m->path);
1087 delete_map(m); 1076 delete_map (m);
1088 m = load_original_map(buf, 0); 1077 m = load_original_map (buf, 0);
1089 if(m==NULL) return NULL; 1078 if (!m) return NULL;
1090 fix_auto_apply(m); /* Chests which open as default */ 1079 fix_auto_apply (m); /* Chests which open as default */
1091 return m; 1080 return m;
1092 } 1081 }
1093
1094 object_thawer thawer (fp, m->tmpname);
1095 1082
1096 if (load_map_header(thawer, m)) { 1083 if (load_map_header(thawer, m)) {
1097 LOG(llevError,"Error loading map header for %s (%s)\n", 1084 LOG(llevError,"Error loading map header for %s (%s)\n",
1098 m->path, m->tmpname); 1085 m->path, m->tmpname);
1099 delete_map(m); 1086 delete_map(m);
1102 } 1089 }
1103 allocate_map(m); 1090 allocate_map(m);
1104 1091
1105 m->in_memory=MAP_LOADING; 1092 m->in_memory=MAP_LOADING;
1106 load_objects (m, thawer, 0); 1093 load_objects (m, thawer, 0);
1107 close_and_delete(fp, comp); 1094
1108 m->in_memory=MAP_IN_MEMORY; 1095 m->in_memory=MAP_IN_MEMORY;
1109 INVOKE_MAP (SWAPIN, m); 1096 INVOKE_MAP (SWAPIN, m);
1110 return m; 1097 return m;
1111} 1098}
1112 1099
1115 * Return the map object we load into (this can change from the passed 1102 * Return the map object we load into (this can change from the passed
1116 * option if we can't find the original map) 1103 * option if we can't find the original map)
1117 */ 1104 */
1118 1105
1119mapstruct *load_overlay_map(const char *filename, mapstruct *m) { 1106mapstruct *load_overlay_map(const char *filename, mapstruct *m) {
1120 FILE *fp;
1121 int comp;
1122 char pathname[MAX_BUF]; 1107 char pathname[MAX_BUF];
1123 1108
1124 strcpy(pathname, create_overlay_pathname(filename)); 1109 strcpy(pathname, create_overlay_pathname(filename));
1125 1110
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); 1111 object_thawer thawer (pathname);
1112
1113 if (!thawer)
1114 return m;
1132 1115
1133 if (load_map_header(thawer, m)) { 1116 if (load_map_header(thawer, m)) {
1134 LOG(llevError,"Error loading map header for overlay %s (%s)\n", 1117 LOG(llevError,"Error loading map header for overlay %s (%s)\n",
1135 m->path, pathname); 1118 m->path, pathname);
1136 delete_map(m); 1119 delete_map(m);
1139 } 1122 }
1140 /*allocate_map(m);*/ 1123 /*allocate_map(m);*/
1141 1124
1142 m->in_memory=MAP_LOADING; 1125 m->in_memory=MAP_LOADING;
1143 load_objects (m, thawer, MAP_OVERLAY); 1126 load_objects (m, thawer, MAP_OVERLAY);
1144 close_and_delete(fp, comp); 1127
1145 m->in_memory=MAP_IN_MEMORY; 1128 m->in_memory=MAP_IN_MEMORY;
1146 return m; 1129 return m;
1147} 1130}
1148 1131
1149/****************************************************************************** 1132/******************************************************************************
1178/* 1161/*
1179 * Loads unique objects from file(s) into the map which is in memory 1162 * Loads unique objects from file(s) into the map which is in memory
1180 * m is the map to load unique items into. 1163 * m is the map to load unique items into.
1181 */ 1164 */
1182static void load_unique_objects(mapstruct *m) { 1165static void load_unique_objects(mapstruct *m) {
1183 FILE *fp;
1184 int comp,count; 1166 int count;
1185 char firstname[MAX_BUF]; 1167 char firstname[MAX_BUF];
1186 1168
1187 for (count=0; count<10; count++) { 1169 for (count=0; count<10; count++) {
1188 sprintf(firstname, "%s.v%02d", create_items_path(m->path), count); 1170 sprintf(firstname, "%s.v%02d", create_items_path(m->path), count);
1189 if (!access(firstname, R_OK)) break; 1171 if (!access(firstname, R_OK)) break;
1190 } 1172 }
1191 /* If we get here, we did not find any map */ 1173 /* If we get here, we did not find any map */
1192 if (count==10) return; 1174 if (count==10) return;
1193 1175
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); 1176 object_thawer thawer (firstname);
1177
1178 if (!thawer)
1179 return;
1203 1180
1204 m->in_memory=MAP_LOADING; 1181 m->in_memory=MAP_LOADING;
1205 if (m->tmpname == NULL) /* if we have loaded unique items from */ 1182 if (m->tmpname == NULL) /* if we have loaded unique items from */
1206 delete_unique_items(m); /* original map before, don't duplicate them */ 1183 delete_unique_items(m); /* original map before, don't duplicate them */
1207 load_object(thawer, NULL, LO_NOREAD,0); 1184 load_object(thawer, NULL, LO_NOREAD,0);
1208 load_objects (m, thawer, 0); 1185 load_objects (m, thawer, 0);
1209 close_and_delete(fp, comp); 1186
1210 m->in_memory=MAP_IN_MEMORY; 1187 m->in_memory=MAP_IN_MEMORY;
1211} 1188}
1212 1189
1213 1190
1214/* 1191/*
1327 fprintf (fp, "winddir %d\n", m->winddir); 1304 fprintf (fp, "winddir %d\n", m->winddir);
1328 if (m->sky) 1305 if (m->sky)
1329 fprintf (fp, "sky %d\n", m->sky); 1306 fprintf (fp, "sky %d\n", m->sky);
1330 if (m->nosmooth) 1307 if (m->nosmooth)
1331 fprintf (fp, "nosmooth %d\n", m->nosmooth); 1308 fprintf (fp, "nosmooth %d\n", m->nosmooth);
1332 if (m->safe_map)
1333 fprintf (fp, "safe_map %d\n", m->safe_map);
1334 1309
1335 /* Save any tiling information, except on overlays */ 1310 /* Save any tiling information, except on overlays */
1336 if (flag != 2) 1311 if (flag != 2)
1337 for (i = 0; i < 4; i++) 1312 for (i = 0; i < 4; i++)
1338 if (m->tile_path[i]) 1313 if (m->tile_path[i])
1339 fprintf (fp, "tile_path_%d %s\n", i + 1, m->tile_path[i]); 1314 fprintf (fp, "tile_path_%d %s\n", i + 1, m->tile_path[i]);
1340 1315
1316 fp.put (m);
1341 fprintf (fp, "end\n"); 1317 fprintf (fp, "end\n");
1342 1318
1343 /* In the game save unique items in the different file, but 1319 /* In the game save unique items in the different file, but
1344 * in the editor save them to the normal map file. 1320 * in the editor save them to the normal map file.
1345 * If unique map, save files in the proper destination (set by 1321 * If unique map, save files in the proper destination (set by
1582 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) { 1558 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) {
1583 m=load_overlay_map(name, m); 1559 m=load_overlay_map(name, m);
1584 if (m==NULL) 1560 if (m==NULL)
1585 return NULL; 1561 return NULL;
1586 } 1562 }
1563
1564 if (flags & MAP_PLAYER_UNIQUE)
1565 INVOKE_MAP (SWAPIN, m);
1587 1566
1588 } else { 1567 } else {
1589 /* If in this loop, we found a temporary map, so load it up. */ 1568 /* If in this loop, we found a temporary map, so load it up. */
1590 1569
1591 m=load_temporary_map (m); 1570 m=load_temporary_map (m);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines