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.19 by root, Thu Aug 31 18:59:23 2006 UTC vs.
Revision 1.28 by root, Fri Sep 8 18:26:22 2006 UTC

1/* 1/*
2 * static char *rcsid_map_c = 2 * static char *rcsid_map_c =
3 * "$Id: map.C,v 1.19 2006/08/31 18:59:23 root Exp $"; 3 * "$Id: map.C,v 1.28 2006/09/08 18:26:22 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
155{ 155{
156 char buf[MAX_BUF]; 156 char buf[MAX_BUF];
157#ifndef WIN32 157#ifndef WIN32
158 char *endbuf; 158 char *endbuf;
159 struct stat statbuf; 159 struct stat statbuf;
160 int mode = 0, i; 160 int mode = 0;
161#endif 161#endif
162 162
163 if (prepend_dir) 163 if (prepend_dir)
164 strcpy (buf, create_pathname(name)); 164 strcpy (buf, create_pathname(name));
165 else 165 else
255 if (mp != oldmap) 255 if (mp != oldmap)
256 retval |= P_NEW_MAP; 256 retval |= P_NEW_MAP;
257 if (newmap) *newmap = mp; 257 if (newmap) *newmap = mp;
258 if (nx) *nx = newx; 258 if (nx) *nx = newx;
259 if (ny) *ny = newy; 259 if (ny) *ny = newy;
260
260 retval |= mp->spaces[newx + mp->width * newy].flags; 261 retval |= mp->spaces[newx + mp->width * newy].flags;
261
262 if (retval & P_SAFE)
263 retval |= P_NO_MAGIC | P_NO_CLERIC; // P_SAFE does imply these
264 262
265 return retval; 263 return retval;
266} 264}
267 265
268 266
482 op->x += tmp->x; 480 op->x += tmp->x;
483 op->y += tmp->y; 481 op->y += tmp->y;
484 op->head = tmp; 482 op->head = tmp;
485 op->map = m; 483 op->map = m;
486 last->more = op; 484 last->more = op;
487 if (tmp->name != op->name) {
488 if (op->name) free_string(op->name);
489 op->name = add_string(tmp->name); 485 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); 486 op->title = tmp->title;
494 }
495 /* we could link all the parts onto tmp, and then just 487 /* we could link all the parts onto tmp, and then just
496 * call insert_ob_in_map once, but the effect is the same, 488 * 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 489 * 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. 490 * the coding is simpler to just to it here with each part.
499 */ 491 */
500 insert_ob_in_map(op, op->map, tmp,INS_NO_MERGE|INS_ABOVE_FLOOR_ONLY|INS_NO_WALK_ON); 492 insert_ob_in_map(op, op->map, tmp,INS_NO_MERGE|INS_ABOVE_FLOOR_ONLY|INS_NO_WALK_ON);
501 } /* for at = tmp->arch->more */ 493 } /* for at = tmp->arch->more */
502 } /* for objects on this space */ 494 } /* for objects on this space */
503} 495}
504 496
505
506
507/* 497/*
508 * Loads (ands parses) the objects into a given map from the specified 498 * Loads (ands parses) the objects into a given map from the specified
509 * file pointer. 499 * file pointer.
510 * mapflags is the same as we get with load_original_map 500 * mapflags is the same as we get with load_original_map
511 */ 501 */
512 502void
513void load_objects (mapstruct *m, object_thawer &fp, int mapflags) { 503load_objects (mapstruct *m, object_thawer &fp, int mapflags)
514 int i,j,bufstate=LO_NEWFILE; 504{
505 int i, j;
515 int unique; 506 int unique;
516 object *op, *prev=NULL,*last_more=NULL, *otmp; 507 object *op, *prev = NULL, *last_more = NULL, *otmp;
517 508
518 op=get_object(); 509 op = get_object ();
519 op->map = m; /* To handle buttons correctly */ 510 op->map = m; /* To handle buttons correctly */
520 511
521 while((i = load_object (fp, op, bufstate, mapflags))) { 512 while ((i = load_object (fp, op, mapflags)))
522 /* Since the loading of the map header does not load an object 513 {
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 514 /* if the archetype for the object is null, means that we
529 * got an invalid object. Don't do anything with it - the game 515 * 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. 516 * or editor will not be able to do anything with it either.
531 */ 517 */
532 if (op->arch==NULL) { 518 if (op->arch == NULL)
533 LOG(llevDebug,"Discarding object without arch: %s\n", op->name?(const char *)op->name:"(null)"); 519 {
520 LOG (llevDebug, "Discarding object without arch: %s\n",
521 op->name ? (const char *) op->name : "(null)");
534 continue; 522 continue;
523 }
524
525
526 switch (i)
535 } 527 {
536
537
538 switch(i) {
539 case LL_NORMAL: 528 case LL_NORMAL:
540 /* if we are loading an overlay, put the floors on the bottom */ 529 /* if we are loading an overlay, put the floors on the bottom */
541 if ((QUERY_FLAG(op, FLAG_IS_FLOOR) || 530 if ((QUERY_FLAG (op, FLAG_IS_FLOOR) ||
542 QUERY_FLAG(op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) 531 QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY)
543 insert_ob_in_map(op,m,op,INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); 532 insert_ob_in_map (op, m, op,
533 INS_NO_MERGE | INS_NO_WALK_ON |
534 INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD);
544 else 535 else
545 insert_ob_in_map(op,m,op,INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); 536 insert_ob_in_map (op, m, op,
537 INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP |
538 INS_MAP_LOAD);
546 539
547 if (op->inv) 540 if (op->inv)
548 sum_weight(op); 541 sum_weight (op);
549 542
550 prev=op,last_more=op; 543 prev = op, last_more = op;
551 break; 544 break;
552 545
553 case LL_MORE: 546 case LL_MORE:
554 insert_ob_in_map(op,m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); 547 insert_ob_in_map (op, m, op,
548 INS_NO_MERGE | INS_NO_WALK_ON |
549 INS_ABOVE_FLOOR_ONLY);
555 op->head=prev,last_more->more=op,last_more=op; 550 op->head = prev, last_more->more = op, last_more = op;
556 break; 551 break;
557 } 552 }
553
558 if (mapflags & MAP_STYLE) { 554 if (mapflags & MAP_STYLE)
559 remove_from_active_list(op); 555 remove_from_active_list (op);
560 } 556
561 op=get_object(); 557 op = get_object ();
562 op->map = m; 558 op->map = m;
563 } 559 }
560
564 for (i=0;i<m->width;i++){ 561 for (i = 0; i < m->width; i++)
562 {
565 for (j=0;j<m->height;j++){ 563 for (j = 0; j < m->height; j++)
564 {
566 unique =0; 565 unique = 0;
567 /* check for unique items, or unique squares */ 566 /* check for unique items, or unique squares */
568 for (otmp = get_map_ob(m, i, j); otmp; otmp = otmp->above) { 567 for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above)
569 if (QUERY_FLAG(otmp, FLAG_UNIQUE) || QUERY_FLAG(otmp, FLAG_OBJ_SAVE_ON_OVL)) 568 {
569 if (QUERY_FLAG (otmp, FLAG_UNIQUE)
570 || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL))
570 unique = 1; 571 unique = 1;
571 if (!(mapflags & (MAP_OVERLAY|MAP_PLAYER_UNIQUE) || unique)) 572 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique))
572 SET_FLAG(otmp, FLAG_OBJ_ORIGINAL); 573 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL);
573 } 574 }
574 } 575 }
575 } 576 }
577
576 free_object(op); 578 free_object (op);
577 link_multipart_objects(m); 579 link_multipart_objects (m);
578} 580}
579 581
580/* This saves all the objects on the map in a non destructive fashion. 582/* This saves all the objects on the map in a non destructive fashion.
581 * Modified by MSW 2001-07-01 to do in a single pass - reduces code, 583 * Modified by MSW 2001-07-01 to do in a single pass - reduces code,
582 * and we only save the head of multi part objects - this is needed 584 * and we only save the head of multi part objects - this is needed
618 * Modified to no longer take a path option which was not being 620 * Modified to no longer take a path option which was not being
619 * used anyways. MSW 2001-07-01 621 * used anyways. MSW 2001-07-01
620 */ 622 */
621 623
622mapstruct *get_linked_map(void) { 624mapstruct *get_linked_map(void) {
623 mapstruct *map=(mapstruct *) calloc(1,sizeof(mapstruct)); 625 mapstruct *map = new mapstruct;
624 mapstruct *mp; 626 mapstruct *mp;
625
626 if(map==NULL)
627 fatal(OUT_OF_MEMORY);
628 627
629 for(mp=first_map;mp!=NULL&&mp->next!=NULL;mp=mp->next); 628 for(mp=first_map;mp!=NULL&&mp->next!=NULL;mp=mp->next);
630 if(mp==NULL) 629 if(mp==NULL)
631 first_map=map; 630 first_map=map;
632 else 631 else
703 number_of_entries++; 702 number_of_entries++;
704 if (p) p++; 703 if (p) p++;
705 } 704 }
706 p=shop_string; 705 p=shop_string;
707 strip_endline(p); 706 strip_endline(p);
708 items=(shopitems *) CALLOC(number_of_entries+1, sizeof(shopitems)); 707 items = new shopitems [number_of_entries + 1];
709 memset(items, 0, (sizeof(shopitems) * number_of_entries+1));
710 for (i=0; i<number_of_entries; i++) { 708 for (i=0; i<number_of_entries; i++) {
711 if (!p) { 709 if (!p) {
712 LOG(llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n"); 710 LOG(llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n");
713 break; 711 break;
714 } 712 }
815 value = NULL; 813 value = NULL;
816 break; 814 break;
817 } 815 }
818 } 816 }
819 } 817 }
818
820 if (!end) { 819 if (!end) {
821 LOG(llevError, "Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n", 820 LOG(llevError, "Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n",
822 buf); 821 buf);
823 return 1; 822 return 1;
824 } 823 }
825
826 824
827 /* key is the field name, value is what it should be set 825 /* key is the field name, value is what it should be set
828 * to. We've already done the work to null terminate key, 826 * to. We've already done the work to null terminate key,
829 * and strip off any leading spaces for both of these. 827 * and strip off any leading spaces for both of these.
830 * We have not touched the newline at the end of the line - 828 * We have not touched the newline at the end of the line -
888 * what really should be used. 886 * what really should be used.
889 */ 887 */
890 else if (!strcmp(key,"oid")) { 888 else if (!strcmp(key,"oid")) {
891 fp.get (m, atoi(value)); 889 fp.get (m, atoi(value));
892 } else if (!strcmp(key, "attach")) { 890 } else if (!strcmp(key, "attach")) {
893 m->attach = add_string (value); 891 m->attach = value;
894 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) { 892 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) {
895 m->enter_x = atoi(value); 893 m->enter_x = atoi(value);
896 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) { 894 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) {
897 m->enter_y = atoi(value); 895 m->enter_y = atoi(value);
898 } else if (!strcmp(key,"x") || !strcmp(key, "width")) { 896 } else if (!strcmp(key,"x") || !strcmp(key, "width")) {
1010 1008
1011mapstruct *load_original_map(const char *filename, int flags) { 1009mapstruct *load_original_map(const char *filename, int flags) {
1012 mapstruct *m; 1010 mapstruct *m;
1013 char pathname[MAX_BUF]; 1011 char pathname[MAX_BUF];
1014 1012
1015 LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags);
1016 if (flags & MAP_PLAYER_UNIQUE) 1013 if (flags & MAP_PLAYER_UNIQUE)
1017 strcpy(pathname, filename); 1014 strcpy(pathname, filename);
1018 else if (flags & MAP_OVERLAY) 1015 else if (flags & MAP_OVERLAY)
1019 strcpy(pathname, create_overlay_pathname(filename)); 1016 strcpy(pathname, create_overlay_pathname(filename));
1020 else 1017 else
1021 strcpy(pathname, create_pathname(filename)); 1018 strcpy(pathname, create_pathname(filename));
1022 1019
1020 LOG(llevDebug, "load_original_map(%x): %s (%s)\n", flags, filename, pathname);
1021
1023 object_thawer thawer (pathname); 1022 object_thawer thawer (pathname);
1024 1023
1025 if (!thawer) 1024 if (!thawer)
1026 return 0; 1025 return 0;
1027 1026
1053 * Return the map object we load into (this can change from the passed 1052 * Return the map object we load into (this can change from the passed
1054 * option if we can't find the original map) 1053 * option if we can't find the original map)
1055 */ 1054 */
1056 1055
1057static mapstruct *load_temporary_map(mapstruct *m) { 1056static mapstruct *load_temporary_map(mapstruct *m) {
1058 int comp;
1059 char buf[MAX_BUF]; 1057 char buf[MAX_BUF];
1060 1058
1061 if (!m->tmpname) { 1059 if (!m->tmpname) {
1062 LOG(llevError, "No temporary filename for map %s\n", m->path); 1060 LOG(llevError, "No temporary filename for map %s\n", m->path);
1063 strcpy(buf, m->path); 1061 strcpy(buf, m->path);
1179 return; 1177 return;
1180 1178
1181 m->in_memory=MAP_LOADING; 1179 m->in_memory=MAP_LOADING;
1182 if (m->tmpname == NULL) /* if we have loaded unique items from */ 1180 if (m->tmpname == NULL) /* if we have loaded unique items from */
1183 delete_unique_items(m); /* original map before, don't duplicate them */ 1181 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); 1182 load_objects (m, thawer, 0);
1186 1183
1187 m->in_memory=MAP_IN_MEMORY; 1184 m->in_memory=MAP_IN_MEMORY;
1188} 1185}
1189 1186
1198 */ 1195 */
1199 1196
1200int 1197int
1201new_save_map (mapstruct * m, int flag) 1198new_save_map (mapstruct * m, int flag)
1202{ 1199{
1203 char filename[MAX_BUF], buf[MAX_BUF], buf_s[MAX_BUF], shop[MAX_BUF]; 1200 char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF];
1204 int i; 1201 int i;
1205 1202
1206 if (flag && !*m->path) 1203 if (flag && !*m->path)
1207 { 1204 {
1208 LOG (llevError, "Tried to save map without path.\n"); 1205 LOG (llevError, "Tried to save map without path.\n");
1412 if (flag && m->spaces) free_all_objects(m); 1409 if (flag && m->spaces) free_all_objects(m);
1413 if (m->name) FREE_AND_CLEAR(m->name); 1410 if (m->name) FREE_AND_CLEAR(m->name);
1414 if (m->spaces) FREE_AND_CLEAR(m->spaces); 1411 if (m->spaces) FREE_AND_CLEAR(m->spaces);
1415 if (m->msg) FREE_AND_CLEAR(m->msg); 1412 if (m->msg) FREE_AND_CLEAR(m->msg);
1416 if (m->maplore) FREE_AND_CLEAR(m->maplore); 1413 if (m->maplore) FREE_AND_CLEAR(m->maplore);
1417 if (m->shopitems) FREE_AND_CLEAR(m->shopitems); 1414 if (m->shopitems) delete [] m->shopitems; m->shopitems = 0;
1418 if (m->shoprace) FREE_AND_CLEAR(m->shoprace); 1415 if (m->shoprace) FREE_AND_CLEAR(m->shoprace);
1419 if (m->buttons) 1416 if (m->buttons)
1420 free_objectlinkpt(m->buttons); 1417 free_objectlinkpt(m->buttons);
1421 m->buttons = NULL; 1418 m->buttons = NULL;
1422 for (i=0; i<4; i++) { 1419 for (i=0; i<4; i++) {
1482 m->path); 1479 m->path);
1483 } 1480 }
1484 else 1481 else
1485 last->next = m->next; 1482 last->next = m->next;
1486 1483
1487 free (m); 1484 delete m;
1488} 1485}
1489 1486
1490 1487
1491 1488
1492/* 1489/*
1535 if (flags & MAP_PLAYER_UNIQUE) 1532 if (flags & MAP_PLAYER_UNIQUE)
1536 LOG(llevDebug, "Trying to load map %s.\n", name); 1533 LOG(llevDebug, "Trying to load map %s.\n", name);
1537 else 1534 else
1538 LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name)); 1535 LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name));
1539 1536
1537 //eval_pv ("$x = Event::time", 1);//D
1540 if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE)))) 1538 if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE))))
1541 return (NULL); 1539 return (NULL);
1540 //eval_pv ("warn \"LOAD \", Event::time - $x", 1);//D
1542 1541
1543 fix_auto_apply(m); /* Chests which open as default */ 1542 fix_auto_apply(m); /* Chests which open as default */
1544 1543
1545 /* If a player unique map, no extra unique object file to load. 1544 /* If a player unique map, no extra unique object file to load.
1546 * if from the editor, likewise. 1545 * if from the editor, likewise.
1547 */ 1546 */
1548 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE))) 1547 if (!(flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE)))
1549 load_unique_objects(m); 1548 load_unique_objects(m);
1550 1549
1551 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) { 1550 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) {
1552 m=load_overlay_map(name, m); 1551 m=load_overlay_map(name, m);
1553 if (m==NULL) 1552 if (m==NULL)
1604 */ 1603 */
1605 1604
1606int calculate_difficulty(mapstruct *m) { 1605int calculate_difficulty(mapstruct *m) {
1607 object *op; 1606 object *op;
1608 archetype *at; 1607 archetype *at;
1609 int x, y, i, diff; 1608 int x, y, i;
1610 long monster_cnt = 0; 1609 long monster_cnt = 0;
1611 double avgexp = 0; 1610 double avgexp = 0;
1612 sint64 total_exp = 0; 1611 sint64 total_exp = 0;
1613 1612
1614 if (MAP_DIFFICULTY (m)) 1613 if (MAP_DIFFICULTY (m))
1804 if (QUERY_FLAG(tmp,FLAG_NO_MAGIC)) 1803 if (QUERY_FLAG(tmp,FLAG_NO_MAGIC))
1805 flags |= P_NO_MAGIC; 1804 flags |= P_NO_MAGIC;
1806 if (QUERY_FLAG(tmp,FLAG_DAMNED)) 1805 if (QUERY_FLAG(tmp,FLAG_DAMNED))
1807 flags |= P_NO_CLERIC; 1806 flags |= P_NO_CLERIC;
1808 if (tmp->type == SAFE_GROUND) 1807 if (tmp->type == SAFE_GROUND)
1809 flags |= P_SAFE | P_NO_CLERIC | P_NO_MAGIC; 1808 flags |= P_SAFE;
1810 1809
1811 if (QUERY_FLAG(tmp,FLAG_BLOCKSVIEW)) 1810 if (QUERY_FLAG(tmp,FLAG_BLOCKSVIEW))
1812 flags |= P_BLOCKSVIEW; 1811 flags |= P_BLOCKSVIEW;
1813 } /* for stack of objects */ 1812 } /* for stack of objects */
1814 1813

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines