--- deliantra/server/common/loader.C 2007/03/18 03:05:39 1.67 +++ deliantra/server/common/loader.C 2007/04/17 18:40:31 1.70 @@ -252,7 +252,7 @@ NULL }; -extern int arch_init; +extern bool loading_arch; /* This function checks the object after it has been loaded (when we * get the 'end' in the input stream). This function can be used to @@ -291,7 +291,7 @@ * really just to catch any errors - program will still run, but * not in the ideal fashion. */ - if ((op->type == WEAPON || op->type == BOW) && arch_init) + if ((op->type == WEAPON || op->type == BOW) && loading_arch) { if (!op->skill) LOG (llevError, "Weapon %s lacks a skill.\n", op->debug_desc ()); @@ -342,7 +342,7 @@ /* 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) + ((op->type == POTION || op->type == ALTAR) && op->stats.sp)) && !op->inv && !loading_arch) { /* Fireall is bizarre in that spell type was stored in dam. Rest are 'normal' * in that spell was stored in sp. @@ -353,7 +353,7 @@ } /* 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) + if ((op->type == SPELLBOOK || op->type == RUNE) && op->slaying && !op->inv && !loading_arch) { object *tmp = get_archetype_by_object_name (op->slaying); insert_ob_in_ob (tmp, op); @@ -553,7 +553,13 @@ continue; case KW_other_arch: - other_arch = archetype::find (f.get_str ()); + other_arch = + loading_arch + ? archetype::get (f.get_str ()) + : archetype::find (f.get_str ()); + + if (!other_arch) + LOG (llevError, "%s uses unknown other_arch '%s'.\n", debug_desc (), f.get_str ()); break; case KW_animation: @@ -910,9 +916,16 @@ break; case KW_randomitems: - randomitems = find_treasurelist (f.get_str ()); - //if (!randomitems) - // LOG (llevError, "%s uses unknown randomitems '%s'.\n", debug_desc (), f.get_str ()); + if (f.get_str ()) + { + randomitems = + loading_arch + ? treasurelist::get (f.get_str ()) + : treasurelist::find (f.get_str ()); + + if (!randomitems) + LOG (llevError, "%s uses unknown randomitems '%s'.\n", debug_desc (), f.get_str ()); + } break; case KW_msg: @@ -943,7 +956,7 @@ case KW_end: check_loaded_object (this); - if (!arch_init) + if (!loading_arch) instantiate (); f.next (); @@ -982,14 +995,13 @@ object *op = object::create (); op->map = map; - op->arch = arch; arch->clone.copy_to (op); // copy_to activates, this should be fixed properly op->deactivate (); if (!op->parse_kv (f)) { - delete op; + op->destroy (true); return 0; } @@ -1389,10 +1401,15 @@ ///////////////////////////////////////////////////////////////////////////// +// generic resource file load, +// currently supports: region, treasures, archetypes bool load_resource_file (const char *filename) { object_thawer f (filename); + bool success = false; + bool seen_arch = false; + f.next (); for (;;) @@ -1401,18 +1418,35 @@ { case KW_region: if (!region::read (f)) - return false; + goto finish; + break; + + case KW_treasure: + case KW_treasureone: + if (!treasurelist::read (f)) + goto finish; + break; + + case KW_object: + seen_arch = true; + if (!archetype::read (f)) + goto finish; break; case KW_EOF: - return true; + success = true; + goto finish; default: if (!f.parse_error ("resource file")) - return false; + goto finish; } - - f.next (); } + +finish: + if (seen_arch) + init_archetype_pointers (); + + return success; }