--- deliantra/server/common/loader.C 2007/01/18 19:42:09 1.47 +++ deliantra/server/common/loader.C 2007/02/15 21:07:48 1.58 @@ -26,11 +26,12 @@ sub/add_weight will transcend the environment updating the carrying variable. */ - #include #include #include +///////////////////////////////////////////////////////////////////////////// + /* Maps the MOVE_* values to names */ static const char *const move_name[] = { "walk", "fly_low", "fly_high", "swim", "boat", NULL }; @@ -264,8 +265,6 @@ static void check_loaded_object (object *op) { - int ip; - /* 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 @@ -276,7 +275,7 @@ * 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 = NULL; + op->name_pl = 0; if (!op->name_pl) op->name_pl = op->name; @@ -289,6 +288,7 @@ else set_materialname (op, 5, NULL); } + /* 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 @@ -297,25 +297,22 @@ if ((op->type == WEAPON || op->type == BOW) && arch_init) { if (!op->skill) - { - LOG (llevError, "Weapon %s lacks a skill.\n", op->debug_desc ()); - } + 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); - } + LOG (llevError, "weapon %s arm usage does not match skill: %d, %s\n", op->debug_desc (), op->body_info[1], &op->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 (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 (op->last_heal) { @@ -324,16 +321,17 @@ op->last_heal = 0; } - ip = calc_item_power (op, 0); + int ip = calc_item_power (op, 0); + /* Legacy objects from before item power was in the game */ if (!op->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", op->debug_desc (), ip); + op->item_power = ip; } + /* Check for possibly bogus values. Has to meet both these criteria - * something that has item_power 1 is probably just fine if our calculated * value is 1 or 2 - these values are small enough that hard to be precise. @@ -341,32 +339,26 @@ * 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); - } - + LOG (llevDebug, "Object %s seems to have too low item power? %d > %d\n", op->debug_desc (), ip, op->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 || /* 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 && !arch_init) { - object *tmp; - /* Fireall is bizarre in that spell type was stored in dam. Rest are 'normal' * in that spell was stored in sp. */ - tmp = get_archetype (spell_mapping[op->type == FIREWALL ? op->stats.dam : op->stats.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 */ } - /* spellbooks & runes use slaying. But not to arch name, but to spell name */ + /* spellbooks & runes use slaying. But not to arch name, but to spell name */ if ((op->type == SPELLBOOK || op->type == RUNE) && op->slaying && !op->inv && !arch_init) { - object *tmp; - - tmp = get_archetype_by_object_name (op->slaying); + 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 */ /* without this, value is all screwed up */ @@ -376,7 +368,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) @@ -409,9 +404,7 @@ op->stats.maxhp = 0; } else - { - op->move_type = MOVE_WALK; - } + op->move_type = MOVE_WALK; } } @@ -495,9 +488,7 @@ for (;;) { - keyword kw = thawer.get_kv (); - - switch (kw) + switch (thawer.get_kv ()) { case KW_Object: // uppercase alias case KW_object: @@ -558,6 +549,7 @@ { tmp = object::create (); /* record the name of the broken object */ + //TODO: but do not log??? tmp->name = str; } @@ -625,17 +617,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; @@ -710,7 +698,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 */ @@ -982,6 +970,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: @@ -1029,12 +1019,13 @@ return LL_EOF; case KW_ERROR: - set_ob_key_value (op, thawer.last_keyword, thawer.last_value, true); - //fprintf (stderr, "addkv(%s,%s)\n", thawer.last_keyword, thawer.last_value);//D + set_ob_key_value (op, thawer.kw_str, thawer.value, true); + //fprintf (stderr, "addkv(%s,%s)\n", thawer.kw_str, thawer.value);//D break; default: - LOG (llevError, "UNSUPPORTED KEYWORD IN MAP: \"%s\", bug in normaliser. skipping.\n", keyword_str[kw]); + if (!thawer.parse_error ("object", op->name)) + return false; break; } } @@ -1378,7 +1369,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); @@ -1465,3 +1456,32 @@ fp.put (KW_end); } +///////////////////////////////////////////////////////////////////////////// + +bool load_resource_file (const char *filename) +{ + object_thawer f (filename); + + f.next_kv (); + + for (;;) + { + switch (f.kw) + { + case KW_region: + if (!region::load (f)) + return false; + break; + + case KW_EOF: + return true; + + default: + if (!f.parse_error ("resource file")) + return false; + } + + f.next_kv (); + } +} +