ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/loader.C
(Generate patch)

Comparing deliantra/server/common/loader.C (file contents):
Revision 1.62 by root, Mon Feb 19 19:10:31 2007 UTC vs.
Revision 1.63 by root, Mon Mar 5 15:36:29 2007 UTC

29#include <global.h> 29#include <global.h>
30#include <loader.h> 30#include <loader.h>
31#include <sproto.h> 31#include <sproto.h>
32 32
33///////////////////////////////////////////////////////////////////////////// 33/////////////////////////////////////////////////////////////////////////////
34
35/* Maps the MOVE_* values to names */
36static const char *const move_name[] = { "walk", "fly_low", "fly_high", "swim", "boat", NULL };
37 34
38/* This table is only necessary to convert objects that existed before the 35/* This table is only necessary to convert objects that existed before the
39 * spell object conversion to the new object. It was not practical 36 * spell object conversion to the new object. It was not practical
40 * to go through every mapping looking for every potion, rod, wand, etc 37 * to go through every mapping looking for every potion, rod, wand, etc
41 * that had a sp set and update to the new value. So this maps the 38 * that had a sp set and update to the new value. So this maps the
409 } 406 }
410 407
411} 408}
412 409
413static void 410static void
414set_move (MoveType & mt, const char *str) 411set_move (MoveType &mt, const char *str)
415{ 412{
413 static const struct flagstr {
414 char *name;
415 MoveType flags;
416 } move_flags[] = {
417 { "walk" , MOVE_WALK },
418 { "flying" , MOVE_FLY_LOW | MOVE_FLY_HIGH },
419 { "fly_low" , MOVE_FLY_LOW },
420 { "fly_high", MOVE_FLY_HIGH },
421 { "swim" , MOVE_SWIM },
422 { "boat" , MOVE_BOAT },
423 { "all" , MOVE_ALL },
424 };
425
416 if (!str) 426 if (!str)
417 { 427 {
418 mt = 0; 428 mt = 0;
419 return; 429 return;
420 } 430 }
427 437
428 mt = 0; 438 mt = 0;
429 439
430 for (str = strtok ((char *) str, " "); str; str = strtok (0, " ")) 440 for (str = strtok ((char *) str, " "); str; str = strtok (0, " "))
431 { 441 {
432 if (!strcasecmp (str, "all")) 442 bool negate = 0;
433 mt |= MOVE_ALL; 443
434 else 444 if (*str == '-')
435 { 445 {
436 int i, negate = 0; 446 negate = 1;
447 str++;
448 }
437 449
438 if (*str == '-') 450 for (const flagstr *f = move_flags; f < move_flags + sizeof (move_flags) / sizeof (move_flags [0]); ++f)
451 {
452 if (!strcmp (f->name, str))
439 { 453 {
440 negate = 1;
441 str++;
442 }
443
444 for (i = 0; move_name[i]; i++)
445 {
446 if (!strcasecmp (move_name[i], str))
447 {
448 if (negate) 454 if (negate)
449 mt &= ~(1 << i); 455 mt &= ~f->flags;
450 else
451 mt |= (1 << i);
452
453 break;
454 }
455 }
456
457 if (!move_name[i])
458 {
459 /* fly is a special case - covers both fly_low and
460 * fly_high - since it doesn't match to a specific
461 * single bit, have to special case it.
462 */
463 if (!strcasecmp (str, "flying"))
464 {
465 if (negate)
466 mt &= ~MOVE_FLYING;
467 else
468 mt |= MOVE_FLYING;
469 }
470 else 456 else
471 LOG (llevDebug, "common/loader.l: set_move - unknown move string '%s'\n", str); 457 mt |= f->flags;
458
459 goto next;
472 } 460 }
473 } 461 }
462
463 LOG (llevDebug, "common/loader.C: set_move - unknown move string '%s'\n", str);
464
465next: ;
474 } 466 }
475} 467}
476 468
477#define GET_FLAG(op,flag) \ 469#define GET_FLAG(op,flag) \
478 if (f.get_sint32 ()) \ 470 if (f.get_sint32 ()) \

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines