--- deliantra/server/common/loader.C 2007/02/01 17:29:16 1.51 +++ deliantra/server/common/loader.C 2007/02/08 03:09:31 1.55 @@ -30,94 +30,18 @@ #include #include -// resource loader pure base class -struct loader_base -{ - const char *filename; - virtual const char *type () const = 0; - - virtual archetype *get_arch (const char *name); - virtual void put_arch (archetype *arch); - - virtual object *get_object (const char *name); - virtual void put_object (object *op); - - virtual player *get_player (); - virtual void put_player (player *pl); - - virtual region *get_region (const char *name); - virtual void put_region (region *region); - - virtual facetile *get_face (const char *name); - virtual void put_face (facetile *face); - - virtual treasurelist *get_treasure (const char *name, bool one = false); - virtual void put_treasure (treasurelist *treasure); - - virtual animation *get_animation (const char *name); - virtual void put_animation (animation *anim); -}; - -// pure base class for default archetype loader -struct loader_arch : virtual loader_base { - archetype *get_arch (const char *name); - void put_arch (archetype *arch); -}; - -// pure base class for default object loader -struct loader_object : virtual loader_base { - object *get_object (const char *name); - void put_object (object *op); -}; - -// pure base class for default player loader -struct loader_player : virtual loader_base { - virtual player *get_player (); - virtual void put_player (player *pl); -}; - -// pure base class for default region loader -struct loader_region : virtual loader_base { - region *get_region (); - void put_region (region *region); -}; - -// pure base class for default face loader -struct loader_face : virtual loader_base { - facetile *get_face (const char *name); - void put_face (facetile *face); -}; - -// pure base class for default treasure loader -struct loader_treasure : virtual loader_base { - treasurelist *get_treasure (const char *name, bool one = false); - void put_treasure (treasurelist *treasure); -}; +///////////////////////////////////////////////////////////////////////////// -// pure base class for default animation loader -struct loader_animation : virtual loader_base { - animation *get_animation (const char *name); - void put_animation (animation *anim); -}; - -// future generic resource loader -// handles generic stuff valid in most files, such as -// animations, treasures, faces and so on -struct loader_generic -: virtual loader_base, - loader_object, loader_player, - loader_region, loader_face, - loader_treasure, loader_animation +loader_base::~loader_base () { - const char *type () const = 0; -}; +} // 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 type %s.\n", - filename, name, type ()); + LOG (llevError, "%s: found archetype definition '%s', which is not allowed in files of this type.\n", + filename, name); return new archetype; } @@ -125,8 +49,8 @@ object * loader_base::get_object (const char *name) { - LOG (llevError, "%s: found object definition '%s', which is not allowed in files of type %s.\n", - filename, name, type ()); + LOG (llevError, "%s: found object definition '%s', which is not allowed in files of this type.\n", + filename, name); return object::create (); } @@ -134,8 +58,8 @@ player * loader_base::get_player () { - LOG (llevError, "%s: found player definition, which is not allowed in files of type %s.\n", - filename, type ()); + LOG (llevError, "%s: found player definition, which is not allowed in files of this type.\n", + filename); return player::create (); } @@ -143,8 +67,8 @@ region * loader_base::get_region (const char *name) { - LOG (llevError, "%s: found region definition '%s', which is not allowed in files of type %s.\n", - filename, name, type ()); + LOG (llevError, "%s: found region definition '%s', which is not allowed in files of this type.\n", + filename, name); return new region; } @@ -152,8 +76,8 @@ facetile * loader_base::get_face (const char *name) { - LOG (llevError, "%s: found face definition '%s', which is not allowed in files of type %s.\n", - filename, name, type ()); + LOG (llevError, "%s: found face definition '%s', which is not allowed in files of this type.\n", + filename, name); return new facetile; } @@ -161,8 +85,8 @@ treasurelist * loader_base::get_treasure (const char *name, bool one) { - LOG (llevError, "%s: found treasure definition '%s', which is not allowed in files of type %s.\n", - filename, name, type ()); + LOG (llevError, "%s: found treasure definition '%s', which is not allowed in files of this type.\n", + filename, name); return new treasurelist;//D } @@ -170,8 +94,8 @@ animation * loader_base::get_animation (const char *name) { - LOG (llevError, "%s: found animation definition '%s', which is not allowed in files of type %s.\n", - filename, name, type ()); + LOG (llevError, "%s: found animation definition '%s', which is not allowed in files of this type.\n", + filename, name); return new animation; } @@ -218,6 +142,54 @@ 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 }; @@ -900,7 +872,7 @@ case KW_magic: thawer.get (op->magic); break; case KW_state: thawer.get (op->state); break; case KW_move_slow_penalty: thawer.get (op->move_slow_penalty); break; - case KW_material: thawer.get (op->material); break; + case KW_material: thawer.get (op->materials); break; //TODO: nuke case KW_materialname: thawer.get (op->materialname); break; /* These are the new values */ @@ -1172,6 +1144,8 @@ case KW_randomitems: op->randomitems = find_treasurelist (thawer.get_str ()); + //if (!op->randomitems) + // LOG (llevError, "%s uses unknown randomitems '%s'.\n", op->debug_desc (), thawer.get_str ()); break; case KW_msg: @@ -1224,7 +1198,8 @@ break; default: - LOG (llevError, "UNSUPPORTED KEYWORD IN MAP: \"%s\", bug in normaliser. skipping.\n", keyword_str[kw]); + if (!thawer.parse_error (kw, "object", op->name)) + return false; break; } } @@ -1568,7 +1543,7 @@ CMP_OUT (path_attuned); CMP_OUT (path_repelled); CMP_OUT (path_denied); - CMP_OUT (material); + CMP_OUT2 (material, materials);//TODO: nuke CMP_OUT (materialname); CMP_OUT (value); CMP_OUT (carrying);