1 | /* |
1 | /* |
2 | * static char *rcsid_map_c = |
2 | * static char *rcsid_map_c = |
3 | * "$Id: map.C,v 1.20 2006/09/03 00:18:40 root Exp $"; |
3 | * "$Id: map.C,v 1.23 2006/09/04 15:51:24 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 | |
… | |
… | |
503 | * file pointer. |
503 | * file pointer. |
504 | * mapflags is the same as we get with load_original_map |
504 | * mapflags is the same as we get with load_original_map |
505 | */ |
505 | */ |
506 | |
506 | |
507 | void load_objects (mapstruct *m, object_thawer &fp, int mapflags) { |
507 | void load_objects (mapstruct *m, object_thawer &fp, int mapflags) { |
508 | int i,j,bufstate=LO_NEWFILE; |
508 | int i,j; |
509 | int unique; |
509 | int unique; |
510 | object *op, *prev=NULL,*last_more=NULL, *otmp; |
510 | object *op, *prev=NULL,*last_more=NULL, *otmp; |
511 | |
511 | |
512 | op=get_object(); |
512 | op=get_object(); |
513 | op->map = m; /* To handle buttons correctly */ |
513 | op->map = m; /* To handle buttons correctly */ |
514 | |
514 | |
515 | while((i = load_object (fp, op, bufstate, mapflags))) { |
515 | while((i = load_object (fp, op, mapflags))) { |
516 | /* Since the loading of the map header does not load an object |
|
|
517 | * anymore, we need to pass LO_NEWFILE for the first object loaded, |
|
|
518 | * and then switch to LO_REPEAT for faster loading. |
|
|
519 | */ |
|
|
520 | bufstate = LO_REPEAT; |
|
|
521 | |
|
|
522 | /* if the archetype for the object is null, means that we |
516 | /* if the archetype for the object is null, means that we |
523 | * 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 |
524 | * 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. |
525 | */ |
519 | */ |
526 | if (op->arch==NULL) { |
520 | if (op->arch==NULL) { |
… | |
… | |
806 | value = NULL; |
800 | value = NULL; |
807 | break; |
801 | break; |
808 | } |
802 | } |
809 | } |
803 | } |
810 | } |
804 | } |
|
|
805 | |
811 | if (!end) { |
806 | if (!end) { |
812 | LOG(llevError, "Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n", |
807 | LOG(llevError, "Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n", |
813 | buf); |
808 | buf); |
814 | return 1; |
809 | return 1; |
815 | } |
810 | } |
816 | |
|
|
817 | |
811 | |
818 | /* key is the field name, value is what it should be set |
812 | /* key is the field name, value is what it should be set |
819 | * to. We've already done the work to null terminate key, |
813 | * to. We've already done the work to null terminate key, |
820 | * and strip off any leading spaces for both of these. |
814 | * and strip off any leading spaces for both of these. |
821 | * We have not touched the newline at the end of the line - |
815 | * We have not touched the newline at the end of the line - |
… | |
… | |
1001 | |
995 | |
1002 | mapstruct *load_original_map(const char *filename, int flags) { |
996 | mapstruct *load_original_map(const char *filename, int flags) { |
1003 | mapstruct *m; |
997 | mapstruct *m; |
1004 | char pathname[MAX_BUF]; |
998 | char pathname[MAX_BUF]; |
1005 | |
999 | |
1006 | LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags); |
|
|
1007 | if (flags & MAP_PLAYER_UNIQUE) |
1000 | if (flags & MAP_PLAYER_UNIQUE) |
1008 | strcpy(pathname, filename); |
1001 | strcpy(pathname, filename); |
1009 | else if (flags & MAP_OVERLAY) |
1002 | else if (flags & MAP_OVERLAY) |
1010 | strcpy(pathname, create_overlay_pathname(filename)); |
1003 | strcpy(pathname, create_overlay_pathname(filename)); |
1011 | else |
1004 | else |
1012 | strcpy(pathname, create_pathname(filename)); |
1005 | strcpy(pathname, create_pathname(filename)); |
|
|
1006 | |
|
|
1007 | LOG(llevDebug, "load_original_map(%x): %s (%s)\n", flags, filename, pathname); |
1013 | |
1008 | |
1014 | object_thawer thawer (pathname); |
1009 | object_thawer thawer (pathname); |
1015 | |
1010 | |
1016 | if (!thawer) |
1011 | if (!thawer) |
1017 | return 0; |
1012 | return 0; |
… | |
… | |
1170 | return; |
1165 | return; |
1171 | |
1166 | |
1172 | m->in_memory=MAP_LOADING; |
1167 | m->in_memory=MAP_LOADING; |
1173 | if (m->tmpname == NULL) /* if we have loaded unique items from */ |
1168 | if (m->tmpname == NULL) /* if we have loaded unique items from */ |
1174 | delete_unique_items(m); /* original map before, don't duplicate them */ |
1169 | delete_unique_items(m); /* original map before, don't duplicate them */ |
1175 | load_object(thawer, NULL, LO_NOREAD,0); |
|
|
1176 | load_objects (m, thawer, 0); |
1170 | load_objects (m, thawer, 0); |
1177 | |
1171 | |
1178 | m->in_memory=MAP_IN_MEMORY; |
1172 | m->in_memory=MAP_IN_MEMORY; |
1179 | } |
1173 | } |
1180 | |
1174 | |
… | |
… | |
1526 | if (flags & MAP_PLAYER_UNIQUE) |
1520 | if (flags & MAP_PLAYER_UNIQUE) |
1527 | LOG(llevDebug, "Trying to load map %s.\n", name); |
1521 | LOG(llevDebug, "Trying to load map %s.\n", name); |
1528 | else |
1522 | else |
1529 | LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name)); |
1523 | LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name)); |
1530 | |
1524 | |
|
|
1525 | //0.427459955215454 /var/crossfire/players/Saladon/_scorn_apartment_apartments |
|
|
1526 | //0.414906024932861 |
|
|
1527 | //0.427063941955566 |
|
|
1528 | eval_pv ("$x = Event::time", 1);//D |
1531 | if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE)))) |
1529 | if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE)))) |
1532 | return (NULL); |
1530 | return (NULL); |
|
|
1531 | eval_pv ("warn \"LOAD \", Event::time - $x", 1);//D |
1533 | |
1532 | |
1534 | fix_auto_apply(m); /* Chests which open as default */ |
1533 | fix_auto_apply(m); /* Chests which open as default */ |
1535 | |
1534 | |
1536 | /* If a player unique map, no extra unique object file to load. |
1535 | /* If a player unique map, no extra unique object file to load. |
1537 | * if from the editor, likewise. |
1536 | * if from the editor, likewise. |