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.35 by root, Sun Dec 10 01:16:27 2006 UTC vs.
Revision 1.41 by root, Tue Dec 12 22:37:05 2006 UTC

24 24
25#include <global.h> 25#include <global.h>
26#include <funcpoint.h> 26#include <funcpoint.h>
27 27
28#include <loader.h> 28#include <loader.h>
29#ifndef WIN32 /* ---win32 exclude header */
30# include <unistd.h> 29#include <unistd.h>
31#endif /* win32 */
32 30
33#include "path.h" 31#include "path.h"
34 32
35 33
36/* 34/*
157int 155int
158check_path (const char *name, int prepend_dir) 156check_path (const char *name, int prepend_dir)
159{ 157{
160 char buf[MAX_BUF]; 158 char buf[MAX_BUF];
161 159
162#ifndef WIN32
163 char *endbuf; 160 char *endbuf;
164 struct stat statbuf; 161 struct stat statbuf;
165 int mode = 0; 162 int mode = 0;
166#endif
167 163
168 if (prepend_dir) 164 if (prepend_dir)
169 strcpy (buf, create_pathname (name)); 165 strcpy (buf, create_pathname (name));
170 else 166 else
171 strcpy (buf, name); 167 strcpy (buf, name);
172#ifdef WIN32 /* ***win32: check this sucker in windows style. */
173 return (_access (buf, 0));
174#else
175 168
176 /* old method (strchr(buf, '\0')) seemd very odd to me - 169 /* old method (strchr(buf, '\0')) seemd very odd to me -
177 * this method should be equivalant and is clearer. 170 * this method should be equivalant and is clearer.
178 * Can not use strcat because we need to cycle through 171 * Can not use strcat because we need to cycle through
179 * all the names. 172 * all the names.
192 if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || 185 if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) ||
193 (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH)) 186 (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH))
194 mode |= 2; 187 mode |= 2;
195 188
196 return (mode); 189 return (mode);
197#endif
198} 190}
199 191
200/* 192/*
201 * Prints out debug-information about a map. 193 * Prints out debug-information about a map.
202 * Dumping these at llevError doesn't seem right, but is 194 * Dumping these at llevError doesn't seem right, but is
540{ 532{
541 int i, j; 533 int i, j;
542 int unique; 534 int unique;
543 object *op, *prev = NULL, *last_more = NULL, *otmp; 535 object *op, *prev = NULL, *last_more = NULL, *otmp;
544 536
545 op = get_object (); 537 op = object::create ();
546 op->map = m; /* To handle buttons correctly */ 538 op->map = m; /* To handle buttons correctly */
547 539
548 while ((i = load_object (fp, op, mapflags))) 540 while ((i = load_object (fp, op, mapflags)))
549 { 541 {
550 /* if the archetype for the object is null, means that we 542 /* if the archetype for the object is null, means that we
558 } 550 }
559 551
560 552
561 switch (i) 553 switch (i)
562 { 554 {
563 case LL_NORMAL: 555 case LL_NORMAL:
564 /* 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 */
565 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)
566 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);
567 else 559 else
568 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);
569 561
570 if (op->inv) 562 if (op->inv)
571 sum_weight (op); 563 sum_weight (op);
572 564
573 prev = op, last_more = op; 565 prev = op, last_more = op;
574 break; 566 break;
575 567
576 case LL_MORE: 568 case LL_MORE:
577 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);
578 op->head = prev, last_more->more = op, last_more = op; 570 op->head = prev, last_more->more = op, last_more = op;
579 break; 571 break;
580 } 572 }
581 573
582 if (mapflags & MAP_STYLE) 574 if (mapflags & MAP_STYLE)
583 remove_from_active_list (op); 575 remove_from_active_list (op);
584 576
585 op = get_object (); 577 op = object::create ();
586 op->map = m; 578 op->map = m;
587 } 579 }
588 580
589 for (i = 0; i < m->width; i++) 581 for (i = 0; i < m->width; i++)
590 { 582 {
594 /* check for unique items, or unique squares */ 586 /* check for unique items, or unique squares */
595 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)
596 { 588 {
597 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))
598 unique = 1; 590 unique = 1;
591
599 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) 592 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique))
600 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); 593 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL);
601 } 594 }
602 } 595 }
603 } 596 }
604 597
605 free_object (op); 598 op->destroy ();
606 link_multipart_objects (m); 599 link_multipart_objects (m);
607} 600}
608 601
609/* This saves all the objects on the map in a non destructive fashion. 602/* This saves all the objects on the map in a non destructive fashion.
610 * Modified by MSW 2001-07-01 to do in a single pass - reduces code, 603 * Modified by MSW 2001-07-01 to do in a single pass - reduces code,
860 853
861 while (fgets (buf, HUGE_BUF, fp) != NULL) 854 while (fgets (buf, HUGE_BUF, fp) != NULL)
862 { 855 {
863 buf[HUGE_BUF - 1] = 0; 856 buf[HUGE_BUF - 1] = 0;
864 key = buf; 857 key = buf;
858
865 while (isspace (*key)) 859 while (isspace (*key))
866 key++; 860 key++;
861
867 if (*key == 0) 862 if (*key == 0)
868 continue; /* empty line */ 863 continue; /* empty line */
864
869 value = strchr (key, ' '); 865 value = strchr (key, ' ');
866
870 if (!value) 867 if (!value)
871 { 868 {
872 end = strchr (key, '\n'); 869 if ((end = strchr (key, '\n')))
873 if (end != NULL)
874 {
875 *end = 0; 870 *end = 0;
876 }
877 } 871 }
878 else 872 else
879 { 873 {
880 *value = 0; 874 *value = 0;
881 value++; 875 value++;
882 end = strchr (value, '\n'); 876 end = strchr (value, '\n');
877
883 while (isspace (*value)) 878 while (isspace (*value))
884 { 879 {
885 value++; 880 value++;
881
886 if (*value == '\0' || value == end) 882 if (*value == '\0' || value == end)
887 { 883 {
888 /* Nothing but spaces. */ 884 /* Nothing but spaces. */
889 value = NULL; 885 value = NULL;
890 break; 886 break;
972 /* first strcmp value on these are old names supported 968 /* first strcmp value on these are old names supported
973 * for compatibility reasons. The new values (second) are 969 * for compatibility reasons. The new values (second) are
974 * what really should be used. 970 * what really should be used.
975 */ 971 */
976 else if (!strcmp (key, "oid")) 972 else if (!strcmp (key, "oid"))
977 {
978 fp.get (m, atoi (value)); 973 fp.get (m, atoi (value));
979 }
980 else if (!strcmp (key, "attach")) 974 else if (!strcmp (key, "attach"))
981 {
982 m->attach = value; 975 m->attach = value;
983 }
984 else if (!strcmp (key, "hp") || !strcmp (key, "enter_x")) 976 else if (!strcmp (key, "hp") || !strcmp (key, "enter_x"))
985 {
986 m->enter_x = atoi (value); 977 m->enter_x = atoi (value);
987 }
988 else if (!strcmp (key, "sp") || !strcmp (key, "enter_y")) 978 else if (!strcmp (key, "sp") || !strcmp (key, "enter_y"))
989 {
990 m->enter_y = atoi (value); 979 m->enter_y = atoi (value);
991 }
992 else if (!strcmp (key, "x") || !strcmp (key, "width")) 980 else if (!strcmp (key, "x") || !strcmp (key, "width"))
993 {
994 m->width = atoi (value); 981 m->width = atoi (value);
995 }
996 else if (!strcmp (key, "y") || !strcmp (key, "height")) 982 else if (!strcmp (key, "y") || !strcmp (key, "height"))
997 {
998 m->height = atoi (value); 983 m->height = atoi (value);
999 }
1000 else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout")) 984 else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout"))
1001 {
1002 m->reset_timeout = atoi (value); 985 m->reset_timeout = atoi (value);
1003 }
1004 else if (!strcmp (key, "value") || !strcmp (key, "swap_time")) 986 else if (!strcmp (key, "value") || !strcmp (key, "swap_time"))
1005 {
1006 m->timeout = atoi (value); 987 m->timeout = atoi (value);
1007 }
1008 else if (!strcmp (key, "level") || !strcmp (key, "difficulty")) 988 else if (!strcmp (key, "level") || !strcmp (key, "difficulty"))
1009 { 989 m->difficulty = clamp (atoi (value), 1, settings.max_level);
1010 m->difficulty = atoi (value);
1011 }
1012 else if (!strcmp (key, "invisible") || !strcmp (key, "darkness")) 990 else if (!strcmp (key, "invisible") || !strcmp (key, "darkness"))
1013 {
1014 m->darkness = atoi (value); 991 m->darkness = atoi (value);
1015 }
1016 else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime")) 992 else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime"))
1017 {
1018 m->fixed_resettime = atoi (value); 993 m->fixed_resettime = atoi (value);
1019 }
1020 else if (!strcmp (key, "unique")) 994 else if (!strcmp (key, "unique"))
1021 {
1022 m->unique = atoi (value); 995 m->unique = atoi (value);
1023 }
1024 else if (!strcmp (key, "template")) 996 else if (!strcmp (key, "template"))
1025 {
1026 m->templatemap = atoi (value); 997 m->templatemap = atoi (value);
1027 }
1028 else if (!strcmp (key, "region")) 998 else if (!strcmp (key, "region"))
1029 {
1030 m->region = get_region_by_name (value); 999 m->region = get_region_by_name (value);
1031 }
1032 else if (!strcmp (key, "shopitems")) 1000 else if (!strcmp (key, "shopitems"))
1033 { 1001 {
1034 *end = 0; 1002 *end = 0;
1035 m->shopitems = parse_shop_string (value); 1003 m->shopitems = parse_shop_string (value);
1036 } 1004 }
1037 else if (!strcmp (key, "shopgreed")) 1005 else if (!strcmp (key, "shopgreed"))
1038 {
1039 m->shopgreed = atof (value); 1006 m->shopgreed = atof (value);
1040 }
1041 else if (!strcmp (key, "shopmin")) 1007 else if (!strcmp (key, "shopmin"))
1042 {
1043 m->shopmin = atol (value); 1008 m->shopmin = atol (value);
1044 }
1045 else if (!strcmp (key, "shopmax")) 1009 else if (!strcmp (key, "shopmax"))
1046 {
1047 m->shopmax = atol (value); 1010 m->shopmax = atol (value);
1048 }
1049 else if (!strcmp (key, "shoprace")) 1011 else if (!strcmp (key, "shoprace"))
1050 { 1012 {
1051 *end = 0; 1013 *end = 0;
1052 m->shoprace = strdup_local (value); 1014 m->shoprace = strdup_local (value);
1053 } 1015 }
1054 else if (!strcmp (key, "outdoor")) 1016 else if (!strcmp (key, "outdoor"))
1055 {
1056 m->outdoor = atoi (value); 1017 m->outdoor = atoi (value);
1057 }
1058 else if (!strcmp (key, "temp")) 1018 else if (!strcmp (key, "temp"))
1059 {
1060 m->temp = atoi (value); 1019 m->temp = atoi (value);
1061 }
1062 else if (!strcmp (key, "pressure")) 1020 else if (!strcmp (key, "pressure"))
1063 {
1064 m->pressure = atoi (value); 1021 m->pressure = atoi (value);
1065 }
1066 else if (!strcmp (key, "humid")) 1022 else if (!strcmp (key, "humid"))
1067 {
1068 m->humid = atoi (value); 1023 m->humid = atoi (value);
1069 }
1070 else if (!strcmp (key, "windspeed")) 1024 else if (!strcmp (key, "windspeed"))
1071 {
1072 m->windspeed = atoi (value); 1025 m->windspeed = atoi (value);
1073 }
1074 else if (!strcmp (key, "winddir")) 1026 else if (!strcmp (key, "winddir"))
1075 {
1076 m->winddir = atoi (value); 1027 m->winddir = atoi (value);
1077 }
1078 else if (!strcmp (key, "sky")) 1028 else if (!strcmp (key, "sky"))
1079 {
1080 m->sky = atoi (value); 1029 m->sky = atoi (value);
1081 }
1082 else if (!strcmp (key, "nosmooth")) 1030 else if (!strcmp (key, "nosmooth"))
1083 {
1084 m->nosmooth = atoi (value); 1031 m->nosmooth = atoi (value);
1085 }
1086 else if (!strncmp (key, "tile_path_", 10)) 1032 else if (!strncmp (key, "tile_path_", 10))
1087 { 1033 {
1088 int tile = atoi (key + 10); 1034 int tile = atoi (key + 10);
1089 1035
1090 if (tile < 1 || tile > 4) 1036 if (tile < 1 || tile > 4)
1133 m->tile_path[tile - 1] = strdup_local (path); 1079 m->tile_path[tile - 1] = strdup_local (path);
1134 } 1080 }
1135 } /* end if tile direction (in)valid */ 1081 } /* end if tile direction (in)valid */
1136 } 1082 }
1137 else 1083 else
1138 {
1139 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);
1140 }
1141 } 1085 }
1086
1142 if (!key || strcmp (key, "end")) 1087 if (!key || strcmp (key, "end"))
1143 { 1088 {
1144 LOG (llevError, "Got premature eof on map header!\n"); 1089 LOG (llevError, "Got premature eof on map header!\n");
1145 return 1; 1090 return 1;
1146 } 1091 }
1092
1147 return 0; 1093 return 0;
1148} 1094}
1149 1095
1150/* 1096/*
1151 * Opens the file "filename" and reads information about the map 1097 * Opens the file "filename" and reads information about the map
1303 1249
1304 for (i = 0; i < MAP_WIDTH (m); i++) 1250 for (i = 0; i < MAP_WIDTH (m); i++)
1305 for (j = 0; j < MAP_HEIGHT (m); j++) 1251 for (j = 0; j < MAP_HEIGHT (m); j++)
1306 { 1252 {
1307 unique = 0; 1253 unique = 0;
1254
1308 for (op = get_map_ob (m, i, j); op; op = next) 1255 for (op = get_map_ob (m, i, j); op; op = next)
1309 { 1256 {
1310 next = op->above; 1257 next = op->above;
1258
1311 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 1259 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE))
1312 unique = 1; 1260 unique = 1;
1261
1313 if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) 1262 if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique))
1314 { 1263 {
1315 clean_object (op); 1264 clean_object (op);
1265
1316 if (QUERY_FLAG (op, FLAG_IS_LINKED)) 1266 if (QUERY_FLAG (op, FLAG_IS_LINKED))
1317 remove_button_link (op); 1267 remove_button_link (op);
1318 remove_ob (op); 1268
1319 free_object (op); 1269 op->destroy ();
1320 } 1270 }
1321 } 1271 }
1322 } 1272 }
1323} 1273}
1324 1274
1427 print_shop_string (m, shop); 1377 print_shop_string (m, shop);
1428 fprintf (freezer, "shopitems %s\n", shop); 1378 fprintf (freezer, "shopitems %s\n", shop);
1429 } 1379 }
1430 if (m->shopgreed) 1380 if (m->shopgreed)
1431 fprintf (freezer, "shopgreed %f\n", m->shopgreed); 1381 fprintf (freezer, "shopgreed %f\n", m->shopgreed);
1432#ifndef WIN32
1433 if (m->shopmin) 1382 if (m->shopmin)
1434 fprintf (freezer, "shopmin %llu\n", m->shopmin); 1383 fprintf (freezer, "shopmin %llu\n", m->shopmin);
1435 if (m->shopmax) 1384 if (m->shopmax)
1436 fprintf (freezer, "shopmax %llu\n", m->shopmax); 1385 fprintf (freezer, "shopmax %llu\n", m->shopmax);
1437#else
1438 if (m->shopmin)
1439 fprintf (freezer, "shopmin %I64u\n", m->shopmin);
1440 if (m->shopmax)
1441 fprintf (freezer, "shopmax %I64u\n", m->shopmax);
1442#endif
1443 if (m->shoprace) 1386 if (m->shoprace)
1444 fprintf (freezer, "shoprace %s\n", m->shoprace); 1387 fprintf (freezer, "shoprace %s\n", m->shoprace);
1445 if (m->darkness) 1388 if (m->darkness)
1446 fprintf (freezer, "darkness %d\n", m->darkness); 1389 fprintf (freezer, "darkness %d\n", m->darkness);
1447 if (m->width) 1390 if (m->width)
1526 object *tmp, *next; 1469 object *tmp, *next;
1527 1470
1528 for (tmp = op->inv; tmp; tmp = next) 1471 for (tmp = op->inv; tmp; tmp = next)
1529 { 1472 {
1530 next = tmp->below; 1473 next = tmp->below;
1474
1531 clean_object (tmp); 1475 clean_object (tmp);
1532 if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) 1476 if (QUERY_FLAG (tmp, FLAG_IS_LINKED))
1533 remove_button_link (tmp); 1477 remove_button_link (tmp);
1534 remove_ob (tmp); 1478
1535 free_object (tmp); 1479 tmp->destroy ();
1536 } 1480 }
1537} 1481}
1538 1482
1539/* 1483/*
1540 * Remove and free all objects in the given map. 1484 * Remove and free all objects in the given map.
1556 if (op == previous_obj) 1500 if (op == previous_obj)
1557 { 1501 {
1558 LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); 1502 LOG (llevDebug, "free_all_objects: Link error, bailing out.\n");
1559 break; 1503 break;
1560 } 1504 }
1505
1561 previous_obj = op; 1506 previous_obj = op;
1507
1562 if (op->head != NULL) 1508 if (op->head != NULL)
1563 op = op->head; 1509 op = op->head;
1564 1510
1565 /* If the map isn't in memory, free_object will remove and 1511 /* If the map isn't in memory, free_object will remove and
1566 * free objects in op's inventory. So let it do the job. 1512 * free objects in op's inventory. So let it do the job.
1567 */ 1513 */
1568 if (m->in_memory == MAP_IN_MEMORY) 1514 if (m->in_memory == MAP_IN_MEMORY)
1569 clean_object (op); 1515 clean_object (op);
1570 remove_ob (op); 1516
1571 free_object (op); 1517 op->destroy ();
1572 } 1518 }
1573 } 1519 }
1574} 1520}
1575 1521
1576/* 1522/*

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines