--- deliantra/server/common/loader.C 2007/02/09 01:52:10 1.56 +++ deliantra/server/common/loader.C 2007/02/15 21:07:48 1.58 @@ -32,164 +32,6 @@ ///////////////////////////////////////////////////////////////////////////// -loader_base::~loader_base () -{ -} - -// 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 this type.\n", - filename, name); - - 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 this type.\n", - filename, name); - - return object::create (); -} - -player * -loader_base::get_player () -{ - LOG (llevError, "%s: found player definition, which is not allowed in files of this type.\n", - filename); - - 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 this type.\n", - filename, name); - - 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 this type.\n", - filename, name); - - 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 this type.\n", - filename, name); - - 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 this type.\n", - filename, name); - - 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; -} - -///////////////////////////////////////////////////////////////////////////// - -bool loader_base::parse (object_thawer &thawer) -{ - for (;;) - { - keyword kw = thawer.get_kv (); - - switch (kw) - { - case KW_region: - { - region *rgn = get_region (thawer.get_str ()); - - if (!parse_region (thawer, rgn)) - { - delete rgn; - return false; - } - - put_region (rgn); - } - break; - - case KW_EOF: - return true; - - default: - if (!thawer.parse_error (kw, "resource file")) - return false; - } - } -} - -bool loader_base::load (const char *filename) -{ - this->filename = filename; - - object_thawer fp (filename); - - if (!fp) - return false; - - return parse (fp); -} - -///////////////////////////////////////////////////////////////////////////// - /* Maps the MOVE_* values to names */ static const char *const move_name[] = { "walk", "fly_low", "fly_high", "swim", "boat", NULL }; @@ -423,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 @@ -435,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; @@ -448,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 @@ -456,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) { @@ -483,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. @@ -500,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 */ @@ -571,9 +404,7 @@ op->stats.maxhp = 0; } else - { - op->move_type = MOVE_WALK; - } + op->move_type = MOVE_WALK; } } @@ -657,9 +488,7 @@ for (;;) { - keyword kw = thawer.get_kv (); - - switch (kw) + switch (thawer.get_kv ()) { case KW_Object: // uppercase alias case KW_object: @@ -1190,12 +1019,12 @@ 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: - if (!thawer.parse_error (kw, "object", op->name)) + if (!thawer.parse_error ("object", op->name)) return false; break; } @@ -1627,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 (); + } +} +