--- deliantra/server/common/loader.C 2007/02/16 19:43:40 1.59 +++ deliantra/server/common/loader.C 2007/04/28 18:18:04 1.74 @@ -32,9 +32,6 @@ ///////////////////////////////////////////////////////////////////////////// -/* Maps the MOVE_* values to names */ -static const char *const move_name[] = { "walk", "fly_low", "fly_high", "swim", "boat", NULL }; - /* This table is only necessary to convert objects that existed before the * spell object conversion to the new object. It was not practical * to go through every mapping looking for every potion, rod, wand, etc @@ -255,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 @@ -294,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 ()); @@ -345,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. @@ -356,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); @@ -411,8 +408,22 @@ } static void -set_move (MoveType & mt, const char *str) +set_move (MoveType &mt, const char *str) { + static const struct flagstr { + const char *name; + MoveType flags; + } move_flags[] = { + { "walk" , MOVE_WALK }, + { "flying" , MOVE_FLY_LOW | MOVE_FLY_HIGH }, + { "fly_low" , MOVE_FLY_LOW }, + { "fly_high", MOVE_FLY_HIGH }, + { "swim" , MOVE_SWIM }, + { "boat" , MOVE_BOAT }, + { "ship" , MOVE_SHIP }, + { "all" , MOVE_ALL }, + }; + if (!str) { mt = 0; @@ -429,48 +440,30 @@ for (str = strtok ((char *) str, " "); str; str = strtok (0, " ")) { - if (!strcasecmp (str, "all")) - mt |= MOVE_ALL; - else - { - int i, negate = 0; - - if (*str == '-') - { - negate = 1; - str++; - } - - for (i = 0; move_name[i]; i++) - { - if (!strcasecmp (move_name[i], str)) - { - if (negate) - mt &= ~(1 << i); - else - mt |= (1 << i); + bool negate = 0; - break; - } - } + if (*str == '-') + { + negate = 1; + str++; + } - if (!move_name[i]) + for (const flagstr *f = move_flags; f < move_flags + sizeof (move_flags) / sizeof (move_flags [0]); ++f) + { + if (!strcmp (f->name, str)) { - /* fly is a special case - covers both fly_low and - * fly_high - since it doesn't match to a specific - * single bit, have to special case it. - */ - if (!strcasecmp (str, "flying")) - { - if (negate) - mt &= ~MOVE_FLYING; - else - mt |= MOVE_FLYING; - } + if (negate) + mt &= ~f->flags; else - LOG (llevDebug, "common/loader.l: set_move - unknown move string '%s'\n", str); + mt |= f->flags; + + goto next; } } + + LOG (llevDebug, "common/loader.C: set_move - unknown move string '%s'\n", str); + +next: ; } } @@ -483,13 +476,6 @@ bool object::parse_kv (object_thawer &f) { - assert (f.kw == KW_object || f.kw == KW_arch); - - if (f.kw == KW_object) - f.get (name); // preset name from object name - - f.next (); - object *op_inv = inv; for (;;) @@ -561,7 +547,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: @@ -597,7 +589,7 @@ break; case KW_face: - face = &new_faces[FindFace (f.get_str (), 0)]; + face = face_find (f.get_str ()); break; case KW_x: f.get (x); break; @@ -843,6 +835,8 @@ case KW_berserk: GET_FLAG (this, FLAG_BERSERK); break; case KW_is_buildable: GET_FLAG (this, FLAG_IS_BUILDABLE); break; case KW_destroy_on_death: GET_FLAG (this, FLAG_DESTROY_ON_DEATH); break; + case KW_treasure_env: GET_FLAG (this, FLAG_TREASURE_ENV); break; + case KW_precious: GET_FLAG (this, FLAG_PRECIOUS); break; case KW_armour: f.get (resist[ATNR_PHYSICAL]); break; case KW_resist_physical: f.get (resist[ATNR_PHYSICAL]); break; @@ -888,7 +882,7 @@ case KW_tooltype: f.get (tooltype); break; case KW_casting_time: f.get (casting_time); break; case KW_elevation: f.get (elevation); break; - case KW_smoothlevel: f.get (smoothlevel); break; + case KW_smoothlevel: f.get (smoothlevel); smoothlevel = clamp (smoothlevel, 0, 255); break; case KW_client_type: f.get (client_type); break; case KW_duration: f.get (duration); break; case KW_range: f.get (range); break; @@ -918,9 +912,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: @@ -951,7 +952,7 @@ case KW_end: check_loaded_object (this); - if (!arch_init) + if (!loading_arch) instantiate (); f.next (); @@ -973,23 +974,32 @@ } object * -object::read (object_thawer &f) +object::read (object_thawer &f, maptile *map) { assert (f.kw == KW_arch); archetype *arch = archetype::find (f.get_str ()); + + if (!arch) + { + LOG (llevError, "object refering to nonexistant archetype '%s'.\n", f.get_str ()); + arch = archetype::find ("earthwall"); + } + assert (arch); //D maybe use exception handling of sorts? + f.next (); + object *op = object::create (); - op->arch = arch; + op->map = map; 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; } @@ -1007,6 +1017,7 @@ { object_thawer f (buf, (AV *)0); + f.next (); return op->parse_kv (f); } @@ -1097,7 +1108,7 @@ KW_generator, KW_is_thrown, KW_auto_apply, - KW_NULL, // was KW_treasure + KW_treasure_env, KW_player_sold, /* 20 */ KW_see_invisible, @@ -1168,7 +1179,7 @@ /* 80 */ KW_has_ready_scroll, KW_can_use_rod, - KW_NULL, + KW_precious, KW_can_use_horn, KW_make_invisible, KW_inv_locked, @@ -1244,7 +1255,8 @@ f.put (KW_lore, KW_endlore, op->lore); CMP_OUT (other_arch); - CMP_OUT (face); + + if (op->face != tmp->face) f.put (KW_face, op->face ? &faces [op->face] : 0); if (op->animation_id != tmp->animation_id) if (op->animation_id) @@ -1387,10 +1399,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 (;;) @@ -1399,18 +1416,38 @@ { 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 (); + f.next (); + break; + } } + +finish: + if (seen_arch) + init_archetype_pointers (); + + return success; }