Exemple #1
0
/* function prototype */
int cups; /*global variable */
int main()
{
  printf("This program will convert cups of liquid to gallons, quarts,");
  printf("\npints, and leftover cups remaining in descending order.");
  printf("\n\nType in how many cups of liquid you wish to convert:\n");
  scanf("%d", &cups);
  liquid(cups); /* call function */
  //	printf("Gallons: %d\nQuarts: %d\nPints: %d\nCups %d\n", gallons, quarts, pints, cups);
}
/**
 * Called when the activity timer for installing parts, repairing, etc times
 * out and the the action is complete.
 */
void complete_vehicle (game *g)
{
    if (g->u.activity.values.size() < 8) {
        debugmsg ("Invalid activity ACT_VEHICLE values:%d", g->u.activity.values.size());
        return;
    }
    vehicle *veh = g->m.veh_at (g->u.activity.values[0], g->u.activity.values[1]);
    if (!veh) {
        debugmsg ("Activity ACT_VEHICLE: vehicle not found");
        return;
    }
    char cmd = (char) g->u.activity.index;
    int dx = g->u.activity.values[4];
    int dy = g->u.activity.values[5];
    int vehicle_part = g->u.activity.values[6];
    int type = g->u.activity.values[7];
    std::string part_id = g->u.activity.str_values[0];
    std::vector<component> tools;
    int welder_charges = static_cast<it_tool *>(itypes["welder"])->charges_per_use;
    int welder_crude_charges = static_cast<it_tool *>(itypes["welder_crude"])->charges_per_use;
    int partnum;
    item used_item;
    bool broken;
    int replaced_wheel;
    std::vector<int> parts;
    int dd = 2;
    switch (cmd) {
    case 'i':
        partnum = veh->install_part (dx, dy, part_id);
        if(partnum < 0) {
            debugmsg ("complete_vehicle install part fails dx=%d dy=%d id=%d", dx, dy, part_id.c_str());
        }
        used_item = consume_vpart_item (g, part_id);
        veh->get_part_properties_from_item(g, partnum, used_item); //transfer damage, etc.
        tools.push_back(component("welder", welder_charges));
        tools.push_back(component("welder_crude", welder_crude_charges));
        tools.push_back(component("duct_tape", DUCT_TAPE_USED));
        tools.push_back(component("toolset", welder_charges / 20));
        g->consume_tools(&g->u, tools, true);

        if ( vehicle_part_types[part_id].has_flag("CONE_LIGHT") ) {
            // Need map-relative coordinates to compare to output of look_around.
            int gx, gy;
            // Need to call coord_translate() directly since it's a new part.
            veh->coord_translate(dx, dy, gx, gy);
            // Stash offset and set it to the location of the part so look_around will start there.
            int px = g->u.view_offset_x;
            int py = g->u.view_offset_y;
            g->u.view_offset_x = veh->global_x() + gx - g->u.posx;
            g->u.view_offset_y = veh->global_y() + gy - g->u.posy;
            popup(_("Choose a facing direction for the new headlight."));
            point headlight_target = g->look_around();
            // Restore previous view offsets.
            g->u.view_offset_x = px;
            g->u.view_offset_y = py;

            int delta_x = headlight_target.x - (veh->global_x() + gx);
            int delta_y = headlight_target.y - (veh->global_y() + gy);

            const double PI = 3.14159265358979f;
            int dir = int(atan2(static_cast<float>(delta_y), static_cast<float>(delta_x)) * 180.0 / PI);
            dir -= veh->face.dir();
            while(dir < 0) {
                dir += 360;
            }
            while(dir > 360) {
                dir -= 360;
            }

            veh->parts[partnum].direction = dir;
        }

        g->add_msg (_("You install a %s into the %s."),
                    vehicle_part_types[part_id].name.c_str(), veh->name.c_str());
        g->u.practice (g->turn, "mechanics", vehicle_part_types[part_id].difficulty * 5 + 20);
        break;
    case 'r':
        if (veh->parts[vehicle_part].hp <= 0) {
            veh->break_part_into_pieces(vehicle_part, g->u.posx, g->u.posy);
            used_item = consume_vpart_item (g, veh->parts[vehicle_part].id);
            veh->parts[vehicle_part].bigness = used_item.bigness;
            tools.push_back(component("wrench", -1));
            g->consume_tools(&g->u, tools, true);
            tools.clear();
            dd = 0;
            veh->insides_dirty = true;
        }
        tools.push_back(component("welder", welder_charges));
        tools.push_back(component("welder_crude", welder_crude_charges));
        tools.push_back(component("duct_tape", DUCT_TAPE_USED));
        tools.push_back(component("toolset", welder_charges / 20));
        g->consume_tools(&g->u, tools, true);
        veh->parts[vehicle_part].hp = veh->part_info(vehicle_part).durability;
        g->add_msg (_("You repair the %s's %s."),
                    veh->name.c_str(), veh->part_info(vehicle_part).name.c_str());
        g->u.practice (g->turn, "mechanics", (veh->part_info(vehicle_part).difficulty + dd) * 5 + 20);
        break;
    case 'f':
        if (!g->pl_refill_vehicle(*veh, vehicle_part, true)) {
            debugmsg ("complete_vehicle refill broken");
        }
        g->pl_refill_vehicle(*veh, vehicle_part);
        break;
    case 'o':
        // Dump contents of part at player's feet, if any.
        for (int i = 0; i < veh->parts[vehicle_part].items.size(); i++) {
            g->m.add_item_or_charges (g->u.posx, g->u.posy, veh->parts[vehicle_part].items[i]);
        }
        veh->parts[vehicle_part].items.clear();

        broken = veh->parts[vehicle_part].hp <= 0;
        if (!broken) {
            used_item = veh->item_from_part( vehicle_part );
            // Transfer fuel back to tank
            if (used_item.typeId() == "metal_tank") {
                ammotype desired_liquid = veh->part_info(vehicle_part).fuel_type;
                item liquid( itypes[default_ammo(desired_liquid)], g->turn );

                liquid.charges = veh->parts[vehicle_part].amount;
                veh->parts[vehicle_part].amount = 0;

                used_item.put_in(liquid);
            }
            g->m.add_item_or_charges(g->u.posx, g->u.posy, used_item);
            if(type != SEL_JACK) { // Changing tires won't make you a car mechanic
                g->u.practice (g->turn, "mechanics", 2 * 5 + 20);
            }
        } else {
            veh->break_part_into_pieces(vehicle_part, g->u.posx, g->u.posy);
        }
        if (veh->parts.size() < 2) {
            g->add_msg (_("You completely dismantle the %s."), veh->name.c_str());
            g->u.activity.type = ACT_NULL;
            g->m.destroy_vehicle (veh);
        } else {
            if (broken) {
                g->add_msg(_("You remove the broken %s from the %s."),
                           veh->part_info(vehicle_part).name.c_str(),
                           veh->name.c_str());
            } else {
                g->add_msg(_("You remove the %s from the %s."),
                           veh->part_info(vehicle_part).name.c_str(),
                           veh->name.c_str());
            }
            veh->remove_part (vehicle_part);
        }
        break;
    case 's':
        g->u.siphon( g, veh, "gasoline" );
        break;
    case 'c':
        parts = veh->parts_at_relative( dx, dy );
        if( parts.size() ) {
            item removed_wheel;
            replaced_wheel = veh->part_with_feature( parts[0], "WHEEL", false );
            if( replaced_wheel == -1 ) {
                debugmsg( "no wheel to remove when changing wheels." );
                return;
            }
            broken = veh->parts[replaced_wheel].hp <= 0;
            removed_wheel = veh->item_from_part( replaced_wheel );
            veh->remove_part( replaced_wheel );
            g->add_msg( _("You replace one of the %s's tires with a %s."),
                        veh->name.c_str(), vehicle_part_types[part_id].name.c_str() );
            partnum = veh->install_part( dx, dy, part_id );
            if( partnum < 0 ) {
                debugmsg ("complete_vehicle tire change fails dx=%d dy=%d id=%d", dx, dy, part_id.c_str());
            }
            used_item = consume_vpart_item( g, part_id );
            veh->get_part_properties_from_item( g, partnum, used_item ); //transfer damage, etc.
            // Place the removed wheel on the map last so consume_vpart_item() doesn't pick it.
            if ( !broken ) {
                g->m.add_item_or_charges( g->u.posx, g->u.posy, removed_wheel );
            }
        }
        break;
    case 'd':
        g->u.siphon( g, veh, "water" );
        break;
    }
}
Exemple #3
0
void bullet_detonate(struct moag *m, int id)
{
    struct bullet *b = &m->bullets[id];
    float d = VEC2_MAG(b->obj.vel);

    if (d < 0.001 && d >- 0.001)
        d = d < 0 ? -1 : 1;

    const float dx = b->obj.vel.x / d;
    const float dy = b->obj.vel.y / d;

    float hitx = b->obj.pos.x;
    float hity = b->obj.pos.y;

    for (int i = 40; i > 0 && get_land_at(m, (int)hitx, (int)hity); i--)
    {
        hitx -= dx;
        hity -= dy;
    }

    switch (b->type)
    {
        case MISSILE:
            explode(m, b->x, b->y, 12, E_EXPLODE);
            break;

        case SHOTGUN:
            explode(m, b->x, b->y, 6, E_EXPLODE);
            break;

        case BABY_NUKE:
            explode(m, b->x, b->y, 55, E_EXPLODE);
            break;

        case NUKE:
            explode(m, b->x, b->y, 150, E_EXPLODE);
            break;

        case DIRT:
            explode(m, b->x, b->y, 55, E_DIRT);
            break;

        case SUPER_DIRT:
            explode(m, b->x, b->y, 300, E_DIRT);
            break;

        case COLLAPSE:
            explode(m, b->x, b->y, 120, E_COLLAPSE);
            break;

        case LIQUID_DIRT:
            for (int i = 0; i < 4; i++)
                set_timer(m, m->frame + 65*i, LIQUID_DIRT_WARHEAD,
                        b->x, b->y, 0, 0);
            break;

        case LIQUID_DIRT_WARHEAD:
            liquid(m, (int)hitx, (int)hity, 2000);
            break;

        case BOUNCER:
            if (b->active > 0)
                b->active = -BOUNCER_BOUNCES;
            b->active++;
            bounce_bullet(m, id, hitx, hity);
            b->obj.vel = VEC2_MUL_CONST(b->obj.vel, 0.9);
            explode(m, b->x, b->y, 12, E_EXPLODE);
            break;

        case TUNNELER:
            if (b->active > 0)
                b->active = -TUNNELER_TUNNELINGS;
            b->active++;
            explode(m, hitx, hity, 9, E_EXPLODE);
            explode(m, hitx + 8 * dx, hity + 8 * dy, 9, E_EXPLODE);
            break;

        case LADDER: {
            int x = b->x;
            int y = b->y;
            for (; y < LAND_HEIGHT; y++)
                if (get_land_at(m, x, y) == 0)
                    break;
            for (; y < LAND_HEIGHT; y++)
                if (get_land_at(m, x, y))
                    break;
            const int maxy = y + 1;
            y = b->y;
            for (; y > 0; y--)
                if (get_land_at(m, x, y) == 0)
                    break;
            const int miny = y;
            for(; y < maxy; y += 2)
            {
                set_land_at(m, x - 1, y,     0);
                set_land_at(m, x    , y,     1);
                set_land_at(m, x + 1, y,     0);
                set_land_at(m, x - 1, y + 1, 1);
                set_land_at(m, x    , y + 1, 1);
                set_land_at(m, x + 1, y + 1, 1);
            }
            broadcast_packed_land_chunk(m, x - 1, miny, 3, maxy - miny + 1);
            break;
        }

        case MIRV:
            bounce_bullet(m, id, hitx, hity);
            explode(m, b->x, b->y, 12, E_EXPLODE);
            for (int i = -3; i < 4; i++)
                fire_bullet(m, MIRV_WARHEAD,
                            b->x, b->y,
                            b->obj.vel.x + i, b->obj.vel.y);
            break;

        case MIRV_WARHEAD:
            explode(m, b->x, b->y, 30, E_EXPLODE);
            break;

        case CLUSTER_BOMB:
            bounce_bullet(m, id, hitx, hity);
            explode(m, b->x, b->y, 20, E_EXPLODE);
            for (int i = 0; i < 11; i++)
                fire_bullet(m, MISSILE, hitx, hity,
                            2.0 * cosf(i * M_PI / 5.5) + 0.50 * b->obj.vel.x,
                            2.0 * sinf(i * M_PI / 5.5) + 0.50 * b->obj.vel.y);
            break;

        case CLUSTER_BOUNCER:
            bounce_bullet(m, id, hitx, hity);
            explode(m, b->x, b->y, 20, E_EXPLODE);
            for (int i = 0; i < 11; i++)
                fire_bullet(m, BOUNCER, hitx, hity,
                            2.0 * cosf(i * M_PI / 5.5) + 0.50 * b->obj.vel.x,
                            2.0 * sinf(i * M_PI / 5.5) + 0.50 * b->obj.vel.y);
            break;

        default: break;
    }

    if (b->active >= 0)
    {
        b->active = 0;
        broadcast_bullet_chunk(m, KILL, id);
    }
}