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.53 by root, Wed Dec 27 09:28:01 2006 UTC vs.
Revision 1.54 by root, Wed Dec 27 13:13:46 2006 UTC

18 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 20
21 The authors can be reached via e-mail at <crossfire@schmorp.de> 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 22*/
23
24 23
25#include <global.h> 24#include <global.h>
26#include <funcpoint.h> 25#include <funcpoint.h>
27 26
28#include <loader.h> 27#include <loader.h>
612 for (op = m->at (i, j).bot; op; op = op->above) 611 for (op = m->at (i, j).bot; op; op = op->above)
613 { 612 {
614 if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR]) 613 if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR])
615 unique = 1; 614 unique = 1;
616 615
617 if (op->type == PLAYER) 616 if (!op->can_map_save ())
618 continue;
619
620 if (op->head || op->owner)
621 continue; 617 continue;
622 618
623 if (unique || op->flag [FLAG_UNIQUE]) 619 if (unique || op->flag [FLAG_UNIQUE])
624 save_object (fp2, op, 1); 620 save_object (fp2, op, 1);
625 else if (flag == 0 || (flag == 2 && (!op->flag [FLAG_OBJ_ORIGINAL] && !op->flag [FLAG_UNPAID]))) 621 else if (flag == 0 || (flag == 2 && (!op->flag [FLAG_OBJ_ORIGINAL] && !op->flag [FLAG_UNPAID])))
629} 625}
630 626
631maptile::maptile () 627maptile::maptile ()
632{ 628{
633 in_memory = MAP_SWAPPED; 629 in_memory = MAP_SWAPPED;
630
634 /* The maps used to pick up default x and y values from the 631 /* The maps used to pick up default x and y values from the
635 * map archetype. Mimic that behaviour. 632 * map archetype. Mimic that behaviour.
636 */ 633 */
637 width = 16; 634 width = 16;
638 height = 16; 635 height = 16;
643 /*set part to -1 indicating conversion to weather map not yet done */ 640 /*set part to -1 indicating conversion to weather map not yet done */
644 worldpartx = -1; 641 worldpartx = -1;
645 worldparty = -1; 642 worldparty = -1;
646} 643}
647 644
645void
646maptile::link ()
647{
648 next = first_map;
649 first_map = this;
650}
651
652void
653maptile::unlink ()
654{
655 if (first_map == this)
656 first_map = next;
657 else
658 for_all_maps (m)
659 if (m->next = this)
660 {
661 m->next = next;
662 break;
663 }
664}
665
648/* 666/*
649 * Allocates, initialises, and returns a pointer to a maptile. 667 * Allocates, initialises, and returns a pointer to a maptile.
650 * Modified to no longer take a path option which was not being 668 * Modified to no longer take a path option which was not being
651 * used anyways. MSW 2001-07-01 669 * used anyways. MSW 2001-07-01
652 */ 670 */
653maptile * 671maptile *
654get_linked_map (void) 672get_linked_map (void)
655{ 673{
656 maptile *map = new maptile; 674 maptile *map = new maptile;
657 675 map->link ();
658 map->next = first_map;
659 first_map = map;
660
661 return map; 676 return map;
662} 677}
663 678
664/* 679/*
665 * Allocates the arrays contained in a maptile. 680 * Allocates the arrays contained in a maptile.
722 p = strchr (p, ';'); 737 p = strchr (p, ';');
723 number_of_entries++; 738 number_of_entries++;
724 if (p) 739 if (p)
725 p++; 740 p++;
726 } 741 }
742
727 p = shop_string; 743 p = shop_string;
728 strip_endline (p); 744 strip_endline (p);
729 items = new shopitems[number_of_entries + 1]; 745 items = new shopitems[number_of_entries + 1];
730 for (i = 0; i < number_of_entries; i++) 746 for (i = 0; i < number_of_entries; i++)
731 { 747 {
732 if (!p) 748 if (!p)
733 { 749 {
734 LOG (llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n"); 750 LOG (llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n");
735 break; 751 break;
736 } 752 }
753
737 next_semicolon = strchr (p, ';'); 754 next_semicolon = strchr (p, ';');
738 next_colon = strchr (p, ':'); 755 next_colon = strchr (p, ':');
739 /* if there is a stregth specified, figure out what it is, we'll need it soon. */ 756 /* if there is a stregth specified, figure out what it is, we'll need it soon. */
740 if (next_colon && (!next_semicolon || next_colon < next_semicolon)) 757 if (next_colon && (!next_semicolon || next_colon < next_semicolon))
741 items[i].strength = atoi (strchr (p, ':') + 1); 758 items[i].strength = atoi (strchr (p, ':') + 1);
768 * the next entry while we're at it, better print a warning 785 * the next entry while we're at it, better print a warning
769 */ 786 */
770 LOG (llevError, "invalid type %s defined in shopitems in string %s\n", p, input_string); 787 LOG (llevError, "invalid type %s defined in shopitems in string %s\n", p, input_string);
771 } 788 }
772 } 789 }
790
773 items[i].index = number_of_entries; 791 items[i].index = number_of_entries;
774 if (next_semicolon) 792 if (next_semicolon)
775 p = ++next_semicolon; 793 p = ++next_semicolon;
776 else 794 else
777 p = NULL; 795 p = NULL;
778 } 796 }
797
779 free (shop_string); 798 free (shop_string);
780 return items; 799 return items;
781} 800}
782 801
783/* opposite of parse string, this puts the string that was originally fed in to 802/* opposite of parse string, this puts the string that was originally fed in to
792 for (i = 0; i < m->shopitems[0].index; i++) 811 for (i = 0; i < m->shopitems[0].index; i++)
793 { 812 {
794 if (m->shopitems[i].typenum) 813 if (m->shopitems[i].typenum)
795 { 814 {
796 if (m->shopitems[i].strength) 815 if (m->shopitems[i].strength)
797 {
798 sprintf (tmp, "%s:%d;", m->shopitems[i].name, m->shopitems[i].strength); 816 sprintf (tmp, "%s:%d;", m->shopitems[i].name, m->shopitems[i].strength);
799 }
800 else 817 else
801 sprintf (tmp, "%s;", m->shopitems[i].name); 818 sprintf (tmp, "%s;", m->shopitems[i].name);
802 } 819 }
803 else 820 else
804 { 821 {
805 if (m->shopitems[i].strength) 822 if (m->shopitems[i].strength)
806 {
807 sprintf (tmp, "*:%d;", m->shopitems[i].strength); 823 sprintf (tmp, "*:%d;", m->shopitems[i].strength);
808 }
809 else 824 else
810 sprintf (tmp, "*"); 825 sprintf (tmp, "*");
811 } 826 }
827
812 strcat (output_string, tmp); 828 strcat (output_string, tmp);
813 } 829 }
814} 830}
815 831
816/* This loads the header information of the map. The header 832/* This loads the header information of the map. The header
1084 * MAP_BLOCK, in which case we block on this load. This happens in all 1100 * MAP_BLOCK, in which case we block on this load. This happens in all
1085 * cases, no matter if this flag is set or not. 1101 * cases, no matter if this flag is set or not.
1086 * MAP_STYLE: style map - don't add active objects, don't add to server 1102 * MAP_STYLE: style map - don't add active objects, don't add to server
1087 * managed map list. 1103 * managed map list.
1088 */ 1104 */
1089
1090maptile * 1105maptile *
1091load_original_map (const char *filename, int flags) 1106load_original_map (const char *filename, int flags)
1092{ 1107{
1093 maptile *m; 1108 maptile *m;
1094 char pathname[MAX_BUF]; 1109 char pathname[MAX_BUF];
1133/* 1148/*
1134 * Loads a map, which has been loaded earlier, from file. 1149 * Loads a map, which has been loaded earlier, from file.
1135 * Return the map object we load into (this can change from the passed 1150 * Return the map object we load into (this can change from the passed
1136 * option if we can't find the original map) 1151 * option if we can't find the original map)
1137 */ 1152 */
1138
1139static maptile * 1153static maptile *
1140load_temporary_map (maptile *m) 1154load_temporary_map (maptile *m)
1141{ 1155{
1142 char buf[MAX_BUF]; 1156 char buf[MAX_BUF];
1143 1157
1187/* 1201/*
1188 * Loads a map, which has been loaded earlier, from file. 1202 * Loads a map, which has been loaded earlier, from file.
1189 * Return the map object we load into (this can change from the passed 1203 * Return the map object we load into (this can change from the passed
1190 * option if we can't find the original map) 1204 * option if we can't find the original map)
1191 */ 1205 */
1192
1193maptile * 1206maptile *
1194load_overlay_map (const char *filename, maptile *m) 1207load_overlay_map (const char *filename, maptile *m)
1195{ 1208{
1196 char pathname[MAX_BUF]; 1209 char pathname[MAX_BUF];
1197 1210
1500void 1513void
1501maptile::do_destroy () 1514maptile::do_destroy ()
1502{ 1515{
1503 attachable::do_destroy (); 1516 attachable::do_destroy ();
1504 1517
1518 unlink ();
1519
1505 free_map (this, 1); 1520 free_map (this, 1);
1506 free (tmpname), tmpname = 0; 1521 free (tmpname), tmpname = 0;
1507 1522
1508 /* We need to look through all the maps and see if any maps 1523 /* We need to look through all the maps and see if any maps
1509 * are pointing at this one for tiling information. Since 1524 * are pointing at this one for tiling information. Since
1513 //TODO: non-euclidean-tiling MUST GO 1528 //TODO: non-euclidean-tiling MUST GO
1514 for_all_maps (m) 1529 for_all_maps (m)
1515 for (int i = 0; i < 4; i++) 1530 for (int i = 0; i < 4; i++)
1516 if (m->tile_map[i] == this) 1531 if (m->tile_map[i] == this)
1517 m->tile_map[i] = 0; 1532 m->tile_map[i] = 0;
1518
1519 if (first_map == this)
1520 first_map = next;
1521 else
1522 for_all_maps (m)
1523 if (m->next = this)
1524 {
1525 m->next = next;
1526 break;
1527 }
1528} 1533}
1529 1534
1530//TODO: must go 1535//TODO: must go
1531void 1536void
1532delete_map (maptile *m) 1537delete_map (maptile *m)
1580 if (flags & MAP_PLAYER_UNIQUE) 1585 if (flags & MAP_PLAYER_UNIQUE)
1581 LOG (llevDebug, "Trying to load map %s.\n", name); 1586 LOG (llevDebug, "Trying to load map %s.\n", name);
1582 else 1587 else
1583 LOG (llevDebug, "Trying to load map %s.\n", create_pathname (name)); 1588 LOG (llevDebug, "Trying to load map %s.\n", create_pathname (name));
1584 1589
1585 //eval_pv ("$x = Event::time", 1);//D
1586 if (!(m = load_original_map (name, (flags & MAP_PLAYER_UNIQUE)))) 1590 if (!(m = load_original_map (name, (flags & MAP_PLAYER_UNIQUE))))
1587 return (NULL); 1591 return (NULL);
1588 //eval_pv ("warn \"LOAD \", Event::time - $x", 1);//D
1589 1592
1590 fix_auto_apply (m); /* Chests which open as default */ 1593 fix_auto_apply (m); /* Chests which open as default */
1591 1594
1592 /* If a player unique map, no extra unique object file to load. 1595 /* If a player unique map, no extra unique object file to load.
1593 * if from the editor, likewise. 1596 * if from the editor, likewise.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines