--- deliantra/server/common/loader.C 2007/04/28 17:51:57 1.73 +++ deliantra/server/common/loader.C 2007/05/26 15:44:02 1.85 @@ -1,5 +1,5 @@ /* - * CrossFire, A Multiplayer game for X-windows + * CrossFire, A Multiplayer game * * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team * Copyright (C) 2002 Mark Wedel & Crossfire Development Team @@ -259,9 +259,65 @@ * deal with legacy objects where fields may have changed. It can also be used * to check for objects to make sure there are no common errors. */ -static void -check_loaded_object (object *op) +void +object::post_load_check () { + if (type >= NUM_TYPES) + { + LOG (llevError, "%s: type out of range, resetting to 0.\n", debug_desc ()); + type = 0; + } + + switch (type) + { + case BOW: + case WAND: + case ROD: + case HORN: + if (slot [body_range].info != -1) + { + LOG (llevError, "%s: body_range %d != -1\n", debug_desc (), slot [body_range].info); + slot [body_range].info = -1; + } + break; + + case WEAPON: + if (slot [body_combat].info != -1) + { + LOG (llevError, "%s: body_combat %d != -1\n", debug_desc (), slot [body_combat].info); + slot [body_combat].info = -1; + } + break; + + case SHIELD: + if (slot [body_shield].info != -1) + { + LOG (llevError, "%s: body_shield %d != -1\n", debug_desc (), slot [body_shield].info); + slot [body_shield].info = -1; + } + break; + + case PLAYER: + if (slot [body_shield].info != 1) + { + LOG (llevError, "%s: body_shield %d != 1\n", debug_desc (), slot [body_shield].info); + slot [body_shield].info = 1; + } + + if (slot [body_combat].info != 1) + { + LOG (llevError, "%s: body_combat %d != 1\n", debug_desc (), slot [body_combat].info); + slot [body_combat].info = 1; + } + + if (slot [body_range].info != 1) + { + LOG (llevError, "%s: body_range %d != 1\n", debug_desc (), slot [body_range].info); + slot [body_range].info = 1; + } + break; + } + /* 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 pluralised), but works to @@ -271,62 +327,57 @@ * Otherwise, what happens is that the the plural name will lose * information (appear as just 'hearts' and not 'goblins heart') */ - if (op->arch && op->name != op->arch->clone.name && op->name_pl == op->arch->clone.name_pl) - op->name_pl = 0; + if (arch && name != arch->clone.name && name_pl == arch->clone.name_pl) + name_pl = 0; - if (!op->name_pl) - op->name_pl = op->name; + if (!name_pl) + name_pl = name; /* objects now have a materialname. try to patch it in */ - if (!(op->is_weapon () && op->level > 0)) - { - if (op->map != NULL) - set_materialname (op, op->map->difficulty, NULL); - else - set_materialname (op, 5, NULL); - } + if (!(is_weapon () && level > 0)) + set_materialname (this, map ? map->difficulty : 5, 0); /* only do these when program is first run - a bit * excessive to do this at every run - most of this is * really just to catch any errors - program will still run, but * not in the ideal fashion. */ - if ((op->type == WEAPON || op->type == BOW) && loading_arch) + if (loading_arch && (type == WEAPON || type == BOW || type == ROD || type == HORN || type == WAND)) { - if (!op->skill) - LOG (llevError, "Weapon %s lacks a skill.\n", op->debug_desc ()); - else if ((!strcmp (op->skill, "one handed weapons") && op->body_info[1] != -1) || - (!strcmp (op->skill, "two handed weapons") && op->body_info[1] != -2)) - LOG (llevError, "weapon %s arm usage does not match skill: %d, %s\n", op->debug_desc (), op->body_info[1], &op->skill); + if (!skill) + LOG (llevError, "Weapon %s lacks a skill.\n", debug_desc ()); + else if ((!strcmp (skill, "one handed weapons") && slot[body_arm].info != -1) || + (!strcmp (skill, "two handed weapons") && slot[body_arm].info != -2)) + LOG (llevError, "weapon %s arm usage does not match skill: %d, %s\n", debug_desc (), slot[body_arm].info, &skill); } /* We changed last_heal to gen_sp_armour, which is what it * really does for many objects. Need to catch any in maps * that may have an old value. */ - if (op->type == WEAPON - || op->type == ARMOUR || op->type == HELMET - || op->type == SHIELD || op->type == RING - || op->type == BOOTS || op->type == GLOVES - || op->type == AMULET || op->type == GIRDLE - || op->type == BRACERS || op->type == CLOAK) + if (type == WEAPON + || type == ARMOUR || type == HELMET + || type == SHIELD || type == RING + || type == BOOTS || type == GLOVES + || type == AMULET || type == GIRDLE + || type == BRACERS || type == CLOAK) { - if (op->last_heal) + if (last_heal) { - LOG (llevDebug, "Object %s still has last_heal set, not gen_sp_armour\n", op->debug_desc ()); - op->gen_sp_armour = op->last_heal; - op->last_heal = 0; + LOG (llevDebug, "Object %s still has last_heal set, not gen_sp_armour\n", debug_desc ()); + gen_sp_armour = last_heal; + last_heal = 0; } - int ip = calc_item_power (op, 0); + int ip = calc_item_power (this, 0); /* Legacy objects from before item power was in the game */ - if (!op->item_power && ip) + if (!item_power && ip) { if (ip > 3) - LOG (llevDebug, "Object %s had no item power, using %d\n", op->debug_desc (), ip); + LOG (llevDebug, "Object %s had no item power, using %d\n", debug_desc (), ip); - op->item_power = ip; + item_power = ip; } /* Check for possibly bogus values. Has to meet both these criteria - @@ -335,54 +386,56 @@ * similarly, it item_power is 0, the first check will always pass, * but not the second one. */ - if (ip > 2 * op->item_power && ip > (op->item_power + 3)) - LOG (llevDebug, "Object %s seems to have too low item power? %d > %d\n", op->debug_desc (), ip, op->item_power); +#if 0 //TODO + if (ip > 2 * item_power && ip > (item_power + 3)) + LOG (llevDebug, "Object %s seems to have too low item power? %d > %d\n", debug_desc (), ip, item_power); +#endif } /* Old spellcasting object - need to load in the appropiate object */ - if ((op->type == ROD || op->type == WAND || op->type == SCROLL || op->type == HORN || op->type == FIREWALL || + if ((type == ROD || type == WAND || type == SCROLL || type == HORN || type == FIREWALL || /* POTIONS and ALTARS don't always cast spells, but if they do, update them */ - ((op->type == POTION || op->type == ALTAR) && op->stats.sp)) && !op->inv && !loading_arch) + ((type == POTION || type == ALTAR) && stats.sp)) && !inv && !loading_arch) { /* Fireall is bizarre in that spell type was stored in dam. Rest are 'normal' * in that spell was stored in sp. */ - object *tmp = get_archetype (spell_mapping[op->type == FIREWALL ? op->stats.dam : op->stats.sp]); - insert_ob_in_ob (tmp, op); - op->randomitems = NULL; /* So another spell isn't created for this object */ + object *tmp = get_archetype (spell_mapping[type == FIREWALL ? stats.dam : stats.sp]); + insert_ob_in_ob (tmp, this); + randomitems = NULL; /* So another spell isn't created for this object */ } /* spellbooks & runes use slaying. But not to arch name, but to spell name */ - if ((op->type == SPELLBOOK || op->type == RUNE) && op->slaying && !op->inv && !loading_arch) + if ((type == SPELLBOOK || type == RUNE) && slaying && !inv && !loading_arch) { - object *tmp = get_archetype_by_object_name (op->slaying); - insert_ob_in_ob (tmp, op); - op->randomitems = NULL; /* So another spell isn't created for this object */ + object *tmp = get_archetype_by_object_name (slaying); + insert_ob_in_ob (tmp, this); + randomitems = NULL; /* So another spell isn't created for this object */ /* without this, value is all screwed up */ - op->value = op->arch->clone.value * op->inv->value; + value = arch->clone.value * inv->value; } - if (QUERY_FLAG (op, FLAG_MONSTER)) + if (QUERY_FLAG (this, FLAG_MONSTER)) { - if (op->stats.hp > op->stats.maxhp) + if (stats.hp > 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; + LOG (llevDebug, "Monster %s has hp set higher than maxhp (%d>%d)\n", debug_desc (), stats.hp, stats.maxhp); + stats.maxhp = stats.hp; } /* The archs just need to be updated for this */ - if (op->move_type == 0) - op->move_type = MOVE_WALK; + if (move_type == 0) + move_type = MOVE_WALK; } - if ((QUERY_FLAG (op, FLAG_GENERATOR) && QUERY_FLAG (op, FLAG_CONTENT_ON_GEN)) || op->type == CREATOR || op->type == CONVERTER) + if ((QUERY_FLAG (this, FLAG_GENERATOR) && QUERY_FLAG (this, FLAG_CONTENT_ON_GEN)) || type == CREATOR || type == CONVERTER) { /* Object will duplicate it's content as part of the * generation process. To do this, we must flag inventory * so it remains unevaluated concerning the randomitems and * the living (a demonlord shouldn't cast from inside generator!) */ - flag_inv (op, FLAG_IS_A_TEMPLATE); + flag_inv (this, FLAG_IS_A_TEMPLATE); } /* Handle player movers. We use move_type for player movers @@ -391,20 +444,19 @@ * on them). If move_type is set, presume person knows what they * are doing, otherwise, set move_type based on maxhp value. */ - if (op->type == PLAYERMOVER) + if (type == PLAYERMOVER) { - if (!op->move_type) + if (!move_type) { - if (op->stats.maxhp) + if (stats.maxhp) { - op->move_type = MOVE_ALL; - op->stats.maxhp = 0; + move_type = MOVE_ALL; + stats.maxhp = 0; } else - op->move_type = MOVE_WALK; + move_type = MOVE_WALK; } } - } static void @@ -467,11 +519,7 @@ } } -#define GET_FLAG(op,flag) \ - if (f.get_sint32 ()) \ - SET_FLAG (op, flag); \ - else \ - CLEAR_FLAG (op, flag) \ +#define GET_FLAG(op,flg) op->flag [flg] = f.get_bool () bool object::parse_kv (object_thawer &f) @@ -726,24 +774,8 @@ break; - case KW_wiz: - GET_FLAG (this, FLAG_WIZ); - //TODO: move to check_object - if (QUERY_FLAG (this, FLAG_WIZ)) - { - SET_FLAG (this, FLAG_WAS_WIZ); - SET_FLAG (this, FLAG_WIZPASS); - SET_FLAG (this, FLAG_WIZCAST); - } - else - { - CLEAR_FLAG (this, FLAG_WIZPASS); - CLEAR_FLAG (this, FLAG_WIZCAST); - } - break; - case KW_friendly: - if (f.get_sint32 ()) + if (f.get_bool ()) if (type != PLAYER) add_friendly_object (this); @@ -782,7 +814,6 @@ case KW_no_magic: GET_FLAG (this, FLAG_NO_MAGIC); break; case KW_no_drop: GET_FLAG (this, FLAG_NO_DROP); break; case KW_random_movement: GET_FLAG (this, FLAG_RANDOM_MOVE); break; - case KW_was_wiz: GET_FLAG (this, FLAG_WAS_WIZ); break; case KW_no_fix_player: GET_FLAG (this, FLAG_NO_FIX_PLAYER); break; case KW_is_lightable: GET_FLAG (this, FLAG_IS_LIGHTABLE); break; case KW_tear_down: GET_FLAG (this, FLAG_TEAR_DOWN); break; @@ -892,18 +923,20 @@ //TODO: mechanism to ensure that KW_xxx is consecutive needed from include/preprocess //TODO: parse from other include files - case KW_body_range: f.get (body_info[0]); break; - case KW_body_arm: f.get (body_info[1]); break; - case KW_body_torso: f.get (body_info[2]); break; - case KW_body_head: f.get (body_info[3]); break; - case KW_body_neck: f.get (body_info[4]); break; - case KW_body_skill: f.get (body_info[5]); break; - case KW_body_finger: f.get (body_info[6]); break; - case KW_body_shoulder: f.get (body_info[7]); break; - case KW_body_foot: f.get (body_info[8]); break; - case KW_body_hand: f.get (body_info[9]); break; - case KW_body_wrist: f.get (body_info[10]); break; - case KW_body_waist: f.get (body_info[11]); break; + case KW_body_range: slot[body_range] .info = f.get_sint32 (); break; + case KW_body_shield: slot[body_shield] .info = f.get_sint32 (); break; + case KW_body_combat: slot[body_combat] .info = f.get_sint32 (); break; + case KW_body_arm: slot[body_arm] .info = f.get_sint32 (); break; + case KW_body_torso: slot[body_torso] .info = f.get_sint32 (); break; + case KW_body_head: slot[body_head] .info = f.get_sint32 (); break; + case KW_body_neck: slot[body_neck] .info = f.get_sint32 (); break; + case KW_body_skill: slot[body_skill] .info = f.get_sint32 (); break; + case KW_body_finger: slot[body_finger] .info = f.get_sint32 (); break; + case KW_body_shoulder: slot[body_shoulder].info = f.get_sint32 (); break; + case KW_body_foot: slot[body_foot] .info = f.get_sint32 (); break; + case KW_body_hand: slot[body_hand] .info = f.get_sint32 (); break; + case KW_body_wrist: slot[body_wrist] .info = f.get_sint32 (); break; + case KW_body_waist: slot[body_waist] .info = f.get_sint32 (); break; case KW_can_apply: break; @@ -922,6 +955,8 @@ if (!randomitems) LOG (llevError, "%s uses unknown randomitems '%s'.\n", debug_desc (), f.get_str ()); } + else + randomitems = 0; break; case KW_msg: @@ -950,8 +985,6 @@ break; case KW_end: - check_loaded_object (this); - if (!loading_arch) instantiate (); @@ -1003,6 +1036,7 @@ return 0; } + op->post_load_check (); return op; } @@ -1089,10 +1123,10 @@ */ static const keyword flag_names [NUM_FLAGS] = { KW_alive, - KW_wiz, KW_NULL, KW_NULL, - KW_was_wiz, + KW_NULL, + KW_NULL, KW_applied, KW_unpaid, KW_can_use_shield, @@ -1363,10 +1397,10 @@ if (flag_names [i] && op->flag [i] != tmp->flag [i]) f.put (flag_names [i], op->flag [i] ? "1" : "0"); - /* Save body locations */ + // save body locations for (i = 0; i < NUM_BODY_LOCATIONS; i++) - if (op->body_info[i] != tmp->body_info[i]) - f.put (body_locations[i].save_name, op->body_info[i]); + if (op->slot[i].info != tmp->slot[i].info) + f.put (body_locations[i].save_name, op->slot[i].info); } /* @@ -1438,6 +1472,9 @@ default: if (!f.parse_error ("resource file")) goto finish; + + f.next (); + break; } }