--- deliantra/server/common/loader.C 2007/05/07 04:21:09 1.77 +++ deliantra/server/common/loader.C 2007/05/12 16:06:41 1.80 @@ -259,9 +259,60 @@ * 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 () { + switch (type) + { + case BOW: + case WAND: + case ROD: + case HORN: + case SKILL_TOOL: + 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 +322,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->slot[1].info != -1) || - (!strcmp (op->skill, "two handed weapons") && op->slot[1].info != -2)) - LOG (llevError, "weapon %s arm usage does not match skill: %d, %s\n", op->debug_desc (), op->slot[1].info, &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 +381,54 @@ * 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 (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); } /* 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 +437,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 @@ -892,18 +937,20 @@ //TODO: mechanism to ensure that KW_xxx is consecutive needed from include/preprocess //TODO: parse from other include files - case KW_body_range: slot[ 0].info = f.get_sint32 (); break; - case KW_body_arm: slot[ 1].info = f.get_sint32 (); break; - case KW_body_torso: slot[ 2].info = f.get_sint32 (); break; - case KW_body_head: slot[ 3].info = f.get_sint32 (); break; - case KW_body_neck: slot[ 4].info = f.get_sint32 (); break; - case KW_body_skill: slot[ 5].info = f.get_sint32 (); break; - case KW_body_finger: slot[ 6].info = f.get_sint32 (); break; - case KW_body_shoulder: slot[ 7].info = f.get_sint32 (); break; - case KW_body_foot: slot[ 8].info = f.get_sint32 (); break; - case KW_body_hand: slot[ 9].info = f.get_sint32 (); break; - case KW_body_wrist: slot[10].info = f.get_sint32 (); break; - case KW_body_waist: slot[11].info = f.get_sint32 (); 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; @@ -952,8 +999,6 @@ break; case KW_end: - check_loaded_object (this); - if (!loading_arch) instantiate (); @@ -1005,6 +1050,7 @@ return 0; } + op->post_load_check (); return op; }