Ejemplo n.º 1
0
static void stringify (val_t * v, int within_op)
{
    static char *dirs[8] =
        { "south", "south-west", "west", "north-west", "north", "north-east",
        "east", "south-east"
    };
    char *buf;

    switch (v->ty)
    {
        case TY_UNDEF:
            buf = strdup ("UNDEF");
            break;

        case TY_INT:
            buf = malloc (32);
            sprintf (buf, "%i", v->v.v_int);
            break;

        case TY_STRING:
            return;

        case TY_DIR:
            buf = strdup (dirs[v->v.v_int]);
            break;

        case TY_ENTITY:
            buf = strdup (show_entity (v->v.v_entity));
            break;

        case TY_LOCATION:
            buf = malloc (128);
            sprintf (buf, "<\"%s\", %d, %d>", map[v->v.v_location.m].name,
                     v->v.v_location.x, v->v.v_location.y);
            break;

        case TY_AREA:
            buf = strdup ("%area");
            free_area (v->v.v_area);
            break;

        case TY_SPELL:
            buf = strdup (v->v.v_spell->name);
            break;

        case TY_INVOCATION:
        {
            invocation_t *invocation = within_op
                ? v->v.v_invocation : (invocation_t *) map_id2bl (v->v.v_int);
            buf = strdup (invocation->spell->name);
        }
            break;

        default:
            fprintf (stderr, "[magic] INTERNAL ERROR: Cannot stringify %d\n",
                     v->ty);
            return;
    }

    v->v.v_string = buf;
    v->ty = TY_STRING;
}
Ejemplo n.º 2
0
static
void stringify(val_t *v, int within_op)
{
    static earray<ZString, DIR, DIR::COUNT> dirs //=
    {{
        {"south"}, {"south-west"},
        {"west"}, {"north-west"},
        {"north"}, {"north-east"},
        {"east"}, {"south-east"},
    }};
    FString buf;

    switch (v->ty)
    {
        case TYPE::UNDEF:
            buf = "UNDEF";
            break;

        case TYPE::INT:
            buf = STRPRINTF("%i", v->v.v_int);
            break;

        case TYPE::STRING:
            return;

        case TYPE::DIR:
            buf = dirs[v->v.v_dir];
            break;

        case TYPE::ENTITY:
            buf = show_entity(v->v.v_entity);
            break;

        case TYPE::LOCATION:
            buf = STRPRINTF("<\"%s\", %d, %d>",
                    v->v.v_location.m->name_,
                    v->v.v_location.x,
                    v->v.v_location.y);
            break;

        case TYPE::AREA:
            buf = "%area";
            free_area(v->v.v_area);
            break;

        case TYPE::SPELL:
            buf = v->v.v_spell->name;
            break;

        case TYPE::INVOCATION:
        {
            dumb_ptr<invocation> invocation_ = within_op
                ? v->v.v_invocation
                : map_id2bl(v->v.v_int)->as_spell();
            buf = invocation_->spell->name;
        }
            break;

        default:
            FPRINTF(stderr, "[magic] INTERNAL ERROR: Cannot stringify %d\n",
                    v->ty);
            return;
    }

    v->v.v_string = dumb_string::copys(buf);
    v->ty = TYPE::STRING;
}