--- deliantra/server/common/loader.C 2007/02/10 01:52:25 1.57 +++ deliantra/server/common/loader.C 2007/02/15 21:07:48 1.58 @@ -32,164 +32,6 @@ ///////////////////////////////////////////////////////////////////////////// -loader_base::~loader_base () -{ -} - -// the base class warns about and skips everything -archetype * -loader_base::get_arch (const char *name) -{ - LOG (llevError, "%s: found archetype definition '%s', which is not allowed in files of this type.\n", - filename, name); - - return new archetype; -} - -object * -loader_base::get_object (const char *name) -{ - LOG (llevError, "%s: found object definition '%s', which is not allowed in files of this type.\n", - filename, name); - - return object::create (); -} - -player * -loader_base::get_player () -{ - LOG (llevError, "%s: found player definition, which is not allowed in files of this type.\n", - filename); - - return player::create (); -} - -region * -loader_base::get_region (const char *name) -{ - LOG (llevError, "%s: found region definition '%s', which is not allowed in files of this type.\n", - filename, name); - - return new region; -} - -facetile * -loader_base::get_face (const char *name) -{ - LOG (llevError, "%s: found face definition '%s', which is not allowed in files of this type.\n", - filename, name); - - return new facetile; -} - -treasurelist * -loader_base::get_treasure (const char *name, bool one) -{ - LOG (llevError, "%s: found treasure definition '%s', which is not allowed in files of this type.\n", - filename, name); - - return new treasurelist;//D -} - -animation * -loader_base::get_animation (const char *name) -{ - LOG (llevError, "%s: found animation definition '%s', which is not allowed in files of this type.\n", - filename, name); - - return new animation; -} - -void -loader_base::put_arch (archetype *arch) -{ - delete arch; -} - -void -loader_base::put_object (object *op) -{ - op->destroy (); -} - -void -loader_base::put_player (player *pl) -{ - delete pl; -} - -void -loader_base::put_region (region *region) -{ - delete region; -} - -void -loader_base::put_face (facetile *face) -{ - delete face; -} - -void -loader_base::put_treasure (treasurelist *treasure) -{ - delete treasure; -} - -void -loader_base::put_animation (animation *anim) -{ - delete anim; -} - -///////////////////////////////////////////////////////////////////////////// - -bool loader_base::parse (object_thawer &thawer) -{ - for (;;) - { - keyword kw = thawer.get_kv (); - - switch (kw) - { - case KW_region: - { - region *rgn = get_region (thawer.get_str ()); - - if (!parse_region (thawer, rgn)) - { - delete rgn; - return false; - } - - put_region (rgn); - } - break; - - case KW_EOF: - return true; - - default: - if (!thawer.parse_error (kw, "resource file")) - return false; - } - } -} - -bool loader_base::load (const char *filename) -{ - this->filename = filename; - - object_thawer fp (filename); - - if (!fp) - return false; - - return parse (fp); -} - -///////////////////////////////////////////////////////////////////////////// - /* Maps the MOVE_* values to names */ static const char *const move_name[] = { "walk", "fly_low", "fly_high", "swim", "boat", NULL }; @@ -646,9 +488,7 @@ for (;;) { - keyword kw = thawer.get_kv (); - - switch (kw) + switch (thawer.get_kv ()) { case KW_Object: // uppercase alias case KW_object: @@ -1179,12 +1019,12 @@ return LL_EOF; case KW_ERROR: - set_ob_key_value (op, thawer.last_keyword, thawer.last_value, true); - //fprintf (stderr, "addkv(%s,%s)\n", thawer.last_keyword, thawer.last_value);//D + set_ob_key_value (op, thawer.kw_str, thawer.value, true); + //fprintf (stderr, "addkv(%s,%s)\n", thawer.kw_str, thawer.value);//D break; default: - if (!thawer.parse_error (kw, "object", op->name)) + if (!thawer.parse_error ("object", op->name)) return false; break; } @@ -1616,3 +1456,32 @@ fp.put (KW_end); } +///////////////////////////////////////////////////////////////////////////// + +bool load_resource_file (const char *filename) +{ + object_thawer f (filename); + + f.next_kv (); + + for (;;) + { + switch (f.kw) + { + case KW_region: + if (!region::load (f)) + return false; + break; + + case KW_EOF: + return true; + + default: + if (!f.parse_error ("resource file")) + return false; + } + + f.next_kv (); + } +} +