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.17 by root, Thu Aug 31 06:23:19 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.17 2006/08/31 06:23:19 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
482 op->x += tmp->x; 482 op->x += tmp->x;
483 op->y += tmp->y; 483 op->y += tmp->y;
484 op->head = tmp; 484 op->head = tmp;
485 op->map = m; 485 op->map = m;
486 last->more = op; 486 last->more = op;
487 if (tmp->name != op->name) {
488 if (op->name) free_string(op->name);
489 op->name = add_string(tmp->name); 487 op->name = tmp->name;
490 }
491 if (tmp->title != op->title) {
492 if (op->title) free_string(op->title);
493 op->title = add_string(tmp->title); 488 op->title = tmp->title;
494 }
495 /* we could link all the parts onto tmp, and then just 489 /* we could link all the parts onto tmp, and then just
496 * 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,
497 * 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
498 * 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.
499 */ 493 */
509 * file pointer. 503 * file pointer.
510 * mapflags is the same as we get with load_original_map 504 * mapflags is the same as we get with load_original_map
511 */ 505 */
512 506
513void load_objects (mapstruct *m, object_thawer &fp, int mapflags) { 507void load_objects (mapstruct *m, object_thawer &fp, int mapflags) {
514 int i,j,bufstate=LO_NEWFILE; 508 int i,j;
515 int unique; 509 int unique;
516 object *op, *prev=NULL,*last_more=NULL, *otmp; 510 object *op, *prev=NULL,*last_more=NULL, *otmp;
517 511
518 op=get_object(); 512 op=get_object();
519 op->map = m; /* To handle buttons correctly */ 513 op->map = m; /* To handle buttons correctly */
520 514
521 while((i = load_object (fp, op, bufstate, mapflags))) { 515 while((i = load_object (fp, op, mapflags))) {
522 /* Since the loading of the map header does not load an object
523 * anymore, we need to pass LO_NEWFILE for the first object loaded,
524 * and then switch to LO_REPEAT for faster loading.
525 */
526 bufstate = LO_REPEAT;
527
528 /* if the archetype for the object is null, means that we 516 /* if the archetype for the object is null, means that we
529 * 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
530 * 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.
531 */ 519 */
532 if (op->arch==NULL) { 520 if (op->arch==NULL) {
533 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)");
534 continue; 522 continue;
535 } 523 }
536 524
537 525
538 switch(i) { 526 switch(i) {
618 * 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
619 * used anyways. MSW 2001-07-01 607 * used anyways. MSW 2001-07-01
620 */ 608 */
621 609
622mapstruct *get_linked_map(void) { 610mapstruct *get_linked_map(void) {
623 mapstruct *map=(mapstruct *) calloc(1,sizeof(mapstruct)); 611 mapstruct *map = new mapstruct;
624 mapstruct *mp; 612 mapstruct *mp;
625
626 if(map==NULL)
627 fatal(OUT_OF_MEMORY);
628 613
629 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);
630 if(mp==NULL) 615 if(mp==NULL)
631 first_map=map; 616 first_map=map;
632 else 617 else
888 * what really should be used. 873 * what really should be used.
889 */ 874 */
890 else if (!strcmp(key,"oid")) { 875 else if (!strcmp(key,"oid")) {
891 fp.get (m, atoi(value)); 876 fp.get (m, atoi(value));
892 } else if (!strcmp(key, "attach")) { 877 } else if (!strcmp(key, "attach")) {
893 m->attach = add_string (value); 878 m->attach = value;
894 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) { 879 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) {
895 m->enter_x = atoi(value); 880 m->enter_x = atoi(value);
896 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) { 881 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) {
897 m->enter_y = atoi(value); 882 m->enter_y = atoi(value);
898 } else if (!strcmp(key,"x") || !strcmp(key, "width")) { 883 } else if (!strcmp(key,"x") || !strcmp(key, "width")) {
1179 return; 1164 return;
1180 1165
1181 m->in_memory=MAP_LOADING; 1166 m->in_memory=MAP_LOADING;
1182 if (m->tmpname == NULL) /* if we have loaded unique items from */ 1167 if (m->tmpname == NULL) /* if we have loaded unique items from */
1183 delete_unique_items(m); /* original map before, don't duplicate them */ 1168 delete_unique_items(m); /* original map before, don't duplicate them */
1184 load_object(thawer, NULL, LO_NOREAD,0);
1185 load_objects (m, thawer, 0); 1169 load_objects (m, thawer, 0);
1186 1170
1187 m->in_memory=MAP_IN_MEMORY; 1171 m->in_memory=MAP_IN_MEMORY;
1188} 1172}
1189 1173
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.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines