--- deliantra/server/common/loader.C 2007/02/19 19:10:31 1.62 +++ deliantra/server/common/loader.C 2007/03/05 15:36:29 1.63 @@ -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++; - } - - 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: ; } }