… | |
… | |
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 */ |
|
|
36 | static 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 | |
413 | static void |
410 | static void |
414 | set_move (MoveType & mt, const char *str) |
411 | set_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 | |
|
|
465 | next: ; |
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 ()) \ |
… | |
… | |
595 | move_slow |= MOVE_WALK; |
587 | move_slow |= MOVE_WALK; |
596 | f.get (move_slow_penalty); |
588 | f.get (move_slow_penalty); |
597 | break; |
589 | break; |
598 | |
590 | |
599 | case KW_face: |
591 | case KW_face: |
600 | face = &new_faces[FindFace (f.get_str (), 0)]; |
592 | face = face_find (f.get_str ()); |
601 | break; |
593 | break; |
602 | |
594 | |
603 | case KW_x: f.get (x); break; |
595 | case KW_x: f.get (x); break; |
604 | case KW_y: f.get (y); break; |
596 | case KW_y: f.get (y); break; |
605 | |
597 | |