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.22 by root, Mon Sep 4 11:07:59 2006 UTC vs.
Revision 1.27 by root, Fri Sep 8 12:56:42 2006 UTC

1/* 1/*
2 * static char *rcsid_map_c = 2 * static char *rcsid_map_c =
3 * "$Id: map.C,v 1.22 2006/09/04 11:07:59 root Exp $"; 3 * "$Id: map.C,v 1.27 2006/09/08 12:56:42 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
494 insert_ob_in_map(op, op->map, tmp,INS_NO_MERGE|INS_ABOVE_FLOOR_ONLY|INS_NO_WALK_ON); 494 insert_ob_in_map(op, op->map, tmp,INS_NO_MERGE|INS_ABOVE_FLOOR_ONLY|INS_NO_WALK_ON);
495 } /* for at = tmp->arch->more */ 495 } /* for at = tmp->arch->more */
496 } /* for objects on this space */ 496 } /* for objects on this space */
497} 497}
498 498
499
500
501/* 499/*
502 * Loads (ands parses) the objects into a given map from the specified 500 * Loads (ands parses) the objects into a given map from the specified
503 * file pointer. 501 * file pointer.
504 * mapflags is the same as we get with load_original_map 502 * mapflags is the same as we get with load_original_map
505 */ 503 */
506 504void
507void load_objects (mapstruct *m, object_thawer &fp, int mapflags) { 505load_objects (mapstruct *m, object_thawer &fp, int mapflags)
506{
508 int i,j; 507 int i, j;
509 int unique; 508 int unique;
510 object *op, *prev=NULL,*last_more=NULL, *otmp; 509 object *op, *prev = NULL, *last_more = NULL, *otmp;
511 510
512 op=get_object(); 511 op = get_object ();
513 op->map = m; /* To handle buttons correctly */ 512 op->map = m; /* To handle buttons correctly */
514 513
515 while((i = load_object (fp, op, mapflags))) { 514 while ((i = load_object (fp, op, mapflags)))
515 {
516 /* if the archetype for the object is null, means that we 516 /* if the archetype for the object is null, means that we
517 * 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
518 * 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.
519 */ 519 */
520 if (op->arch==NULL) { 520 if (op->arch == NULL)
521 LOG(llevDebug,"Discarding object without arch: %s\n", op->name?(const char *)op->name:"(null)"); 521 {
522 LOG (llevDebug, "Discarding object without arch: %s\n",
523 op->name ? (const char *) op->name : "(null)");
522 continue; 524 continue;
525 }
526
527
528 switch (i)
523 } 529 {
524
525
526 switch(i) {
527 case LL_NORMAL: 530 case LL_NORMAL:
528 /* if we are loading an overlay, put the floors on the bottom */ 531 /* if we are loading an overlay, put the floors on the bottom */
529 if ((QUERY_FLAG(op, FLAG_IS_FLOOR) || 532 if ((QUERY_FLAG (op, FLAG_IS_FLOOR) ||
530 QUERY_FLAG(op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) 533 QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY)
531 insert_ob_in_map(op,m,op,INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); 534 insert_ob_in_map (op, m, op,
535 INS_NO_MERGE | INS_NO_WALK_ON |
536 INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD);
532 else 537 else
533 insert_ob_in_map(op,m,op,INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); 538 insert_ob_in_map (op, m, op,
539 INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP |
540 INS_MAP_LOAD);
534 541
535 if (op->inv) 542 if (op->inv)
536 sum_weight(op); 543 sum_weight (op);
537 544
538 prev=op,last_more=op; 545 prev = op, last_more = op;
539 break; 546 break;
540 547
541 case LL_MORE: 548 case LL_MORE:
542 insert_ob_in_map(op,m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); 549 insert_ob_in_map (op, m, op,
550 INS_NO_MERGE | INS_NO_WALK_ON |
551 INS_ABOVE_FLOOR_ONLY);
543 op->head=prev,last_more->more=op,last_more=op; 552 op->head = prev, last_more->more = op, last_more = op;
544 break; 553 break;
545 } 554 }
555
546 if (mapflags & MAP_STYLE) { 556 if (mapflags & MAP_STYLE)
547 remove_from_active_list(op); 557 remove_from_active_list (op);
548 } 558
549 op=get_object(); 559 op = get_object ();
550 op->map = m; 560 op->map = m;
551 } 561 }
562
552 for (i=0;i<m->width;i++){ 563 for (i = 0; i < m->width; i++)
564 {
553 for (j=0;j<m->height;j++){ 565 for (j = 0; j < m->height; j++)
566 {
554 unique =0; 567 unique = 0;
555 /* check for unique items, or unique squares */ 568 /* check for unique items, or unique squares */
556 for (otmp = get_map_ob(m, i, j); otmp; otmp = otmp->above) { 569 for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above)
557 if (QUERY_FLAG(otmp, FLAG_UNIQUE) || QUERY_FLAG(otmp, FLAG_OBJ_SAVE_ON_OVL)) 570 {
571 if (QUERY_FLAG (otmp, FLAG_UNIQUE)
572 || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL))
558 unique = 1; 573 unique = 1;
559 if (!(mapflags & (MAP_OVERLAY|MAP_PLAYER_UNIQUE) || unique)) 574 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique))
560 SET_FLAG(otmp, FLAG_OBJ_ORIGINAL); 575 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL);
561 } 576 }
562 } 577 }
563 } 578 }
579
564 free_object(op); 580 free_object (op);
565 link_multipart_objects(m); 581 link_multipart_objects (m);
566} 582}
567 583
568/* This saves all the objects on the map in a non destructive fashion. 584/* This saves all the objects on the map in a non destructive fashion.
569 * Modified by MSW 2001-07-01 to do in a single pass - reduces code, 585 * Modified by MSW 2001-07-01 to do in a single pass - reduces code,
570 * and we only save the head of multi part objects - this is needed 586 * and we only save the head of multi part objects - this is needed
688 number_of_entries++; 704 number_of_entries++;
689 if (p) p++; 705 if (p) p++;
690 } 706 }
691 p=shop_string; 707 p=shop_string;
692 strip_endline(p); 708 strip_endline(p);
693 items=(shopitems *) CALLOC(number_of_entries+1, sizeof(shopitems)); 709 items = new shopitems [number_of_entries + 1];
694 memset(items, 0, (sizeof(shopitems) * number_of_entries+1));
695 for (i=0; i<number_of_entries; i++) { 710 for (i=0; i<number_of_entries; i++) {
696 if (!p) { 711 if (!p) {
697 LOG(llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n"); 712 LOG(llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n");
698 break; 713 break;
699 } 714 }
974 LOG(llevError,"Got unknown value in map header: %s %s\n", key, value); 989 LOG(llevError,"Got unknown value in map header: %s %s\n", key, value);
975 } 990 }
976 } 991 }
977 if (!key || strcmp(key,"end")) { 992 if (!key || strcmp(key,"end")) {
978 LOG(llevError,"Got premature eof on map header!\n"); 993 LOG(llevError,"Got premature eof on map header!\n");
979 abort();//D
980 return 1; 994 return 1;
981 } 995 }
982 return 0; 996 return 0;
983} 997}
984 998
1040 * Return the map object we load into (this can change from the passed 1054 * Return the map object we load into (this can change from the passed
1041 * option if we can't find the original map) 1055 * option if we can't find the original map)
1042 */ 1056 */
1043 1057
1044static mapstruct *load_temporary_map(mapstruct *m) { 1058static mapstruct *load_temporary_map(mapstruct *m) {
1045 int comp;
1046 char buf[MAX_BUF]; 1059 char buf[MAX_BUF];
1047 1060
1048 if (!m->tmpname) { 1061 if (!m->tmpname) {
1049 LOG(llevError, "No temporary filename for map %s\n", m->path); 1062 LOG(llevError, "No temporary filename for map %s\n", m->path);
1050 strcpy(buf, m->path); 1063 strcpy(buf, m->path);
1184 */ 1197 */
1185 1198
1186int 1199int
1187new_save_map (mapstruct * m, int flag) 1200new_save_map (mapstruct * m, int flag)
1188{ 1201{
1189 char filename[MAX_BUF], buf[MAX_BUF], buf_s[MAX_BUF], shop[MAX_BUF]; 1202 char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF];
1190 int i; 1203 int i;
1191 1204
1192 if (flag && !*m->path) 1205 if (flag && !*m->path)
1193 { 1206 {
1194 LOG (llevError, "Tried to save map without path.\n"); 1207 LOG (llevError, "Tried to save map without path.\n");
1398 if (flag && m->spaces) free_all_objects(m); 1411 if (flag && m->spaces) free_all_objects(m);
1399 if (m->name) FREE_AND_CLEAR(m->name); 1412 if (m->name) FREE_AND_CLEAR(m->name);
1400 if (m->spaces) FREE_AND_CLEAR(m->spaces); 1413 if (m->spaces) FREE_AND_CLEAR(m->spaces);
1401 if (m->msg) FREE_AND_CLEAR(m->msg); 1414 if (m->msg) FREE_AND_CLEAR(m->msg);
1402 if (m->maplore) FREE_AND_CLEAR(m->maplore); 1415 if (m->maplore) FREE_AND_CLEAR(m->maplore);
1403 if (m->shopitems) FREE_AND_CLEAR(m->shopitems); 1416 if (m->shopitems) delete [] m->shopitems; m->shopitems = 0;
1404 if (m->shoprace) FREE_AND_CLEAR(m->shoprace); 1417 if (m->shoprace) FREE_AND_CLEAR(m->shoprace);
1405 if (m->buttons) 1418 if (m->buttons)
1406 free_objectlinkpt(m->buttons); 1419 free_objectlinkpt(m->buttons);
1407 m->buttons = NULL; 1420 m->buttons = NULL;
1408 for (i=0; i<4; i++) { 1421 for (i=0; i<4; i++) {
1521 if (flags & MAP_PLAYER_UNIQUE) 1534 if (flags & MAP_PLAYER_UNIQUE)
1522 LOG(llevDebug, "Trying to load map %s.\n", name); 1535 LOG(llevDebug, "Trying to load map %s.\n", name);
1523 else 1536 else
1524 LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name)); 1537 LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name));
1525 1538
1526 //0.427459955215454 /var/crossfire/players/Saladon/_scorn_apartment_apartments
1527 //0.414906024932861
1528 //0.427063941955566
1529 eval_pv ("$x = Event::time", 1);//D 1539 //eval_pv ("$x = Event::time", 1);//D
1530 if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE)))) 1540 if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE))))
1531 return (NULL); 1541 return (NULL);
1532 eval_pv ("warn \"LOAD \", Event::time - $x", 1);//D 1542 //eval_pv ("warn \"LOAD \", Event::time - $x", 1);//D
1533 1543
1534 fix_auto_apply(m); /* Chests which open as default */ 1544 fix_auto_apply(m); /* Chests which open as default */
1535 1545
1536 /* If a player unique map, no extra unique object file to load. 1546 /* If a player unique map, no extra unique object file to load.
1537 * if from the editor, likewise. 1547 * if from the editor, likewise.
1538 */ 1548 */
1539 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE))) 1549 if (!(flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE)))
1540 load_unique_objects(m); 1550 load_unique_objects(m);
1541 1551
1542 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) { 1552 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) {
1543 m=load_overlay_map(name, m); 1553 m=load_overlay_map(name, m);
1544 if (m==NULL) 1554 if (m==NULL)
1595 */ 1605 */
1596 1606
1597int calculate_difficulty(mapstruct *m) { 1607int calculate_difficulty(mapstruct *m) {
1598 object *op; 1608 object *op;
1599 archetype *at; 1609 archetype *at;
1600 int x, y, i, diff; 1610 int x, y, i;
1601 long monster_cnt = 0; 1611 long monster_cnt = 0;
1602 double avgexp = 0; 1612 double avgexp = 0;
1603 sint64 total_exp = 0; 1613 sint64 total_exp = 0;
1604 1614
1605 if (MAP_DIFFICULTY (m)) 1615 if (MAP_DIFFICULTY (m))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines