… | |
… | |
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 | /* |
… | |
… | |
157 | int |
155 | int |
158 | check_path (const char *name, int prepend_dir) |
156 | check_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 |
… | |
… | |
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 | { |
… | |
… | |
600 | SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); |
592 | SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); |
601 | } |
593 | } |
602 | } |
594 | } |
603 | } |
595 | } |
604 | |
596 | |
605 | free_object (op); |
597 | op->destroy (); |
606 | link_multipart_objects (m); |
598 | link_multipart_objects (m); |
607 | } |
599 | } |
608 | |
600 | |
609 | /* This saves all the objects on the map in a non destructive fashion. |
601 | /* 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, |
602 | * Modified by MSW 2001-07-01 to do in a single pass - reduces code, |
… | |
… | |
860 | |
852 | |
861 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
853 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
862 | { |
854 | { |
863 | buf[HUGE_BUF - 1] = 0; |
855 | buf[HUGE_BUF - 1] = 0; |
864 | key = buf; |
856 | key = buf; |
|
|
857 | |
865 | while (isspace (*key)) |
858 | while (isspace (*key)) |
866 | key++; |
859 | key++; |
|
|
860 | |
867 | if (*key == 0) |
861 | if (*key == 0) |
868 | continue; /* empty line */ |
862 | continue; /* empty line */ |
|
|
863 | |
869 | value = strchr (key, ' '); |
864 | value = strchr (key, ' '); |
|
|
865 | |
870 | if (!value) |
866 | if (!value) |
871 | { |
867 | { |
872 | end = strchr (key, '\n'); |
868 | if ((end = strchr (key, '\n'))) |
873 | if (end != NULL) |
|
|
874 | { |
|
|
875 | *end = 0; |
869 | *end = 0; |
876 | } |
|
|
877 | } |
870 | } |
878 | else |
871 | else |
879 | { |
872 | { |
880 | *value = 0; |
873 | *value = 0; |
881 | value++; |
874 | value++; |
882 | end = strchr (value, '\n'); |
875 | end = strchr (value, '\n'); |
|
|
876 | |
883 | while (isspace (*value)) |
877 | while (isspace (*value)) |
884 | { |
878 | { |
885 | value++; |
879 | value++; |
|
|
880 | |
886 | if (*value == '\0' || value == end) |
881 | if (*value == '\0' || value == end) |
887 | { |
882 | { |
888 | /* Nothing but spaces. */ |
883 | /* Nothing but spaces. */ |
889 | value = NULL; |
884 | value = NULL; |
890 | break; |
885 | break; |
… | |
… | |
1303 | |
1298 | |
1304 | for (i = 0; i < MAP_WIDTH (m); i++) |
1299 | for (i = 0; i < MAP_WIDTH (m); i++) |
1305 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1300 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1306 | { |
1301 | { |
1307 | unique = 0; |
1302 | unique = 0; |
|
|
1303 | |
1308 | for (op = get_map_ob (m, i, j); op; op = next) |
1304 | for (op = get_map_ob (m, i, j); op; op = next) |
1309 | { |
1305 | { |
1310 | next = op->above; |
1306 | next = op->above; |
|
|
1307 | |
1311 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
1308 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
1312 | unique = 1; |
1309 | unique = 1; |
|
|
1310 | |
1313 | if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
1311 | if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
1314 | { |
1312 | { |
1315 | clean_object (op); |
1313 | clean_object (op); |
|
|
1314 | |
1316 | if (QUERY_FLAG (op, FLAG_IS_LINKED)) |
1315 | if (QUERY_FLAG (op, FLAG_IS_LINKED)) |
1317 | remove_button_link (op); |
1316 | remove_button_link (op); |
1318 | remove_ob (op); |
1317 | |
1319 | free_object (op); |
1318 | op->destroy (); |
1320 | } |
1319 | } |
1321 | } |
1320 | } |
1322 | } |
1321 | } |
1323 | } |
1322 | } |
1324 | |
1323 | |
… | |
… | |
1427 | print_shop_string (m, shop); |
1426 | print_shop_string (m, shop); |
1428 | fprintf (freezer, "shopitems %s\n", shop); |
1427 | fprintf (freezer, "shopitems %s\n", shop); |
1429 | } |
1428 | } |
1430 | if (m->shopgreed) |
1429 | if (m->shopgreed) |
1431 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1430 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1432 | #ifndef WIN32 |
|
|
1433 | if (m->shopmin) |
1431 | if (m->shopmin) |
1434 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1432 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1435 | if (m->shopmax) |
1433 | if (m->shopmax) |
1436 | fprintf (freezer, "shopmax %llu\n", m->shopmax); |
1434 | 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) |
1435 | if (m->shoprace) |
1444 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1436 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1445 | if (m->darkness) |
1437 | if (m->darkness) |
1446 | fprintf (freezer, "darkness %d\n", m->darkness); |
1438 | fprintf (freezer, "darkness %d\n", m->darkness); |
1447 | if (m->width) |
1439 | if (m->width) |
… | |
… | |
1526 | object *tmp, *next; |
1518 | object *tmp, *next; |
1527 | |
1519 | |
1528 | for (tmp = op->inv; tmp; tmp = next) |
1520 | for (tmp = op->inv; tmp; tmp = next) |
1529 | { |
1521 | { |
1530 | next = tmp->below; |
1522 | next = tmp->below; |
|
|
1523 | |
1531 | clean_object (tmp); |
1524 | clean_object (tmp); |
1532 | if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) |
1525 | if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) |
1533 | remove_button_link (tmp); |
1526 | remove_button_link (tmp); |
1534 | remove_ob (tmp); |
1527 | |
1535 | free_object (tmp); |
1528 | tmp->destroy (); |
1536 | } |
1529 | } |
1537 | } |
1530 | } |
1538 | |
1531 | |
1539 | /* |
1532 | /* |
1540 | * Remove and free all objects in the given map. |
1533 | * Remove and free all objects in the given map. |
… | |
… | |
1556 | if (op == previous_obj) |
1549 | if (op == previous_obj) |
1557 | { |
1550 | { |
1558 | LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); |
1551 | LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); |
1559 | break; |
1552 | break; |
1560 | } |
1553 | } |
|
|
1554 | |
1561 | previous_obj = op; |
1555 | previous_obj = op; |
|
|
1556 | |
1562 | if (op->head != NULL) |
1557 | if (op->head != NULL) |
1563 | op = op->head; |
1558 | op = op->head; |
1564 | |
1559 | |
1565 | /* If the map isn't in memory, free_object will remove and |
1560 | /* 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. |
1561 | * free objects in op's inventory. So let it do the job. |
1567 | */ |
1562 | */ |
1568 | if (m->in_memory == MAP_IN_MEMORY) |
1563 | if (m->in_memory == MAP_IN_MEMORY) |
1569 | clean_object (op); |
1564 | clean_object (op); |
1570 | remove_ob (op); |
1565 | |
1571 | free_object (op); |
1566 | op->destroy (); |
1572 | } |
1567 | } |
1573 | } |
1568 | } |
1574 | } |
1569 | } |
1575 | |
1570 | |
1576 | /* |
1571 | /* |