--- deliantra/server/common/loader.C 2007/02/16 19:43:40 1.59 +++ deliantra/server/common/loader.C 2007/03/11 02:12:44 1.64 @@ -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 @@ -411,8 +408,21 @@ } static void -set_move (MoveType & mt, const char *str) +set_move (MoveType &mt, const char *str) { + static const struct flagstr { + 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 }, + { "all" , MOVE_ALL }, + }; + if (!str) { mt = 0; @@ -429,48 +439,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++; - } + bool negate = 0; - for (i = 0; move_name[i]; i++) - { - if (!strcasecmp (move_name[i], str)) - { - if (negate) - mt &= ~(1 << i); - else - mt |= (1 << i); - - 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: ; } } @@ -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; @@ -973,15 +965,23 @@ } 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? object *op = object::create (); + op->map = map; op->arch = arch; arch->clone.copy_to (op); // copy_to activates, this should be fixed properly @@ -1007,6 +1007,7 @@ { object_thawer f (buf, (AV *)0); + f.kw = KW_arch; // special hack so that parse_kv skips return op->parse_kv (f); }