1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
3 | |
3 | |
|
|
4 | Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | |
7 | This program is free software; you can redistribute it and/or modify |
8 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | it under the terms of the GNU General Public License as published by |
… | |
… | |
399 | * Loads (ands parses) the objects into a given map from the specified |
400 | * Loads (ands parses) the objects into a given map from the specified |
400 | * file pointer. |
401 | * file pointer. |
401 | * mapflags is the same as we get with load_original_map |
402 | * mapflags is the same as we get with load_original_map |
402 | */ |
403 | */ |
403 | bool |
404 | bool |
404 | maptile::load_objects (object_thawer &thawer) |
405 | maptile::_load_objects (object_thawer &thawer) |
405 | { |
406 | { |
406 | int unique; |
407 | int unique; |
407 | object *op, *prev = NULL, *last_more = NULL, *otmp; |
408 | object *op, *prev = NULL, *last_more = NULL, *otmp; |
408 | |
409 | |
409 | op = object::create (); |
410 | op = object::create (); |
… | |
… | |
485 | for (object *op = ms->bot; op; op = op->above) |
486 | for (object *op = ms->bot; op; op = op->above) |
486 | op->deactivate_recursive (); |
487 | op->deactivate_recursive (); |
487 | } |
488 | } |
488 | |
489 | |
489 | bool |
490 | bool |
490 | maptile::save_objects (object_freezer &freezer, int flags) |
491 | maptile::_save_objects (object_freezer &freezer, int flags) |
491 | { |
492 | { |
492 | static int cede_count = 0; |
493 | static int cede_count = 0; |
493 | |
494 | |
494 | if (flags & IO_HEADER) |
495 | if (flags & IO_HEADER) |
495 | save_header (freezer); |
496 | _save_header (freezer); |
496 | |
497 | |
497 | if (!spaces) |
498 | if (!spaces) |
498 | return false; |
499 | return false; |
499 | |
500 | |
500 | for (int i = 0; i < size (); ++i) |
501 | for (int i = 0; i < size (); ++i) |
… | |
… | |
529 | |
530 | |
530 | return true; |
531 | return true; |
531 | } |
532 | } |
532 | |
533 | |
533 | bool |
534 | bool |
534 | maptile::load_objects (const char *path, bool skip_header) |
535 | maptile::_load_objects (const char *path, bool skip_header) |
535 | { |
536 | { |
536 | object_thawer thawer (path); |
537 | object_thawer thawer (path); |
537 | |
538 | |
538 | if (!thawer) |
539 | if (!thawer) |
539 | return false; |
540 | return false; |
… | |
… | |
547 | break; |
548 | break; |
548 | |
549 | |
549 | thawer.skip_kv (kw); |
550 | thawer.skip_kv (kw); |
550 | } |
551 | } |
551 | |
552 | |
552 | return load_objects (thawer); |
553 | return _load_objects (thawer); |
553 | } |
554 | } |
554 | |
555 | |
555 | bool |
556 | bool |
556 | maptile::save_objects (const char *path, int flags) |
557 | maptile::_save_objects (const char *path, int flags) |
557 | { |
558 | { |
558 | object_freezer freezer; |
559 | object_freezer freezer; |
559 | |
560 | |
560 | if (!save_objects (freezer, flags)) |
561 | if (!_save_objects (freezer, flags)) |
561 | return false; |
562 | return false; |
562 | |
563 | |
563 | return freezer.save (path); |
564 | return freezer.save (path); |
564 | } |
565 | } |
565 | |
566 | |
… | |
… | |
729 | * This could be done in lex (like the object loader), but I think |
730 | * This could be done in lex (like the object loader), but I think |
730 | * currently, there are few enough fields this is not a big deal. |
731 | * currently, there are few enough fields this is not a big deal. |
731 | * MSW 2001-07-01 |
732 | * MSW 2001-07-01 |
732 | */ |
733 | */ |
733 | bool |
734 | bool |
734 | maptile::load_header (object_thawer &thawer) |
735 | maptile::_load_header (object_thawer &thawer) |
735 | { |
736 | { |
736 | for (;;) |
737 | for (;;) |
737 | { |
738 | { |
738 | keyword kw = thawer.get_kv (); |
739 | keyword kw = thawer.get_kv (); |
739 | |
740 | |
… | |
… | |
815 | |
816 | |
816 | abort (); |
817 | abort (); |
817 | } |
818 | } |
818 | |
819 | |
819 | bool |
820 | bool |
820 | maptile::load_header (const char *path) |
821 | maptile::_load_header (const char *path) |
821 | { |
822 | { |
822 | object_thawer thawer (path); |
823 | object_thawer thawer (path); |
823 | |
824 | |
824 | if (!thawer) |
825 | if (!thawer) |
825 | return false; |
826 | return false; |
826 | |
827 | |
827 | return load_header (thawer); |
828 | return _load_header (thawer); |
828 | } |
829 | } |
829 | |
830 | |
830 | /****************************************************************************** |
831 | /****************************************************************************** |
831 | * This is the start of unique map handling code |
832 | * This is the start of unique map handling code |
832 | *****************************************************************************/ |
833 | *****************************************************************************/ |
… | |
… | |
855 | } |
856 | } |
856 | } |
857 | } |
857 | } |
858 | } |
858 | |
859 | |
859 | bool |
860 | bool |
860 | maptile::save_header (object_freezer &freezer) |
861 | maptile::_save_header (object_freezer &freezer) |
861 | { |
862 | { |
862 | #define MAP_OUT(k) freezer.put (KW_ ## k, k) |
863 | #define MAP_OUT(k) freezer.put (KW_ ## k, k) |
863 | #define MAP_OUT2(k,v) freezer.put (KW_ ## k, v) |
864 | #define MAP_OUT2(k,v) freezer.put (KW_ ## k, v) |
864 | |
865 | |
865 | MAP_OUT2 (arch, "map"); |
866 | MAP_OUT2 (arch, "map"); |
… | |
… | |
914 | |
915 | |
915 | return true; |
916 | return true; |
916 | } |
917 | } |
917 | |
918 | |
918 | bool |
919 | bool |
919 | maptile::save_header (const char *path) |
920 | maptile::_save_header (const char *path) |
920 | { |
921 | { |
921 | object_freezer freezer; |
922 | object_freezer freezer; |
922 | |
923 | |
923 | if (!save_header (freezer)) |
924 | if (!_save_header (freezer)) |
924 | return false; |
925 | return false; |
925 | |
926 | |
926 | return freezer.save (path); |
927 | return freezer.save (path); |
927 | } |
928 | } |
928 | |
929 | |