--- deliantra/server/common/loader.C 2007/01/02 23:39:21 1.37 +++ deliantra/server/common/loader.C 2007/01/19 17:50:10 1.48 @@ -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,49 @@ #include #include +// future resource loader base class +struct 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); + + virtual player *get_player (); + virtual void put_player (player *pl); + + virtual region *get_region (); + 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 +{ + virtual region *get_region (); + 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); +}; + /* Maps the MOVE_* values to names */ static const char *const move_name[] = { "walk", "fly_low", "fly_high", "swim", "boat", NULL }; @@ -265,9 +309,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 +366,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) { @@ -633,11 +675,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 +693,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 +857,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 +948,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 +1309,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 +1318,8 @@ KW_NULL, KW_is_buildable, /* 110 */ + KW_destroy_on_death, + KW_NULL, }; int i; @@ -1284,7 +1327,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);