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.21 by root, Sun Sep 3 22:45:55 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.21 2006/09/03 22:45:55 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) ||
490 op->x += tmp->x; 482 op->x += tmp->x;
491 op->y += tmp->y; 483 op->y += tmp->y;
492 op->head = tmp; 484 op->head = tmp;
493 op->map = m; 485 op->map = m;
494 last->more = op; 486 last->more = op;
495 if (tmp->name != op->name) {
496 if (op->name) free_string(op->name);
497 op->name = add_string(tmp->name); 487 op->name = tmp->name;
498 }
499 if (tmp->title != op->title) {
500 if (op->title) free_string(op->title);
501 op->title = add_string(tmp->title); 488 op->title = tmp->title;
502 }
503 /* we could link all the parts onto tmp, and then just 489 /* we could link all the parts onto tmp, and then just
504 * call insert_ob_in_map once, but the effect is the same, 490 * call insert_ob_in_map once, but the effect is the same,
505 * as insert_ob_in_map will call itself with each part, and 491 * as insert_ob_in_map will call itself with each part, and
506 * the coding is simpler to just to it here with each part. 492 * the coding is simpler to just to it here with each part.
507 */ 493 */
517 * file pointer. 503 * file pointer.
518 * mapflags is the same as we get with load_original_map 504 * mapflags is the same as we get with load_original_map
519 */ 505 */
520 506
521void load_objects (mapstruct *m, object_thawer &fp, int mapflags) { 507void load_objects (mapstruct *m, object_thawer &fp, int mapflags) {
522 int i,j,bufstate=LO_NEWFILE; 508 int i,j;
523 int unique; 509 int unique;
524 object *op, *prev=NULL,*last_more=NULL, *otmp; 510 object *op, *prev=NULL,*last_more=NULL, *otmp;
525 511
526 op=get_object(); 512 op=get_object();
527 op->map = m; /* To handle buttons correctly */ 513 op->map = m; /* To handle buttons correctly */
528 514
529 while((i = load_object (fp, op, bufstate, mapflags))) { 515 while((i = load_object (fp, op, mapflags))) {
530 /* Since the loading of the map header does not load an object
531 * anymore, we need to pass LO_NEWFILE for the first object loaded,
532 * and then switch to LO_REPEAT for faster loading.
533 */
534 bufstate = LO_REPEAT;
535
536 /* if the archetype for the object is null, means that we 516 /* if the archetype for the object is null, means that we
537 * got an invalid object. Don't do anything with it - the game 517 * 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. 518 * or editor will not be able to do anything with it either.
539 */ 519 */
540 if (op->arch==NULL) { 520 if (op->arch==NULL) {
541 LOG(llevDebug,"Discarding object without arch: %s\n", op->name?op->name:"(null)"); 521 LOG(llevDebug,"Discarding object without arch: %s\n", op->name?(const char *)op->name:"(null)");
542 continue; 522 continue;
543 } 523 }
544 524
545 525
546 switch(i) { 526 switch(i) {
626 * Modified to no longer take a path option which was not being 606 * Modified to no longer take a path option which was not being
627 * used anyways. MSW 2001-07-01 607 * used anyways. MSW 2001-07-01
628 */ 608 */
629 609
630mapstruct *get_linked_map(void) { 610mapstruct *get_linked_map(void) {
631 mapstruct *map=(mapstruct *) calloc(1,sizeof(mapstruct)); 611 mapstruct *map = new mapstruct;
632 mapstruct *mp; 612 mapstruct *mp;
633
634 if(map==NULL)
635 fatal(OUT_OF_MEMORY);
636 613
637 for(mp=first_map;mp!=NULL&&mp->next!=NULL;mp=mp->next); 614 for(mp=first_map;mp!=NULL&&mp->next!=NULL;mp=mp->next);
638 if(mp==NULL) 615 if(mp==NULL)
639 first_map=map; 616 first_map=map;
640 else 617 else
896 * what really should be used. 873 * what really should be used.
897 */ 874 */
898 else if (!strcmp(key,"oid")) { 875 else if (!strcmp(key,"oid")) {
899 fp.get (m, atoi(value)); 876 fp.get (m, atoi(value));
900 } else if (!strcmp(key, "attach")) { 877 } else if (!strcmp(key, "attach")) {
901 m->attach = add_string (value); 878 m->attach = value;
902 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) { 879 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) {
903 m->enter_x = atoi(value); 880 m->enter_x = atoi(value);
904 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) { 881 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) {
905 m->enter_y = atoi(value); 882 m->enter_y = atoi(value);
906 } else if (!strcmp(key,"x") || !strcmp(key, "width")) { 883 } else if (!strcmp(key,"x") || !strcmp(key, "width")) {
1181 /* If we get here, we did not find any map */ 1158 /* If we get here, we did not find any map */
1182 if (count==10) return; 1159 if (count==10) return;
1183 1160
1184 object_thawer thawer (firstname); 1161 object_thawer thawer (firstname);
1185 1162
1163 if (!thawer)
1164 return;
1165
1186 m->in_memory=MAP_LOADING; 1166 m->in_memory=MAP_LOADING;
1187 if (m->tmpname == NULL) /* if we have loaded unique items from */ 1167 if (m->tmpname == NULL) /* if we have loaded unique items from */
1188 delete_unique_items(m); /* original map before, don't duplicate them */ 1168 delete_unique_items(m); /* original map before, don't duplicate them */
1189 load_object(thawer, NULL, LO_NOREAD,0);
1190 load_objects (m, thawer, 0); 1169 load_objects (m, thawer, 0);
1191 1170
1192 m->in_memory=MAP_IN_MEMORY; 1171 m->in_memory=MAP_IN_MEMORY;
1193} 1172}
1194 1173
1230 } 1209 }
1231 else 1210 else
1232 { 1211 {
1233 if (!m->tmpname) 1212 if (!m->tmpname)
1234 m->tmpname = tempnam_local (settings.tmpdir, NULL); 1213 m->tmpname = tempnam_local (settings.tmpdir, NULL);
1214
1235 strcpy (filename, m->tmpname); 1215 strcpy (filename, m->tmpname);
1236 } 1216 }
1237 1217
1238 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); 1218 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename);
1239 m->in_memory = MAP_SAVING; 1219 m->in_memory = MAP_SAVING;
1240 1220
1241 object_freezer fp (filename); 1221 object_freezer freezer;
1242 1222
1243 /* legacy */ 1223 /* legacy */
1244 fprintf (fp, "arch map\n"); 1224 fprintf (freezer, "arch map\n");
1245 if (m->name) 1225 if (m->name)
1246 fprintf (fp, "name %s\n", m->name); 1226 fprintf (freezer, "name %s\n", m->name);
1247 if (!flag) 1227 if (!flag)
1248 fprintf (fp, "swap_time %d\n", m->swap_time); 1228 fprintf (freezer, "swap_time %d\n", m->swap_time);
1249 if (m->reset_timeout) 1229 if (m->reset_timeout)
1250 fprintf (fp, "reset_timeout %d\n", m->reset_timeout); 1230 fprintf (freezer, "reset_timeout %d\n", m->reset_timeout);
1251 if (m->fixed_resettime) 1231 if (m->fixed_resettime)
1252 fprintf (fp, "fixed_resettime %d\n", m->fixed_resettime); 1232 fprintf (freezer, "fixed_resettime %d\n", m->fixed_resettime);
1253 /* we unfortunately have no idea if this is a value the creator set 1233 /* 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 1234 * or a difficulty value we generated when the map was first loaded
1255 */ 1235 */
1256 if (m->difficulty) 1236 if (m->difficulty)
1257 fprintf (fp, "difficulty %d\n", m->difficulty); 1237 fprintf (freezer, "difficulty %d\n", m->difficulty);
1258 if (m->region) 1238 if (m->region)
1259 fprintf (fp, "region %s\n", m->region->name); 1239 fprintf (freezer, "region %s\n", m->region->name);
1260 if (m->shopitems) 1240 if (m->shopitems)
1261 { 1241 {
1262 print_shop_string (m, shop); 1242 print_shop_string (m, shop);
1263 fprintf (fp, "shopitems %s\n", shop); 1243 fprintf (freezer, "shopitems %s\n", shop);
1264 } 1244 }
1265 if (m->shopgreed) 1245 if (m->shopgreed)
1266 fprintf (fp, "shopgreed %f\n", m->shopgreed); 1246 fprintf (freezer, "shopgreed %f\n", m->shopgreed);
1267#ifndef WIN32 1247#ifndef WIN32
1268 if (m->shopmin) 1248 if (m->shopmin)
1269 fprintf (fp, "shopmin %llu\n", m->shopmin); 1249 fprintf (freezer, "shopmin %llu\n", m->shopmin);
1270 if (m->shopmax) 1250 if (m->shopmax)
1271 fprintf (fp, "shopmax %llu\n", m->shopmax); 1251 fprintf (freezer, "shopmax %llu\n", m->shopmax);
1272#else 1252#else
1273 if (m->shopmin) 1253 if (m->shopmin)
1274 fprintf (fp, "shopmin %I64u\n", m->shopmin); 1254 fprintf (freezer, "shopmin %I64u\n", m->shopmin);
1275 if (m->shopmax) 1255 if (m->shopmax)
1276 fprintf (fp, "shopmax %I64u\n", m->shopmax); 1256 fprintf (freezer, "shopmax %I64u\n", m->shopmax);
1277#endif 1257#endif
1278 if (m->shoprace) 1258 if (m->shoprace)
1279 fprintf (fp, "shoprace %s\n", m->shoprace); 1259 fprintf (freezer, "shoprace %s\n", m->shoprace);
1280 if (m->darkness) 1260 if (m->darkness)
1281 fprintf (fp, "darkness %d\n", m->darkness); 1261 fprintf (freezer, "darkness %d\n", m->darkness);
1282 if (m->width) 1262 if (m->width)
1283 fprintf (fp, "width %d\n", m->width); 1263 fprintf (freezer, "width %d\n", m->width);
1284 if (m->height) 1264 if (m->height)
1285 fprintf (fp, "height %d\n", m->height); 1265 fprintf (freezer, "height %d\n", m->height);
1286 if (m->enter_x) 1266 if (m->enter_x)
1287 fprintf (fp, "enter_x %d\n", m->enter_x); 1267 fprintf (freezer, "enter_x %d\n", m->enter_x);
1288 if (m->enter_y) 1268 if (m->enter_y)
1289 fprintf (fp, "enter_y %d\n", m->enter_y); 1269 fprintf (freezer, "enter_y %d\n", m->enter_y);
1290 if (m->msg) 1270 if (m->msg)
1291 fprintf (fp, "msg\n%sendmsg\n", m->msg); 1271 fprintf (freezer, "msg\n%sendmsg\n", m->msg);
1292 if (m->maplore) 1272 if (m->maplore)
1293 fprintf (fp, "maplore\n%sendmaplore\n", m->maplore); 1273 fprintf (freezer, "maplore\n%sendmaplore\n", m->maplore);
1294 if (m->unique) 1274 if (m->unique)
1295 fprintf (fp, "unique %d\n", m->unique); 1275 fprintf (freezer, "unique %d\n", m->unique);
1296 if (m->templatemap) 1276 if (m->templatemap)
1297 fprintf (fp, "template %d\n", m->templatemap); 1277 fprintf (freezer, "template %d\n", m->templatemap);
1298 if (m->outdoor) 1278 if (m->outdoor)
1299 fprintf (fp, "outdoor %d\n", m->outdoor); 1279 fprintf (freezer, "outdoor %d\n", m->outdoor);
1300 if (m->temp) 1280 if (m->temp)
1301 fprintf (fp, "temp %d\n", m->temp); 1281 fprintf (freezer, "temp %d\n", m->temp);
1302 if (m->pressure) 1282 if (m->pressure)
1303 fprintf (fp, "pressure %d\n", m->pressure); 1283 fprintf (freezer, "pressure %d\n", m->pressure);
1304 if (m->humid) 1284 if (m->humid)
1305 fprintf (fp, "humid %d\n", m->humid); 1285 fprintf (freezer, "humid %d\n", m->humid);
1306 if (m->windspeed) 1286 if (m->windspeed)
1307 fprintf (fp, "windspeed %d\n", m->windspeed); 1287 fprintf (freezer, "windspeed %d\n", m->windspeed);
1308 if (m->winddir) 1288 if (m->winddir)
1309 fprintf (fp, "winddir %d\n", m->winddir); 1289 fprintf (freezer, "winddir %d\n", m->winddir);
1310 if (m->sky) 1290 if (m->sky)
1311 fprintf (fp, "sky %d\n", m->sky); 1291 fprintf (freezer, "sky %d\n", m->sky);
1312 if (m->nosmooth) 1292 if (m->nosmooth)
1313 fprintf (fp, "nosmooth %d\n", m->nosmooth); 1293 fprintf (freezer, "nosmooth %d\n", m->nosmooth);
1314 1294
1315 /* Save any tiling information, except on overlays */ 1295 /* Save any tiling information, except on overlays */
1316 if (flag != 2) 1296 if (flag != 2)
1317 for (i = 0; i < 4; i++) 1297 for (i = 0; i < 4; i++)
1318 if (m->tile_path[i]) 1298 if (m->tile_path[i])
1319 fprintf (fp, "tile_path_%d %s\n", i + 1, m->tile_path[i]); 1299 fprintf (freezer, "tile_path_%d %s\n", i + 1, m->tile_path[i]);
1320 1300
1321 fp.put (m); 1301 freezer.put (m);
1322 fprintf (fp, "end\n"); 1302 fprintf (freezer, "end\n");
1323 1303
1324 /* In the game save unique items in the different file, but 1304 /* In the game save unique items in the different file, but
1325 * in the editor save them to the normal map file. 1305 * in the editor save them to the normal map file.
1326 * If unique map, save files in the proper destination (set by 1306 * If unique map, save files in the proper destination (set by
1327 * player) 1307 * player)
1328 */ 1308 */
1329 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap) 1309 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap)
1330 { 1310 {
1311 object_freezer unique;
1312
1313 if (flag == 2)
1314 save_objects (m, freezer, unique, 2);
1315 else
1316 save_objects (m, freezer, unique, 0);
1317
1331 sprintf (buf, "%s.v00", create_items_path (m->path)); 1318 sprintf (buf, "%s.v00", create_items_path (m->path));
1332 1319
1333 object_freezer fp2 (buf); 1320 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 } 1321 }
1340 else 1322 else
1341 { /* save same file when not playing, like in editor */ 1323 { /* save same file when not playing, like in editor */
1342 save_objects (m, fp, fp, 0); 1324 save_objects (m, freezer, freezer, 0);
1343 } 1325 }
1326
1327 freezer.save (filename);
1344 1328
1345 return 0; 1329 return 0;
1346} 1330}
1347 1331
1348 1332
1393 clean_object(op); 1377 clean_object(op);
1394 remove_ob(op); 1378 remove_ob(op);
1395 free_object(op); 1379 free_object(op);
1396 } 1380 }
1397 } 1381 }
1398#ifdef MANY_CORES
1399 /* I see periodic cores on metalforge where a map has been swapped out, but apparantly
1400 * an item on that map was not saved - look for that condition and die as appropriate -
1401 * this leaves more of the map data intact for better debugging.
1402 */
1403 for (op=objects; op!=NULL; op=op->next) {
1404 if (!QUERY_FLAG(op, FLAG_REMOVED) && op->map == m) {
1405 LOG(llevDebug,"free_all_objects: object %s still on map after it should have been freed\n", op->name);
1406 abort();
1407 }
1408 }
1409#endif
1410} 1382}
1411 1383
1412/* 1384/*
1413 * Frees everything allocated by the given mapstructure. 1385 * Frees everything allocated by the given mapstructure.
1414 * don't free tmpname - our caller is left to do that 1386 * don't free tmpname - our caller is left to do that
1494 m->path); 1466 m->path);
1495 } 1467 }
1496 else 1468 else
1497 last->next = m->next; 1469 last->next = m->next;
1498 1470
1499 free (m); 1471 delete m;
1500} 1472}
1501 1473
1502 1474
1503 1475
1504/* 1476/*
1547 if (flags & MAP_PLAYER_UNIQUE) 1519 if (flags & MAP_PLAYER_UNIQUE)
1548 LOG(llevDebug, "Trying to load map %s.\n", name); 1520 LOG(llevDebug, "Trying to load map %s.\n", name);
1549 else 1521 else
1550 LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name)); 1522 LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name));
1551 1523
1524 //0.427459955215454 /var/crossfire/players/Saladon/_scorn_apartment_apartments
1525 //0.414906024932861
1526 //0.427063941955566
1527 eval_pv ("$x = Event::time", 1);//D
1552 if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE)))) 1528 if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE))))
1553 return (NULL); 1529 return (NULL);
1530 eval_pv ("warn \"LOAD \", Event::time - $x", 1);//D
1554 1531
1555 fix_auto_apply(m); /* Chests which open as default */ 1532 fix_auto_apply(m); /* Chests which open as default */
1556 1533
1557 /* If a player unique map, no extra unique object file to load. 1534 /* If a player unique map, no extra unique object file to load.
1558 * if from the editor, likewise. 1535 * if from the editor, likewise.
1563 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) { 1540 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) {
1564 m=load_overlay_map(name, m); 1541 m=load_overlay_map(name, m);
1565 if (m==NULL) 1542 if (m==NULL)
1566 return NULL; 1543 return NULL;
1567 } 1544 }
1545
1546 if (flags & MAP_PLAYER_UNIQUE)
1547 INVOKE_MAP (SWAPIN, m);
1568 1548
1569 } else { 1549 } else {
1570 /* If in this loop, we found a temporary map, so load it up. */ 1550 /* If in this loop, we found a temporary map, so load it up. */
1571 1551
1572 m=load_temporary_map (m); 1552 m=load_temporary_map (m);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines