예제 #1
0
void complete_vehicle (game *g)
{
    if (g->u.activity.values.size() < 7)
    {
        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 part = g->u.activity.values[6];
    std::vector<component> tools;
    int welder_charges = ((it_tool *) g->itypes["welder"])->charges_per_use;
    itype_id itm;
    int partnum;
    item used_item;
    bool broken;
    int bigness;

    int dd = 2;
    switch (cmd)
    {
    case 'i':
        partnum = veh->install_part (dx, dy, (vpart_id) part);
        if(partnum < 0)
            debugmsg ("complete_vehicle install part fails dx=%d dy=%d id=%d", dx, dy, part);
        used_item = consume_vpart_item (g, (vpart_id) part);
        veh->get_part_properties_from_item(g, partnum, used_item); //transfer damage, etc.
        tools.push_back(component("welder", welder_charges));
        tools.push_back(component("toolset", welder_charges/5));
        g->consume_tools(tools);
        g->add_msg ("You install a %s into the %s.",
                   vpart_list[part].name, veh->name.c_str());
        g->u.practice ("mechanics", vpart_list[part].difficulty * 5 + 20);
        break;
    case 'r':
        if (veh->parts[part].hp <= 0)
        {
            used_item = consume_vpart_item (g, veh->parts[part].id);
            tools.push_back(component("wrench", 1));
            g->consume_tools(tools);
            tools.clear();
            dd = 0;
            veh->insides_dirty = true;
        }
        tools.push_back(component("welder", welder_charges));
        tools.push_back(component("toolset", welder_charges/5));
        g->consume_tools(tools);
        veh->parts[part].hp = veh->part_info(part).durability;
        g->add_msg ("You repair the %s's %s.",
                    veh->name.c_str(), veh->part_info(part).name);
        g->u.practice ("mechanics", (vpart_list[part].difficulty + dd) * 5 + 20);
        break;
    case 'f':
        if (!g->pl_refill_vehicle(*veh, part, true))
            debugmsg ("complete_vehicle refill broken");
        g->pl_refill_vehicle(*veh, part);
        break;
    case 'o':
        for (int i = 0; i < veh->parts[part].items.size(); i++)
            g->m.add_item (g->u.posx, g->u.posy, veh->parts[part].items[i]);
        veh->parts[part].items.clear();
        itm = veh->part_info(part).item;
        broken = veh->parts[part].hp <= 0;
        bigness = veh->parts[part].bigness;
        if (!broken){
            itype* parttype = g->itypes[itm];
            item tmp(parttype, g->turn);
            veh->give_part_properties_to_item(g, part, tmp); //transfer damage, etc.
            if(parttype->is_var_veh_part()){
               // has bigness.
               tmp.bigness = bigness;
            }
            g->m.add_item(g->u.posx, g->u.posy, tmp);
            //else {
            //   g->m.add_item (g->u.posx, g->u.posy, g->itypes[itm], g->turn);
            //}
            g->u.practice ("mechanics", 2 * 5 + 20);
        }
        if (veh->parts.size() < 2)
        {
            g->add_msg ("You completely dismantle %s.", veh->name.c_str());
            g->u.activity.type = ACT_NULL;
            g->m.destroy_vehicle (veh);
        }
        else
        {
            g->add_msg ("You remove %s%s from %s.", broken? "broken " : "",
                        veh->part_info(part).name, veh->name.c_str());
            veh->remove_part (part);
        }
        //break;
    default:;
    }
}
예제 #2
0
/**
 * 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 *>(g->itypes["welder"])->charges_per_use;
    int welder_crude_charges = static_cast<it_tool *>(g->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("toolset", welder_charges/20));
        g->consume_tools(&g->u, tools, true);

        if ( vehicle_part_types[part_id].has_flag("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 = (atan2(delta_y, 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)
        {
            used_item = consume_vpart_item (g, veh->parts[vehicle_part].id);
            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("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 );
            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);
            }
        }
        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 );
            broken = veh->parts[replaced_wheel].hp <= 0;
            if( replaced_wheel != -1 ) {
                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() );
            } else {
                debugmsg( "no wheel to remove when changing wheels." );
                return;
            }
            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;
    }
}
예제 #3
0
void complete_vehicle (game *g)
{
    if (g->u.activity.values.size() < 7)
    {
        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 part = g->u.activity.values[6];
    int type = g->u.activity.values[7];
    std::vector<component> tools;
    int welder_charges = ((it_tool *) g->itypes["welder"])->charges_per_use;
    itype_id itm;
    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, (vpart_id) part);
        if(partnum < 0)
            debugmsg ("complete_vehicle install part fails dx=%d dy=%d id=%d", dx, dy, part);
        used_item = consume_vpart_item (g, (vpart_id) part);
        veh->get_part_properties_from_item(g, partnum, used_item); //transfer damage, etc.
        tools.push_back(component("welder", welder_charges));
        tools.push_back(component("toolset", welder_charges/20));
        g->consume_tools(&g->u, tools, true);
        g->add_msg ("You install a %s into the %s.",
                    vpart_list[part].name, veh->name.c_str());
        g->u.practice (g->turn, "mechanics", vpart_list[part].difficulty * 5 + 20);
        break;
    case 'r':
        if (veh->parts[part].hp <= 0)
        {
            used_item = consume_vpart_item (g, veh->parts[part].id);
            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("toolset", welder_charges/20));
        g->consume_tools(&g->u, tools, true);
        veh->parts[part].hp = veh->part_info(part).durability;
        g->add_msg ("You repair the %s's %s.",
                    veh->name.c_str(), veh->part_info(part).name);
        g->u.practice (g->turn, "mechanics", (vpart_list[part].difficulty + dd) * 5 + 20);
        break;
    case 'f':
        if (!g->pl_refill_vehicle(*veh, part, true))
            debugmsg ("complete_vehicle refill broken");
        g->pl_refill_vehicle(*veh, part);
        break;
    case 'o':
        // Dump contents of part at player's feet, if any.
        for (int i = 0; i < veh->parts[part].items.size(); i++)
            g->m.add_item_or_charges (g->u.posx, g->u.posy, veh->parts[part].items[i], 1, false);
        veh->parts[part].items.clear();

        broken = veh->parts[part].hp <= 0;
        if (!broken) {
            used_item = veh->item_from_part( part );
            g->m.add_item(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);
        }
        if (veh->parts.size() < 2)
        {
            g->add_msg ("You completely dismantle %s.", veh->name.c_str());
            g->u.activity.type = ACT_NULL;
            g->m.destroy_vehicle (veh);
        }
        else
        {
            g->add_msg ("You remove %s%s from %s.", broken? "broken " : "",
                        veh->part_info(part).name, veh->name.c_str());
            veh->remove_part (part);
        }
        break;
    case 's':
        g->u.siphon_gas(g, veh);
        break;
    case 'c':
        parts = veh->parts_at_relative( dx, dy );
        if( parts.size() ) {
            item removed_wheel;
            replaced_wheel = veh->part_with_feature( parts[0], vpf_wheel, false );
            broken = veh->parts[replaced_wheel].hp <= 0;
            if( replaced_wheel != -1 ) {
                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 %s.",
                            veh->name.c_str(), vpart_list[part].name );
            } else {
                debugmsg( "no wheel to remove when changing wheels." );
                return;
            }
            partnum = veh->install_part( dx, dy, (vpart_id) part );
            if( partnum < 0 )
                debugmsg ("complete_vehicle tire change fails dx=%d dy=%d id=%d", dx, dy, part);
            used_item = consume_vpart_item( g, (vpart_id) part );
            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( g->u.posx, g->u.posy, removed_wheel );
            }
        }

        break;
    default:;
    }
}