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.40 by root, Tue Dec 12 21:39:56 2006 UTC vs.
Revision 1.43 by root, Thu Dec 14 22:45:40 2006 UTC

550 } 550 }
551 551
552 552
553 switch (i) 553 switch (i)
554 { 554 {
555 case LL_NORMAL: 555 case LL_NORMAL:
556 /* if we are loading an overlay, put the floors on the bottom */ 556 /* if we are loading an overlay, put the floors on the bottom */
557 if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) 557 if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY)
558 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); 558 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD);
559 else 559 else
560 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); 560 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD);
561 561
562 if (op->inv) 562 if (op->inv)
563 sum_weight (op); 563 sum_weight (op);
564 564
565 prev = op, last_more = op; 565 prev = op, last_more = op;
566 break; 566 break;
567 567
568 case LL_MORE: 568 case LL_MORE:
569 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); 569 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY);
570 op->head = prev, last_more->more = op, last_more = op; 570 op->head = prev, last_more->more = op, last_more = op;
571 break; 571 break;
572 } 572 }
573 573
574 if (mapflags & MAP_STYLE) 574 if (mapflags & MAP_STYLE)
575 remove_from_active_list (op); 575 remove_from_active_list (op);
576 576
586 /* check for unique items, or unique squares */ 586 /* check for unique items, or unique squares */
587 for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above) 587 for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above)
588 { 588 {
589 if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) 589 if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL))
590 unique = 1; 590 unique = 1;
591
591 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) 592 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique))
592 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); 593 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL);
593 } 594 }
594 } 595 }
595 } 596 }
729 char *shop_string, *p, *q, *next_semicolon, *next_colon; 730 char *shop_string, *p, *q, *next_semicolon, *next_colon;
730 shopitems *items = NULL; 731 shopitems *items = NULL;
731 int i = 0, number_of_entries = 0; 732 int i = 0, number_of_entries = 0;
732 const typedata *current_type; 733 const typedata *current_type;
733 734
734 shop_string = strdup_local (input_string); 735 shop_string = strdup (input_string);
735 p = shop_string; 736 p = shop_string;
736 /* first we'll count the entries, we'll need that for allocating the array shortly */ 737 /* first we'll count the entries, we'll need that for allocating the array shortly */
737 while (p) 738 while (p)
738 { 739 {
739 p = strchr (p, ';'); 740 p = strchr (p, ';');
925 * with nothing between). There is no reason in those cases to 926 * with nothing between). There is no reason in those cases to
926 * keep the empty message. Also, msgbuf contains garbage data 927 * keep the empty message. Also, msgbuf contains garbage data
927 * when msgpos is zero, so copying it results in crashes 928 * when msgpos is zero, so copying it results in crashes
928 */ 929 */
929 if (msgpos != 0) 930 if (msgpos != 0)
930 m->msg = strdup_local (msgbuf); 931 m->msg = strdup (msgbuf);
931 } 932 }
932 else if (!strcmp (key, "maplore")) 933 else if (!strcmp (key, "maplore"))
933 { 934 {
934 while (fgets (buf, HUGE_BUF, fp) != NULL) 935 while (fgets (buf, HUGE_BUF, fp) != NULL)
935 { 936 {
941 strcpy (maplorebuf + maplorepos, buf); 942 strcpy (maplorebuf + maplorepos, buf);
942 maplorepos += strlen (buf); 943 maplorepos += strlen (buf);
943 } 944 }
944 } 945 }
945 if (maplorepos != 0) 946 if (maplorepos != 0)
946 m->maplore = strdup_local (maplorebuf); 947 m->maplore = strdup (maplorebuf);
947 } 948 }
948 else if (!strcmp (key, "end")) 949 else if (!strcmp (key, "end"))
949 { 950 {
950 break; 951 break;
951 } 952 }
960 LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value); 961 LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value);
961 } 962 }
962 else if (!strcmp (key, "name")) 963 else if (!strcmp (key, "name"))
963 { 964 {
964 *end = 0; 965 *end = 0;
965 m->name = strdup_local (value); 966 m->name = strdup (value);
966 } 967 }
967 /* first strcmp value on these are old names supported 968 /* first strcmp value on these are old names supported
968 * for compatibility reasons. The new values (second) are 969 * for compatibility reasons. The new values (second) are
969 * what really should be used. 970 * what really should be used.
970 */ 971 */
971 else if (!strcmp (key, "oid")) 972 else if (!strcmp (key, "oid"))
972 {
973 fp.get (m, atoi (value)); 973 fp.get (m, atoi (value));
974 }
975 else if (!strcmp (key, "attach")) 974 else if (!strcmp (key, "attach"))
976 {
977 m->attach = value; 975 m->attach = value;
978 }
979 else if (!strcmp (key, "hp") || !strcmp (key, "enter_x")) 976 else if (!strcmp (key, "hp") || !strcmp (key, "enter_x"))
980 {
981 m->enter_x = atoi (value); 977 m->enter_x = atoi (value);
982 }
983 else if (!strcmp (key, "sp") || !strcmp (key, "enter_y")) 978 else if (!strcmp (key, "sp") || !strcmp (key, "enter_y"))
984 {
985 m->enter_y = atoi (value); 979 m->enter_y = atoi (value);
986 }
987 else if (!strcmp (key, "x") || !strcmp (key, "width")) 980 else if (!strcmp (key, "x") || !strcmp (key, "width"))
988 {
989 m->width = atoi (value); 981 m->width = atoi (value);
990 }
991 else if (!strcmp (key, "y") || !strcmp (key, "height")) 982 else if (!strcmp (key, "y") || !strcmp (key, "height"))
992 {
993 m->height = atoi (value); 983 m->height = atoi (value);
994 }
995 else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout")) 984 else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout"))
996 {
997 m->reset_timeout = atoi (value); 985 m->reset_timeout = atoi (value);
998 }
999 else if (!strcmp (key, "value") || !strcmp (key, "swap_time")) 986 else if (!strcmp (key, "value") || !strcmp (key, "swap_time"))
1000 {
1001 m->timeout = atoi (value); 987 m->timeout = atoi (value);
1002 }
1003 else if (!strcmp (key, "level") || !strcmp (key, "difficulty")) 988 else if (!strcmp (key, "level") || !strcmp (key, "difficulty"))
1004 { 989 m->difficulty = clamp (atoi (value), 1, settings.max_level);
1005 m->difficulty = atoi (value);
1006 }
1007 else if (!strcmp (key, "invisible") || !strcmp (key, "darkness")) 990 else if (!strcmp (key, "invisible") || !strcmp (key, "darkness"))
1008 {
1009 m->darkness = atoi (value); 991 m->darkness = atoi (value);
1010 }
1011 else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime")) 992 else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime"))
1012 {
1013 m->fixed_resettime = atoi (value); 993 m->fixed_resettime = atoi (value);
1014 }
1015 else if (!strcmp (key, "unique")) 994 else if (!strcmp (key, "unique"))
1016 {
1017 m->unique = atoi (value); 995 m->unique = atoi (value);
1018 }
1019 else if (!strcmp (key, "template")) 996 else if (!strcmp (key, "template"))
1020 {
1021 m->templatemap = atoi (value); 997 m->templatemap = atoi (value);
1022 }
1023 else if (!strcmp (key, "region")) 998 else if (!strcmp (key, "region"))
1024 {
1025 m->region = get_region_by_name (value); 999 m->region = get_region_by_name (value);
1026 }
1027 else if (!strcmp (key, "shopitems")) 1000 else if (!strcmp (key, "shopitems"))
1028 { 1001 {
1029 *end = 0; 1002 *end = 0;
1030 m->shopitems = parse_shop_string (value); 1003 m->shopitems = parse_shop_string (value);
1031 } 1004 }
1032 else if (!strcmp (key, "shopgreed")) 1005 else if (!strcmp (key, "shopgreed"))
1033 {
1034 m->shopgreed = atof (value); 1006 m->shopgreed = atof (value);
1035 }
1036 else if (!strcmp (key, "shopmin")) 1007 else if (!strcmp (key, "shopmin"))
1037 {
1038 m->shopmin = atol (value); 1008 m->shopmin = atol (value);
1039 }
1040 else if (!strcmp (key, "shopmax")) 1009 else if (!strcmp (key, "shopmax"))
1041 {
1042 m->shopmax = atol (value); 1010 m->shopmax = atol (value);
1043 }
1044 else if (!strcmp (key, "shoprace")) 1011 else if (!strcmp (key, "shoprace"))
1045 { 1012 {
1046 *end = 0; 1013 *end = 0;
1047 m->shoprace = strdup_local (value); 1014 m->shoprace = strdup (value);
1048 } 1015 }
1049 else if (!strcmp (key, "outdoor")) 1016 else if (!strcmp (key, "outdoor"))
1050 {
1051 m->outdoor = atoi (value); 1017 m->outdoor = atoi (value);
1052 }
1053 else if (!strcmp (key, "temp")) 1018 else if (!strcmp (key, "temp"))
1054 {
1055 m->temp = atoi (value); 1019 m->temp = atoi (value);
1056 }
1057 else if (!strcmp (key, "pressure")) 1020 else if (!strcmp (key, "pressure"))
1058 {
1059 m->pressure = atoi (value); 1021 m->pressure = atoi (value);
1060 }
1061 else if (!strcmp (key, "humid")) 1022 else if (!strcmp (key, "humid"))
1062 {
1063 m->humid = atoi (value); 1023 m->humid = atoi (value);
1064 }
1065 else if (!strcmp (key, "windspeed")) 1024 else if (!strcmp (key, "windspeed"))
1066 {
1067 m->windspeed = atoi (value); 1025 m->windspeed = atoi (value);
1068 }
1069 else if (!strcmp (key, "winddir")) 1026 else if (!strcmp (key, "winddir"))
1070 {
1071 m->winddir = atoi (value); 1027 m->winddir = atoi (value);
1072 }
1073 else if (!strcmp (key, "sky")) 1028 else if (!strcmp (key, "sky"))
1074 {
1075 m->sky = atoi (value); 1029 m->sky = atoi (value);
1076 }
1077 else if (!strcmp (key, "nosmooth")) 1030 else if (!strcmp (key, "nosmooth"))
1078 {
1079 m->nosmooth = atoi (value); 1031 m->nosmooth = atoi (value);
1080 }
1081 else if (!strncmp (key, "tile_path_", 10)) 1032 else if (!strncmp (key, "tile_path_", 10))
1082 { 1033 {
1083 int tile = atoi (key + 10); 1034 int tile = atoi (key + 10);
1084 1035
1085 if (tile < 1 || tile > 4) 1036 if (tile < 1 || tile > 4)
1118 } 1069 }
1119 1070
1120 if (editor) 1071 if (editor)
1121 { 1072 {
1122 /* Use the value as in the file. */ 1073 /* Use the value as in the file. */
1123 m->tile_path[tile - 1] = strdup_local (value); 1074 m->tile_path[tile - 1] = strdup (value);
1124 } 1075 }
1125 else if (path != NULL) 1076 else if (path != NULL)
1126 { 1077 {
1127 /* Use the normalized value. */ 1078 /* Use the normalized value. */
1128 m->tile_path[tile - 1] = strdup_local (path); 1079 m->tile_path[tile - 1] = strdup (path);
1129 } 1080 }
1130 } /* end if tile direction (in)valid */ 1081 } /* end if tile direction (in)valid */
1131 } 1082 }
1132 else 1083 else
1133 {
1134 LOG (llevError, "Got unknown value in map header: %s %s\n", key, value); 1084 LOG (llevError, "Got unknown value in map header: %s %s\n", key, value);
1135 }
1136 } 1085 }
1086
1137 if (!key || strcmp (key, "end")) 1087 if (!key || strcmp (key, "end"))
1138 { 1088 {
1139 LOG (llevError, "Got premature eof on map header!\n"); 1089 LOG (llevError, "Got premature eof on map header!\n");
1140 return 1; 1090 return 1;
1141 } 1091 }
1092
1142 return 0; 1093 return 0;
1143} 1094}
1144 1095
1145/* 1096/*
1146 * Opens the file "filename" and reads information about the map 1097 * Opens the file "filename" and reads information about the map
1392 make_path_to_file (filename); 1343 make_path_to_file (filename);
1393 } 1344 }
1394 else 1345 else
1395 { 1346 {
1396 if (!m->tmpname) 1347 if (!m->tmpname)
1397 m->tmpname = tempnam_local (settings.tmpdir, NULL); 1348 m->tmpname = tempnam (settings.tmpdir, NULL);
1398 1349
1399 strcpy (filename, m->tmpname); 1350 strcpy (filename, m->tmpname);
1400 } 1351 }
1401 1352
1402 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); 1353 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename);
1581 if (!m->in_memory) 1532 if (!m->in_memory)
1582 { 1533 {
1583 LOG (llevError, "Trying to free freed map.\n"); 1534 LOG (llevError, "Trying to free freed map.\n");
1584 return; 1535 return;
1585 } 1536 }
1537
1538 // TODO: use new/delete
1539#define FREE_AND_CLEAR(p) { free (p); p = NULL; }
1540
1586 if (flag && m->spaces) 1541 if (flag && m->spaces)
1587 free_all_objects (m); 1542 free_all_objects (m);
1588 if (m->name) 1543 if (m->name)
1589 FREE_AND_CLEAR (m->name); 1544 FREE_AND_CLEAR (m->name);
1590 if (m->spaces) 1545 if (m->spaces)
1591 FREE_AND_CLEAR (m->spaces); 1546 FREE_AND_CLEAR (m->spaces);
1592 if (m->msg) 1547 if (m->msg)
1593 FREE_AND_CLEAR (m->msg); 1548 FREE_AND_CLEAR (m->msg);
1594 if (m->maplore) 1549 if (m->maplore)
1595 FREE_AND_CLEAR (m->maplore); 1550 FREE_AND_CLEAR (m->maplore);
1596 if (m->shopitems) 1551
1597 delete[]m->shopitems; 1552 delete [] m->shopitems;
1598 m->shopitems = 0; 1553 m->shopitems = 0;
1554
1599 if (m->shoprace) 1555 if (m->shoprace)
1600 FREE_AND_CLEAR (m->shoprace); 1556 FREE_AND_CLEAR (m->shoprace);
1557
1601 if (m->buttons) 1558 if (m->buttons)
1602 free_objectlinkpt (m->buttons); 1559 free_objectlinkpt (m->buttons);
1560
1603 m->buttons = NULL; 1561 m->buttons = NULL;
1562
1604 for (i = 0; i < 4; i++) 1563 for (i = 0; i < 4; i++)
1605 { 1564 {
1606 if (m->tile_path[i]) 1565 if (m->tile_path[i])
1607 FREE_AND_CLEAR (m->tile_path[i]); 1566 FREE_AND_CLEAR (m->tile_path[i]);
1608 m->tile_map[i] = NULL; 1567 m->tile_map[i] = NULL;
1609 } 1568 }
1569
1610 m->in_memory = MAP_SWAPPED; 1570 m->in_memory = MAP_SWAPPED;
1571
1572#undef FREE_AND_CLEAR
1573
1611} 1574}
1612 1575
1613/* 1576/*
1614 * function: vanish maptile 1577 * function: vanish maptile
1615 * m : pointer to maptile, if NULL no action 1578 * m : pointer to maptile, if NULL no action
2145 timeout = MAP_RESET_TIMEOUT (map); 2108 timeout = MAP_RESET_TIMEOUT (map);
2146 if (timeout <= 0) 2109 if (timeout <= 0)
2147 timeout = MAP_DEFAULTRESET; 2110 timeout = MAP_DEFAULTRESET;
2148 if (timeout >= MAP_MAXRESET) 2111 if (timeout >= MAP_MAXRESET)
2149 timeout = MAP_MAXRESET; 2112 timeout = MAP_MAXRESET;
2150 MAP_WHEN_RESET (map) = seconds () + timeout; 2113 MAP_WHEN_RESET (map) = time (0) + timeout;
2151} 2114}
2152 2115
2153/* this updates the orig_map->tile_map[tile_num] value after loading 2116/* this updates the orig_map->tile_map[tile_num] value after loading
2154 * the map. It also takes care of linking back the freshly loaded 2117 * the map. It also takes care of linking back the freshly loaded
2155 * maps tile_map values if it tiles back to this one. It returns 2118 * maps tile_map values if it tiles back to this one. It returns

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines