--- deliantra/server/common/loader.C 2007/01/19 17:50:10 1.48 +++ deliantra/server/common/loader.C 2007/02/09 01:52:10 1.56 @@ -26,53 +26,169 @@ sub/add_weight will transcend the environment updating the carrying variable. */ - #include #include #include -// future resource loader base class -struct loader_base +///////////////////////////////////////////////////////////////////////////// + +loader_base::~loader_base () { - 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); +// 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); - virtual player *get_player (); - virtual void put_player (player *pl); + return new archetype; +} - virtual region *get_region (); - virtual void put_region (region *region); +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); - virtual facetile *get_face (const char *name); - virtual void put_face (facetile *face); + return object::create (); +} - virtual treasurelist *get_treasure (const char *name, bool one = false); - virtual void put_treasure (treasurelist *treasure); +player * +loader_base::get_player () +{ + LOG (llevError, "%s: found player definition, which is not allowed in files of this type.\n", + filename); - virtual animation *get_animation (const char *name); - virtual void put_animation (animation *anim); -}; + return player::create (); +} -// future generic resource loader -// handles generic stuff valid in most files, such as -// animations, treasures, faces and so on -struct loader_generic : loader_base -{ - virtual region *get_region (); - virtual void put_region (region *region); +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); - virtual facetile *get_face (const char *name); - virtual void put_face (facetile *face); + return new region; +} - virtual treasurelist *get_treasure (const char *name, bool one = false); - virtual void put_treasure (treasurelist *treasure); +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); - virtual animation *get_animation (const char *name); - virtual void put_animation (animation *anim); -}; + 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 }; @@ -419,7 +535,10 @@ if (QUERY_FLAG (op, FLAG_MONSTER)) { if (op->stats.hp > op->stats.maxhp) - LOG (llevDebug, "Monster %s has hp set higher than maxhp (%d>%d)\n", op->debug_desc (), op->stats.hp, op->stats.maxhp); + { + LOG (llevDebug, "Monster %s has hp set higher than maxhp (%d>%d)\n", op->debug_desc (), op->stats.hp, op->stats.maxhp); + op->stats.maxhp = op->stats.hp; + } /* The archs just need to be updated for this */ if (op->move_type == 0) @@ -601,6 +720,7 @@ { tmp = object::create (); /* record the name of the broken object */ + //TODO: but do not log??? tmp->name = str; } @@ -668,17 +788,13 @@ case KW_animation: { - const char *str = thawer.get_str (); + CLEAR_FLAG (op, FLAG_ANIMATE); + op->animation_id = 0; - if (!str) - { - op->animation_id = 0; - CLEAR_FLAG (op, FLAG_ANIMATE); - } - else if ((op->animation_id = find_animation (str))) + const char *str = thawer.get_str (); + if (str && (op->animation_id = find_animation (str))) SET_FLAG (op, FLAG_ANIMATE); } - break; case KW_last_heal: thawer.get (op->last_heal); break; @@ -753,7 +869,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 */ @@ -1025,6 +1141,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: @@ -1077,7 +1195,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; } } @@ -1421,7 +1540,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);