--- deliantra/server/common/loader.C 2007/01/02 23:39:21 1.37 +++ deliantra/server/common/loader.C 2007/01/19 18:06:51 1.50 @@ -1,25 +1,26 @@ /* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 2002 Mark Wedel & Crossfire Development Team - Copyright (C) 1992 Frank Tore Johansen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - The authors can be reached via e-mail at -*/ + * CrossFire, A Multiplayer game for X-windows + * + * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team + * Copyright (C) 2002 Mark Wedel & Crossfire Development Team + * Copyright (C) 1992 Frank Tore Johansen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * The authors can be reached via e-mail at + */ /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. sub/add_weight will transcend the environment updating the carrying @@ -30,6 +31,160 @@ #include #include +// future resource loader 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); +}; + +// future generic resource loader +// handles generic stuff valid in most files, such as +// animations, treasures, faces and so on +struct loader_generic : loader_base +{ + const char *type () const = 0; + + region *get_region (); + void put_region (region *region); + + facetile *get_face (const char *name); + void put_face (facetile *face); + + treasurelist *get_treasure (const char *name, bool one = false); + void put_treasure (treasurelist *treasure); + + animation *get_animation (const char *name); + void put_animation (animation *anim); +}; + +// 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 ()); + + 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 type %s.\n", + filename, name, type ()); + + return object::create (); +} + +player * +loader_base::get_player () +{ + LOG (llevError, "%s: found player definition, which is not allowed in files of type %s.\n", + filename, type ()); + + 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 type %s.\n", + filename, name, type ()); + + 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 type %s.\n", + filename, name, type ()); + + 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 type %s.\n", + filename, name, type ()); + + 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 type %s.\n", + filename, name, type ()); + + 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; +} + /* Maps the MOVE_* values to names */ static const char *const move_name[] = { "walk", "fly_low", "fly_high", "swim", "boat", NULL }; @@ -265,9 +420,9 @@ { int ip; - /* We do some specialized handling to handle legacy cases of name_pl. + /* We do some specialised handling to handle legacy cases of name_pl. * If the object doesn't have a name_pl, we just use the object name - - * this isn't perfect (things won't be properly pluralized), but works to + * this isn't perfect (things won't be properly pluralised), but works to * that degree (5 heart is still quite understandable). But the case we * also have to catch is if this object is not using the normal name for * the object. In that case, we also want to use the loaded name. @@ -322,10 +477,8 @@ op->gen_sp_armour = op->last_heal; op->last_heal = 0; } - if (editor) - ip = 0; - else - ip = calc_item_power (op, 0); + + ip = calc_item_power (op, 0); /* Legacy objects from before item power was in the game */ if (!op->item_power && ip) { @@ -377,7 +530,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) @@ -633,11 +789,8 @@ op->animation_id = 0; CLEAR_FLAG (op, FLAG_ANIMATE); } - else - { - op->animation_id = find_animation (str); - SET_FLAG (op, FLAG_ANIMATE); - } + else if ((op->animation_id = find_animation (str))) + SET_FLAG (op, FLAG_ANIMATE); } break; @@ -654,7 +807,7 @@ //TODO: maybe do in check_object // removed check for style maps if (op->speed < 0) - op->speed_left = op->speed_left - RANDOM () % 100 / 100.0; + op->speed_left = op->speed_left - rndm (); break; @@ -818,16 +971,17 @@ break; case KW_friendly: - GET_FLAG (op, FLAG_FRIENDLY); - //TODO: move to check_object or so - if (op->type != PLAYER && QUERY_FLAG (op, FLAG_FRIENDLY)) - add_friendly_object (op); + if (thawer.get_sint32 ()) + if (op->type != PLAYER) + add_friendly_object (op); + break; case KW_monster: GET_FLAG (op, FLAG_MONSTER); break; case KW_neutral: GET_FLAG (op, FLAG_NEUTRAL); break; case KW_no_attack: GET_FLAG (op, FLAG_NO_ATTACK); break; case KW_no_damage: GET_FLAG (op, FLAG_NO_DAMAGE); break; + case KW_obj_original: GET_FLAG (op, FLAG_OBJ_ORIGINAL); break; case KW_generator: GET_FLAG (op, FLAG_GENERATOR); break; case KW_use_content_on_gen: GET_FLAG (op, FLAG_CONTENT_ON_GEN); break; case KW_is_thrown: GET_FLAG (op, FLAG_IS_THROWN); break; @@ -908,6 +1062,7 @@ case KW_one_hit: GET_FLAG (op, FLAG_ONE_HIT); break; case KW_berserk: GET_FLAG (op, FLAG_BERSERK); break; case KW_is_buildable: GET_FLAG (op, FLAG_IS_BUILDABLE); break; + case KW_destroy_on_death: GET_FLAG (op, FLAG_DESTROY_ON_DEATH); break; case KW_armour: thawer.get (op->resist[ATNR_PHYSICAL]); break; case KW_resist_physical: thawer.get (op->resist[ATNR_PHYSICAL]); break; @@ -1268,7 +1423,7 @@ /* 100 */ KW_no_attack, KW_no_damage, - KW_NULL, + KW_obj_original, KW_NULL, KW_activate_on_push, KW_activate_on_release, @@ -1277,6 +1432,8 @@ KW_NULL, KW_is_buildable, /* 110 */ + KW_destroy_on_death, + KW_NULL, }; int i; @@ -1284,7 +1441,7 @@ /* This saves the key/value lists. We do it first so that any * keys that match field names will be overwritten by the loader. */ - for (key_value *my_field = op->key_values; my_field != NULL; my_field = my_field->next) + for (key_value *my_field = op->key_values; my_field; my_field = my_field->next) { /* Find the field in the opposing member. */ key_value *arch_field = get_ob_key_link (tmp, my_field->key);