--- deliantra/server/common/loader.C 2007/03/05 15:36:29 1.63 +++ deliantra/server/common/loader.C 2007/05/07 04:21:09 1.77 @@ -1,5 +1,5 @@ /* - * CrossFire, A Multiplayer game for X-windows + * CrossFire, A Multiplayer game * * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team * Copyright (C) 2002 Mark Wedel & Crossfire Development Team @@ -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,13 +291,13 @@ * 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 ()); - 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); + 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); } /* We changed last_heal to gen_sp_armour, which is what it @@ -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); @@ -411,7 +411,7 @@ set_move (MoveType &mt, const char *str) { static const struct flagstr { - char *name; + const char *name; MoveType flags; } move_flags[] = { { "walk" , MOVE_WALK }, @@ -420,6 +420,7 @@ { "fly_high", MOVE_FLY_HIGH }, { "swim" , MOVE_SWIM }, { "boat" , MOVE_BOAT }, + { "ship" , MOVE_SHIP }, { "all" , MOVE_ALL }, }; @@ -475,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 (;;) @@ -553,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: @@ -589,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; @@ -835,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; @@ -880,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; @@ -890,18 +892,18 @@ //TODO: mechanism to ensure that KW_xxx is consecutive needed from include/preprocess //TODO: parse from other include files - case KW_body_range: f.get (body_info[0]); break; - case KW_body_arm: f.get (body_info[1]); break; - case KW_body_torso: f.get (body_info[2]); break; - case KW_body_head: f.get (body_info[3]); break; - case KW_body_neck: f.get (body_info[4]); break; - case KW_body_skill: f.get (body_info[5]); break; - case KW_body_finger: f.get (body_info[6]); break; - case KW_body_shoulder: f.get (body_info[7]); break; - case KW_body_foot: f.get (body_info[8]); break; - case KW_body_hand: f.get (body_info[9]); break; - case KW_body_wrist: f.get (body_info[10]); break; - case KW_body_waist: f.get (body_info[11]); break; + 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_can_apply: break; @@ -910,9 +912,18 @@ 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 ()); + } + else + randomitems = 0; break; case KW_msg: @@ -943,7 +954,7 @@ case KW_end: check_loaded_object (this); - if (!arch_init) + if (!loading_arch) instantiate (); f.next (); @@ -979,17 +990,18 @@ assert (arch); //D maybe use exception handling of sorts? + f.next (); + 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; } @@ -1007,7 +1019,7 @@ { object_thawer f (buf, (AV *)0); - f.kw = KW_arch; // special hack so that parse_kv skips + f.next (); return op->parse_kv (f); } @@ -1098,7 +1110,7 @@ KW_generator, KW_is_thrown, KW_auto_apply, - KW_NULL, // was KW_treasure + KW_treasure_env, KW_player_sold, /* 20 */ KW_see_invisible, @@ -1169,7 +1181,7 @@ /* 80 */ KW_has_ready_scroll, KW_can_use_rod, - KW_NULL, + KW_precious, KW_can_use_horn, KW_make_invisible, KW_inv_locked, @@ -1245,7 +1257,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) @@ -1352,10 +1365,10 @@ if (flag_names [i] && op->flag [i] != tmp->flag [i]) f.put (flag_names [i], op->flag [i] ? "1" : "0"); - /* Save body locations */ + // save body locations for (i = 0; i < NUM_BODY_LOCATIONS; i++) - if (op->body_info[i] != tmp->body_info[i]) - f.put (body_locations[i].save_name, op->body_info[i]); + if (op->slot[i].info != tmp->slot[i].info) + f.put (body_locations[i].save_name, op->slot[i].info); } /* @@ -1388,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 (;;) @@ -1400,18 +1418,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; }