--- deliantra/server/common/loader.C 2010/05/06 22:58:03 1.160 +++ deliantra/server/common/loader.C 2011/05/01 16:58:15 1.169 @@ -1,7 +1,7 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2002 Mark Wedel & Crossfire Development Team * Copyright (©) 1992 Frank Tore Johansen * @@ -267,6 +267,7 @@ switch (type) { + case RANGED: case BOW: case WAND: case ROD: @@ -415,7 +416,7 @@ * in that spell was stored in sp. */ //LOG (llevError, "old spellcasting object found: %s", debug_desc ()); - object *tmp = get_archetype (spell_mapping[type == FIREWALL ? stats.dam : stats.sp]); + object *tmp = archetype::get (spell_mapping[type == FIREWALL ? stats.dam : stats.sp]); insert_ob_in_ob (tmp, this); randomitems = 0; } @@ -551,7 +552,7 @@ object::parse_kv (object_thawer &f) { object *op_inv = inv; - key_value *last_kv = key_values; + key_value *last_kv = kv.first; for (;;) { @@ -919,6 +920,7 @@ case KW_treasure_env: GET_FLAG (this, FLAG_TREASURE_ENV); break; case KW_precious: GET_FLAG (this, FLAG_PRECIOUS); break; case KW_random_speed: GET_FLAG (this, FLAG_RANDOM_SPEED); break; + case KW_is_quad: GET_FLAG (this, FLAG_IS_QUAD); break; case KW_armour: f.get (resist[ATNR_PHYSICAL]); break; case KW_resist_physical: f.get (resist[ATNR_PHYSICAL]); break; @@ -1040,27 +1042,9 @@ return true; case KW_ERROR: - // append as key value pair (do not use kv_set as it prepends) - // we also do not even try to find old values, duplicate keys stay duplicate - { - key_value *kv = new key_value; - - kv->next = 0; - kv->key = shstr (f.kw_str); - kv->value = shstr (f.value); - - if (!last_kv) - key_values = last_kv = kv; - else - { - while (last_kv->next) - last_kv = last_kv->next; - - last_kv->next = kv; - last_kv = kv; - } - } - //fprintf (stderr, "addkv(%s,%s)\n", f.kw_str, f.value);//D + // we do not even try to find old values, duplicate keys stay duplicate + // the list gets reversed after loading + kv.add (shstr (f.kw_str), shstr (f.value)); break; default: @@ -1082,7 +1066,7 @@ if (!arch) { - LOG (llevError, "object refering to nonexistant archetype '%s'.\n", f.get_str ()); + LOG (llevError, "object referring to nonexistent archetype '%s'.\n", f.get_str ()); arch = archetype::find (shstr_earthwall); } @@ -1101,6 +1085,10 @@ return 0; } + // the loader reverses the ordering of kv-pairs, so we reverse it again after loading + // that greatly simplifies the loading code. + op->kv.reverse (); + op->post_load_check (); return op; } @@ -1114,7 +1102,7 @@ int set_variable (object *op, char *buf) { - object_thawer f (buf, (AV *)0); + object_thawer f (format ("%s\nend", buf), (AV *)0); return op->parse_kv (f); } @@ -1276,8 +1264,8 @@ /* This saves the key/value lists. We do it first so that any * keys that match field names will be overwritten by the loader. */ - for (key_value *kv = op->key_values; kv; kv = kv->next) - if (!arch->key_values || arch->kv (kv->key) != kv->value) + for (key_value *kv = op->kv.first; kv; kv = kv->next) + if (arch->kv.empty () || arch->kv [kv->key] != kv->value) f.put (kv->key, kv->value); if (op->uuid) @@ -1466,7 +1454,7 @@ // save body locations. gcc's memcmp does an abysmal job when used for (int i = 0; i < NUM_BODY_LOCATIONS; i++) if (expect_false (op->slot[i].info != arch->slot[i].info)) - f.put (body_locations[i].save_name, op->slot[i].info); + f.put (body_locations[i].kw, op->slot[i].info); } /*