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.14 by root, Wed Aug 30 06:06:26 2006 UTC vs.
Revision 1.18 by root, Thu Aug 31 17:54:14 2006 UTC

1/* 1/*
2 * static char *rcsid_map_c = 2 * static char *rcsid_map_c =
3 * "$Id: map.C,v 1.14 2006/08/30 06:06:26 root Exp $"; 3 * "$Id: map.C,v 1.18 2006/08/31 17:54:14 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) ||
536 /* if the archetype for the object is null, means that we 528 /* if the archetype for the object is null, means that we
537 * got an invalid object. Don't do anything with it - the game 529 * got an invalid object. Don't do anything with it - the game
538 * or editor will not be able to do anything with it either. 530 * or editor will not be able to do anything with it either.
539 */ 531 */
540 if (op->arch==NULL) { 532 if (op->arch==NULL) {
541 LOG(llevDebug,"Discarding object without arch: %s\n", op->name?op->name:"(null)"); 533 LOG(llevDebug,"Discarding object without arch: %s\n", op->name?(const char *)op->name:"(null)");
542 continue; 534 continue;
543 } 535 }
544 536
545 537
546 switch(i) { 538 switch(i) {
1181 /* If we get here, we did not find any map */ 1173 /* If we get here, we did not find any map */
1182 if (count==10) return; 1174 if (count==10) return;
1183 1175
1184 object_thawer thawer (firstname); 1176 object_thawer thawer (firstname);
1185 1177
1178 if (!thawer)
1179 return;
1180
1186 m->in_memory=MAP_LOADING; 1181 m->in_memory=MAP_LOADING;
1187 if (m->tmpname == NULL) /* if we have loaded unique items from */ 1182 if (m->tmpname == NULL) /* if we have loaded unique items from */
1188 delete_unique_items(m); /* original map before, don't duplicate them */ 1183 delete_unique_items(m); /* original map before, don't duplicate them */
1189 load_object(thawer, NULL, LO_NOREAD,0); 1184 load_object(thawer, NULL, LO_NOREAD,0);
1190 load_objects (m, thawer, 0); 1185 load_objects (m, thawer, 0);
1230 } 1225 }
1231 else 1226 else
1232 { 1227 {
1233 if (!m->tmpname) 1228 if (!m->tmpname)
1234 m->tmpname = tempnam_local (settings.tmpdir, NULL); 1229 m->tmpname = tempnam_local (settings.tmpdir, NULL);
1230
1235 strcpy (filename, m->tmpname); 1231 strcpy (filename, m->tmpname);
1236 } 1232 }
1237 1233
1238 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); 1234 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename);
1239 m->in_memory = MAP_SAVING; 1235 m->in_memory = MAP_SAVING;
1240 1236
1241 object_freezer fp (filename); 1237 object_freezer freezer;
1242 1238
1243 /* legacy */ 1239 /* legacy */
1244 fprintf (fp, "arch map\n"); 1240 fprintf (freezer, "arch map\n");
1245 if (m->name) 1241 if (m->name)
1246 fprintf (fp, "name %s\n", m->name); 1242 fprintf (freezer, "name %s\n", m->name);
1247 if (!flag) 1243 if (!flag)
1248 fprintf (fp, "swap_time %d\n", m->swap_time); 1244 fprintf (freezer, "swap_time %d\n", m->swap_time);
1249 if (m->reset_timeout) 1245 if (m->reset_timeout)
1250 fprintf (fp, "reset_timeout %d\n", m->reset_timeout); 1246 fprintf (freezer, "reset_timeout %d\n", m->reset_timeout);
1251 if (m->fixed_resettime) 1247 if (m->fixed_resettime)
1252 fprintf (fp, "fixed_resettime %d\n", m->fixed_resettime); 1248 fprintf (freezer, "fixed_resettime %d\n", m->fixed_resettime);
1253 /* we unfortunately have no idea if this is a value the creator set 1249 /* we unfortunately have no idea if this is a value the creator set
1254 * or a difficulty value we generated when the map was first loaded 1250 * or a difficulty value we generated when the map was first loaded
1255 */ 1251 */
1256 if (m->difficulty) 1252 if (m->difficulty)
1257 fprintf (fp, "difficulty %d\n", m->difficulty); 1253 fprintf (freezer, "difficulty %d\n", m->difficulty);
1258 if (m->region) 1254 if (m->region)
1259 fprintf (fp, "region %s\n", m->region->name); 1255 fprintf (freezer, "region %s\n", m->region->name);
1260 if (m->shopitems) 1256 if (m->shopitems)
1261 { 1257 {
1262 print_shop_string (m, shop); 1258 print_shop_string (m, shop);
1263 fprintf (fp, "shopitems %s\n", shop); 1259 fprintf (freezer, "shopitems %s\n", shop);
1264 } 1260 }
1265 if (m->shopgreed) 1261 if (m->shopgreed)
1266 fprintf (fp, "shopgreed %f\n", m->shopgreed); 1262 fprintf (freezer, "shopgreed %f\n", m->shopgreed);
1267#ifndef WIN32 1263#ifndef WIN32
1268 if (m->shopmin) 1264 if (m->shopmin)
1269 fprintf (fp, "shopmin %llu\n", m->shopmin); 1265 fprintf (freezer, "shopmin %llu\n", m->shopmin);
1270 if (m->shopmax) 1266 if (m->shopmax)
1271 fprintf (fp, "shopmax %llu\n", m->shopmax); 1267 fprintf (freezer, "shopmax %llu\n", m->shopmax);
1272#else 1268#else
1273 if (m->shopmin) 1269 if (m->shopmin)
1274 fprintf (fp, "shopmin %I64u\n", m->shopmin); 1270 fprintf (freezer, "shopmin %I64u\n", m->shopmin);
1275 if (m->shopmax) 1271 if (m->shopmax)
1276 fprintf (fp, "shopmax %I64u\n", m->shopmax); 1272 fprintf (freezer, "shopmax %I64u\n", m->shopmax);
1277#endif 1273#endif
1278 if (m->shoprace) 1274 if (m->shoprace)
1279 fprintf (fp, "shoprace %s\n", m->shoprace); 1275 fprintf (freezer, "shoprace %s\n", m->shoprace);
1280 if (m->darkness) 1276 if (m->darkness)
1281 fprintf (fp, "darkness %d\n", m->darkness); 1277 fprintf (freezer, "darkness %d\n", m->darkness);
1282 if (m->width) 1278 if (m->width)
1283 fprintf (fp, "width %d\n", m->width); 1279 fprintf (freezer, "width %d\n", m->width);
1284 if (m->height) 1280 if (m->height)
1285 fprintf (fp, "height %d\n", m->height); 1281 fprintf (freezer, "height %d\n", m->height);
1286 if (m->enter_x) 1282 if (m->enter_x)
1287 fprintf (fp, "enter_x %d\n", m->enter_x); 1283 fprintf (freezer, "enter_x %d\n", m->enter_x);
1288 if (m->enter_y) 1284 if (m->enter_y)
1289 fprintf (fp, "enter_y %d\n", m->enter_y); 1285 fprintf (freezer, "enter_y %d\n", m->enter_y);
1290 if (m->msg) 1286 if (m->msg)
1291 fprintf (fp, "msg\n%sendmsg\n", m->msg); 1287 fprintf (freezer, "msg\n%sendmsg\n", m->msg);
1292 if (m->maplore) 1288 if (m->maplore)
1293 fprintf (fp, "maplore\n%sendmaplore\n", m->maplore); 1289 fprintf (freezer, "maplore\n%sendmaplore\n", m->maplore);
1294 if (m->unique) 1290 if (m->unique)
1295 fprintf (fp, "unique %d\n", m->unique); 1291 fprintf (freezer, "unique %d\n", m->unique);
1296 if (m->templatemap) 1292 if (m->templatemap)
1297 fprintf (fp, "template %d\n", m->templatemap); 1293 fprintf (freezer, "template %d\n", m->templatemap);
1298 if (m->outdoor) 1294 if (m->outdoor)
1299 fprintf (fp, "outdoor %d\n", m->outdoor); 1295 fprintf (freezer, "outdoor %d\n", m->outdoor);
1300 if (m->temp) 1296 if (m->temp)
1301 fprintf (fp, "temp %d\n", m->temp); 1297 fprintf (freezer, "temp %d\n", m->temp);
1302 if (m->pressure) 1298 if (m->pressure)
1303 fprintf (fp, "pressure %d\n", m->pressure); 1299 fprintf (freezer, "pressure %d\n", m->pressure);
1304 if (m->humid) 1300 if (m->humid)
1305 fprintf (fp, "humid %d\n", m->humid); 1301 fprintf (freezer, "humid %d\n", m->humid);
1306 if (m->windspeed) 1302 if (m->windspeed)
1307 fprintf (fp, "windspeed %d\n", m->windspeed); 1303 fprintf (freezer, "windspeed %d\n", m->windspeed);
1308 if (m->winddir) 1304 if (m->winddir)
1309 fprintf (fp, "winddir %d\n", m->winddir); 1305 fprintf (freezer, "winddir %d\n", m->winddir);
1310 if (m->sky) 1306 if (m->sky)
1311 fprintf (fp, "sky %d\n", m->sky); 1307 fprintf (freezer, "sky %d\n", m->sky);
1312 if (m->nosmooth) 1308 if (m->nosmooth)
1313 fprintf (fp, "nosmooth %d\n", m->nosmooth); 1309 fprintf (freezer, "nosmooth %d\n", m->nosmooth);
1314 1310
1315 /* Save any tiling information, except on overlays */ 1311 /* Save any tiling information, except on overlays */
1316 if (flag != 2) 1312 if (flag != 2)
1317 for (i = 0; i < 4; i++) 1313 for (i = 0; i < 4; i++)
1318 if (m->tile_path[i]) 1314 if (m->tile_path[i])
1319 fprintf (fp, "tile_path_%d %s\n", i + 1, m->tile_path[i]); 1315 fprintf (freezer, "tile_path_%d %s\n", i + 1, m->tile_path[i]);
1320 1316
1321 fp.put (m); 1317 freezer.put (m);
1322 fprintf (fp, "end\n"); 1318 fprintf (freezer, "end\n");
1323 1319
1324 /* In the game save unique items in the different file, but 1320 /* In the game save unique items in the different file, but
1325 * in the editor save them to the normal map file. 1321 * in the editor save them to the normal map file.
1326 * If unique map, save files in the proper destination (set by 1322 * If unique map, save files in the proper destination (set by
1327 * player) 1323 * player)
1328 */ 1324 */
1329 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap) 1325 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap)
1330 { 1326 {
1327 object_freezer unique;
1328
1329 if (flag == 2)
1330 save_objects (m, freezer, unique, 2);
1331 else
1332 save_objects (m, freezer, unique, 0);
1333
1331 sprintf (buf, "%s.v00", create_items_path (m->path)); 1334 sprintf (buf, "%s.v00", create_items_path (m->path));
1332 1335
1333 object_freezer fp2 (buf); 1336 unique.save (buf);
1334
1335 if (flag == 2)
1336 save_objects (m, fp, fp2, 2);
1337 else
1338 save_objects (m, fp, fp2, 0);
1339 } 1337 }
1340 else 1338 else
1341 { /* save same file when not playing, like in editor */ 1339 { /* save same file when not playing, like in editor */
1342 save_objects (m, fp, fp, 0); 1340 save_objects (m, freezer, freezer, 0);
1343 } 1341 }
1342
1343 freezer.save (filename);
1344 1344
1345 return 0; 1345 return 0;
1346} 1346}
1347 1347
1348 1348
1563 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) { 1563 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) {
1564 m=load_overlay_map(name, m); 1564 m=load_overlay_map(name, m);
1565 if (m==NULL) 1565 if (m==NULL)
1566 return NULL; 1566 return NULL;
1567 } 1567 }
1568
1569 if (flags & MAP_PLAYER_UNIQUE)
1570 INVOKE_MAP (SWAPIN, m);
1568 1571
1569 } else { 1572 } else {
1570 /* If in this loop, we found a temporary map, so load it up. */ 1573 /* If in this loop, we found a temporary map, so load it up. */
1571 1574
1572 m=load_temporary_map (m); 1575 m=load_temporary_map (m);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines