Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vehicle installation requirements (part 3) [RDY] #17302

Merged
merged 12 commits into from
Jun 23, 2016
4 changes: 1 addition & 3 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1241,9 +1241,7 @@ void activity_handlers::vehicle_finish( player_activity *act, player *pl )
g->refresh_all();
// TODO: Z (and also where the activity is queued)
// Or not, because the vehicle coords are dropped anyway
g->exam_vehicle(*veh,
tripoint( act->values[0], act->values[1], pl->posz() ),
act->values[2], act->values[3]);
g->exam_vehicle( *veh, act->values[ 2 ], act->values[ 3 ] );
return;
} else {
dbg(D_ERROR) << "game:process_activity: ACT_VEHICLE: vehicle not found";
Expand Down
23 changes: 8 additions & 15 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7418,13 +7418,9 @@ void game::handbrake()
u.moves = 0;
}

void game::exam_vehicle(vehicle &veh, const tripoint &p, int cx, int cy)
void game::exam_vehicle( vehicle &veh, int cx, int cy )
{
(void)p; // not currently used
veh_interact vehint;
vehint.ddx = cx;
vehint.ddy = cy;
vehint.exec(&veh);
veh_interact vehint( veh, cx, cy );

if( vehint.sel_cmd == 'q' ) {
refresh_all();
Expand All @@ -7440,7 +7436,7 @@ void game::exam_vehicle(vehicle &veh, const tripoint &p, int cx, int cy)
int setuptime = std::max(setup * 3000, setup * 6000 - skill * 400);
int dmg = 1000;
if (vehint.sel_cmd == 'r') {
dmg = 1000 - vehint.sel_vehicle_part->hp * 1000 / vehint.sel_vpart_info->durability;
dmg = 1000 - vehint.part()->hp * 1000 / vehint.sel_vpart_info->durability;
}
int mintime = 300 + diff * dmg;
// sel_cmd = Install Repair reFill remOve Siphon Drainwater Changetire reName
Expand All @@ -7465,21 +7461,18 @@ void game::exam_vehicle(vehicle &veh, const tripoint &p, int cx, int cy)

// if we're working on an existing part, use that part as the reference point
// otherwise (e.g. installing a new frame), just use part 0
point q = veh.coord_translate(vehint.sel_vehicle_part ? vehint.sel_vehicle_part->mount : veh.parts[0].mount);
point q = veh.coord_translate( vehint.part() ? vehint.part()->mount : veh.parts[0].mount );
u.activity.values.push_back(veh.global_x() + q.x); // values[0]
u.activity.values.push_back(veh.global_y() + q.y); // values[1]
u.activity.values.push_back(vehint.ddx); // values[2]
u.activity.values.push_back(vehint.ddy); // values[3]
u.activity.values.push_back(-vehint.ddx); // values[4]
u.activity.values.push_back(-vehint.ddy); // values[5]
// values[6]
u.activity.values.push_back(veh.index_of_part(vehint.sel_vehicle_part));
u.activity.values.push_back(vehint.sel_type); // int. might make bitmask
if (vehint.sel_vpart_info != NULL) {
u.activity.str_values.push_back(vehint.sel_vpart_info->id.str());
} else {
u.activity.str_values.push_back(vpart_str_id::NULL_ID.str());
}
u.activity.values.push_back( veh.index_of_part( vehint.part() ) );

u.activity.str_values.push_back( vehint.sel_vpart_info->id.str() );

u.moves = 0;
}
refresh_all();
Expand Down
5 changes: 3 additions & 2 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,9 @@ class game
bool right_sidebar;
bool fullscreen;
bool was_fullscreen;
void exam_vehicle(vehicle &veh, const tripoint &p, int cx = 0,
int cy = 0); // open vehicle interaction screen

/** open vehicle interaction screen */
void exam_vehicle(vehicle &veh, int cx = 0, int cy = 0);

// put items from the item-vector on the map/a vehicle
// at (dirx, diry), items are dropped into a vehicle part
Expand Down
2 changes: 1 addition & 1 deletion src/pickup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Pickup::interact_results Pickup::interact_with_vehicle( vehicle *veh, const trip
return DONE;

case EXAMINE:
g->exam_vehicle( *veh, pos );
g->exam_vehicle( *veh );
return DONE;

case GET_ITEMS_ON_GROUND:
Expand Down
58 changes: 14 additions & 44 deletions src/veh_interact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#define ISNAN std::isnan
#endif

static const int DUCT_TAPE_USED = 100;

static inline const char * status_color( bool status )
{
static const char *good = "green";
Expand All @@ -57,25 +59,9 @@ void act_vehicle_siphon(vehicle* veh);
/**
* Creates a blank veh_interact window.
*/
veh_interact::veh_interact ()
: main_context("VEH_INTERACT")
veh_interact::veh_interact( vehicle &veh, int x, int y )
: ddx( x ), ddy( y ), veh( &veh ), main_context( "VEH_INTERACT" )
{
cpart = -1;
ddx = 0;
ddy = 0;
sel_cmd = ' ';
sel_type = 0;
sel_vpart_info = NULL;
sel_vehicle_part = NULL;

// Starting index of where to start printing fuels from
fuel_index = 0;

totalDurabilityColor = c_green;
worstDurabilityColor = c_green;
durabilityPercent = 100;
mostDamagedPart = -1;

// Only build the shapes map and the wheel list once
for( auto vp : vpart_info::get_all() ) {
vpart_shapes[ vp->name() + vp->item ].push_back( vp );
Expand All @@ -99,15 +85,7 @@ veh_interact::veh_interact ()
main_context.register_action("NEXT_TAB");
main_context.register_action("CONFIRM");
main_context.register_action("HELP_KEYBINDINGS");
}

/**
* Creates a veh_interact window based on the given parameters.
* @param v The vehicle the player is interacting with.
*/
void veh_interact::exec(vehicle *v)
{
veh = v;
countDurability();
cache_tool_availability();
allocate_windows();
Expand Down Expand Up @@ -259,16 +237,8 @@ void veh_interact::cache_tool_availability()
int charges = charges_per_use( "welder" );
int charges_oxy = charges_per_use( "oxy_torch" );
int charges_crude = charges_per_use( "welder_crude" );
has_screwdriver = crafting_inv.has_quality( SCREW );
has_wrench = crafting_inv.has_quality( WRENCH );
has_hammer = crafting_inv.has_quality( HAMMER );
has_nailgun = crafting_inv.has_tools("nailgun", 1);
has_goggles = (g->u.has_bionic("bio_sunglasses") || crafting_inv.has_quality( GLARE, 2 ));
has_hacksaw = crafting_inv.has_quality( SAW_M_FINE ) ||
(crafting_inv.has_tools("circsaw_off", 1) &&
crafting_inv.has_charges("circsaw_off", CIRC_SAW_USED)) ||
(crafting_inv.has_tools("oxy_torch", 1) &&
crafting_inv.has_charges("oxy_torch", OXY_CUTTING) && has_goggles);
has_welder = (crafting_inv.has_tools("welder", 1) &&
crafting_inv.has_charges("welder", charges)) ||
(crafting_inv.has_tools("oxy_torch", 1) &&
Expand All @@ -277,11 +247,7 @@ void veh_interact::cache_tool_availability()
crafting_inv.has_charges("welder_crude", charges_crude)) ||
(crafting_inv.has_tools("toolset", 1) &&
crafting_inv.has_charges("toolset", charges_crude));
has_duct_tape = (crafting_inv.has_charges("duct_tape", DUCT_TAPE_USED) ||
(crafting_inv.has_tools("toolbox", 1) &&
crafting_inv.has_charges("toolbox", DUCT_TAPE_USED)));
has_nails = crafting_inv.has_charges("nail", NAILS_USED);
has_siphon = crafting_inv.has_tools("hose", 1);
has_duct_tape = crafting_inv.has_charges( "duct_tape", DUCT_TAPE_USED );

has_wheel = crafting_inv.has_components( "wheel", 1 ) ||
crafting_inv.has_components( "wheel_wide", 1 ) ||
Expand Down Expand Up @@ -390,7 +356,7 @@ task_reason veh_interact::cant_do (char mode)
break;
}
}
has_tools = has_siphon;
has_tools = crafting_inv.has_tools( "hose", 1 );
break;
case 'c': // change tire
valid_target = wheel != NULL;
Expand Down Expand Up @@ -2069,7 +2035,7 @@ void act_vehicle_siphon(vehicle* veh) {
*/
void complete_vehicle ()
{
if (g->u.activity.values.size() < 8) {
if (g->u.activity.values.size() < 7) {
debugmsg ("Invalid activity ACT_VEHICLE values:%d", g->u.activity.values.size());
return;
}
Expand Down Expand Up @@ -2105,7 +2071,7 @@ void complete_vehicle ()

const auto& reqs = vpinfo.install_reqs;
if( !reqs.can_make_with_inventory( inv ) ) {
add_msg( m_info, _( "You lack the requirements to install the %s." ), vpinfo.name().c_str() );
add_msg( m_info, _( "You don't meet the requirements to install the %s." ), vpinfo.name().c_str() );
break;
}

Expand All @@ -2118,6 +2084,10 @@ void complete_vehicle ()
}
}
}
if( base.is_null() ) {
add_msg( m_info, _( "Could not find base part in requirements for %s." ), vpinfo.name().c_str() );
break;
}

for( const auto& e : reqs.get_tools() ) {
g->u.consume_tools( e );
Expand All @@ -2128,6 +2098,7 @@ void complete_vehicle ()
int partnum = !base.is_null() ? veh->install_part( dx, dy, part_id, std::move( base ) ) : -1;
if(partnum < 0) {
debugmsg ("complete_vehicle install part fails dx=%d dy=%d id=%d", dx, dy, part_id.c_str());
break;
}

if ( vpinfo.has_flag("CONE_LIGHT") ) {
Expand Down Expand Up @@ -2197,7 +2168,6 @@ void complete_vehicle ()
tools.emplace_back( "toolset", welder_crude_charges * dmg );
}
tools.emplace_back( "duct_tape", DUCT_TAPE_USED * dmg );
tools.emplace_back( "toolbox", DUCT_TAPE_USED * dmg );

g->u.consume_tools( tools, 1, repair_hotkeys );
add_msg( m_good, _( "You repair the %1$s's %2$s." ), veh->name.c_str(), name.c_str() );
Expand All @@ -2215,7 +2185,7 @@ void complete_vehicle ()

const auto& reqs = vpinfo.removal_reqs;
if( !reqs.can_make_with_inventory( inv ) ) {
add_msg( m_info, _( "You lack the requirements to remove the %s." ), vpinfo.name().c_str() );
add_msg( m_info, _( "You don't meet the requirements to remove the %s." ), vpinfo.name().c_str() );
break;
}

Expand Down
52 changes: 21 additions & 31 deletions src/veh_interact.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@
#include <vector>
#include <map>

#define DUCT_TAPE_USED 100
#define NAILS_USED 10
#define CIRC_SAW_USED 20
#define OXY_CUTTING 10

class vpart_info;
using vpart_id = int_id<vpart_info>;
using vpart_str_id = string_id<vpart_info>;

enum sel_types {
SEL_NULL, SEL_JACK
};

/** Represents possible return values from the cant_do function. */
enum task_reason {
UNKNOWN_TASK = -1, //No such task
Expand All @@ -39,20 +30,29 @@ enum task_reason {
};

class vehicle;
struct vehicle_part;

class veh_interact
{
public:
int ddx;
int ddy;
const vpart_info *sel_vpart_info;
const struct vehicle_part *sel_vehicle_part;
char sel_cmd; //Command currently being run by the player
int sel_type;
veh_interact( vehicle &veh, int x, int y );

int ddx = 0;
int ddy = 0;
const vpart_info *sel_vpart_info = nullptr;
char sel_cmd = ' '; //Command currently being run by the player

/** Get selected vehicle part (if any) */
const vehicle_part *part() const {
return sel_vehicle_part;
}

private:
int cpart;
const vehicle_part *sel_vehicle_part = nullptr;

int cpart = -1;
int page_size;
int fuel_index;
int fuel_index = 0; /** Starting index of where to start printing fuels from */
WINDOW *w_grid;
WINDOW *w_mode;
WINDOW *w_msg;
Expand All @@ -64,17 +64,11 @@ class veh_interact
WINDOW *w_name;

vehicle *veh;
bool has_screwdriver;
bool has_wrench;
bool has_hammer;
bool has_nailgun;
bool has_welder;
bool has_goggles;
bool has_duct_tape;
bool has_nails;
bool has_hacksaw;
bool has_jack;
bool has_siphon;
bool has_wheel;
inventory crafting_inv;
input_context main_context;
Expand Down Expand Up @@ -121,14 +115,14 @@ class veh_interact
friend nc_color getDurabilityColor( const int &dur );
std::string getDurabilityDescription( const int &dur );

int durabilityPercent;
int durabilityPercent = 100;
std::string totalDurabilityText;
std::string worstDurabilityText;
nc_color totalDurabilityColor;
nc_color worstDurabilityColor;
nc_color totalDurabilityColor = c_green;
nc_color worstDurabilityColor = c_green;

/** Store the most damaged part's index, or -1 if they're all healthy. */
int mostDamagedPart;
int mostDamagedPart = -1;

//do_remove supporting operation, writes requirements to ui
bool can_remove_part( int idx );
Expand Down Expand Up @@ -178,10 +172,6 @@ class veh_interact
void allocate_windows();
void do_main_loop();
void deallocate_windows();

public:
veh_interact();
void exec( vehicle *v );
};

void complete_vehicle();
Expand Down
2 changes: 1 addition & 1 deletion src/veh_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ void vpart_info::check()
} else {
part.install_reqs.qualities = { { { { quality_id( "WRENCH" ), 1, 2 } },
{ { quality_id( "GLARE" ), 1, 2 } } } };
part.install_reqs.tools.push_back( { { { "welder", 50 }, { "welder_crude", 75 }, { "oxy_torch", 10 } } } );
part.install_reqs.tools.push_back( { { { "welder", 50 }, { "welder_crude", 75 }, { "oxy_torch", 10 }, { "toolset", 75 } } } );
part.removal_reqs.qualities = { { { { quality_id( "WRENCH" ), 1, 2 } },
{ { quality_id( "SAW_M" ), 1, 2 } } } };
}
Expand Down